示例#1
0
        private void StartButton_Clicked(object sender, EventArgs e)
        {
            GC.Collect();

            UserInterface.ResetAll();

            UserInterface.SetProgramStatus("Scanning");
            Logger.Info("Starting scan");

            if (Directory.Exists(OutputPath_TextBox.Text) || Directory.CreateDirectory(OutputPath_TextBox.Text).Exists)
            {
                if (running)
                {
                    Logger.Debug("Already running");
                    return;
                }
                running = true;

                HotkeyManager.Current.AddOrReplace("Stop", Keys.Enter, Hotkey_Pressed);
                Logger.Info("Hotkey registered");
                var settings = Properties.Settings.Default;
                var options  = $"\n\tWeapons:\t\t\t {settings.ScanWeapons}\n" +
                               $"\tArtifacts:\t\t\t {settings.ScanArtifacts}\n" +
                               $"\tCharacters:\t\t\t {settings.ScanCharacters}\n" +
                               $"\tDev Items:\t\t\t {settings.ScanCharDevItems}\n" +
                               $"\tMaterials:\t\t\t {settings.ScanMaterials}\n" +
                               $"\tMin Weapon Rarity:\t {settings.MinimumWeaponRarity}\n" +
                               $"\tMin Artifact Rarity: {settings.MinimumArtifactRarity}\n" +
                               $"\tDelay:\t\t\t\t {settings.ScannerDelay}";

                scannerThread = new Thread(() =>
                {
                    try
                    {
                        // Get Screen Location and Size
                        Navigation.Initialize();

                        List <Size> sizes = new List <Size>
                        {
                            new Size(16, 9),
                            new Size(8, 5),
                        };

                        if (!sizes.Contains(Navigation.GetAspectRatio()))
                        {
                            throw new NotImplementedException($"{Navigation.GetSize().Width}x{Navigation.GetSize().Height} is an unsupported resolution.");
                        }

                        if (Navigation.GetSize() != Navigation.CaptureWindow().Size)
                        {
                            throw new FormatException("Window size and screenshot size mismatch. Please make sure the game is not in a fullscreen mode.");
                        }

                        data = new InventoryKamera();

                        // Add navigation delay
                        Navigation.SetDelay(ScannerDelayValue(Delay));

                        Logger.Info("Scan settings: {0}", options);

                        // The Data object of json object
                        data.GatherData();

                        // Covert to GOOD
                        GOOD good = new GOOD(data);
                        Logger.Info("Data converted to GOOD");

                        // Make Json File
                        good.WriteToJSON(OutputPath_TextBox.Text);
                        Logger.Info("Exported data");

                        UserInterface.SetProgramStatus("Finished");
                    }
                    catch (ThreadAbortException)
                    {
                        // Workers can get stuck if the thread is aborted or an exception is raised
                        if (!(data is null))
                        {
                            data.StopImageProcessorWorkers();
                        }
                        UserInterface.SetProgramStatus("Scan stopped");
                    }
                    catch (NotImplementedException ex)
                    {
                        UserInterface.AddError(ex.Message);
                    }
                    catch (Exception ex)
                    {
                        // Workers can get stuck if the thread is aborted or an exception is raised
                        if (!(data is null))
                        {
                            data.StopImageProcessorWorkers();
                        }
                        UserInterface.AddError(ex.ToString());
                        UserInterface.SetProgramStatus("Scan aborted", ok: false);
                    }
                    finally
                    {
                        ResetUI();
                        running = false;
                        Logger.Info("Scanner stopped");
                    }
                })
                {
                    IsBackground = true
                };
                scannerThread.Start();
            }
            else
            {
                if (string.IsNullOrWhiteSpace(OutputPath_TextBox.Text))
                {
                    UserInterface.AddError("Please set an output directory");
                }
                else
                {
                    UserInterface.AddError($"{OutputPath_TextBox.Text} is not a valid directory");
                }
            }
        }