public static void SafeCreateFile(FsPath filename, Action <FsPath> createFile) { if (!filename.IsFile()) { createFile(filename); return; } FsPath backupName = filename.Concat(".bak"); if (backupName.IsFile()) { backupName.DeleteFile(); } filename.MoveFileTo(backupName); try { createFile(filename); } catch (Exception) { backupName.MoveFileTo(filename); throw; } backupName.DeleteFile(); }
public static FileSignature[] ReadFromFile(FsPath targetFile, bool internPath) { if (!targetFile.IsFile()) { return(null); } var lines = targetFile.ReadAllLines() .Where(_ => !string.IsNullOrEmpty(_)); var result = lines .Select(_ => new FileSignature { Md5Hash = _.Substring(0, 32), Path = FsPathPersistence.Deserialize(_.Substring(33)).Intern(internPath) }).ToArray(); return(result); }