コード例 #1
0
ファイル: Theme.cs プロジェクト: wadkar/toggldesktop
        private static ColorScheme?DetectOsColorScheme()
        {
            try
            {
                using (var subKey = Registry.CurrentUser.OpenSubKey(
                           @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", false))
                {
                    if (subKey == null)
                    {
                        return(null);
                    }

                    var value = Convert.ToInt32(subKey.GetValue("AppsUseLightTheme", -1));
                    switch (value)
                    {
                    case 0: return(ColorScheme.Dark);

                    case 1: return(ColorScheme.Light);

                    default: return(null);
                    }
                }
            }
            catch (Exception e)
            {
                BugsnagService.NotifyBugsnag(e);
                return(null);
            }
        }
コード例 #2
0
 public static void InstallProtocol()
 {
     try
     {
         var regLocation = Registry.CurrentUser.OpenSubKey("Software", true).OpenSubKey("Classes", true);
         var key         = regLocation.OpenSubKey(StartupUri, true) ?? regLocation.CreateSubKey(StartupUri);
         key?.SetValue("URL Protocol", _ssoLogin);
         var commandKey = key?.OpenSubKey(@"shell\open\command", true) ?? key?.CreateSubKey(@"shell\open\command");
         commandKey?.SetValue("", Assembly.GetExecutingAssembly().Location + " %1");
     }
     catch (Exception e)
     {
         BugsnagService.NotifyBugsnag(e);
     }
 }
コード例 #3
0
        private static void DeleteOldUpdates()
        {
            Directory.CreateDirectory(Toggl.UpdatesPath); // make sure the directory exists
            var di = new DirectoryInfo(Toggl.UpdatesPath);

            foreach (var file in di.GetFiles("TogglDesktopInstaller*.exe", SearchOption.TopDirectoryOnly))
            {
                try
                {
                    Utils.DeleteFile(file.FullName);
                }
                catch (Exception e)
                {
                    BugsnagService.NotifyBugsnag(e);
                    Toggl.NewError($"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.NewError($"Unable to delete the file: {file.FullName}. Delete this file manually.", false);
                    }
                }
            }
        }
コード例 #4
0
        public async Task ExtractPackageAsync(string sourceFilePath, string destDirPath, IProgress <double> progress = null,
                                              CancellationToken cancellationToken = new CancellationToken())
        {
            await Task.Run(() =>
            {
                var installerPath = sourceFilePath;
                var exePath       = Path.ChangeExtension(sourceFilePath, ".exe");
                try
                {
                    File.Move(sourceFilePath, exePath);
                    installerPath = exePath;
                }
                catch (Exception e) when(e is IOException || e is UnauthorizedAccessException)
                {
                    BugsnagService.NotifyBugsnag(e);
                }

                try
                {
                    var process = new Process
                    {
                        StartInfo =
                        {
                            FileName        = installerPath,
                            Arguments       = $"/S /autoupdate /D={destDirPath}",
                            UseShellExecute = false
                        }
                    };
                    process.Start();
                    process.WaitForExit();
                }
                catch (Exception e) when(e is Win32Exception || e is IOException || e is UnauthorizedAccessException)
                {
                    BugsnagService.NotifyBugsnag(e);
                }
            }, cancellationToken);
        }
コード例 #5
0
        public bool InstallPendingUpdate(bool withRestart = true)
        {
            var lastPreparedVersion = _updateManager.GetPreparedUpdates().LastOrDefault();

            if (lastPreparedVersion != null)
            {
                try
                {
                    _updateManager.LaunchUpdater(lastPreparedVersion, withRestart);
                    return(true);
                }
                catch (Exception e)
                    when(e is UpdaterAlreadyLaunchedException || e is LockFileNotAcquiredException)
                    {
                        // Ignore race conditions
                    }
                catch (Win32Exception e)
                {
                    BugsnagService.NotifyBugsnag(e);
                }
            }

            return(false);
        }