private static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Cef.EnableHighDPISupport(); WindowRestoreMessage = NativeMethods.RegisterWindowMessage("TweetDuckRestore"); SubProcessMessage = NativeMethods.RegisterWindowMessage("TweetDuckSubProcess"); if (!WindowsUtils.CheckFolderWritePermission(StoragePath)) { FormMessage.Warning("Permission Error", "TweetDuck does not have write permissions to the storage folder: " + StoragePath, FormMessage.OK); return; } if (Arguments.HasFlag(Arguments.ArgRestart)) { LockManager.Result lockResult = LockManager.LockWait(10000); while (lockResult != LockManager.Result.Success) { if (lockResult == LockManager.Result.Fail) { FormMessage.Error("TweetDuck Has Failed :(", "An unknown error occurred accessing the data folder. Please, make sure TweetDuck is not already running. If the problem persists, try restarting your system.", FormMessage.OK); return; } else if (!FormMessage.Warning("TweetDuck Cannot Restart", "TweetDuck is taking too long to close.", FormMessage.Retry, FormMessage.Exit)) { return; } lockResult = LockManager.LockWait(5000); } } else { LockManager.Result lockResult = LockManager.Lock(); if (lockResult == LockManager.Result.HasProcess) { if (!LockManager.RestoreLockingProcess(2000) && FormMessage.Error("TweetDuck is Already Running", "Another instance of TweetDuck is already running.\nDo you want to close it?", FormMessage.Yes, FormMessage.No)) { if (!LockManager.CloseLockingProcess(10000, 5000)) { FormMessage.Error("TweetDuck Has Failed :(", "Could not close the other process.", FormMessage.OK); return; } lockResult = LockManager.Lock(); } else { return; } } if (lockResult != LockManager.Result.Success) { FormMessage.Error("TweetDuck Has Failed :(", "An unknown error occurred accessing the data folder. Please, make sure TweetDuck is not already running. If the problem persists, try restarting your system.", FormMessage.OK); return; } } UserConfig = UserConfig.Load(UserConfigFilePath); SystemConfig = SystemConfig.Load(SystemConfigFilePath); if (Arguments.HasFlag(Arguments.ArgImportCookies)) { ExportManager.ImportCookies(); } else if (Arguments.HasFlag(Arguments.ArgDeleteCookies)) { ExportManager.DeleteCookies(); } if (Arguments.HasFlag(Arguments.ArgUpdated)) { WindowsUtils.TryDeleteFolderWhenAble(InstallerPath, 8000); } CefSharpSettings.WcfEnabled = false; CefSettings settings = new CefSettings { AcceptLanguageList = BrowserUtils.HeaderAcceptLanguage, UserAgent = BrowserUtils.HeaderUserAgent, Locale = Arguments.GetValue(Arguments.ArgLocale, string.Empty), BrowserSubprocessPath = BrandName + ".Browser.exe", CachePath = StoragePath, LogFile = ConsoleLogFilePath, #if !DEBUG LogSeverity = Arguments.HasFlag(Arguments.ArgLogging) ? LogSeverity.Info : LogSeverity.Disable #endif }; CommandLineArgs.ReadCefArguments(UserConfig.CustomCefArgs).ToDictionary(settings.CefCommandLineArgs); BrowserUtils.SetupCefArgs(settings.CefCommandLineArgs); Cef.Initialize(settings, false, new BrowserProcessHandler()); Application.ApplicationExit += (sender, args) => ExitCleanup(); UpdaterSettings updaterSettings = new UpdaterSettings { AllowPreReleases = Arguments.HasFlag(Arguments.ArgDebugUpdates), DismissedUpdate = UserConfig.DismissedUpdate, InstallerDownloadFolder = InstallerPath }; FormBrowser mainForm = new FormBrowser(updaterSettings); Application.Run(mainForm); if (mainForm.UpdateInstallerPath != null) { ExitCleanup(); // ProgramPath has a trailing backslash string updaterArgs = "/SP- /SILENT /CLOSEAPPLICATIONS /UPDATEPATH=\"" + ProgramPath + "\" /RUNARGS=\"" + Arguments.GetCurrentForInstallerCmd() + "\"" + (IsPortable ? " /PORTABLE=1" : ""); bool runElevated = !IsPortable || !WindowsUtils.CheckFolderWritePermission(ProgramPath); if (WindowsUtils.OpenAssociatedProgram(mainForm.UpdateInstallerPath, updaterArgs, runElevated)) { Application.Exit(); } else { RestartWithArgsInternal(Arguments.GetCurrentClean()); } } }