public async void ExecuteUpdate()
        {
            string platformName = string.Empty;

            if (System.Environment.Is64BitOperatingSystem)
            {
                platformName = "win64";
            }
            else
            {
                platformName = "win32";
            }

            string assetToDownload = string.Empty;

            foreach (GitHub.Asset asset in _Release.Assets)
            {
                if (asset.BrowserDownloadUrl.Contains(platformName))
                {
                    assetToDownload = asset.BrowserDownloadUrl;
                    break;
                }
            }

            if (!string.IsNullOrEmpty(assetToDownload))
            {
                string downloadPath = Path.Combine(Path.GetTempPath(), Path.GetFileName(assetToDownload));
                using (WebClient webClient = new CustomizedWebClient())
                {
                    webClient.Headers.Add("User-Agent: Other");
                    StatusText = "Downloading Update...";
                    await webClient.DownloadFileTaskAsync(assetToDownload, downloadPath);
                }

                StatusText = "Extracting Files...";

                string parentFolderName = Directory.GetParent(System.Reflection.Assembly.GetEntryAssembly().Location).FullName;
                RenameFilesRecursively(parentFolderName);

                System.IO.Compression.ZipFile.ExtractToDirectory(downloadPath, parentFolderName);

                StatusText = "Restarting Application...";

                var filename = Directory.GetFiles(parentFolderName, "*.exe").First();
                System.Diagnostics.Process.Start(Path.Combine(parentFolderName, filename), "/cleanupUpdateFiles");
                App.Current.Shutdown();
            }
        }
Beispiel #2
0
        internal static async void Launch()
        {
            if (!App.Instance.Conf.CheckForUpdates)
            {
                return;
            }

            List <GitHub.Release> releases = null;

            using (WebClient webClient = new CustomizedWebClient())
            {
                webClient.Headers.Add("User-Agent: Other");
                var json = await webClient.DownloadStringTaskAsync(ReleasesConstants.ApiEndpoint);

                releases = JsonConvert.DeserializeObject <List <GitHub.Release> >(json);
            }

            Version    assemblyVersion    = Assembly.GetEntryAssembly().GetName().Version;
            SemVersion semAssemblyVersion = SemVersion.Parse($"{assemblyVersion.Major}.{assemblyVersion.Minor}.{assemblyVersion.Build}");

            GitHub.Release bestRelease        = null;
            SemVersion     bestReleaseVersion = semAssemblyVersion;

            foreach (GitHub.Release release in releases)
            {
                SemVersion releaseSemVersion = SemVersion.Parse(release.TagName);
                if (releaseSemVersion > bestReleaseVersion)
                {
                    bestReleaseVersion = releaseSemVersion;
                    bestRelease        = release;
                }
            }

            CleanupOldFiles();

            if (bestRelease != null && bestReleaseVersion > semAssemblyVersion)
            {
                if (MessageBox.Show("There is a new version available, do you wish to update?", "New Version", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    UpdateView view = new UpdateView(bestRelease);
                    view.ExecuteUpdate();
                }
            }
        }