Example #1
0
        public static void CreateEmptyXmlRepository()
        {
            if (!System.IO.File.Exists(Util.GetXML_RepoPath()))
            {
                System.Xml.XmlTextWriter text = new System.Xml.XmlTextWriter(Util.GetXML_RepoPath(), null);
                text.Formatting  = System.Xml.Formatting.Indented;
                text.Indentation = 4;
                text.WriteStartDocument();

                text.WriteStartElement("root");

                text.WriteStartElement("book");
                text.WriteStartAttribute("folder");
                text.WriteEndAttribute();


                text.WriteStartElement("page");
                text.WriteStartAttribute("src");
                text.WriteEndAttribute();
                text.WriteEndElement();

                text.WriteEndElement();


                text.WriteEndElement();

                text.WriteEndDocument();
                text.Flush();
                text.Close();
            }
        }
Example #2
0
    //////////////////////////////////////////
    public void WriteToXML(List <AnimatedFrameInfo> AnimFrameInfoList, bool bRelativeToScreen)
    {
        //===========================================
        //          Get Save Location
        //===========================================
        SaveFileDialog SaveFD = new SaveFileDialog();

        SaveFD.Title    = "Select a Save Location";
        SaveFD.FileName = "";
        SaveFD.Filter   = "XML File (*.xml)|*.xml";
        if (SaveFD.ShowDialog() != System.Windows.Forms.DialogResult.OK)
        {
            return;
        }

        int iPartialCompletionFrame = 0;

        for (; iPartialCompletionFrame < AnimFrameInfoList.Count; iPartialCompletionFrame++)
        {
            if (AnimFrameInfoList.ElementAt(iPartialCompletionFrame).m_bAnimationPartiallyCompleted)
            {
                break;
            }
        }

        System.Xml.XmlTextWriter XmlWriter = new System.Xml.XmlTextWriter(SaveFD.FileName, null);
        XmlWriter.Formatting = System.Xml.Formatting.Indented;

        XmlWriter.WriteStartDocument();
        XmlWriter.WriteStartElement("Animation");
        //===========================================
        //          Write Frame Count
        //===========================================
        XmlWriter.WriteStartElement("AnimationInfo");
        XmlWriter.WriteStartAttribute("TotalFrames");
        XmlWriter.WriteString(AnimFrameInfoList.Count.ToString());
        XmlWriter.WriteEndAttribute();
        XmlWriter.WriteStartAttribute("PartialAnimationCompletionFrame");
        XmlWriter.WriteString(iPartialCompletionFrame.ToString());
        XmlWriter.WriteEndAttribute();
        XmlWriter.WriteStartAttribute("RelativeToScreen");
        XmlWriter.WriteString(bRelativeToScreen ? "1" : "0");
        XmlWriter.WriteEndAttribute();
        XmlWriter.WriteEndElement();
        //===========================================
        //          Write FrameInfo
        //===========================================
        for (int i = 0; i < AnimFrameInfoList.Count(); i++)
        {
            AnimatedFrameInfo AFI = AnimFrameInfoList.ElementAt(i);
            ///////////////////////////////////////////////////////
            XmlWriter.WriteStartElement("Frame" + (i + 1).ToString());
            XmlWriter.WriteStartAttribute("TotalSprites");
            XmlWriter.WriteString(AFI.m_SpriteInfoList.Count().ToString());
            XmlWriter.WriteEndAttribute();
            XmlWriter.WriteStartAttribute("WaitTillNextFrame");
            XmlWriter.WriteString(AFI.m_iWaitTimeTillNextFrame.ToString());
            XmlWriter.WriteEndAttribute();
            XmlWriter.WriteStartAttribute("TintScreen");
            XmlWriter.WriteString(AFI.m_bTintScreen ? "1" : "0");
            XmlWriter.WriteEndAttribute();
            XmlWriter.WriteStartAttribute("ScreenTintRed");
            XmlWriter.WriteString(AFI.m_iTintScreenRed.ToString());
            XmlWriter.WriteEndAttribute();
            XmlWriter.WriteStartAttribute("ScreenTintGreen");
            XmlWriter.WriteString(AFI.m_iTintScreenGreen.ToString());
            XmlWriter.WriteEndAttribute();
            XmlWriter.WriteStartAttribute("ScreenTintBlue");
            XmlWriter.WriteString(AFI.m_iTintScreenBlue.ToString());
            XmlWriter.WriteEndAttribute();
            XmlWriter.WriteStartAttribute("ScreenTintAlpha");
            XmlWriter.WriteString(AFI.m_iTintScreenAlpha.ToString());
            XmlWriter.WriteEndAttribute();
            XmlWriter.WriteStartAttribute("TintCharacter");
            XmlWriter.WriteString(AFI.m_bTintCharacter ? "1" : "0");
            XmlWriter.WriteEndAttribute();
            XmlWriter.WriteStartAttribute("CharacterTintRed");
            XmlWriter.WriteString(AFI.m_iTintCharacterRed.ToString());
            XmlWriter.WriteEndAttribute();
            XmlWriter.WriteStartAttribute("CharacterTintGreen");
            XmlWriter.WriteString(AFI.m_iTintCharacterGreen.ToString());
            XmlWriter.WriteEndAttribute();
            XmlWriter.WriteStartAttribute("CharacterTintBlue");
            XmlWriter.WriteString(AFI.m_iTintCharacterBlue.ToString());
            XmlWriter.WriteEndAttribute();
            XmlWriter.WriteStartAttribute("SoundFilename");
            XmlWriter.WriteString(AFI.m_sSoundFilename);
            XmlWriter.WriteEndAttribute();

            //===========================================
            //          Write Sprite Info
            //===========================================
            for (int j = 0; j < AFI.m_SpriteInfoList.Count(); j++)
            {
                SpriteInfo Sprite = AFI.m_SpriteInfoList.ElementAt(j);
                //////////////////////////////////////////////////////
                XmlWriter.WriteStartElement("Sprite" + (j + 1).ToString());
                XmlWriter.WriteStartAttribute("TextureName");
                XmlWriter.WriteString(System.IO.Path.GetFileName(Sprite.TextureName));
                XmlWriter.WriteEndAttribute();
                XmlWriter.WriteStartAttribute("X");
                XmlWriter.WriteString(Sprite.X.ToString());
                XmlWriter.WriteEndAttribute();
                XmlWriter.WriteStartAttribute("Y");
                XmlWriter.WriteString(Sprite.Y.ToString());
                XmlWriter.WriteEndAttribute();
                XmlWriter.WriteStartAttribute("W");
                XmlWriter.WriteString(Sprite.W.ToString());
                XmlWriter.WriteEndAttribute();
                XmlWriter.WriteStartAttribute("H");
                XmlWriter.WriteString(Sprite.H.ToString());
                XmlWriter.WriteEndAttribute();
                ///////////////////////////////////////////////
                XmlWriter.WriteStartAttribute("UVCoordStartX");
                XmlWriter.WriteString(((float)Sprite.BlitRect.X / (float)Sprite.Texture.Width).ToString());
                XmlWriter.WriteEndAttribute();
                XmlWriter.WriteStartAttribute("UVCoordStartY");
                XmlWriter.WriteString(((float)Sprite.BlitRect.Y / (float)Sprite.Texture.Height).ToString());
                XmlWriter.WriteEndAttribute();
                XmlWriter.WriteStartAttribute("UVCoordEndX");
                XmlWriter.WriteString((((float)Sprite.BlitRect.X + (float)Sprite.BlitRect.Width) / (float)Sprite.Texture.Width).ToString());
                XmlWriter.WriteEndAttribute();
                XmlWriter.WriteStartAttribute("UVCoordEndY");
                XmlWriter.WriteString((((float)Sprite.BlitRect.Y + (float)Sprite.BlitRect.Height) / (float)Sprite.Texture.Height).ToString());
                XmlWriter.WriteEndAttribute();
                XmlWriter.WriteEndElement();
            }
            XmlWriter.WriteEndElement();
        }
        //===========================================
        //          Finish Up
        //===========================================
        XmlWriter.WriteEndElement();     // Animation
        XmlWriter.WriteEndDocument();
        XmlWriter.Close();
    }
Example #3
0
    //////////////////////////////////////////
    public void WriteToXML(string sFullImagePath, string sMapImageFileName, string sAudioFileName, uint iAudioLoopStart, uint iAudioLoopEnd, string sWeatherEffectOne, uint iPowerOfWeatherEffectOne, string sWeatherEffectTwo, uint iPowerOfWeatherEffectTwo, List <List <LevelInfo> > lLevelInfoList, uint iTileRows, uint iTileCols)
    {
        if (sMapImageFileName == null && sAudioFileName == null)
        {
            string sWarning = "WARNING, You do not have either a background image or audio for this level (what the hell do you think this is?), would you like to continue?";
            if (MessageBox.Show(sWarning, "Warning!", MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                return;
            }
        }
        else if (sMapImageFileName == null)
        {
            string sWarning = "WARNING, You do not have a background image for this level, are you sure you want a regular boring background for this level?";
            if (MessageBox.Show(sWarning, "Warning!", MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                return;
            }
        }
        else if (sAudioFileName == null)
        {
            string sWarning = "WARNING, You do not have audio selected for this level, are you sure you don't want to allow the level to seduce your ears?";
            if (MessageBox.Show(sWarning, "Warning!", MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                return;
            }
        }
        //===========================================
        //          Get Save Location
        //===========================================
        SaveFileDialog SaveFD = new SaveFileDialog();

        SaveFD.Title    = "Select a Save Location";
        SaveFD.FileName = "";
        SaveFD.Filter   = "XML File (*.xml)|*.xml";
        if (SaveFD.ShowDialog() != System.Windows.Forms.DialogResult.OK)
        {
            return;
        }


        System.Xml.XmlTextWriter XmlWriter = new System.Xml.XmlTextWriter(SaveFD.FileName, null);
        XmlWriter.Formatting = System.Xml.Formatting.Indented;

        XmlWriter.WriteStartDocument();
        XmlWriter.WriteStartElement("LevelInfo");
        //===========================================
        //          Write Level Size
        //===========================================
        XmlWriter.WriteStartElement("LevelSize");
        XmlWriter.WriteStartAttribute("Rows");
        XmlWriter.WriteString(iTileRows.ToString());
        XmlWriter.WriteEndAttribute();
        XmlWriter.WriteStartAttribute("Cols");
        XmlWriter.WriteString(iTileCols.ToString());
        XmlWriter.WriteEndAttribute();
        XmlWriter.WriteEndElement();
        //===========================================
        //          Write LevelData
        //===========================================
        XmlWriter.WriteStartElement("LevelData");
        for (int Row = 0; Row < lLevelInfoList.Count(); Row++)
        {
            XmlWriter.WriteStartElement("Row");
            for (int Col = 0; Col < lLevelInfoList.ElementAt(Row).Count(); Col++)
            {
                int iIncrem = Col + 1;
                XmlWriter.WriteStartAttribute("Col" + iIncrem.ToString());
                XmlWriter.WriteString(lLevelInfoList.ElementAt(Row).ElementAt(Col).TextureName);
                XmlWriter.WriteEndAttribute();
            }
            XmlWriter.WriteEndElement();
        }
        XmlWriter.WriteEndElement();
        //===========================================
        //          Write Background Texture
        //===========================================
        XmlWriter.WriteStartElement("BackgroundImage");
        XmlWriter.WriteStartAttribute("Name");
        XmlWriter.WriteString(sMapImageFileName);
        XmlWriter.WriteEndAttribute();
        XmlWriter.WriteStartAttribute("FullPath");
        XmlWriter.WriteString(sFullImagePath);
        XmlWriter.WriteEndAttribute();
        XmlWriter.WriteEndElement();
        //===========================================
        //          Write Audio Info
        //===========================================
        XmlWriter.WriteStartElement("AudioName");
        XmlWriter.WriteStartAttribute("Name");
        XmlWriter.WriteString(sAudioFileName);
        XmlWriter.WriteEndAttribute();
        XmlWriter.WriteStartAttribute("LoopStart");
        XmlWriter.WriteString(iAudioLoopStart.ToString());
        XmlWriter.WriteEndAttribute();
        XmlWriter.WriteStartAttribute("LoopEnd");
        XmlWriter.WriteString(iAudioLoopEnd.ToString());
        XmlWriter.WriteEndAttribute();
        XmlWriter.WriteEndElement();
        //===========================================
        //          Write NoteTag Info
        //===========================================
        XmlWriter.WriteStartElement("Weather");
        XmlWriter.WriteStartElement("EffectOne");
        XmlWriter.WriteStartAttribute("Type");
        XmlWriter.WriteString(sWeatherEffectOne);
        XmlWriter.WriteEndAttribute();
        XmlWriter.WriteStartAttribute("Power");
        XmlWriter.WriteString(iPowerOfWeatherEffectOne.ToString());
        XmlWriter.WriteEndAttribute();
        XmlWriter.WriteEndElement();
        XmlWriter.WriteStartElement("EffectTwo");
        XmlWriter.WriteStartAttribute("Type");
        XmlWriter.WriteString(sWeatherEffectTwo);
        XmlWriter.WriteEndAttribute();
        XmlWriter.WriteStartAttribute("Power");
        XmlWriter.WriteString(iPowerOfWeatherEffectTwo.ToString());
        XmlWriter.WriteEndAttribute();
        XmlWriter.WriteEndElement();
        XmlWriter.WriteEndElement();
        //===========================================
        //          Finish Up
        //===========================================
        XmlWriter.WriteEndElement();     // LevelInfo
        XmlWriter.WriteEndDocument();
        XmlWriter.Close();


        if ((!m_bWarnedAboutNeedingToImportTextureAndSound && sMapImageFileName != null) || (!m_bWarnedAboutNeedingToImportTextureAndSound && sAudioFileName != null))
        {
            m_bWarnedAboutNeedingToImportTextureAndSound = true;
            MessageBox.Show("Note that whilst you have successfully saved an XML File, you will not be able to use your custom texture or sound unless you import it to the appropriate game folder");
        }
    }
Example #4
0
        /// <summary>
        /// Create and Save a default configuration Xml file based on a easily specific or default defined xml string
        /// </summary>
        /// <param name="FilePath">The fullpath including filename.xml to save to</param>
        /// <param name="XmlConfigurationFileString">If not specified, then will use the XmlDefaultConfigurationFileString</param>
        /// <returns>True if succesfull created</returns>
        /// <remarks></remarks>
        public bool SaveXmlDefaultConfigurationFile(string FilePath, string XmlConfigurationFileString)
        {
            string theXmlString = ((XmlConfigurationFileString != null) ? XmlConfigurationFileString : XmlDefaultConfigurationFileString);
            //What Method You want to use ?, try any by simply change the var XmlSaveMethod declared at top
            switch (XmlSaveMethod) {
                case enumXmlSaveMethod.StreamWrite:
                    //Easy Method
                    using (System.IO.StreamWriter StreamWriter = new System.IO.StreamWriter(FilePath)) {
                        //Without Compact Framework more easily using file.WriteAllText but, CF doesn't have this method
                        StreamWriter.Write(theXmlString);
                        StreamWriter.Close();
                    }

                    return true;

                case enumXmlSaveMethod.XmlTextWriter:
                    //Alternative Method
                    using (System.Xml.XmlTextWriter XmlTextWriter = new System.Xml.XmlTextWriter(FilePath, System.Text.UTF8Encoding.UTF8)) {
                        XmlTextWriter.WriteStartDocument();
                        XmlTextWriter.WriteStartElement("configuration");
                        XmlTextWriter.WriteStartElement("appSettings");
                        foreach (string Item in GetListItems(theXmlString)) {
                            XmlTextWriter.WriteStartElement("add");

                            XmlTextWriter.WriteStartAttribute("key", string.Empty);
                            XmlTextWriter.WriteRaw(GetKey(Item));
                            XmlTextWriter.WriteEndAttribute();

                            XmlTextWriter.WriteStartAttribute("value", string.Empty);
                            XmlTextWriter.WriteRaw(GetValue(Item));
                            XmlTextWriter.WriteEndAttribute();

                            XmlTextWriter.WriteEndElement();

                        }

                        XmlTextWriter.WriteEndElement();
                        XmlTextWriter.WriteEndElement();
                        //XmlTextWriter.WriteEndDocument()
                        XmlTextWriter.Close();

                    }

                    return true;

                case enumXmlSaveMethod.XmlDocument:
                    //Method you will practice
                    System.Xml.XmlDocument XmlDoc = new System.Xml.XmlDocument();
                    System.Xml.XmlElement xRoot = XmlDoc.CreateElement("configuration");
                    XmlDoc.AppendChild(xRoot);
                    System.Xml.XmlElement xAppSettingsElement = XmlDoc.CreateElement("appSettings");
                    xRoot.AppendChild(xAppSettingsElement);

                    System.Xml.XmlElement xElement = default(System.Xml.XmlElement);
                    System.Xml.XmlAttribute xAttrKey = default(System.Xml.XmlAttribute);
                    System.Xml.XmlAttribute xAttrValue = default(System.Xml.XmlAttribute);
                    foreach (string Item in GetListItems(theXmlString)) {
                        xElement = XmlDoc.CreateElement("add");
                        xAttrKey = XmlDoc.CreateAttribute("key");
                        xAttrValue = XmlDoc.CreateAttribute("value");
                        xAttrKey.InnerText = GetKey(Item);
                        xElement.SetAttributeNode(xAttrKey);
                        xAttrValue.InnerText = GetValue(Item);
                        xElement.SetAttributeNode(xAttrValue);
                        xAppSettingsElement.AppendChild(xElement);
                    }

                    System.Xml.XmlProcessingInstruction XmlPI = XmlDoc.CreateProcessingInstruction("xml", "version='1.0' encoding='utf-8'");
                    XmlDoc.InsertBefore(XmlPI, XmlDoc.ChildNodes[0]);
                    XmlDoc.Save(FilePath);

                    return true;
            }
            return false;
        }