Ejemplo n.º 1
0
        private void ExtractFile(byte[] key, string path, string name)
        {
            try
            {
                if (config.OnlineMode)
                {
                    throw new Exception("OnlineMode=true");
                }

                var idxInfo = LocalIndex.GetIndexInfo(key);

                if (idxInfo == null)
                {
                    throw new Exception("local index missing");
                }

                var stream = GetDataStream(idxInfo.Index);

                stream.Position = idxInfo.Offset;

                stream.Position += 30;
                //byte[] unkHash = reader.ReadBytes(16);
                //int __size = reader.ReadInt32();
                //byte[] unkData1 = reader.ReadBytes(2);
                //byte[] unkData2 = reader.ReadBytes(8);

                using (BLTEHandler blte = new BLTEHandler(stream, idxInfo.Size - 30))
                {
                    blte.ExtractToFile(path, name);
                }
            }
            catch
            {
                var idxInfo = CDNIndex.GetIndexInfo(key);

                if (idxInfo != null)
                {
                    using (Stream s = CDNIndex.OpenDataFile(key))
                        using (BLTEHandler blte = new BLTEHandler(s, idxInfo.Size))
                        {
                            blte.ExtractToFile(path, name);
                        }
                }
                else
                {
                    try
                    {
                        using (Stream s = CDNIndex.OpenDataFileDirect(key))
                            using (BLTEHandler blte = new BLTEHandler(s, (int)s.Length))
                            {
                                blte.ExtractToFile(path, name);
                            }
                    }
                    catch
                    {
                        throw new Exception("CDN index missing");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private Stream OpenFile(byte[] key)
        {
            try
            {
                if (config.OnlineMode)
                {
                    throw new Exception("OnlineMode=true");
                }

                var idxInfo = LocalIndex.GetIndexInfo(key);

                if (idxInfo == null)
                {
                    throw new Exception("local index missing");
                }

                var stream = GetDataStream(idxInfo.Index);

                stream.Position = idxInfo.Offset;

                stream.Position += 30;

                using (BLTEHandler blte = new BLTEHandler(stream, idxInfo.Size - 30))
                {
                    return(blte.OpenFile());
                }
            }
            catch
            {
                var idxInfo = CDNIndex.GetIndexInfo(key);

                if (idxInfo != null)
                {
                    using (Stream s = CDNIndex.OpenDataFile(key))
                        using (BLTEHandler blte = new BLTEHandler(s, idxInfo.Size))
                        {
                            return(blte.OpenFile());
                        }
                }
                else
                {
                    try
                    {
                        using (Stream s = CDNIndex.OpenDataFileDirect(key))
                            using (BLTEHandler blte = new BLTEHandler(s, (int)s.Length))
                            {
                                return(blte.OpenFile());
                            }
                    }
                    catch
                    {
                        throw new Exception("CDN index missing");
                    }
                }
            }
        }