public override File GetByName(string name) { try { using (StreamReader infile = new StreamReader(ArchiveFolder + name + ".txt", true)) { String fileBody = infile.ReadToEnd().Replace("\r\n", "\n") ; File retFile = new File(name); retFile.Deserialize(fileBody); base.DeleteByName(name); files.Add(retFile); return retFile; } } catch (Exception e) { return null; } }
private void loadAll() { Directory.CreateDirectory(ArchiveFolder); // Attempt to migrate files from old archive drive if (KSP.IO.File.Exists<File>(HighLogic.fetch.GameSaveFolder + "/arc")) { var reader = KSP.IO.BinaryReader.CreateForType<File>(HighLogic.fetch.GameSaveFolder + "/arc"); int fileCount = reader.ReadInt32(); for (int i = 0; i < fileCount; i++) { try { String filename = reader.ReadString(); String body = reader.ReadString(); File file = new File(filename); file.Deserialize(body); files.Add(file); SaveFile(file); } catch (EndOfStreamException e) { break; } } reader.Close(); KSP.IO.File.Delete<File>(HighLogic.fetch.GameSaveFolder + "/arc"); } }