/// <summary> /// Remove all deleted entries and shrink all over-sized entries. /// Actually we're just reading the file, deleting it, and writing it down again. /// </summary> /// <param name="Path"></param> public static void DefragmentFile(string Path) { var toWrite = GetDictionary(Path).Values.Where((p) => !p.IsMarkedDeleted); File.Delete(Path); using (var file = new Mrq(Path)) //creates a new file. foreach (var entry in toWrite) { file.AppendEntry(entry); } //yes, we will increment the count frequently. but i want my code to be A S T H E T I C }
/// <summary> /// <3 /// </summary> /// <param name="argssquarebracket1closingsquarebracket">aka "input file"</param> /// <returns></returns> public static MrqEntry DoYourThingPlease(string ArgsSquareBracket1ClosingSquareBracket) { string expectedMrqPath = Directory.GetFiles(Path.GetDirectoryName(ArgsSquareBracket1ClosingSquareBracket)).Where((s) => Path.GetExtension(s).Equals("mrq")).First(); using (var file = new Mrq(expectedMrqPath)) { var fname = Path.GetFileName(ArgsSquareBracket1ClosingSquareBracket); file.SeekUntilFileNameIs(fname); var entry = file.GetCurrentEntry(); entry.FileName = fname; return(entry); } }
/// <summary> /// Process the entire file at once, and converts it into a dictionary. You're welcome. /// </summary> /// <param name="Path"></param> /// <returns></returns> public static Dictionary <string, MrqEntry> GetDictionary(string Path) { using (var file = new Mrq(Path)) return(file.ToDictionary()); }