/// <summary> /// Creates a plugin descriptor from a file on disk /// </summary> /// <param name="FileName">The filename to read</param> /// <returns>New plugin descriptor</returns> public static ProjectDescriptor FromFile(string FileName) { JsonObject RawObject = JsonObject.FromFile(FileName); try { ProjectDescriptor Descriptor = new ProjectDescriptor(); // Read the version if (!RawObject.TryGetIntegerField("FileVersion", out Descriptor.FileVersion)) { if (!RawObject.TryGetIntegerField("ProjectFileVersion", out Descriptor.FileVersion)) { throw new BuildException("Project descriptor '{0}' does not contain a valid FileVersion entry", FileName); } } // Check it's not newer than the latest version we can parse if (Descriptor.FileVersion > (int)PluginDescriptorVersion.Latest) { throw new BuildException("Project descriptor '{0}' appears to be in a newer version ({1}) of the file format that we can load (max version: {2}).", FileName, Descriptor.FileVersion, (int)ProjectDescriptorVersion.Latest); } // Read simple fields RawObject.TryGetStringField("EngineAssociation", out Descriptor.EngineAssociation); RawObject.TryGetStringField("Category", out Descriptor.Category); RawObject.TryGetStringField("Description", out Descriptor.Description); // Read the modules JsonObject[] ModulesArray; if (RawObject.TryGetObjectArrayField("Modules", out ModulesArray)) { Descriptor.Modules = Array.ConvertAll(ModulesArray, x => ModuleDescriptor.FromJsonObject(x)); } // Read the plugins JsonObject[] PluginsArray; if (RawObject.TryGetObjectArrayField("Plugins", out PluginsArray)) { Descriptor.Plugins = Array.ConvertAll(PluginsArray, x => PluginReferenceDescriptor.FromJsonObject(x)); } // Read the target platforms RawObject.TryGetStringArrayField("TargetPlatforms", out Descriptor.TargetPlatforms); // Get the sample name hash RawObject.TryGetUnsignedIntegerField("EpicSampleNameHash", out Descriptor.EpicSampleNameHash); return(Descriptor); } catch (JsonParseException ParseException) { throw new JsonParseException("{0} (in {1})", ParseException.Message, FileName); } }
/// <summary> /// Creates a plugin descriptor from a file on disk /// </summary> /// <param name="FileName">The filename to read</param> /// <returns>New plugin descriptor</returns> public static PluginDescriptor FromFile(string FileName) { JsonObject RawObject = JsonObject.FromFile(FileName); try { PluginDescriptor Descriptor = new PluginDescriptor(); // Read the version if (!RawObject.TryGetIntegerField("FileVersion", out Descriptor.FileVersion)) { if (!RawObject.TryGetIntegerField("PluginFileVersion", out Descriptor.FileVersion)) { throw new BuildException("Plugin descriptor file '{0}' does not contain a valid FileVersion entry", FileName); } } // Check it's not newer than the latest version we can parse if (Descriptor.FileVersion > (int)PluginDescriptorVersion.Latest) { throw new BuildException("Plugin descriptor file '{0}' appears to be in a newer version ({1}) of the file format that we can load (max version: {2}).", FileName, Descriptor.FileVersion, (int)PluginDescriptorVersion.Latest); } // Read the other fields RawObject.TryGetIntegerField("Version", out Descriptor.Version); RawObject.TryGetStringField("VersionName", out Descriptor.VersionName); RawObject.TryGetStringField("FriendlyName", out Descriptor.FriendlyName); RawObject.TryGetStringField("Description", out Descriptor.Description); if (!RawObject.TryGetStringField("Category", out Descriptor.Category)) { // Category used to be called CategoryPath in .uplugin files RawObject.TryGetStringField("CategoryPath", out Descriptor.Category); } // Due to a difference in command line parsing between Windows and Mac, we shipped a few Mac samples containing // a category name with escaped quotes. Remove them here to make sure we can list them in the right category. if (Descriptor.Category != null && Descriptor.Category.Length >= 2 && Descriptor.Category.StartsWith("\"") && Descriptor.Category.EndsWith("\"")) { Descriptor.Category = Descriptor.Category.Substring(1, Descriptor.Category.Length - 2); } RawObject.TryGetStringField("CreatedBy", out Descriptor.CreatedBy); RawObject.TryGetStringField("CreatedByURL", out Descriptor.CreatedByURL); RawObject.TryGetStringField("DocsURL", out Descriptor.DocsURL); RawObject.TryGetStringField("MarketplaceURL", out Descriptor.MarketplaceURL); RawObject.TryGetStringField("SupportURL", out Descriptor.SupportURL); JsonObject[] ModulesArray; if (RawObject.TryGetObjectArrayField("Modules", out ModulesArray)) { Descriptor.Modules = Array.ConvertAll(ModulesArray, x => ModuleDescriptor.FromJsonObject(x)); } RawObject.TryGetBoolField("EnabledByDefault", out Descriptor.bEnabledByDefault); RawObject.TryGetBoolField("CanContainContent", out Descriptor.bCanContainContent); RawObject.TryGetBoolField("IsBetaVersion", out Descriptor.bIsBetaVersion); RawObject.TryGetBoolField("Installed", out Descriptor.bInstalled); return(Descriptor); } catch (JsonParseException ParseException) { throw new JsonParseException("{0} (in {1})", ParseException.Message, FileName); } }