comparison FrmMain.cs @ 68:fd8654afd331

Fixes #183: Get logging working with WinForms * Add required line to AssemblyInfo.cs * Tidy up logging in FrmMain and make sure that we have startup and shutdown messages
author IBBoard <dev@ibboard.co.uk>
date Sat, 26 Sep 2009 19:12:04 +0000
parents 75cf9b6608f5
children 12f11e3c6261
comparison
equal deleted inserted replaced
67:75cf9b6608f5 68:fd8654afd331
37 { 37 {
38 private static readonly string AppTitle = "WarFoundry"; 38 private static readonly string AppTitle = "WarFoundry";
39 const string DefaultDataDir = "data"; 39 const string DefaultDataDir = "data";
40 40
41 private Preferences preferences; 41 private Preferences preferences;
42 protected readonly ILog logger = LogManager.GetLogger(typeof(FrmMain)); 42 private readonly ILog log = LogManager.GetLogger(typeof(FrmMain));
43 43
44 private CommandStack commandStack; 44 private CommandStack commandStack;
45 private ToolBarButton[] categoryButtons; 45 private ToolBarButton[] categoryButtons;
46 46
47 public ObjectAddDelegate UnitAddedMethod; 47 public ObjectAddDelegate UnitAddedMethod;
97 [STAThread] 97 [STAThread]
98 static void Main(string[] args) 98 static void Main(string[] args)
99 { 99 {
100 try 100 try
101 { 101 {
102 LogManager.GetLogger(typeof(FrmMain)).Info("Starting WarFoundry WinForms");
102 Application.EnableVisualStyles(); 103 Application.EnableVisualStyles();
103 Application.Run(new FrmMain(args)); 104 Application.Run(new FrmMain(args));
105 LogManager.GetLogger(typeof(FrmMain)).Info("Closing WarFoundry WinForms");
104 } 106 }
105 catch (Exception ex) 107 catch (Exception ex)
106 { 108 {
107 LogManager.GetLogger(typeof(FrmMain)).Fatal(ex); 109 LogManager.GetLogger(typeof(FrmMain)).Fatal(ex);
108 MessageBox.Show(null, "A major, unexpected and fatal error ocurred while starting the application: \r\n\r\n" + ex.Message + "\r\n\r\n" + ex.StackTrace, "Fatal error", MessageBoxButtons.OK, MessageBoxIcon.Error); 110 MessageBox.Show(null, "A major, unexpected and fatal error ocurred while starting the application: \r\n\r\n" + ex.Message + "\r\n\r\n" + ex.StackTrace, "Fatal error", MessageBoxButtons.OK, MessageBoxIcon.Error);
121 { 123 {
122 Translation.InitialiseTranslations(Constants.ExecutablePath, Preferences["language"].ToString()); 124 Translation.InitialiseTranslations(Constants.ExecutablePath, Preferences["language"].ToString());
123 } 125 }
124 catch (TranslationLoadException ex) 126 catch (TranslationLoadException ex)
125 { 127 {
126 logger.Error(ex); 128 log.Error("Translation loading failed for language " + Preferences["language"].ToString(), ex);
127 MessageBox.Show(this, "Translation loading failed for language " + Preferences["language"].ToString(), "Translation failure", MessageBoxButtons.OK, MessageBoxIcon.Error); 129 MessageBox.Show(this, "Translation loading failed for language " + Preferences["language"].ToString(), "Translation failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
128 } 130 }
129 131
130 //pnlRight.Left = ClientSize.Width - pnlRight.Width - 2; 132 //pnlRight.Left = ClientSize.Width - pnlRight.Width - 2;
131 //pnlRight.Top = toolBar.Height + 5; 133 //pnlRight.Top = toolBar.Height + 5;
544 546
545 private void FileLoadingFinished(List<FileLoadFailure> failures) 547 private void FileLoadingFinished(List<FileLoadFailure> failures)
546 { 548 {
547 foreach (FileLoadFailure failure in failures) 549 foreach (FileLoadFailure failure in failures)
548 { 550 {
549 logger.Warn("Failed to load " + failure.FailedFile.FullName + ": " + failure.Message); 551 log.Warn("Failed to load " + failure.FailedFile.FullName + ": " + failure.Message);
550 } 552 }
551 } 553 }
552 554
553 private void miExit_Click(object sender, System.EventArgs e) 555 private void miExit_Click(object sender, System.EventArgs e)
554 { 556 {
574 } 576 }
575 } 577 }
576 578
577 private bool OpenArmy() 579 private bool OpenArmy()
578 { 580 {
579 if (CloseCurrentArmy()) 581 if (openArmyDialog.Filter=="")
580 { 582 {
581 if (openArmyDialog.Filter=="") 583 string savePath = ArmiesPath;
582 { 584
583 string savePath = ArmiesPath; 585 if (!Directory.Exists(savePath))
584 586 {
585 if (!Directory.Exists(savePath)) 587 Directory.CreateDirectory(savePath);
586 { 588 }
587 Directory.CreateDirectory(savePath); 589
588 } 590 openArmyDialog.InitialDirectory = savePath;
589 591 openArmyDialog.Filter = Translation.GetTranslation("armyFileFilter")+"|*.army";
590 openArmyDialog.InitialDirectory = savePath; 592 openArmyDialog.Title = Translation.GetTranslation("openArmyDialog");
591 openArmyDialog.Filter = Translation.GetTranslation("armyFileFilter")+"|*.army"; 593
592 openArmyDialog.Title = Translation.GetTranslation("openArmyDialog"); 594 }
593 595
594 } 596 DialogResult dr = openArmyDialog.ShowDialog(this);
595 597
596 DialogResult dr = openArmyDialog.ShowDialog(this); 598 if (dr == DialogResult.OK)
597 599 {
598 if (dr == DialogResult.OK) 600 if (CloseCurrentArmy())
599 { 601 {
600 try 602 try
601 { 603 {
602 string newFilePath = openArmyDialog.FileName; 604 string newFilePath = openArmyDialog.FileName;
603 CurrentArmy = WarFoundryLoader.GetDefault().LoadArmy(new FileInfo(newFilePath)); 605 CurrentArmy = WarFoundryLoader.GetDefault().LoadArmy(new FileInfo(newFilePath));
604 loadedFilePath = newFilePath; 606 loadedFilePath = newFilePath;
605 return true; 607 return true;
606 } 608 }
607 catch (InvalidFileException ex) 609 catch (InvalidFileException ex)
608 { 610 {
609 logger.Error(ex); 611 log.Error(ex);
610 MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidFileBoxTitle", "Invalid data file"), MessageBoxButtons.OK, MessageBoxIcon.Error); 612 MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidFileBoxTitle", "Invalid army file"), MessageBoxButtons.OK, MessageBoxIcon.Error);
611 return false; 613 return false;
612 } 614 }
613 } 615 }
614 else 616 else
615 { 617 {
1264 1266
1265 if (dr == DialogResult.OK) 1267 if (dr == DialogResult.OK)
1266 { 1268 {
1267 Army army = CurrentArmy; 1269 Army army = CurrentArmy;
1268 string filePath = dialog.FileName; 1270 string filePath = dialog.FileName;
1269 logger.DebugFormat("Exporting {0} to {1} as basic HTML", army.Name, filePath); 1271 log.DebugFormat("Exporting {0} to {1} as basic HTML", army.Name, filePath);
1270 WarFoundryHtmlExporter.GetDefault().ExportArmy(army, filePath); 1272 WarFoundryHtmlExporter.GetDefault().ExportArmy(army, filePath);
1271 } 1273 }
1272 } 1274 }
1273 1275
1274 private void FrmMain_Load(object sender, EventArgs e) 1276 private void FrmMain_Load(object sender, EventArgs e)
1275 { 1277 {
1276 string gameSystemID = Preferences.GetStringProperty("currSystem"); 1278 string gameSystemID = Preferences.GetStringProperty("currSystem");
1277 1279
1278 if (gameSystemID != null && !"".Equals(gameSystemID)) 1280 if (gameSystemID != null && !"".Equals(gameSystemID))
1279 { 1281 {
1280 logger.Debug("Attempting to load current game system from properties"); 1282 log.Debug("Attempting to load current game system from properties");
1281 GameSystem sys = WarFoundryLoader.GetDefault().GetGameSystem(gameSystemID); 1283 GameSystem sys = WarFoundryLoader.GetDefault().GetGameSystem(gameSystemID);
1282 1284
1283 if (sys != null) 1285 if (sys != null)
1284 { 1286 {
1285 WarFoundryCore.CurrentGameSystem = sys; 1287 WarFoundryCore.CurrentGameSystem = sys;
1286 logger.InfoFormat("Loaded game system {0} from properties", gameSystemID); 1288 log.InfoFormat("Loaded game system {0} from properties", gameSystemID);
1287 } 1289 }
1288 } 1290 }
1289 } 1291 }
1290 } 1292 }
1291 } 1293 }