public async void StartChecking(BinUpdaterKey cfg) { ClearReplacementsDir(); if (cfg.EveryMin < 1) { return; } IsEnabled = true; while (IsEnabled) { var changes = await GetChangedFiles(cfg); //Status = $"Checked for newer version. {changes.Count.x("updatable file")} found."; if (changes.Count > 0) { IsEnabled = false; DisplacingOutdateds?.Invoke(this, EventArgs.Empty); Status = "Updates found. Displacing outdated files..."; DisplaceOutdatedFiles(changes); DownloadingUpdates?.Invoke(this, EventArgs.Empty); Status = "Outdateds displaced. Downloading updates..."; await DownloadUpdates(changes, cfg); UpdatesInstalled?.Invoke(this, EventArgs.Empty); Status = "Updates downloaded and installed."; break; } await DelayRetry(cfg.EveryMin); } }
private async Task DownloadUpdates(List <AppFilesDTO> changedFiles, BinUpdaterKey cfg) { foreach (var file in changedFiles) { if (!file.app_file_fid.HasValue) { continue; } var rsrc = FileContentURL(file.app_file_fid.Value); FetchFile: var contnt = await ApiGet <List <FileContentDTO> >(rsrc, cfg); var byts = DecodeDownloaded(contnt); if (byts != null) { File.WriteAllBytes(file.LocalPath, byts); } if (!VerifyWritten(file)) { goto FetchFile; } } }
private async Task <List <AppFilesDTO> > GetChangedFiles(BinUpdaterKey cfg) { //Status = $"Checking for updates as “{cfg.Username}”..."; var rsrc = AppFilesURL(cfg.AppNid); var list = await ApiGet <List <AppFilesDTO> >(rsrc, cfg); foreach (var f in list) { f.FileDiffered += (s, e) => Status = e.Value; } list?.RemoveAll(x => x.IsSame()); return(list); }
protected abstract Task <T> ApiGet <T> (string url, BinUpdaterKey cfg);