Esempio n. 1
0
        /// <summary>
        /// Loads the .sav file specified by SavPath, using DDsavelib if it is packed,
        /// and returns the Pawn in the slot specified by SavSourcePawn.
        /// Throws an exception if anything fails.
        /// </summary>
        /// <returns>The loaded Pawn</returns>
        public PawnData Import()
        {
            bool?    isPacked;
            XElement savRoot = LoadSav(out isPacked);

            return(PawnIO.LoadPawnSav(SavSourcePawn, savRoot));
        }
Esempio n. 2
0
        private void butLoad_Click(object sender, RoutedEventArgs e)
        {
            PawnData       result     = null;
            OpenFileDialog openDialog = new OpenFileDialog();

            openDialog.Filter = PawnFilter;
            openDialog.Title  = "Open Pawn file";

            bool?dialogResult = openDialog.ShowDialog();

            if (dialogResult == true)
            {
                try
                {
                    result = PawnIO.LoadPawn(openDialog.FileName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(
                        ex.Message,
                        "Error loading Pawn",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }
            }
            if (result != null)
            {
                SetLoadedPawn(result);
            }
        }
Esempio n. 3
0
        private void butSave_Click(object sender, RoutedEventArgs e)
        {
            if (PawnModel.LoadedPawn != null)
            {
                SaveFileDialog saveDialog = new SaveFileDialog();
                saveDialog.Filter   = PawnFilter;
                saveDialog.Title    = "Save Pawn file";
                saveDialog.FileName = PawnModel.Name;

                bool?dialogResult = saveDialog.ShowDialog();
                if (dialogResult == true)
                {
                    try
                    {
                        PawnIO.SavePawn(PawnModel.LoadedPawn, saveDialog.FileName);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(
                            ex.Message,
                            "Error loading Pawn",
                            MessageBoxButton.OK,
                            MessageBoxImage.Error);
                    }
                }
            }
        }
Esempio n. 4
0
        private void SetConfig(XElement config)
        {
            int?version = GetConfigVersion(config);

            configFileVersion = version.HasValue ? version.Value : 0;

            PawnTemplateCategory template = PawnIO.ParseConfig(config);

            pawnModel = new PawnModel(template);
            PawnEditTreeTab.TreeList.Model = pawnModel;

            NotifyPropertyChanged("PawnModel");
        }
Esempio n. 5
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));
            }
        }