Beispiel #1
0
        private static void WriteMetaData(VSProject project)
        {
            string metaUrl = Path.Combine(project.metaFolderUrl, "projects.meta");

            NjoxNode metaRoot = new NjoxNode("meta");
            NjoxNode cache    = new NjoxNode("cached_guids");

            foreach (var pair in cachedGuids)
            {
                cache.AddChild(new NjoxNode(pair.Key.Replace(" ", "_%20_"), pair.Value.ToString()));
            }

            metaRoot.AddChild(cache);
            NjoxStatics.TryWriteObjectToFile(metaUrl, metaRoot);
        }
Beispiel #2
0
        private static void LoadMetaData(VSProject project)
        {
            string metaUrl = Path.Combine(project.metaFolderUrl, "projects.meta");

            cachedGuids = new Dictionary <string, Guid>();

            NjoxNode metaRoot;

            if (NjoxStatics.TryReadObjectFromFile(metaUrl, out metaRoot))
            {
                NjoxNode cachedGuidNode;
                if (metaRoot.TryGetFirstChild("cached_guids", out cachedGuidNode))
                {
                    foreach (NjoxNode node in cachedGuidNode.ChildNodes)
                    {
                        Guid guid;
                        if (Guid.TryParse(node.PrimaryProperty.Value, out guid))
                        {
                            cachedGuids[node.PrimaryProperty.Key.Replace("_%20_", " ")] = guid;
                        }
                    }
                }
            }
        }
Beispiel #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);
        }
Beispiel #4
0
        /// <summary>
        /// Load all modules from current data
        /// </summary>
        private bool LoadAllModules()
        {
            modules = new Dictionary <string, ModuleContainer>();
            if (!LoadModulesFromDirectory(new DirectoryInfo(modulesDirectory), modules))
            {
                return(false);
            }


            // Load any meta-data
            NjoxNode collectionMeta;
            NjoxNode moduleMeta;

            if (!NjoxStatics.TryReadObjectFromFile(collectionMetaFileUrl, out collectionMeta))
            {
                // Create new empty meta data
                collectionMeta = new NjoxNode("meta");
                moduleMeta     = new NjoxNode("modules");
                collectionMeta.AddChild(moduleMeta);
            }
            else
            {
                // Create new modules object (Can't be found)
                if (!collectionMeta.TryGetFirstChild("modules", out moduleMeta))
                {
                    moduleMeta = new NjoxNode("modules");
                    collectionMeta.AddChild(moduleMeta);
                }
            }

            // Read in module info
            foreach (var pair in modules)
            {
                ModuleContainer module = pair.Value;
                module.collection = this;

                // Read in any stored info
                NjoxNode moduleInfo;

                if (moduleMeta.TryGetFirstChild(module.internalName, out moduleInfo))
                {
                    module.ReadMetaData(moduleInfo);
                }
                else
                {
                    moduleInfo = new NjoxNode(module.internalName);
                    moduleMeta.AddChild(moduleInfo);
                }

                // Update any changed info
                module.WriteMetaData(moduleInfo);
            }


            if (!NjoxStatics.TryWriteObjectToFile(collectionMetaFileUrl, collectionMeta))
            {
                Logger.LogWarning("Failed to write collection meta to file '" + collectionMetaFileUrl + "'");
            }

            return(true);
        }
Beispiel #5
0
        /// <summary>
        /// Attempt to load
        /// </summary>
        /// <param name="url">The url to the module.aethermod file</param>
        /// <param name="container">The container which will be created</param>
        /// <returns>True if the container is successfully loaded</returns>
        public static bool TryLoadFromFile(string url, out ModuleContainer container)
        {
            container         = new ModuleContainer();
            container.fileUrl = Path.GetFullPath(url);


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

            // Load file info from aetherproj njox
            NjoxNode rootNode;

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


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

            float version;

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


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

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

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

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


            // Load recipe assembly for this module
            {
                // Load recipe assembly
                Assembly recipeAssembly;
                if (!ModuleRecipe.TryLoadAssembly(Path.Combine(mainDirectory, container.internalName + "ModuleRecipe.cs"), out recipeAssembly))
                {
                    Logger.LogError("Failed to compile ModuleRecipe for '" + container.fileUrl + "'");
                    return(false);
                }

                // Check required class exists
                container.recipeType = recipeAssembly.GetType(container.internalName + "ModuleRecipe");
                if (container.recipeType == null)
                {
                    Logger.LogError("ModuleRecipe is missing " + container.internalName + "ModuleRecipe class for '" + container.fileUrl + "'");
                    return(false);
                }
                if (!container.recipeType.IsSubclassOf(typeof(ModuleRecipe)))
                {
                    Logger.LogError("ModuleRecipe " + container.internalName + "ModuleRecipe class needs to extend from ModuleRecipe for '" + container.fileUrl + "'");
                    return(false);
                }
            }


            Logger.Log("ModuleContainer successfully loaded '" + container.fileUrl, 5);
            return(true);
        }