Esempio n. 1
0
        private void MainForm_Shown(object sender, EventArgs e)
        {
            _simulator.RenderFrame += GameViewRenderFrame;

            var libPath = "./assets/fmj.lib";

            Text = $"{nameof(RPGSimulator)} - {Utilities.GetGameName(libPath)}";

            var options = new SimulatorOptions()
            {
                LibPath = libPath,
                KeyMap  = new Dictionary <int, int>()
                {
                    { (int)Keys.Enter, SimulatorKeys.KEY_ENTER },
                    { (int)Keys.Space, SimulatorKeys.KEY_ENTER },
                    { (int)Keys.Escape, SimulatorKeys.KEY_CANCEL },
                    { (int)Keys.Q, SimulatorKeys.KEY_PAGEUP },
                    { (int)Keys.PageUp, SimulatorKeys.KEY_PAGEUP },
                    { (int)Keys.W, SimulatorKeys.KEY_PAGEDOWN },
                    { (int)Keys.PageDown, SimulatorKeys.KEY_PAGEDOWN },
                },
            };

            _simulator.Start(options);
            GetNewGraphics();
        }
Esempio n. 2
0
        /**
         * Handles the target migration change event.
         */
        public static void TargetMigrationChangeHandler()
        {
            SimulatorOption simOption;

            if (!ignoreTargetMigrationChange)
            {
                MigrationComboFunctions.FillTargetMigrationComboOptions();

                simOption = SimulatorOptions.GetOptionBySelectedItem(MainForm.GetMigrateTargetCombo());
                SettingsHandler.SetSetting("migrationTarget", simOption.GetValue().ToString());
            }

            simOption = SimulatorOptions.GetOptionBySelectedItem(MainForm.GetMigrateTargetCombo());
            selectedTargetSimulator = simOption;
        }
Esempio n. 3
0
        /**
         * Handles the main form's load functionality.
         */
        public static void OnLoadHandler()
        {
            CloseIfAlreadyRunning();

            MigrationComboFunctions.FillSourceMigrationComboOptions();
            MigrationComboFunctions.FillTargetMigrationComboOptions();

            //If the settings exist, we initialize the selected options from the settings
            string migrationSourceVal = SettingsHandler.GetSetting("migrationSource");
            string migrationTargetVal = SettingsHandler.GetSetting("migrationTarget");

            if (!migrationSourceVal.Equals(""))
            {
                SimulatorOptions.SetSelectedOptionByVal(MainForm.GetMigrateSourceCombo(), Int32.Parse(migrationSourceVal));
            }

            if (!migrationTargetVal.Equals(""))
            {
                SimulatorOptions.SetSelectedOptionByVal(MainForm.GetMigrateTargetCombo(), Int32.Parse(migrationTargetVal));
            }

            string isStarted = SettingsHandler.GetSetting("started");
            string autoStart = SettingsHandler.GetSetting("autoStart");

            //Initializes the listeners if the auto start option is available and the migration is in started mode.
            if (isStarted.Equals("1") && autoStart.Equals("1"))
            {
                startMigrateButton.Text = STOP_MIGRATION_TEXT;

                DisableMigrationCombos();
                FileListeners.InitStaticListeners();
            }
            else
            {
                SettingsHandler.SetSetting("started", "0");
                FilesHandler.RestoreSourceConfigFiles(GetSelectedSourceSimulator()); //Restores the source config files if exist
            }

            InitializeDefaultSettings();
        }
Esempio n. 4
0
        private void Start(object parameter)
        {
            List <Frame> frames = new List <Frame>();

            for (int i = 0; i < PacketSizeViewModel.GetSize(); i++)
            {
                frames.Add(DataGenerator.GenerateFrame(FrameSizeViewModel.GetSize(),
                                                       FrameChecksumViewModel.SelectedChecksumType, FrameChecksumViewModel.GetChecksumSize()));
            }

            Packet packet = DataGenerator.GeneratePacket(frames,
                                                         PacketChecksumViewModel.SelectedChecksumType, PacketChecksumViewModel.GetChecksumSize());

            ErrorNumbers errorNumbers = new ErrorNumbers
            {
                SizeType    = ErrorsSizeViewModel.SizeType,
                FixedSize   = ErrorsSizeViewModel.FixedSize,
                RandomEnd   = ErrorsSizeViewModel.RandomEnd,
                RandomStart = ErrorsSizeViewModel.RandomStart
            };

            SimulatorOptions options = new SimulatorOptions
            {
                Packet             = packet,
                DurationModel      = DurationViewModel,
                ErrorGenerator     = ErrorGeneratorFactory.Create(ErrorsViewModel.ErrorPositionType, errorNumbers),
                FaultyFramesNumber = ErrorsViewModel.LimitFaultyFrames ? ErrorsViewModel.FrameNumber : 0,
                FrameChecksumType  = FrameChecksumViewModel.SelectedChecksumType,
                PacketChecksumType = PacketChecksumViewModel.SelectedChecksumType
            };

            Simulator       simulator       = new Simulator(options);
            SimulatorWindow simulatorWindow = new SimulatorWindow(simulator);

            simulatorWindow.ShowDialog();
        }
Esempio n. 5
0
        /**
         * Reverts all changes according to the history file.
         */
        public static bool RevertChanges()
        {
            FileListeners.RemoveListeners();

            List <string> history = GetHistory();

            history.Reverse();
            List <string> newHistory = new List <string>(history);

            foreach (string item in history)
            {
                if (!IsValidHistoryRow(item))
                {
                    newHistory.Remove(item);

                    continue;
                }

                string[]        itemData = item.Split(',');
                int             itemType = Int32.Parse(itemData[0]);
                int             simOptionVal;
                SimulatorOption simOption;

                switch (itemType)
                {
                case 1:
                    //Revert registry changes.
                    simOptionVal = Int32.Parse(itemData[1]);
                    simOption    = SimulatorOptions.GetOptionByVal(simOptionVal);

                    if (simOption != null)
                    {
                        bool deleteKey     = itemData.Length < 4 || itemData[3].Equals("") || itemData[3].Equals("0");
                        int  registryIndex = Int32.Parse(itemData[2]);
                        int  counter       = 0;

                        foreach (string registryPath in simOption.GetRegistryPaths())
                        {
                            if (registryIndex != counter)
                            {
                                counter++;
                                continue;
                            }

                            if (deleteKey)
                            {
                                RegistryInterface.DeleteRegistryKey(registryPath);
                            }
                            else
                            {
                                string sourcePath = itemData[3];

                                RegistryInterface.SetRegistryValue(registryPath, sourcePath, true);
                            }

                            counter++;
                        }
                    }

                    newHistory.Remove(item);

                    break;

                case 2:
                    //Delete the fake FSX executable file.
                    simOption = MainFormHandler.GetSelectedTargetSimulator();
                    FilesHandler.DeleteFakeFsxExecutable(simOption.GetSimPath());
                    newHistory.Remove(item);

                    break;

                case 3:
                    //Restore the config files from the migrationBackup folder and delete the file from the backup folder.
                    simOptionVal = Int32.Parse(itemData[1]);
                    simOption    = SimulatorOptions.GetOptionByVal(simOptionVal);

                    FilesHandler.RestoreSourceConfigFiles(simOption);

                    newHistory.Remove(item);

                    break;
                }
            }

            //Sets the history file content.
            SetHistory(newHistory);

            return(true);
        }