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 diff
     1.1 --- a/.hgignore	Wed Dec 08 18:44:10 2010 -0600
     1.2 +++ b/.hgignore	Sun Dec 12 16:13:15 2010 -0600
     1.3 @@ -1,3 +1,7 @@
     1.4  syntax:glob
     1.5  bin/*
     1.6 -obj/*
     1.7 \ No newline at end of file
     1.8 +obj/*
     1.9 +*.orig
    1.10 +*.user
    1.11 +*.userprefs
    1.12 +*.suo
    1.13 \ No newline at end of file
     2.1 --- a/FrmMain.cs	Wed Dec 08 18:44:10 2010 -0600
     2.2 +++ b/FrmMain.cs	Sun Dec 12 16:13:15 2010 -0600
     2.3 @@ -51,10 +51,13 @@
     2.4  		private System.ComponentModel.IContainer components;
     2.5  		private System.Windows.Forms.MainMenu mainMenu;
     2.6  		private MenuStrip menuStrip;
     2.7 +		private System.Windows.Forms.OpenFileDialog openFile;
     2.8  		// File Menu and Contents
     2.9  		private IBBToolStripMenuItem menuFile;
    2.10  		private IBBToolStripMenuItem menuNew;
    2.11  		private IBBToolStripMenuItem miNewSystem;
    2.12 +		private IBBToolStripMenuItem menuOpen;
    2.13 +		private IBBToolStripMenuItem miOpenSystem;
    2.14  		private ToolStripSeparator toolStripSeparator2;
    2.15  		private IBBToolStripMenuItem miExit;
    2.16  		// About Menu and Contents
    2.17 @@ -69,7 +72,7 @@
    2.18  		{
    2.19  			try
    2.20  			{
    2.21 -				XmlConfigurator.Configure(new System.IO.FileInfo("WarFoundryForge.log4net"));
    2.22 +				XmlConfigurator.Configure(new System.IO.FileInfo("WarFoundryForge.exe.log4net"));
    2.23  				LogManager.GetLogger(typeof(FrmMain)).Info("Starting WarFoundry Forge WinForms");
    2.24  				Application.EnableVisualStyles();
    2.25  				Application.Run(new FrmMain(args));
    2.26 @@ -121,6 +124,12 @@
    2.27  			TranslateControls();
    2.28  		}
    2.29  
    2.30 +		public GameSystem CurrentGameSystem
    2.31 +		{
    2.32 +			get { return WarFoundryCore.CurrentGameSystem; }
    2.33 +			set { WarFoundryCore.CurrentGameSystem = value; }
    2.34 +		}
    2.35 +
    2.36  		public static string DataPath
    2.37  		{
    2.38  			get { return Constants.ExecutablePath + Constants.DirectoryChar + "data"; }
    2.39 @@ -171,10 +180,13 @@
    2.40  			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmMain));
    2.41  			this.mainMenu = new System.Windows.Forms.MainMenu(this.components);
    2.42  			this.menuStrip = new System.Windows.Forms.MenuStrip();
    2.43 +			this.openFile = new System.Windows.Forms.OpenFileDialog();
    2.44  			// File Menu and Contents
    2.45  			this.menuFile = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
    2.46  			this.menuNew = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
    2.47  			this.miNewSystem = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
    2.48 +			this.menuOpen = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
    2.49 +			this.miOpenSystem = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
    2.50  			this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
    2.51  			this.miExit = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
    2.52  			// About Menu and Contents
    2.53 @@ -197,6 +209,7 @@
    2.54  			// 
    2.55  			this.menuFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
    2.56  			this.menuNew,
    2.57 +			this.menuOpen,
    2.58  			this.toolStripSeparator2,
    2.59              this.miExit});
    2.60  			this.menuFile.Name = "menuFile";
    2.61 @@ -218,6 +231,21 @@
    2.62  			this.miNewSystem.Text = "s&ystem";
    2.63  			this.miNewSystem.Click += new System.EventHandler(this.miNewSystem_Click);
    2.64  			// 
    2.65 +			// menuOpen
    2.66 +			// 
    2.67 +			this.menuOpen.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
    2.68 +			this.miOpenSystem});
    2.69 +			this.menuOpen.Name = "menuOpen";
    2.70 +			this.menuOpen.Size = new System.Drawing.Size(164, 22);
    2.71 +			this.menuOpen.Text = "&open";
    2.72 +			// 
    2.73 +			// miOpenSystem
    2.74 +			// 
    2.75 +			this.miOpenSystem.Name = "miOpenSystem";
    2.76 +			this.miOpenSystem.Size = new System.Drawing.Size(164, 22);
    2.77 +			this.miOpenSystem.Text = "s&ystem";
    2.78 +			this.miOpenSystem.Click += new System.EventHandler(this.miOpenSystem_Click);
    2.79 +			// 
    2.80  			// toolStripSeparator2
    2.81  			// 
    2.82  			this.toolStripSeparator2.Name = "toolStripSeparator2";
    2.83 @@ -272,10 +300,75 @@
    2.84  		
    2.85  		private void miNewSystem_Click(object sender, System.EventArgs e)
    2.86  		{
    2.87 -			FrmSystem system = new FrmSystem();
    2.88 +			FrmSystem system = new FrmSystem(new GameSystem(" ", " ", null));
    2.89  			system.ShowDialog(this);
    2.90  		}
    2.91  
    2.92 +		private void miOpenSystem_Click(object sender, System.EventArgs e)
    2.93 +		{
    2.94 +			OpenFile();
    2.95 +			FrmSystem system = new FrmSystem(CurrentGameSystem);
    2.96 +			system.ShowDialog(this);
    2.97 +		}
    2.98 +		
    2.99 +		private bool OpenFile()
   2.100 +		{
   2.101 +			if (openFile.Filter == "")
   2.102 +			{
   2.103 +				string savePath = DataPath;
   2.104 +
   2.105 +				if (!Directory.Exists(savePath))
   2.106 +				{
   2.107 +					Directory.CreateDirectory(savePath);
   2.108 +				}
   2.109 +
   2.110 +				openFile.InitialDirectory = savePath;
   2.111 +				openFile.Filter = Translation.GetTranslation("systemFileFilter") + "|*.system";
   2.112 +				openFile.Title = Translation.GetTranslation("openSystemDialog");
   2.113 +
   2.114 +			}
   2.115 +			
   2.116 +			DialogResult dr = openFile.ShowDialog(this);
   2.117 +			if (dr == DialogResult.OK)
   2.118 +			{
   2.119 +				try
   2.120 +				{
   2.121 +					string newFilePath = openFile.FileName;
   2.122 +					ICollection<IWarFoundryObject> fileContents = WarFoundryLoader.GetDefault().LoadFile(new FileInfo(newFilePath));
   2.123 +					
   2.124 +					if(fileContents.Count > 0)
   2.125 +					{
   2.126 +						foreach(IWarFoundryObject fileObject in fileContents)
   2.127 +						{
   2.128 +							if(fileObject is GameSystem)
   2.129 +							{
   2.130 +								CurrentGameSystem = (GameSystem)fileObject;
   2.131 +							}
   2.132 +						}
   2.133 +					}
   2.134 +					log.DebugFormat("Game System set to: {0}", CurrentGameSystem.Name);
   2.135 +					loadedFilePath = newFilePath;
   2.136 +					return true;
   2.137 +				}
   2.138 +				catch (RequiredDataMissingException ex)
   2.139 +				{
   2.140 +					log.Error(ex);
   2.141 +					MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidArmyFileBoxTitle", "invalid army file"), MessageBoxButtons.OK, MessageBoxIcon.Error);
   2.142 +					return false;
   2.143 +				}
   2.144 +				catch (InvalidFileException ex)
   2.145 +				{
   2.146 +					log.Error(ex);
   2.147 +					MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidArmyFileBoxTitle", "invalid army file"), MessageBoxButtons.OK, MessageBoxIcon.Error);
   2.148 +					return false;
   2.149 +				}
   2.150 +			}
   2.151 +			else
   2.152 +			{
   2.153 +				return false;
   2.154 +			}
   2.155 +		}
   2.156 +
   2.157  		private void miExit_Click(object sender, System.EventArgs e)
   2.158  		{
   2.159  			Application.Exit();
     3.1 --- a/FrmSystem.cs	Wed Dec 08 18:44:10 2010 -0600
     3.2 +++ b/FrmSystem.cs	Sun Dec 12 16:13:15 2010 -0600
     3.3 @@ -14,9 +14,33 @@
     3.4  {
     3.5  	public partial class FrmSystem : IBBoard.Windows.Forms.IBBForm
     3.6  	{
     3.7 -		public FrmSystem()
     3.8 +		private IBBoard.WarFoundry.API.Objects.GameSystem system;
     3.9 +		
    3.10 +		public FrmSystem(IBBoard.WarFoundry.API.Objects.GameSystem loadSystem)
    3.11  		{
    3.12  			InitializeComponent();
    3.13 +			system = loadSystem;
    3.14 +			if(loadSystem.IsFullyLoaded)
    3.15 +			{
    3.16 +				this.txtSystemName.Text = system.Name;
    3.17 +				this.txtSystemId.Text = system.ID;
    3.18 +				if(system.AllowAllies)
    3.19 +				{
    3.20 +					this.radSystemAlliesYes.Checked = true;
    3.21 +				}
    3.22 +				else
    3.23 +				{
    3.24 +					this.radSystemAlliesNo.Checked = true;
    3.25 +				}
    3.26 +				if (system.WarnOnError)
    3.27 +				{
    3.28 +					this.radSystemWarnYes.Checked = true;
    3.29 +				}
    3.30 +				else
    3.31 +				{
    3.32 +					this.radSystemWarnNo.Checked = true;
    3.33 +				}
    3.34 +			}
    3.35  		}
    3.36  
    3.37  		private void btnSystemClose_Click(object sender, EventArgs e)
     4.1 --- a/IBBoard.WarFoundry.Forge.WinForms.csproj	Wed Dec 08 18:44:10 2010 -0600
     4.2 +++ b/IBBoard.WarFoundry.Forge.WinForms.csproj	Sun Dec 12 16:13:15 2010 -0600
     4.3 @@ -62,6 +62,7 @@
     4.4    </ItemGroup>
     4.5    <ItemGroup>
     4.6      <Compile Include="FrmAbout.cs">
     4.7 +      <SubType>Form</SubType>
     4.8      </Compile>
     4.9      <Compile Include="FrmAbout.Designer.cs">
    4.10        <DependentUpon>FrmAbout.cs</DependentUpon>
     5.1 Binary file bin/Debug/IBBoard.WarFoundry.API.dll has changed
     6.1 Binary file bin/Debug/IBBoard.dll has changed
     7.1 Binary file bin/Debug/IBBoardWF.dll has changed
     8.1 Binary file bin/Debug/ICSharpCode.SharpZipLib.dll has changed
     9.1 Binary file obj/Debug/ResolveAssemblyReference.cache has changed