public static string GetSRI(FsPath path) { using (var fs = File.OpenRead(path.ToString())) { using (var hashAlgorithm = new SHA384Managed()) { byte[] hash = hashAlgorithm.ComputeHash(fs); return("sha384-" + Convert.ToBase64String(hash)); } } }
public static void ProtectDirectory(this FsPath directory) { var outp = directory.Combine("index.html"); StringBuilder sb = new StringBuilder(4096); for (int i = 0; i < 256; i++) { sb.Append(" "); } outp.WriteFile(sb.ToString()); }
public static bool CreateDir(this FsPath path) { if (!FsPath.IsEmptyPath(path)) { Directory.CreateDirectory(path.ToString()); return(true); } else { return(false); } }
public static bool Copy(this FsPath source, FsPath target, bool overwrite) { if (!source.IsExisting) { return(false); } var dir = Path.GetDirectoryName(target.ToString()); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } File.Copy(source.ToString(), target.ToString(), overwrite); return(true); }
public static bool CopyDirectory(this FsPath sourceDirectory, FsPath TargetDir) { if (!Directory.Exists(TargetDir.ToString())) { Directory.CreateDirectory(TargetDir.ToString()); } foreach (string newPath in Directory.GetFiles(sourceDirectory.ToString(), "*.*", SearchOption.AllDirectories)) { var targetfile = newPath.Replace(sourceDirectory.ToString(), TargetDir.ToString()); File.Copy(newPath, targetfile, true); } return(true); }
public static bool WriteFile(this FsPath target, params string[] contents) { FileInfo fileInfo = new FileInfo(target.ToString()); if (!fileInfo.Exists) { Directory.CreateDirectory(fileInfo.Directory.FullName); } using (var writer = File.CreateText(target.ToString())) { foreach (var content in contents) { writer.Write(content); } } return(true); }
public static bool CreateBackup(this FsPath source) { if (!source.IsExisting) { return(false); } string targetname = $"{source}_backup"; if (File.Exists(targetname)) { bool exists = true; int counter = 1; do { targetname = $"{source}_backup{counter}"; ++counter; exists = File.Exists(targetname); }while (exists); } File.Copy(source.ToString(), targetname); return(true); }
public static bool SerializeXml <T>(this FsPath path, T obj, IList <(string prefix, string namespac)>?nslist = null) where T : class, new()