static uint GetSteam3AppBuildNumber(int appId, string branch)
        {
            if (appId == -1 || !AppIsSteam3(appId))
            {
                return(0);
            }


            KeyValue depots   = ContentDownloader.GetSteam3AppSection(appId, EAppInfoSection.Depots);
            KeyValue branches = depots["branches"];
            KeyValue node     = branches[branch];

            if (node == null)
            {
                return(0);
            }

            KeyValue buildid = node["buildid"];

            if (buildid == null)
            {
                return(0);
            }

            return(uint.Parse(buildid.Value));
        }
        static bool InitializeSteam(string username, string password)
        {
            if (username != null && password == null && (!ContentDownloader.Config.RememberPassword || !AccountSettingsStore.Instance.LoginKeys.ContainsKey(username)))
            {
                do
                {
                    Console.Write("Enter account password for \"{0}\": ", username);
                    if (Console.IsInputRedirected)
                    {
                        password = Console.ReadLine();
                    }
                    else
                    {
                        // Avoid console echoing of password
                        password = Util.ReadPassword();
                    }
                    Console.WriteLine();
                } while (String.Empty == password);
            }
            else if (username == null)
            {
                Console.WriteLine("No username given. Using anonymous account with dedicated server subscription.");
            }

            // capture the supplied password in case we need to re-use it after checking the login key
            ContentDownloader.Config.SuppliedPassword = password;

            return(ContentDownloader.InitializeSteam3(username, password));
        }
Beispiel #3
0
 public DepotDownloader(DownloadConfig config)
 {
     this._config             = config;
     ContentDownloader.Config = config;
     Logger.SetConfig(config);
     ContentDownloader.InitializeSteam3();
 }
Beispiel #4
0
        static uint GetSteam3AppBuildNumber(uint appId, string branch)
        {
            if (appId == INVALID_APP_ID)
            {
                return(0);
            }


            KeyValue depots   = ContentDownloader.GetSteam3AppSection(appId, EAppInfoSection.Depots);
            KeyValue branches = depots["branches"];
            KeyValue node     = branches[branch];

            if (node == KeyValue.Invalid)
            {
                return(0);
            }

            KeyValue buildid = node["buildid"];

            if (buildid == KeyValue.Invalid)
            {
                return(0);
            }

            return(uint.Parse(buildid.Value));
        }
Beispiel #5
0
 void Shutdown()
 {
     if (Started)
     {
         ContentDownloader.ShutdownSteam3();
         Started = false;
     }
 }
Beispiel #6
0
 bool Start()
 {
     if (!Started)
     {
         Started = ContentDownloader.InitializeSteam3(Username, Password);
         if (!Started)
         {
             Console.WriteLine("Warning: Unable to initialize Steam!");
         }
     }
     return(Started);
 }
Beispiel #7
0
        public void Download(bool wait = false)
        {
            ConfigStore.LoadFromFile(Path.Combine(Directory.GetCurrentDirectory(), "DepotDownloader.config"));
            var task1 = ContentDownloader.DownloadAppAsync();
            var task  = Task.Run(async() => await task1);

            if (wait)
            {
                task.GetAwaiter().GetResult();
            }
            ContentDownloader.ShutdownSteam3();
        }
Beispiel #8
0
        public static SteamVRVersion PopulateVersion(string branch, string verString)
        {
            var ver = new SteamVRVersion();

            ver.Version  = verString;
            ver.BuildNum = ContentDownloader.GetSteam3AppBuildNumber(ver.AppId, branch);
            PopulateDepot(branch, ver, ref ver.Content);
            PopulateDepot(branch, ver, ref ver.Win32);
            PopulateDepot(branch, ver, ref ver.OSX);
            PopulateDepot(branch, ver, ref ver.Linux);
            return(ver);
        }
Beispiel #9
0
 void Download(string dir, Downloadable dl)
 {
     if (!Started)
     {
         if (!Start())
         {
             return;
         }
     }
     ContentDownloader.Config.InstallDirectory = dir;
     ContentDownloader.Config.ManifestId       = dl.ManifestId;
     ContentDownloader.DownloadApp(dl.AppId, dl.DepotId, dl.Branch, dl.ForceDepot);
 }
        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);
            }
        }
Beispiel #11
0
        static async Task MainAsync(string[] args)
        {
            if (args.Length == 0)
            {
                PrintUsage();
                return;
            }

            DebugLog.Enabled = false;

            ConfigStore.LoadFromFile(Path.Combine(Directory.GetCurrentDirectory(), "DepotDownloader.config"));

            #region Common Options

            string username = GetParameter <string>(args, "-username") ?? GetParameter <string>(args, "-user");
            string password = GetParameter <string>(args, "-password") ?? GetParameter <string>(args, "-pass");
            ContentDownloader.Config.RememberPassword = HasParameter(args, "-remember-password");

            ContentDownloader.Config.DownloadManifestOnly = HasParameter(args, "-manifest-only");

            int cellId = GetParameter <int>(args, "-cellid", -1);
            if (cellId == -1)
            {
                cellId = 0;
            }

            ContentDownloader.Config.CellID = cellId;

            string   fileList = GetParameter <string>(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());
                }
            }

            ContentDownloader.Config.InstallDirectory = GetParameter <string>(args, "-dir");

            ContentDownloader.Config.VerifyAll    = HasParameter(args, "-verify-all") || HasParameter(args, "-verify_all") || HasParameter(args, "-validate");
            ContentDownloader.Config.MaxServers   = GetParameter <int>(args, "-max-servers", 20);
            ContentDownloader.Config.MaxDownloads = GetParameter <int>(args, "-max-downloads", 4);
            ContentDownloader.Config.MaxServers   = Math.Max(ContentDownloader.Config.MaxServers, ContentDownloader.Config.MaxDownloads);

            #endregion

            ulong pubFile = GetParameter <ulong>(args, "-pubfile", ContentDownloader.INVALID_MANIFEST_ID);
            if (pubFile != ContentDownloader.INVALID_MANIFEST_ID)
            {
                #region Pubfile Downloading

                if (InitializeSteam(username, password))
                {
                    await ContentDownloader.DownloadPubfileAsync(pubFile).ConfigureAwait(false);

                    ContentDownloader.ShutdownSteam3();
                }

                #endregion
            }
            else
            {
                #region App downloading

                string branch = GetParameter <string>(args, "-branch") ?? GetParameter <string>(args, "-beta") ?? ContentDownloader.DEFAULT_BRANCH;
                ContentDownloader.Config.BetaPassword = GetParameter <string>(args, "-betapassword");

                ContentDownloader.Config.DownloadAllPlatforms = HasParameter(args, "-all-platforms");
                string os = GetParameter <string>(args, "-os", null);

                if (ContentDownloader.Config.DownloadAllPlatforms && !String.IsNullOrEmpty(os))
                {
                    Console.WriteLine("Error: Cannot specify -os when -all-platforms is specified.");
                    return;
                }

                uint appId = GetParameter <uint>(args, "-app", ContentDownloader.INVALID_APP_ID);
                if (appId == ContentDownloader.INVALID_APP_ID)
                {
                    Console.WriteLine("Error: -app not specified!");
                    return;
                }

                uint depotId;
                bool isUGC = false;

                ulong manifestId = GetParameter <ulong>(args, "-ugc", ContentDownloader.INVALID_MANIFEST_ID);
                if (manifestId != ContentDownloader.INVALID_MANIFEST_ID)
                {
                    depotId = appId;
                    isUGC   = true;
                }
                else
                {
                    depotId    = GetParameter <uint>(args, "-depot", ContentDownloader.INVALID_DEPOT_ID);
                    manifestId = GetParameter <ulong>(args, "-manifest", ContentDownloader.INVALID_MANIFEST_ID);
                    if (depotId == ContentDownloader.INVALID_DEPOT_ID && manifestId != ContentDownloader.INVALID_MANIFEST_ID)
                    {
                        Console.WriteLine("Error: -manifest requires -depot to be specified");
                        return;
                    }
                }

                if (InitializeSteam(username, password))
                {
                    await ContentDownloader.DownloadAppAsync(appId, depotId, manifestId, branch, os, isUGC).ConfigureAwait(false);

                    ContentDownloader.ShutdownSteam3();
                }

                #endregion
            }
        }
Beispiel #12
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                PrintUsage();
                return;
            }

            DebugLog.Enabled = false;

            ConfigStore.LoadFromFile(Path.Combine(Environment.CurrentDirectory, "DepotDownloader.config"));

            bool bDumpManifest = HasParameter(args, "-manifest-only");
            uint appId         = GetParameter <uint>(args, "-app", ContentDownloader.INVALID_APP_ID);
            uint depotId       = GetParameter <uint>(args, "-depot", ContentDownloader.INVALID_DEPOT_ID);

            ContentDownloader.Config.ManifestId = GetParameter <ulong>(args, "-manifest", ContentDownloader.INVALID_MANIFEST_ID);

            if (appId == ContentDownloader.INVALID_APP_ID)
            {
                Console.WriteLine("Error: -app not specified!");
                return;
            }

            if (depotId == ContentDownloader.INVALID_DEPOT_ID && ContentDownloader.Config.ManifestId != ContentDownloader.INVALID_MANIFEST_ID)
            {
                Console.WriteLine("Error: -manifest requires -depot to be specified");
                return;
            }

            ContentDownloader.Config.DownloadManifestOnly = bDumpManifest;

            int cellId = GetParameter <int>(args, "-cellid", -1);

            if (cellId == -1)
            {
                cellId = 0;
            }

            ContentDownloader.Config.CellID       = cellId;
            ContentDownloader.Config.BetaPassword = GetParameter <string>(args, "-betapassword");

            string fileList = GetParameter <string>(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 = GetParameter <string>(args, "-username") ?? GetParameter <string>(args, "-user");
            string password = GetParameter <string>(args, "-password") ?? GetParameter <string>(args, "-pass");

            ContentDownloader.Config.InstallDirectory     = GetParameter <string>(args, "-dir");
            ContentDownloader.Config.DownloadAllPlatforms = HasParameter(args, "-all-platforms");
            ContentDownloader.Config.VerifyAll            = HasParameter(args, "-verify-all") || HasParameter(args, "-verify_all") || HasParameter(args, "-validate");
            ContentDownloader.Config.MaxServers           = GetParameter <int>(args, "-max-servers", 8);
            ContentDownloader.Config.MaxDownloads         = GetParameter <int>(args, "-max-downloads", 4);
            string branch = GetParameter <string>(args, "-branch") ?? GetParameter <string>(args, "-beta") ?? "Public";

            if (username != null && password == null)
            {
                Console.Write("Enter account password for \"{0}\": ", username);
                password = Util.ReadPassword();
                Console.WriteLine();
            }
            else if (username == null)
            {
                Console.WriteLine("No username given. Using anonymous account with dedicated server subscription.");
            }

            ContentDownloader.InitializeSteam3(username, password);
            ContentDownloader.DownloadApp(appId, depotId, branch);
            ContentDownloader.ShutdownSteam3();
        }
Beispiel #13
0
        static async Task <int> MainAsync(string[] args)
        {
            if (args.Length == 0)
            {
                PrintUsage();
                return(1);
            }

            DebugLog.Enabled = false;

            AccountSettingsStore.LoadFromFile("account.config");

            #region Common Options

            if (HasParameter(args, "-debug"))
            {
                DebugLog.Enabled = true;
                DebugLog.AddListener((category, message) =>
                {
                    Console.WriteLine("[{0}] {1}", category, message);
                });
            }

            string username = GetParameter <string>(args, "-username") ?? GetParameter <string>(args, "-user");
            string password = GetParameter <string>(args, "-password") ?? GetParameter <string>(args, "-pass");
            ContentDownloader.Config.RememberPassword = HasParameter(args, "-remember-password");

            ContentDownloader.Config.DownloadManifestOnly = HasParameter(args, "-manifest-only");

            int cellId = GetParameter <int>(args, "-cellid", -1);
            if (cellId == -1)
            {
                cellId = 0;
            }

            ContentDownloader.Config.CellID = cellId;

            string fileList = GetParameter <string>(args, "-filelist");

            if (fileList != null)
            {
                try
                {
                    string fileListData = await File.ReadAllTextAsync(fileList);

                    var files = fileListData.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);

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

                    foreach (var fileEntry in files)
                    {
                        if (fileEntry.StartsWith("regex:"))
                        {
                            Regex rgx = new Regex(fileEntry.Substring(6), RegexOptions.Compiled | RegexOptions.IgnoreCase);
                            ContentDownloader.Config.FilesToDownloadRegex.Add(rgx);
                        }
                        else
                        {
                            ContentDownloader.Config.FilesToDownload.Add(fileEntry.Replace('\\', '/'));
                        }
                    }

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

            ContentDownloader.Config.InstallDirectory = GetParameter <string>(args, "-dir");

            ContentDownloader.Config.VerifyAll    = HasParameter(args, "-verify-all") || HasParameter(args, "-verify_all") || HasParameter(args, "-validate");
            ContentDownloader.Config.MaxServers   = GetParameter <int>(args, "-max-servers", 20);
            ContentDownloader.Config.MaxDownloads = GetParameter <int>(args, "-max-downloads", 8);
            ContentDownloader.Config.MaxServers   = Math.Max(ContentDownloader.Config.MaxServers, ContentDownloader.Config.MaxDownloads);
            ContentDownloader.Config.LoginID      = HasParameter(args, "-loginid") ? (uint?)GetParameter <uint>(args, "-loginid") : null;

            #endregion

            uint appId = GetParameter <uint>(args, "-app", ContentDownloader.INVALID_APP_ID);
            if (appId == ContentDownloader.INVALID_APP_ID)
            {
                Console.WriteLine("Error: -app not specified!");
                return(1);
            }

            ulong pubFile = GetParameter <ulong>(args, "-pubfile", ContentDownloader.INVALID_MANIFEST_ID);
            ulong ugcId   = GetParameter <ulong>(args, "-ugc", ContentDownloader.INVALID_MANIFEST_ID);
            if (pubFile != ContentDownloader.INVALID_MANIFEST_ID)
            {
                #region Pubfile Downloading

                if (InitializeSteam(username, password, null))
                {
                    try
                    {
                        await ContentDownloader.DownloadPubfileAsync(appId, pubFile).ConfigureAwait(false);
                    }
                    catch (Exception ex) when(
                        ex is ContentDownloaderException ||
                        ex is OperationCanceledException)
                    {
                        Console.WriteLine(ex.Message);
                        return(1);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Download failed to due to an unhandled exception: {0}", e.Message);
                        throw;
                    }
                    finally
                    {
                        ContentDownloader.ShutdownSteam3();
                    }
                }
                else
                {
                    Console.WriteLine("Error: InitializeSteam failed");
                    return(1);
                }

                #endregion
            }
            else if (ugcId != ContentDownloader.INVALID_MANIFEST_ID)
            {
                #region UGC Downloading

                if (InitializeSteam(username, password, null))
                {
                    try
                    {
                        await ContentDownloader.DownloadUGCAsync(appId, ugcId).ConfigureAwait(false);
                    }
                    catch (Exception ex) when(
                        ex is ContentDownloaderException ||
                        ex is OperationCanceledException)
                    {
                        Console.WriteLine(ex.Message);
                        return(1);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Download failed to due to an unhandled exception: {0}", e.Message);
                        throw;
                    }
                    finally
                    {
                        ContentDownloader.ShutdownSteam3();
                    }
                }
                else
                {
                    Console.WriteLine("Error: InitializeSteam failed");
                    return(1);
                }

                #endregion
            }
            else
            {
                #region App downloading

                string branch = GetParameter <string>(args, "-branch") ?? GetParameter <string>(args, "-beta") ?? ContentDownloader.DEFAULT_BRANCH;
                ContentDownloader.Config.BetaPassword = GetParameter <string>(args, "-betapassword");

                ContentDownloader.Config.DownloadAllPlatforms = HasParameter(args, "-all-platforms");
                string os = GetParameter <string>(args, "-os", null);

                if (ContentDownloader.Config.DownloadAllPlatforms && !String.IsNullOrEmpty(os))
                {
                    Console.WriteLine("Error: Cannot specify -os when -all-platforms is specified.");
                    return(1);
                }

                string arch = GetParameter <string>(args, "-osarch", null);

                ContentDownloader.Config.DownloadAllLanguages = HasParameter(args, "-all-languages");
                string language = GetParameter <string>(args, "-language", null);

                if (ContentDownloader.Config.DownloadAllLanguages && !String.IsNullOrEmpty(language))
                {
                    Console.WriteLine("Error: Cannot specify -language when -all-languages is specified.");
                    return(1);
                }

                bool lv = HasParameter(args, "-lowviolence");

                List <(uint, ulong)>  depotManifestIds = new List <(uint, ulong)>();
                List <(uint, byte[])> depotDepotkeys   = new List <(uint, byte[])>();
                bool isUGC = false;

                List <uint>   depotIdList    = GetParameterList <uint>(args, "-depot");
                List <string> depotKeyList   = GetParameterList <string>(args, "-depotkey");
                List <ulong>  manifestIdList = GetParameterList <ulong>(args, "-manifest");
                if (manifestIdList.Count > 0)
                {
                    if (depotIdList.Count != manifestIdList.Count)
                    {
                        Console.WriteLine("Error: -manifest requires one id for every -depot specified");
                        return(1);
                    }

                    var zippedDepotManifest = depotIdList.Zip(manifestIdList, (depotId, manifestId) => (depotId, manifestId));
                    depotManifestIds.AddRange(zippedDepotManifest);
                }
                else
                {
                    depotManifestIds.AddRange(depotIdList.Select(depotId => (depotId, ContentDownloader.INVALID_MANIFEST_ID)));
                }

                if (depotKeyList.Count > 0)
                {
                    if (depotIdList.Count != depotKeyList.Count)
                    {
                        Console.WriteLine("Error: -depotkey requires one key for every -depot specified");
                        return(1);
                    }

                    var zippedDepotKeys = depotIdList.Zip(depotKeyList, (depotId, depotkey) => (depotId, Util.DecodeHexString(depotkey)));
                    depotDepotkeys.AddRange(zippedDepotKeys);
                }

                if (InitializeSteam(username, password, depotDepotkeys))
                {
                    try
                    {
                        await ContentDownloader.DownloadAppAsync(appId, depotManifestIds, branch, os, arch, language, lv, isUGC).ConfigureAwait(false);
                    }
                    catch (Exception ex) when(
                        ex is ContentDownloaderException ||
                        ex is OperationCanceledException)
                    {
                        Console.WriteLine(ex.Message);
                        return(1);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Download failed to due to an unhandled exception: {0}", e.Message);
                        throw;
                    }
                    finally
                    {
                        ContentDownloader.ShutdownSteam3();
                    }
                }
                else
                {
                    Console.WriteLine("Error: InitializeSteam failed");
                    return(1);
                }

                #endregion
            }

            return(0);
        }
        static async Task <int> MainAsync(string[] args)
        {
            if (args.Length == 0)
            {
                PrintUsage();
                return(1);
            }

            DebugLog.Enabled = false;

            AccountSettingsStore.LoadFromFile("account.config");

            #region Common Options

            if (HasParameter(args, "-debug"))
            {
                DebugLog.Enabled = true;
                DebugLog.AddListener((category, message) =>
                {
                    Console.WriteLine("[{0}] {1}", category, message);
                });
            }

            string username = GetParameter <string>(args, "-username") ?? GetParameter <string>(args, "-user");
            string password = GetParameter <string>(args, "-password") ?? GetParameter <string>(args, "-pass");
            ContentDownloader.Config.RememberPassword = HasParameter(args, "-remember-password");

            ContentDownloader.Config.DownloadManifestOnly = HasParameter(args, "-manifest-only");

            int cellId = GetParameter <int>(args, "-cellid", -1);
            if (cellId == -1)
            {
                cellId = 0;
            }

            ContentDownloader.Config.CellID = cellId;

            string   fileList = GetParameter <string>(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>();

                    var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
                    foreach (var fileEntry in files)
                    {
                        try
                        {
                            string fileEntryProcessed;
                            if (isWindows)
                            {
                                // On Windows, ensure that forward slashes can match either forward or backslashes in depot paths
                                fileEntryProcessed = fileEntry.Replace("/", "[\\\\|/]");
                            }
                            else
                            {
                                // On other systems, treat / normally
                                fileEntryProcessed = fileEntry;
                            }
                            Regex rgx = new Regex(fileEntryProcessed, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                            ContentDownloader.Config.FilesToDownloadRegex.Add(rgx);
                        }
                        catch
                        {
                            // For anything that can't be processed as a Regex, allow both forward and backward slashes to match
                            // on Windows
                            if (isWindows)
                            {
                                ContentDownloader.Config.FilesToDownload.Add(fileEntry.Replace("/", "\\"));
                            }
                            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());
                }
            }

            ContentDownloader.Config.InstallDirectory = GetParameter <string>(args, "-dir");

            ContentDownloader.Config.VerifyAll    = HasParameter(args, "-verify-all") || HasParameter(args, "-verify_all") || HasParameter(args, "-validate");
            ContentDownloader.Config.MaxServers   = GetParameter <int>(args, "-max-servers", 20);
            ContentDownloader.Config.MaxDownloads = GetParameter <int>(args, "-max-downloads", 4);
            ContentDownloader.Config.MaxServers   = Math.Max(ContentDownloader.Config.MaxServers, ContentDownloader.Config.MaxDownloads);
            ContentDownloader.Config.LoginID      = HasParameter(args, "-loginid") ? (uint?)GetParameter <uint>(args, "-loginid") : null;

            #endregion

            uint appId = GetParameter <uint>(args, "-app", ContentDownloader.INVALID_APP_ID);
            if (appId == ContentDownloader.INVALID_APP_ID)
            {
                Console.WriteLine("Error: -app not specified!");
                return(1);
            }

            ulong pubFile = GetParameter <ulong>(args, "-pubfile", ContentDownloader.INVALID_MANIFEST_ID);
            if (pubFile != ContentDownloader.INVALID_MANIFEST_ID)
            {
                #region Pubfile Downloading

                if (InitializeSteam(username, password))
                {
                    try
                    {
                        await ContentDownloader.DownloadPubfileAsync(appId, pubFile).ConfigureAwait(false);
                    }
                    catch (Exception ex) when(
                        ex is ContentDownloaderException ||
                        ex is OperationCanceledException)
                    {
                        Console.WriteLine(ex.Message);
                        return(1);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Download failed to due to an unhandled exception: {0}", e.Message);
                        throw;
                    }
                    finally
                    {
                        ContentDownloader.ShutdownSteam3();
                    }
                }
                else
                {
                    Console.WriteLine("Error: InitializeSteam failed");
                    return(1);
                }

                #endregion
            }
            else
            {
                #region App downloading

                string branch = GetParameter <string>(args, "-branch") ?? GetParameter <string>(args, "-beta") ?? ContentDownloader.DEFAULT_BRANCH;
                ContentDownloader.Config.BetaPassword = GetParameter <string>(args, "-betapassword");

                ContentDownloader.Config.DownloadAllPlatforms = HasParameter(args, "-all-platforms");
                string os = GetParameter <string>(args, "-os", null);

                if (ContentDownloader.Config.DownloadAllPlatforms && !String.IsNullOrEmpty(os))
                {
                    Console.WriteLine("Error: Cannot specify -os when -all-platforms is specified.");
                    return(1);
                }

                string arch = GetParameter <string>(args, "-osarch", null);

                ContentDownloader.Config.DownloadAllLanguages = HasParameter(args, "-all-languages");
                string language = GetParameter <string>(args, "-language", null);

                if (ContentDownloader.Config.DownloadAllLanguages && !String.IsNullOrEmpty(language))
                {
                    Console.WriteLine("Error: Cannot specify -language when -all-languages is specified.");
                    return(1);
                }

                bool lv = HasParameter(args, "-lowviolence");

                uint depotId;
                bool isUGC = false;

                ulong manifestId = GetParameter <ulong>(args, "-ugc", ContentDownloader.INVALID_MANIFEST_ID);
                if (manifestId != ContentDownloader.INVALID_MANIFEST_ID)
                {
                    depotId = appId;
                    isUGC   = true;
                }
                else
                {
                    depotId    = GetParameter <uint>(args, "-depot", ContentDownloader.INVALID_DEPOT_ID);
                    manifestId = GetParameter <ulong>(args, "-manifest", ContentDownloader.INVALID_MANIFEST_ID);
                    if (depotId == ContentDownloader.INVALID_DEPOT_ID && manifestId != ContentDownloader.INVALID_MANIFEST_ID)
                    {
                        Console.WriteLine("Error: -manifest requires -depot to be specified");
                        return(1);
                    }
                }

                if (InitializeSteam(username, password))
                {
                    try
                    {
                        await ContentDownloader.DownloadAppAsync(appId, depotId, manifestId, branch, os, arch, language, lv, isUGC).ConfigureAwait(false);
                    }
                    catch (Exception ex) when(
                        ex is ContentDownloaderException ||
                        ex is OperationCanceledException)
                    {
                        Console.WriteLine(ex.Message);
                        return(1);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Download failed to due to an unhandled exception: {0}", e.Message);
                        throw;
                    }
                    finally
                    {
                        ContentDownloader.ShutdownSteam3();
                    }
                }
                else
                {
                    Console.WriteLine("Error: InitializeSteam failed");
                    return(1);
                }

                #endregion
            }

            return(0);
        }
Beispiel #15
0
 public static void PopulateDepot(string branch, SteamVRVersion ver, ref SteamVRDepot depot)
 {
     ContentDownloader.Config.ManifestId = ContentDownloader.INVALID_MANIFEST_ID;
     depot.ManifestId = ContentDownloader.GetSteam3DepotManifest(depot.DepotId, ver.AppId, branch);
 }
Beispiel #16
0
        static async Task MainAsync(string[] args)
        {
            if (args.Length == 0)
            {
                PrintUsage();
                return;
            }

            DebugLog.Enabled = false;

            ConfigStore.LoadFromFile(Path.Combine(Directory.GetCurrentDirectory(), "DepotDownloader.config"));

            bool bDumpManifest = HasParameter(args, "-manifest-only");
            uint appId         = GetParameter <uint>(args, "-app", ContentDownloader.INVALID_APP_ID);
            uint depotId       = GetParameter <uint>(args, "-depot", ContentDownloader.INVALID_DEPOT_ID);

            ContentDownloader.Config.ManifestId = GetParameter <ulong>(args, "-manifest", ContentDownloader.INVALID_MANIFEST_ID);

            if (appId == ContentDownloader.INVALID_APP_ID)
            {
                Console.WriteLine("Error: -app not specified!");
                return;
            }

            if (depotId == ContentDownloader.INVALID_DEPOT_ID && ContentDownloader.Config.ManifestId != ContentDownloader.INVALID_MANIFEST_ID)
            {
                Console.WriteLine("Error: -manifest requires -depot to be specified");
                return;
            }

            ContentDownloader.Config.DownloadManifestOnly = bDumpManifest;

            int cellId = GetParameter <int>(args, "-cellid", -1);

            if (cellId == -1)
            {
                cellId = 0;
            }

            ContentDownloader.Config.CellID       = cellId;
            ContentDownloader.Config.BetaPassword = GetParameter <string>(args, "-betapassword");

            string fileList = GetParameter <string>(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 = GetParameter <string>(args, "-username") ?? GetParameter <string>(args, "-user");
            string password = GetParameter <string>(args, "-password") ?? GetParameter <string>(args, "-pass");

            ContentDownloader.Config.RememberPassword     = HasParameter(args, "-remember-password");
            ContentDownloader.Config.InstallDirectory     = GetParameter <string>(args, "-dir");
            ContentDownloader.Config.DownloadAllPlatforms = HasParameter(args, "-all-platforms");
            ContentDownloader.Config.VerifyAll            = HasParameter(args, "-verify-all") || HasParameter(args, "-verify_all") || HasParameter(args, "-validate");
            ContentDownloader.Config.MaxServers           = GetParameter <int>(args, "-max-servers", 20);
            ContentDownloader.Config.MaxDownloads         = GetParameter <int>(args, "-max-downloads", 4);
            string branch     = GetParameter <string>(args, "-branch") ?? GetParameter <string>(args, "-beta") ?? "Public";
            bool   forceDepot = HasParameter(args, "-force-depot");
            string os         = GetParameter <string>(args, "-os", null);

            if (ContentDownloader.Config.DownloadAllPlatforms && !String.IsNullOrEmpty(os))
            {
                Console.WriteLine("Error: Cannot specify -os when -all-platforms is specified.");
                return;
            }

            ContentDownloader.Config.MaxServers = Math.Max(ContentDownloader.Config.MaxServers, ContentDownloader.Config.MaxDownloads);

            if (username != null && password == null && (!ContentDownloader.Config.RememberPassword || !ConfigStore.TheConfig.LoginKeys.ContainsKey(username)))
            {
                Console.Write("Enter account password for \"{0}\": ", username);
                password = Util.ReadPassword();
                Console.WriteLine();
            }
            else if (username == null)
            {
                Console.WriteLine("No username given. Using anonymous account with dedicated server subscription.");
            }

            // capture the supplied password in case we need to re-use it after checking the login key
            ContentDownloader.Config.SuppliedPassword = password;

            if (ContentDownloader.InitializeSteam3(username, password))
            {
                await ContentDownloader.DownloadAppAsync(appId, depotId, branch, os, forceDepot).ConfigureAwait(false);

                ContentDownloader.ShutdownSteam3();
            }
        }
Beispiel #17
0
        public void RequestAppInfo(uint appId)
        {
            if (AppInfo.ContainsKey(appId) || bAborted)
            {
                return;
            }

            Action <SteamApps.PICSTokensCallback, JobID> cbMethodTokens = (appTokens, jobId) =>
            {
                if (appTokens.AppTokensDenied.Contains(appId))
                {
                    Console.WriteLine("Insufficient privileges to get access token for app {0}", appId);
                }

                foreach (var token_dict in appTokens.AppTokens)
                {
                    this.AppTokens.Add(token_dict.Key, token_dict.Value);
                }
            };

            using (JobCallback <SteamApps.PICSTokensCallback> appTokensCallback = new JobCallback <SteamApps.PICSTokensCallback>(cbMethodTokens, callbacks, steamApps.PICSGetAccessTokens(new List <uint>()
            {
                appId
            }, new List <uint>()
            {
            })))
            {
                do
                {
                    WaitForCallbacks();
                }while (!appTokensCallback.Completed && !bAborted);
            }

            Action <SteamApps.PICSProductInfoCallback, JobID> cbMethod = (appInfo, jobId) =>
            {
                Debug.Assert(appInfo.ResponsePending == false);

                foreach (var app_value in appInfo.Apps)
                {
                    var app = app_value.Value;

                    Console.WriteLine("Got AppInfo for {0}", app.ID);
                    AppInfo.Add(app.ID, app);

                    KeyValue depots = ContentDownloader.GetSteam3AppSection((int)app.ID, EAppInfoSection.Depots);
                    if (depots != null)
                    {
                        if (depots["OverridesCDDB"].AsBoolean(false))
                        {
                            AppInfoOverridesCDR[app.ID] = true;
                        }
                    }
                }

                foreach (var app in appInfo.UnknownApps)
                {
                    AppInfo.Add(app, null);
                }
            };

            SteamApps.PICSRequest request = new SteamApps.PICSRequest(appId);
            if (AppTokens.ContainsKey(appId))
            {
                request.AccessToken = AppTokens[appId];
                request.Public      = false;
            }

            using (JobCallback <SteamApps.PICSProductInfoCallback> appInfoCallback = new JobCallback <SteamApps.PICSProductInfoCallback>(cbMethod, callbacks, steamApps.PICSGetProductInfo(new List <SteamApps.PICSRequest>()
            {
                request
            }, new List <SteamApps.PICSRequest>()
            {
            })))
            {
                do
                {
                    WaitForCallbacks();
                }while (!appInfoCallback.Completed && !bAborted);
            }
        }
Beispiel #18
0
 public void ClearCache()
 {
     ContentDownloader.ClearCache();
 }
Beispiel #19
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();
        }