public override bool SaveFile(ProgramFile file) { base.SaveFile(file); Directory.CreateDirectory(archiveFolder); try { using (var outfile = new StreamWriter(archiveFolder + file.Filename + ".txt", false)) { string fileBody = file.Content; if (Application.platform == RuntimePlatform.WindowsPlayer) { // Only evil windows gets evil windows line breaks fileBody = fileBody.Replace("\n", "\r\n"); } outfile.Write(fileBody); } } catch (Exception e) { Debug.LogException(e); return(false); } return(true); }
public static ProgramFile ToProgramFile(this ConfigNode configNode) { var filename = configNode.GetValue(FILENAME_VALUE_STRING); var toReturn = new ProgramFile(filename); Decode(toReturn, configNode.GetValue("line")); return(toReturn); }
public override bool IsRoomFor(ProgramFile newFile) { int usedSpace = GetUsedSpace(); ProgramFile existingFile = GetByName(newFile.Filename); if (existingFile != null) { usedSpace -= existingFile.GetSize(); } return ((Capacity - usedSpace) >= newFile.GetSize()); }
public virtual void AppendToFile(string name, string textToAppend) { ProgramFile file = GetByName(name) ?? new ProgramFile(name); if (file.Content.Length > 0 && !file.Content.EndsWith("\n")) { textToAppend = "\n" + textToAppend; } file.Content += textToAppend; SaveFile(file); }
public override bool IsRoomFor(ProgramFile newFile) { int usedSpace = GetUsedSpace(); ProgramFile existingFile = GetByName(newFile.Filename); if (existingFile != null) { usedSpace -= existingFile.GetSize(); } return((Capacity - usedSpace) >= newFile.GetSize()); }
public virtual bool RenameFile(string name, string newName) { ProgramFile file = GetByName(name); if (file != null) { DeleteByName(name); file.Filename = newName; Add(file); return(true); } return(false); }
public virtual void AppendToFile(string name, string textToAppend) { ProgramFile file = GetByName(name); if (file == null) { file = new ProgramFile(name); } if (file.Content.Length > 0 && !file.Content.EndsWith("\n")) { textToAppend = "\n" + textToAppend; } file.Content += textToAppend; SaveFile(file); }
public override ProgramFile GetByName(string name) { try { using (var infile = new StreamReader(archiveFolder + name + ".txt", true)) { string fileBody = infile.ReadToEnd().Replace("\r\n", "\n"); var retFile = new ProgramFile(name) {Content = fileBody}; base.DeleteByName(name); base.Add(retFile); return retFile; } } catch (Exception e) { Debug.LogException(e); return null; } }
public override ProgramFile GetByName(string name) { try { using (StreamReader infile = new StreamReader(_archiveFolder + name + ".txt", true)) { string fileBody = infile.ReadToEnd().Replace("\r\n", "\n"); ProgramFile retFile = new ProgramFile(name); retFile.Content = fileBody; base.DeleteByName(name); base.Add(retFile); return(retFile); } } catch (Exception e) { Debug.LogException(e); return(null); } }
public static ConfigNode ToConfigNode(this ProgramFile programFile, string nodeName) { var node = new ConfigNode(nodeName); node.AddValue(FILENAME_VALUE_STRING, programFile.Filename); if (programFile.Category == FileCategory.KSM) { node.AddValue("line", EncodeBase64(programFile.BinaryContent)); } else { if (Config.Instance.UseCompressedPersistence) { node.AddValue("line", EncodeBase64(programFile.StringContent)); } else { node.AddValue("line", PersistenceUtilities.EncodeLine(programFile.StringContent)); } } return(node); }
private static void Decode(ProgramFile programFile, string input) { try { string decodedString; try { // base64 encoding // Fix for issue #429. See comment up in EncodeBase64() method above for an explanation: string massagedInput = input.Replace(',', '/'); byte[] decodedBuffer = DecodeBase64ToBinary(massagedInput); FileCategory whatKind = PersistenceUtilities.IdentifyCategory(decodedBuffer); if (whatKind == FileCategory.ASCII || whatKind == FileCategory.KERBOSCRIPT) { decodedString = Encoding.ASCII.GetString(decodedBuffer); programFile.StringContent = decodedString; } else { programFile.BinaryContent = decodedBuffer; } } catch (FormatException) { // standard encoding decodedString = PersistenceUtilities.DecodeLine(input); programFile.StringContent = decodedString; } } catch (Exception e) { SafeHouse.Logger.Log(string.Format("Exception decoding: {0} | {1}", e, e.Message)); } }
public virtual bool SaveFile(ProgramFile file) { DeleteByName(file.Filename); Add(file); return(true); }
public virtual void Add(ProgramFile file) { _files.Add(file.Filename.ToLower(), file); }
public virtual bool IsRoomFor(ProgramFile newFile) { return(true); }
public ProgramFile(ProgramFile copy) { Filename = copy.Filename; Content = copy.Content; }
public override bool SaveFile(ProgramFile file) { base.SaveFile(file); Directory.CreateDirectory(_archiveFolder); try { using (StreamWriter outfile = new StreamWriter(_archiveFolder + file.Filename + ".txt", false)) { string fileBody = file.Content; if (Application.platform == RuntimePlatform.WindowsPlayer) { // Only evil windows gets evil windows line breaks fileBody = fileBody.Replace("\n", "\r\n"); } outfile.Write(fileBody); } } catch (Exception e) { Debug.LogException(e); return false; } return true; }
public override bool IsRoomFor(ProgramFile newFile) { return true; }
public void SaveContents() { var file = new ProgramFile(fileName) {Content = contents}; if (! volume.SaveFile(file) ) { // For some reason the normal trap that prints exeptions on // the terminal doesn't work here in this part of the code, // thus the two messages: term.Print("[File Save failed. Check space on device?]"); throw new Exception( "File Save Failed from Text Editor."); } isDirty = false; term.Print("[Saved changes to " + fileName + "]"); }
public virtual bool SaveFile(ProgramFile file) { DeleteByName(file.Filename); Add(file); return true; }
public virtual bool IsRoomFor(ProgramFile newFile) { return true; }
public override bool SaveFile(ProgramFile file) { return IsRoomFor(file) && base.SaveFile(file); }
public override bool IsRoomFor(ProgramFile newFile) { return(true); }
public void InitObjects() { Debug.LogWarning("kOS: InitObjects: " + (shared == null)); shared = new SharedObjects(); CreateFactory(); shared.Vessel = vessel; shared.Processor = this; shared.UpdateHandler = new UpdateHandler(); shared.BindingMgr = new BindingManager(shared); shared.Interpreter = shared.Factory.CreateInterpreter(shared); shared.Screen = shared.Interpreter; shared.ScriptHandler = new Compilation.KS.KSScript(); shared.Logger = new KSPLogger(shared); shared.VolumeMgr = new VolumeManager(shared); shared.ProcessorMgr = new ProcessorManager(); shared.Cpu = new Execution.CPU(shared); // initialize archive var archive = shared.Factory.CreateArchive(); shared.VolumeMgr.Add(archive); // initialize harddisk if (HardDisk == null && archive.CheckRange(vessel)) { HardDisk = new Harddisk(Mathf.Min(diskSpace, PROCESSOR_HARD_CAP)); var bootProgramFile = archive.GetByName(bootFile); if (bootProgramFile != null) { // Copy to HardDisk as "boot". var boot = new ProgramFile(bootProgramFile) {Filename = "boot"}; HardDisk.Add(boot); } } shared.VolumeMgr.Add(HardDisk); // process setting if (!Config.Instance.StartOnArchive) { shared.VolumeMgr.SwitchTo(HardDisk); } shared.Cpu.Boot(); }
public override bool SaveFile(ProgramFile file) { return(IsRoomFor(file) && base.SaveFile(file)); }