bool AddAdditionalAssets(AssetDescSet assets) { try { DirectoryInfo directoryInfo = new DirectoryInfo(_dataFolderName); FileInfo[] fileInfos = directoryInfo.GetFiles("*", SearchOption.AllDirectories); if (fileInfos.Length <= 0) { throw new Exception("No files in \"" + _dataFolderName + "\"."); } foreach (FileInfo fileInfo in fileInfos) { string relativePath = fileInfo.FullName.Substring(_projectFolderName.Length); string extension = Path.GetExtension(relativePath); int endOfName = relativePath.Length - extension.Length; uint hashID = getSR1HashName(relativePath); // There may be more than one file with the same hash ID in the source bigfile. // Update the sizes for all of them. List <AssetDesc> existingEntries = assets.FindAll(x => x.FileHash == hashID); if (existingEntries != null) { foreach (AssetDesc existingEntry in existingEntries) { existingEntry.FileLength = (uint)fileInfo.Length; } } else { AssetDesc newEntry = new AssetDesc(); newEntry.FilePath = relativePath; newEntry.FileHash = hashID; newEntry.FileLength = (uint)fileInfo.Length; newEntry.Code.code0 = char.ToUpperInvariant(relativePath[endOfName - 4]); newEntry.Code.code1 = char.ToUpperInvariant(relativePath[endOfName - 3]); newEntry.Code.code2 = char.ToUpperInvariant(relativePath[endOfName - 2]); newEntry.Code.code3 = char.ToUpperInvariant(relativePath[endOfName - 1]); newEntry.FileIndex = assets.Count; assets.Add(newEntry); } } } catch (Exception) { assets.Clear(); Console.WriteLine("Error: Couldn't generate bigfile entries."); return(false); } return(true); }
bool LoadBigfileEntries(AssetDescSet assets) { if (!LoadHashTable(out Hashtable hashTable)) { return(false); } assets.Clear(); try { FileStream sourceFile = new FileStream(_sourceBigfileName, FileMode.Open, FileAccess.Read); BinaryReader reader = new BinaryReader(sourceFile); uint entryCount = reader.ReadUInt32(); while (entryCount > 0) { AssetDesc entry = new AssetDesc(); entry.FileHash = reader.ReadUInt32(); entry.FileLength = reader.ReadUInt32(); entry.FileOffset = reader.ReadUInt32(); entry.Code.code = reader.ReadUInt32(); string hashString = string.Format("{0:X8}", entry.FileHash); if (hashTable.Contains(hashString)) { entry.FilePath = (string)hashTable[hashString]; } assets.Add(entry); entryCount--; } reader.Close(); sourceFile.Close(); // Sort by offsets. SortedList <uint, AssetDesc> sortedAssets = new SortedList <uint, AssetDesc>(); foreach (AssetDesc asset in assets.Assets) { sortedAssets.Add(asset.FileOffset, asset); } // Fill indices according to their offset. int assetIndex = 0; foreach (AssetDesc asset in sortedAssets.Values) { asset.FileIndex = assetIndex; assetIndex++; } } catch (Exception) { assets.Clear(); Console.WriteLine("Error: Couldn't load bigfile entries."); return(false); } return(true); }
public void Add(AssetDesc asset) { _AssetDescList.Add(asset); }