예제 #1
0
        /// <summary>
        /// Loads the .sav file specified by SavPath, using DDsavelib if it is packed,
        /// replaces the Pawn in the slot specified by SavSourcePawn with the given Pawn,
        /// then writes the modified .sav back, repacking it using DDsavelib if it was originally packed.
        /// Throws an exception if anything fails.
        /// </summary>
        /// <param name="exportPawn">The Pawn to export to the .sav file</param>
        public void Export(PawnData exportPawn)
        {
            bool?    isPacked;
            XElement savRoot = LoadSav(out isPacked);

            PawnIO.SavePawnSav(exportPawn, SavSourcePawn, savRoot);

            string encoded = EncodeXml(savRoot);

            if (isPacked == true)
            {
                SavTool.RepackSav(SavPath, encoded);
            }
            else if (isPacked == false)
            {
                File.WriteAllText(SavPath, encoded, new UTF8Encoding(false));
            }
        }
예제 #2
0
        private XElement LoadSav(out bool?isPacked)
        {
            if (!File.Exists(SavPath))
            {
                throw new Exception(string.Format("File {0} does not exist", SavPath));
            }

            isPacked = null;

            if (SavTool.ValidateSav(SavPath))
            {
                isPacked = true;
                string unpackedText = SavTool.UnpackSav(SavPath);
                return(XElement.Parse(unpackedText, LoadOptions.PreserveWhitespace));
            }
            else
            {
                isPacked = false;
                return(XElement.Load(SavPath, LoadOptions.PreserveWhitespace));
            }
        }