Ejemplo n.º 1
0
        public PatcherData Read()
        {
            DebugLogger.Log("Reading.");

            PatcherData data = new PatcherData();

            string forceAppSecret;

            if (TryReadEnvironmentVariable(ForceSecretEnvironmentVariable, out forceAppSecret))
            {
                DebugLogger.Log(string.Format("Setting forced app secret {0}", forceAppSecret));
                data.AppSecret = forceAppSecret;
            }
            else
            {
                string appSecret;

                if (!TryReadArgument("--secret", out appSecret))
                {
                    throw new ApplicationException("Unable to parse secret from command line.");
                }
                data.AppSecret = IsReadable() ? appSecret : DecodeSecret(appSecret);
            }

            string forceOverrideLatestVersionIdString;

            if (TryReadEnvironmentVariable(ForceVersionEnvironmentVariable, out forceOverrideLatestVersionIdString))
            {
                int forceOverrideLatestVersionId;

                if (int.TryParse(forceOverrideLatestVersionIdString, out forceOverrideLatestVersionId))
                {
                    DebugLogger.Log(string.Format("Setting forced version id {0}", forceOverrideLatestVersionId));
                    data.OverrideLatestVersionId = forceOverrideLatestVersionId;
                }
            }
            else
            {
                data.OverrideLatestVersionId = 0;
            }

            string relativeAppDataPath;

            if (!TryReadArgument("--installdir", out relativeAppDataPath))
            {
                throw new ApplicationException("Unable to parse app data path from command line.");
            }

            data.AppDataPath = MakeAppDataPathAbsolute(relativeAppDataPath);

            return(data);
        }
        public PatcherData Read()
        {
            DebugLogger.Log("Reading.");

            PatcherData data = new PatcherData();

            if (!HasArgument("--secret") || !HasArgument("--installdir"))
            {
                DebugLogger.Log("Expected the secret and installdir to be present in the command line arguments.");
                throw new NonLauncherExecutionException("Patcher has been started without a Launcher.");
            }

            string forceAppSecret;

            if (EnvironmentInfo.TryReadEnvironmentVariable(EnvironmentVariables.ForceSecretEnvironmentVariable, out forceAppSecret))
            {
                DebugLogger.LogFormat("Setting forced app secret {0}", forceAppSecret);
                data.AppSecret = forceAppSecret;
            }
            else
            {
                string appSecret;

                if (!TryReadArgument("--secret", out appSecret))
                {
                    throw new ApplicationException("Unable to parse secret from command line.");
                }
                data.AppSecret = IsReadable() ? appSecret : DecodeSecret(appSecret);
            }

            string forceOverrideLatestVersionIdString;

            if (EnvironmentInfo.TryReadEnvironmentVariable(EnvironmentVariables.ForceVersionEnvironmentVariable, out forceOverrideLatestVersionIdString))
            {
                int forceOverrideLatestVersionId;

                if (int.TryParse(forceOverrideLatestVersionIdString, out forceOverrideLatestVersionId))
                {
                    DebugLogger.LogFormat("Setting forced version id {0}", forceOverrideLatestVersionId);
                    data.OverrideLatestVersionId = forceOverrideLatestVersionId;
                }
            }
            else
            {
                data.OverrideLatestVersionId = 0;
            }

            string relativeAppDataPath;

            if (!TryReadArgument("--installdir", out relativeAppDataPath))
            {
                throw new ApplicationException("Unable to parse app data path from command line.");
            }
            data.AppDataPath = MakeAppDataPathAbsolute(relativeAppDataPath);

            string lockFilePath;

            if (TryReadArgument("--lockfile", out lockFilePath))
            {
                data.LockFilePath = lockFilePath;
                DebugLogger.LogFormat("Using lock file: {0}", lockFilePath);
            }
            else
            {
                DebugLogger.LogWarning("Lock file not provided.");
            }

            return(data);
        }