コード例 #1
0
ファイル: Settings.cs プロジェクト: LazyBone152/XV2-Tools
        private void LoadSettings()
        {
            //if (CurrentApp == Application.NotSet) throw new InvalidOperationException("SettingsManager.LoadSettings: CurrentApp has not been set.");

#if DEBUG
            //In release build, rely on the try/catch instead
            if (!File.Exists(GetSetingsPath()))
            {
                Settings = new Settings();

                Settings.InitSettings();

                SaveSettings();
                UpdateEepkToolInterlop();
                return;
            }
#endif


#if !DEBUG
            try
            {
#endif
            //Try to load the settings
            var oldSettings = Settings;
            var settings    = Settings.Load(GetSetingsPath());
            settings.InitSettings();
            settings.ValidateSettings();

            Settings = settings;
            SettingsReloaded?.Invoke(oldSettings, new EventArgs());
#if !DEBUG
        }
        catch
        {
            //If it fails, create a new instance and save it to disk.
            Settings = new Settings();

            Settings.InitSettings();

            SaveSettings();
        }
#endif

            UpdateEepkToolInterlop();
        }
コード例 #2
0
        private static async void SettingsFileChanged(object sender, FileSystemEventArgs e)
        {
            if (e.FullPath == ConfigurationFile)
            {
                if (reloadEventCancellation != null)
                {
                    reloadEventCancellation.Cancel();
                    reloadEventCancellation.Dispose();
                }

                reloadEventCancellation = new CancellationTokenSource();
                try
                {
                    await Task.Delay(SettingsWatcherTimeout, reloadEventCancellation.Token);
                    await Load();

                    SettingsReloaded?.Invoke(null, new EventArgs());
                }
                catch (TaskCanceledException) { }
            }
        }