Пример #1
0
 public void OpenBigArchive()
 {
     using (var bigArchive = new BigArchive(_bigFilePath))
     {
         Assert.Equal(4432, bigArchive.Entries.Count);
     }
 }
Пример #2
0
        static void AddFileToArchive(BigArchive archive, string filepath, bool update = false)
        {
            BigArchiveEntry entry = null;

            if (!update)
            {
                Console.WriteLine("adding: {0}", filepath);
                entry = archive.CreateEntry(filepath);
            }
            else
            {
                try
                {
                    entry = archive.Entries.First(x => x.FullName == filepath);
                    Console.WriteLine("updating: {0}", filepath);
                }
                catch (InvalidOperationException e)
                {
                    entry = archive.CreateEntry(filepath);
                    Console.WriteLine("adding: {0}", filepath);
                }
            }

            using (var entryStream = entry.Open())
            {
                using (var fileStream = File.OpenRead(filepath))
                {
                    fileStream.CopyTo(entryStream);
                }
            }
        }
Пример #3
0
        public FileSystem(string rootDirectory)
        {
            _fileTable   = new Dictionary <string, FileSystemEntry>(StringComparer.OrdinalIgnoreCase);
            _bigArchives = new List <BigArchive>();

            // TODO: Figure out if there's a specific order that .big files should be loaded in,
            // since some files are contained in more than one .big file so the later one
            // takes precedence over the earlier one.

            foreach (var file in Directory.GetFiles(rootDirectory, "*.*", SearchOption.AllDirectories))
            {
                var ext = Path.GetExtension(file).ToLower();
                if (ext == ".big")
                {
                    var bigStream = File.OpenRead(file);
                    var archive   = new BigArchive(bigStream);

                    _bigArchives.Add(archive);

                    foreach (var entry in archive.Entries)
                    {
                        _fileTable[entry.FullName] = new FileSystemEntry(this, entry.FullName, entry.Length, entry.Open);
                    }
                }
                else
                {
                    var relativePath = file.Substring(rootDirectory.Length);
                    if (relativePath.StartsWith(Path.DirectorySeparatorChar.ToString()))
                    {
                        relativePath = relativePath.Substring(1);
                    }
                    _fileTable[relativePath] = new FileSystemEntry(this, relativePath, (uint)new FileInfo(file).Length, () => File.OpenRead(file));
                }
            }
        }
Пример #4
0
 public void OpenBigArchive()
 {
     using (var bigStream = File.OpenRead(BigFilePath))
         using (var bigArchive = new BigArchive(bigStream))
         {
             Assert.Equal(4432, bigArchive.Entries.Count);
         }
 }
Пример #5
0
        public void GetEntryByName()
        {
            using (var bigArchive = new BigArchive(_bigFilePath))
            {
                var entry = bigArchive.GetEntry(@"Art\W3D\ABBarracks_AC.W3D");

                Assert.Equal(@"Art\W3D\ABBarracks_AC.W3D", entry.FullName);
                Assert.Equal(9334u, entry.Length);
            }
        }
Пример #6
0
        public void ReadFirstEntry()
        {
            using (var bigArchive = new BigArchive(_bigFilePath))
            {
                var firstEntry = bigArchive.Entries[0];

                Assert.Equal(@"Art\W3D\ABBarracks_AC.W3D", firstEntry.FullName);
                Assert.Equal(9334u, firstEntry.Length);
            }
        }
Пример #7
0
 static void AddDirectoryToArchive(BigArchive archive, string dirpath, bool update = false)
 {
     foreach (string dir in Directory.GetDirectories(dirpath))
     {
         foreach (string file in Directory.GetFiles(dir))
         {
             AddFileToArchive(archive, file);
         }
         AddDirectoryToArchive(archive, dir);
     }
 }
Пример #8
0
        public void LoadW3dFromBigFile()
        {
            var bigFilePath = Path.Combine(InstalledFilesTestData.GetInstallationDirectory(SageGame.CncGeneralsZeroHour), "W3DZH.big");

            using (var bigArchive = new BigArchive(bigFilePath))
            {
                var entry = bigArchive.GetEntry(@"Art\W3D\ABBarracks_AC.W3D");

                var w3dFile = W3dFile.FromFileSystemEntry(new FileSystemEntry(null, entry.FullName, entry.Length, entry.Open));
                Assert.Equal(3, w3dFile.Meshes.Count);
            }
        }
Пример #9
0
        private void Open_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            //ofd.Filter = ""
            if (ofd.ShowDialog() == true)
            {
                BigArchive arch = new BigArchive(File.Open(ofd.FileName, FileMode.Open));
                ui_listview.ItemsSource = arch.Entries;
                CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(ui_listview.ItemsSource);
                view.Filter = UserFilter;
            }
        }
Пример #10
0
        public void LoadW3dFromBigFile()
        {
            const string bigFilePath = @"C:\Program Files (x86)\Origin Games\Command and Conquer Generals Zero Hour\Command and Conquer Generals Zero Hour\W3DZH.big";

            using (var bigStream = File.OpenRead(bigFilePath))
                using (var bigArchive = new BigArchive(bigStream))
                {
                    var entry = bigArchive.GetEntry(@"Art\W3D\ABBarracks_AC.W3D");

                    var w3dFile = W3dFile.FromFileSystemEntry(new FileSystemEntry(null, entry.FullName, entry.Length, entry.Open));
                    Assert.Equal(3, w3dFile.Meshes.Count);
                }
        }
Пример #11
0
        static void ListMode(Options opts)
        {
            var archive = new BigArchive(opts.ArchiveName, BigArchiveMode.Read);

            Console.WriteLine("Archive: " + Path.GetFileName(archive.FilePath));

            var table = new ConsoleTable("Length", "Name");

            foreach (var entry in archive.Entries)
            {
                table.AddRow(entry.Length, entry.FullName);
            }

            table.Write(Format.Minimal);
        }
Пример #12
0
        private void AddBigArchive(string path)
        {
            var archive = new BigArchive(path);

            _bigArchives.Add(archive);

            foreach (var entry in archive.Entries)
            {
                var filePath = NormalizeFilePath(entry.FullName);
                if (!_fileTable.ContainsKey(filePath))
                {
                    _fileTable.Add(filePath, new FileSystemEntry(this, filePath, entry.Length, entry.Open));
                }
            }
        }
Пример #13
0
        public void CheckEntryCount()
        {
            var bigFilePath = Path.Combine(InstalledFilesTestData.GetInstallationDirectory(SageGame.Bfme2), "apt/MainMenu.big");

            using (var bigArchive = new BigArchive(bigFilePath))
            {
                var entry = bigArchive.GetEntry(@"MainMenu.const");

                var data = ConstantData.FromFileSystemEntry(new FileSystemEntry(null, entry.FullName, entry.Length, entry.Open));
                Assert.NotNull(data);

                //requires unmodified main menu
                Assert.Equal(412, data.Entries.Count);
            }
        }
Пример #14
0
        private void OpenBigFile(string filePath)
        {
            RemoveAndDispose(ref _bigArchive);

            if (File.Exists(filePath))
            {
                _bigArchive = AddDisposable(new BigArchive(filePath));
            }

            _currentFile      = -1;
            _currentFileText  = null;
            _searchTextBuffer = new byte[32];
            _filePathBuffer   = new byte[1024];
            _files.Clear();
            UpdateSearch(null);
        }
Пример #15
0
        public void ReadFirstEntryStream()
        {
            using (var bigArchive = new BigArchive(_bigFilePath))
            {
                var firstEntry = bigArchive.Entries[0];

                using (var firstEntryStream = firstEntry.Open())
                {
                    Assert.Equal(9334, firstEntryStream.Length);

                    var buffer    = new byte[10000];
                    var readBytes = firstEntryStream.Read(buffer, 0, buffer.Length);
                    Assert.Equal(9334, readBytes);
                }
            }
        }
Пример #16
0
        public void LoadW3dFromBigFile()
        {
            var bigFilePath = Path.Combine(InstalledFilesTestData.GetInstallationDirectory(SageGame.CncGeneralsZeroHour), "W3DZH.big");

            using (var bigArchive = new BigArchive(bigFilePath))
            {
                var entry = bigArchive.GetEntry(@"Art\W3D\ABBarracks_AC.W3D");

                W3dFile w3dFile;
                using (var entryStream = entry.Open())
                {
                    w3dFile = W3dFile.FromStream(entryStream, entry.FullName);
                }

                Assert.Equal(3, w3dFile.GetMeshes().Count);
            }
        }
Пример #17
0
        static void CreateMode(Options opts)
        {
            var archive = new BigArchive(opts.ArchiveName, BigArchiveMode.Create);

            foreach (var entryName in opts.Files)
            {
                var attr = File.GetAttributes(entryName);

                if (attr.HasFlag(FileAttributes.Directory))
                {
                    AddDirectoryToArchive(archive, entryName);
                }
                else
                {
                    AddFileToArchive(archive, entryName);
                }
            }
        }
Пример #18
0
        static void DeleteMode(Options opts)
        {
            var archive = new BigArchive(opts.ArchiveName, BigArchiveMode.Update);

            foreach (var entryName in opts.Files)
            {
                try
                {
                    var entry = archive.Entries.First(x => x.FullName == entryName);
                    Console.WriteLine("deleting: {0}", entryName);
                    entry.Delete();
                }
                catch (InvalidOperationException e)
                {
                    Console.WriteLine(e.Message + ": " + entryName);
                }
            }
        }
Пример #19
0
        void AppendEntry()
        {
            var fullPath = Path.Combine(RootFolder, "test.big");

            using (var bigArchive = new BigArchive(fullPath))
            {
                Assert.Equal(2, bigArchive.Entries.Count);

                var entry = bigArchive.CreateEntry("b.txt");

                using (var stream = entry.Open())
                {
                    using (var sw = new StreamWriter(stream))
                    {
                        sw.Write("This is sample B");
                    }
                }
            }
        }
Пример #20
0
        private void OpenBigFile(DialogResult result)
        {
            if (!result.Success)
            {
                return;
            }

            Reset();

            if (File.Exists(result.FileName))
            {
                try
                {
                    _bigArchive = AddDisposable(new BigArchive(result.FileName, BigArchiveMode.Update));
                }
                catch (Exception e)
                {
                    logger.Error(e.Message);
                }
            }
        }
Пример #21
0
        static void ExtractMode(Options opts)
        {
            var archive = new BigArchive(opts.ArchiveName, BigArchiveMode.Read);

            foreach (var entry in archive.Entries)
            {
                using (var entryStream = entry.Open())
                {
                    var dirName = Path.GetDirectoryName(entry.FullName);
                    if (!string.IsNullOrEmpty(dirName))
                    {
                        Directory.CreateDirectory(dirName);
                    }

                    using (var fileStream = File.OpenWrite(entry.FullName))
                    {
                        Console.WriteLine("extracting: {0}", entry.FullName);
                        entryStream.CopyTo(fileStream);
                    }
                }
            }
        }
Пример #22
0
        private void OpenBigFile(string filePath)
        {
            RemoveAndDispose(ref _bigArchive);

            if (File.Exists(filePath))
            {
                try
                {
                    _bigArchive = AddDisposable(new BigArchive(filePath));
                }
                catch (Exception e)
                {
                    logger.Error(e.Message);
                }
            }

            _currentFile      = -1;
            _currentFileName  = "";
            _currentFileText  = null;
            _searchTextBuffer = new byte[32];
            _filePathBuffer   = new byte[1024];
            _files.Clear();
            UpdateSearch(null);
        }