public static MemoryContents Deserialize(XmlReader rdr) { MemoryContents ret = new MemoryContents(); while (rdr.Name != "Memory") { rdr.Read(); if (rdr.EOF) { throw new FormatException("Unexpected end of file looking for start of Memory tag"); } } do { rdr.Read(); if (rdr.Name == "Memory" && !rdr.IsStartElement()) { return(ret); } Utils.ProcessXmlElementInParent(rdr, "Commands", "Command", (Action)(() => { int content = (int)rdr.MoveToContent(); string s = rdr.ReadElementContentAsString(); if (s.Contains("\n")) { string[] strArray = s.Split(Utils.robustNewlineDelim, StringSplitOptions.None); for (int index = 0; index < strArray.Length; ++index) { if (string.IsNullOrEmpty(strArray[index])) { strArray[index] = " "; } ret.CommandsRun.Add(ComputerLoader.filter(Folder.deFilter(strArray[index]))); } } else { ret.CommandsRun.Add(ComputerLoader.filter(Folder.deFilter(s))); } })); Utils.ProcessXmlElementInParent(rdr, "Data", "Block", (Action)(() => { int content = (int)rdr.MoveToContent(); ret.DataBlocks.Add(ComputerLoader.filter(Folder.deFilter(rdr.ReadElementContentAsString()))); })); Utils.ProcessXmlElementInParent(rdr, "FileFragments", "File", (Action)(() => { string s1 = "UNKNOWN"; if (rdr.MoveToAttribute("name")) { s1 = rdr.ReadContentAsString(); } int content = (int)rdr.MoveToContent(); string s2 = rdr.ReadElementContentAsString(); ret.FileFragments.Add(new KeyValuePair <string, string>(Folder.deFilter(s1), Folder.deFilter(s2))); })); Utils.ProcessXmlElementInParent(rdr, "Images", "Image", (Action)(() => { int content = (int)rdr.MoveToContent(); ret.Images.Add(Folder.deFilter(rdr.ReadElementContentAsString())); })); }while (!rdr.EOF); throw new FormatException("Unexpected end of file trying to deserialize memory contents!"); }
public static Folder load(XmlReader reader) { while (reader.Name != "folder" || reader.NodeType == XmlNodeType.EndElement) { reader.Read(); if (reader.EOF) { return((Folder)null); } } reader.MoveToAttribute("name"); Folder folder = new Folder(Folder.deFilter(reader.ReadContentAsString())); reader.Read(); while (reader.Name != "folder" && reader.Name != "file") { reader.Read(); if (reader.EOF || reader.Name == "folder" && reader.NodeType == XmlNodeType.EndElement) { return(folder); } } while (reader.Name == "folder") { if (reader.NodeType == XmlNodeType.EndElement) { return(folder); } folder.folders.Add(Folder.load(reader)); reader.Read(); while (reader.Name != "folder" && reader.Name != "file") { reader.Read(); if (reader.EOF || reader.Name == "computer") { return(folder); } } } while (reader.Name != "folder" && reader.Name != "file") { reader.Read(); } while (reader.Name == "file" && reader.NodeType != XmlNodeType.EndElement) { reader.MoveToAttribute("name"); string s = reader.ReadContentAsString(); bool flag = true; if (reader.MoveToAttribute("EduSafe")) { flag = reader.ReadContentAsBoolean(); } string nameEntry = Folder.deFilter(s); reader.MoveToElement(); string dataEntry = Folder.deFilter(reader.ReadElementContentAsString()); if (flag || !Settings.EducationSafeBuild) { folder.files.Add(new FileEntry(dataEntry, nameEntry)); } reader.Read(); while (reader.Name != "folder" && reader.Name != "file") { reader.Read(); } } reader.Read(); return(folder); }
public static object load(XmlReader reader) { while (reader.Name != "mission") { reader.Read(); } reader.MoveToAttribute("next"); string next = reader.ReadContentAsString(); reader.MoveToAttribute("goals"); string filename = reader.ReadContentAsString(); if (reader.MoveToAttribute("genTarget")) { string str1 = reader.ReadContentAsString(); reader.MoveToAttribute("genFile"); string str2 = reader.ReadContentAsString(); reader.MoveToAttribute("genPath"); string str3 = reader.ReadContentAsString(); reader.MoveToAttribute("genTargetName"); string str4 = reader.ReadContentAsString(); reader.MoveToAttribute("genOther"); string str5 = reader.ReadContentAsString(); MissionGenerationParser.Comp = str1; MissionGenerationParser.File = str2; MissionGenerationParser.Path = str3; MissionGenerationParser.Target = str4; MissionGenerationParser.Other = str5; } reader.MoveToAttribute("activeChack"); int num1 = 0; if (reader.MoveToAttribute("reqRank")) { num1 = reader.ReadContentAsInt(); } bool flag = reader.ReadContentAsString().ToLower().Equals("true"); if (next == "NULL_MISSION") { return((object)null); } if (!Settings.IsInExtensionMode && !filename.StartsWith("Content")) { filename = "Content/" + filename; } List <MisisonGoal> _goals = new List <MisisonGoal>(); ActiveMission activeMission1 = new ActiveMission(new List <MisisonGoal>(), "NONE", new MailServer.EMailData("Unknown", "Unknown", "Unknown", new List <string>())); try { activeMission1 = (ActiveMission)ComputerLoader.readMission(filename); _goals = activeMission1.goals; flag = flag || activeMission1.activeCheck; } catch (Exception ex) { Utils.SendRealWorldEmail("Mission Load Error", "*****@*****.**", "Hacknet " + MainMenu.OSVersion + "\r\n" + Utils.GenerateReportFromException(ex)); } string sendr = "ERRORBOT"; string subj = "ERROR"; string bod = "ERROR :: MAIL LOAD FAILED"; while (reader.Name != "email" && reader.Name != "endFunc") { reader.Read(); } if (reader.Name.Equals("email")) { if (reader.MoveToAttribute("sender")) { sendr = Folder.deFilter(reader.ReadContentAsString()); } if (reader.MoveToAttribute("subject")) { subj = Folder.deFilter(reader.ReadContentAsString()); } int content = (int)reader.MoveToContent(); bod = Folder.deFilter(reader.ReadElementContentAsString()); } MailServer.EMailData _email = new MailServer.EMailData(sendr, bod, subj, activeMission1.email.attachments); ActiveMission activeMission2 = new ActiveMission(_goals, next, _email); activeMission2.activeCheck = flag; activeMission2.reloadGoalsSourceFile = filename; activeMission2.requiredRank = num1; while (reader.Name != "endFunc") { reader.Read(); } reader.MoveToAttribute("val"); int num2 = reader.ReadContentAsInt(); reader.MoveToAttribute("name"); string str6 = reader.ReadContentAsString(); activeMission2.endFunctionName = str6; activeMission2.endFunctionValue = num2; while (reader.Name != "posting") { reader.Read(); } reader.MoveToAttribute("title"); string str7 = Folder.deFilter(reader.ReadContentAsString()); int content1 = (int)reader.MoveToContent(); string str8 = Folder.deFilter(reader.ReadElementContentAsString()); activeMission2.postingTitle = str7; activeMission2.postingBody = str8; return((object)activeMission2); }