/// <summary> /// Import Glow config.ini file /// </summary> public static void ImportConfig(MainWindow mainwindow, ViewModel vm) { try { List <string> listFailedImports = new List <string>(); // Start INI File Read ConfigureWindow.INIFile inif = null; // ------------------------- // Check if config.ini file exists // ------------------------- if (File.Exists(Paths.configINIFile)) { inif = new ConfigureWindow.INIFile(Paths.configINIFile); // ------------------------- // Main Window // ------------------------- //Window Position Top double?top = Double.Parse(inif.Read("Main Window", "Window_Position_Top")); if (top != null) { mainwindow.Top = Convert.ToDouble(inif.Read("Main Window", "Window_Position_Top")); } // Window Position Left double?left = Double.Parse(inif.Read("Main Window", "Window_Position_Left")); if (left != null) { mainwindow.Left = Convert.ToDouble(inif.Read("Main Window", "Window_Position_Left")); } // Window Maximized if (Convert.ToBoolean(inif.Read("Main Window", "WindowState_Maximized").ToLower()) == true) { mainwindow.WindowState = WindowState.Maximized; } else { mainwindow.WindowState = WindowState.Normal; } // Window Width double?width = Double.Parse(inif.Read("Main Window", "Window_Width")); if (width != null) { mainwindow.Width = Convert.ToDouble(inif.Read("Main Window", "Window_Width")); } // Window Height double?height = Double.Parse(inif.Read("Main Window", "Window_Height")); if (height != null) { mainwindow.Height = Convert.ToDouble(inif.Read("Main Window", "Window_Height")); } // Profiles Selected Item Path //vm.Profiles_SelectedItem = inif.Read("Main Window", "Profiles_SelectedItem"); // ------------------------- // Configure Window // ------------------------- // mpv Path vm.mpvPath_Text = inif.Read("Configure Window", "mpvPath_Text"); // mpv Config Path vm.mpvConfigPath_Text = inif.Read("Configure Window", "mpvConfigPath_Text"); // Profiles Path vm.ProfilesPath_Text = inif.Read("Configure Window", "ProfilesPath_Text"); // Theme string theme = inif.Read("Configure Window", "Theme_SelectedItem"); if (vm.Theme_Items.Contains(theme)) { vm.Theme_SelectedItem = theme; } //else // listFailedImports.Add("Configure Window: Theme"); // Update Auto Check vm.UpdateAutoCheck_IsChecked = Convert.ToBoolean(inif.Read("Configure Window", "UpdateAutoCheck_IsChecked").ToLower()); } // ------------------------- // Profile ini file does not exist // ------------------------- else if (!File.Exists(Paths.configINIFile)) { MessageBox.Show("Profile does not exist.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } // -------------------------------------------------- // Failed Imports // -------------------------------------------------- //if (listFailedImports.Count > 0 && listFailedImports != null) //{ // failedImportMessage = string.Join(Environment.NewLine, listFailedImports); // // Detect which screen we're on // var allScreens = System.Windows.Forms.Screen.AllScreens.ToList(); // var thisScreen = allScreens.SingleOrDefault(s => mainwindow.Left >= s.WorkingArea.Left && mainwindow.Left < s.WorkingArea.Right); // // Start Window // FailedImportWindow failedimportwindow = new FailedImportWindow(); // // Position Relative to MainWindow // failedimportwindow.Left = Math.Max((mainwindow.Left + (mainwindow.Width - failedimportwindow.Width) / 2), thisScreen.WorkingArea.Left); // failedimportwindow.Top = Math.Max((mainwindow.Top + (mainwindow.Height - failedimportwindow.Height) / 2), thisScreen.WorkingArea.Top); // // Open Window // failedimportwindow.Show(); //} } // Error Loading config.ini // catch { // Delete config.ini and Restart // Check if config.ini Exists if (File.Exists(Paths.configINIFile)) { // Yes/No Dialog Confirmation // MessageBoxResult result = MessageBox.Show( "Could not load config.ini. \n\nDelete config and reload defaults?", "Error", MessageBoxButton.YesNo, MessageBoxImage.Error); switch (result) { // Create case MessageBoxResult.Yes: File.Delete(Paths.configINIFile); // Reload Control Defaults LoadDefaults(mainwindow, vm); // Restart Program Process.Start(Application.ResourceAssembly.Location); Application.Current.Shutdown(); break; // Use Default case MessageBoxResult.No: // Force Shutdown System.Windows.Forms.Application.ExitThread(); Environment.Exit(0); return; } } // If config.ini Not Found else { MessageBox.Show("No Previous Config File Found.", "Notice", MessageBoxButton.OK, MessageBoxImage.Information); return; } } }
/// <summary> /// Export Glow config.ini /// </summary> public static void ExportConfig(MainWindow mainwindow, ViewModel vm) { // Check if Directory Exists if (!Directory.Exists(Paths.configINIDir)) { // Yes/No Dialog Confirmation // MessageBoxResult resultExport = MessageBox.Show("Config Folder does not exist. Automatically create it?", "Directory Not Found", MessageBoxButton.YesNo, MessageBoxImage.Information); switch (resultExport) { // Create case MessageBoxResult.Yes: try { Directory.CreateDirectory(Paths.configINIDir); } catch { MessageBox.Show("Could not create Config folder. May require Administrator privileges.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } break; // Use Default case MessageBoxResult.No: break; } } // Save config.ini file if directory exists else if (Directory.Exists(Paths.configINIDir)) { // Start INI File Write ConfigureWindow.INIFile inif = new ConfigureWindow.INIFile(Paths.configINIFile); // ------------------------- // Main Window // ------------------------- // Window Position Top inif.Write("Main Window", "Window_Position_Top", Convert.ToString(mainwindow.Top)); // Window Position Left inif.Write("Main Window", "Window_Position_Left", Convert.ToString(mainwindow.Left)); // Window Width inif.Write("Main Window", "Window_Width", Convert.ToString(mainwindow.Width)); // Window Height inif.Write("Main Window", "Window_Height", Convert.ToString(mainwindow.Height)); // Window Maximized if (mainwindow.WindowState == WindowState.Maximized) { inif.Write("Main Window", "WindowState_Maximized", "true"); } else { inif.Write("Main Window", "WindowState_Maximized", "false"); } // Profiles Selected Item inif.Write("Main Window", "Profiles_SelectedItem", vm.Profiles_SelectedItem); // ------------------------- // Configure Window // ------------------------- // mpv Path inif.Write("Configure Window", "mpvPath_Text", vm.mpvPath_Text); // mpv Config Path inif.Write("Configure Window", "mpvConfigPath_Text", vm.mpvConfigPath_Text); // Profiles Path inif.Write("Configure Window", "ProfilesPath_Text", vm.ProfilesPath_Text); // Theme inif.Write("Configure Window", "Theme_SelectedItem", vm.Theme_SelectedItem); // Update Auto Check inif.Write("Configure Window", "UpdateAutoCheck_IsChecked", Convert.ToString(vm.UpdateAutoCheck_IsChecked).ToLower()); } }