Exemple #1
0
        private static cdnsFile getCDNs(string program)
        {
            string content;

            using (var webClient = new System.Net.WebClient())
            {
                content = webClient.DownloadString(new Uri(baseUrl + program + "/" + "cdns"));
            }

            var lines = content.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);

            var cdns = new cdnsFile();

            cdns.entries = new cdnsEntry[lines.Count() - 1];
            for (var i = 0; i < lines.Count(); i++)
            {
                if (lines[i].StartsWith("Name!"))
                {
                    continue;
                }
                var cols = lines[i].Split('|');
                cdns.entries[i - 1].name = cols[0];
                cdns.entries[i - 1].path = cols[1];
                var hosts = cols[2].Split(' ');
                cdns.entries[i - 1].hosts = new string[hosts.Count()];
                for (var h = 0; h < hosts.Count(); h++)
                {
                    cdns.entries[i - 1].hosts[h] = hosts[h];
                }
            }

            //TODO For now thisll have to do
            var dirname = cacheDir + "ngdp\\" + program + "_" + versions.entries[0].buildId + "_" + versions.entries[0].versionsName;

            if (!Directory.Exists(dirname))
            {
                Directory.CreateDirectory(dirname);
            }
            File.WriteAllText(dirname + "/cdns", content);

            return(cdns);
        }
Exemple #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();
        }