/// <summary> /// Removes the given directory if it exists on the given machine /// If the machineName is null, the local machine is assumed to be the default /// </summary> /// <param name="directory"></param> /// <param name="machineName"></param> internal static void DeleteDirectoryIfExist(string directory, string machineName) { #if DotNetCoreClrLinux if (!string.IsNullOrEmpty(machineName)) { directory = GetRemotePath(directory, machineName); } if (FabricDirectory.Exists(directory)) { string[] files = FabricDirectory.GetFiles(directory); string[] dirs = FabricDirectory.GetDirectories(directory); foreach (string file in files) { File.SetAttributes(file, FileAttributes.Normal); File.Delete(file); } FabricDirectory.Delete(directory, true); } #else if (!string.IsNullOrEmpty(machineName)) { directory = GetRemotePath(directory, machineName); } if (Directory.Exists(directory)) { Directory.Delete(directory, true); } #endif }
public static string GetCabVersion(string cabPath) { string tempPath = Helpers.GetNewTempPath(); string fileToExtract = Path.Combine(Constants.PathToFabricCode, Constants.FabricExe); string tempFile = Path.Combine(tempPath, fileToExtract); ExtractFiltered(cabPath, tempPath, new string[] { fileToExtract }, true); if (!File.Exists(tempFile)) // Package is WU { fileToExtract = Constants.FabricExe; tempFile = Path.Combine(tempPath, fileToExtract); ExtractFiltered(cabPath, tempPath, new string[] { fileToExtract }, true); if (!File.Exists(tempFile)) { throw new FileNotFoundException(string.Format("{0} was not extracted from CAB package.", Constants.FabricExe)); } } try { var fileVersion = FileVersionInfo.GetVersionInfo(tempFile); return(string.Format( CultureInfo.InvariantCulture, "{0}.{1}.{2}.{3}", fileVersion.FileMajorPart, fileVersion.FileMinorPart, fileVersion.FileBuildPart, fileVersion.FilePrivatePart)); } finally { if (Directory.Exists(tempPath)) { try { FabricDirectory.Delete(tempPath, true, true); } catch { } } } }