private void Application_SessionEnding(object sender, SessionEndingCancelEventArgs e)
        {
            LogWriter.Write(string.Format(
                                "Due to pending Windows {0}, application will try to save the current settings and presets",
                                e.ReasonSessionEnding.ToString()));

            GlobalSettings.TrySaveToFile();

            try
            {
                PresetDataManager.WritePresetDataToFile();
                LogWriter.Write("Presets successfully saved");
            }
            catch (Exception ex)
            {
                LogWriter.Write("Presets saving failed:");
                LogWriter.Write(ex.ToString());
            }

            var splitter = Helpers.SplitterHelper.TryFindSplitter();

            if (splitter != null)
            {
                splitter.Destroy();
            }
        }
Beispiel #2
0
 private void Start()
 {
     debugMod = new Debug_Mod();
     UserInfo = StrategyTopTaskManager.GetLogicManager().UserInfo;
     ButtonManager.setButtonDelegate(Util.CreateEventDelegate(this, "OnPushPreset", null));
     TaskStrategyDebug.isControl = true;
     presetDataManager           = new PresetDataManager();
     NextMemID     = 2;
     ShipParamList = new List <Entity_PresetShip.Param>();
     presetDataManager.GetPresetShipParam("初期艦").MemID = 1;
 }
        private void OnExportPresetsClicked(object sender, RoutedEventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();

            dialog.AddExtension     = true;
            dialog.CheckPathExists  = true;
            dialog.DefaultExt       = "*.xml";
            dialog.DereferenceLinks = true;
            dialog.Filter           = "XML file (*.xml)|*.xml";
            dialog.Title            = "Export presets";
            dialog.ValidateNames    = true;
            Interceptor.Interception.DisableMouseEvents = true;
            var result = dialog.ShowDialog(this);

            Interceptor.Interception.DisableMouseEvents = false;
            if (result != true)
            {
                return;
            }

            var extension = System.IO.Path.GetExtension(dialog.FileName);

            if (extension.ToLower() != ".xml")
            {
                Controls.MessageBox.Show(
                    "You must export presets as xml file!",
                    ApplicationInfo.AppName,
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);

                return;
            }

            try
            {
                PresetDataManager.WritePresetDataToFile(dialog.FileName);
            }
            catch (Exception ex)
            {
                LogWriter.Write(ex.ToString());
                Controls.MessageBox.Show(
                    "Presets export failed! Please refer to " + LogWriter.GetLogFileName + " for details",
                    ApplicationInfo.AppName,
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
            }
        }
        private void Window_Closing(object sender, CancelEventArgs e)
        {
            LogWriter.Write("Application is about to close. Checking for unsaved presets...");

            // checking for unsaved presets
            var unsavedPresets = new List <IPreset>();

            foreach (var preset in PresetDataManager.CurrentPresets)
            {
                if (PresetDataManager.IsPresetChanged(preset))
                {
                    unsavedPresets.Add(preset);
                }
            }

            string message = string.Empty;

            foreach (var preset in unsavedPresets)
            {
                message += string.Format("Preset '{0}'{1}", preset.Name, Environment.NewLine);
            }

            if (message.Length > 0)
            {
                var result = Controls.MessageBox.Show(
                    "Do you want to save the following unsaved presets, before you quit?\r\n\r\n" + message,
                    "You are about to quit " + ApplicationInfo.AppNameVersion,
                    MessageBoxButton.YesNoCancel,
                    MessageBoxImage.Question);

                if (result == MessageBoxResult.Yes)
                {
                    // save the presets
                    PresetDataManager.WritePresetDataToFile();
                }

                e.Cancel = result == MessageBoxResult.Cancel;
            }
        }
        private GameStatus GetStatus()
        {
            if (this.gamePath == null)
            {
                // Serializer is creating empty SlotsData collection
                return(GameStatus.NotSet);
            }

            if (!File.Exists(this.gamePath) || Path.GetExtension(this.gamePath).ToLower() != ".exe")
            {
                return(GameStatus.ExeNotFound);
            }

            if (this.slotsData.Count < 1 || this.slotsData.Count > 4)
            {
                return(GameStatus.InvalidSlotsCount);
            }

            foreach (var slotData in this.slotsData)
            {
                if (slotData.SlotNumber < 1 || slotData.SlotNumber > 4)
                {
                    return(GameStatus.InvalidSlotNumber);
                }

                if (slotData.GamepadUserIndex < 1 || slotData.GamepadUserIndex > 4)
                {
                    return(GameStatus.InvalidGamepadUserIndex);
                }

                var inputDevices = KeyboardSplitter.Managers.InputManager.ConnectedInputDevices;
                if (slotData.KeyboardHardwareId != string.Empty)
                {
                    if (inputDevices.FirstOrDefault(x => x.IsKeyboard && x.HardwareID.ToLower() == slotData.KeyboardHardwareId.ToLower()) == null)
                    {
                        // Keyboard is not connected
                        return(GameStatus.KeyboardMissing);
                    }
                }

                if (slotData.MouseHardwareId != string.Empty)
                {
                    if (inputDevices.FirstOrDefault(x => !x.IsKeyboard && x.HardwareID.ToLower() == slotData.MouseHardwareId.ToLower()) == null)
                    {
                        // Mouse is not connected
                        return(GameStatus.MouseMissing);
                    }
                }

                if (!PresetDataManager.IsProtectedPreset(slotData.PresetName))
                {
                    if (PresetDataManager.CurrentPresets.FirstOrDefault(x => x.Name.ToLower() == slotData.PresetName) == null)
                    {
                        // Preset unavailable
                        return(GameStatus.PresetMissing);
                    }
                }
            }

            return(GameStatus.OK);
        }
 private void DeleteGlobalPreset(Preset preset)
 {
     PresetDataManager.DeletePreset(preset);
 }
 private void AddGlobalPreset(Preset preset)
 {
     PresetDataManager.AddNewPreset(preset);
 }
 private bool IsProtectedPreset(string presetName)
 {
     return(PresetDataManager.IsProtectedPreset(presetName));
 }
        private void OnImportPresetsClicked(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.AddExtension     = true;
            dialog.CheckFileExists  = true;
            dialog.CheckPathExists  = true;
            dialog.DefaultExt       = "*.xml";
            dialog.DereferenceLinks = true;
            dialog.Filter           = "XML file (*.xml)|*.xml";
            dialog.Multiselect      = false;
            dialog.Title            = "Choose presets file to import";
            dialog.ValidateNames    = true;
            Interceptor.Interception.DisableMouseEvents = true;
            var result = dialog.ShowDialog(this);

            Interceptor.Interception.DisableMouseEvents = false;
            if (result != true)
            {
                return;
            }

            var extension = System.IO.Path.GetExtension(dialog.FileName);

            if (extension.ToLower() != ".xml")
            {
                Controls.MessageBox.Show(
                    "You must provide an xml file!",
                    ApplicationInfo.AppName,
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);

                return;
            }

            List <Preset> presets = new List <Preset>();
            Exception     ex      = null;

            try
            {
                presets = PresetData.Deserialize(dialog.FileName).Presets.ToList();
            }
            catch (Exception currentVersionException)
            {
                ex = currentVersionException;
            }

            if (ex != null)
            {
                ex = null;
                try
                {
                    presets = PresetUpgrader.GetUpgradedPresets(dialog.FileName).ToList();
                }
                catch (Exception oldVersionException)
                {
                    ex = oldVersionException;
                }
            }

            if (ex != null)
            {
                LogWriter.Write(ex.ToString());
                Controls.MessageBox.Show(
                    "Failed to load presets! See " + LogWriter.GetLogFileName + " for more details",
                    ApplicationInfo.AppName,
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);

                return;
            }

            var presetNames     = string.Empty;
            var overwriteString = string.Empty;

            foreach (var preset in presets)
            {
                presetNames += Environment.NewLine + preset.Name;
                var duplicate = PresetDataManager.FindPreset(preset.Name);
                if (duplicate != null)
                {
                    presetNames    += " [Will be overwritten]";
                    overwriteString = "/overwrite";
                }
            }

            var message = string.Format(
                "Are you sure that you want to add{0} the following presets?{1}{2}",
                overwriteString,
                Environment.NewLine,
                presetNames);

            var confirm = Controls.MessageBox.Show(
                message,
                ApplicationInfo.AppName,
                MessageBoxButton.YesNo,
                MessageBoxImage.Question);

            if (confirm == MessageBoxResult.Yes)
            {
                foreach (var preset in presets)
                {
                    var duplicateToDelete = PresetDataManager.FindPreset(preset.Name);
                    if (duplicateToDelete != null)
                    {
                        PresetDataManager.DeletePreset(duplicateToDelete);
                    }

                    PresetDataManager.AddNewPreset(preset);
                }
            }
        }
Beispiel #10
0
        private void Window_Closing(object sender, CancelEventArgs e)
        {
            LogWriter.Write("Application is about to close. Checking for unsaved presets...");

            // Checking for unsaved presets
            var unsavedPresets = new List <IPreset>();

            foreach (var preset in PresetDataManager.CurrentPresets)
            {
                if (PresetDataManager.IsPresetChanged(preset))
                {
                    unsavedPresets.Add(preset);
                }
            }

            string message = string.Empty;

            foreach (var preset in unsavedPresets)
            {
                message += string.Format("Preset '{0}'{1}", preset.Name, Environment.NewLine);
            }

            if (message.Length > 0)
            {
                var result = Controls.MessageBox.Show(
                    "Do you want to save the following unsaved presets, before you quit?\r\n\r\n" + message,
                    "You are about to quit " + ApplicationInfo.AppNameVersion,
                    MessageBoxButton.YesNoCancel,
                    MessageBoxImage.Question);

                if (result == MessageBoxResult.Yes)
                {
                    // save the presets
                    PresetDataManager.WritePresetDataToFile();
                }

                e.Cancel = result == MessageBoxResult.Cancel;
            }
            else
            {
                // We may have a deleted preset(s)
                var  xmlPresets = PresetDataManager.ReadPresetDataFromFile();
                bool hasChanges = false;
                foreach (var preset in xmlPresets.Presets)
                {
                    try
                    {
                        if (PresetDataManager.IsPresetChanged(preset))
                        {
                            hasChanges = true;
                        }
                    }
                    catch (InvalidOperationException)
                    {
                        // Preset is deleted
                        hasChanges = true;
                    }
                }

                if (hasChanges)
                {
                    PresetDataManager.WritePresetDataToFile();
                }
            }
        }