public static MemoryStream PrepareImage(Workflow wf, ZScreenOptions zo, Image img, out EImageFormat imageFormat,
            bool bConvert = true, bool bTargetFileSize = true)
        {
            imageFormat = wf.ImageFormat;
            MemoryStream stream = img.SaveImage(wf, wf.ImageFormat);

            if (bConvert)
            {
                long streamLength = stream.Length / 1024;
                int sizeLimit = zo.ConfigImageEffects.ImageSizeLimit * 1024;

                if (wf.ImageFormat != wf.ImageFormat2 && sizeLimit > 0 && stream.Length > sizeLimit)
                {
                    stream = img.SaveImage(wf, wf.ImageFormat2);

                    if (bTargetFileSize)
                    {
                        DebugHelper.WriteLine(ConvertImageString(streamLength, wf, stream));
                        while (stream.Length > sizeLimit && wf.ImageFormat2 == EImageFormat.JPEG)
                        {
                            if (wf.ImageJpegQuality == FreeImageJpegQualityType.JPEG_QUALITYBAD)
                            {
                                break;
                            }

                            wf.ImageJpegQuality = wf.ImageJpegQuality - 1;
                            stream = img.SaveImage(wf, EImageFormat.JPEG);
                            DebugHelper.WriteLine(ConvertImageString(streamLength, wf, stream));
                        }
                    }

                    imageFormat = wf.ImageFormat2;
                }
            }

            stream.Position = 0;

            return stream;
        }
        public static MemoryStream PrepareImage(Workflow wf, ZScreenOptions zo, Image img, out EImageFormat imageFormat,
                                                bool bConvert = true, bool bTargetFileSize = true)
        {
            imageFormat = wf.ImageFormat;
            MemoryStream stream = img.SaveImage(wf, wf.ImageFormat);

            if (bConvert)
            {
                long streamLength = stream.Length / 1024;
                int  sizeLimit    = zo.ConfigImageEffects.ImageSizeLimit * 1024;

                if (wf.ImageFormat != wf.ImageFormat2 && sizeLimit > 0 && stream.Length > sizeLimit)
                {
                    stream = img.SaveImage(wf, wf.ImageFormat2);

                    if (bTargetFileSize)
                    {
                        DebugHelper.WriteLine(ConvertImageString(streamLength, wf, stream));
                        while (stream.Length > sizeLimit && wf.ImageFormat2 == EImageFormat.JPEG)
                        {
                            if (wf.ImageJpegQuality == FreeImageJpegQualityType.JPEG_QUALITYBAD)
                            {
                                break;
                            }

                            wf.ImageJpegQuality = wf.ImageJpegQuality - 1;
                            stream = img.SaveImage(wf, EImageFormat.JPEG);
                            DebugHelper.WriteLine(ConvertImageString(streamLength, wf, stream));
                        }
                    }

                    imageFormat = wf.ImageFormat2;
                }
            }

            stream.Position = 0;

            return(stream);
        }
        public static void LoadSettings(string fp = null)
        {
            LoggerTimer timer = EngineLogger.StartTimer("LoadSettings started");

            Thread threadOptions = new Thread(() =>
            {
                Engine.ConfigOptions = ZScreenOptions.Read(OptionsFilePath);
            });

            Thread threadMainFormSettings = new Thread(() =>
            {
                if (string.IsNullOrEmpty(fp))
                {
                    Engine.ConfigUI = XMLSettings.Read();
                }
                else
                {
                    Engine.ConfigUI = XMLSettings.Read(fp);
                }
            });

            Thread threadWorkflow = new Thread(() =>
            {
                Engine.ConfigWorkflow = Workflow.Read(WorkflowConfigPath);
            });

            Thread threadUploadersConfig = new Thread(() =>
            {
                Engine.ConfigUploaders = UploadersConfig.Load(UploadersConfigPath);
            });

            Thread threadGt = new Thread(() =>
            {
                Engine.ConfigGT = GoogleTranslatorConfig.Read(GoogleTranslateConfigPath);
            });

            threadOptions.Start();
            threadMainFormSettings.Start();
            threadGt.Start();
            threadWorkflow.Start();
            threadUploadersConfig.Start();

            threadMainFormSettings.Join();
            threadWorkflow.Join();
            threadUploadersConfig.Join();

            timer.WriteLineTime("LoadSettings finished");

            Engine.InitializeFiles();

            // Use Configuration Wizard Settings if applied
            if (RunConfig)
            {
                Engine.ConfigUI.ConfOutputs = Engine.ConfigApp.AppOutputs;
                Engine.ConfigUI.ConfClipboardContent = Engine.ConfigApp.ClipboardContent;
                Engine.ConfigUI.MyImageUploaders = Engine.ConfigApp.ImageUploaders;
                Engine.ConfigUI.MyTextUploaders = Engine.ConfigApp.TextUploaders;
                Engine.ConfigUI.MyFileUploaders = Engine.ConfigApp.FileUploaders;
                Engine.ConfigUI.MyURLShorteners = Engine.ConfigApp.LinkUploaders;
            }

            // Portable then we don't need PreferSystemFolders to be true
            if (IsPortable)
            {
                Engine.ConfigApp.PreferSystemFolders = false;
            }
        }
        public ZScreenOptionsUI(ZScreenOptions config)
        {
            InitializeComponent();

            this.Config = config;

            // General

            chkStartWin.Checked = RegistryHelper.CheckStartWithWindows();
            chkShellExt.Checked = RegistryHelper.CheckShellContextMenu();

            chkOpenMainWindow.Checked = Engine.ConfigApp.ShowMainWindow;

            if (Loader.MainForm.IsReady && !Engine.ConfigApp.ShowInTaskbar)
            {
                this.chkWindows7TaskbarIntegration.Checked = false; // Windows 7 Taskbar Integration cannot work without showing in Taskbar
            }

            cbShowHelpBalloonTips.Checked = Engine.ConfigUI.ShowHelpBalloonTips;
            cbAutoSaveSettings.Checked = Config.AutoSaveSettings;
            chkWindows7TaskbarIntegration.Checked = TaskbarManager.IsPlatformSupported && Engine.ConfigApp.Windows7TaskbarIntegration;
            chkWindows7TaskbarIntegration.Enabled = TaskbarManager.IsPlatformSupported;

            if (cboCloseButtonAction.Items.Count == 0)
            {
                cboMinimizeButtonAction.Items.AddRange(typeof(WindowButtonAction).GetEnumDescriptions());
            }
            if (cboCloseButtonAction.Items.Count == 0)
            {
                cboCloseButtonAction.Items.AddRange(typeof(WindowButtonAction).GetEnumDescriptions());
            }
            cboCloseButtonAction.SelectedIndex = (int)Engine.ConfigApp.WindowButtonActionClose;
            cboMinimizeButtonAction.SelectedIndex = (int)Engine.ConfigApp.WindowButtonActionMinimize;

            chkCheckUpdates.Checked = Engine.ConfigUI.CheckUpdates;
            if (cboReleaseChannel.Items.Count == 0)
            {
                cboReleaseChannel.Items.AddRange(typeof(ReleaseChannelType).GetEnumDescriptions());
                cboReleaseChannel.SelectedIndex = (int)Engine.ConfigUI.ReleaseChannel;
            }

            // Workflow
            nudFlashIconCount.Value = Config.FlashTrayCount;
            chkCaptureFallback.Checked = Config.CaptureEntireScreenOnError;
            chkShowPopup.Checked = Config.ShowBalloonTip;
            chkBalloonTipOpenLink.Checked = Config.BalloonTipOpenLink;
            cbShowUploadDuration.Checked = Config.ShowUploadDuration;
            cbCompleteSound.Checked = Config.CompleteSound;
            chkTwitterEnable.Checked = Config.TwitterEnabled;

            // Directory Indexer
            pgIndexer.SelectedObject = config.IndexerConfig;

            // Effects
            pgWorkflowImageEffects.SelectedObject = Config.ConfigImageEffects;

            // Paths
            ConfigurePaths();

            // History
            nudHistoryMaxItems.Value = Config.HistoryMaxNumber;
            cbHistorySave.Checked = Config.HistorySave;
        }
        public static void LoadSettings(string fp = null)
        {
            LoggerTimer timer = EngineLogger.StartTimer("LoadSettings started");

            Thread threadOptions = new Thread(() =>
            {
                Engine.ConfigOptions = ZScreenOptions.Read(OptionsFilePath);
            });

            Thread threadMainFormSettings = new Thread(() =>
            {
                if (string.IsNullOrEmpty(fp))
                {
                    Engine.ConfigUI = XMLSettings.Read();
                }
                else
                {
                    Engine.ConfigUI = XMLSettings.Read(fp);
                }
            });

            Thread threadWorkflow = new Thread(() =>
            {
                Engine.ConfigWorkflow = Workflow.Read(WorkflowConfigPath);
            });

            Thread threadUploadersConfig = new Thread(() =>
            {
                Engine.ConfigUploaders = UploadersConfig.Load(UploadersConfigPath);
            });

            Thread threadGt = new Thread(() =>
            {
                Engine.ConfigGT = GoogleTranslatorConfig.Read(GoogleTranslateConfigPath);
            });

            threadOptions.Start();
            threadMainFormSettings.Start();
            threadGt.Start();
            threadWorkflow.Start();
            threadUploadersConfig.Start();

            threadMainFormSettings.Join();
            threadWorkflow.Join();
            threadUploadersConfig.Join();

            timer.WriteLineTime("LoadSettings finished");

            Engine.InitializeFiles();

            // Use Configuration Wizard Settings if applied
            if (RunConfig)
            {
                Engine.ConfigUI.ConfOutputs          = Engine.ConfigApp.AppOutputs;
                Engine.ConfigUI.ConfClipboardContent = Engine.ConfigApp.ClipboardContent;
                Engine.ConfigUI.MyImageUploaders     = Engine.ConfigApp.ImageUploaders;
                Engine.ConfigUI.MyTextUploaders      = Engine.ConfigApp.TextUploaders;
                Engine.ConfigUI.MyFileUploaders      = Engine.ConfigApp.FileUploaders;
                Engine.ConfigUI.MyURLShorteners      = Engine.ConfigApp.LinkUploaders;
            }

            // Portable then we don't need PreferSystemFolders to be true
            if (IsPortable)
            {
                Engine.ConfigApp.PreferSystemFolders = false;
            }
        }