Example #1
0
        // ReSharper disable once UnusedMember.Local
        // (updates are disabled in Debug configuration to allow for proper debugging)
        private static void installPendingUpdates()
        {
            Directory.CreateDirectory(UpdatesPath); // make sure the directory exists
            var di = new DirectoryInfo(UpdatesPath);

            foreach (var file in di.GetFiles("TogglDesktopInstaller*.exe", SearchOption.TopDirectoryOnly))
            {
                try
                {
                    Utils.DeleteFile(file.FullName);
                }
                catch (Exception e)
                {
                    BugsnagService.NotifyBugsnag(e);
                    Toggl.OnError?.Invoke($"Unable to delete the file: {file.FullName}. Delete this file manually.", false);
                }
            }

            var aboutWindowViewModel = mainWindow.GetWindow <AboutWindow>().ViewModel;

            if (aboutWindowViewModel.InstallPendingUpdate())
            {
                // quit, updater will restart the app
                Environment.Exit(0);
            }
        }
Example #2
0
        private static Action createUpdateAction()
        {
            if (!Directory.Exists(updatePath))
            {
                return(null);
            }

            var di    = new DirectoryInfo(updatePath);
            var files = di.GetFiles("TogglDesktopInstaller*.exe", SearchOption.TopDirectoryOnly);

            if (files.Length > 1)
            {
                Debug("Multiple update installers found. Deleting.");
                foreach (var file in files)
                {
                    try
                    {
                        Utils.DeleteFile(file.FullName);
                    }
                    catch (Exception e)
                    {
                        BugsnagService.NotifyBugsnag(e);
                        Toggl.OnError?.Invoke($"Unable to delete the file: {file.FullName}. Delete this file manually.", false);
                    }
                }
                return(null);
            }

            if (files.Length < 1)
            {
                return(null);
            }

            var installerFullPath = files[0].FullName;

            return(() =>
            {
                Process process;
                try
                {
                    process = Process.Start(installerFullPath, "/S /U");
                }
                catch (Win32Exception e)
                {
                    BugsnagService.NotifyBugsnag(e);
                    Toggl.OnError?.Invoke("Unable to run the installer. Please update manually.", false);
                    return;
                }

                if (process != null && !process.HasExited && process.Id != 0)
                {
                    // Update has started. Quit, installer will restart me.
                    Environment.Exit(0);
                }
                else
                {
                    Toggl.OnError?.Invoke("Unable to run the installer. Please update manually.", false);
                }
            });
        }
Example #3
0
        // ReSharper disable once UnusedMember.Local
        // (updates are disabled in Release_VS configuration to allow for proper debugging)
        private static void installPendingUpdates()
        {
            if (Environment.GetCommandLineArgs().Contains("--updated"))
            {
                // --updated means we've just been silently updated and started by the installer
                // so we just clean up the installer files and continue
                var di = new DirectoryInfo(updatePath);
                foreach (var file in di.GetFiles("TogglDesktopInstaller*.exe", SearchOption.TopDirectoryOnly))
                {
                    try
                    {
                        Utils.DeleteFile(file.FullName);
                    }
                    catch (Exception e)
                    {
                        BugsnagService.NotifyBugsnag(e);
                        Toggl.OnError?.Invoke($"Unable to delete the file: {file.FullName}. Delete this file manually.", false);
                    }
                }

                return;
            }

            var update = createUpdateAction();

            if (update == null)
            {
                return;
            }

            update();
        }
Example #4
0
 private static void OnBeforeStartup()
 {
     Toggl.OnLogin += delegate(bool open, ulong user_id) {
         UserId = user_id;
     };
     BugsnagService.Init();
     singleInstanceManager.BeforeStartup -= OnBeforeStartup;
 }
Example #5
0
        private static void OnBeforeStartup()
        {
            Toggl.OnLogin += delegate(bool open, ulong user_id) {
                UserId = user_id;
            };
            BugsnagService.Init();
#if TOGGL_ALLOW_UPDATE_CHECK
            Toggl.UpdateService.InstallPendingUpdatesOnStartup();
#endif
            DeepLinkProtocolInstaller.InstallProtocol();
            singleInstanceManager.BeforeStartup -= OnBeforeStartup;
        }
Example #6
0
        public static bool ShowNotification(this TaskbarIcon icon, UIElement element, PopupAnimation animation,
                                            TimeSpan?timeout = null)
        {
            try
            {
                icon.ShowCustomBalloon(element, animation, (int?)timeout?.TotalMilliseconds);
            }
            catch (Exception e)
            {
                BugsnagService.NotifyBugsnag(new Exception("Failed to show a custom notification", e));
                return(false);
            }

            return(true);
        }
        private static void DeleteOldUpdates()
        {
            Directory.CreateDirectory(UpdatesPath); // make sure the directory exists
            var di = new DirectoryInfo(UpdatesPath);

            foreach (var file in di.GetFiles("TogglDesktopInstaller*.exe", SearchOption.TopDirectoryOnly))
            {
                try
                {
                    Utils.DeleteFile(file.FullName);
                }
                catch (Exception e)
                {
                    BugsnagService.NotifyBugsnag(e);
                    Toggl.OnError?.Invoke($"Unable to delete the file: {file.FullName}. Delete this file manually.", false);
                }
            }
            var updatesDir = new DirectoryInfo(
                Path.Combine(
                    Environment.GetFolderPath(
                        Environment.SpecialFolder.LocalApplicationData), "Onova", "TogglDesktop"));

            if (updatesDir.Exists)
            {
                foreach (var file in updatesDir.GetFiles("*.exe", SearchOption.TopDirectoryOnly))
                {
                    try
                    {
                        Utils.DeleteFile(file.FullName);
                    }
                    catch (Exception e)
                    {
                        BugsnagService.NotifyBugsnag(e);
                        Toggl.OnError?.Invoke($"Unable to delete the file: {file.FullName}. Delete this file manually.", false);
                    }
                }
            }
        }
 public static void ShowErrorAndNotify(string errmsg, Exception ex)
 {
     NewError(errmsg, true);
     BugsnagService.NotifyBugsnag(ex);
 }