Beispiel #1
0
        private bool parseUnrealProject(string unrealProjectPath)
        {
            string json;

            try
            {
                json = File.ReadAllText(unrealProjectPath);
            }
            catch (Exception ex)
            {
                return(false);
            }

            JObject uproject = JObject.Parse(json);

            try
            {
                EngineVersion = uproject.Property("EngineAssociation").Value.ToString();
                Category      = uproject.Property("Category").Value.ToString();
                Description   = uproject.Property("Description").Value.ToString();

                //Go through and try to parse each defined module
                IList <JToken> modules = uproject["Modules"].Children().ToList();

                foreach (JToken moduleJson in modules)
                {
                    //First quickly try to parse the name
                    UProjectModule   jsonConv = UProjectModule.LoadFromJObject(moduleJson);
                    ModuleDefinition module   = FindProjectModule(jsonConv.Name);

                    module.SetUProjectSettings(jsonConv);
                }
            }
            catch (JsonException ex)
            {
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        private void addOrEditUprojectModule(string unrealProjectPath, string moduleName, UProjectModule settings)
        {
            string json;

            try
            {
                json = File.ReadAllText(unrealProjectPath);
            }
            catch (Exception ex)
            {
                return;
            }

            JObject uproject = JObject.Parse(json);

            //Get the array of modules and try to find to find a matching one to update
            JArray moduleArray     = (JArray)uproject["Modules"];
            IEnumerator <JToken> e = moduleArray.GetEnumerator();

            foreach (JToken moduleJson in moduleArray.Children().ToList())
            {
                UProjectModule jsonConv = UProjectModule.LoadFromJObject(moduleJson);

                //If they're matching names, remove it from the array (we'll add it later)
                if (jsonConv.Name.Equals(settings.Name, StringComparison.InvariantCultureIgnoreCase))
                {
                    moduleJson.Remove();
                    break;
                }
            }

            //Add to the array
            moduleArray.Add(JToken.FromObject(settings));

            //Write it out to the file
            File.WriteAllText(unrealProjectPath, uproject.ToString());
        }