private void TestStorage() { GamePadInput pad = GamePadInput.GetGamePad0(); if (pad.ButtonY.WasPressed) { doTest = 0; } if (doTest >= 0) { string fileName = "Test0.dat"; if (!Storage4.FileExists(fileName)) { doTest = 0; } Stream writeStream = Storage4.OpenWrite(fileName); if (writeStream == null) { doTest = 0; } byte[] writeBytes = new byte[10000]; writeStream.Write(writeBytes, 0, writeBytes.Length); Storage4.Close(writeStream); if (!Storage4.FileExists(fileName)) { doTest = 0; } ++testsDone; } }
private void TestXml2() { GamePadInput pad = GamePadInput.GetGamePad0(); if (pad.ButtonY.WasPressed) { doTest = 0; } if (doTest >= 0) { if (!Storage4.FileExists(BokuGame.Settings.MediaPath + @"Xml\OptionsData.Xml")) { doTest = 0; /// This breakpoint isn't ever hit, OptionsData.xml exists here } Stream hoseStream = Storage4.OpenWrite(@"Xml\Hoser.xml"); XmlHose hoser = new XmlHose(); hoser.hoser = true; XmlSerializer serializer = new XmlSerializer(typeof(XmlHose)); serializer.Serialize(hoseStream, hoser); Storage4.Close(hoseStream); if (!Storage4.FileExists(BokuGame.Settings.MediaPath + @"Xml\OptionsData.Xml")) { doTest = 0; /// THis breakpoint is hit on failure, after the flush /// OptionsData.xml is not longer there. } ++testsDone; } }
/// <summary> /// Load current options data. /// </summary> /// <returns></returns> private static XmlOptionsData Load() { XmlOptionsData xmlData = null; Stream stream = null; DateTime xmlFileTime = new DateTime();//used to compare against InstallLanguage.txt try { // Try the real filename first. string xmlFileName = FileName(); if (Storage4.FileExists(xmlFileName, StorageSource.All)) { xmlFileTime = Storage4.GetLastWriteTimeUtc(xmlFileName, StorageSource.All); stream = Storage4.OpenRead(xmlFileName, StorageSource.All); XmlSerializer serializer = new XmlSerializer(typeof(XmlOptionsData)); xmlData = serializer.Deserialize(stream) as XmlOptionsData; } else { // If not there, try the back compat version. xmlFileName = BackCompatFileName(); if (Storage4.FileExists(xmlFileName, StorageSource.All)) { xmlFileTime = Storage4.GetLastWriteTimeUtc(xmlFileName, StorageSource.All); stream = Storage4.OpenRead(xmlFileName, StorageSource.All); XmlSerializer serializer = new XmlSerializer(typeof(XmlOptionsData)); xmlData = serializer.Deserialize(stream) as XmlOptionsData; } } } catch (Exception e) { Debug.WriteLine(e.Message); } if (stream != null) { Storage4.Close(stream); } //Check for override of language. if (xmlData != null && Storage4.FileExists(InstalledLanguageFileName(), StorageSource.All)) { var langFileTime = Storage4.GetLastWriteTimeUtc(InstalledLanguageFileName(), StorageSource.All); //If InstallerLanguage.txt is later than selected language. if (langFileTime > xmlFileTime) { //Update language to match newly installed version. xmlData.langauge = GetInstallerLanguageOrDefault(); Save(); } } return(xmlData); } // end of Load()
public UpdateObj(MainMenu parent, Shared shared) { this.parent = parent; this.shared = shared; #if DEBUG Debug.Assert(Storage4.FileExists(BokuGame.Settings.MediaPath + BokuGame.BuiltInWorldsPath + TrialModeLevelName, StorageSource.TitleSpace), "Trial mode level does not exist"); #endif }
public DateTime?LastUpdated(string language) { var resourcePath = Path.Combine(LanguageDir, language, Name); if (Storage4.FileExists(resourcePath, StorageSource.All)) { return(Storage4.GetLastWriteTimeUtc(resourcePath, StorageSource.All)); } return(null); }
private static string GetInstallerLanguageOrDefault() { if (Storage4.FileExists(InstalledLanguageFileName(), StorageSource.All)) { var lines = Storage4.ReadAllLines(InstalledLanguageFileName(), StorageSource.All); if (lines.Any()) { return(lines[0]); } } return("");//Default }
} // end of OpenFile /// <summary> /// /// </summary> /// <param name="fixup">Tells system to not use version with .. in it. Pure hack uglisness to maintain back compatibility.</param> /// <returns></returns> static private string NewFileName(bool fixup) { // If using the default path, step up one level in the tree. Else just use the path given by the user. string root = fixup ? @"Kode" : @"..\Kode"; string ext = @".txt"; string fmt = "D4"; int i = 0; while (Storage4.FileExists(root + i.ToString(fmt) + ext, StorageSource.UserSpace)) { ++i; } return(root + i.ToString(fmt) + ext); } // end of NewFileName()
/// <summary> /// Return whether there exists a valid file to resume from the last session. /// No file integrity is checked, just existence. /// </summary> /// <returns></returns> public static bool HaveResume() { int lastAuto = XmlOptionsData.LastAutoSave; if (lastAuto >= 0) { string fullPath = BokuGame.Settings.MediaPath + BokuGame.UnDoPath + @"AutoSave" + lastAuto.ToString() + @".Xml"; if (Storage4.FileExists(fullPath, StorageSource.UserSpace)) { return(true); } } return(false); }
public override void Activate() { // If we have a level to resume, check for the crashed cookie. If we find the cookie // delete it and activate the dialog letting the user know they can recover the level. if (InGame.UnDoStack.HaveResume()) { if (Storage4.FileExists(MainMenu.CrashCookieFilename, StorageSource.UserSpace)) { Storage4.Delete(MainMenu.CrashCookieFilename); parent.prevSessionCrashedMessage.Activate(); } } // Force feed to refresh rendering. shared.liveFeed.Dirty = true; // Start showing the current, signed-in creator. AuthUI.ShowStatusDialog(); }
private void TestXml() { GamePadInput pad = GamePadInput.GetGamePad0(); if (pad.ButtonY.WasPressed) { doTest = 0; } if (doTest >= 0) { if (!Storage4.FileExists(BokuGame.Settings.MediaPath + @"Xml\OptionsData.Xml")) { doTest = 0; } XmlOptionsData.UIVolume = XmlOptionsData.UIVolume; if (!Storage4.FileExists(BokuGame.Settings.MediaPath + @"Xml\OptionsData.Xml")) { doTest = 0; } ++testsDone; } }
/// <summary> /// Load a named resource, assuming file naming convention. /// </summary> /// <param name="name"></param> /// <returns></returns> public static XmlGameActor Deserialize(string name) { XmlGameActor xmlActor = null; string xmlFileName = Prefix + name + Suffix; if (Storage4.FileExists(xmlFileName, StorageSource.TitleSpace)) { Stream stream = Storage4.OpenRead(xmlFileName, StorageSource.TitleSpace); XmlSerializer serializer = new XmlSerializer(typeof(XmlGameActor)); xmlActor = serializer.Deserialize(stream) as XmlGameActor; Storage4.Close(stream); xmlActor.XmlFileName = xmlFileName; if (xmlActor != null) { xmlActor.OnLoad(); allActors.Add(xmlActor); } } else { //Debug.Assert(false, "Missing actor file"); } return(xmlActor); }
public static Crumb[] Init() { CrumbList crumbList = null; CrumbList crumbStrings = null; const string stringsFilename = @"TutorialStrings.Xml"; const string crumbsFilename = @"TutorialCrumbs.Xml"; // Get the actual crumb list. This contains all the mode links. // Note, since this no longer contains strings it is no longer inthe Localizable folder... string filename = Path.Combine(@"Content\Xml", crumbsFilename); if (Storage4.FileExists(filename, StorageSource.TitleSpace)) { crumbList = Load(filename, StorageSource.TitleSpace); } else { Debug.Assert(false, "Missing file!"); } // Now get the strings for each of the crumbs. // First we need to get the default, English version. Look in both user and title space // since the shipped version may have been superceeded by a downloaded one. if (Storage4.FileExists(Path.Combine(Localizer.DefaultLanguageDir, stringsFilename), StorageSource.All)) { crumbStrings = Load(Path.Combine(Localizer.DefaultLanguageDir, stringsFilename), StorageSource.All); } else { Debug.Assert(false, "Missing file!"); } Crumb[] result = null; if (crumbStrings != null) { // Start with list of crumbs. result = crumbList.Crumbs; // Now match up crumbs with their strings. foreach (Crumb crumb in result) { // Find matching strings and copy over. for (int i = 0; i < crumbStrings.Crumbs.Length; i++) { Crumb strCrumb = crumbStrings.Crumbs[i]; if (crumb.id == strCrumb.id) { crumb.gamepadText = strCrumb.gamepadText; crumb.mouseText = strCrumb.mouseText; crumb.touchText = strCrumb.touchText; } } } } // 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, stringsFilename); if (Storage4.FileExists(localFile, StorageSource.All)) { CrumbList localCrumbs = Load(localFile, StorageSource.All); if (result != null && localCrumbs != null) { // Loop over each of the crumbs we currently have... for (int i = 0; i < result.Length; i++) { var defCrumb = result[i]; var foundLocalCrumb = false; // Loop over each of the localized crumbs searching for a match to existing crumbs. for (int j = 0; j < localCrumbs.Crumbs.Length; j++) { var localCrumb = localCrumbs.Crumbs[j]; // If the crumbs are the same, override the default with the localized if (localCrumb.id == defCrumb.id) { if (Localizer.ShouldReportMissing && localCrumb.GamepadText.Equals(defCrumb.GamepadText, StringComparison.OrdinalIgnoreCase) && localCrumb.MouseText.Equals(defCrumb.MouseText, StringComparison.OrdinalIgnoreCase) && localCrumb.TouchText.Equals(defCrumb.TouchText, StringComparison.OrdinalIgnoreCase) ) { Localizer.ReportIdentical(stringsFilename, "TargetMode: " + defCrumb.TargetMode.ToString()); } // Copy any localized strings over. if (!string.IsNullOrEmpty(localCrumb.GamepadText)) { result[i].gamepadText = localCrumb.GamepadText; } if (!string.IsNullOrEmpty(localCrumb.MouseText)) { result[i].mouseText = localCrumb.MouseText; } if (!string.IsNullOrEmpty(localCrumb.TouchText)) { result[i].touchText = localCrumb.TouchText; } foundLocalCrumb = true; break; } } if (!foundLocalCrumb) { Localizer.ReportMissing(stringsFilename, "TargetMode: " + defCrumb.TargetMode.ToString()); } } } else { Localizer.ReportMissing(stringsFilename, "CAN'T LOAD CRUMBS!"); } } else { Localizer.ReportMissing(stringsFilename, "CAN'T FIND FILE!"); } } else { Localizer.ReportMissing(localPath, "CAN'T FIND PATH FOR THIS LANGUAGE!"); } } /* * // Output crumb data for GraphViz * foreach (Crumb crumb in result) * { * foreach (TutorialManager.GameMode curmode in crumb.CurModes) * { * Debug.Print(curmode.ToString() + " -> " + crumb.targetMode.ToString() + " [ label = \" \" ];"); * } * } */ return(result); } // end of Init()
public static Dictionary <string, List <string> > ReadToDictionary(string fileName, int startDepth, StorageSource source, string testName) { // DebugLog.WriteLine("ReadToDictionary2"); // Setup our result dictionary var result = new Dictionary <string, List <string> >(StringComparer.OrdinalIgnoreCase); // If we can't find the given file, we'll return the empty dictionary if (!Storage4.FileExists(fileName, source)) { // DebugLog.WriteLine(" failed read, can't find file : " + fileName + " " + source.ToString()); Debug.Assert(false, "We're trying to read a localization file that doesn't exist!"); Localizer.ReportMissing(Path.GetFileName(fileName), "CAN'T FIND FILE!"); return(result); } #if NETFX_CORE XmlReader reader = null; #else XmlTextReader reader = null; #endif Stream stream = null; try { // Open our file // DebugLog.WriteLine(" open : " + fileName); stream = Storage4.OpenRead(fileName, StorageSource.All); // Create our xml reader #if NETFX_CORE XmlReaderSettings settings = new XmlReaderSettings(); settings.ConformanceLevel = ConformanceLevel.Fragment; settings.IgnoreWhitespace = true; settings.IgnoreComments = true; reader = XmlReader.Create(stream, settings); #else // DebugLog.WriteLine(" create reader"); reader = new XmlTextReader(stream); #endif // DebugLog.WriteLine(" advance reader"); // Advance the reader to the specified start depth while (reader.Depth < startDepth && reader.Read()) { ; } // Create a stack that will be used as a scratch var for // keeping track of the current node tree. var nodeTree = new Stack <string>(); var attributeDepth = 0; // Tracks the number of attributes we've read var isEmpty = false; // Is the element our reader is in empty? bool firstElement = true; // Is this the first element we've found? // DebugLog.WriteLine(" read XML"); // Read the XML { LoopStart: // Push to the tree switch (reader.NodeType) { case XmlNodeType.Element: if (!reader.IsEmptyElement || reader.HasAttributes) { const char trimChar = '_'; nodeTree.Push(reader.LocalName.TrimStart(trimChar)); isEmpty = reader.IsEmptyElement; } break; case XmlNodeType.Attribute: nodeTree.Push(reader.LocalName); break; } // Grab reader value switch (reader.NodeType) { case XmlNodeType.Attribute: case XmlNodeType.CDATA: case XmlNodeType.Text: // Grab the element list var es = nodeTree.ToArray(); // Change LIFO to FIFO ordering Array.Reverse(es); // Concat with dots var key = String.Join(".", es); // Get or create a dictionary value List <string> val; if (!result.TryGetValue(key, out val)) { result[key] = val = new List <string>(); } // Add localization text to dictionary val.Add(reader.Value); break; } // Pop from the tree switch (reader.NodeType) { case XmlNodeType.EndElement: nodeTree.Pop(); break; case XmlNodeType.Attribute: nodeTree.Pop(); if (reader.AttributeCount == attributeDepth && isEmpty) { nodeTree.Pop(); } break; } if (reader.IsEmptyElement) { } // If this node has attributes or if the reader still has // content at the desired depth, keep reading if (reader.MoveToNextAttribute()) { attributeDepth++; goto LoopStart; } else if (reader.Read() && reader.Depth >= startDepth) { // The way this code is set up we can't tell the difference between one file and another. // So, we pass in testName which should be the name of the first element in the file. // If this doesn't match, assume we've got a bad file and bail. if (firstElement) { if (!string.IsNullOrWhiteSpace(testName) && reader.Name != testName) { //throw new Exception(); } firstElement = false; } attributeDepth = 0; goto LoopStart; } } } catch { result = null; } #if NETFX_CORE if (reader != null) { reader.Dispose(); } #else if (reader != null) { reader.Close(); } #endif if (stream != null) { stream.Close(); } return(result); }
public static void LoadContent(bool immediate) { if (instance != null) { return; } try { var defaultFile = Path.Combine(Localizer.DefaultLanguageDir, LocalizationResourceManager.HelpResource.Name); // Load for the default language instance = Load(defaultFile); // 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, LocalizationResourceManager.HelpResource.Name); if (Storage4.FileExists(localFile, StorageSource.All)) { var localData = Load(localFile); // Override the defaults with localized text var keys = instance.actorHelp.Keys.ToArray(); foreach (var key in keys) { if (localData.actorHelp.ContainsKey(key)) { if (Localizer.ShouldReportMissing && !localData.actorHelp[key].description.Equals(instance.actorHelp[key].description, StringComparison.OrdinalIgnoreCase)) { Localizer.ReportIdentical(LocalizationResourceManager.HelpResource.Name, key); } instance.actorHelp[key] = localData.actorHelp[key]; } else { Localizer.ReportMissing(LocalizationResourceManager.HelpResource.Name, key); } } // For the programming examples, we'll just override everything //ToDo (DZ): Is this the behavior we want? Comparing examples // is harder than most localization info because we don't have // upids. This comparision is possible but it would end up // being more fragile and it may not be worth the trouble. // An ideal solution would be to come up with a guid for each // example. instance.programmingExamples = localData.programmingExamples; } else { Localizer.ReportMissing(LocalizationResourceManager.HelpResource.Name, "CAN'T FIND FILE!"); } } else { Localizer.ReportMissing(localPath, "CAN'T FIND PATH FOR THIS LANGUAGE!"); } } } catch { instance = new Help(); } if (instance.programmingExamples == null) { instance.programmingExamples = new List <ExamplePage>(); } if (instance.actorHelp == null) { instance.actorHelp = new XmlSerializableDictionary <string, ActorHelp>(); } #if DEBUG //if (instance.programmingExamples.Count == 0) //instance.LoadWithSampleData(); #endif // Make sure we only have valid characters in our descriptions. List <ExamplePage> set = instance.programmingExamples; for (int i = 0; i < set.Count; i++) { set[i].description = TextHelper.FilterInvalidCharacters(set[i].description); } }
public override void Update() { shared.timer.Update(); // Keep Kodu animating even if a dialog is active. shared.boku.UpdateFace(); shared.boku.UpdateAnimations(); if (AuthUI.IsModalActive) { return; } if (parent.newWorldDialog.Active) { parent.newWorldDialog.Update(); return; } // If not modal, always show status. AuthUI.ShowStatusDialog(); // Update the dialogs. parent.prevSessionCrashedMessage.Update(); parent.noCommunityMessage.Update(); parent.noSharingMessage.Update(); // Don't do anything else until the user reads and dismisses the dialogs. if (parent.prevSessionCrashedMessage.Active || parent.exitingKodu) { return; } // Update the options menu. Do this first so that if it is active it can steal input. shared.optionsMenu.Update(); // Main menu should always be active. shared.menu.Active = true; // If OptionsMenu is active, don't look at input. This is a problem for touch input // which doesn't support any kind of "ClearAllWasPressedState" functionality. if (!shared.optionsMenu.Active) { // Check for click on signOut tile or url. if (MouseInput.Left.WasPressed || Actions.Select.WasPressed || TouchInput.WasTouched) { TouchContact touch = TouchInput.GetOldestTouch(); if (touch != null) { touch.position = ScreenWarp.ScreenToRT(touch.position); } Vector2 mouseHit = MouseInput.GetMouseInRtCoords(); // url is in rt coords. if (shared.urlBox.Contains(mouseHit) || (null != touch && shared.urlBox.Contains(touch.position))) { #if NETFX_CORE Launcher.LaunchUriAsync(new Uri(KoduGameLabUrl)); #else Process.Start(KoduGameLabUrl); #endif MouseInput.Left.ClearAllWasPressedState(); } } // Enable resume option if we have something to resume to. if (InGame.UnDoStack.HaveResume() && (shared.menu.Item(0) != Strings.Localize("mainMenu.resume"))) { shared.menu.InsertText(Strings.Localize("mainMenu.resume"), 0); } shared.liveFeed.UpdateFeed(); shared.liveFeed.Update(shared.camera); if (!UpdateNonMenuItems()) { // JW - Only update the menu and process input if the interactive non-menu // items didn't already handle the input. int curIndex = shared.menu.CurIndex; shared.menu.Update(shared.camera, ref shared.worldMatrix); int newIndex = shared.menu.CurIndex; // If the user made a menu change, have boku glance over. if (curIndex != newIndex) { shared.boku.DirectGaze(new Vector3(0.2f, -0.4f, 0.08f - 0.05f * newIndex), 0.5f); } } } if (Actions.MiniHub.WasPressed && InGame.XmlWorldData != null) { parent.Deactivate(); InGame.inGame.SwitchToMiniHub(); return; } #if IMPORT_DEBUG if (!string.IsNullOrEmpty(StartupWorldFilename)) { LevelPackage.DebugPrint("MainMenu"); LevelPackage.DebugPrint(" StartupWorldFilename : " + StartupWorldFilename); } #endif // Jump into the startup world, if it was specified. if (!String.IsNullOrEmpty(StartupWorldFilename)) { if (Storage4.FileExists(StartupWorldFilename, StorageSource.All)) { #if IMPORT_DEBUG LevelPackage.DebugPrint(" level exists, trying to load and run"); #endif if (BokuGame.bokuGame.inGame.LoadLevelAndRun(StartupWorldFilename, keepPersistentScores: false, newWorld: false, andRun: true)) { #if IMPORT_DEBUG LevelPackage.DebugPrint(" success on load and run"); #endif parent.Deactivate(); } #if IMPORT_DEBUG else { LevelPackage.DebugPrint(" fail to load and run"); } #endif shared.waitingForStorage = false; } #if IMPORT_DEBUG else { LevelPackage.DebugPrint(" level not found"); } #endif StartupWorldFilename = null; } // Set news feed state to opposite of options menu. This allows the // News Feed to "hide" when the Options Menu is active. if (shared.optionsMenu.Active) { shared.liveFeed.Deactivate(); } else { shared.liveFeed.Activate(); shared.liveFeed.UpdateFeed(); } } // end of Update()