コード例 #1
0
ファイル: GameVM.cs プロジェクト: Doomdoging/TiTsEd
        public GameVM(AmfFile file, GameVM previousVM)
            : base(file)
        {
            SetCharacterOptions();
            setCharacter("PC");
            SaveFile = new AmfObjectVM(file);

            var flagsObject = FlagsObject;

            _flags = new GeneralObjectVM(flagsObject);
            if (null != previousVM)
            {
                _searchText = previousVM._searchText;
            }

            // Flags
            foreach (var xmlFlag in XmlData.Current.Flags)
            {
                if (!_allFlags.ContainsKey(xmlFlag.Name))
                {
                    _allFlags[xmlFlag.Name] = new FlagVM(this, ref flagsObject, xmlFlag);
                }
            }
            foreach (var flag in flagsObject)
            {
                string flagName = flag.ToString();
                if (!_allFlags.ContainsKey(flagName))
                {
                    XmlEnum data = new XmlEnum();
                    data.Name           = flagName;
                    _allFlags[flagName] = new FlagVM(this, ref flagsObject, data);
                }
            }
            Flags = new UpdatableCollection <FlagVM>(_allFlags.Values.ToList().Where(x => x.Match(SearchText)));
        }
コード例 #2
0
        public GameVM(AmfFile file, GameVM previousVM)
            : base(file)
        {
            SetCharacterOptions();
            setCharacter("PC");

            _flags = new GeneralObjectVM(GetObj("flags"));

            // Perks
            var charPerks = Character.GetObj("perks");

            if (null == charPerks)
            {
                charPerks = new Model.AmfObject(AmfTypes.Array);
            }
            var xmlPerks         = XmlData.Current.PerkGroups.SelectMany(x => x.Perks).ToArray();
            var unknownPerkGroup = XmlData.Current.PerkGroups.Last();

            ImportMissingNamedVectors(charPerks, xmlPerks, "storageName", x => x.GetString("tooltip"), unknownPerkGroup.Perks);

            PerkGroups = new List <PerkGroupVM>();
            foreach (var xmlGroup in XmlData.Current.PerkGroups)
            {
                var perksVM = xmlGroup.Perks.OrderBy(x => x.Name).Select(x => new PerkVectorVM(this, charPerks, x)).ToArray();
                _allPerks.AddRange(perksVM);

                var groupVM = new PerkGroupVM(this, xmlGroup.Name, perksVM);
                PerkGroups.Add(groupVM);
            }
            ;
        }
コード例 #3
0
ファイル: App.xaml.cs プロジェクト: zeek20freak/TiTsEd
 static void PrintStatuses(AmfFile file)
 {
     foreach (AmfPair pair in file.GetObj("statusAffects"))
     {
         int key  = Int32.Parse(pair.Key as string);
         var name = pair.ValueAsObject.GetString("statusAffectName");
         Debug.WriteLine(key.ToString("000") + " - " + name);
     }
 }
コード例 #4
0
ファイル: VM.cs プロジェクト: zeek20freak/TiTsEd
        // More file corruption testing
        private bool HasBadPropertyNames(AmfFile file)
        {
            var identiferRe = new Regex(@"^[$A-Za-z_][$A-Za-z0-9_]*$");

            foreach (var pair in file)
            {
                if (pair.Key.GetType() != typeof(string))
                {
                    return(true);
                }
                else if (!identiferRe.IsMatch((string)pair.Key))
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #5
0
ファイル: App.xaml.cs プロジェクト: lasnevadas/TiTsEd
        static AmfFile AutoLoad(FlashDirectory[] directories)
        {
            //find first file
            AmfFile file = null;

            foreach (var dir in directories)
            {
                foreach (var dfile in dir.Files)
                {
                    file = dfile;
                    break;
                }
            }

            VM.Instance.Load(file.FilePath, SerializationFormat.Slot, createBackup: true);
            return(file);
        }
コード例 #6
0
ファイル: VM.cs プロジェクト: zeek20freak/TiTsEd
        public void Load(string path, SerializationFormat expectedFormat, bool createBackup)
        {
            FileManager.TryRegisterExternalFile(path);
            var file        = new AmfFile(path);
            var dataVersion = file.GetString("version");

            if (file.Error != null)
            {
                var box = new ExceptionBox();
                box.Title            = "Could not read file.";
                box.Message          = "TiTsEd could not read this file correctly. Maybe it was corrupted or generated by an old version of Flash. Continuing may make TiTsEd unstable or cause it to corrupt the file. It is strongly advised that you cancel this operation.";
                box.Path             = file.FilePath;
                box.ExceptionMessage = file.Error.Mesg;
                box.IsWarning        = true;
                var result = box.ShowDialog(ExceptionBoxButtons.Continue, ExceptionBoxButtons.Cancel);

                Logger.Error(file.Error.Mesg);
                if (result != ExceptionBoxResult.Continue)
                {
                    return;
                }
            }
            else if (String.IsNullOrEmpty(dataVersion))
            {
                var box = new ExceptionBox();
                box.Title     = "File version too old.";
                box.Message   = "TiTsEd may not be able to read this file correctly as it was generated by an older version of T**s. Continuing may make TiTsEd unstable or cause it to corrupt the file. It is strongly advised that you cancel this operation.";
                box.IsWarning = true;
                var result = box.ShowDialog(ExceptionBoxButtons.Continue, ExceptionBoxButtons.Cancel);

                Logger.Error(String.Format("{0} T**s data version: {1}.", box.Title, dataVersion));
                if (result != ExceptionBoxResult.Continue)
                {
                    return;
                }
            }

            // I would like to test dataVersion here some day to ensure that it's not too old of a version,
            // however, as long as Fen keeps occasionally pushing crappy version strings (e.g. 0.8.4.8d),
            // that can't happen.  Ideally, I'd like to see them switch to a segmented version system.

            // Sanity checks: see if the save can be re-saved as-is OR if any of the top-level property names are invalid as identifiers.
            if (!file.CanBeSaved(SerializationFormat.Slot) || HasBadPropertyNames(file))
            {
                var box = new ExceptionBox();
                box.Title     = "File could not be read correctly.";
                box.Message   = "TiTsEd could not read this file correctly, it is likely corrupted. Cancelling this operation.";
                box.IsWarning = true;
                box.ShowDialog(ExceptionBoxButtons.OK);

                Logger.Error(String.Format("{0} T**s data version: {1}.", box.Title, dataVersion));
                return;
            }

            // Sanity check: ensure the actual format matches the expected format (just a warning to the user about mixing up the formats).
            if (file.Format != expectedFormat)
            {
                var box = new ExceptionBox();
                box.Title     = "File format different from expected format.";
                box.Message   = "The file is actually a " + (file.Format == SerializationFormat.Slot ? "\"Slot\"" : "\"Save to File\"") + " format save, but it was loaded as though it were a " + (expectedFormat == SerializationFormat.Slot ? "\"Slot\"" : "\"Save to File\"") + " format save.\n\nThe two formats are not compatible, so care should be taken to ensure you do not confuse the two, since T**s can only load each format in a specific way.  Attempting to load a \"Slot\" save as though it were a \"Save to File\" save, or vice versa, will cause T**s to think the save is corrupt, at best, or see the save deleted, at worse. Do not mix them up.";
                box.IsWarning = true;
                box.ShowDialog(ExceptionBoxButtons.OK);
            }

            if (createBackup)
            {
                FileManager.CreateBackup(path);
            }
            _currentFile = file;

            XmlData.Select(XmlData.Files.T**s);
            Data = XmlData.Current;
            Game = new GameVM(_currentFile, Game);

            OnPropertyChanged("Data");
            OnPropertyChanged("Game");
            OnPropertyChanged("HasData");
            UpdateAppTitle();
            VM.Instance.NotifySaveRequiredChanged(false);
            if (FileOpened != null)
            {
                FileOpened(null, null);
            }
        }
コード例 #7
0
ファイル: FilesVM.cs プロジェクト: reddraggon2001/TiTsEd
 public FileVM(AmfFile source, DirectoryKind directoryKind, bool openOnClick)
 {
     Source         = source;
     _openOnClick   = openOnClick;
     _directoryKind = directoryKind;
 }
コード例 #8
0
ファイル: GameVM.cs プロジェクト: zeek20freak/TiTsEd
        public GameVM(AmfFile file, GameVM previousVM)
            : base(file)
        {
            SetCharacterOptions();
            setCharacter("PC");

            var flagsObject = FlagsObject;

            _flags = new GeneralObjectVM(flagsObject);
            if (null != previousVM)
            {
                _perkSearchText    = previousVM._perkSearchText;
                _keyItemSearchText = previousVM._keyItemSearchText;
                _rawDataSearchText = previousVM._rawDataSearchText;
            }

            // Perks
            var charPerks        = Character.PerksArray;
            var xmlPerks         = XmlData.Current.PerkGroups.SelectMany(x => x.Perks).ToArray();
            var unknownPerkGroup = XmlData.Current.PerkGroups.Last();

            ImportMissingNamedVectors(charPerks, xmlPerks, "storageName", x => x.GetString("tooltip"), unknownPerkGroup.Perks);

            Character.PerkGroups = new List <PerkGroupVM>();
            foreach (var xmlGroup in XmlData.Current.PerkGroups)
            {
                var perksVM = xmlGroup.Perks.OrderBy(x => x.Name).Select(x => new PerkVM(this, charPerks, x)).ToArray();
                _allPerks.AddRange(perksVM);

                var groupVM = new PerkGroupVM(this, xmlGroup.Name, perksVM);
                Character.PerkGroups.Add(groupVM);
            }
            //Character.Perks = new UpdatableCollection<PerkVM>(_allPerks.Where(x => x.Match(PerkSearchText)));

            // KeyItems
            var keyItems = Character.KeyItemsArray;
            var xmlKeys  = XmlData.Current.KeyItems;

            ImportMissingNamedVectors(keyItems, xmlKeys, "storageName", x => x.GetString("tooltip"));
            _allKeyItems       = XmlData.Current.KeyItems.OrderBy(x => x.Name).Select(x => new KeyItemVM(this, keyItems, x)).ToArray();
            Character.KeyItems = new UpdatableCollection <KeyItemVM>(_allKeyItems.Where(x => x.Match(KeyItemSearchText)));

            // Statuses
            var statuses    = Character.StatusEffectsArray;
            var xmlStatuses = XmlData.Current.Statuses;

            ImportMissingNamedVectors(statuses, xmlStatuses, "storageName", x => x.GetString("tooltip"));
            _allStatuses            = XmlData.Current.Statuses.OrderBy(x => x.Name).Select(x => new StatusEffectVM(this, statuses, x)).ToArray();
            Character.StatusEffects = new UpdatableCollection <StatusEffectVM>(_allStatuses.Where(x => x.Match(RawDataSearchText)));

            // Flags
            foreach (var xmlFlag in XmlData.Current.Flags)
            {
                if (!_allFlags.ContainsKey(xmlFlag.Name))
                {
                    _allFlags[xmlFlag.Name] = new FlagVM(this, ref flagsObject, xmlFlag);
                }
            }
            foreach (var flag in flagsObject)
            {
                string flagName = flag.ToString();
                if (!_allFlags.ContainsKey(flagName))
                {
                    XmlEnum data = new XmlEnum();
                    data.Name           = flagName;
                    _allFlags[flagName] = new FlagVM(this, ref flagsObject, data);
                }
            }
            Flags = new UpdatableCollection <FlagVM>(_allFlags.Values.ToList().Where(x => x.Match(RawDataSearchText)));
        }
コード例 #9
0
ファイル: GameVM.cs プロジェクト: Rainbowhail/TiTsEd
        public GameVM(AmfFile file, GameVM previousVM)
            : base(file)
        {
            SetCharacterOptions();
            CharacterSelection = "PC";

            var shittyShips = GetObj("shittyShips") ?? new AmfObject(AmfTypes.Array);

            Ships = new ShipArrayVM(this, shittyShips);

            var flagsObject = FlagsObject;

            _flags = new GeneralObjectVM(flagsObject);

            // Flags
            var flagNames = AllFlags.Keys.ToList();

            foreach (var flagName in flagNames)
            {
                XmlEnum data = new XmlEnum();
                data.Name          = flagName;
                AllFlags[flagName] = new FlagVM(this, ref flagsObject, data);
            }

            foreach (var xmlFlag in XmlData.Current.Flags)
            {
                if (!AllFlags.ContainsKey(xmlFlag.Name))
                {
                    AllFlags[xmlFlag.Name] = new FlagVM(this, ref flagsObject, xmlFlag);
                }
            }

            foreach (var flag in flagsObject)
            {
                string flagName = flag.ToString();
                if (!AllFlags.ContainsKey(flagName))
                {
                    XmlEnum data = new XmlEnum();
                    data.Name          = flagName;
                    AllFlags[flagName] = new FlagVM(this, ref flagsObject, data);
                }
            }

            if (null != previousVM)
            {
                foreach (var flag in previousVM.AllFlags)
                {
                    string flagName = flag.Key.ToString();
                    if (!AllFlags.ContainsKey(flagName))
                    {
                        XmlEnum data = new XmlEnum();
                        data.Name          = flagName;
                        AllFlags[flagName] = new FlagVM(this, ref flagsObject, data);
                    }
                }
            }

            Flags = new UpdatableCollection <FlagVM>(AllFlags.Values.ToList().Where(x => x.Match(SearchText)));
            OnPropertyChanged("Flags");

            // Codex
            var codexEntries = AllCodexEntries.Keys.ToList();

            foreach (var codexName in codexEntries)
            {
                XmlCodexEntry data = new XmlCodexEntry();
                data.Name = codexName;
                AllCodexEntries[codexName] = new CodexEntryVM(this, data);
            }

            foreach (var xmlCodex in XmlData.Current.CodexEntries)
            {
                if (!AllCodexEntries.ContainsKey(xmlCodex.Name))
                {
                    AllCodexEntries[xmlCodex.Name] = new CodexEntryVM(this, xmlCodex);
                }
            }

            foreach (var codexEntry in CodexUnlockedEntriesObj)
            {
                string codexName = codexEntry.Value.ToString();
                if (!AllCodexEntries.ContainsKey(codexName))
                {
                    XmlCodexEntry data = new XmlCodexEntry(codexName);
                    AllCodexEntries[codexName] = new CodexEntryVM(this, data);
                }
            }

            foreach (var codexEntry in CodexViewedEntriesObj)
            {
                string codexName = codexEntry.Value.ToString();
                if (!AllCodexEntries.ContainsKey(codexName))
                {
                    XmlCodexEntry data = new XmlCodexEntry(codexName);
                    AllCodexEntries[codexName] = new CodexEntryVM(this, data);
                }
            }

            if (null != previousVM)
            {
                foreach (var codexEntry in previousVM.AllCodexEntries)
                {
                    string codexName = codexEntry.Value.ToString();
                    if (!AllCodexEntries.ContainsKey(codexName))
                    {
                        XmlCodexEntry data = new XmlCodexEntry(codexName);
                        AllCodexEntries[codexName] = new CodexEntryVM(this, data);
                    }
                }
            }

            CodexEntries = new UpdatableCollection <CodexEntryVM>(AllCodexEntries.Values.ToList().Where(x => x.Match(SearchText)));
            OnPropertyChanged("CodexEntries");
        }
コード例 #10
0
ファイル: VM.cs プロジェクト: klorpa/CoCEd
        public void Load(string path, SerializationFormat expectedFormat, bool createBackup)
        {
            FileManager.TryRegisterExternalFile(path);
            var file        = new AmfFile(path);
            var dataVersion = file.GetString("version");

            if (file.Error != null)
            {
                var box = new ExceptionBox()
                {
                    Title            = "Could not read file.",
                    Message          = "CoCEd could not read this file correctly. Maybe it was corrupted or generated by an old version of Flash. Continuing may make CoCEd unstable or cause it to corrupt the file. It is strongly advised that you cancel this operation.",
                    Path             = file.FilePath,
                    ExceptionMessage = file.Error.Mesg,
                    IsWarning        = true,
                };
                var result = box.ShowDialog(ExceptionBoxButtons.Continue, ExceptionBoxButtons.Cancel);

                Logger.Error(file.Error.Mesg);
                if (result != ExceptionBoxResult.Continue)
                {
                    return;
                }
            }
            else if (String.IsNullOrEmpty(dataVersion))
            {
                var box = new ExceptionBox()
                {
                    Title     = "File version too old.",
                    Message   = "CoCEd may not be able to read this file correctly as it was generated by an older version of CoC. Continuing may make CoCEd unstable or cause it to corrupt the file. It is strongly advised that you cancel this operation.",
                    IsWarning = true,
                };
                var result = box.ShowDialog(ExceptionBoxButtons.Continue, ExceptionBoxButtons.Cancel);

                Logger.Error(String.Format("{0} CoC data version: {1}.", box.Title, dataVersion));
                if (result != ExceptionBoxResult.Continue)
                {
                    return;
                }
            }

            // Some day I would like to be able to test `dataVersion` to ensure that it's not too old
            // of a version, however, as long as CoC developers keep pushing crappy version strings
            // (e.g. 0.8.4.8d), that can't happen.  Ideally, I'd like to see them switch to SemVer.
            //
            // This probably doesn't really apply to Vanilla anymore, since its finished and unlikely
            // to even receive patches at this point.

            // Sanity checks: see if the save can be re-saved as-is OR if any of the top-level property names are invalid as identifiers.
            if (!file.CanBeSaved(SerializationFormat.Slot) || HasBadPropertyNames(file))
            {
                var box = new ExceptionBox()
                {
                    Title     = "File could not be read correctly.",
                    Message   = "CoCEd could not read this file correctly, it is likely corrupted. Cancelling this operation.",
                    IsWarning = true,
                };
                box.ShowDialog(ExceptionBoxButtons.OK);

                Logger.Error(String.Format("{0} CoC data version: {1}.", box.Title, dataVersion));
                return;
            }

            // Sanity check: ensure the actual format matches the expected format (just a warning to the user about mixing up the formats).
            if (file.Format != expectedFormat)
            {
                var box = new ExceptionBox()
                {
                    Title     = "File format different from expected format.",
                    Message   = "The file is actually a " + (file.Format == SerializationFormat.Slot ? "\"Slot\"" : "\"Save to File\"") + " format save, but it was loaded as though it were a " + (expectedFormat == SerializationFormat.Slot ? "\"Slot\"" : "\"Save to File\"") + " format save.\n\nThe two formats are not compatible, so care should be taken to ensure you do not confuse the two, since CoC can only load each format in a specific way.  Attempting to load a \"Slot\" save as though it were a \"Save to File\" save, or vice versa, will cause CoC to think the save is corrupt, at best, or see the save deleted, at worse. Do not mix them up.",
                    IsWarning = true,
                };
                box.ShowDialog(ExceptionBoxButtons.OK);
            }

            if (createBackup)
            {
                FileManager.CreateBackup(path);
            }
            _currentFile = file;

            // Is this save from Vanilla, Revamp, or Xianxia?
            ModType modType;

            //if (_currentFile.Contains("soulforce"))
            //{
            //    modType = ModType.Xianxia;
            //    XmlData.Select(XmlData.Files.Xianxia);
            //}
            //else
            if (_currentFile.Contains("hunger"))
            {
                modType = ModType.Revamp;
                XmlData.Select(XmlData.Files.Revamp);
            }
            else
            {
                modType = ModType.Vanilla;
                XmlData.Select(XmlData.Files.Vanilla);
            }

            Data = XmlData.Current;
            Game = new GameVM(_currentFile, Game, modType);

            OnPropertyChanged("Data");
            OnPropertyChanged("Game");
            OnPropertyChanged("HasData");
            UpdateAppTitle();
            VM.Instance.NotifySaveRequiredChanged(false);
            if (FileOpened != null)
            {
                FileOpened(null, null);
            }
        }