Пример #1
0
        ///// ------------------------------------------------------------------------------------
        ///// <summary>
        ///// Asks the user to specify a TMX file for saving TMX information.
        ///// </summary>
        ///// ------------------------------------------------------------------------------------
        //public static string AskForTMXFileAndWrite(TMXDocument tmxDoc)
        //{
        //    using (SaveFileDialog dlg = new SaveFileDialog())
        //    {
        //        dlg.OverwritePrompt = true;
        //        dlg.Title = Properties.Resources.kstidTMXSFDCaption;
        //        dlg.Filter = Properties.Resources.kstidTMXOpenAndSaveDlgFilter;
        //        DialogResult result = dlg.ShowDialog();
        //        if (result == DialogResult.Cancel)
        //            return null;

        //        Write(tmxDoc, dlg.FileName);
        //        return dlg.FileName;
        //    }
        //}

        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Writes the specified TMXDocument information to the specified TMX file.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public static void Write(TMXDocument tmxDoc, string tmxFile)
        {
            if (tmxDoc == null)
            {
                throw new ArgumentNullException("tmxDoc");
            }

            TMXXmlSerializationHelper.SerializeToFile(tmxFile, tmxDoc);
        }
Пример #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Saves the TMXDocument to the specified TMX file.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void Save(string tmxFile)
        {
            var dir = Path.GetDirectoryName(tmxFile);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            TMXXmlSerializationHelper.SerializeToFile(tmxFile, this);
        }
Пример #3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Reads the specified TMX file and returns a TMXDocument containing the information
        /// in the file.
        /// </summary>
        /// <param name="tmxFile">The TMX file to read.</param>
        /// ------------------------------------------------------------------------------------
        public static TMXDocument Read(string tmxFile)
        {
            if (!File.Exists(tmxFile))
            {
                throw new FileNotFoundException("TMX file not found.", tmxFile);
            }

            var tmxDoc = TMXXmlSerializationHelper.DeserializeFromFile <TMXDocument>(tmxFile, out var e);

            if (e != null)
            {
                throw e;
            }

            return(tmxDoc);
        }