private void OnUserPresetableChanged(IUserPresetable oldValue, IUserPresetable newValue) { if (oldValue != null) { Instances.GetList(oldValue.PresetableKey).Remove(this); } Instances.GetList(newValue.PresetableKey).Add(this); if (_presetable != null) { PresetsManager.Instance.Watcher(_presetable.PresetableCategory).Update -= Presets_Update; _presetable.Changed -= Presetable_Changed; } _presetable = newValue; SetValue(PreviewProviderPropertyKey, _presetable as IPresetsPreviewProvider); if (_presetable == null) { return; } PresetsManager.Instance.Watcher(_presetable.PresetableCategory).Update += Presets_Update; _presetable.Changed += Presetable_Changed; UpdateSavedPresets(); SetChanged(); }
private static ArgumentHandleResult ProcessSharedSettingsPreset(IUserPresetable presetable, SharedEntry shared, byte[] data) { var result = ShowDialog(shared); switch (result) { case Choise.Save: case Choise.ApplyAndSave: var filename = FileUtils.EnsureUnique(Path.Combine( PresetsManager.Instance.GetDirectory(presetable.PresetableKey), @"Loaded", shared.GetFileName())); Directory.CreateDirectory(Path.GetDirectoryName(filename) ?? ""); File.WriteAllBytes(filename, data); if (result == Choise.ApplyAndSave) { UserPresetsControl.LoadPreset(presetable.PresetableKey, filename); } return(ArgumentHandleResult.SuccessfulShow); case Choise.Apply: presetable.ImportFromPresetData(data.ToUtf8String()); return(ArgumentHandleResult.SuccessfulShow); default: return(ArgumentHandleResult.Failed); } }
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); }
private static void Apply(CustomPresetEntryBase entry, IUserPresetable presetable, string name) { Apply(entry, presetable, name, false); }
private static IDisposable ApplyWithUpdate(CustomPresetEntryBase entry, IUserPresetable presetable, string name) { return(Apply(entry, presetable, name, true)); }
public PresetSelection(IUserPresetable parent, string key) { _parent = parent; _key = key; }
private void OnUserPresetableChanged(IUserPresetable oldValue, IUserPresetable newValue) { if (oldValue != null) { Instances.Remove(oldValue.PresetableKey); } Instances.RemoveDeadReferences(); if (newValue != null) { Instances[newValue.PresetableKey] = new WeakReference<UserPresetsControl>(this); } if (_presetable != null) { PresetsManager.Instance.Watcher(_presetable.PresetableCategory).Update -= Presets_Update; _presetable.Changed -= Presetable_Changed; } _presetable = newValue; SetValue(PreviewProviderPropertyKey, _presetable as IPresetsPreviewProvider); if (_presetable == null) return; PresetsManager.Instance.Watcher(_presetable.PresetableCategory).Update += Presets_Update; _presetable.Changed += Presetable_Changed; UpdateSavedPresets(); SetChanged(); }