void downloader_Complete(object sender, EventArgs e)
        {
            if (DownloadProgress != null)
            {
                progress.bytesDownloaded = downloader.TotalBytesDownloaded;
                progress.downloadRate    = 0;
                DownloadProgress(this, progress);
            }

            archive = null;

            if (Complete != null)
            {
                Complete(this, e);
            }

            if (progress.manifestsDownloaded + progress.filesDownloaded > 0 && progress.manifestsDownloaded == progress.manifestsTotal && progress.filesDownloaded == progress.filesTotal)
            {
                if (!progress.rescan || progress.filesDownloaded > 0)
                {
                    if (PatchReady != null)
                    {
                        var pr = new PatchEventArgs()
                        {
                            Build   = progress.build,
                            Elapsed = DateTime.UtcNow.Subtract(progress.startTime),
                            Files   = progress.filesTotal + progress.manifestsTotal,
                            Size    = progress.contentBytesTotal - progress.contentBytesCore
                        };
                        PatchReady(this, pr);
                    }
                }
            }
        }
Example #2
0
        private static byte[] CreateGw2Cache(Dat.Compression.Archive compressor, int build, bool compress)
        {
            var buffer = new byte[532];
            var b      = BitConverter.GetBytes(build);

            buffer[0] = (byte)'A';
            buffer[1] = (byte)'R';
            buffer[2] = (byte)'A';
            buffer[3] = (byte)'P';

            buffer[4] = b[0];
            buffer[5] = b[1];

            //null terminated unicode string

            //int i = 6;
            //foreach (char c in CUSTOM_GW2CACHE_FOLDER_NAME)
            //{
            //    buffer[i] = (byte)c;
            //    i += 2;
            //}

            buffer[6]  = (byte)'g';
            buffer[8]  = (byte)'w';
            buffer[10] = (byte)'2';
            buffer[12] = (byte)'c';
            buffer[14] = (byte)'a';
            buffer[16] = (byte)'c';
            buffer[18] = (byte)'h';
            buffer[20] = (byte)'e';

            buffer[528] = (byte)'D';
            buffer[529] = (byte)'I';
            buffer[530] = (byte)'O';
            buffer[531] = (byte)'N';

            if (compress)
            {
                using (var ms = new MemoryStream(buffer.Length))
                {
                    var size = compressor.Compress(buffer, 0, buffer.Length, ms);

                    return(ms.ToArray());
                }
            }
            else
            {
                return(buffer);
            }
        }
Example #3
0
        private byte[] CreateGw2Cache(Dat.Compression.Archive compressor, int build, bool compress)
        {
            var buffer = new byte[532];
            var b      = BitConverter.GetBytes(build);

            buffer[0] = (byte)'A';
            buffer[1] = (byte)'R';
            buffer[2] = (byte)'A';
            buffer[3] = (byte)'P';

            buffer[4] = b[0];
            buffer[5] = b[1];

            buffer[6]  = (byte)'g';
            buffer[8]  = (byte)'w';
            buffer[10] = (byte)'2';
            buffer[12] = (byte)'c';
            buffer[14] = (byte)'a';
            buffer[16] = (byte)'c';
            buffer[18] = (byte)'h';
            buffer[20] = (byte)'e';

            buffer[528] = (byte)'D';
            buffer[529] = (byte)'I';
            buffer[530] = (byte)'O';
            buffer[531] = (byte)'N';

            if (compress)
            {
                using (var ms = new MemoryStream(buffer.Length))
                {
                    var size = compressor.Compress(buffer, 0, buffer.Length, ms);

                    return(ms.ToArray());
                }
            }
            else
            {
                return(buffer);
            }
        }
Example #4
0
        private async Task <bool> GetManifests(int manifestId, int manifestSize, Dictionary <int, int> baseIds, bool rescan)
        {
            int existing;

            if (baseIds.TryGetValue(MANIFEST_BASE_ID, out existing) && existing == manifestId)
            {
                if (!rescan)
                {
                    return(true); //the manifest is already up to date
                }
            }
            else if (rescan)
            {
                progress.rescan = false;
            }

            progress.manifestsTotal++;
            progress.estimatedBytesRemaining += manifestSize;
            progress.estimatedTotalBytes     += manifestSize;

            int language;

            switch (Settings.BackgroundPatchingLang.Value)
            {
            case 1:     //DE
                language = 296042;
                break;

            case 3:     //FR
                language = 296043;
                break;

            case 2:     //ES (n/a)
            case 0:     //EN
            default:
                language = 296040;
                break;
            }

#warning useCompression = BitConverter.IsLittleEndian
            var useCompression = BitConverter.IsLittleEndian;

            if (useCompression && archive == null)
            {
                archive = new Dat.Compression.Archive();
            }

            //var asset = new Net.AssetDownloader.Asset(manifestId, false, manifestSize);
            var asset = new Net.AssetDownloader.Asset(manifestId, useCompression, useCompression ? (int)(manifestSize * AVG_COMPRESSION + 0.5f) : manifestSize);
            asset.Complete += delegate(object o, Net.AssetDownloader.Asset.CompleteEventArgs c)
            {
                progress.contentBytesCore += c.ContentLength;
            };
            asset.Progress += asset_Progress;

            var cache = await downloader.Download(asset);

            using (cache)
            {
                if (cache != null && cache.HasData)
                {
                    cache.SetPositionToContent();
                    var          p = cache.Position;
                    Dat.Manifest manifest;

                    if (useCompression)
                    {
                        using (var ms = new MemoryStream(archive.DecompressRaw(cache, manifestSize)))
                        {
                            manifest = Tools.Dat.Manifest.Parse(ms);
                        }
                    }
                    else
                    {
                        manifest = Tools.Dat.Manifest.Parse(cache);
                        Create404Manifest(manifestId);
                    }

                    List <Net.AssetDownloader.Asset> assets = new List <Net.AssetDownloader.Asset>(manifest.records.Length);
                    long size = 0;

                    foreach (var record in manifest.records)
                    {
                        bool isUsed = true;

                        switch (record.baseId)
                        {
                        case 724786:        //Launcher
                            break;

                        case 1283391:       //Launcher64

                            if (!Is64())
                            {
                                isUsed = false;
                            }

                            break;

                        case 1475411:       //LauncherOSX

                            isUsed = false;

                            break;

                        case 622855:        //ClientContent86
                            break;

                        case 1283393:       //ClientContent64
                            break;

                        case 296040:        //English
                        case 296042:        //German
                        case 296043:        //French
                        case 1051220:       //Chinese

                            isUsed = record.baseId == language;

                            break;
                        }

                        //asset = new Net.AssetDownloader.Asset(record.fileId, !isUsed, !isUsed ? (int)(record.size * AVG_COMPRESSION + 0.5f) : record.size);
                        asset = new Net.AssetDownloader.Asset(record.fileId, useCompression, useCompression ? (int)(record.size * AVG_COMPRESSION + 0.5f) : record.size);
                        if (isUsed)
                        {
                            asset.Complete += manifestUsed_Complete;
                        }
                        else
                        {
                            asset.Complete += manifestUnused_Complete;
                        }
                        asset.Cancelled += manifest_Cancelled;
                        asset.Progress  += asset_Progress;

                        assets.Add(asset);

                        size += asset.size;
                    }

                    progress.manifestsTotal += assets.Count;
                    progress.manifestsDownloaded++;
                    progress.estimatedBytesRemaining += size;
                    progress.estimatedTotalBytes     += size;

                    downloader.Add(assets);

                    return(true);
                }
            }

            return(false);
        }