示例#1
0
 ConfigStatus SetStringArrayProperty <T>(
     T assignObject, PropertyInfo property, string paramName, string value)
 {
     property.SetValue(assignObject, value.Split(',')
                       .Where(s => !string.IsNullOrWhiteSpace(s)).ToArray());
     return(ConfigStatus.OkStatus());
 }
示例#2
0
        ConfigStatus ParseParamsCmd(LaunchParams parameters,
                                    IDictionary <string, string> queryParams)
        {
            if (!queryParams.ContainsKey(QueryParamMapping.Cmd))
            {
                return(ConfigStatus.OkStatus());
            }

            string queryParamsCmd = queryParams[QueryParamMapping.Cmd];

            if (string.IsNullOrWhiteSpace(parameters.Cmd))
            {
                parameters.Cmd = queryParamsCmd;
                return(ConfigStatus.OkStatus());
            }

            // The cmd is valid only if the binary name is the same as in
            // the project output.
            string settingsBinaryName =
                parameters.Cmd.Split(' ').First(s => !string.IsNullOrEmpty(s));
            string queryBinaryName =
                queryParamsCmd.Split(' ').FirstOrDefault(s => !string.IsNullOrEmpty(s));

            if (queryBinaryName != settingsBinaryName)
            {
                return(ConfigStatus.ErrorStatus(
                           ErrorStrings.InvalidBinaryName(settingsBinaryName, queryBinaryName)));
            }

            parameters.Cmd = queryParamsCmd;

            return(ConfigStatus.OkStatus());
        }
示例#3
0
        ConfigStatus SetEnumProperty <T>(
            T assignObject, PropertyInfo property, string paramName, string value)
        {
            Type propertyType   = property.PropertyType;
            var  expectedValues = new List <string>();

            foreach (string fieldName in Enum.GetNames(propertyType))
            {
                FieldInfo fieldInfo = propertyType.GetField(fieldName);
                var       attr      = (MapValueAttribute)fieldInfo
                                      .GetCustomAttributes(typeof(MapValueAttribute), false).SingleOrDefault();
                if (attr == null)
                {
                    continue;
                }

                if (value.ToLower() == attr.QueryParameterValue.ToLower())
                {
                    property.SetValue(assignObject, Enum.Parse(propertyType, fieldName));
                    return(ConfigStatus.OkStatus());
                }

                expectedValues.Add(attr.QueryParameterValue);
            }

            return(ConfigStatus.WarningStatus(
                       ErrorStrings.InvalidEnumValue(paramName, value, expectedValues)));
        }
示例#4
0
        ConfigStatus ParseLaunchRequestVulkanDriverVariant(LaunchGameRequest launchRequest,
                                                           IDictionary <string, string> queryParams)
        {
            ConfigStatus status = ConfigStatus.OkStatus();

            if (queryParams.ContainsKey(QueryParamMapping.VulkanDriverVariant))
            {
                string driverVariant = "GGP_DEV_VK_DRIVER_VARIANT";
                if (!launchRequest.EnvironmentVariablePairs.ContainsKey(driverVariant))
                {
                    var allowedValues = new[] { "opt", "optprintasserts", "dbgtrapasserts" };
                    if (!allowedValues.Contains(queryParams[QueryParamMapping.VulkanDriverVariant]
                                                .ToLower()))
                    {
                        status.AppendWarning(ErrorStrings.InvalidEnumValue(
                                                 QueryParamMapping.VulkanDriverVariant,
                                                 queryParams[QueryParamMapping.VulkanDriverVariant],
                                                 allowedValues));
                    }
                    else
                    {
                        launchRequest.EnvironmentVariablePairs.Add(
                            driverVariant,
                            queryParams[QueryParamMapping.VulkanDriverVariant].ToLower());
                    }
                }
            }

            return(status);
        }
示例#5
0
        ConfigStatus AddBoolEnvironmentVariable(LaunchGameRequest launchRequest,
                                                IDictionary <string, string> queryParams,
                                                string variableName, string queryParamName)
        {
            if (!queryParams.ContainsKey(queryParamName) ||
                launchRequest.EnvironmentVariablePairs.ContainsKey(variableName))
            {
                return(ConfigStatus.OkStatus());
            }

            if (!bool.TryParse(queryParams[queryParamName], out bool isTrue))
            {
                if (!int.TryParse(queryParams[queryParamName], out int intVal) || intVal < 0 ||
                    intVal > 1)
                {
                    return(ConfigStatus.WarningStatus(ErrorStrings.InvalidQueryParameterType(
                                                          queryParamName,
                                                          queryParams[queryParamName],
                                                          typeof(bool))));
                }

                isTrue = intVal == 1;
            }

            if (isTrue)
            {
                launchRequest.EnvironmentVariablePairs.Add(variableName, "1");
            }

            return(ConfigStatus.OkStatus());
        }
示例#6
0
 ConfigStatus SetUlongProperty <T>(
     T assignObject, PropertyInfo property, string paramName, string value)
 {
     if (!ulong.TryParse(value, out ulong ulongValue))
     {
         return(ConfigStatus.WarningStatus(
                    ErrorStrings.InvalidQueryParameterType(paramName, value, typeof(ulong))));
     }
     property.SetValue(assignObject, ulongValue);
     return(ConfigStatus.OkStatus());
 }
示例#7
0
 ConfigStatus SetIntProperty <T>(
     T assignObject, PropertyInfo property, string paramName, string value)
 {
     if (!int.TryParse(value, out int intValue))
     {
         return(ConfigStatus.WarningStatus(
                    ErrorStrings.InvalidQueryParameterType(paramName, value, typeof(int))));
     }
     property.SetValue(assignObject, intValue);
     return(ConfigStatus.OkStatus());
 }
示例#8
0
 ConfigStatus ParseParamsVars(LaunchParams parameters,
                              IDictionary <string, string> queryParams)
 {
     if (queryParams.ContainsKey(QueryParamMapping.Vars))
     {
         // The last occurrence of the an environment variable wins.
         parameters.GameletEnvironmentVars = parameters.GameletEnvironmentVars + ";" +
                                             queryParams[QueryParamMapping.Vars];
     }
     return(ConfigStatus.OkStatus());
 }
        ConfigStatus CommandLineArguments(LaunchParams parameters,
                                          out string[] args)
        {
            args = new string[0];
            if (string.IsNullOrWhiteSpace(parameters.Cmd))
            {
                return(ConfigStatus.OkStatus());
            }

            args = parameters.Cmd.Trim().Split(' ').Where(s => !string.IsNullOrEmpty(s)).Skip(1)
                   .ToArray();
            return(ConfigStatus.OkStatus());
        }
        ConfigStatus AddFlagsEnvironmentVariables(
            LaunchParams parameters, IDictionary <string, string> variables)
        {
            ConfigStatus status = ConfigStatus.OkStatus();
            var          flagEnvironmentVariables = new Dictionary <string, string>();

            if (!string.IsNullOrWhiteSpace(parameters.VulkanDriverVariant))
            {
                flagEnvironmentVariables.Add("GGP_DEV_VK_DRIVER_VARIANT",
                                             parameters.VulkanDriverVariant);
            }
            if (parameters.RenderDoc)
            {
                flagEnvironmentVariables.Add("ENABLE_VULKAN_RENDERDOC_CAPTURE", "1");
                flagEnvironmentVariables.Add("RENDERDOC_TEMP", "/mnt/developer/ggp");
                flagEnvironmentVariables.Add("RENDERDOC_DEBUG_LOG_FILE", "/var/game/RDDebug.log");
            }
            if (parameters.Rgp)
            {
                flagEnvironmentVariables.Add("GGP_INTERNAL_LOAD_RGP", "1");
                flagEnvironmentVariables.Add("RGP_DEBUG_LOG_FILE", "/var/game/RGPDebug.log");
            }

            foreach (string key in flagEnvironmentVariables.Keys)
            {
                if (variables.ContainsKey(key))
                {
                    status.AppendWarning(ErrorStrings.EnvironmentVariableOverride(key));
                    continue;
                }
                variables.Add(key, flagEnvironmentVariables[key]);
            }

            if (parameters.Rgp)
            {
                if (!variables.ContainsKey("LD_PRELOAD"))
                {
                    variables.Add("LD_PRELOAD", string.Empty);
                }
                variables["LD_PRELOAD"] += (string.IsNullOrEmpty(variables["LD_PRELOAD"])
                    ? string.Empty
                    : ":") + "librgpserver.so";
            }

            return(status);
        }
示例#11
0
        ConfigStatus SetBoolProperty <T>(
            T assignObject, PropertyInfo property, string paramName, string value)
        {
            value = value.ToLower();
            if (!bool.TryParse(value, out bool boolValue))
            {
                if (!int.TryParse(value, out int intVal) || intVal < 0 || intVal > 1)
                {
                    return(ConfigStatus.WarningStatus(
                               ErrorStrings.InvalidQueryParameterType(paramName, value, typeof(bool))));
                }

                boolValue = intVal == 1;
            }
            property.SetValue(assignObject, boolValue);
            return(ConfigStatus.OkStatus());
        }
示例#12
0
        /// <summary>
        /// Parses the query string to a dictionary.
        /// Values in the dictionary contain decoded special characters.
        /// For example: the value 'value%3D%C3%BC' in the query string will be 'value=ü'
        /// in the resulting dictionary.
        /// </summary>
        ConfigStatus ToQueryParams(string queryString,
                                   out IDictionary <string, string> queryParams)
        {
            queryParams = new Dictionary <string, string>();
            if (string.IsNullOrEmpty(queryString))
            {
                return(ConfigStatus.OkStatus());
            }

            try
            {
                NameValueCollection nameValueCollection;
                try
                {
                    // May throw an exception when maximum number of keys is exceeded.
                    nameValueCollection = HttpUtility.ParseQueryString(queryString);
                }
                catch (Exception e)
                {
                    throw new ApplicationException(e.Message);
                }

                foreach (string key in nameValueCollection.AllKeys)
                {
                    if (string.IsNullOrWhiteSpace(key))
                    {
                        throw new ApplicationException("Parameter 'Key' can not be empty.");
                    }

                    queryParams.Add(key, nameValueCollection.Get(key));
                }

                LogQueryString(queryString, queryParams);
                return(ConfigStatus.OkStatus());
            }
            catch (ApplicationException e)
            {
                Trace.TraceWarning($"Error happened while parsing query string. {e.Message}");
                queryParams = new Dictionary <string, string>();
                return(ConfigStatus.WarningStatus(
                           ErrorStrings.QueryParametersWrongFormat));
            }
        }
示例#13
0
        ConfigStatus AssignValues <T>(T assignObject,
                                      IDictionary <string, string> queryParams)
        {
            var status = ConfigStatus.OkStatus();
            Dictionary <string, QueryParamMapping> paramsToMap = _queryParamsMappings
                                                                 .Where(p => p.SetRequestParam && p.MapType == typeof(T))
                                                                 .ToDictionary(p => p.ParamName, p => p);

            foreach (KeyValuePair <string, string> queryParam in queryParams)
            {
                if (!paramsToMap.ContainsKey(queryParam.Key))
                {
                    continue;
                }

                status = status.Merge(AssignValue(assignObject, paramsToMap[queryParam.Key],
                                                  queryParam.Key, queryParam.Value));
            }

            return(status);
        }
        ConfigStatus EnvironmentVariables(LaunchParams parameters,
                                          out IDictionary <string, string> envVariables)
        {
            ConfigStatus status          = ConfigStatus.OkStatus();
            string       variablesString = parameters.GameletEnvironmentVars ?? string.Empty;

            envVariables = variablesString.Split(';')
                           .Select(v => v.Trim())
                           .Where(v => !string.IsNullOrWhiteSpace(v)).Select(v =>
            {
                List <string> parts = v.Split('=').ToList();

                if (string.IsNullOrWhiteSpace(parts[0]))
                {
                    status.AppendWarning(ErrorStrings.InvalidEnvironmentVariable(v));
                    return(Tuple.Create(string.Empty, string.Empty));
                }

                return(Tuple.Create(parts[0], string.Join("=", parts.Skip(1))));
            }).Where(t => !string.IsNullOrEmpty(t.Item1)).GroupBy(tuple => tuple.Item1).Select(
                tuple =>
            {
                if (tuple.Count() > 1)
                {
                    status.AppendWarning(
                        ErrorStrings.MultipleEnvironmentVariableKeys(tuple.Key));
                }

                return(tuple);
            }).ToDictionary(t => t.Key, t => t.Last().Item2);
            status = status.Merge(AddFlagsEnvironmentVariables(parameters, envVariables));
            if (!status.IsOk)
            {
                status.AppendWarning(ErrorStrings.EditEnvironmentVariables);
            }

            return(status);
        }
示例#15
0
        public ConfigStatus GetFinalQueryString(
            IDictionary <string, string> queryParams, out string queryString)
        {
            var           status            = ConfigStatus.OkStatus();
            List <string> ignoredParameters = _queryParamsMappings
                                              .Where(p => p.IsIgnored && queryParams.ContainsKey(p.ParamName))
                                              .Select(p => p.ParamName).ToList();

            if (ignoredParameters.Any())
            {
                status.AppendWarning(ErrorStrings.QueryParametersIgnored(ignoredParameters));
            }

            Dictionary <string, QueryParamMapping> queryParamsMappingsDict =
                _queryParamsMappings.ToDictionary(
                    p => p.ParamName, p => p);
            IEnumerable <KeyValuePair <string, string> > paramsToStayInQuery = queryParams.Where(
                p => !queryParamsMappingsDict.ContainsKey(p.Key) ||
                queryParamsMappingsDict[p.Key].PassAsUrlParam);

            queryString = string.Join("&", paramsToStayInQuery.Select(
                                          p => $"{Uri.EscapeDataString(p.Key)}={Uri.EscapeDataString(p.Value)}"));
            return(status);
        }
示例#16
0
 ConfigStatus SetStringProperty <T>(
     T assignObject, PropertyInfo property, string value)
 {
     property.SetValue(assignObject, value);
     return(ConfigStatus.OkStatus());
 }