public static ExtensionInfo ReadExtensionInfo(string folderpath) { if (!ExtensionInfo.ExtensionExists(folderpath)) { throw new FileNotFoundException("No extension info exists for folder " + folderpath); } ExtensionInfo extensionInfo = new ExtensionInfo(); extensionInfo.FolderPath = folderpath; extensionInfo.Language = "en-us"; using (FileStream fileStream = File.OpenRead(folderpath + "/ExtensionInfo.xml")) { XmlReader xmlReader = XmlReader.Create((Stream)fileStream); while (!xmlReader.EOF) { if (xmlReader.Name == "Name") { int content = (int)xmlReader.MoveToContent(); extensionInfo.Name = Utils.CleanStringToLanguageRenderable(xmlReader.ReadElementContentAsString()); } if (xmlReader.Name == "Language") { int content = (int)xmlReader.MoveToContent(); extensionInfo.Language = xmlReader.ReadElementContentAsString(); } if (xmlReader.Name == "AllowSaves") { int content = (int)xmlReader.MoveToContent(); extensionInfo.AllowSave = xmlReader.ReadElementContentAsBoolean(); } if (xmlReader.Name == "StartingVisibleNodes") { int content = (int)xmlReader.MoveToContent(); string str = xmlReader.ReadElementContentAsString(); extensionInfo.StartingVisibleNodes = str.Split(new char[6] { ',', ' ', '\t', '\n', '\r', '/' }, StringSplitOptions.RemoveEmptyEntries); } if (xmlReader.Name == "StartingMission") { int content = (int)xmlReader.MoveToContent(); extensionInfo.StartingMissionPath = xmlReader.ReadElementContentAsString(); if (extensionInfo.StartingMissionPath == "NONE") { extensionInfo.StartingMissionPath = (string)null; } } if (xmlReader.Name == "StartingActions") { int content = (int)xmlReader.MoveToContent(); extensionInfo.StartingActionsPath = xmlReader.ReadElementContentAsString(); if (extensionInfo.StartingActionsPath == "NONE") { extensionInfo.StartingActionsPath = (string)null; } } if (xmlReader.Name == "Description") { int content = (int)xmlReader.MoveToContent(); extensionInfo.Description = Utils.CleanFilterStringToRenderable(xmlReader.ReadElementContentAsString()); } if (xmlReader.Name == "Faction") { int content = (int)xmlReader.MoveToContent(); extensionInfo.FactionDescriptorPaths.Add(xmlReader.ReadElementContentAsString()); } if (xmlReader.Name == "StartsWithTutorial") { int content = (int)xmlReader.MoveToContent(); extensionInfo.StartsWithTutorial = xmlReader.ReadElementContentAsString().ToLower() == "true"; } if (xmlReader.Name == "HasIntroStartup") { int content = (int)xmlReader.MoveToContent(); extensionInfo.HasIntroStartup = xmlReader.ReadElementContentAsString().ToLower() == "true"; } if (xmlReader.Name == "StartingTheme") { int content = (int)xmlReader.MoveToContent(); string lower = xmlReader.ReadElementContentAsString().ToLower(); extensionInfo.Theme = lower; } if (xmlReader.Name == "IntroStartupSong") { int content = (int)xmlReader.MoveToContent(); string str = xmlReader.ReadElementContentAsString(); extensionInfo.IntroStartupSong = str; } if (xmlReader.Name == "IntroStartupSongDelay") { int content = (int)xmlReader.MoveToContent(); float num = xmlReader.ReadElementContentAsFloat(); extensionInfo.IntroStartupSongDelay = num; } if (xmlReader.Name == "SequencerSpinUpTime") { int content = (int)xmlReader.MoveToContent(); float num = xmlReader.ReadElementContentAsFloat(); extensionInfo.SequencerSpinUpTime = num; } if (xmlReader.Name == "ActionsToRunOnSequencerStart") { int content = (int)xmlReader.MoveToContent(); string str = xmlReader.ReadElementContentAsString(); extensionInfo.ActionsToRunOnSequencerStart = str; } if (xmlReader.Name == "SequencerFlagRequiredForStart") { int content = (int)xmlReader.MoveToContent(); string str = xmlReader.ReadElementContentAsString(); extensionInfo.SequencerFlagRequiredForStart = str; } if (xmlReader.Name == "SequencerTargetID") { int content = (int)xmlReader.MoveToContent(); string str = xmlReader.ReadElementContentAsString(); extensionInfo.SequencerTargetID = str; } if (xmlReader.Name == "WorkshopDescription") { int content = (int)xmlReader.MoveToContent(); extensionInfo.WorkshopDescription = xmlReader.ReadElementContentAsString(); } if (xmlReader.Name == "WorkshopVisibility") { int content = (int)xmlReader.MoveToContent(); extensionInfo.WorkshopVisibility = (byte)xmlReader.ReadElementContentAsInt(); } if (xmlReader.Name == "WorkshopTags") { int content = (int)xmlReader.MoveToContent(); extensionInfo.WorkshopTags = xmlReader.ReadElementContentAsString(); } if (xmlReader.Name == "WorkshopPreviewImagePath") { int content = (int)xmlReader.MoveToContent(); extensionInfo.WorkshopPreviewImagePath = xmlReader.ReadElementContentAsString(); } if (xmlReader.Name == "WorkshopLanguage") { int content = (int)xmlReader.MoveToContent(); extensionInfo.WorkshopLanguage = xmlReader.ReadElementContentAsString(); } if (xmlReader.Name == "WorkshopPublishID") { int content = (int)xmlReader.MoveToContent(); extensionInfo.WorkshopPublishID = xmlReader.ReadElementContentAsString(); } xmlReader.Read(); } } string path = folderpath + "/Logo"; bool flag = false; if (File.Exists(path + ".png")) { path += ".png"; flag = true; } else if (File.Exists(path + ".jpg")) { path += ".png"; flag = true; } if (flag) { using (FileStream fileStream = File.OpenRead(path)) extensionInfo.LogoImage = Texture2D.FromStream(Game1.getSingleton().GraphicsDevice, (Stream)fileStream); } return(extensionInfo); }
public static void LoadNewExtensionSession(ExtensionInfo info, object os_obj) { LocaleActivator.ActivateLocale(info.Language, Game1.getSingleton().Content); OS os = (OS)os_obj; People.ReInitPeopleForExtension(); if (Directory.Exists(info.FolderPath + "/Nodes")) { Utils.ActOnAllFilesRevursivley(info.FolderPath + "/Nodes", (Action <string>)(filename => { if (!filename.EndsWith(".xml")) { return; } if (OS.TestingPassOnly) { try { Computer c = Computer.loadFromFile(filename); if (c != null) { ExtensionLoader.CheckAndAssignCoreServer(c, os); } } catch (Exception ex) { string format = "COMPUTER LOAD ERROR:\nError loading computer \"{0}\""; Exception exception = ex; string message = string.Format(format, (object)filename); for (; exception != null; exception = exception.InnerException) { string str = string.Format("\r\nError: {0} - {1}", (object)exception.GetType().Name, (object)exception.Message); message += str; } throw new FormatException(message, ex); } } else { Computer c = Computer.loadFromFile(filename); if (c != null) { ExtensionLoader.CheckAndAssignCoreServer(c, os); } } })); } if (ComputerLoader.postAllLoadedActions != null) { ComputerLoader.postAllLoadedActions(); } if (Programs.getComputer(os, "jmail") == null) { Computer c = new Computer("JMail Email Server", NetworkMap.generateRandomIP(), new Vector2(0.8f, 0.2f), 6, (byte)1, os); c.idName = "jmail"; c.daemons.Add((Daemon) new MailServer(c, "JMail", os)); MailServer.shouldGenerateJunk = false; c.users.Add(new UserDetail(os.defaultUser.name, "mailpassword", (byte)2)); c.initDaemons(); os.netMap.mailServer = c; os.netMap.nodes.Add(c); } for (int index = 0; index < info.StartingVisibleNodes.Length; ++index) { Computer computer = Programs.getComputer(os, info.StartingVisibleNodes[index]); if (computer != null) { os.netMap.discoverNode(computer); } } for (int index = 0; index < info.FactionDescriptorPaths.Count; ++index) { string path = info.FolderPath + "/" + info.FactionDescriptorPaths[index]; using (FileStream fileStream = File.OpenRead(path)) { try { Faction faction = Faction.loadFromSave(XmlReader.Create((Stream)fileStream)); os.allFactions.factions.Add(faction.idName, faction); } catch (Exception ex) { throw new FormatException("Error loading Faction: " + path, ex); } } } OSTheme theme = OSTheme.Custom; bool flag = false; foreach (object obj in Enum.GetValues(typeof(OSTheme))) { if (obj.ToString().ToLower() == info.Theme) { theme = (OSTheme)obj; flag = true; } } if (!flag) { if (File.Exists(info.FolderPath + "/" + info.Theme)) { ThemeManager.setThemeOnComputer((object)os.thisComputer, info.Theme); ThemeManager.switchTheme((object)os, info.Theme); } } else { ThemeManager.setThemeOnComputer((object)os.thisComputer, theme); ThemeManager.switchTheme((object)os, theme); } ExtensionLoader.LoadExtensionStartTrackAsCurrentSong(info); if (info.StartingActionsPath != null) { RunnableConditionalActions.LoadIntoOS(info.StartingActionsPath, (object)os); } if (info.StartingMissionPath == null || info.StartsWithTutorial || info.HasIntroStartup) { return; } ExtensionLoader.SendStartingEmailForActiveExtensionNextFrame((object)os); }