Beispiel #1
0
 private void InitialiseConfigFile()
 {
     _snapshotsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), FolderName);
     if (!Directory.Exists(_snapshotsPath))
     {
         Directory.CreateDirectory(_snapshotsPath);
     }
     ConfigSettings settings;
     _settingsPath = Path.Combine(_snapshotsPath, "setting.json");
     if (!File.Exists(_settingsPath))
     {
         _snapshotsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), FolderName);
         _saveFrequency = 60;
         Directory.CreateDirectory(_snapshotsPath);
         settings = new ConfigSettings
         {
             SnapshotPath = _snapshotsPath,
             SaveFrequency = _saveFrequency
         };
     }
     else
     {
         settings = LoadSettings();
         _snapshotsPath = settings.SnapshotPath;
         _saveFrequency = settings.SaveFrequency;
         if (_saveFrequency == 0)
         {
             settings.SaveFrequency = 60;
             _saveFrequency = 60;
         }
         if (!Directory.Exists(_snapshotsPath))
         {
             Directory.CreateDirectory(_snapshotsPath);
         }
     }
     UpdateSettings(settings);
     UpdateFormSettings(settings);
 }
Beispiel #2
0
 private void UpdateSettings(ConfigSettings config)
 {
     var raw = JsonConvert.SerializeObject(config);
     File.WriteAllText(_settingsPath, raw);
 }
Beispiel #3
0
 private void UpdateSettingsFromForm()
 {
     _snapshotsPath = txtSavePath.Text;
     _saveFrequency = int.Parse(txtSaveFrequency.Text);
     var config = new ConfigSettings
     {
         SaveFrequency = _saveFrequency,
         SnapshotPath = _snapshotsPath
     };
     UpdateSettings(config);
     timer1.Interval = config.SaveFrequency * 1000;
 }
Beispiel #4
0
 private void UpdateFormSettings(ConfigSettings config)
 {
     txtSavePath.Text = config.SnapshotPath;
     txtSaveFrequency.Text = config.SaveFrequency.ToString();
     if (config.SaveFrequency == 0) return;
     timer1.Interval = config.SaveFrequency * 1000;
 }