private void ReadIndex(FileStream file) { var arr = new byte[header.directorySize]; int readLen = file.Read(arr, 0, header.directorySize); if (readLen != header.directorySize) { Debug.WriteLine(String.Format( "ERROR: File reading: Expecting length {0}, got {1}.", header.directorySize, readLen)); throw new VpkException(VpkException.ExceptionReason.Unknown); } try { for (int i = 0; i < readLen;) { // Ahh, ref.Cannot imagine whatif it's in java. // https://www.c-sharpcorner.com/article/ref-keyword-in-c-sharp/ // https://stackoverflow.com/questions/186891/why-use-the-ref-keyword-when-passing-an-object var extensionName = CStringUtil.ReadCString(arr, ref i); if (extensionName.Length == 0) { break; } var extensionNode = new Dictionary <string, Dictionary <string, VpkContainedFileDescription> >(); Vindex[extensionName] = extensionNode; i = ReadUnderExtensionName(arr, i, extensionNode); } } catch (InvalidOperationException) { Debug.WriteLine( "ERROR: File index parsing: Reading null-terminated string out of bound." ); throw new VpkException(VpkException.ExceptionReason.Unknown); } }
private int ReadUnderPath(byte[] buffer, int offset, Dictionary <string, VpkContainedFileDescription> pathNode) { int maxLen = buffer.Length; while (offset < maxLen) { var name = CStringUtil.ReadCString(buffer, ref offset); if (name.Length == 0) { break; } //name = JoinPath(path, name, extensionName); var fileNode = new VpkContainedFileDescription(name); pathNode[name] = fileNode; offset = ReadFileIndexerOfName(buffer, offset, fileNode); } return(offset); }
private int ReadUnderExtensionName(byte[] buffer, int offset, Dictionary <string, Dictionary <string, VpkContainedFileDescription> > extensionNode) { int maxLen = buffer.Length; while (offset < maxLen) { var path = CStringUtil.ReadCString(buffer, ref offset); if (path.Length == 0) { break; } if (path == " ") { path = ""; } var pathNode = new Dictionary <string, VpkContainedFileDescription>(); extensionNode[path] = pathNode; offset = ReadUnderPath(buffer, offset, pathNode); } return(offset); }