Exemplo n.º 1
0
        private void crawlDirectoryTree(string _rootDirectory)
        {
            Folder root = new Folder(_rootDirectory);
            serializeAllFiles(ref root, Directory.GetFiles(_rootDirectory));

            string[] directories = Directory.GetDirectories(_rootDirectory);
            
            foreach(string s in directories)
            {
                Folder f = new Folder(s);
                root.addSubFolder(f);
                crawlDirectoryTree(ref f);
            }

            List<byte> byteBuffer = new List<byte>();
            UInt32 offset = sizeof(UInt32);
            getAssetBinaryBlob(root, ref offset, ref byteBuffer);
            getFolderHeaderData(root, ref byteBuffer);

            List<byte> finalByteBuffer = new List<byte>(byteBuffer.Count + sizeof(UInt32));
            finalByteBuffer.AddRange(BitConverter.GetBytes(offset));
            finalByteBuffer.AddRange(byteBuffer);

            if(cb_compress.Checked)
            {
                using (FileStream fs = File.Create(folderPath + "_comp" + fileFormatName))
                {
                    using (GZipStream gz = new GZipStream(fs, CompressionMode.Compress, false))
                    {
                        gz.Write(finalByteBuffer.ToArray(), 0, finalByteBuffer.Count);
                    }
                }
            }
            else
            {
                using (FileStream fs = File.Create(folderPath + fileFormatName))
                {
                    fs.Write(finalByteBuffer.ToArray(), 0, finalByteBuffer.Count);
                }
            }
        }
Exemplo n.º 2
0
 public void addSubFolder(Folder _folder)
 {
     subFolders.Add(_folder);
 }
Exemplo n.º 3
0
        private void crawlDirectoryTree(ref Folder _rootDirectory)
        {
            serializeAllFiles(ref _rootDirectory, Directory.GetFiles(_rootDirectory.getPath()));

            string[] directories = Directory.GetDirectories(_rootDirectory.getPath());

            foreach (string s in directories)
            {
                Folder f = new Folder(s);
                _rootDirectory.addSubFolder(f);
                crawlDirectoryTree(ref f);
            }
        }
Exemplo n.º 4
0
        private void getFolderHeaderData(Folder _f, ref List<byte> _list)
        {
            _list.AddRange(Utils.serializeString(_f.getName()));
            _list.AddRange(BitConverter.GetBytes((UInt32)_f.getAssets().Count));

            foreach(Asset a in _f.getAssets())
            {
                _list.AddRange(Utils.serializeString(a.getName()));
                _list.AddRange(BitConverter.GetBytes((UInt32)a.getStart()));
                _list.AddRange(BitConverter.GetBytes((UInt32)a.getSize()));
            }

            _list.AddRange(BitConverter.GetBytes((UInt32)_f.getSubFolders().Count()));

            foreach(Folder f in _f.getSubFolders())
            {
                getFolderHeaderData(f, ref _list);
            }
        }
Exemplo n.º 5
0
        private void getAssetBinaryBlob(Folder _f, ref UInt32 _offset, ref List<byte> _list)
        {
            foreach (Asset a in _f.getAssets())
            {
                a.setStart(_offset);
                _offset += a.getSize();
                _list.AddRange(a.getBytes());
            }

            foreach (Folder f in _f.getSubFolders())
            {
                getAssetBinaryBlob(f, ref _offset, ref _list);
            }
        }
Exemplo n.º 6
0
 private void serializeAllFiles(ref Folder _folder, string[] _files)
 {
     for (int i = 0; i < _files.Length; i++)
     {
         byte[] tmp = File.ReadAllBytes(_files[i]);
         _folder.addAsset(new Asset(_files[i], tmp));
     }
 }