示例#1
0
        /// <summary>
        /// Checks that the <see cref="ReleaseEntry"/> can be used
        /// </summary>
        public static bool CheckReleaseEntry(this ReleaseEntry releaseEntry, SemanticVersion applicationVersion, bool successfullyDownloaded)
        {
            Logger.Information("Checking {0}", releaseEntry.Filename);
            if (successfullyDownloaded && releaseEntry.IsValidReleaseEntry(applicationVersion, true))
            {
                return(true);
            }

            Logger.Error("Checking file {0} failed after downloading, going to delete it to be safe", releaseEntry.Filename);
            try
            {
                File.Delete(releaseEntry.FileLocation);
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
            return(false);
        }
示例#2
0
        public override async Task <bool> DownloadUpdate(ReleaseEntry releaseEntry, Action <double>?progress)
        {
            //No need to copy the file if it's what we expect already
            if (releaseEntry.IsValidReleaseEntry(AppMetadata.ApplicationVersion, true))
            {
                Logger.Information("{0} already exists and is what we expect, working with that", releaseEntry.FileLocation);
                return(true);
            }

            var bytesWritten = 0d;

            using var releaseStream = FileHelper.OpenWrite(releaseEntry.FileLocation, releaseEntry.Filesize);
            using var packageStream = new ProgressStream(
                      FileHelper.MakeFileStream(Path.Combine(_folderLocation, releaseEntry.Filename), FileMode.Open, FileAccess.ReadWrite),
                      (count =>
            {
                bytesWritten += count;
                progress?.Invoke(bytesWritten / releaseEntry.Filesize);
            }));

            await packageStream.CopyToAsync(releaseStream);

            return(releaseEntry.CheckReleaseEntry(AppMetadata.ApplicationVersion, true));
        }