Exemple #1
0
        /// <summary>
        /// Parses the resources xml and set the properties.  Also generates the
        /// constants file.
        /// </summary>
        /// <returns><c>true</c>, if resources was parsed, <c>false</c> otherwise.</returns>
        /// <param name="classDirectory">Class directory.</param>
        /// <param name="className">Class name.</param>
        /// <param name="res">Res. the data to parse.</param>
        private static bool ParseResources(string classDirectory, string className, string res)
        {
            XmlTextReader reader       = new XmlTextReader(new StringReader(res));
            bool          inResource   = false;
            string        lastProp     = null;
            Hashtable     resourceKeys = new Hashtable();
            string        appId        = null;

            while (reader.Read())
            {
                if (reader.Name == "resources")
                {
                    inResource = true;
                }

                if (inResource && reader.Name == "string")
                {
                    lastProp = reader.GetAttribute("name");
                }
                else if (inResource && !string.IsNullOrEmpty(lastProp))
                {
                    if (reader.HasValue)
                    {
                        if (lastProp == "app_id")
                        {
                            appId = reader.Value;
                            GPGSProjectSettings.Instance.Set(GPGSUtil.APPIDKEY, appId);
                        }
                        else if (lastProp == "package_name")
                        {
                            GPGSProjectSettings.Instance.Set(GPGSUtil.ANDROIDBUNDLEIDKEY, reader.Value);
                        }
                        else
                        {
                            resourceKeys[lastProp] = reader.Value;
                        }

                        lastProp = null;
                    }
                }
            }

            reader.Close();
            if (resourceKeys.Count > 0)
            {
                GPGSUtil.WriteResourceIds(classDirectory, className, resourceKeys);
            }

            return(appId != null);
        }
        private static bool ParseResources(string classDirectory, string className, string res)
        {
            // parse the resources, they keys are in the form of
            // #define <KEY> @"<VALUE>"

            // transform the string to make it easier to parse
            string input = res.Replace("#define ", string.Empty);

            input = input.Replace("@\"", string.Empty);
            input = input.Replace("\"", string.Empty);

            // now input is name value, one per line
            StringReader reader = new StringReader(input);
            string       line   = reader.ReadLine();
            string       key;
            string       value;
            string       clientId     = null;
            Hashtable    resourceKeys = new Hashtable();

            while (line != null)
            {
                string[] parts = line.Split(' ');
                key = parts[0];
                if (parts.Length > 1)
                {
                    value = parts[1];
                }
                else
                {
                    value = null;
                }

                if (!string.IsNullOrEmpty(value))
                {
                    if (key == "CLIENT_ID")
                    {
                        clientId = value;
                        GPGSProjectSettings.Instance.Set(GPGSUtil.IOSCLIENTIDKEY, clientId);
                    }
                    else if (key == "BUNDLE_ID")
                    {
                        GPGSProjectSettings.Instance.Set(GPGSUtil.IOSBUNDLEIDKEY, value);
                    }
                    else if (key.StartsWith("ACH_"))
                    {
                        string prop = "achievement_" + key.Substring(4).ToLower();
                        resourceKeys[prop] = value;
                    }
                    else if (key.StartsWith("LEAD_"))
                    {
                        string prop = "leaderboard_" + key.Substring(5).ToLower();
                        resourceKeys[prop] = value;
                    }
                    else if (key.StartsWith("EVENT_"))
                    {
                        string prop = "event_" + key.Substring(6).ToLower();
                        resourceKeys[prop] = value;
                    }
                    else if (key.StartsWith("QUEST_"))
                    {
                        string prop = "quest_" + key.Substring(6).ToLower();
                        resourceKeys[prop] = value;
                    }
                    else
                    {
                        resourceKeys[key] = value;
                    }
                }

                line = reader.ReadLine();
            }

            reader.Close();
            if (resourceKeys.Count > 0)
            {
                GPGSUtil.WriteResourceIds(classDirectory, className, resourceKeys);
            }

            GPGSProjectSettings.Instance.Save();
            return(!string.IsNullOrEmpty(clientId));
        }