Пример #1
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));
        }