/// <summary> /// Deserialize from a binary file into a SaveSettings object. /// </summary> /// <param name="file">Path to the file that holds the settings.</param> /// <param name="obj">SaveSettings object to load the object state into.</param> /// <remarks>That is to say, loads settings</remarks> internal static SaveSettings Deserialize(string file) { SaveSettings ret; if (File.Exists(file)) { try { FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read); BinaryFormatter bf = new BinaryFormatter(); ret = (SaveSettings)bf.Deserialize(fs); fs.Close(); } catch (Exception e) { // Access, security and whatnot exceptions ret = new SaveSettings(); } } else { // File doesn't exist (first application start etc.) ret = new SaveSettings(); } return(ret); }
public MainWindow() { InitializeComponent(); string[] cmdParams = System.Environment.GetCommandLineArgs(); // Check if application is already running string instance = System.Diagnostics.Process.GetCurrentProcess().ProcessName; System.Diagnostics.Process[] instances = System.Diagnostics.Process.GetProcessesByName(instance); if (instances.Length > 1) { // This is a subsequent instance of the application. Send command line // parameters to the main process. if (cmdParams.Length >= 2) { OpenFilePipe.PassArgument(cmdParams[1].Replace("\"", "")); } // Exit App.Current.Shutdown(); } else { // This is the first instance of the application. Open a pipe. OpenFilePipe.CreatePipe(); OpenFilePipe.ArgumentPassedEvent += new EventHandler <ArgumentPassedArgs>(OpenFilePipe_ArgumentPassed); } // Deserialize from a previous session FileInfo info = new FileInfo(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)); settings = SaveSettings.Deserialize(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Blpc.conf"); // Some custom CommandBindings for menus this.CommandBindings.Add(new CommandBinding(About, CommandBinding_Executed)); this.CommandBindings.Add(new CommandBinding(AssociateFile, CommandBinding_Executed)); menuAbout.Command = About; menuExtension.Command = AssociateFile; // Menu DataBindings menuMips.DataContext = settings; foreach (MenuItem m in menuFormat.Items) { m.DataContext = settings; } foreach (MenuItem m in menuResize.Items) { m.DataContext = settings; } foreach (MenuItem m in menuDxtQuality.Items) { m.DataContext = settings; } foreach (var m in menuRaw1Quality.Items) { if (m.GetType() == typeof(MenuItem)) { ((MenuItem)m).DataContext = settings; } } // Set file association menu (un)checked try { var keyBlp = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Classes\.blp"); menuExtension.IsChecked = ((string)keyBlp.GetValue("")) == "Blpc"; } catch (Exception) { }; // Open file from command line (file association, drag & drop on .exe) if (cmdParams.Length >= 2) { if ((new FileInfo(cmdParams[1].Replace("\"", "")).Exists)) { Open(cmdParams[1].Replace("\"", "")); } } // Cursor resources curHand = ((TextBlock)App.Current.Resources["curHand"]).Cursor; curHandGrab = ((TextBlock)App.Current.Resources["curHandGrab"]).Cursor; curZoomIn = ((TextBlock)App.Current.Resources["curZoomIn"]).Cursor; curZoomOut = ((TextBlock)App.Current.Resources["curZoomOut"]).Cursor; scrollViewer.Cursor = curHand; }