/// <summary> /// Update the level's xml on disk. /// Does not change the level's timestamp. /// </summary> /// <param name="level"></param> public static void UpdateWorldXml(XmlWorldData xml) { try { string bucket = Utils.FolderNameFromFlags((Genres)xml.genres); string fullPath = BokuGame.Settings.MediaPath + bucket + xml.id.ToString() + @".Xml"; //make sure the world exists if (!Storage4.FileExists(fullPath, StorageSource.All)) { return; } if (xml != null) { bool isDownload = (xml.genres & (int)Genres.Downloads) != 0; // Manage the stream ourselves so avoid level timestamp being changed. Stream stream = Storage4.OpenWrite(fullPath); xml.Save(stream, isDownload); Storage4.Close(stream); } } catch (Exception e) { Debug.WriteLine(e.Message); } }
public static bool CheckWorldExistsByGenre(Guid worldId, Genres genres) { string bucket = BokuGame.MyWorldsPath; if (genres != 0) { bucket = Utils.FolderNameFromFlags(genres); if (bucket == null) { return(false); } } string fullPath = BokuGame.Settings.MediaPath + bucket + worldId.ToString() + @".Xml"; StorageSource sources = StorageSource.All; if ((genres & Genres.Downloads) != 0) { sources = StorageSource.UserSpace; } return(Storage4.FileExists(fullPath, sources)); }
private bool IsAlreadyDownloaded(LevelMetadata level) { string filename = BokuGame.Settings.MediaPath + BokuGame.DownloadsPath + level.WorldId.ToString() + @".Xml"; if (Storage4.FileExists(filename, StorageSource.UserSpace)) { XmlWorldData xml = XmlWorldData.Load(filename, XnaStorageHelper.Instance); if (xml != null) { LevelMetadata local = LevelMetadata.CreateFromXml(xml); return( local.WorldId == level.WorldId && local.Creator == level.Creator && local.LastWriteTime >= level.LastWriteTime); } } return(false); }
/// <summary> /// Loads Actors.xml and initializes the list of static actors. /// </summary> /// <remarks> /// The actors' model and xml file isn't loaded until LoadModels is called. /// </remarks> public static void LoadActors() { if (Storage4.FileExists(XmlActorsListFileName, StorageSource.TitleSpace)) { // Read our actor list from file var stream = Storage4.OpenRead(XmlActorsListFileName, StorageSource.TitleSpace); var serializer = new XmlSerializer(typeof(XmlActorsList)); var xmlActors = serializer.Deserialize(stream) as XmlActorsList; Storage4.Close(stream); if (xmlActors != null) { for (int i = 0; i < xmlActors.Actors.Length; i++) { var xmlStaticActor = xmlActors.Actors[i]; Actors.Add(xmlStaticActor.NonLocalizedName, new StaticActor(xmlStaticActor)); } } } else { Debug.Assert(false, "Missing actor file."); } }
/// <summary> /// Returns true on success, false if failed. /// </summary> public bool ReadFromXml(string filename) { bool success = true; // Fix up the filename with the full path. var defaultFile = Path.Combine(Localizer.DefaultLanguageDir, filename); // Read the Xml file into local data. XmlHelpTextData data = Load(defaultFile); // Build a dictionary with the default info var dict = new Dictionary <string, TweakScreenHelp.HelpText>(data.helpText.Count); foreach (var helpText in data.helpText) { dict[helpText.id] = helpText; } // Is our run-time local language different from the default? if (!Localizer.IsLocalDefault) { var localPath = Localizer.LocalLanguageDir; // Do we have a directory for the local language? if (localPath != null) { var localFile = Path.Combine(localPath, filename); if (Storage4.FileExists(localFile, StorageSource.All)) { var localData = Load(localFile); var localDict = new Dictionary <string, TweakScreenHelp.HelpText>(localData.helpText.Count); foreach (var helpText in localData.helpText) { localDict[helpText.id] = helpText; } // Replace as much of the default data as we can with localized data var keys = dict.Keys.ToArray(); foreach (var key in keys) { if (localDict.ContainsKey(key)) { if (Localizer.ShouldReportMissing && localDict[key].desc.Equals(dict[key].desc, StringComparison.OrdinalIgnoreCase)) { Localizer.ReportIdentical(filename, key); } dict[key] = localDict[key]; } else { Localizer.ReportMissing(filename, key); } } data.helpText = dict.Values.ToList(); } else { Localizer.ReportMissing(filename, "CAN'T FIND FILE!"); } } else { Localizer.ReportMissing(localPath, "CAN'T FIND PATH FOR THIS LANGUAGE!"); } } if (data == null) { success = false; } else { this.helpText = data.helpText; } return(success); } // end of XmlHelpTextData ReadFromXml()
private void ScrubTerrainFiles() { // Build a list of all terrain files in user storage. // For each world in local storage (all three bins) // get the XmlWorldData file // from the XmlWorldData file, get the terrain filename // remove that filename from the list // // Any terrain filenames still on the list should be deleted // since they're no longer referenced by any files. string[] terrainFiles = Storage4.GetFiles(BokuGame.Settings.MediaPath + BokuGame.TerrainPath, @"*.raw", StorageSource.UserSpace); // If nothing to scrub, just return. if (terrainFiles == null) { return; } string[] undoFiles = Storage4.GetFiles(BokuGame.Settings.MediaPath + BokuGame.UnDoPath, @"*.Xml", StorageSource.UserSpace); string[] myWorldsFiles = Storage4.GetFiles(BokuGame.Settings.MediaPath + BokuGame.MyWorldsPath, @"*.Xml", StorageSource.UserSpace); string[] starterWorldsFiles = Storage4.GetFiles(BokuGame.Settings.MediaPath + BokuGame.BuiltInWorldsPath, @"*.Xml", StorageSource.TitleSpace); string[] downloadsFiles = Storage4.GetFiles(BokuGame.Settings.MediaPath + BokuGame.DownloadsPath, @"*.Xml", StorageSource.UserSpace); /// Undo/Resume files. We might have to fall back on these if the user deletes the /// world they are editing and then back back to it. if (undoFiles != null) { for (int i = 0; i < undoFiles.Length; ++i) { string filename = undoFiles[i]; XmlWorldData xmlWorldData = XmlWorldData.Load(filename, XnaStorageHelper.Instance); if (xmlWorldData == null) { continue; } if (xmlWorldData.xmlTerrainData2 != null) { string terrainName = Path.Combine(Storage4.UserLocation, BokuGame.Settings.MediaPath, xmlWorldData.xmlTerrainData2.virtualMapFile); for (int j = 0; j < terrainFiles.Length; ++j) { if (terrainName == terrainFiles[j]) { // Remove this file. terrainFiles[j] = null; break; } } } } } // MyWorlds if (myWorldsFiles != null) { for (int i = 0; i < myWorldsFiles.Length; ++i) { string filename = myWorldsFiles[i]; XmlWorldData xmlWorldData = XmlWorldData.Load(filename, XnaStorageHelper.Instance); if (xmlWorldData == null) { continue; } if (xmlWorldData.xmlTerrainData2 != null) { string terrainName = Path.Combine(Storage4.UserLocation, BokuGame.Settings.MediaPath, xmlWorldData.xmlTerrainData2.virtualMapFile); for (int j = 0; j < terrainFiles.Length; ++j) { if (terrainName == terrainFiles[j]) { // Remove this file. terrainFiles[j] = null; break; } } } } } // BuiltInWorlds if (starterWorldsFiles != null) { for (int i = 0; i < starterWorldsFiles.Length; ++i) { try { string filename = starterWorldsFiles[i]; XmlWorldData xmlWorldData = XmlWorldData.Load(filename, XnaStorageHelper.Instance); if (xmlWorldData == null) { continue; } if (xmlWorldData.xmlTerrainData2 != null) { string terrainName = Path.Combine(Storage4.UserLocation, BokuGame.Settings.MediaPath, xmlWorldData.xmlTerrainData2.virtualMapFile); for (int j = 0; j < terrainFiles.Length; ++j) { if (terrainName == terrainFiles[j]) { // Remove this file. terrainFiles[j] = null; break; } } } } catch { } } } // Downloads if (downloadsFiles != null) { for (int i = 0; i < downloadsFiles.Length; ++i) { string filename = downloadsFiles[i]; XmlWorldData xmlWorldData = XmlWorldData.Load(filename, XnaStorageHelper.Instance); if (xmlWorldData == null) { continue; } if (xmlWorldData.xmlTerrainData2 != null) { string terrainName = Path.Combine(Storage4.UserLocation, BokuGame.Settings.MediaPath, xmlWorldData.xmlTerrainData2.virtualMapFile); for (int j = 0; j < terrainFiles.Length; ++j) { if (terrainName == terrainFiles[j]) { // Remove this file. terrainFiles[j] = null; break; } } } } } int deleteCount = 0; // Now, anything that's left in the list should be fair game for deletion. for (int i = 0; i < terrainFiles.Length; i++) { if (terrainFiles[i] != null) { if (Storage4.FileExists(terrainFiles[i], StorageSource.UserSpace)) { if (Storage4.Delete(terrainFiles[i])) { deleteCount += 1; } } } } //System.Diagnostics.Debug.WriteLine(String.Format("Scrubbed {0} terrain files", deleteCount)); } // end of ScrubTerrainFiles()