예제 #1
0
        public void AddCollection(ModuleCollection collection)
        {
            foreach (ModuleContainer container in collection.modules.Values)
            {
                ModuleRecipe recipe = container.GetRecipe(target);
                if (recipe == null)
                {
                    throw new Exception("ModuleRecipe is null");
                }

                if (moduleRecipes.ContainsKey(container.internalUrl))
                {
                    throw new Exception("Multiple module entries for " + container.internalUrl);
                }

                moduleRecipes[container.internalUrl] = recipe;
            }
        }
예제 #2
0
        public static ModuleCollection[] LoadRequestedCollections()
        {
            List <ModuleCollection> collections = new List <ModuleCollection>();

            string[] targetFiles = LaunchArgs.GetTargetFiles();
            Logger.Log("Attempting to load " + targetFiles.Length + " collections", 3);

            foreach (string str in targetFiles)
            {
                ModuleCollection collection;

                if (!ModuleCollection.TryLoadFromURL(str, out collection))
                {
                    Logger.LogWarning("Failed to load collection '" + str + "'; skipping");
                    continue;
                }
                else
                {
                    collections.Add(collection);
                }
            }

            return(collections.ToArray());
        }
예제 #3
0
        /// <summary>
        /// Load module collection info from path
        /// </summary>
        /// <param name="url">The URL of the collection file to load</param>
        /// <returns></returns>
        public static bool TryLoadFromURL(string url, out ModuleCollection collection)
        {
            collection         = new ModuleCollection();
            collection.fileUrl = Path.GetFullPath(url);


            // Check file exists
            if (!File.Exists(collection.fileUrl))
            {
                Logger.LogError("Unable to load ModuleCollection from path (Unable to locate): '" + collection.fileUrl + "'");
                return(false);
            }

            // Load file info from aetherproj njox
            NjoxNode rootNode;

            if (!NjoxStatics.TryParseObject(File.ReadAllText(collection.fileUrl), out rootNode))
            {
                Logger.LogError("Unable to load ModuleCollection from path (Unable to parse njox): '" + collection.fileUrl + "'");
                return(false);
            }
            string mainDirectory = new FileInfo(collection.fileUrl).Directory.FullName;


            if (rootNode.Properties.Length != 2)
            {
                Logger.LogError("Unable to load ModuleCollection from path (Expected root node Project <version_number>): '" + collection.fileUrl + "'");
                return(false);
            }
            if (rootNode.PrimaryProperty.Key != "Project")
            {
                Logger.LogError("Unable to load ModuleCollection from path (Expected root node Project <version_number>): '" + collection.fileUrl + "'");
                return(false);
            }

            float version;

            if (!rootNode.Properties[1].GetKeyAs <float>(out version) || version != 1.0f)
            {
                Logger.LogError("Unable to load ModuleCollection from path (Expected Project version to be 1.0): '" + collection.fileUrl + "'");
                return(false);
            }


            // Read collection data
            if (!rootNode.HasChild("name"))
            {
                Logger.LogError("Unable to load ModuleCollection from path (Expected name node): '" + collection.fileUrl + "'");
                return(false);
            }

            // Read internal and display name
            {
                var nameNode = rootNode.GetFirstChild("name");
                if (!nameNode.HasProperty("internal"))
                {
                    Logger.LogError("ModuleCollection node 'name' is missing required property 'internal': '" + collection.fileUrl + "'");
                    return(false);
                }

                collection.internalName = nameNode.GetFirstProperty("internal").Value;
                collection.displayName  = collection.internalName;

                if (nameNode.HasProperty("display"))
                {
                    collection.displayName = nameNode.GetFirstProperty("display").Value;
                }
            }


            // Load build directories
            {
                NjoxNode modulesDir;
                if (!rootNode.TryGetFirstChild("modules_directory", out modulesDir))
                {
                    Logger.LogError("ModuleCollection missing required node 'modules_directory': '" + collection.fileUrl + "'");
                    return(false);
                }
                collection.modulesDirectory = Path.GetFullPath(Path.Combine(mainDirectory, modulesDir.PrimaryProperty.Value));

                NjoxNode metaDir;
                if (!rootNode.TryGetFirstChild("meta_directory", out metaDir))
                {
                    Logger.LogError("ModuleCollection missing required node 'meta_directory': '" + collection.fileUrl + "'");
                    return(false);
                }
                collection.metaDirectory = Path.GetFullPath(Path.Combine(mainDirectory, metaDir.PrimaryProperty.Value));

                NjoxNode binDir;
                if (!rootNode.TryGetFirstChild("output_directory", out binDir))
                {
                    Logger.LogError("ModuleCollection missing required node 'output_directory': '" + collection.fileUrl + "'");
                    return(false);
                }
                collection.outputDirectory = Path.GetFullPath(Path.Combine(mainDirectory, binDir.PrimaryProperty.Value));
            }


            if (!collection.LoadAllModules())
            {
                Logger.LogError("ModuleCollection failed to load all modules '" + collection.fileUrl + "'");
                return(false);
            }

            Logger.Log("ModuleCollection successfully loaded '" + collection.fileUrl + "' with " + collection.modules.Count + " modules", 4);
            return(true);
        }