예제 #1
0
        public void OpenSettings(Type startTab)
        {
            if (!FormManager.TryBringToFront <FormSettings>())
            {
                bool prevEnableUpdateCheck = Config.EnableUpdateCheck;

                FormSettings form = new FormSettings(this, plugins, updates, analytics, startTab);

                form.FormClosed += (sender, args) => {
                    if (!prevEnableUpdateCheck && Config.EnableUpdateCheck)
                    {
                        Config.DismissedUpdate = null;
                        Config.Save();

                        updates.Check(true);
                    }

                    if (!Config.EnableTrayHighlight)
                    {
                        trayIcon.HasNotifications = false;
                    }

                    if (Config.AllowDataCollection)
                    {
                        if (analytics == null)
                        {
                            analytics = new AnalyticsManager(this, plugins, Program.AnalyticsFilePath);
                        }
                    }
                    else if (analytics != null)
                    {
                        analytics.Dispose();
                        analytics = null;
                    }

                    BrowserCache.RefreshTimer();

                    if (form.ShouldReloadBrowser)
                    {
                        FormManager.TryFind <FormPlugins>()?.Close();
                        plugins.Reload(); // also reloads the browser
                    }
                    else
                    {
                        browser.UpdateProperties();
                    }

                    notification.RequiresResize = true;
                    form.Dispose();
                };

                AnalyticsFile.OpenOptions.Trigger();
                ShowChildForm(form);
            }
        }
예제 #2
0
파일: Program.cs 프로젝트: chylex/TweetDuck
            public void Launch(ResourceCache resourceCache, PluginManager pluginManager)
            {
                string storagePath = App.StoragePath;

                BrowserCache.RefreshTimer();

                CefSharpSettings.WcfEnabled = false;
                CefSharpSettings.SubprocessExitIfParentProcessClosed = false;

                CefSettings settings = new CefSettings {
                    UserAgent             = BrowserUtils.UserAgentChrome,
                    BrowserSubprocessPath = Path.Combine(App.ProgramPath, BrandName + ".Browser.exe"),
                    CachePath             = storagePath,
                    UserDataPath          = Path.Combine(storagePath, CefDataFolder),
                    LogFile = Path.Combine(storagePath, ConsoleLogFile),
                                        #if !DEBUG
                    LogSeverity = Arguments.HasFlag(Arguments.ArgLogging) ? LogSeverity.Info : LogSeverity.Disable
                                        #endif
                };

                CefSchemeHandlerFactory.Register(settings, new TweetDuckSchemeHandler(resourceCache));
                CefSchemeHandlerFactory.Register(settings, new PluginSchemeHandler(resourceCache, pluginManager));

                CefUtils.ParseCommandLineArguments(Config.User.CustomCefArgs).ToDictionary(settings.CefCommandLineArgs);
                BrowserUtils.SetupCefArgs(settings.CefCommandLineArgs);

                Cef.Initialize(settings, false, new BrowserProcessHandler());

                Win.Application.ApplicationExit += (sender, args) => ExitCleanup();
                var updateCheckClient = new UpdateCheckClient(Path.Combine(storagePath, InstallerFolder));
                var mainForm          = new FormBrowser(resourceCache, pluginManager, updateCheckClient, lockManager.WindowRestoreMessage);

                Win.Application.Run(mainForm);

                if (mainForm.UpdateInstaller != null)
                {
                    ExitCleanup();

                    if (mainForm.UpdateInstaller.Launch())
                    {
                        Win.Application.Exit();
                    }
                    else
                    {
                        RestartWithArgsInternal(Arguments.GetCurrentClean());
                    }
                }
            }
예제 #3
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Cef.EnableHighDPISupport();

            WindowRestoreMessage = NativeMethods.RegisterWindowMessage("TweetDuckRestore");

            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;
                }
            }

            Config.LoadAll();

            if (Arguments.HasFlag(Arguments.ArgImportCookies))
            {
                ProfileManager.ImportCookies();
            }
            else if (Arguments.HasFlag(Arguments.ArgDeleteCookies))
            {
                ProfileManager.DeleteCookies();
            }

            if (Arguments.HasFlag(Arguments.ArgUpdated))
            {
                WindowsUtils.TryDeleteFolderWhenAble(InstallerPath, 8000);
                BrowserCache.TryClearNow();
            }

            BrowserCache.RefreshTimer();

            CefSharpSettings.WcfEnabled = false;
            CefSharpSettings.LegacyJavascriptBindingEnabled = true;

            CefSettings settings = new CefSettings {
                UserAgent             = BrowserUtils.UserAgentChrome,
                BrowserSubprocessPath = BrandName + ".Browser.exe",
                CachePath             = StoragePath,
                UserDataPath          = CefDataPath,
                LogFile = ConsoleLogFilePath,
                #if !DEBUG
                LogSeverity = Arguments.HasFlag(Arguments.ArgLogging) ? LogSeverity.Info : LogSeverity.Disable
                #endif
            };

            CommandLineArgs.ReadCefArguments(Config.User.CustomCefArgs).ToDictionary(settings.CefCommandLineArgs);
            BrowserUtils.SetupCefArgs(settings.CefCommandLineArgs);

            Cef.Initialize(settings, false, new BrowserProcessHandler());

            Application.ApplicationExit += (sender, args) => ExitCleanup();

            FormBrowser mainForm = new FormBrowser();

            Application.Run(mainForm);

            if (mainForm.UpdateInstallerPath != null)
            {
                ExitCleanup();

                // ProgramPath has a trailing backslash
                string updaterArgs = "/SP- /SILENT /FORCECLOSEAPPLICATIONS /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());
                }
            }
        }
예제 #4
0
        private static void Main()
        {
            SetupWinForms();
            Cef.EnableHighDPISupport();

            WindowRestoreMessage = NativeMethods.RegisterWindowMessage("TweetDuckRestore");

            if (!FileUtils.CheckFolderWritePermission(StoragePath))
            {
                FormMessage.Warning("Permission Error", "TweetDuck does not have write permissions to the storage folder: " + StoragePath, FormMessage.OK);
                return;
            }

            if (!LockManager.Lock(Arguments.HasFlag(Arguments.ArgRestart)))
            {
                return;
            }

            Config.LoadAll();

            if (Arguments.HasFlag(Arguments.ArgImportCookies))
            {
                ProfileManager.ImportCookies();
            }
            else if (Arguments.HasFlag(Arguments.ArgDeleteCookies))
            {
                ProfileManager.DeleteCookies();
            }

            if (Arguments.HasFlag(Arguments.ArgUpdated))
            {
                WindowsUtils.TryDeleteFolderWhenAble(InstallerPath, 8000);
                WindowsUtils.TryDeleteFolderWhenAble(Path.Combine(StoragePath, "Service Worker"), 4000);
                BrowserCache.TryClearNow();
            }

            try{
                ResourceRequestHandlerBase.LoadResourceRewriteRules(Arguments.GetValue(Arguments.ArgFreeze));
            }catch (Exception e) {
                FormMessage.Error("Resource Freeze", "Error parsing resource rewrite rules: " + e.Message, FormMessage.OK);
                return;
            }

            BrowserCache.RefreshTimer();

            CefSharpSettings.WcfEnabled = false;
            CefSharpSettings.LegacyJavascriptBindingEnabled = true;

            CefSettings settings = new CefSettings {
                UserAgent             = BrowserUtils.UserAgentChrome,
                BrowserSubprocessPath = Path.Combine(ProgramPath, BrandName + ".Browser.exe"),
                CachePath             = StoragePath,
                UserDataPath          = CefDataPath,
                LogFile = ConsoleLogFilePath,
                #if !DEBUG
                LogSeverity = Arguments.HasFlag(Arguments.ArgLogging) ? LogSeverity.Info : LogSeverity.Disable
                #endif
            };

            var pluginScheme = new PluginSchemeFactory();

            settings.RegisterScheme(new CefCustomScheme {
                SchemeName           = PluginSchemeFactory.Name,
                IsStandard           = false,
                IsSecure             = true,
                IsCorsEnabled        = true,
                IsCSPBypassing       = true,
                SchemeHandlerFactory = pluginScheme
            });

            CommandLineArgs.ReadCefArguments(Config.User.CustomCefArgs).ToDictionary(settings.CefCommandLineArgs);
            BrowserUtils.SetupCefArgs(settings.CefCommandLineArgs);

            Cef.Initialize(settings, false, new BrowserProcessHandler());

            Win.Application.ApplicationExit += (sender, args) => ExitCleanup();

            FormBrowser mainForm = new FormBrowser(pluginScheme);

            Resources.Initialize(mainForm);
            Win.Application.Run(mainForm);

            if (mainForm.UpdateInstaller != null)
            {
                ExitCleanup();

                if (mainForm.UpdateInstaller.Launch())
                {
                    Win.Application.Exit();
                }
                else
                {
                    RestartWithArgsInternal(Arguments.GetCurrentClean());
                }
            }
        }