public async Task DownloadLatestVersion(ITaskProgress taskProgress)
        {
            cachedResponse ??= await InternalCheckForUpdates();

            if (cachedResponse != null)
            {
                var physPath = fileSystem.ResolvePhysicalPath(platformService.UpdateZipFilePath);
                await UpdateClient.DownloadUpdate(cachedResponse, physPath.FullName, taskProgress.ToProgress());

                if (cachedResponse.ChangeLog?.Length > 0)
                {
                    fileSystem.WriteAllText("~/changelog.json", JsonConvert.SerializeObject(cachedResponse.ChangeLog));
                }
            }

            taskProgress.ReportFinished();
        }
Ejemplo n.º 2
0
        public async Task <bool> DownloadLatestVersion(ITaskProgress taskProgress)
        {
            cachedResponse ??= await InternalCheckForUpdates();

            if (cachedResponse != null)
            {
                var  physPath = fileSystem.ResolvePhysicalPath(platformService.UpdateZipFilePath);
                bool success  = false;
                int  trial    = 0;
                do
                {
                    trial++;
                    success = true;
                    await UpdateClient.DownloadUpdate(cachedResponse, physPath.FullName, taskProgress.ToProgress());

                    if (!string.IsNullOrEmpty(cachedResponse.DownloadMd5))
                    {
                        success = await updateVerifier.IsUpdateValid((FileInfo)physPath, cachedResponse.DownloadMd5);
                    }
                } while (!success && trial < 3);

                if (!success)
                {
                    physPath.Delete();
                    taskProgress.ReportFinished();
                    return(false);
                }

                if (cachedResponse.ChangeLog?.Length > 0)
                {
                    fileSystem.WriteAllText("~/changelog.json", JsonConvert.SerializeObject(cachedResponse.ChangeLog));
                }

                taskProgress.ReportFinished();
                return(true);
            }

            taskProgress.ReportFinished();
            return(false);
        }