/// <summary> /// Handle the UI exceptions by showing a dialog box, and asking the user whether or not they wish to abort execution. /// </summary> /// <param name="sender">sender object</param> /// <param name="t">ThreadExceptionEventArgs data</param> private static void MainForm_UIThreadException(object sender, ThreadExceptionEventArgs t) { DialogResult result = DialogResult.Cancel; try { Log.Error("UI Thread Exception", t.Exception); result = MessageBox.Show(Log.FormatException(t.Exception), "Windows Forms Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1, rightToLeft); } catch { try { Log.Fatal("Fatal Windows Forms Error", t.Exception); MessageBox.Show(Log.FormatException(t.Exception), "Fatal Windows Forms Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1, rightToLeft); } finally { Application.Exit(); } } // Exits the program when the user clicks Abort. if (result == DialogResult.Abort) { Application.Exit(); } }
/// <summary> /// Shows things that you may want to know before a close. /// Like holding an item /// </summary> /// <returns>TRUE if none of the conditions exist or the user selected to ignore the message</returns> private bool DoCloseStuff() { bool ok = false; try { // Make sure we are not dragging anything if (this.DragInfo.IsActive) { MessageBox.Show(Resources.MainFormHoldingItem, Resources.MainFormHoldingItem2, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, RightToLeftOptions); return(false); } this.SaveAllModifiedFiles(); // Added by VillageIdiot this.SaveConfiguration(); ok = true; } catch (IOException exception) { Log.Error("Save files failed !", exception); MessageBox.Show(Log.FormatException(exception), Resources.GlobalError, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, RightToLeftOptions); } return(ok); }
/// <summary> /// Registers the VXPlibrary.dll /// </summary> private void registerVXPlibrary() { Process proc = new Process(); ProcessStartInfo info = new ProcessStartInfo(); info.UseShellExecute = true; info.WorkingDirectory = "\"" + Directory.GetCurrentDirectory() + "\""; info.FileName = Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\Regsvr32.exe"; info.Verb = "runas"; info.Arguments = "/c \"" + Directory.GetCurrentDirectory() + "\\VXPlib.dll\""; try { proc.StartInfo = info; proc.Start(); proc.WaitForExit(); } catch (Exception ex) { Log.ErrorException(ex); MessageBox.Show(Log.FormatException(ex)); } }
public MainForm() { Log = Logger.Get(this); Log.Info("TQVaultAE Initialization !"); this.Enabled = false; this.ShowInTaskbar = false; this.Opacity = 0; this.Hide(); this.InitializeComponent(); this.SetupFormSize(); #region Apply custom font & scaling this.exitButton.Font = FontHelper.GetFontAlbertusMTLight(12F, UIService.UI.Scale); ScaleControl(this.exitButton); this.characterComboBox.Font = FontHelper.GetFontAlbertusMTLight(13F, UIService.UI.Scale); ScaleControl(this.characterComboBox); ScaleControl(this.characterLabel); ScaleControl(this.itemTextPanel); ScaleControl(this.itemText); this.vaultListComboBox.Font = FontHelper.GetFontAlbertusMTLight(13F, UIService.UI.Scale); ScaleControl(this.vaultListComboBox); this.vaultLabel.Font = FontHelper.GetFontAlbertusMTLight(11F, UIService.UI.Scale); ScaleControl(this.vaultLabel); this.configureButton.Font = FontHelper.GetFontAlbertusMTLight(12F, UIService.UI.Scale); ScaleControl(this.configureButton); this.customMapText.Font = FontHelper.GetFontAlbertusMT(11.25F, UIService.UI.Scale); ScaleControl(this.customMapText); this.panelSelectButton.Font = FontHelper.GetFontAlbertusMTLight(12F, UIService.UI.Scale); ScaleControl(this.panelSelectButton); this.secondaryVaultListComboBox.Font = FontHelper.GetFontAlbertusMTLight(11F, UIService.UI.Scale); ScaleControl(this.secondaryVaultListComboBox); this.aboutButton.Font = FontHelper.GetFontMicrosoftSansSerif(8.25F, UIService.UI.Scale); ScaleControl(this.aboutButton); this.titleLabel.Font = FontHelper.GetFontAlbertusMTLight(24F, UIService.UI.Scale); ScaleControl(this.titleLabel); this.searchButton.Font = FontHelper.GetFontAlbertusMTLight(12F, UIService.UI.Scale); ScaleControl(this.searchButton); #endregion try { this.tooltip = new TTLib(); } catch (Exception ex) { Log.Error("Get TTLib fail !", ex); MessageBox.Show(Log.FormatException(ex)); // Handle failure to create to tooltip here // VXPlib not registered checkVXPlibrary(); this.tooltip = new TTLib(); } // Changed to a global for versions in tqdebug AssemblyName aname = Assembly.GetExecutingAssembly().GetName(); this.currentVersion = aname.Version.ToString(); this.Text = string.Format(CultureInfo.CurrentCulture, "{0} {1}", aname.Name, this.currentVersion); if (TQDebug.DebugEnabled) { // Write this version into the debug file. Log.DebugFormat(CultureInfo.InvariantCulture, "Current TQVault Version: {0}", this.currentVersion); Log.Debug(string.Empty); Log.Debug("Debug Levels"); Log.DebugFormat(CultureInfo.InvariantCulture, "ARCFileDebugLevel: {0}", TQDebug.ArcFileDebugLevel); Log.DebugFormat(CultureInfo.InvariantCulture, "DatabaseDebugLevel: {0}", TQDebug.DatabaseDebugLevel); Log.DebugFormat(CultureInfo.InvariantCulture, "ItemAttributesDebugLevel: {0}", TQDebug.ItemAttributesDebugLevel); Log.DebugFormat(CultureInfo.InvariantCulture, "ItemDebugLevel: {0}", TQDebug.ItemDebugLevel); Log.Debug(string.Empty); } // Setup localized strings. this.characterLabel.Text = Resources.MainFormLabel1; this.vaultLabel.Text = Resources.MainFormLabel2; this.configureButton.Text = Resources.MainFormBtnConfigure; this.exitButton.Text = Resources.GlobalExit; this.panelSelectButton.Text = Resources.MainFormBtnPanelSelect; this.Icon = Resources.TQVIcon; this.searchButton.Text = Resources.MainFormSearchButtonText; // Set up Item strings Item.ItemWith = Resources.ItemWith; Item.ItemRelicBonus = Resources.ItemRelicBonus; Item.ItemRelicCompleted = Resources.ItemRelicCompleted; Item.ItemQuest = Resources.ItemQuest; Item.ItemSeed = Resources.ItemSeed; Item.ItemIT = Resources.ItemIT; Item.ItemRagnarok = Resources.ItemRagnarok; Item.ItemAtlantis = Resources.ItemAtlantis; Item.ShowSkillLevel = Config.Settings.Default.ShowSkillLevel; if (Config.Settings.Default.NoToolTipDelay) { this.tooltip.SetNoDelay(); } this.lastDragPoint.X = -1; this.dragInfo = new ItemDragInfo(); this.CreatePanels(); // Process the mouse scroll wheel to cycle through the vaults. this.MouseWheel += new MouseEventHandler(this.MainFormMouseWheel); this.splashScreen = new SplashScreenForm(); this.splashScreen.MaximumValue = 1; this.splashScreen.FormClosed += new FormClosedEventHandler(this.SplashScreenClosed); if (Config.Settings.Default.LoadAllFiles) { this.splashScreen.MaximumValue += LoadAllFilesTotal(); } this.splashScreen.Show(); this.splashScreen.Update(); }
public static void Main() { try { // Add the event handler for handling UI thread exceptions to the event. Application.ThreadException += new ThreadExceptionEventHandler(MainForm_UIThreadException); // Set the unhandled exception mode to force all Windows Forms errors to go through our handler. Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); // Add the event handler for handling non-UI thread exceptions to the event. AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); #if DEBUG Logger.ChangeRootLogLevel(Level.Debug); //TQDebug.DebugEnabled = true; #endif restart: // Configure DI var scol = new ServiceCollection() // Logs .AddSingleton(typeof(ILogger <>), typeof(ILoggerImpl <>)) // States .AddSingleton <SessionContext>() // Providers .AddTransient <IRecordInfoProvider, RecordInfoProvider>() .AddTransient <IArcFileProvider, ArcFileProvider>() .AddTransient <IArzFileProvider, ArzFileProvider>() .AddSingleton <IDatabase, Database>() .AddSingleton <IItemProvider, ItemProvider>() .AddTransient <ILootTableCollectionProvider, LootTableCollectionProvider>() .AddTransient <IStashProvider, StashProvider>() .AddTransient <IPlayerCollectionProvider, PlayerCollectionProvider>() .AddTransient <ISackCollectionProvider, SackCollectionProvider>() .AddSingleton <IItemAttributeProvider, ItemAttributeProvider>() .AddTransient <IDBRecordCollectionProvider, DBRecordCollectionProvider>() // Services .AddTransient <IAddFontToOS, AddFontToOSWin>() .AddSingleton <IGamePathService, GamePathServiceWin>() .AddTransient <IPlayerService, PlayerService>() .AddTransient <IStashService, StashService>() .AddTransient <IVaultService, VaultService>() .AddTransient <ISearchService, SearchService>() .AddTransient <IFontService, FontService>() .AddTransient <ITranslationService, TranslationService>() .AddSingleton <IUIService, UIService>() .AddSingleton <ITQDataService, TQDataService>() .AddTransient <IBitmapService, BitmapService>() // Forms .AddSingleton <MainForm>() .AddTransient <AboutBox>() .AddTransient <CharacterEditDialog>() .AddTransient <ItemProperties>() .AddTransient <ItemSeedDialog>() .AddTransient <ResultsDialog>() .AddTransient <SearchDialog>() .AddTransient <SettingsDialog>() .AddTransient <VaultMaintenanceDialog>() .AddTransient <SplashScreenForm>(); Program.ServiceProvider = scol.BuildServiceProvider(); var gamePathResolver = Program.ServiceProvider.GetService <IGamePathService>(); try { ManageCulture(); SetUILanguage(); SetupGamePaths(gamePathResolver); SetupMapName(gamePathResolver); } catch (ExGamePathNotFound ex) { using (var fbd = new FolderBrowserDialog() { Description = ex.Message, ShowNewFolderButton = false }) { DialogResult result = fbd.ShowDialog(); if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath)) { Config.Settings.Default.ForceGamePath = fbd.SelectedPath; Config.Settings.Default.Save(); goto restart; } else { goto exit; } } } var mainform = Program.ServiceProvider.GetService <MainForm>(); Application.Run(mainform); } catch (Exception ex) { Log.ErrorException(ex); MessageBox.Show(Log.FormatException(ex), Resources.GlobalError, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); } exit :; }