private void DeleteExistingDump() { if (fileSystemOperations.DirectoryExists(AppPaths.LogDump)) { fileSystemOperations.DeleteDirectory(AppPaths.LogDump); } }
public async Task ExtractToFolder(Stream stream, string folderPath) { var temp = FileUtils.GetTempDirectoryName(); await Observable.Start(() => { using (var zip = new ZipArchive(stream, ZipArchiveMode.Read, false)) { zip.ExtractToDirectory(temp); } }); var folderName = Path.GetFileName(folderPath); if (fileSystemOperations.DirectoryExists(folderPath)) { await fileSystemOperations.DeleteDirectory(folderPath); } var firstChild = Path.Combine(temp, folderName); await fileSystemOperations.CopyDirectory(firstChild, folderPath); await fileSystemOperations.DeleteDirectory(temp); }
private async Task ExtractContents(ICollection <ZipArchiveEntry> entries, string destination, IEntry baseEntry = null, IOperationProgress progressObserver = null) { var total = entries.Count; var copied = 0; foreach (var entry in entries) { var filePath = entry.Key.Substring(baseEntry?.Key.Length ?? 0); var destFile = Path.Combine(destination, filePath.Replace("/", "\\")); var dir = Path.GetDirectoryName(destFile); if (!fileSystemOperations.DirectoryExists(dir)) { fileSystemOperations.CreateDirectory(dir); } using (var destStream = File.Open(destFile, FileMode.OpenOrCreate)) using (var stream = entry.OpenEntryStream()) { await stream.CopyToAsync(destStream); copied++; progressObserver?.Percentage.OnNext(copied / (double)total); } } progressObserver?.Percentage.OnNext(double.NaN); }
public string PickFile() { var dialog = new OpenFileDialog(); var lines = FileTypeFilter.Select(x => { var exts = string.Join(";", x.Extensions); return($"{x.Description}|{exts}"); }); var filter = string.Join("|", lines); dialog.Filter = filter; dialog.FileName = ""; if (fileSystemOperations.DirectoryExists(InitialDirectory)) { dialog.InitialDirectory = InitialDirectory; } if (dialog.ShowDialog(Application.Current.MainWindow) == true) { return(dialog.FileName); } return(null); }
private async Task DeleteExistingFolder() { if (fileSystemOperations.DirectoryExists(AppPaths.Feed)) { await fileSystemOperations.DeleteDirectory(AppPaths.Feed); } }
private async Task DeleteFeedFolder() { if (fileSystemOperations.DirectoryExists(FeedFolder)) { await fileSystemOperations.DeleteDirectory(FeedFolder); } }
/// <summary> /// Returns a stream backed by the specified package if it exists; otherwise returns null. /// </summary> /// <param name="packageId">The ID of the package.</param> /// <param name="packageVersion">The version of the package.</param> /// <returns>Stream backed by the specified package if it exists; otherwise null.</returns> /// <exception cref="ArgumentNullException"><paramref name="packageId"/> is null or contains only whitespace or <paramref name="packageVersion"/> is null.</exception> public override Stream OpenPackage(string packageId, SemanticVersion packageVersion) { if (string.IsNullOrWhiteSpace(packageId)) { throw new ArgumentNullException("packageId"); } if (packageVersion == null) { throw new ArgumentNullException("packageVersion"); } InitPackageStore(); _logger.Debug("OpenPackage('" + packageId + "', '" + packageVersion + "') called"); var packagePath = Path.Combine(RootPath, packageId); if (!_fileSystemOperations.DirectoryExists(packagePath)) { _logger.Warn("Attempted to open package '" + packageId + "', version '" + packageVersion + "', in folder '" + packagePath + "' but the folder didn't exist"); return(null); } var versionPath = Path.Combine(packagePath, packageId + "." + packageVersion + ".nupkg"); if (!_fileSystemOperations.FileExists(versionPath)) { _logger.Warn("Attempted to open package '" + packageId + "', version '" + packageVersion + "', at path '" + versionPath + "' but it didn't exist"); return(null); } try { return(_fileSystemOperations.GetFileStream(versionPath, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete)); } catch (FileNotFoundException ex) { _logger.Error("File not found error looking for package '" + packageId + "', version '" + packageVersion + "'.", ex); return(null); } catch (DirectoryNotFoundException ex) { _logger.Error("Directory not found error looking for package '" + packageId + "', version '" + packageVersion + "'.", ex); return(null); } }
public async Task Execute() { if (fileSystemOperations.DirectoryExists(destination)) { Log.Warning("UEFI was already downloaded. Skipping download."); return; } using (var stream = await githubCient.Open("https://github.com/andreiw/RaspberryPiPkg")) { var zipArchive = await Observable.Start(() => new ZipArchive(stream, ZipArchiveMode.Read)); var mostRecentFolderEntry = GetMostRecentDirEntry(zipArchive); var contents = zipArchive.Entries.Where(x => x.FullName.StartsWith(mostRecentFolderEntry.FullName) && !x.FullName.EndsWith("/")); await ExtractContents(mostRecentFolderEntry, contents); } }
private async Task DownloadDeploymentScripts() { if (fileSystemOperations.DirectoryExists(ScriptsDownloadPath)) { await fileSystemOperations.DeleteDirectory(ScriptsDownloadPath); } await RunScript(BootstrapPath); }
protected override async Task ExecuteCore() { if (fileSystemOperations.DirectoryExists(destination)) { return; } var stream = await downloader.GetStream(url, progressObserver); await extractor.ExtractToFolder(stream, destination); }
public async Task Execute() { if (fileSystemOperations.DirectoryExists(destination)) { Log.Warning("UEFI was already downloaded. Skipping download."); return; } using (var stream = await GitHubMixin.GetBranchZippedStream("https://github.com/andreiw/RaspberryPiPkg", progressObserver: progressObserver)) { await extractor.ExtractRelativeFolder(stream, GetMostRecentDirEntry, destination, progressObserver); } }
private async Task CleanDownloadedIfNeeded() { if (!settingsService.CleanDownloadedBeforeDeployment) { return; } if (fileSystemOperations.DirectoryExists(AppPaths.DownloadedFolderName)) { Log.Information("Deleting previously downloaded deployment files"); await fileSystemOperations.DeleteDirectory(AppPaths.DownloadedFolderName); } }
public async Task Execute() { if (fileSystemOperations.DirectoryExists(destination)) { Log.Warning("{Url}{Folder} was already downloaded. Skipping download.", url, relativePath); return; } using (var stream = await GitHubMixin.GetBranchZippedStream(downloader, url, progressObserver: progressObserver)) { await zipExtractor.ExtractRelativeFolder(stream, relativePath, destination); } }