Beispiel #1
0
        private static downloadFile getDownload(string url, string hash)
        {
            var download = new downloadFile();

            using (var webClient = new System.Net.WebClient())
            {
                byte[] content;
                content = downloadAndReturnCDNFile(url + "data/" + hash[0] + hash[1] + "/" + hash[2] + hash[3] + "/" + hash);
                byte[] parsedContent = parseBLTEfile(content);

                using (BinaryReader bin = new BinaryReader(new MemoryStream(parsedContent)))
                {
                    if (Encoding.UTF8.GetString(bin.ReadBytes(2)) != "DL")
                    {
                        throw new Exception("Error while parsing download file. Did BLTE header size change?");
                    }
                    download.unk        = bin.ReadBytes(3); // Unk
                    download.numEntries = bin.ReadUInt32(true);
                    download.numTags    = bin.ReadUInt16(true);

                    download.entries = new downloadEntry[download.numEntries];
                    for (int i = 0; i < download.numEntries; i++)
                    {
                        download.entries[i].hash = BitConverter.ToString(bin.ReadBytes(16)).Replace("-", "");
                        bin.ReadBytes(10);
                    }
                }
            }

            return(download);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            if (args.Count() == 0)
            {
                Console.WriteLine("App requires a program code as argument.");
                Environment.Exit(1);
            }

            if (args.Count() > 1)
            {
                cacheDir = args[1];
            }
            else
            {
                cacheDir = @"\\huiskamer\2tb\";
            }

            if (!Directory.Exists(cacheDir))
            {
                Directory.CreateDirectory(cacheDir);
            }

            var sw = Stopwatch.StartNew();

            program = args[0];
            Console.WriteLine("Using program " + program);

            versions = getVersions(program);
            Console.WriteLine("Loaded " + versions.entries.Count() + " versions");

            cdns = getCDNs(program);
            Console.WriteLine("Loaded " + cdns.entries.Count() + " cdns");

            buildConfig = getBuildConfig(program, "http://" + cdns.entries[0].hosts[0] + "/" + cdns.entries[0].path + "/", versions.entries[0].buildConfig);
            Console.WriteLine("BuildConfig for " + buildConfig.buildName + " loaded");

            cdnConfig = getCDNconfig(program, "http://" + cdns.entries[0].hosts[0] + "/" + cdns.entries[0].path + "/", versions.entries[0].cdnConfig);
            Console.WriteLine("CDNConfig loaded, " + cdnConfig.builds.Count() + " builds, " + cdnConfig.archives.Count() + " archives");

            cdnBuildConfigs = new buildConfigFile[cdnConfig.builds.Count()];

            var allBuilds = true; // Whether or not to grab other builds mentioned in cdnconfig, adds a few min to execution if it has to DL everything fresh.

            Dictionary <string, string> hashes = new Dictionary <string, string>();

            if (allBuilds == true)
            {
                for (var i = 0; i < cdnConfig.builds.Count(); i++)
                {
                    cdnBuildConfigs[i] = getBuildConfig(program, "http://" + cdns.entries[0].hosts[0] + "/" + cdns.entries[0].path + "/", cdnConfig.builds[i]);

                    Console.WriteLine("Retrieved additional build config in cdn config: " + cdnBuildConfigs[i].buildName);

                    Console.WriteLine("Loading encoding " + cdnBuildConfigs[i].encoding[1]);
                    var subBuildEncoding = getEncoding("http://" + cdns.entries[0].hosts[0] + "/" + cdns.entries[0].path + "/", cdnBuildConfigs[i].encoding[1], int.Parse(cdnBuildConfigs[i].encodingSize[1])); //Use of first encoding is unknown

                    string subBuildRootKey     = null;
                    string subBuildDownloadKey = null;
                    string subBuildInstallKey  = null;

                    foreach (var entry in subBuildEncoding.entries)
                    {
                        if (!hashes.ContainsKey(entry.key))
                        {
                            hashes.Add(entry.key, entry.hash);
                        }

                        if (entry.hash == cdnBuildConfigs[i].root.ToUpper())
                        {
                            subBuildRootKey = entry.key;
                        }
                        if (entry.hash == cdnBuildConfigs[i].download.ToUpper())
                        {
                            subBuildDownloadKey = entry.key;
                        }
                        if (entry.hash == cdnBuildConfigs[i].install.ToUpper())
                        {
                            subBuildInstallKey = entry.key;
                        }
                    }

                    if (subBuildRootKey != null && program != "pro") // Overwatch has it in archives
                    {
                        Console.WriteLine("Downloading root " + subBuildRootKey + " (in buildconfig: " + cdnBuildConfigs[i].root.ToUpper() + ")");
                        downloadCDNFile("http://" + cdns.entries[0].hosts[0] + "/" + cdns.entries[0].path + "/" + "data/" + subBuildRootKey[0] + subBuildRootKey[1] + "/" + subBuildRootKey[2] + subBuildRootKey[3] + "/" + subBuildRootKey);
                    }

                    if (subBuildDownloadKey != null)
                    {
                        Console.WriteLine("Downloading download " + subBuildDownloadKey);
                        downloadCDNFile("http://" + cdns.entries[0].hosts[0] + "/" + cdns.entries[0].path + "/" + "data/" + subBuildDownloadKey[0] + subBuildDownloadKey[1] + "/" + subBuildDownloadKey[2] + subBuildDownloadKey[3] + "/" + subBuildDownloadKey);
                    }

                    if (subBuildInstallKey != null)
                    {
                        Console.WriteLine("Downloading install " + subBuildInstallKey);
                        downloadCDNFile("http://" + cdns.entries[0].hosts[0] + "/" + cdns.entries[0].path + "/" + "data/" + subBuildInstallKey[0] + subBuildInstallKey[1] + "/" + subBuildInstallKey[2] + subBuildInstallKey[3] + "/" + subBuildInstallKey);
                    }

                    if (cdnBuildConfigs[i].patchConfig != null)
                    {
                        if (cdnBuildConfigs[i].patchConfig.Contains(" "))
                        {
                            throw new Exception("Patch config has multiple entries");
                        }
                        Console.WriteLine("Downloading patch config " + cdnBuildConfigs[i].patchConfig);
                        downloadCDNFile("http://" + cdns.entries[0].hosts[0] + "/" + cdns.entries[0].path + "/" + "config/" + cdnBuildConfigs[i].patchConfig[0] + cdnBuildConfigs[i].patchConfig[1] + "/" + cdnBuildConfigs[i].patchConfig[2] + cdnBuildConfigs[i].patchConfig[3] + "/" + cdnBuildConfigs[i].patchConfig);
                    }

                    if (cdnBuildConfigs[i].patch != null)
                    {
                        if (cdnBuildConfigs[i].patch.Contains(" "))
                        {
                            throw new Exception("Patch has multiple entries");
                        }
                        Console.WriteLine("Downloading patch " + cdnBuildConfigs[i].patch);
                        downloadCDNFile("http://" + cdns.entries[0].hosts[0] + "/" + cdns.entries[0].path + "/" + "patch/" + cdnBuildConfigs[i].patch[0] + cdnBuildConfigs[i].patch[1] + "/" + cdnBuildConfigs[i].patch[2] + cdnBuildConfigs[i].patch[3] + "/" + cdnBuildConfigs[i].patch);
                    }
                }
            }

            //Get all stuff from additional builds

            if (cdnConfig.patchArchives != null)
            {
                for (var i = 0; i < cdnConfig.patchArchives.Count(); i++)
                {
                    Console.WriteLine("Downloading patch archive " + cdnConfig.patchArchives[i]);
                    downloadCDNFile("http://" + cdns.entries[0].hosts[0] + "/" + cdns.entries[0].path + "/" + "patch/" + cdnConfig.patchArchives[i][0] + cdnConfig.patchArchives[i][1] + "/" + cdnConfig.patchArchives[i][2] + cdnConfig.patchArchives[i][3] + "/" + cdnConfig.patchArchives[i]);
                    downloadCDNFile("http://" + cdns.entries[0].hosts[0] + "/" + cdns.entries[0].path + "/" + "patch/" + cdnConfig.patchArchives[i][0] + cdnConfig.patchArchives[i][1] + "/" + cdnConfig.patchArchives[i][2] + cdnConfig.patchArchives[i][3] + "/" + cdnConfig.patchArchives[i] + ".index");
                }
            }

            Console.Write("Loading " + cdnConfig.archives.Count() + " indexes..");
            indexes = getIndexes("http://" + cdns.entries[0].hosts[0] + "/" + cdns.entries[0].path + "/", cdnConfig.archives);
            Console.Write("..done\n");
            Console.Write("Downloading " + cdnConfig.archives.Count() + " archives..");
            getArchives("http://" + cdns.entries[0].hosts[0] + "/" + cdns.entries[0].path + "/", cdnConfig.archives);
            Console.Write("..done\n");

            Console.Write("Loading encoding..");
            encoding = getEncoding("http://" + cdns.entries[0].hosts[0] + "/" + cdns.entries[0].path + "/", buildConfig.encoding[1], int.Parse(buildConfig.encodingSize[1])); //Use of first encoding is unknown

            string rootKey     = "";
            string downloadKey = "";
            string installKey  = "";

            foreach (var entry in encoding.entries)
            {
                if (entry.hash == buildConfig.root.ToUpper())
                {
                    rootKey = entry.key;
                }
                if (entry.hash == buildConfig.download.ToUpper())
                {
                    downloadKey = entry.key;
                }
                if (entry.hash == buildConfig.install.ToUpper())
                {
                    installKey = entry.key;
                }
                if (!hashes.ContainsKey(entry.key))
                {
                    hashes.Add(entry.key, entry.hash);
                }
            }

            Console.Write("..done\n");


            if (program != "pro")
            {
                Console.Write("Loading root..");
                if (rootKey == "")
                {
                    Console.WriteLine("Unable to find root key in encoding!");
                }
                else
                {
                    getRoot("http://" + cdns.entries[0].hosts[0] + "/" + cdns.entries[0].path + "/", rootKey);
                }
                Console.Write("..done\n");

                Console.Write("Loading download..");
                if (downloadKey == "")
                {
                    Console.WriteLine("Unable to find download key in encoding!");
                }
                else
                {
                    download = getDownload("http://" + cdns.entries[0].hosts[0] + "/" + cdns.entries[0].path + "/", downloadKey);
                }
                Console.Write("..done\n");

                Console.Write("Loading install..");
                if (installKey == "")
                {
                    Console.WriteLine("Unable to find install key in encoding!");
                }
                else
                {
                    getInstall("http://" + cdns.entries[0].hosts[0] + "/" + cdns.entries[0].path + "/", installKey);
                }
                Console.Write("..done\n");
            }


            foreach (var index in indexes)
            {
                foreach (var entry in index.archiveIndexEntries)
                {
                    hashes.Remove(entry.headerHash);
                }
            }

            Console.WriteLine("Downloading " + hashes.Count() + " unarchived files..");

            foreach (var entry in hashes)
            {
                Console.WriteLine("Downloading " + entry.Key);
                downloadCDNFile("http://" + cdns.entries[0].hosts[0] + "/" + cdns.entries[0].path + "/" + "data/" + entry.Key[0] + entry.Key[1] + "/" + entry.Key[2] + entry.Key[3] + "/" + entry.Key);
            }

            Console.WriteLine("Done downloading unarchived files.");

            sw.Stop();

            GC.Collect();
            Console.WriteLine("Took " + sw.Elapsed + " to load");

            Console.ReadLine();
        }