Read() public static method

public static Read ( string FileName ) : JsonObject
FileName string
return JsonObject
Example #1
0
        /// <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.Read(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);

                // Read the pre and post-build steps
                CustomBuildSteps.TryRead(RawObject, "PreBuildSteps", out Descriptor.PreBuildSteps);
                CustomBuildSteps.TryRead(RawObject, "PostBuildSteps", out Descriptor.PostBuildSteps);

                return(Descriptor);
            }
            catch (JsonParseException ParseException)
            {
                throw new JsonParseException("{0} (in {1})", ParseException.Message, FileName);
            }
        }
Example #2
0
        /// <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(FileReference FileName)
        {
            JsonObject RawObject = JsonObject.Read(FileName);

            try
            {
                return(new PluginDescriptor(RawObject));
            }
            catch (JsonParseException ParseException)
            {
                throw new JsonParseException("{0} (in {1})", ParseException.Message, FileName);
            }
        }
        /// <summary>
        /// Read an app receipt from disk
        /// </summary>
        /// <param name="FileName">Filename to read from</param>
        /// <returns>The receipt that was read</returns>
        public static ModuleManifest Read(FileReference FileName)
        {
            JsonObject Object = JsonObject.Read(FileName);

            ModuleManifest Receipt = new ModuleManifest(Object.GetStringField("BuildId"));

            JsonObject Modules = Object.GetObjectField("Modules");

            foreach (string ModuleName in Modules.KeyNames)
            {
                Receipt.ModuleNameToFileName.Add(ModuleName, Modules.GetStringField(ModuleName));
            }
            return(Receipt);
        }
Example #4
0
        /// <summary>
        /// Read an app receipt from disk
        /// </summary>
        /// <param name="FileName">Filename to read from</param>
        /// <returns>The receipt that was read</returns>
        public static VersionManifest Read(string FileName)
        {
            JsonObject Object = JsonObject.Read(FileName);

            VersionManifest Receipt = new VersionManifest(Object.GetIntegerField("Changelist"), Object.GetStringField("BuildId"));

            JsonObject Modules = Object.GetObjectField("Modules");

            foreach (string ModuleName in Modules.KeyNames)
            {
                Receipt.ModuleNameToFileName.Add(ModuleName, Modules.GetStringField(ModuleName));
            }
            return(Receipt);
        }
Example #5
0
        /// <summary>
        /// Read a receipt from disk.
        /// </summary>
        /// <param name="Location">Filename to read from</param>
        public static PrecompiledManifest Read(FileReference Location)
        {
            DirectoryReference  BaseDir  = Location.Directory;
            PrecompiledManifest Manifest = new PrecompiledManifest();

            JsonObject RawObject = JsonObject.Read(Location);

            string[] OutputFiles = RawObject.GetStringArrayField("OutputFiles");
            foreach (string OutputFile in OutputFiles)
            {
                Manifest.OutputFiles.Add(FileReference.Combine(BaseDir, OutputFile));
            }

            return(Manifest);
        }
Example #6
0
        /// <summary>
        /// Imports an action graph from a JSON file
        /// </summary>
        /// <param name="InputFile">The file to read from</param>
        /// <returns>List of actions</returns>
        public static List <Action> ImportJson(FileReference InputFile)
        {
            JsonObject Object = JsonObject.Read(InputFile);

            JsonObject EnvironmentObject = Object.GetObjectField("Environment");

            foreach (string KeyName in EnvironmentObject.KeyNames)
            {
                Environment.SetEnvironmentVariable(KeyName, EnvironmentObject.GetStringField(KeyName));
            }

            List <Action> Actions = new List <Action>();

            foreach (JsonObject ActionObject in Object.GetObjectArrayField("Actions"))
            {
                Actions.Add(Action.ImportJson(ActionObject));
            }
            return(Actions);
        }
        /// <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(FileReference FileName)
        {
            JsonObject RawObject = JsonObject.Read(FileName);

            try
            {
                PluginDescriptor Descriptor = new PluginDescriptor(RawObject);
                if (Descriptor.Modules != null)
                {
                    foreach (ModuleDescriptor Module in Descriptor.Modules)
                    {
                        Module.Validate(FileName);
                    }
                }
                return(Descriptor);
            }
            catch (JsonParseException ParseException)
            {
                throw new JsonParseException("{0} (in {1})", ParseException.Message, FileName);
            }
        }
Example #8
0
        /// <summary>
        /// Read an app receipt from disk
        /// </summary>
        /// <param name="FileName">Filename to read from</param>
        /// <returns>The receipt that was read</returns>
        public static VersionManifest Read(string FileName)
        {
            JsonObject Object = JsonObject.Read(FileName);

            int Changelist = Object.GetIntegerField("Changelist");

            int CompatibleChangelist;

            if (!Object.TryGetIntegerField("CompatibleChangelist", out CompatibleChangelist))
            {
                CompatibleChangelist = Changelist;
            }

            VersionManifest Receipt = new VersionManifest(Changelist, CompatibleChangelist, Object.GetStringField("BuildId"));

            JsonObject Modules = Object.GetObjectField("Modules");

            foreach (string ModuleName in Modules.KeyNames)
            {
                Receipt.ModuleNameToFileName.Add(ModuleName, Modules.GetStringField(ModuleName));
            }
            return(Receipt);
        }
Example #9
0
        /// <summary>
        /// Creates a plugin descriptor from a file on disk
        /// </summary>
        /// <param name="FileName">The filename to read</param>
        /// <param name="bPluginTypeEnabledByDefault">Whether this plugin should be enabled by default based on its location</param>
        /// <returns>New plugin descriptor</returns>
        public static PluginDescriptor FromFile(FileReference FileName, bool bPluginTypeEnabledByDefault)
        {
            JsonObject RawObject = JsonObject.Read(FileName.FullName);

            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);
                RawObject.TryGetIntegerField("CompatibleChangelist", out Descriptor.CompatibleChangelist);

                JsonObject[] ModulesArray;
                if (RawObject.TryGetObjectArrayField("Modules", out ModulesArray))
                {
                    Descriptor.Modules = Array.ConvertAll(ModulesArray, x => ModuleDescriptor.FromJsonObject(x));
                }

                JsonObject[] LocalizationTargetsArray;
                if (RawObject.TryGetObjectArrayField("LocalizationTargets", out LocalizationTargetsArray))
                {
                    Descriptor.LocalizationTargets = Array.ConvertAll(LocalizationTargetsArray, x => LocalizationTargetDescriptor.FromJsonObject(x));
                }

                if (!RawObject.TryGetBoolField("EnabledByDefault", out Descriptor.bEnabledByDefault))
                {
                    Descriptor.bEnabledByDefault = bPluginTypeEnabledByDefault;
                }

                RawObject.TryGetBoolField("CanContainContent", out Descriptor.bCanContainContent);
                RawObject.TryGetBoolField("IsBetaVersion", out Descriptor.bIsBetaVersion);
                RawObject.TryGetBoolField("IsMod", out Descriptor.bIsMod);
                RawObject.TryGetBoolField("Installed", out Descriptor.bInstalled);
                RawObject.TryGetBoolField("CanBeUsedWithUnrealHeaderTool", out Descriptor.bCanBeUsedWithUnrealHeaderTool);
                RawObject.TryGetBoolField("RequiresBuildPlatform", out Descriptor.bRequiresBuildPlatform);

                CustomBuildSteps.TryRead(RawObject, "PreBuildSteps", out Descriptor.PreBuildSteps);
                CustomBuildSteps.TryRead(RawObject, "PostBuildSteps", out Descriptor.PostBuildSteps);

                return(Descriptor);
            }
            catch (JsonParseException ParseException)
            {
                throw new JsonParseException("{0} (in {1})", ParseException.Message, FileName);
            }
        }
Example #10
0
        /// <summary>
        /// Checks to see if the assembly needs compilation
        /// </summary>
        /// <param name="SourceFiles">Set of source files</param>
        /// <param name="AssemblyManifestFilePath">File containing information about this assembly, like which source files it was built with and engine version</param>
        /// <param name="OutputAssemblyPath">Output path for the assembly</param>
        /// <returns>True if the assembly needs to be built</returns>
        private static bool RequiresCompilation(HashSet <FileReference> SourceFiles, FileReference AssemblyManifestFilePath, FileReference OutputAssemblyPath)
        {
            // Check to see if we already have a compiled assembly file on disk
            FileItem OutputAssemblyInfo = FileItem.GetItemByFileReference(OutputAssemblyPath);

            if (!OutputAssemblyInfo.Exists)
            {
                Log.TraceLog("Compiling {0}: Assembly does not exist", OutputAssemblyPath);
                return(true);
            }

            // Check the time stamp of the UnrealBuildTool.exe file.  If Unreal Build Tool was compiled more
            // recently than the dynamically-compiled assembly, then we'll always recompile it.  This is
            // because Unreal Build Tool's code may have changed in such a way that invalidate these
            // previously-compiled assembly files.
            FileItem ExecutableItem = FileItem.GetItemByFileReference(UnrealBuildTool.GetUBTPath());

            if (ExecutableItem.LastWriteTimeUtc > OutputAssemblyInfo.LastWriteTimeUtc)
            {
                Log.TraceLog("Compiling {0}: {1} is newer", OutputAssemblyPath, ExecutableItem.Name);
                return(true);
            }


            // Make sure we have a manifest of source files used to compile the output assembly.  If it doesn't exist
            // for some reason (not an expected case) then we'll need to recompile.
            FileItem AssemblySourceListFile = FileItem.GetItemByFileReference(AssemblyManifestFilePath);

            if (!AssemblySourceListFile.Exists)
            {
                Log.TraceLog("Compiling {0}: Missing source file list ({1})", OutputAssemblyPath, AssemblyManifestFilePath);
                return(true);
            }

            JsonObject Manifest = JsonObject.Read(AssemblyManifestFilePath);

            // check if the engine version is different
            string EngineVersionManifest = Manifest.GetStringField("EngineVersion");
            string EngineVersionCurrent  = FormatVersionNumber(ReadOnlyBuildVersion.Current);

            if (EngineVersionManifest != EngineVersionCurrent)
            {
                Log.TraceLog("Compiling {0}: Engine Version changed from {1} to {2}", OutputAssemblyPath, EngineVersionManifest, EngineVersionCurrent);
                return(true);
            }


            // Make sure the source files we're compiling are the same as the source files that were compiled
            // for the assembly that we want to load
            HashSet <FileItem> CurrentSourceFileItems = new HashSet <FileItem>();

            foreach (string Line in Manifest.GetStringArrayField("SourceFiles"))
            {
                CurrentSourceFileItems.Add(FileItem.GetItemByPath(Line));
            }

            // Get the new source files
            HashSet <FileItem> SourceFileItems = new HashSet <FileItem>();

            foreach (FileReference SourceFile in SourceFiles)
            {
                SourceFileItems.Add(FileItem.GetItemByFileReference(SourceFile));
            }

            // Check if there are any differences between the sets
            foreach (FileItem CurrentSourceFileItem in CurrentSourceFileItems)
            {
                if (!SourceFileItems.Contains(CurrentSourceFileItem))
                {
                    Log.TraceLog("Compiling {0}: Removed source file ({1})", OutputAssemblyPath, CurrentSourceFileItem);
                    return(true);
                }
            }
            foreach (FileItem SourceFileItem in SourceFileItems)
            {
                if (!CurrentSourceFileItems.Contains(SourceFileItem))
                {
                    Log.TraceLog("Compiling {0}: Added source file ({1})", OutputAssemblyPath, SourceFileItem);
                    return(true);
                }
            }

            // Check if any of the timestamps are newer
            foreach (FileItem SourceFileItem in SourceFileItems)
            {
                if (SourceFileItem.LastWriteTimeUtc > OutputAssemblyInfo.LastWriteTimeUtc)
                {
                    Log.TraceLog("Compiling {0}: {1} is newer", OutputAssemblyPath, SourceFileItem);
                    return(true);
                }
            }

            return(false);
        }
Example #11
0
        /// <summary>
        /// Read a receipt from disk.
        /// </summary>
        /// <param name="Location">Filename to read from</param>
        /// <param name="EngineDir">Engine directory for expanded variables</param>
        public static TargetReceipt Read(FileReference Location, DirectoryReference EngineDir)
        {
            JsonObject RawObject = JsonObject.Read(Location);

            // Read the initial fields
            string                    TargetName    = RawObject.GetStringField("TargetName");
            TargetType                TargetType    = RawObject.GetEnumField <TargetType>("TargetType");
            UnrealTargetPlatform      Platform      = UnrealTargetPlatform.Parse(RawObject.GetStringField("Platform"));
            UnrealTargetConfiguration Configuration = RawObject.GetEnumField <UnrealTargetConfiguration>("Configuration");

            // Try to read the build version
            BuildVersion Version;

            if (!BuildVersion.TryParse(RawObject.GetObjectField("Version"), out Version))
            {
                throw new JsonParseException("Invalid 'Version' field");
            }

            // Read the project path
            FileReference ProjectFile;

            string RelativeProjectFile;

            if (RawObject.TryGetStringField("Project", out RelativeProjectFile))
            {
                ProjectFile = FileReference.Combine(Location.Directory, RelativeProjectFile);
            }
            else
            {
                ProjectFile = null;
            }

            // Create the receipt
            TargetReceipt Receipt = new TargetReceipt(ProjectFile, TargetName, TargetType, Platform, Configuration, Version);

            // Get the project directory
            DirectoryReference ProjectDir = Receipt.ProjectDir;

            // Read the launch executable
            string Launch;

            if (RawObject.TryGetStringField("Launch", out Launch))
            {
                Receipt.Launch = ExpandPathVariables(Launch, EngineDir, ProjectDir);
            }

            // Read the build products
            JsonObject[] BuildProductObjects;
            if (RawObject.TryGetObjectArrayField("BuildProducts", out BuildProductObjects))
            {
                foreach (JsonObject BuildProductObject in BuildProductObjects)
                {
                    string           Path;
                    BuildProductType Type;
                    if (BuildProductObject.TryGetStringField("Path", out Path) && BuildProductObject.TryGetEnumField("Type", out Type))
                    {
                        FileReference File = ExpandPathVariables(Path, EngineDir, ProjectDir);

                        string Module;
                        BuildProductObject.TryGetStringField("Module", out Module);

                        Receipt.AddBuildProduct(File, Type);
                    }
                }
            }

            // Read the runtime dependencies
            JsonObject[] RuntimeDependencyObjects;
            if (RawObject.TryGetObjectArrayField("RuntimeDependencies", out RuntimeDependencyObjects))
            {
                foreach (JsonObject RuntimeDependencyObject in RuntimeDependencyObjects)
                {
                    string Path;
                    if (RuntimeDependencyObject.TryGetStringField("Path", out Path))
                    {
                        FileReference File = ExpandPathVariables(Path, EngineDir, ProjectDir);

                        StagedFileType Type;
                        if (!RuntimeDependencyObject.TryGetEnumField("Type", out Type))
                        {
                            // Previous format included an optional IgnoreIfMissing flag, which was only used for debug files. We can explicitly reference them as DebugNonUFS files now.
                            bool bIgnoreIfMissing;
                            if (RuntimeDependencyObject.TryGetBoolField("IgnoreIfMissing", out bIgnoreIfMissing))
                            {
                                bIgnoreIfMissing = false;
                            }
                            Type = bIgnoreIfMissing? StagedFileType.DebugNonUFS : StagedFileType.NonUFS;
                        }

                        Receipt.RuntimeDependencies.Add(File, Type);
                    }
                }
            }

            // Read the additional properties
            JsonObject[] AdditionalPropertyObjects;
            if (RawObject.TryGetObjectArrayField("AdditionalProperties", out AdditionalPropertyObjects))
            {
                foreach (JsonObject AdditionalPropertyObject in AdditionalPropertyObjects)
                {
                    string Name;
                    if (AdditionalPropertyObject.TryGetStringField("Name", out Name))
                    {
                        string Value;
                        if (AdditionalPropertyObject.TryGetStringField("Value", out Value))
                        {
                            Receipt.AdditionalProperties.Add(new ReceiptProperty(Name, Value));
                        }
                    }
                }
            }

            return(Receipt);
        }
Example #12
0
        /// <summary>
        /// Read a receipt from disk.
        /// </summary>
        /// <param name="FileName">Filename to read from</param>
        public static TargetReceipt Read(string FileName)
        {
            JsonObject RawObject = JsonObject.Read(FileName);

            // Read the initial fields
            string TargetName = RawObject.GetStringField("TargetName");
            UnrealTargetPlatform      Platform      = RawObject.GetEnumField <UnrealTargetPlatform>("Platform");
            UnrealTargetConfiguration Configuration = RawObject.GetEnumField <UnrealTargetConfiguration>("Configuration");
            string BuildId = RawObject.GetStringField("BuildId");

            // Try to read the build version
            BuildVersion Version;

            if (!BuildVersion.TryParse(RawObject.GetObjectField("Version"), out Version))
            {
                throw new JsonParseException("Invalid 'Version' field");
            }

            // Create the receipt
            TargetReceipt Receipt = new TargetReceipt(TargetName, Platform, Configuration, BuildId, Version);

            // Read the build products
            JsonObject[] BuildProductObjects;
            if (RawObject.TryGetObjectArrayField("BuildProducts", out BuildProductObjects))
            {
                foreach (JsonObject BuildProductObject in BuildProductObjects)
                {
                    string           Path;
                    BuildProductType Type;
                    if (BuildProductObject.TryGetStringField("Path", out Path) && BuildProductObject.TryGetEnumField("Type", out Type))
                    {
                        string Module;
                        BuildProductObject.TryGetStringField("Module", out Module);

                        BuildProduct NewBuildProduct = Receipt.AddBuildProduct(Path, Type);

                        bool IsPrecompiled;
                        if (BuildProductObject.TryGetBoolField("IsPrecompiled", out IsPrecompiled))
                        {
                            NewBuildProduct.IsPrecompiled = IsPrecompiled;
                        }
                    }
                }
            }

            // Read the runtime dependencies
            JsonObject[] RuntimeDependencyObjects;
            if (RawObject.TryGetObjectArrayField("RuntimeDependencies", out RuntimeDependencyObjects))
            {
                foreach (JsonObject RuntimeDependencyObject in RuntimeDependencyObjects)
                {
                    string Path;
                    if (RuntimeDependencyObject.TryGetStringField("Path", out Path))
                    {
                        StagedFileType Type;
                        if (!RuntimeDependencyObject.TryGetEnumField("Type", out Type))
                        {
                            // Previous format included an optional IgnoreIfMissing flag, which was only used for debug files. We can explicitly reference them as DebugNonUFS files now.
                            bool bIgnoreIfMissing;
                            if (RuntimeDependencyObject.TryGetBoolField("IgnoreIfMissing", out bIgnoreIfMissing))
                            {
                                bIgnoreIfMissing = false;
                            }
                            Type = bIgnoreIfMissing? StagedFileType.DebugNonUFS : StagedFileType.NonUFS;
                        }
                        Receipt.RuntimeDependencies.Add(Path, Type);
                    }
                }
            }

            // Read the additional properties
            JsonObject[] AdditionalPropertyObjects;
            if (RawObject.TryGetObjectArrayField("AdditionalProperties", out AdditionalPropertyObjects))
            {
                foreach (JsonObject AdditionalPropertyObject in AdditionalPropertyObjects)
                {
                    string Name;
                    if (AdditionalPropertyObject.TryGetStringField("Name", out Name))
                    {
                        string Value;
                        if (AdditionalPropertyObject.TryGetStringField("Value", out Value))
                        {
                            Receipt.AdditionalProperties.Add(new ReceiptProperty(Name, Value));
                        }
                    }
                }
            }

            // Read the precompiled dependencies
            string[] PrecompiledBuildDependencies;
            if (RawObject.TryGetStringArrayField("PrecompiledBuildDependencies", out PrecompiledBuildDependencies))
            {
                Receipt.PrecompiledBuildDependencies.UnionWith(PrecompiledBuildDependencies);
            }

            // Read the precompiled dependencies
            string[] PrecompiledRuntimeDependencies;
            if (RawObject.TryGetStringArrayField("PrecompiledRuntimeDependencies", out PrecompiledRuntimeDependencies))
            {
                Receipt.PrecompiledRuntimeDependencies.UnionWith(PrecompiledRuntimeDependencies);
            }

            return(Receipt);
        }
        /// <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.Read(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));
                }

                string[] Dirs;
                Descriptor.AdditionalPluginDirectories = new List <DirectoryReference>();
                // Read the additional plugin directories
                if (RawObject.TryGetStringArrayField("AdditionalPluginDirectories", out Dirs))
                {
                    for (int Index = 0; Index < Dirs.Length; Index++)
                    {
                        if (Path.IsPathRooted(Dirs[Index]))
                        {
                            // Absolute path so create in place
                            Descriptor.AdditionalPluginDirectories.Add(new DirectoryReference(Dirs[Index]));
                            Log.TraceVerbose("Project ({0}) : Added additional absolute plugin directory ({1})", FileName, Dirs[Index]);
                        }
                        else
                        {
                            // This path is relative to the project path so build that out
                            string RelativePath = Path.Combine(Path.GetDirectoryName(FileName), Dirs[Index]);
                            Descriptor.AdditionalPluginDirectories.Add(new DirectoryReference(RelativePath));
                            Log.TraceVerbose("Project ({0}) : Added additional relative plugin directory ({1})", FileName, Dirs[Index]);
                        }
                    }
                }

                // Read the target platforms
                RawObject.TryGetStringArrayField("TargetPlatforms", out Descriptor.TargetPlatforms);

                // Get the sample name hash
                RawObject.TryGetUnsignedIntegerField("EpicSampleNameHash", out Descriptor.EpicSampleNameHash);

                // Read the pre and post-build steps
                CustomBuildSteps.TryRead(RawObject, "PreBuildSteps", out Descriptor.PreBuildSteps);
                CustomBuildSteps.TryRead(RawObject, "PostBuildSteps", out Descriptor.PostBuildSteps);

                return(Descriptor);
            }
            catch (JsonParseException ParseException)
            {
                throw new JsonParseException("{0} (in {1})", ParseException.Message, FileName);
            }
        }
Example #14
0
        /// <summary>
        /// Read a receipt from disk.
        /// </summary>
        /// <param name="FileName">Filename to read from</param>
        public static TargetReceipt Read(string FileName)
        {
            JsonObject RawObject = JsonObject.Read(FileName);

            // Read the initial fields
            string TargetName = RawObject.GetStringField("TargetName");
            UnrealTargetPlatform      Platform      = RawObject.GetEnumField <UnrealTargetPlatform>("Platform");
            UnrealTargetConfiguration Configuration = RawObject.GetEnumField <UnrealTargetConfiguration>("Configuration");
            string BuildId = RawObject.GetStringField("BuildId");

            // Try to read the build version
            BuildVersion Version;

            if (!BuildVersion.TryParse(RawObject.GetObjectField("Version"), out Version))
            {
                throw new JsonParseException("Invalid 'Version' field");
            }

            // Create the receipt
            TargetReceipt Receipt = new TargetReceipt(TargetName, Platform, Configuration, BuildId, Version);

            // Read the build products
            JsonObject[] BuildProductObjects;
            if (RawObject.TryGetObjectArrayField("BuildProducts", out BuildProductObjects))
            {
                foreach (JsonObject BuildProductObject in BuildProductObjects)
                {
                    string           Path;
                    BuildProductType Type;
                    if (BuildProductObject.TryGetStringField("Path", out Path) && BuildProductObject.TryGetEnumField("Type", out Type))
                    {
                        string Module;
                        BuildProductObject.TryGetStringField("Module", out Module);

                        BuildProduct NewBuildProduct = Receipt.AddBuildProduct(Path, Type);

                        bool IsPrecompiled;
                        if (BuildProductObject.TryGetBoolField("IsPrecompiled", out IsPrecompiled))
                        {
                            NewBuildProduct.IsPrecompiled = IsPrecompiled;
                        }
                    }
                }
            }

            // Read the runtime dependencies
            JsonObject[] RuntimeDependencyObjects;
            if (RawObject.TryGetObjectArrayField("RuntimeDependencies", out RuntimeDependencyObjects))
            {
                foreach (JsonObject RuntimeDependencyObject in RuntimeDependencyObjects)
                {
                    string Path;
                    if (RuntimeDependencyObject.TryGetStringField("Path", out Path))
                    {
                        string StagePath;
                        if (!RuntimeDependencyObject.TryGetStringField("StagePath", out StagePath))
                        {
                            StagePath = null;
                        }
                        bool bIgnoreIfMissing;
                        if (!RuntimeDependencyObject.TryGetBoolField("IgnoreIfMissing", out bIgnoreIfMissing))
                        {
                            bIgnoreIfMissing = false;
                        }
                        Receipt.AddRuntimeDependency(Path, StagePath, bIgnoreIfMissing);
                    }
                }
            }

            // Read the additional properties
            JsonObject[] AdditionalPropertyObjects;
            if (RawObject.TryGetObjectArrayField("AdditionalProperties", out AdditionalPropertyObjects))
            {
                foreach (JsonObject AdditionalPropertyObject in AdditionalPropertyObjects)
                {
                    string Name;
                    if (AdditionalPropertyObject.TryGetStringField("Name", out Name))
                    {
                        string Value;
                        if (AdditionalPropertyObject.TryGetStringField("Value", out Value))
                        {
                            Receipt.AdditionalProperties.Add(new ReceiptProperty(Name, Value));
                        }
                    }
                }
            }

            return(Receipt);
        }