Esempio n. 1
0
        public void PrepareUpdate(GithubReleaseResponse latestVersionResponse)
        {
            IsDownloading = true;
            var releaseZip = latestVersionResponse.Assets
                             .Where(asset => asset.FileName.Equals(releaseFileName, StringComparison.InvariantCultureIgnoreCase))
                             .FirstOrDefault();

            if (!releaseZip.FileName.Equals(releaseFileName, StringComparison.InvariantCultureIgnoreCase))
            {
                DebugWindow.LogError("AutoUpdate -> Download failed, release .zip url not found.");
                IsDownloading = false;
                return;
            }

            var fileLocation = Path.Combine(UPDATE_FOLDER, releaseFileName);

            if (UseExistingRelease(latestVersionResponse))
            {
                IsReadyToUpdate = true;
            }
            else
            {
                Download(releaseZip.BrowserDownloadUrl, fileLocation);
                Unzip(fileLocation);
                IsReadyToUpdate = true;
            }
            IsDownloading = false;
        }
Esempio n. 2
0
        private bool UseExistingRelease(GithubReleaseResponse latestVersionResponse)
        {
            var unzippedDir = new DirectoryInfo(Path.Combine(UPDATE_FOLDER, RELEASE_FOLDER));

            if (!unzippedDir.Exists)
            {
                return(false);
            }

            var localVersion = VersionChecker.LoadLocalVersion(Path.Combine(unzippedDir.FullName, VersionChecker.VERSION_FILE_NAME));

            if (localVersion == null)
            {
                DebugWindow.LogError($"AutoUpdate -> Cant read local version");
                CleanUpdateFolder();
                return(false);
            }

            var latestVersion = VersionChecker.ConvertStringToVersionJson(latestVersionResponse.VersionString);

            if (latestVersion == null)
            {
                DebugWindow.LogError($"AutoUpdate -> Cant read latest version, {latestVersionResponse.VersionString}");
                CleanUpdateFolder();
                return(false);
            }

            var versionComparison = VersionChecker.VersionComparison(localVersion.Value, latestVersion.Value);

            if (versionComparison.IsUpdateAvailable())
            {
                DebugWindow.LogError($"AutoUpdate -> Current update folder is outdated, delete and start update process again");
                CleanUpdateFolder();
                return(false);
            }

            return(true);
        }