/// <summary> /// Minimize to tray /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnMinimizeWindow(object sender, EventArgs e) { try { if (_settingsController.MinimizeToTray) { if (WindowState == FormWindowState.Minimized) { Hide(); notifyIcon1.Visible = true; } else /*if (this.WindowState == FormWindowState.Normal)*/ { notifyIcon1.Visible = false; _previousWindowState = WindowState; } } } catch (Exception ex) { Logger.Warn(ex.Message); Logger.Warn(ex.StackTrace); } _usageStatisticsReporter.ResetLastMinimized(); _automaticUpdateChecker.ResetLastMinimized(); }
private void MainWindow_Load(object sender, EventArgs e) { if (Thread.CurrentThread.Name == null) { Thread.CurrentThread.Name = "UI"; } Logger.Debug("Starting UI initialization"); // Set version number var version = Assembly.GetExecutingAssembly().GetName().Version; DateTime buildDate = new DateTime(2000, 1, 1) .AddDays(version.Build) .AddSeconds(version.Revision * 2); statusLabel.Text = statusLabel.Text + $" - {version.Major}.{version.Minor}.{version.Build}.{version.Revision} from {buildDate.ToString("dd/MM/yyyy")}"; var settingsService = _serviceProvider.Get <SettingsService>(); ExceptionReporter.EnableLogUnhandledOnThread(); SizeChanged += OnMinimizeWindow; // Chicken and the egg.. search controller needs browser, browser needs search controllers var. var databaseItemDao = _serviceProvider.Get <IDatabaseItemDao>(); var searchController = _serviceProvider.Get <SearchController>(); searchController.JsIntegration.OnRequestSetItemAssociations += (s, evvv) => { (evvv as GetSetItemAssociationsEventArgs).Elements = databaseItemDao.GetItemSetAssociations(); }; _cefBrowserHandler.InitializeChromium(searchController.JsIntegration, Browser_IsBrowserInitializedChanged, tabControl1); searchController.Browser = _cefBrowserHandler; searchController.JsIntegration.OnClipboard += SetItemsClipboard; searchController.JsIntegration.OnRequestFeatureRecommendation += (o, args) => { var features = settingsService.GetPersistent().FeaturesNotShown; (args as FeatureSuggestionArgs).Feature = features.FirstOrDefault(); (args as FeatureSuggestionArgs).HasFeature = features.Count > 0; }; searchController.JsIntegration.OnSeenFeatureRecommendation += (o, args) => settingsService.GetPersistent().AddShownFeature((args as FeatureSuggestionArgs).Feature); var playerItemDao = _serviceProvider.Get <IPlayerItemDao>(); var cacher = _serviceProvider.Get <TransferStashServiceCache>(); _parsingService.OnParseComplete += (o, args) => cacher.Refresh(); var stashWriter = new SafeTransferStashWriter(settingsService, _cefBrowserHandler); var transferStashService = new TransferStashService(_serviceProvider.Get <IDatabaseItemStatDao>(), settingsService, stashWriter); var transferStashService2 = new TransferStashService2(playerItemDao, cacher, transferStashService, stashWriter, settingsService, _cefBrowserHandler); _serviceProvider.Add(transferStashService2); _transferStashWorker = new TransferStashWorker(transferStashService2, _userFeedbackService); _stashFileMonitor.OnStashModified += (_, __) => { StashEventArg args = __ as StashEventArg; _transferStashWorker.Queue(args?.Filename); // May not minimize, but _usageStatisticsReporter.ResetLastMinimized(); _automaticUpdateChecker.ResetLastMinimized(); }; if (!_stashFileMonitor.StartMonitorStashfile(GlobalPaths.SavePath)) { MessageBox.Show("Ooops!\nIt seems you are synchronizing your saves to steam cloud..\nThis tool is unfortunately not compatible.\n"); _cefBrowserHandler.ShowHelp(HelpService.HelpType.CloudSavesEnabled); Logger.Warn("Shutting down IA, unable to monitor stash files."); if (!Debugger.IsAttached) { Close(); } } // Load the grim database var grimDawnDetector = _serviceProvider.Get <GrimDawnDetector>(); string gdPath = grimDawnDetector.GetGrimLocation(); if (!string.IsNullOrEmpty(gdPath)) { } else { Logger.Warn("Could not find the Grim Dawn install location"); statusLabel.Text = "Could not find the Grim Dawn install location"; var timer = new System.Windows.Forms.Timer(); timer.Tick += TimerTickLookForGrimDawn; timer.Interval = 10000; timer.Start(); } // Load recipes foreach (string file in GlobalPaths.FormulasFiles) { if (!string.IsNullOrEmpty(file)) { bool isHardcore = file.EndsWith("gsh"); Logger.InfoFormat("Reading recipes at \"{0}\", IsHardcore={1}", file, isHardcore); _recipeParser.UpdateFormulas(file, isHardcore); } } var buddyItemDao = _serviceProvider.Get <IBuddyItemDao>(); var buddySubscriptionDao = _serviceProvider.Get <IBuddySubscriptionDao>(); var databaseSettingDao = _serviceProvider.Get <IDatabaseSettingDao>(); _authService = new AuthService(_cefBrowserHandler, new AuthenticationProvider(settingsService), playerItemDao); var backupSettings = new BackupSettings(playerItemDao, settingsService, _cefBrowserHandler); UIHelper.AddAndShow(backupSettings, backupPanel); // TODO: buttonLogin.Visible = !BlockedLogsDetection.DreamcrashBlocked(); var onlineSettings = new OnlineSettings(playerItemDao, _authService, settingsService, _cefBrowserHandler, buddyItemDao, buddySubscriptionDao); UIHelper.AddAndShow(onlineSettings, onlinePanel); _cefBrowserHandler.OnAuthSuccess += (_, __) => onlineSettings.UpdateUi(); UIHelper.AddAndShow(new ModsDatabaseConfig(DatabaseLoadedTrigger, playerItemDao, _parsingService, databaseSettingDao, grimDawnDetector, settingsService, _cefBrowserHandler), modsPanel); if (!BlockedLogsDetection.DreamcrashBlocked()) { UIHelper.AddAndShow(new LoggingWindow(), panelLogging); } var itemTagDao = _serviceProvider.Get <IItemTagDao>(); var backupService = new BackupService(_authService, playerItemDao, settingsService); _charBackupService = new CharacterBackupService(settingsService, _authService); _backupServiceWorker = new BackupServiceWorker(backupService, _charBackupService); searchController.JsIntegration.OnRequestBackedUpCharacterList += (_, args) => { RequestCharacterListEventArg a = args as RequestCharacterListEventArg; a.Characters = _charBackupService.ListBackedUpCharacters(); }; searchController.JsIntegration.OnRequestCharacterDownloadUrl += (_, args) => { RequestCharacterDownloadUrlEventArg a = args as RequestCharacterDownloadUrlEventArg; a.Url = _charBackupService.GetDownloadUrl(a.Character); }; backupService.OnUploadComplete += (o, args) => _searchWindow.UpdateListView(); searchController.OnSearch += (o, args) => backupService.OnSearch(); _searchWindow = new SplitSearchWindow(_cefBrowserHandler.BrowserControl, SetFeedback, playerItemDao, searchController, itemTagDao, settingsService); UIHelper.AddAndShow(_searchWindow, searchPanel); searchPanel.Height = searchPanel.Parent.Height; searchPanel.Width = searchPanel.Parent.Width; transferStashService2.OnUpdate += (_, __) => { _searchWindow.UpdateListView(); }; var languagePackPicker = new LanguagePackPicker(itemTagDao, playerItemDao, _parsingService, settingsService); var dm = new DarkMode(this); UIHelper.AddAndShow( new SettingsWindow( _cefBrowserHandler, _tooltipHelper, ListviewUpdateTrigger, playerItemDao, _searchWindow.ModSelectionHandler.GetAvailableModSelection(), transferStashService, transferStashService2, languagePackPicker, settingsService, grimDawnDetector, dm ), settingsPanel); #if !DEBUG if (!BlockedLogsDetection.DreamcrashBlocked()) // Uses dreamcrash server { ThreadPool.QueueUserWorkItem(m => ExceptionReporter.ReportUsage()); _automaticUpdateChecker.CheckForUpdates(); } #endif Shown += (_, __) => { StartInjector(); }; _buddyItemsService = new BuddyItemsService( buddyItemDao, 3 * 60 * 1000, settingsService, _authService, buddySubscriptionDao ); // Start the backup task _backupBackgroundTask = new BackgroundTask(new FileBackup(playerItemDao, settingsService)); LocalizationLoader.ApplyLanguage(Controls, RuntimeSettings.Language); new EasterEgg(settingsService).Activate(this); // Initialize the "stash packer" used to find item positions for transferring items ingame while the stash is open { _dynamicPacker.Initialize(8, 16); var transferFiles = GlobalPaths.TransferFiles; if (transferFiles.Count > 0) { var file = transferFiles.MaxBy(m => m.LastAccess); var stash = TransferStashService.GetStash(file.Filename); if (stash != null) { _dynamicPacker.Initialize(stash.Width, stash.Height); if (stash.Tabs.Count >= 3) { foreach (var item in stash.Tabs[2].Items) { byte[] bx = BitConverter.GetBytes(item.XOffset); uint x = (uint)BitConverter.ToSingle(bx, 0); byte[] by = BitConverter.GetBytes(item.YOffset); uint y = (uint)BitConverter.ToSingle(by, 0); _dynamicPacker.Insert(item.BaseRecord, item.Seed, x, y); } } } } } _messageProcessors.Add(new ItemPositionFinder(_dynamicPacker)); _messageProcessors.Add(new PlayerPositionTracker(Debugger.IsAttached && false)); _messageProcessors.Add(new StashStatusHandler()); _messageProcessors.Add(new CloudDetectorProcessor(SetFeedback)); _messageProcessors.Add(new GenericErrorHandler()); RuntimeSettings.StashStatusChanged += GlobalSettings_StashStatusChanged; _transferController = new ItemTransferController( _cefBrowserHandler, SetFeedback, SetTooltipAtmouse, _searchWindow, playerItemDao, transferStashService, _serviceProvider.Get <ItemStatService>(), settingsService ); Application.AddMessageFilter(new MousewheelMessageFilter()); var titleTag = RuntimeSettings.Language.GetTag("iatag_ui_itemassistant"); if (!string.IsNullOrEmpty(titleTag)) { this.Text += $" - {titleTag}"; } // Popup login diag if (_authService.CheckAuthentication() == AuthService.AccessStatus.Unauthorized && !settingsService.GetLocal().OptOutOfBackups) { if (!BlockedLogsDetection.DreamcrashBlocked()) { // Backup login wont work var t = new System.Windows.Forms.Timer { Interval = 100 }; t.Tick += (o, args) => { if (_cefBrowserHandler.BrowserControl.CanExecuteJavascriptInMainFrame) { _authService.Authenticate(); t.Stop(); } }; t.Start(); } } searchController.JsIntegration.ItemTransferEvent += TransferItem; new WindowSizeManager(this, settingsService); // Suggest translation packs if available if (string.IsNullOrEmpty(settingsService.GetLocal().LocalizationFile) && !settingsService.GetLocal().HasSuggestedLanguageChange) { if (LocalizationLoader.HasSupportedTranslations(grimDawnDetector.GetGrimLocations())) { Logger.Debug("A new language pack has been detected, informing end user.."); new LanguagePackPicker(itemTagDao, playerItemDao, _parsingService, settingsService).Show(grimDawnDetector.GetGrimLocations()); settingsService.GetLocal().HasSuggestedLanguageChange = true; } } if (settingsService.GetPersistent().DarkMode) { dm.Activate(); // Needs a lot more work before its ready, for example custom components uses Draw and does not respect coloring. _cefBrowserHandler.SetDarkMode(settingsService.GetPersistent().DarkMode); } Logger.Debug("UI initialization complete"); }