Beispiel #1
0
        private void AddPresetButton_Click(object sender, RoutedEventArgs e)
        {
            Application application = Application.Current as Application;
            string      presetName  = Properties.Resources.DefaultPresetName;
            int         index       = 1;

            while (application.Settings.ConversionPresets.Any(match => match.Name == presetName))
            {
                index++;
                presetName = $"{Properties.Resources.DefaultPresetName} ({index})";
            }

            ConversionPreset newPreset = null;

            if (this.SelectedPreset != null)
            {
                newPreset = new ConversionPreset(presetName, this.SelectedPreset);
            }
            else
            {
                newPreset = new ConversionPreset(presetName, OutputType.Mkv, new string[0]);
            }

            application.Settings.ConversionPresets.Add(newPreset);
            this.SelectedPreset = newPreset;
            this.PresetNameTextBox.Focus();
            this.PresetNameTextBox.SelectAll();
        }
Beispiel #2
0
        private static void MigrateConversionPresetToCurrentVersion(ConversionPreset preset, int settingsVersion)
        {
            if (settingsVersion <= 2)
            {
                // Migrate video encoding speed.
                string videoEncodingSpeed = preset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoEncodingSpeed);
                if (videoEncodingSpeed != null)
                {
                    VideoEncodingSpeed encodingSpeed;
                    if (!Enum.TryParse(videoEncodingSpeed, out encodingSpeed))
                    {
                        switch (videoEncodingSpeed)
                        {
                        case "Ultra Fast":
                            preset.SetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoEncodingSpeed, VideoEncodingSpeed.UltraFast.ToString());
                            break;

                        case "Super Fast":
                            preset.SetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoEncodingSpeed, VideoEncodingSpeed.SuperFast.ToString());
                            break;

                        case "Very Fast":
                            preset.SetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoEncodingSpeed, VideoEncodingSpeed.VeryFast.ToString());
                            break;

                        case "Very Slow":
                            preset.SetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoEncodingSpeed, VideoEncodingSpeed.VerySlow.ToString());
                            break;
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public ConversionPreset(string name, ConversionPreset source, params string[] additionalInputTypes)
        {
            this.Name       = name;
            this.OutputType = source.outputType;
            List <string> inputTypeList = new List <string>();

            if (source.inputTypes != null)
            {
                inputTypeList.AddRange(source.inputTypes);
            }

            if (additionalInputTypes != null)
            {
                inputTypeList.AddRange(additionalInputTypes);
            }

            this.InputTypes = inputTypeList;

            this.outputFileNameTemplate = source.OutputFileNameTemplate;

            foreach (KeyValuePair <string, string> conversionSetting in source.settings)
            {
                this.SetSettingsValue(conversionSetting.Key, conversionSetting.Value);
            }
        }
Beispiel #4
0
        private void MovePresetDownButton_Click(object sender, RoutedEventArgs e)
        {
            ConversionPreset presetToMove = this.SelectedPreset;

            if (presetToMove == null)
            {
                return;
            }

            int indexOfSelectedPreset    = this.settings.ConversionPresets.IndexOf(presetToMove);
            int newIndexOfSelectedPreset = System.Math.Min(this.settings.ConversionPresets.Count - 1, indexOfSelectedPreset + 1);

            this.settings.ConversionPresets.Move(indexOfSelectedPreset, newIndexOfSelectedPreset);
        }
        private static void MigrateConversionPresetToCurrentVersion(ConversionPreset preset, int settingsVersion)
        {
            if (settingsVersion <= 2)
            {
                // Migrate video encoding speed.
                string videoEncodingSpeed = preset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoEncodingSpeed);
                if (videoEncodingSpeed != null)
                {
                    VideoEncodingSpeed encodingSpeed;
                    if (!Enum.TryParse(videoEncodingSpeed, out encodingSpeed))
                    {
                        switch (videoEncodingSpeed)
                        {
                        case "Ultra Fast":
                            preset.SetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoEncodingSpeed, VideoEncodingSpeed.UltraFast.ToString());
                            break;

                        case "Super Fast":
                            preset.SetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoEncodingSpeed, VideoEncodingSpeed.SuperFast.ToString());
                            break;

                        case "Very Fast":
                            preset.SetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoEncodingSpeed, VideoEncodingSpeed.VeryFast.ToString());
                            break;

                        case "Very Slow":
                            preset.SetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoEncodingSpeed, VideoEncodingSpeed.VerySlow.ToString());
                            break;
                        }
                    }
                }
            }

            if (settingsVersion <= 3)
            {
                // Try to fix corrupted settings (GitHub issue #5).
                string scale = preset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.ImageScale);
                if (scale != null)
                {
                    preset.SetSettingsValue(ConversionPreset.ConversionSettingKeys.ImageScale, scale.Replace(',', '.'));
                }

                scale = preset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoScale);
                if (scale != null)
                {
                    preset.SetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoScale, scale.Replace(',', '.'));
                }
            }
        }
Beispiel #6
0
        private Settings Merge(Settings settings)
        {
            if (settings == null)
            {
                return(this);
            }

            for (int index = 0; index < settings.conversionPresets.Count; index++)
            {
                ConversionPreset conversionPreset = settings.conversionPresets[index];
                if (this.conversionPresets.Any(match => match.Name == conversionPreset.Name))
                {
                    continue;
                }

                this.conversionPresets.Add(conversionPreset);
            }

            return(this);
        }
        private void Initialize()
        {
#if BUILD32
            Diagnostics.Debug.Log("File Converter v" + ApplicationVersion.ToString() + " (32 bits)");
#else
            Diagnostics.Debug.Log("File Converter v" + ApplicationVersion.ToString() + " (64 bits)");
#endif

            // Retrieve arguments.
            Debug.Log("Retrieve arguments...");
            string[] args = Environment.GetCommandLineArgs();

#if (DEBUG)
            {
                ////System.Array.Resize(ref args, 5);
                ////args[1] = "--conversion-preset";
                ////args[2] = "To Png";
                ////args[3] = "--verbose";
                ////args[4] = @"D:\Test\images\Mario Big.png";
            }
#endif

            // Log arguments.
            for (int index = 0; index < args.Length; index++)
            {
                string argument = args[index];
                Debug.Log("Arg{0}: {1}", index, argument);
            }

            Debug.Log(string.Empty);

            if (args.Length == 1)
            {
                // Diplay help windows to explain that this application is a context menu extension.
                ApplicationStartHelp applicationStartHelp = new ApplicationStartHelp();
                applicationStartHelp.Show();
                this.HideMainWindow = true;
                return;
            }

            // Parse arguments.
            List <string> filePaths            = new List <string>();
            string        conversionPresetName = null;
            for (int index = 1; index < args.Length; index++)
            {
                string argument = args[index];
                if (string.IsNullOrEmpty(argument))
                {
                    continue;
                }

                if (argument.StartsWith("--"))
                {
                    // This is an optional parameter.
                    string parameterTitle = argument.Substring(2).ToLowerInvariant();

                    switch (parameterTitle)
                    {
                    case "post-install-init":
                        Settings.PostInstallationInitialization();
                        Dispatcher.BeginInvoke((Action)(() => Application.Current.Shutdown()));
                        return;

                    case "version":
                        Console.Write(ApplicationVersion.ToString());
                        Dispatcher.BeginInvoke((Action)(() => Application.Current.Shutdown()));
                        return;

                    case "settings":
                        this.ShowSettings   = true;
                        this.HideMainWindow = true;
                        break;

                    case "apply-settings":
                        Settings.ApplyTemporarySettings();
                        Dispatcher.BeginInvoke((Action)(() => Application.Current.Shutdown()));
                        return;

                    case "conversion-preset":
                        if (index >= args.Length - 1)
                        {
                            Debug.LogError("Invalid format. (code 0x01)");
                            Dispatcher.BeginInvoke((Action)(() => Application.Current.Shutdown()));
                            return;
                        }

                        conversionPresetName = args[index + 1];
                        index++;
                        continue;

                    case "verbose":
                    {
                        this.Verbose = true;
                    }

                    break;

                    default:
                        Debug.LogError("Unknown application argument: '--{0}'.", parameterTitle);
                        return;
                    }
                }
                else
                {
                    filePaths.Add(argument);
                }
            }

            // Load settigns.
            Debug.Log("Load settings...");
            this.Settings = Settings.Load();
            if (this.Settings == null)
            {
                Diagnostics.Debug.LogError("The application will now shutdown. If you want to fix the problem yourself please edit or delete the file: C:\\Users\\UserName\\AppData\\Local\\FileConverter\\Settings.user.xml.");
                Dispatcher.BeginInvoke((Action)(() => Application.Current.Shutdown()));
                return;
            }

            if (this.Settings.MaximumNumberOfSimultaneousConversions <= 0)
            {
                this.Settings.MaximumNumberOfSimultaneousConversions = System.Math.Max(1, Environment.ProcessorCount / 2);
                Diagnostics.Debug.Log("The number of processors on this computer is {0}. Set the default number of conversion threads to {0}", this.Settings.MaximumNumberOfSimultaneousConversions);
            }

            this.numberOfConversionThread = this.Settings.MaximumNumberOfSimultaneousConversions;
            Diagnostics.Debug.Log("Maximum number of conversion threads: {0}", this.numberOfConversionThread);

            // Check upgrade.
            if (this.Settings.CheckUpgradeAtStartup)
            {
#if DEBUG
                Task <UpgradeVersionDescription> task = Upgrade.Helpers.GetLatestVersionDescriptionAsync(this.OnGetLatestVersionDescription);
#else
                long     fileTime           = Registry.GetValue <long>(Registry.Keys.LastUpdateCheckDate);
                DateTime lastUpdateDateTime = DateTime.FromFileTime(fileTime);

                TimeSpan durationSinceLastUpdate = DateTime.Now.Subtract(lastUpdateDateTime);
                if (durationSinceLastUpdate > new TimeSpan(1, 0, 0, 0))
                {
                    Task <UpgradeVersionDescription> task = Upgrade.Helpers.GetLatestVersionDescriptionAsync(this.OnGetLatestVersionDescription);
                }
#endif
            }

            ConversionPreset conversionPreset = null;
            if (!string.IsNullOrEmpty(conversionPresetName))
            {
                conversionPreset = this.Settings.GetPresetFromName(conversionPresetName);
                if (conversionPreset == null)
                {
                    Debug.LogError("Invalid conversion preset '{0}'. (code 0x02)", conversionPresetName);
                    Dispatcher.BeginInvoke((Action)(() => Application.Current.Shutdown()));
                    return;
                }
            }

            if (conversionPreset != null)
            {
                // Create convertion jobs.
                Debug.Log("Create jobs for conversion preset: '{0}'", conversionPreset.Name);
                try
                {
                    for (int index = 0; index < filePaths.Count; index++)
                    {
                        string        inputFilePath = filePaths[index];
                        ConversionJob conversionJob = ConversionJobFactory.Create(conversionPreset, inputFilePath);

                        this.conversionJobs.Add(conversionJob);
                    }
                }
                catch (Exception exception)
                {
                    Debug.LogError(exception.Message);
                    throw;
                }

                this.needToRunConversionThread = true;
            }
        }