Ejemplo n.º 1
0
        /// <summary>
        /// Export axiom.conf
        /// </summary>
        public static void ExportConfig(MainWindow mainwindow, string path)
        {
            // -------------------------
            // Check if Directory Exists
            // -------------------------
            if (!Directory.Exists(path /*configDir*/))
            {
                try
                {
                    // Create Config Directory
                    Directory.CreateDirectory(path /*configDir*/);
                }
                catch
                {
                    MessageBox.Show("Could not create Config folder. May require Administrator privileges.",
                                    "Error",
                                    MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                }

                //// 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(configDir);
                //        }
                //        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 axiom.conf file if directory exists
            // -------------------------
            if (Directory.Exists(path /*configDir*/))
            {
                //MessageBox.Show(path);

                try
                {
                    // Start conf File Write
                    Configure.INIFile conf = new Configure.INIFile(path + "axiom.conf" /*configFile*/);

                    // -------------------------
                    // Main Window
                    // -------------------------
                    // Window Position Top
                    conf.Write("Main Window", "Window_Position_Top", mainwindow.Top.ToString());

                    // Window Position Left
                    conf.Write("Main Window", "Window_Position_Left", mainwindow.Left.ToString());

                    // Window Width
                    conf.Write("Main Window", "Window_Width", mainwindow.Width.ToString());

                    // Window Height
                    conf.Write("Main Window", "Window_Height", mainwindow.Height.ToString());

                    // Window Maximized
                    if (mainwindow.WindowState == WindowState.Maximized)
                    {
                        conf.Write("Main Window", "WindowState_Maximized", "true");
                    }
                    else
                    {
                        conf.Write("Main Window", "WindowState_Maximized", "false");
                    }

                    // CMD Keep Window Open Toggle
                    conf.Write("Main Window", "CMDWindowKeep_IsChecked", VM.MainView.CMDWindowKeep_IsChecked.ToString().ToLower());

                    // Auto Sort Script Toggle
                    conf.Write("Main Window", "AutoSortScript_IsChecked", VM.MainView.AutoSortScript_IsChecked.ToString().ToLower());


                    // --------------------------------------------------
                    // Settings
                    // --------------------------------------------------
                    // Config Path
                    conf.Write("Settings", "ConfigPath_SelectedItem", VM.ConfigureView.ConfigPath_SelectedItem);

                    // Presets
                    conf.Write("Settings", "CustomPresetsPath_Text", VM.ConfigureView.CustomPresetsPath_Text);

                    // FFmpeg
                    conf.Write("Settings", "FFmpegPath_Text", VM.ConfigureView.FFmpegPath_Text);
                    conf.Write("Settings", "FFprobePath_Text", VM.ConfigureView.FFprobePath_Text);
                    conf.Write("Settings", "FFplayPath_Text", VM.ConfigureView.FFplayPath_Text);

                    // Log
                    conf.Write("Settings", "LogCheckBox_IsChecked", VM.ConfigureView.LogCheckBox_IsChecked.ToString().ToLower());
                    conf.Write("Settings", "LogPath_Text", VM.ConfigureView.LogPath_Text);

                    // Threads
                    conf.Write("Settings", "Threads_SelectedItem", VM.ConfigureView.Threads_SelectedItem);

                    // Theme
                    conf.Write("Settings", "Theme_SelectedItem", VM.ConfigureView.Theme_SelectedItem);

                    // Updates
                    conf.Write("Settings", "UpdateAutoCheck_IsChecked", VM.ConfigureView.UpdateAutoCheck_IsChecked.ToString().ToLower());


                    // --------------------------------------------------
                    // User
                    // --------------------------------------------------
                    // Input Previous Path
                    if (!string.IsNullOrEmpty(MainWindow.inputPreviousPath))
                    {
                        if (Directory.Exists(MainWindow.inputPreviousPath))
                        {
                            conf.Write("User", "InputPreviousPath", MainWindow.inputPreviousPath);
                        }
                    }

                    // Output Previous Path
                    if (!string.IsNullOrEmpty(MainWindow.outputPreviousPath))
                    {
                        if (Directory.Exists(MainWindow.outputPreviousPath))
                        {
                            conf.Write("User", "OutputPreviousPath", MainWindow.outputPreviousPath);
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Could not save config file. May require Administrator privileges.",
                                    "Error",
                                    MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///    Import axiom.conf file
        /// </summary>
        public static void ImportConfig(MainWindow mainwindow, ViewModel vm)
        {
            try
            {
                List <string> listFailedImports = new List <string>();

                // Start INI File Read
                Configure.INIFile conf = null;

                // -------------------------
                // Check if axiom.conf file exists in C:\ProgramData\Axiom UI\
                // -------------------------
                if (File.Exists(configFile))
                {
                    conf = new Configure.INIFile(configFile);

                    // Read
                    ReadConfig(mainwindow, vm, conf);
                }

                // -------------------------
                // Check if axiom.conf file exists in App Dir
                // -------------------------
                else if (File.Exists(MainWindow.appDir + "axiom.conf"))
                {
                    conf = new Configure.INIFile(MainWindow.appDir + "axiom.conf");

                    // Read
                    ReadConfig(mainwindow, vm, conf);
                }

                // -------------------------
                // Preset ini file does not exist
                // -------------------------
                else if (!File.Exists(configFile))
                {
                    MessageBox.Show("Confg file axiom.conf does not exist.",
                                    "Error",
                                    MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                }


                // --------------------------------------------------
                // Failed Imports
                // --------------------------------------------------
                if (listFailedImports.Count > 0 && listFailedImports != null)
                {
                    Profiles.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 axiom.conf
            //
            catch
            {
                // Delete axiom.conf and Restart
                // Check if axiom.conf Exists
                if (File.Exists(configFile))
                {
                    // Yes/No Dialog Confirmation
                    //
                    MessageBoxResult result = MessageBox.Show(
                        "Could not load axiom.conf. \n\nDelete config and reload defaults?",
                        "Error",
                        MessageBoxButton.YesNo,
                        MessageBoxImage.Error);
                    switch (result)
                    {
                    // Create
                    case MessageBoxResult.Yes:
                        File.Delete(configFile);

                        // Reload Control Defaults
                        vm.LoadConfigDefaults();
                        vm.LoadControlsDefaults();

                        // 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 axiom.conf Not Found
                else
                {
                    MessageBox.Show("No Previous Config File Found.",
                                    "Notice",
                                    MessageBoxButton.OK,
                                    MessageBoxImage.Information);

                    return;
                }
            }
        }