//Save Changes Button
        private async void Save(object s, RoutedEventArgs e)
        {
            try {
                Cursor = Cursors.Wait;

                ConfigHelper.Save();

                //Restart for applied changes
                InstallerHelper.KillImgurSniper(false);
                //If not Tray Service, do not start
                if (ConfigHelper.RunOnBoot)
                {
                    try {
                        InstallerHelper.StartImgurSniper();
                    } catch {
                        await ErrorToast.ShowAsync(str.trayServiceNotRunning, TimeSpan.FromSeconds(3));
                    }
                }

                SuccessToast.Show(str.applied, TimeSpan.FromSeconds(2));

                BtnSave.IsEnabled = false;
            } catch {
                ErrorToast.Show(str.couldNotApply, TimeSpan.FromSeconds(3));
            }
            Cursor = Cursors.Arrow;
        }
Example #2
0
        private async void DownloadCompleted(object sender, AsyncCompletedEventArgs e)
        {
            string file          = Path.Combine(_updateZipPath, "ImgurSniperSetup.zip");
            string extractTo     = Path.Combine(_updateZipPath, "ImgurSniperInstaller");
            string installerPath = Path.Combine(extractTo, "ImgurSniperSetup.exe");

            if (!File.Exists(file))
            {
                _error.Show(strings.couldNotDownload,
                            TimeSpan.FromSeconds(5));
                await Task.Delay(1000);

                Process.Start("https://mrousavy.github.io/ImgurSniper");
            }
            else
            {
                Extract(file, extractTo);

                //Update current version
                ConfigHelper.CurrentCommits  = Commits.Count;
                ConfigHelper.UpdateAvailable = false;
                ConfigHelper.Save();

                //Remove /VERYSILENT ?
                Process.Start(installerPath, "/VERYSILENT");

                KillImgurSniper(true);
            }
        }
 private void SkipClick(object sender, RoutedEventArgs e)
 {
     Skipped = true;
     ConfigHelper.CurrentCommits = _latest;
     ConfigHelper.UpdateAvailable = false;
     ConfigHelper.Save();
     DialogResult = false;
 }
Example #4
0
        private static void LoadLanguage()
        {
            string language = ConfigHelper.Language;

            //If language is not yet set manually, select system default
            if (!string.IsNullOrWhiteSpace(language))
            {
                Thread.CurrentThread.CurrentCulture   = new CultureInfo(language);
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);
                FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(
                                                                       XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
            }
            else
            {
                ConfigHelper.Language = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
                ConfigHelper.Save();
            }
        }
Example #5
0
        //forceSearch = true if should search for updates even if Last Checked is not longer than 1 Day ago
        public static async Task <bool> CheckForUpdates(MainWindow window, bool forceSearch)
        {
            try {
                //Last update Check
                DateTime lastChecked = ConfigHelper.LastChecked;

                //Update Available?
                bool updateAvailable = ConfigHelper.UpdateAvailable;

                //Last Update Content for Label
                window.SetProgressStatus(string.Format(strings.updateLast, $"{lastChecked:dd.MM.yyyy HH:mm}"));

                //If AutoUpdate is disabled and the User does not manually search, exit Method
                if (!ConfigHelper.AutoUpdate && !forceSearch)
                {
                    return(false);
                }

                //Update Loading Indicator
                window.SetProgressStatus(strings.checkingUpdate);

                //Check for Update, if last update is longer than 1 Day ago
                if (forceSearch || DateTime.Now - lastChecked > TimeSpan.FromDays(1) || updateAvailable)
                {
                    //Retrieve info from github
                    GitHubClient github = new GitHubClient(new ProductHeaderValue("ImgurSniper"));
                    IReadOnlyList <GitHubCommit> commitsRaw = await github.Repository.Commit.GetAll("mrousavy",
                                                                                                    "ImgurSniper");

                    //All Commits where a new ImgurSniper Version is available start with "R:"
                    Commits      = new List <GitHubCommit>(commitsRaw.Where(c => c.Commit.Message.StartsWith("R:")));
                    TotalCommits = commitsRaw.Count;
                    ConfigHelper.TotalCommits = TotalCommits;
                    ConfigHelper.LastChecked  = DateTime.Now;
                    ConfigHelper.Save();

                    //Last Update Content for Label
                    window.SetProgressStatus(string.Format(strings.updateLast, $"{DateTime.Now:dd.MM.yyyy HH:mm}"));

                    int currentCommits = ConfigHelper.CurrentCommits;
                    //999 = value is unset
                    if (currentCommits == 999)
                    {
                        ConfigHelper.CurrentCommits = Commits.Count;
                        ConfigHelper.Save();
                    }
                    else if (updateAvailable || Commits.Count > currentCommits)
                    {
                        //Newer Version is available
                        ConfigHelper.UpdateAvailable = true;
                        ConfigHelper.Save();
                        window.SuccessToast.Show(string.Format(strings.updateAvailable, currentCommits, Commits.Count),
                                                 TimeSpan.FromSeconds(4));

                        return(true);
                    }
                    else
                    {
                        //No Update available
                        ConfigHelper.UpdateAvailable = false;
                        ConfigHelper.Save();
                    }
                }
            } catch {
                window.ErrorToast.Show(strings.failedUpdate, TimeSpan.FromSeconds(3));
            }
            //Any other way than return true = no update
            return(false);
        }