Example #1
0
        public void writeSAVE(Stream oldsavefile, string @newsavepath, Stream newsavefile)
        {
            //First things first, we create a backup of the old savefile.
            FileStream save_backup;

            save_backup          = File.OpenWrite(@newsavepath + ".backup");
            oldsavefile.Position = 0;
            oldsavefile.CopyTo(save_backup);
            save_backup.Close();

            //Load save file
            //XmlDataDocument xmlsav = new XmlDataDocument();
            //xmlsav.PreserveWhitespace = true;
            oldsavefile.Position = 0; //We have to reset the position to 0 otherwise this fails
            //xmlsav.Load(oldsavefile); //Load the Save file as an XML document
            XmlNode hnSav = xmlsav.GetElementsByTagName("HacknetSave")[0];
            XmlAttributeCollection miscData = hnSav.Attributes;

            hnSav.Attributes.GetNamedItem("Username").InnerText = userNameInput.Text; //set username
            hnSav.Attributes.GetNamedItem("Language").InnerText = textBox1.Text;      //set language
            if (hideMailFlag.Checked)
            {
                hnSav.Attributes.GetNamedItem("DisableMailIcon").InnerText = "true";
            }
            else
            {
                hnSav.Attributes.GetNamedItem("DisableMailIcon").InnerText = "false";
            }
            XmlNode mission = xmlsav.GetElementsByTagName("mission")[0];

            mission.Attributes.GetNamedItem("next").Value  = missionInput.Text;
            mission.Attributes.GetNamedItem("goals").Value = goalInput.Text;



            //===========================================================
            //Now we actually save the values to a file
            //===========================================================

            //xmlsav.PreserveWhitespace = false;
            newsavefile.Close();
            XmlWriterSettings xmlSettings = new XmlWriterSettings();

            xmlSettings.Indent          = false;
            xmlSettings.NewLineHandling = System.Xml.NewLineHandling.None;
            //xmlSettings.
            XmlWriter newsavefile_final = XmlWriter.Create(newsavepath, xmlSettings);

            xmlsav.Normalize();
            xmlsav.Save(newsavefile_final);

            newsavefile_final.Close();

            Console.WriteLine("Saved successfully!");
        }