changeset 4:866d0093bb11

WarFoundryLoader.GetDefault().LoadFile returning null object.
author Tsudico
date Sun, 12 Dec 2010 16:13:15 -0600
parents 2f52da2e7605
children 387f17b36f52
files .hgignore FrmMain.cs FrmSystem.cs IBBoard.WarFoundry.Forge.WinForms.csproj bin/Debug/IBBoard.WarFoundry.API.dll bin/Debug/IBBoard.dll bin/Debug/IBBoardWF.dll bin/Debug/ICSharpCode.SharpZipLib.dll obj/Debug/ResolveAssemblyReference.cache
diffstat 9 files changed, 126 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Wed Dec 08 18:44:10 2010 -0600
+++ b/.hgignore	Sun Dec 12 16:13:15 2010 -0600
@@ -1,3 +1,7 @@
 syntax:glob
 bin/*
-obj/*
\ No newline at end of file
+obj/*
+*.orig
+*.user
+*.userprefs
+*.suo
\ No newline at end of file
--- a/FrmMain.cs	Wed Dec 08 18:44:10 2010 -0600
+++ b/FrmMain.cs	Sun Dec 12 16:13:15 2010 -0600
@@ -51,10 +51,13 @@
 		private System.ComponentModel.IContainer components;
 		private System.Windows.Forms.MainMenu mainMenu;
 		private MenuStrip menuStrip;
+		private System.Windows.Forms.OpenFileDialog openFile;
 		// File Menu and Contents
 		private IBBToolStripMenuItem menuFile;
 		private IBBToolStripMenuItem menuNew;
 		private IBBToolStripMenuItem miNewSystem;
+		private IBBToolStripMenuItem menuOpen;
+		private IBBToolStripMenuItem miOpenSystem;
 		private ToolStripSeparator toolStripSeparator2;
 		private IBBToolStripMenuItem miExit;
 		// About Menu and Contents
@@ -69,7 +72,7 @@
 		{
 			try
 			{
-				XmlConfigurator.Configure(new System.IO.FileInfo("WarFoundryForge.log4net"));
+				XmlConfigurator.Configure(new System.IO.FileInfo("WarFoundryForge.exe.log4net"));
 				LogManager.GetLogger(typeof(FrmMain)).Info("Starting WarFoundry Forge WinForms");
 				Application.EnableVisualStyles();
 				Application.Run(new FrmMain(args));
@@ -121,6 +124,12 @@
 			TranslateControls();
 		}
 
+		public GameSystem CurrentGameSystem
+		{
+			get { return WarFoundryCore.CurrentGameSystem; }
+			set { WarFoundryCore.CurrentGameSystem = value; }
+		}
+
 		public static string DataPath
 		{
 			get { return Constants.ExecutablePath + Constants.DirectoryChar + "data"; }
@@ -171,10 +180,13 @@
 			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmMain));
 			this.mainMenu = new System.Windows.Forms.MainMenu(this.components);
 			this.menuStrip = new System.Windows.Forms.MenuStrip();
+			this.openFile = new System.Windows.Forms.OpenFileDialog();
 			// File Menu and Contents
 			this.menuFile = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
 			this.menuNew = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
 			this.miNewSystem = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
+			this.menuOpen = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
+			this.miOpenSystem = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
 			this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
 			this.miExit = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
 			// About Menu and Contents
@@ -197,6 +209,7 @@
 			// 
 			this.menuFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
 			this.menuNew,
+			this.menuOpen,
 			this.toolStripSeparator2,
             this.miExit});
 			this.menuFile.Name = "menuFile";
@@ -218,6 +231,21 @@
 			this.miNewSystem.Text = "s&ystem";
 			this.miNewSystem.Click += new System.EventHandler(this.miNewSystem_Click);
 			// 
+			// menuOpen
+			// 
+			this.menuOpen.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+			this.miOpenSystem});
+			this.menuOpen.Name = "menuOpen";
+			this.menuOpen.Size = new System.Drawing.Size(164, 22);
+			this.menuOpen.Text = "&open";
+			// 
+			// miOpenSystem
+			// 
+			this.miOpenSystem.Name = "miOpenSystem";
+			this.miOpenSystem.Size = new System.Drawing.Size(164, 22);
+			this.miOpenSystem.Text = "s&ystem";
+			this.miOpenSystem.Click += new System.EventHandler(this.miOpenSystem_Click);
+			// 
 			// toolStripSeparator2
 			// 
 			this.toolStripSeparator2.Name = "toolStripSeparator2";
@@ -272,9 +300,74 @@
 		
 		private void miNewSystem_Click(object sender, System.EventArgs e)
 		{
-			FrmSystem system = new FrmSystem();
+			FrmSystem system = new FrmSystem(new GameSystem(" ", " ", null));
+			system.ShowDialog(this);
+		}
+
+		private void miOpenSystem_Click(object sender, System.EventArgs e)
+		{
+			OpenFile();
+			FrmSystem system = new FrmSystem(CurrentGameSystem);
 			system.ShowDialog(this);
 		}
+		
+		private bool OpenFile()
+		{
+			if (openFile.Filter == "")
+			{
+				string savePath = DataPath;
+
+				if (!Directory.Exists(savePath))
+				{
+					Directory.CreateDirectory(savePath);
+				}
+
+				openFile.InitialDirectory = savePath;
+				openFile.Filter = Translation.GetTranslation("systemFileFilter") + "|*.system";
+				openFile.Title = Translation.GetTranslation("openSystemDialog");
+
+			}
+			
+			DialogResult dr = openFile.ShowDialog(this);
+			if (dr == DialogResult.OK)
+			{
+				try
+				{
+					string newFilePath = openFile.FileName;
+					ICollection<IWarFoundryObject> fileContents = WarFoundryLoader.GetDefault().LoadFile(new FileInfo(newFilePath));
+					
+					if(fileContents.Count > 0)
+					{
+						foreach(IWarFoundryObject fileObject in fileContents)
+						{
+							if(fileObject is GameSystem)
+							{
+								CurrentGameSystem = (GameSystem)fileObject;
+							}
+						}
+					}
+					log.DebugFormat("Game System set to: {0}", CurrentGameSystem.Name);
+					loadedFilePath = newFilePath;
+					return true;
+				}
+				catch (RequiredDataMissingException ex)
+				{
+					log.Error(ex);
+					MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidArmyFileBoxTitle", "invalid army file"), MessageBoxButtons.OK, MessageBoxIcon.Error);
+					return false;
+				}
+				catch (InvalidFileException ex)
+				{
+					log.Error(ex);
+					MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidArmyFileBoxTitle", "invalid army file"), MessageBoxButtons.OK, MessageBoxIcon.Error);
+					return false;
+				}
+			}
+			else
+			{
+				return false;
+			}
+		}
 
 		private void miExit_Click(object sender, System.EventArgs e)
 		{
--- a/FrmSystem.cs	Wed Dec 08 18:44:10 2010 -0600
+++ b/FrmSystem.cs	Sun Dec 12 16:13:15 2010 -0600
@@ -14,9 +14,33 @@
 {
 	public partial class FrmSystem : IBBoard.Windows.Forms.IBBForm
 	{
-		public FrmSystem()
+		private IBBoard.WarFoundry.API.Objects.GameSystem system;
+		
+		public FrmSystem(IBBoard.WarFoundry.API.Objects.GameSystem loadSystem)
 		{
 			InitializeComponent();
+			system = loadSystem;
+			if(loadSystem.IsFullyLoaded)
+			{
+				this.txtSystemName.Text = system.Name;
+				this.txtSystemId.Text = system.ID;
+				if(system.AllowAllies)
+				{
+					this.radSystemAlliesYes.Checked = true;
+				}
+				else
+				{
+					this.radSystemAlliesNo.Checked = true;
+				}
+				if (system.WarnOnError)
+				{
+					this.radSystemWarnYes.Checked = true;
+				}
+				else
+				{
+					this.radSystemWarnNo.Checked = true;
+				}
+			}
 		}
 
 		private void btnSystemClose_Click(object sender, EventArgs e)
--- a/IBBoard.WarFoundry.Forge.WinForms.csproj	Wed Dec 08 18:44:10 2010 -0600
+++ b/IBBoard.WarFoundry.Forge.WinForms.csproj	Sun Dec 12 16:13:15 2010 -0600
@@ -62,6 +62,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="FrmAbout.cs">
+      <SubType>Form</SubType>
     </Compile>
     <Compile Include="FrmAbout.Designer.cs">
       <DependentUpon>FrmAbout.cs</DependentUpon>
Binary file bin/Debug/IBBoard.WarFoundry.API.dll has changed
Binary file bin/Debug/IBBoard.dll has changed
Binary file bin/Debug/IBBoardWF.dll has changed
Binary file bin/Debug/ICSharpCode.SharpZipLib.dll has changed
Binary file obj/Debug/ResolveAssemblyReference.cache has changed