public void ProcessPostDownload() { foreach (var fileUpdateInfo in FileUpdateInfos.Where(f => f.LocalFilePath.EndsWith(@".zip"))) { FilePath localPath = fileUpdateInfo.LocalFilePath; if (!localPath.Exists()) { continue; } using (var archive = ZipFile.OpenRead(localPath)) { ExtractToDirectory(archive, localPath.GetDirPath(), true); } if (localPath.GetFileExt() == ".zip") { FilePath zipMd5Path = localPath.GetDirPath() + localPath.GetFileNameWithoutExtension() + @".md5"; File.WriteAllText(zipMd5Path, fileUpdateInfo.RemoteMD5); } localPath.DeleteIfExists(); } OnUpdateCompleted(); }
private async Task GetFileList() { List <RemoteFileInfo> remoteFileInfos; try { remoteFileInfos = await _restApi.GetRemoteFileListAsync(_remoteUrl); //Logger.Trace("Remote files:\r\n{0}", string.Join("\r\n", remoteFileInfos.Select(rfi => rfi.Name))); } catch (Exception e) { Logger.Error(e); var _errorView = new ErrorView(L("FilesNotReady"), e.Message, "https://www.bphots.com/articles/errors/"); //ShowMessageBox(L("FilesNotReady"), MessageBoxButton.OK, MessageBoxImage.Exclamation); RequestClose(false); return; } remoteFileInfos.ForEach(r => _totalBytes += long.Parse(r.Size)); FileUpdateInfos.AddRange(remoteFileInfos.Select(fi => new FileUpdateInfo { FileName = fi.Name, Url = fi.Url, RemoteMD5 = fi.MD5, LocalFilePath = Path.Combine(App.AppPath, _localDir, fi.Name.TrimStart('/')), Path = fi.Url.Remove(0, 24), //移去https://static.bphots.com/ FileStatus = L("Updating") })); }
private void DownloadFileCompleted(object sender, DownloadDataCompletedEventArgs e) { var webClient = (WebClient)sender; _downloadedBytes += e.Result.Length; var fileUpdateInfo = FileUpdateInfos[_currentIndex]; var content = e.Result; content.SaveAs(fileUpdateInfo.LocalFilePath); FilePath localPath = fileUpdateInfo.LocalFilePath; Logger.Trace("Downloaded. Bytes count: {0}", content.Length); if (localPath.GetFileExt() == ".zip" && localPath.Exists() || !NeedUpdate(fileUpdateInfo)) { fileUpdateInfo.FileStatus = L("UpToDate"); } else { fileUpdateInfo.FileStatus = L("UpdateFailed"); } Logger.Trace("File status: {0}", fileUpdateInfo.FileStatus); FileUpdateInfos.Refresh(); webClient.Dispose(); DownloadNextItem(); }
private void CheckFiles() { try { if (FileUpdateInfos.Any(fui => fui.FileStatus == L("UpdateFailed"))) { var _errorView = new ErrorView(L("FileUpdateFail"), L("FilesNotReady"), "https://www.bphots.com/articles/errors/"); _errorView.ShowDialog(); //ShowMessageBox(L("FilesNotReady"), MessageBoxButton.OK, MessageBoxImage.Exclamation); RequestClose(false); } } catch (InvalidOperationException e) { Logger.Error(e); var errorView = new ErrorView(L("FileUpdateFail"), e.Message, "https://www.bphots.com/articles/errors/1"); errorView.ShowDialog(); RequestClose(false); return; } catch (Exception e) { Logger.Error(e); var errorView = new ErrorView(L("FilesNotReady"), e.Message, "https://www.bphots.com/articles/errors/"); errorView.ShowDialog(); RequestClose(false); return; } RequestClose(true); }