Exemple #1
0
        /// <summary>
        /// Loads a GMAD file with given path and extracts properties and files list
        /// </summary>
        /// <param name="path">Path to .gmad file</param>
        public void Parse(string path)
        {
            Reset();

            _filePath = path;

            using (var r = new BinaryReader(File.Open(path, FileMode.Open)))
            {
                var length = r.BaseStream.Length;
                _header.Ident = Encoding.ASCII.GetString(r.ReadBytes(4));

                if (_header.Ident != "GMAD")
                    throw new GmadReaderException("File is not a GMAD file. Got ident " + _header.Ident);

                _header.Version = r.ReadByte();

                if (_header.Version > FileFormat.Version)
                    throw new GmadReaderException("File is in a newer format than this version of GMAD.NET supports. Format version is " + _header.Version);

                _header.SteamId = BitConverter.ToUInt64(r.ReadBytes(8), 0);

                var timestamp = BitConverter.ToUInt64(r.ReadBytes(8), 0);
                _header.Timestamp = (new DateTime(1970, 1, 1, 0, 0, 0)).AddSeconds(Convert.ToDouble(timestamp));

                // Not used
                if (_header.Version > 1)
                {
                    var content = r.ReadNullTerminatedString();

                    while (!String.IsNullOrEmpty(content))
                    {
                        content = r.ReadNullTerminatedString();
                    }
                }

                _header.Name = r.ReadNullTerminatedString();
                _header.Description = r.ReadNullTerminatedString();
                _header.Author = r.ReadNullTerminatedString();

                _header.AddonVersion = r.ReadInt32();

                long offset = 0;
                uint fileno = 1;

                // Files block
                while (r.ReadUInt32() != 0)
                {
                    var entry = new FileFormat.FileEntry();

                    entry.StrName = r.ReadNullTerminatedString();
                    entry.Size = r.ReadInt64();
                    entry.CRC = r.ReadUInt32();
                    entry.Offset = offset;
                    entry.FileNumber = fileno;

                    offset += entry.Size;
                    fileno++;

                    _files.Add(entry);
                }

                if(_files.Count < 1)
                    throw new GmadReaderException("Got no files from GMAD package.");

                _header.FileBlock = r.BaseStream.Position;
            }
        }
Exemple #2
0
        protected void AddDirectory(string basedir, string path)
        {
            foreach (var d in Directory.GetDirectories(path + "/"))
            {
                if(basedir != d)
                    AddDirectory(basedir, d); // recursive directory search
            }

            foreach(var f in Directory.GetFiles(path))
            {
                if (Whitelist.Check(f))
                {
                    // do stuff with files
                    var file = new FileFormat.FileEntry();
                    file.LocalFile = true;
                    file.PhysicalPath = f;
                    file.StrName = file.PhysicalPath.Substring(basedir.Length + 1).Replace("\\", "/");
                    file.Size = 0;

                    activeReader.Files.Add(file);
                }
            }
        }