public MainWindow() { // 启动 string[] pargs = Environment.GetCommandLineArgs(); baseDir = System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); if (pargs.Length > 1) { if (pargs[1] != "--baseDir") { MessageBox.Show("不支持的启动参数!", "初始化警告", MessageBoxButton.OK, MessageBoxImage.Warning); } else { baseDir = pargs[2]; } } // 准备数据对象 encodingQueue = new EncodingQueue(); presetcollection = PresetCollection.Load(baseDir); // 初始化界面 InitializeComponent(); config = new Config(); presetSelecter.ItemsSource = presetcollection.Presets; }
public static void Save(PresetCollection item, string baseDir) { var cfgFilepath = Path.Combine(baseDir, "presets.cfg"); FileStream fs = new FileStream(cfgFilepath, FileMode.Create); BinaryFormatter b = new BinaryFormatter(); b.Serialize(fs, item); fs.Close(); }
private void presetSelecter_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (windowIsLoaded) { presetcollection.ActiveIndex = presetSelecter.SelectedIndex; PresetCollection.Save(presetcollection, baseDir); } if (presetcollection.ActiveIndex >= 0 && presetcollection.ActiveIndex < presetcollection.Presets.Count) { ApplyPresetItem(presetcollection.Presets[presetcollection.ActiveIndex]); } }
public static PresetCollection Load(string baseDir) { var cfgFilepath = Path.Combine(baseDir, "presets.cfg"); var c = new PresetCollection(); try { FileStream fs = new FileStream(cfgFilepath, FileMode.Open, FileAccess.Read, FileShare.Read); BinaryFormatter b = new BinaryFormatter(); c = b.Deserialize(fs) as PresetCollection; } catch { } return(c); }
private void addPreset_Click(object sender, RoutedEventArgs e) { var inputDialog = new InputDialog(); if (inputDialog.ShowDialog() == true) { var presetname = inputDialog.PresetName; if (presetname != "") { if (presetcollection.Presets.Any(s => s.Name == presetname)) { MessageBox.Show("无法建立具有相同的名称的预设: " + presetname); return; } presetcollection.Presets.Add(Preset.GetPresentPreset(this, presetname)); presetcollection.ActiveIndex = presetcollection.Presets.Count - 1; presetSelecter.SelectedIndex = presetcollection.ActiveIndex; PresetCollection.Save(presetcollection, baseDir); } } }