Пример #1
0
        /// <summary>
        /// Reads file data. This method should not be called from subclasses !
        /// </summary>
        protected override void _ReadData()
        {
            try
            {
                // File decryption
                string tempFolder = File2.SetTemporaryFolder(null, LibraryConstants.FOLDER_TEMP, true);

                _WorkingFileName = string.Concat(tempFolder, FILE_AICONFIG_XML);
                XTEAEncryption.Decrypt(_FileName, _WorkingFileName);

                // Extracting xml and dirty data
                byte[] xmlData;

                using (BinaryReader reader = new BinaryReader(new FileStream(_WorkingFileName, FileMode.Open, FileAccess.Read)))
                {
                    // Finding 0x00 0x00 sequence
                    byte readByte = 0xAA;

                    while (readByte != 0x00)
                    {
                        readByte = reader.ReadByte();
                    }

                    long xmlPartLength = reader.BaseStream.Position;

                    reader.BaseStream.Seek(0, SeekOrigin.Begin);
                    xmlData    = reader.ReadBytes((int)(xmlPartLength - 1));
                    _DirtyData = reader.ReadBytes((int)(reader.BaseStream.Length - xmlData.Length));
                }

                // Loading xml...
                _Doc = new XmlDocument();

                File2.WriteBytesToFile(_WorkingFileName, xmlData);
                _Doc.Load(_WorkingFileName);

                // Locating zones
                const string xRequest = "/AICONFIG/VEHICLE_REPARTITION/ZONE";

                _ZoneNodes = _Doc.SelectNodes(xRequest);

                if (_ZoneNodes == null || _ZoneNodes.Count == 0)
                {
                    throw new Exception("Invalid zoning data in AIConfig.xml: see " + xRequest);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to read file: " + _FileName, ex);
            }
        }
Пример #2
0
        /// <summary>
        /// Extrait le fichier spécifié du BNK.
        /// If destination file already exists, it is renamed to *_old.
        /// </summary>
        /// <param name="aFile">Fichier empaqueté</param>
        /// <param name="path">Nom du fichier à créer ou nom du dossier où il doit être extrait (le nom sera inchangé)</param>
        /// <param name="toFolder">true si le path désigne un nom de dossier, false si c'est un nom de fichier</param>
        private static void _ExtractPackedFile(PackedFile aFile, string path, bool toFolder)
        {
            if (!string.IsNullOrEmpty(path) && aFile.exists)
            {
                // Gestion des deux modes d'extraction
                string newFileName = path;

                if (toFolder)
                {
                    newFileName = Path.Combine(path, aFile.fileName);
                }

                // Same name management
                Tools.RenameIfNecessary(newFileName, LibraryConstants.SUFFIX_OLD_FILE);

                // On lance la création
                File2.WriteBytesToFile(newFileName, aFile.Data);
            }
        }