コード例 #1
0
        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));
        }
コード例 #2
0
        public IndexEntry GetIndexInfo(MD5Hash key)
        {
            if (!CDNIndexData.TryGetValue(key, out IndexEntry result))
            {
                Logger.WriteLine("CDNIndexHandler: missing index: {0}", key.ToHexString());
            }

            return(result);
        }
コード例 #3
0
        public IndexEntry GetIndexInfo(MD5Hash key)
        {
            if (!CDNIndexData.TryGetValue(key, out IndexEntry result))
            {
                Debug.Log($"CDNIndexHandler: missing index: {key.ToHexString()}");
            }

            return(result);
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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));
        }
コード例 #9
0
        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));
        }
コード例 #10
0
        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
        }
コード例 #11
0
        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);
        }