public void OpenBigArchive() { using (var bigArchive = new BigArchive(_bigFilePath)) { Assert.Equal(4432, bigArchive.Entries.Count); } }
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); } } }
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)); } } }
public void OpenBigArchive() { using (var bigStream = File.OpenRead(BigFilePath)) using (var bigArchive = new BigArchive(bigStream)) { Assert.Equal(4432, bigArchive.Entries.Count); } }
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); } }
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); } }
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); } }
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); } }
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; } }
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); } }
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); }
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)); } } }
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); } }
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); }
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); } } }
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); } }
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); } } }
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); } } }
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"); } } } }
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); } } }
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); } } } }
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); }