Пример #1
0
        static bool AccountHasAccess(int depotId, bool appId = false)
        {
            if (steam3 == null || steam3.Licenses == null)
            {
                return(CDRManager.SubHasDepot(0, depotId));
            }

            foreach (var license in steam3.Licenses)
            {
                steam3.RequestPackageInfo(license.PackageID);

                SteamApps.PackageInfoCallback.Package package;
                if (steam3.PackageInfo.TryGetValue((uint)license.PackageID, out package) && package.Status == SteamApps.PackageInfoCallback.Package.PackageStatus.OK)
                {
                    KeyValue root   = package.Data[license.PackageID.ToString()];
                    KeyValue subset = (appId == true ? root["appids"] : root["depotids"]);

                    foreach (var child in subset.Children)
                    {
                        if (child.AsInteger() == depotId)
                        {
                            return(true);
                        }
                    }
                }

                if (CDRManager.SubHasDepot(( int )license.PackageID, depotId))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #2
0
        static bool AccountHasAccess(int depotId, bool appId = false)
        {
            if (steam3 == null || (steam3.Licenses == null && steam3.steamUser.SteamID.AccountType != EAccountType.AnonUser))
            {
                return(CDRManager.SubHasDepot(0, depotId));
            }

            IEnumerable <uint> licenseQuery;

            if (steam3.steamUser.SteamID.AccountType == EAccountType.AnonUser)
            {
                licenseQuery = new List <uint>()
                {
                    17906
                };
            }
            else
            {
                licenseQuery = steam3.Licenses.Select(x => x.PackageID);
            }

            steam3.RequestPackageInfo(licenseQuery);

            foreach (var license in licenseQuery)
            {
                SteamApps.PICSProductInfoCallback.PICSProductInfo package;
                if (steam3.PackageInfo.TryGetValue(license, out package) || package == null)
                {
                    KeyValue root   = package.KeyValues[license.ToString()];
                    KeyValue subset = (appId == true ? root["appids"] : root["depotids"]);

                    foreach (var child in subset.Children)
                    {
                        if (child.AsInteger() == depotId)
                        {
                            return(true);
                        }
                    }
                }

                if (CDRManager.SubHasDepot(( int )license, depotId))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #3
0
        static bool CreateDirectories(int depotId, uint depotVersion, DownloadSource source, out string installDir)
        {
            installDir = null;
            try
            {
                if (ContentDownloader.Config.InstallDirectory == null || ContentDownloader.Config.InstallDirectory == "")
                {
                    Directory.CreateDirectory(DEFAULT_DIR);

                    string depotPath = Path.Combine(DEFAULT_DIR, depotId.ToString());
                    Directory.CreateDirectory(depotPath);

                    installDir = Path.Combine(depotPath, depotVersion.ToString());
                    Directory.CreateDirectory(installDir);
                }
                else
                {
                    Directory.CreateDirectory(ContentDownloader.Config.InstallDirectory);

                    installDir = ContentDownloader.Config.InstallDirectory;

                    if (source == DownloadSource.Steam2)
                    {
                        string serverFolder = CDRManager.GetDedicatedServerFolder(depotId);
                        if (serverFolder != null && serverFolder != "")
                        {
                            installDir = Path.Combine(ContentDownloader.Config.InstallDirectory, serverFolder);
                            Directory.CreateDirectory(installDir);
                        }
                    }
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Пример #4
0
        public static void DownloadDepotsForGame(string game, string branch)
        {
            var        infos2   = new List <DepotDownloadInfo2>();
            var        infos3   = new List <DepotDownloadInfo3>();
            List <int> depotIDs = CDRManager.GetDepotIDsForGameserver(game, ContentDownloader.Config.DownloadAllPlatforms);

            foreach (var depot in depotIDs)
            {
                int depotVersion = CDRManager.GetLatestDepotVersion(depot, ContentDownloader.Config.PreferBetaVersions);
                if (depotVersion == -1)
                {
                    Console.WriteLine("Error: Unable to find DepotID {0} in the CDR!", depot);
                    ContentDownloader.ShutdownSteam3();
                    continue;
                }

                IDepotDownloadInfo info = GetDepotInfo(depot, depotVersion, 0, branch);
                if (info.GetDownloadType() == DownloadSource.Steam2)
                {
                    infos2.Add((DepotDownloadInfo2)info);
                }
                else if (info.GetDownloadType() == DownloadSource.Steam3)
                {
                    infos3.Add((DepotDownloadInfo3)info);
                }
            }

            if (infos2.Count() > 0)
            {
                DownloadSteam2(infos2);
            }

            if (infos3.Count() > 0)
            {
                DownloadSteam3(infos3);
            }
        }
Пример #5
0
        static string GetAppOrDepotName(int depotId, int appId)
        {
            if (appId == -1 || !AppIsSteam3(appId))
            {
                return(CDRManager.GetDepotName(depotId));
            }
            else if (depotId == -1)
            {
                KeyValue info = GetSteam3AppSection(appId, EAppInfoSection.Common);

                if (info == null)
                {
                    return(String.Empty);
                }

                return(info["name"].AsString());
            }
            else
            {
                KeyValue depots = GetSteam3AppSection(appId, EAppInfoSection.Depots);

                if (depots == null)
                {
                    return(String.Empty);
                }

                KeyValue depotChild = depots[depotId.ToString()];

                if (depotChild == null)
                {
                    return(String.Empty);
                }

                return(depotChild["name"].AsString());
            }
        }
Пример #6
0
        public static void DownloadApp(int appId, int depotId, string branch, bool bListOnly = false)
        {
            if (steam3 != null)
            {
                steam3.RequestAppInfo((uint)appId);
            }

            if (!AccountHasAccess(appId, true))
            {
                string contentName = GetAppOrDepotName(-1, appId);
                Console.WriteLine("App {0} ({1}) is not available from this account.", appId, contentName);
                return;
            }

            List <int> depotIDs = null;

            if (AppIsSteam3(appId))
            {
                depotIDs = new List <int>();
                KeyValue depots = GetSteam3AppSection(appId, EAppInfoSection.Depots);

                if (depots != null)
                {
                    foreach (var child in depots.Children)
                    {
                        int id = -1;
                        if (int.TryParse(child.Name, out id) && child.Children.Count > 0 && (depotId == -1 || id == depotId))
                        {
                            depotIDs.Add(id);
                        }
                    }
                }
            }
            else
            {
                // steam2 path
                depotIDs = CDRManager.GetDepotIDsForApp(appId, Config.DownloadAllPlatforms);
            }

            if (depotIDs == null || (depotIDs.Count == 0 && depotId == -1))
            {
                Console.WriteLine("Couldn't find any depots to download for app {0}", appId);
                return;
            }
            else if (depotIDs.Count == 0)
            {
                Console.WriteLine("Depot {0} not listed for app {1}", depotId, appId);
                return;
            }

            if (bListOnly)
            {
                Console.WriteLine("\n  {0} Depots:", appId);

                foreach (var depot in depotIDs)
                {
                    var depotName = CDRManager.GetDepotName(depot);
                    Console.WriteLine("{0} - {1}", depot, depotName);
                }

                return;
            }

            var infos2 = new List <DepotDownloadInfo2>();
            var infos3 = new List <DepotDownloadInfo3>();

            foreach (var depot in depotIDs)
            {
                int depotVersion = 0;

                if (!AppIsSteam3(appId))
                {
                    // Steam2 dependency
                    depotVersion = CDRManager.GetLatestDepotVersion(depot, Config.PreferBetaVersions);
                    if (depotVersion == -1)
                    {
                        Console.WriteLine("Error: Unable to find DepotID {0} in the CDR!", depot);
                        return;
                    }
                }

                IDepotDownloadInfo info = GetDepotInfo(depot, depotVersion, appId, branch);
                if (info != null)
                {
                    if (info.GetDownloadType() == DownloadSource.Steam2)
                    {
                        infos2.Add((DepotDownloadInfo2)info);
                    }
                    else if (info.GetDownloadType() == DownloadSource.Steam3)
                    {
                        infos3.Add((DepotDownloadInfo3)info);
                    }
                }
            }

            if (infos2.Count() > 0)
            {
                DownloadSteam2(infos2);
            }

            if (infos3.Count() > 0)
            {
                DownloadSteam3(infos3);
            }
        }
Пример #7
0
        private static void DownloadSteam2(List <DepotDownloadInfo2> depots)
        {
            Console.WriteLine("Found depots:");
            foreach (var depot in depots)
            {
                Console.WriteLine("- {0}\t{1}  (version {2})", depot.id, depot.contentName, depot.version);
            }

            Console.Write("Finding content servers...");
            foreach (var depot in depots)
            {
                depot.contentServers = GetStorageServer(depot.id, depot.version, Config.CellID);
                if (depot.contentServers == null || depot.contentServers.Length == 0)
                {
                    Console.WriteLine("\nError: Unable to find any Steam2 content servers for depot {0}, version {1}", depot.id, depot.version);
                    return;
                }
            }

            Console.WriteLine(" Done!");

            ContentServerClient csClient = new ContentServerClient();

            csClient.ConnectionTimeout = TimeSpan.FromSeconds(STEAM2_CONNECT_TIMEOUT_SECONDS);

            ContentServerClient.StorageSession session;

            foreach (var depot in depots)
            {
                session = GetSteam2StorageSession(depot.contentServers, csClient, depot.id, depot.version);
                if (session == null)
                {
                    continue;
                }

                Console.Write(String.Format("Downloading manifest for depot {0}...", depot.id));

                string             txtManifest     = Path.Combine(depot.installDir, string.Format("manifest_{0}.txt", depot.id));
                Steam2ChecksumData checksums       = null;
                StringBuilder      manifestBuilder = new StringBuilder();
                string[]           excludeList     = null;

                depot.cryptKey = CDRManager.GetDepotEncryptionKey(depot.id, depot.version);
                depot.manifest = session.DownloadManifest();

                Console.WriteLine(" Done!");

                if (Config.UsingExclusionList)
                {
                    excludeList = GetExcludeList(session, depot.manifest);
                }

                // Build a list of files that need downloading.
                for (int x = 0; x < depot.manifest.Nodes.Count; ++x)
                {
                    var    dirEntry     = depot.manifest.Nodes[x];
                    string downloadPath = Path.Combine(depot.installDir, dirEntry.FullName.ToLower());
                    if (Config.DownloadManifestOnly)
                    {
                        if (dirEntry.FileID == -1)
                        {
                            continue;
                        }

                        manifestBuilder.Append(string.Format("{0}\n", dirEntry.FullName));
                        continue;
                    }
                    if (Config.UsingExclusionList && IsFileExcluded(dirEntry.FullName, excludeList))
                    {
                        continue;
                    }

                    if (!TestIsFileIncluded(dirEntry.FullName))
                    {
                        continue;
                    }

                    string path = Path.GetDirectoryName(downloadPath);

                    if (path != "" && !Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    if (dirEntry.FileID == -1)
                    {
                        if (!Directory.Exists(downloadPath))
                        {
                            // this is a directory, so lets just create it
                            Directory.CreateDirectory(downloadPath);
                        }

                        continue;
                    }

                    if (checksums == null)
                    {
                        // Skip downloading checksums if we're only interested in manifests.
                        Console.Write(String.Format("Downloading checksums for depot {0}...", depot.id));

                        checksums = session.DownloadChecksums();

                        Console.WriteLine(" Done!");
                    }

                    FileInfo fi = new FileInfo(downloadPath);
                    if (fi.Exists)
                    {
                        // Similar file, let's check checksums
                        if (fi.Length == dirEntry.SizeOrCount &&
                            Util.ValidateSteam2FileChecksums(fi, checksums.GetFileChecksums(dirEntry.FileID)))
                        {
                            // checksums OK
                            float perc = ((float)x / (float)depot.manifest.Nodes.Count) * 100.0f;
                            Console.WriteLine("{0,6:#00.00}%\t{1}", perc, downloadPath);

                            continue;
                        }
                        // Unlink the current file before we download a new one.
                        // This will keep symbolic/hard link targets from being overwritten.
                        fi.Delete();
                    }
                    depot.NodesToDownload.Add(x);
                }

                if (Config.DownloadManifestOnly)
                {
                    File.WriteAllText(txtManifest, manifestBuilder.ToString());
                    return;
                }
            }

            foreach (var depot in depots)
            {
                Console.Write("Downloading requested files from depot {0}... ", depot.id);
                if (depot.NodesToDownload.Count == 0)
                {
                    Console.WriteLine("none needed.");
                }
                else
                {
                    Console.WriteLine();
                }

                session = GetSteam2StorageSession(depot.contentServers, csClient, depot.id, depot.version);
                if (session == null)
                {
                    continue;
                }

                for (int x = 0; x < depot.NodesToDownload.Count; ++x)
                {
                    var    dirEntry     = depot.manifest.Nodes[depot.NodesToDownload[x]];
                    string downloadPath = Path.Combine(depot.installDir, dirEntry.FullName.ToLower());

                    float perc = (( float )x / ( float )depot.NodesToDownload.Count) * 100.0f;
                    Console.WriteLine("{0,6:#00.00}%\t{1}", perc, downloadPath);

                    using (var fs = new FileStream(downloadPath, FileMode.Create))
                    {
                        session.DownloadFileToStream(dirEntry, fs, ContentServerClient.StorageSession.DownloadPriority.High, depot.cryptKey);
                    }
                }
            }
            csClient.Disconnect();
        }
Пример #8
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                PrintUsage();
                return;
            }

            DebugLog.Enabled = false;

            ServerCache.Build();
            CDRManager.Update();

            if (HasParameter(args, "-list"))
            {
                CDRManager.ListGameServers();
                return;
            }

            bool bGameserver   = true;
            bool bApp          = false;
            bool bListDepots   = HasParameter(args, "-listdepots");
            bool bDumpManifest = HasParameter(args, "-manifest");

            int    appId    = -1;
            int    depotId  = -1;
            string gameName = GetStringParameter(args, "-game");

            if (gameName == null)
            {
                appId       = GetIntParameter(args, "-app");
                bGameserver = false;

                depotId = GetIntParameter(args, "-depot");

                if (depotId == -1 && appId == -1)
                {
                    Console.WriteLine("Error: -game, -app, or -depot not specified!");
                    return;
                }
                else if (appId >= 0)
                {
                    bApp = true;
                }
            }

            ContentDownloader.Config.DownloadManifestOnly = bDumpManifest;

            int cellId = GetIntParameter(args, "-cellid");

            if (cellId == -1)
            {
                cellId = 0;
                Console.WriteLine(
                    "Warning: Using default CellID of 0! This may lead to slow downloads. " +
                    "You can specify the CellID using the -cellid parameter");
            }

            ContentDownloader.Config.CellID = cellId;

            int depotVersion = GetIntParameter(args, "-version");

            ContentDownloader.Config.PreferBetaVersions = HasParameter(args, "-beta");

            // this is a Steam2 option
            if (!bGameserver && !bApp && depotVersion == -1)
            {
                int latestVer = CDRManager.GetLatestDepotVersion(depotId, ContentDownloader.Config.PreferBetaVersions);

                if (latestVer == -1)
                {
                    Console.WriteLine("Error: Unable to find DepotID {0} in the CDR!", depotId);
                    return;
                }

                string strVersion = GetStringParameter(args, "-version");
                if (strVersion != null && strVersion.Equals("latest", StringComparison.OrdinalIgnoreCase))
                {
                    Console.WriteLine("Using latest version: {0}", latestVer);
                    depotVersion = latestVer;
                }
                else if (strVersion == null)
                {
                    // this could probably be combined with the above
                    Console.WriteLine("No version specified.");
                    Console.WriteLine("Using latest version: {0}", latestVer);
                    depotVersion = latestVer;
                }
                else
                {
                    Console.WriteLine("Available depot versions:");
                    Console.WriteLine("  Oldest: 0");
                    Console.WriteLine("  Newest: {0}", latestVer);
                    return;
                }
            }

            string fileList = GetStringParameter(args, "-filelist");

            string[] files = null;

            if (fileList != null)
            {
                try
                {
                    string fileListData = File.ReadAllText(fileList);
                    files = fileListData.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);

                    ContentDownloader.Config.UsingFileList        = true;
                    ContentDownloader.Config.FilesToDownload      = new List <string>();
                    ContentDownloader.Config.FilesToDownloadRegex = new List <Regex>();

                    foreach (var fileEntry in files)
                    {
                        try
                        {
                            Regex rgx = new Regex(fileEntry, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                            ContentDownloader.Config.FilesToDownloadRegex.Add(rgx);
                        }
                        catch
                        {
                            ContentDownloader.Config.FilesToDownload.Add(fileEntry);
                            continue;
                        }
                    }

                    Console.WriteLine("Using filelist: '{0}'.", fileList);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Warning: Unable to load filelist: {0}", ex.ToString());
                }
            }

            string username = GetStringParameter(args, "-username");
            string password = GetStringParameter(args, "-password");

            ContentDownloader.Config.InstallDirectory = GetStringParameter(args, "-dir");
            bool bNoExclude = HasParameter(args, "-no-exclude");

            ContentDownloader.Config.DownloadAllPlatforms = HasParameter(args, "-all-platforms");

            if (username != null && password == null)
            {
                Console.Write("Enter account password: "******"Error: No depots for specified game '{0}'", gameName);
                    return;
                }

                if (bListDepots)
                {
                    Console.WriteLine("\n  '{0}' Depots:", gameName);

                    foreach (var depot in depotIDs)
                    {
                        var depotName = CDRManager.GetDepotName(depot);
                        Console.WriteLine("{0} - {1}", depot, depotName);
                    }

                    return;
                }

                foreach (int currentDepotId in depotIDs)
                {
                    depotVersion = CDRManager.GetLatestDepotVersion(currentDepotId, ContentDownloader.Config.PreferBetaVersions);
                    if (depotVersion == -1)
                    {
                        Console.WriteLine("Error: Unable to find DepotID {0} in the CDR!", currentDepotId);
                        ContentDownloader.ShutdownSteam3();
                        return;
                    }

                    ContentDownloader.DownloadDepot(currentDepotId, depotVersion);
                }
            }

            ContentDownloader.ShutdownSteam3();
        }
Пример #9
0
        private static void DownloadSteam2(int depotId, int depotVersion, string installDir)
        {
            Console.Write("Finding content servers...");
            IPEndPoint[] contentServers = GetStorageServer(depotId, depotVersion, Config.CellID);

            if (contentServers == null || contentServers.Length == 0)
            {
                Console.WriteLine("\nError: Unable to find any Steam2 content servers for depot {0}, version {1}", depotId, depotVersion);
                return;
            }

            Console.WriteLine(" Done!");
            Console.Write("Downloading depot manifest...");

            string txtManifest = Path.Combine(installDir, "manifest.txt");

            ContentServerClient csClient = new ContentServerClient();

            ContentServerClient.StorageSession session = GetSteam2StorageSession(contentServers, csClient, depotId, depotVersion);
            if (session == null)
            {
                return;
            }

            Steam2Manifest     manifest        = null;
            Steam2ChecksumData checksums       = null;
            List <int>         NodesToDownload = new List <int>();
            StringBuilder      manifestBuilder = new StringBuilder();

            byte[]   cryptKey    = CDRManager.GetDepotEncryptionKey(depotId, depotVersion);
            string[] excludeList = null;
            using ( session )
            {
                manifest = session.DownloadManifest();

                Console.WriteLine(" Done!");

                if (!Config.DownloadManifestOnly)
                {
                    // Skip downloading checksums if we're only interested in manifests.
                    Console.Write("Downloading depot checksums...");

                    checksums = session.DownloadChecksums();

                    Console.WriteLine(" Done!");
                }

                if (Config.UsingExclusionList)
                {
                    excludeList = GetExcludeList(session, manifest);
                }
            }
            csClient.Disconnect();

            if (!Config.DownloadManifestOnly)
            {
                Console.WriteLine("Building list of files to download and checking existing files...");
            }
            // Build a list of files that need downloading.
            for (int x = 0; x < manifest.Nodes.Count; ++x)
            {
                var    dirEntry     = manifest.Nodes[x];
                string downloadPath = Path.Combine(installDir, dirEntry.FullName.ToLower());
                if (Config.DownloadManifestOnly)
                {
                    if (dirEntry.FileID == -1)
                    {
                        continue;
                    }

                    manifestBuilder.Append(string.Format("{0}\n", dirEntry.FullName));
                    continue;
                }
                if (Config.UsingExclusionList && IsFileExcluded(dirEntry.FullName, excludeList))
                {
                    continue;
                }

                if (!TestIsFileIncluded(dirEntry.FullName))
                {
                    continue;
                }

                string path = Path.GetDirectoryName(downloadPath);

                if (path != "" && !Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                if (dirEntry.FileID == -1)
                {
                    if (!Directory.Exists(downloadPath))
                    {
                        // this is a directory, so lets just create it
                        Directory.CreateDirectory(downloadPath);
                    }

                    continue;
                }

                FileInfo fi = new FileInfo(downloadPath);
                if (fi.Exists)
                {
                    float perc = (( float )x / ( float )manifest.Nodes.Count) * 100.0f;
                    Console.WriteLine("{0,6:#00.00}%\t{1}", perc, downloadPath);
                    // Similar file, let's check checksums
                    if (fi.Length == dirEntry.SizeOrCount &&
                        Util.ValidateFileChecksums(fi, checksums.GetFileChecksums(dirEntry.FileID)))
                    {
                        // checksums OK
                        continue;
                    }
                    // Unlink the current file before we download a new one.
                    // This will keep symbolic/hard link targets from being overwritten.
                    fi.Delete();
                }
                NodesToDownload.Add(x);
            }

            if (Config.DownloadManifestOnly)
            {
                File.WriteAllText(txtManifest, manifestBuilder.ToString());
                return;
            }


            session = GetSteam2StorageSession(contentServers, csClient, depotId, depotVersion);
            if (session == null)
            {
                return;
            }

            using ( session )
            {
                Console.WriteLine("Downloading selected files.");
                for (int x = 0; x < NodesToDownload.Count; ++x)
                {
                    var    dirEntry     = manifest.Nodes[NodesToDownload[x]];
                    string downloadPath = Path.Combine(installDir, dirEntry.FullName.ToLower());

                    float perc = (( float )x / ( float )NodesToDownload.Count) * 100.0f;
                    Console.WriteLine("{0,6:#00.00}%\t{1}", perc, downloadPath);

                    var file = session.DownloadFile(dirEntry, ContentServerClient.StorageSession.DownloadPriority.High, cryptKey);
                    File.WriteAllBytes(downloadPath, file);
                }
            }
            csClient.Disconnect();
        }