public Stream OpenDataFileDirect(MD5Hash key) { var keyStr = key.ToHexString().ToLower(); var file = config.CDNPath + "/data/" + keyStr.Substring(0, 2) + "/" + keyStr.Substring(2, 2) + "/" + keyStr; var url = "http://" + config.CDNHost + "/" + file; return(OpenFile(url)); }
public IndexEntry GetIndexInfo(MD5Hash key) { if (!CDNIndexData.TryGetValue(key, out IndexEntry result)) { Logger.WriteLine("CDNIndexHandler: missing index: {0}", key.ToHexString()); } return(result); }
public IndexEntry GetIndexInfo(MD5Hash key) { if (!CDNIndexData.TryGetValue(key, out IndexEntry result)) { Debug.Log($"CDNIndexHandler: missing index: {key.ToHexString()}"); } return(result); }
protected override Stream GetLocalDataStream(MD5Hash key) { IndexEntry idxInfo = LocalIndex.GetIndexInfo(key); if (idxInfo == null) { Console.WriteLine("Local index missing: {0}", key.ToHexString()); } return(GetLocalDataStreamInternal(idxInfo, key)); }
protected override Stream GetLocalDataStream(MD5Hash key) { IndexEntry idxInfo = LocalIndex.GetIndexInfo(key); if (idxInfo == null) { Debug.Log($"Local index missing: {key.ToHexString()}"); } return(GetLocalDataStreamInternal(idxInfo, key)); }
public unsafe IndexEntry GetIndexInfo(MD5Hash key) { ulong *ptr = (ulong *)&key; ptr[1] &= 0xFF; if (!LocalIndexData.TryGetValue(key, out IndexEntry result)) { Console.WriteLine("LocalIndexHandler: missing index: {0}", key.ToHexString()); } return(result); }
public unsafe IndexEntry GetIndexInfo(MD5Hash key) { ulong *ptr = (ulong *)&key; ptr[1] &= 0xFF; if (!LocalIndexData.TryGetValue(key, out IndexEntry result)) { Debug.Log($"LocalIndexHandler: missing index: {key.ToHexString()}"); } return(result); }
public Stream OpenDataFileDirect(MD5Hash key) { var keyStr = key.ToHexString().ToLower(); worker?.ReportProgress(0, string.Format("Downloading \"{0}\" file...", keyStr)); string file = config.CDNPath + "/data/" + keyStr.Substring(0, 2) + "/" + keyStr.Substring(2, 2) + "/" + keyStr; string url = "http://" + config.CDNHost + "/" + file; Stream stream = Cache.OpenFile(file, url, false); if (stream != null) { return(stream); } return(downloader.OpenFile(url)); }
public Stream OpenDataFileDirect(MD5Hash key) { var keyStr = key.ToHexString().ToLower(); worker?.ReportProgress(0, string.Format("Downloading \"{0}\" file...", keyStr)); string file = config.CDNPath + "/data/" + keyStr.Substring(0, 2) + "/" + keyStr.Substring(2, 2) + "/" + keyStr; Stream stream = CDNCache.Instance.OpenFile(file, false); if (stream != null) { stream.Position = 0; MemoryStream ms = new MemoryStream(); stream.CopyTo(ms); ms.Position = 0; return(ms); } string url = "http://" + config.CDNHost + "/" + file; return(OpenFile(url)); }
public EncodingHandler(BinaryReader stream, BackgroundWorkerEx worker) { worker?.ReportProgress(0, "Loading \"encoding\"..."); stream.Skip(2); // EN byte b1 = stream.ReadByte(); byte checksumSizeA = stream.ReadByte(); byte checksumSizeB = stream.ReadByte(); ushort flagsA = stream.ReadUInt16(); ushort flagsB = stream.ReadUInt16(); int numEntriesA = stream.ReadInt32BE(); int numEntriesB = stream.ReadInt32BE(); byte b4 = stream.ReadByte(); int stringBlockSize = stream.ReadInt32BE(); stream.Skip(stringBlockSize); //string[] strings = Encoding.ASCII.GetString(stream.ReadBytes(stringBlockSize)).Split(new[] { '\0' }, StringSplitOptions.RemoveEmptyEntries); stream.Skip(numEntriesA * 32); //for (int i = 0; i < numEntriesA; ++i) //{ // byte[] firstHash = stream.ReadBytes(16); // byte[] blockHash = stream.ReadBytes(16); //} long chunkStart = stream.BaseStream.Position; for (int i = 0; i < numEntriesA; ++i) { ushort keysCount; while ((keysCount = stream.ReadUInt16()) != 0) { int fileSize = stream.ReadInt32BE(); MD5Hash md5 = stream.Read <MD5Hash>(); EncodingEntry entry = new EncodingEntry() { Size = fileSize }; // how do we handle multiple keys? for (int ki = 0; ki < keysCount; ++ki) { MD5Hash key = stream.Read <MD5Hash>(); // use first key for now if (ki == 0) { entry.Key = key; } else { Logger.WriteLine("Multiple encoding keys for MD5 {0}: {1}", md5.ToHexString(), key.ToHexString()); } } //Encodings[md5] = entry; EncodingData.Add(md5, entry); } // each chunk is 4096 bytes, and zero padding at the end long remaining = CHUNK_SIZE - ((stream.BaseStream.Position - chunkStart) % CHUNK_SIZE); if (remaining > 0) { stream.BaseStream.Position += remaining; } worker?.ReportProgress((int)((i + 1) / (float)numEntriesA * 100)); } stream.Skip(numEntriesB * 32); //for (int i = 0; i < numEntriesB; ++i) //{ // byte[] firstKey = stream.ReadBytes(16); // byte[] blockHash = stream.ReadBytes(16); //} long chunkStart2 = stream.BaseStream.Position; for (int i = 0; i < numEntriesB; ++i) { byte[] key = stream.ReadBytes(16); int stringIndex = stream.ReadInt32BE(); byte unk1 = stream.ReadByte(); int fileSize = stream.ReadInt32BE(); // each chunk is 4096 bytes, and zero padding at the end long remaining = CHUNK_SIZE - ((stream.BaseStream.Position - chunkStart2) % CHUNK_SIZE); if (remaining > 0) { stream.BaseStream.Position += remaining; } } // string block till the end of file }
protected Stream OpenFileOnlineInternal(IndexEntry idxInfo, MD5Hash key) { Stream s; if (idxInfo != null) { s = CDNIndex.OpenDataFile(idxInfo); } else { s = CDNIndex.OpenDataFileDirect(key); } BLTEStream blte; try { blte = new BLTEStream(s, key); } catch (BLTEDecoderException exc) when(exc.ErrorCode == 0) { CDNCache.Instance.InvalidateFile(idxInfo != null ? Config.Archives[idxInfo.Index] : key.ToHexString()); return(OpenFileOnlineInternal(idxInfo, key)); } return(blte); }