/// <summary> /// Downloads the package. /// </summary> /// <param name="release">The release.</param> /// <returns></returns> /// <exception cref="Exception">Target Release ${release} doesn't have a Package URI specified.</exception> private string DownloadPackage(RockRelease release) { if (release.PackageUri.IsNullOrWhiteSpace()) { throw new Exception($"Target Release ${release} doesn't have a Package URI specified."); } var localRockPackageDirectory = Path.Combine(FileManagementHelper.ROOT_PATH, LOCAL_ROCK_PACKAGE_FOLDER); if (!Directory.Exists(localRockPackageDirectory)) { Directory.CreateDirectory(localRockPackageDirectory); } var localRockPackagePath = Path.Combine(localRockPackageDirectory, $"{release.SemanticVersion}.rockpkg"); FileManagementHelper.DeleteOrRename(localRockPackagePath); try { var wc = new WebClient(); wc.DownloadFile(release.PackageUri, localRockPackagePath); } catch { FileManagementHelper.DeleteOrRename(localRockPackagePath); throw; } return(localRockPackagePath); }
/// <summary> /// Backups the file. /// </summary> /// <param name="filepathToBackup">The filepath to backup.</param> private void BackupFile(string filepathToBackup) { if (File.Exists(filepathToBackup)) { var backupFilePath = GetBackupFileLocation(filepathToBackup); var backupDirectory = Path.GetDirectoryName(backupFilePath); if (!Directory.Exists(backupDirectory)) { Directory.CreateDirectory(backupDirectory); } FileManagementHelper.DeleteOrRename(backupFilePath); File.Copy(filepathToBackup, backupFilePath); } }