コード例 #1
0
 private static void Apply(CustomPresetEntryBase entry, string destination, string name)
 {
     if (entry.IsActuallyEnabled() && entry.Filename != null)
     {
         Logging.Debug($"Applying {name} preset {entry.Filename}…");
         if (File.Exists(entry.Filename))
         {
             File.Copy(entry.Filename, destination, true);
         }
         else
         {
             NonfatalError.NotifyBackground($"Can’t load {name} preset", $"File “{entry.Name}” is missing.");
         }
     }
 }
コード例 #2
0
        private static IDisposable Apply(CustomPresetEntryBase entry, IUserPresetable presetable, string name, bool updateIfNeeded)
        {
            if (entry.IsActuallyEnabled() && entry.Filename != null)
            {
                Logging.Debug($"Applying {name} preset {entry.Filename}…");
                if (File.Exists(entry.Filename))
                {
                    var data = File.ReadAllText(entry.Filename);
                    if (updateIfNeeded && SettingsHolder.Drive.PresetsPerModeAutoUpdate)
                    {
                        presetable.ImportFromPresetData(data);
                        return(new ActionAsDisposable(() => {
                            try {
                                var newData = presetable.ExportToPresetData();
                                if (newData != data)
                                {
                                    File.WriteAllText(entry.Filename, newData);
                                    Logging.Debug($"Preset {name} updated");
                                }
                            } catch (Exception e) {
                                NonfatalError.NotifyBackground("Can’t update preset", e);
                            }
                        }));
                    }
                    else
                    {
                        presetable.ImportFromPresetData(data);
                    }
                }
                else
                {
                    NonfatalError.NotifyBackground($"Can’t load {name} preset", $"File “{entry.Name}” is missing.");
                }
            }

            return(null);
        }