/// ----------------------------------------------------------------------------- /// <summary> /// The RestoreFile method restores a file from the backup folder /// </summary> /// <param name="installFile">The file to restore</param> /// <param name="basePath">The basePath to the file</param> /// <param name="log">A Logger to log the result</param> /// <history> /// [cnurse] 08/03/2007 created /// </history> /// ----------------------------------------------------------------------------- public static void RestoreFile(InstallFile installFile, string basePath, Logger log) { string fullFileName = Path.Combine(basePath, installFile.FullName); string backupFileName = Path.Combine(installFile.BackupPath, installFile.Name + ".config"); //Copy File back over install file FileSystemUtils.CopyFile(backupFileName, fullFileName); log.AddInfo(string.Format(FILE_RestoreBackup, installFile.FullName)); }
/// ----------------------------------------------------------------------------- /// <summary> /// The DeleteFile method deletes a file. /// </summary> /// <param name="fileName">The file to delete</param> /// <param name="basePath">The basePath to the file</param> /// <param name="log">A Logger to log the result</param> /// <history> /// [cnurse] 08/03/2007 created /// </history> /// ----------------------------------------------------------------------------- public static void DeleteFile(string fileName, string basePath, Logger log) { string fullFileName = Path.Combine(basePath, fileName); if (File.Exists(fullFileName)) { RetryableAction.RetryEverySecondFor30Seconds(() => FileSystemUtils.DeleteFile(fullFileName), "Delete file " + fullFileName); log.AddInfo(string.Format(FILE_Deleted, fileName)); string folderName = Path.GetDirectoryName(fullFileName); if (folderName != null) { var folder = new DirectoryInfo(folderName); TryDeleteFolder(folder, log); } } }
/// ----------------------------------------------------------------------------- /// <summary> /// The BackupFile method backs up a file to the backup folder /// </summary> /// <param name="installFile">The file to backup</param> /// <param name="basePath">The basePath to the file</param> /// <param name="log">A Logger to log the result</param> /// <history> /// [cnurse] 08/03/2007 created /// </history> /// ----------------------------------------------------------------------------- public static void BackupFile(InstallFile installFile, string basePath, Logger log) { string fullFileName = Path.Combine(basePath, installFile.FullName); string backupFileName = Path.Combine(installFile.BackupPath, installFile.Name + ".config"); //create the backup folder if neccessary if (!Directory.Exists(installFile.BackupPath)) { Directory.CreateDirectory(installFile.BackupPath); } //Copy file to backup location RetryableAction.RetryEverySecondFor30Seconds(() => FileSystemUtils.CopyFile(fullFileName, backupFileName), "Backup file " + fullFileName); log.AddInfo(string.Format(FILE_CreateBackup, installFile.FullName)); }
/// ----------------------------------------------------------------------------- /// <summary> /// The CopyFile method copies a file from the temporary extract location. /// </summary> /// <param name="installFile">The file to copy</param> /// <param name="basePath">The basePath to the file</param> /// <param name="log">A Logger to log the result</param> /// <history> /// [cnurse] 08/03/2007 created /// </history> /// ----------------------------------------------------------------------------- public static void CopyFile(InstallFile installFile, string basePath, Logger log) { string filePath = Path.Combine(basePath, installFile.Path); string fullFileName = Path.Combine(basePath, installFile.FullName); //create the folder if neccessary if (!Directory.Exists(filePath)) { log.AddInfo(string.Format(FOLDER_Created, filePath)); Directory.CreateDirectory(filePath); } //Copy file from temp location RetryableAction.RetryEverySecondFor30Seconds(() => FileSystemUtils.CopyFile(installFile.TempFileName, fullFileName), "Copy file to " + fullFileName); log.AddInfo(string.Format(FILE_Created, installFile.FullName)); }
private static void TryDeleteFolder(DirectoryInfo folder, Logger log) { if (folder.GetFiles().Length == 0 && folder.GetDirectories().Length == 0) { folder.Delete(); log.AddInfo(string.Format(FOLDER_Deleted, folder.Name)); TryDeleteFolder(folder.Parent, log); } }