コード例 #1
0
        public static void LoadContent(bool immediate)
        {
            if (ShouldReportMissing)
            {
                if (reportWriter == null)
                {
                    reportPath = ReportFile;
                    try
                    {
                        reportWriter = Storage4.OpenStreamWriter(reportPath);
                    }
                    catch (Exception e)
                    {
                        if (e != null)
                        {
                        }

#if NETFX_CORE
                        MessageDialog dialog = new MessageDialog("reportPath = " + reportPath + "\nLoadContent failure in Localizer.");
#else
                        System.Windows.Forms.MessageBox.Show(
                            "reportPath = " + reportPath,
                            "LoadContent failure in Localizer.",
                            System.Windows.Forms.MessageBoxButtons.OK,
                            System.Windows.Forms.MessageBoxIcon.Asterisk);
#endif
                    }
                }
            }
        }
コード例 #2
0
        private static void GetLocalesCallback(IAsyncResult asyncResult)
        {
            // DebugLog.WriteLine("GetLocalesCallback()");
            try
            {
                // DebugLog.WriteLine("    get request");
                var request = (HttpWebRequest)asyncResult.AsyncState;
                // DebugLog.WriteLine("    get response");
                var response = (HttpWebResponse)request.EndGetResponse(asyncResult);
                // DebugLog.WriteLine("    get stream");
                var responseStream = response.GetResponseStream();

                bool persist = true;
                // If disk version is newer than online version, don't persist.  This
                // should only happen when a user is adding a new language.  In this
                // case we want ehm to be able to modify their local copy.
                DateTime lastModTime = Storage4.GetLastWriteTimeUtc(LocalesFilePath, StorageSource.UserSpace);
#if NETFX_CORE
                // For WindowsStore build .LastModified is not supported so just always persist file.
                if (true)
#else
                if (lastModTime > response.LastModified)
#endif
                {
                    persist = false;
                }

                // DebugLog.WriteLine("    persist : " + persist.ToString());

                if (persist)
                {
                    // DebugLog.WriteLine("    Populating from XML stream.");
                    PopulatesLocalesFromXmlStream(responseStream, persist);
                }
                else
                {
                    // DebugLog.WriteLine("    Getting from file.");
                    GetLocalesFromFile();
                }
            }
            catch (Exception e)
            {
                // Keep the compiler quiet when LOCALES_DEBUG not defined.
                if (e != null)
                {
                    // DebugLog.WriteException(e, "GetLocalesCallback()");
                }
#if LOCALES_DEBUG
                LocalesDebugPrint("Exception thrown in GetLocalesCallback()\n" + e.ToString());
#endif
            }
            finally
            {
                if (_locales == null)
                {
                    // DebugLog.WriteLine("    Safe get from file.");
                    SafeGetLocalesFromFile();
                }
            }
        }
コード例 #3
0
        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;
            }
        }
コード例 #4
0
        public static bool Load()
        {
            bool result = false;

            Stream stream = null;

            try
            {
                XmlSerializer xml = new XmlSerializer(typeof(SiteID));

                stream = Storage4.OpenRead(MyFilename, StorageSource.UserSpace);

                Instance = (SiteID)xml.Deserialize(stream);

                result = true;
            }
            catch { }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
            }

            return(result);
        }
コード例 #5
0
        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;
            }
        }
コード例 #6
0
        /// <summary>
        /// Attempts to read Locales.xml from local storage.
        /// </summary>
        private static void GetLocalesFromFile()
        {
            // DebugLog.WriteLine("GetLocalesFromFile()");
            try
            {
                // DebugLog.WriteLine("    open stream for read.");
                var localesFileStream = Storage4.OpenRead(LocalesFilePath, StorageSource.All);
                // DebugLog.WriteLine("    read.");
                PopulatesLocalesFromXmlStream(localesFileStream);
#if LOCALES_DEBUG
                LocalesDebugPrint("In GetLocalesFromFile()");
                foreach (Locale loc in Locales)
                {
                    LocalesDebugPrint(loc.ToString());
                }
#endif
            }
            catch (Exception e)
            {
                // Keep the compiler quiet when LOCALES_DEBUG not defined.
                if (e != null)
                {
                    // DebugLog.WriteException(e, "GetLocalesFromFile()");
                }
#if LOCALES_DEBUG
                LocalesDebugPrint("Exception thrown in GetLocalesFromFile()\n" + e.ToString());
#endif
            }
        }
コード例 #7
0
        /// <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()
コード例 #8
0
        public void Serialize(string filepath)
        {
            string        pathName   = MapFolder + filepath;
            XmlSerializer serializer = new XmlSerializer(typeof(CommandMap));
            Stream        stream     = Storage4.OpenWrite(pathName);

            serializer.Serialize(stream, this);
            Storage4.Close(stream);
        }
コード例 #9
0
ファイル: MainMenu.cs プロジェクト: eanders-MS/KoduGameLab-1
            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
            }
コード例 #10
0
        public void Save()
        {
            XmlSerializer xml = new XmlSerializer(typeof(SiteOptions));

            Stream stream = Storage4.OpenWrite(MyFilename);

            xml.Serialize(stream, this);

            stream.Close();
        }
コード例 #11
0
            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);
            }
コード例 #12
0
        }   // end of Render()

        #endregion

        #region Internal

        public void LoadContent(bool immediate)
        {
            titleBarTexture   = BokuGame.Load <Texture2D>(BokuGame.Settings.MediaPath + @"Textures\GridElements\BlueTextTileWide");
            dialogBodyTexture = BokuGame.Load <Texture2D>(BokuGame.Settings.MediaPath + @"Textures\LoadLevel\PopupFrame");

            // Get thumbnails for levels.
            foreach (NewWorldLevel level in levels)
            {
                level.ThumbnailTexture = Storage4.TextureLoad(level.ThumbnailName);
            }
        }
コード例 #13
0
        public static SiteOptions Load(StorageSource sources)
        {
            XmlSerializer xml = new XmlSerializer(typeof(SiteOptions));

            Stream stream = Storage4.OpenRead(MyFilename, sources);

            SiteOptions result = (SiteOptions)xml.Deserialize(stream);

            stream.Close();

            return(result);
        }
コード例 #14
0
ファイル: Print.cs プロジェクト: Yash-Codemaster/KoduGameLab
        }   // end of GetFullPath()

        static private TextWriter OpenFile(string fullPath)
        {
            TextWriter tw = null;

#if NETFX_CORE
            tw = Storage4.OpenStreamWriter(fullPath);
#else
            tw = new StreamWriter(fullPath);
#endif

            return(tw);
        }   // end of OpenFile
コード例 #15
0
 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
 }
コード例 #16
0
        }   // end of SetXButton()

        public override void Update(ref Matrix parentMatrix)
        {
            // Check for input but only if selected.
            if (selected)
            {
                GamePadInput pad = GamePadInput.GetGamePad0();

                if (Actions.Select.WasPressed)
                {
                    Actions.Select.ClearAllWasPressedState();

                    onSetNextLevel();
                }

                if (Actions.X.WasPressed)
                {
                    Actions.X.ClearAllWasPressedState();

                    NextLevel = null;
                    if (onClear != null)
                    {
                        onClear();
                    }
                }
            }

            //load thumbnail if it hasn't loaded yet
            if (nextLevel != null && !nextLevel.Thumbnail.IsLoaded)
            {
                if (nextLevel.ThumbnailBytes == null)
                {
                    string texFilename = BokuGame.Settings.MediaPath + Utils.FolderNameFromFlags(nextLevel.Genres) + nextLevel.WorldId.ToString();
                    Stream texStream   = Storage4.TextureFileOpenRead(texFilename);
                    if (texStream != null)
                    {
                        nextLevel.Thumbnail.Texture = Storage4.TextureLoad(texStream);
                        Storage4.Close(texStream);
                    }
                }
                else
                {
                    MemoryStream stream = new MemoryStream(nextLevel.ThumbnailBytes);
                    nextLevel.Thumbnail.Texture = Storage4.TextureLoad(stream);
                    nextLevel.ThumbnailBytes    = null;
                }
            }

            //refresh the render target
            RefreshTexture();

            base.Update(ref parentMatrix);
        }   // end of UIGridModularCheckboxElement Update()
コード例 #17
0
        public void Save()
        {
            XmlSerializer xml = new XmlSerializer(typeof(SiteID));

            Stream stream = Storage4.OpenWrite(MyFilename);

            if (stream != null)
            {
                xml.Serialize(stream, this);

                stream.Close();
            }
        }
コード例 #18
0
        }   // end of HeightMap c'tor

        /// <summary>
        /// Writes the current height map to a file.
        /// </summary>
        /// <param name="filename"></param>
        public void Save(string filename)
        {
            Stream       fs = Storage4.OpenWrite(filename);
            BinaryWriter bw = new BinaryWriter(fs);

            Save(bw);

#if NETFX_CORE
            bw.Flush();
            bw.Dispose();
#else
            bw.Close();
#endif
            Storage4.Close(fs);
        }   // end of HeightMap Save()
コード例 #19
0
ファイル: Print.cs プロジェクト: Yash-Codemaster/KoduGameLab
        }   // 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()
コード例 #20
0
        public HeightMap(string filename, Point size, Vector3 scale)
        {
            this.filename = filename;
            Init(Vector2.Zero, size, scale);
            // Load the heightmap.
            Stream       fs = Storage4.OpenRead(filename, StorageSource.All);
            BinaryReader br = new BinaryReader(fs);

            Load(br);

#if NETFX_CORE
            br.Dispose();
#else
            br.Close();
#endif
            Storage4.Close(fs);
        }   // end of HeightMap c'tor
コード例 #21
0
ファイル: Help.cs プロジェクト: Yash-Codemaster/KoduGameLab
        public static void UnloadContent()
        {
            if (instance == null)
            {
                return;
            }
#if DEBUG
            try
            {
                Stream        stream     = Storage4.OpenWrite(LocalizationResourceManager.HelpResource.Name);
                XmlSerializer serializer = new XmlSerializer(typeof(Help));
                serializer.Serialize(stream, instance);
                Storage4.Close(stream);
            }
            catch { }
#endif
        }
コード例 #22
0
            public void Update(string language, string newResource)
            {
                var resourcePath = Path.Combine(LanguageDir, language, Name);
                var resourceXml  = XDocument.Load(XmlReader.Create(new StringReader(newResource)));

                Encoding encoding = null;

                // Ensure that the declared XML encoding is used while saving the file when available
                if (resourceXml.Declaration != null && !string.IsNullOrEmpty(resourceXml.Declaration.Encoding))
                {
                    encoding = GetEncoding(resourceXml.Declaration.Encoding);
                }
                using (var streamWriter = Storage4.OpenStreamWriter(resourcePath, encoding))
                {
                    streamWriter.Write(newResource);
                }
            }
コード例 #23
0
            /// <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);
            }
コード例 #24
0
ファイル: MainMenu.cs プロジェクト: eanders-MS/KoduGameLab-1
            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();
            }
コード例 #25
0
        public static Dictionary <string, List <string> > ReadToDictionary(string fileName, string testName)
        {
            // DebugLog.WriteLine("ReadToDictionary1");

            Dictionary <string, List <string> > dict = null;

            dict = ReadToDictionary(fileName, 1, StorageSource.All, testName);

            if (dict == null)
            {
                // DebugLog.WriteLine("    failed read, trying titlespace");
                // If we're here the file read failed.  This seems to happen when the
                // version downloaded from the server is bad.  So, delete the file
                // so it gets downloaded again on next startup and then read the file
                // from the TitleSpace.
                Storage4.Delete(fileName);
                dict = ReadToDictionary(fileName, 1, StorageSource.TitleSpace, testName);
            }

            return(dict);
        }
コード例 #26
0
        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;
            }
        }
コード例 #27
0
        }   // end of XmlHelpScreensData ReadFromXml()

        private static XmlHelpScreensData Load(string filename)
        {
            // Fix up the filename with the full path.
            filename = BokuGame.Settings.MediaPath + @"Xml\" + filename;

            XmlHelpScreensData data = null;

            try
            {
                Stream stream = Storage4.OpenRead(filename, StorageSource.All);

                XmlSerializer serializer = new XmlSerializer(typeof(XmlHelpScreensData));
                data = (XmlHelpScreensData)serializer.Deserialize(stream);
                Storage4.Close(stream);
            }
            catch (Exception)
            {
                data = null;
            }

            return(data);
        } // end of XmlHelpScreensData Load()
コード例 #28
0
        }   // end of Load()

        private static void Save()
        {
            Stream stream = null;

            try
            {
                string xmlFileName = FileName();

                XmlSerializer serializer = new XmlSerializer(typeof(XmlOptionsData));
                stream = Storage4.OpenWrite(xmlFileName);
                serializer.Serialize(stream, _instance);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }

            if (stream != null)
            {
                Storage4.Close(stream);
            }
        }   // end of Save()
コード例 #29
0
        static protected CommandMap Deserialize(string filepath)
        {
            string     oldPathName = Storage4.TitleLocation + MapFolder + filepath;
            string     pathName    = MapFolder + filepath;
            CommandMap profile;

//            try
            {
                Stream        stream     = Storage4.OpenRead(pathName, StorageSource.TitleSpace);
                XmlSerializer serializer = new XmlSerializer(typeof(CommandMap));
                profile = (CommandMap)serializer.Deserialize(stream);
                Storage4.Close(stream);
            }

/*
 *          catch (FileNotFoundException ex)
 *          {
 *              profile = new CommandMap();
 *              profile.Serialize(pathName);
 *          }
 */
            return(profile);
        }
コード例 #30
0
        /// <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);
        }