Ejemplo n.º 1
0
//private void StartInjector()
//{


//    // Start looking for GD processes!
//    _registerWindowDelegate = CustomWndProc;
//    _window = new RegisterWindow("GDIAWindowClass", _registerWindowDelegate);

//    // This prevents a implicit cast to new ProgressChangedEventHandler(func), which would hit the GC and before being used from another thread
//    // Same happens when shutting down, fix unknown
//    _injectorCallbackDelegate = InjectorCallback;

//    var hasMods = _searchWindow.ModSelectionHandler.HasMods;
//#if DEBUG
//    hasMods = false; // TODO TODO TODO TODO
//#endif
//    // CBA dealing with this.
//    InstalootSettingType instaloot = (InstalootSettingType)Properties.Settings.Default.InstalootSetting;
//    string dllname = (!hasMods && instaloot == InstalootSettingType.Enabled) ? "ItemAssistantHook-exp.dll" : "ItemAssistantHook.dll";
//    Logger.Debug($"Using {dllname} as the default hook due to HasMods: {hasMods}, Instaloot setting: {instaloot}");

//    _injector = new InjectionHelper(new BackgroundWorker(), _injectorCallbackDelegate, false, "Grim Dawn", string.Empty, dllname);
//}

//void TransferItem(object ignored, EventArgs args) {

//            if (InvokeRequired) {
//                Invoke((MethodInvoker)delegate {
//                    _transferController.TransferItem(ignored, args);
//                });
//            }
//            else {
//                _transferController.TransferItem(ignored, args);
//            }
//        }

//private void GlobalSettings_StashStatusChanged(object sender, EventArgs e)
//{

//    if (InvokeRequired)
//    {
//        Invoke((MethodInvoker)delegate { GlobalSettings_StashStatusChanged(sender, e); });
//        return;
//    }

//    switch (GlobalSettings.StashStatus)
//    {
//        case StashAvailability.OPEN:
//            tsStashStatus.ForeColor = Color.FromArgb(255, 192, 0, 0);
//            tsStashStatus.Text = GlobalSettings.Language.GetTag("iatag_stash_open");
//            break;
//        case StashAvailability.CRAFTING:
//            tsStashStatus.ForeColor = Color.FromArgb(255, 192, 0, 0);
//            tsStashStatus.Text = GlobalSettings.Language.GetTag("iatag_stash_crafting");
//            break;
//        case StashAvailability.CLOSED:
//            tsStashStatus.ForeColor = Color.FromArgb(255, 0, 142, 0);
//            tsStashStatus.Text = GlobalSettings.Language.GetTag("iatag_stash_closed");
//            break;
//        case StashAvailability.ERROR:
//            tsStashStatus.ForeColor = Color.FromArgb(255, 192, 0, 0);
//            tsStashStatus.Text = GlobalSettings.Language.GetTag("iatag_stash_error");
//            break;
//        case StashAvailability.UNKNOWN:
//            tsStashStatus.ForeColor = Color.FromArgb(255, 192, 0, 0);
//            tsStashStatus.Text = GlobalSettings.Language.GetTag("iatag_stash_unknown");
//            break;
//        case StashAvailability.SORTED:
//            tsStashStatus.ForeColor = Color.FromArgb(255, 192, 0, 0);
//            tsStashStatus.Text = GlobalSettings.Language.GetTag("iatag_stash_sorted");
//            break;
//        default:
//            tsStashStatus.ForeColor = Color.FromArgb(255, 192, 0, 0);
//            tsStashStatus.Text = GlobalSettings.Language.GetTag("iatag_stash_") + GlobalSettings.StashStatus;
//            break;

//    }
//}

        #region Tray and Menu

/// <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;
                        if (BackupNagScreen.ShouldNag)
                        {
                            var b = new BackupNagScreen();
                            b.ShowDialog();
                            if (b.UserWantsBackups)
                            {
                                tabControl1.SelectedTab = tabPageBackups;
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                Logger.Warn(ex.Message);
                Logger.Warn(ex.StackTrace);
            }

            _lastTimeNotMinimized = DateTime.Now;
        }
Ejemplo n.º 2
0
//private void CheckForUpdates()
//{
//    if (GetTickCount64() > 5 * 60 * 1000 && (DateTime.Now - _lastAutomaticUpdateCheck).TotalHours > 36)
//    {
//        AutoUpdater.LetUserSelectRemindLater = true;
//        AutoUpdater.RemindLaterTimeSpan = RemindLaterFormat.Days;
//        AutoUpdater.RemindLaterAt = 7;
//        AutoUpdater.Start(UPDATE_XML);

//        _lastAutomaticUpdateCheck = DateTime.Now;
//        Logger.Info("Checking for updates..");
//    }
//}

//private void TimerTickLookForGrimDawn(object sender, EventArgs e)
//{
//    System.Windows.Forms.Timer timer = sender as System.Windows.Forms.Timer;
//    if (Thread.CurrentThread.Name == null)
//        Thread.CurrentThread.Name = "DetectGrimDawnTimer";

//    string gdPath = GrimDawnDetector.GetGrimLocation();
//    if (!string.IsNullOrEmpty(gdPath) && Directory.Exists(gdPath))
//    {
//        timer?.Stop();

//        // Attempt to force a database update
//        foreach (Control c in modsPanel.Controls)
//        {
//            ModsDatabaseConfig config = c as ModsDatabaseConfig;
//            if (config != null)
//            {
//                config.ForceDatabaseUpdate(gdPath, true);
//                break;
//            }
//        }

//        Logger.InfoFormat("Found Grim Dawn at {0}", gdPath);
//    }
//}

/// <summary>
/// We've looted some items, so make sure the listview is up to date!
/// Otherwise people freak out.
///
/// The first ~1700 users did not notice at all, but past that seems its the end of days if items don't appear immediately.
/// </summary>
///
//private void ListviewUpdateTrigger() {
//            _searchWindow?.UpdateListviewDelayed();
//        }

//        private void DatabaseLoadedTrigger() {
//            _searchWindow.UpdateInterface();
//            _searchWindow?.UpdateListviewDelayed();
//        }



        private void MainWindow_Load(object sender, EventArgs e)
        {
            if (Thread.CurrentThread.Name == null)
            {
                Thread.CurrentThread.Name = "UI";
            }


            //ExceptionReporter.EnableLogUnhandledOnThread();
            SizeChanged += OnMinimizeWindow;

            buttonDevTools.Visible = Debugger.IsAttached;


            //_stashManager = new StashManager(_playerItemDao, _databaseItemStatDao);
            //if (!_stashManager.StartMonitorStashfile(SetFeedback, ListviewUpdateTrigger)) {
            //    MessageBox.Show("Ooops!\nIt seems you are synchronizing your saves to steam cloud..\nThis tool is unfortunately not compatible.\n");
            //    Process.Start("http://www.grimdawn.com/forums/showthread.php?t=20752");

            //    if (!Debugger.IsAttached)
            //        Close();

            //}

            //ItemHtmlWriter.Write(new List<PlayerHeldItem>());

            // Chicken and the egg..
            SearchController searchController = new SearchController(
                _databaseItemDao,
                _playerItemDao,
                _databaseItemStatDao,
                _itemSkillDao,
                _buddyItemDao
                //_stashManager
                );

            _cefBrowserHandler.InitializeChromium(searchController.JsBind, Browser_IsBrowserInitializedChanged);
            searchController.Browser = _cefBrowserHandler;
            //searchController.JsBind.OnTransfer += TransferItem;
            searchController.JsBind.OnClipboard += SetItemsClipboard;

            //// Load the grim database
            //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 addAndShow = UIHelper.AddAndShow;


            // Create the tab contents
            _buddySettingsWindow = new BuddySettings(delegate(bool b) { BuddySyncEnabled = b; },
                                                     _buddyItemDao,
                                                     _buddySubscriptionDao
                                                     );

            addAndShow(_buddySettingsWindow, buddyPanel);

            //var backupSettings = new BackupSettings(EnableOnlineBackups, _playerItemDao);
            //tabControl1.Selected += ((s, ev) => {
            //    if (ev.TabPage == tabPageBackups)
            //        backupSettings?.BackupSettings_GotFocus();
            //});
            //addAndShow(backupSettings, backupPanel);
            //addAndShow(new ModsDatabaseConfig(DatabaseLoadedTrigger, _databaseSettingDao, _arzParser, _playerItemDao), modsPanel);
            addAndShow(new HelpTab(), panelHelp);
            addAndShow(new LoggingWindow(), panelLogging);


            _searchWindow = new SearchWindow(_cefBrowserHandler.BrowserControl, SetFeedback, _playerItemDao, searchController, _databaseItemDao);
            addAndShow(_searchWindow, searchPanel);


            //addAndShow(
            //    new SettingsWindow(_tooltipHelper,
            //        ListviewUpdateTrigger,
            //        _databaseSettingDao,
            //        _databaseItemDao,
            //        _playerItemDao,
            //        _arzParser,
            //        _searchWindow.ModSelectionHandler.GetAvailableModSelection()
            //        _stashManager
            //    ),
            //    settingsPanel);


            //new StashTabPicker(_stashManager.NumStashTabs).SaveStashSettingsToRegistry();

#if !DEBUG
            ThreadPool.QueueUserWorkItem(m => ExceptionReporter.ReportUsage());
            CheckForUpdates();
#endif

            int min  = 1000 * 60;
            int hour = 60 * min;
            _timerReportUsage = new Timer();
            _timerReportUsage.Start();
            _timerReportUsage.Elapsed += (a1, a2) => {
                if (Thread.CurrentThread.Name == null)
                {
                    Thread.CurrentThread.Name = "ReportUsageThread";
                }
                //ReportUsage();
            };
            _timerReportUsage.Interval  = 12 * hour;
            _timerReportUsage.AutoReset = true;
            _timerReportUsage.Start();


            //Shown += (_, __) => { StartInjector(); };

            //settingsController.Data.budd
            BuddySyncEnabled = (bool)Settings.Default.BuddySyncEnabled;

            // Start the backup task
            _backupBackgroundTask = new BackgroundTask(new CloudBackup(_playerItemDao));



            LocalizationLoader.ApplyLanguage(Controls, GlobalSettings.Language);
            EasterEgg.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 = StashManager.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());
            //_messageProcessors.Add(new StashStatusHandler());
            //_messageProcessors.Add(new ItemReceivedProcessor(_searchWindow, _stashManager, _playerItemDao));
            //_messageProcessors.Add(new ItemInjectCallbackProcessor(_searchWindow.UpdateListviewDelayed, _playerItemDao));
            //_messageProcessors.Add(new ItemSpawnedProcessor());
            //_messageProcessors.Add(new CloudDetectorProcessor(SetFeedback));
            //_messageProcessors.Add(new GenericErrorHandler());
            //messageProcessors.Add(new LogMessageProcessor());
#if DEBUG
            //messageProcessors.Add(new DebugMessageProcessor());
#endif

            //GlobalSettings.StashStatusChanged += GlobalSettings_StashStatusChanged;

            //_transferController = new ItemTransferController(
            //    _cefBrowserHandler,
            //    SetFeedback,
            //    SetTooltipAtmouse,
            //    _settingsController,
            //    _searchWindow,
            //    _dynamicPacker,
            //    _playerItemDao,
            //    _stashManager,
            //    new ItemStatService(_databaseItemStatDao, _itemSkillDao)
            //    );
            Application.AddMessageFilter(new MousewheelMessageFilter());


            //{
            //    var b = !string.IsNullOrEmpty(Settings.Default.OnlineBackupToken) && Settings.Default.OnlineBackupVerified;
            //    EnableOnlineBackups(b);
            //}



            if (BackupNagScreen.ShouldNag)
            {
                var b = new BackupNagScreen();
                b.ShowDialog();
                if (b.UserWantsBackups)
                {
                    tabControl1.SelectedTab = tabPageBackups;
                }
            }

            var titleTag = GlobalSettings.Language.GetTag("iatag_ui_itemassistant");
            if (!string.IsNullOrEmpty(titleTag))
            {
                this.Text += $" - {titleTag}";
            }
        }