public CachedNamespace(string namespaceName, string moduleName, UnrealModuleType moduleType, UnrealModuleType moduleAssetType)
 {
     Namespace       = namespaceName;
     ModuleName      = moduleName;
     ModuleType      = moduleType;
     ModuleAssetType = moduleAssetType;
 }
 public UnrealModuleInfo(UPackage package, string name, string path)
     : this(package, name, path, UnrealModuleType.Unknown)
 {
     IPlugin[] plugins = IPluginManager.Instance.GetDiscoveredPlugins();
     Type = GetModuleType(name, path, plugins);
     IPlugin.Dispose(plugins);
 }
 public UnrealModuleInfo(UPackage package, string name, string path, UnrealModuleType type)
 {
     Package = package;
     Name    = name;
     Path    = path;
     Type    = type;
 }
Beispiel #4
0
        protected string GetRootFolderName(string path, string root, UnrealModuleType moduleType, UnrealModuleType moduleAssetType)
        {
            switch (moduleType)
            {
            case UnrealModuleType.Game:
                switch (moduleAssetType)
                {
                case UnrealModuleType.Game: return("Game");

                case UnrealModuleType.Engine: return(Path.Combine("EngineAssets"));

                case UnrealModuleType.EnginePlugin: return(Path.Combine("EnginePluginAssets", root));

                case UnrealModuleType.GamePlugin: return(Path.Combine("GamePluginAssets", root));
                }
                return("Game");

            case UnrealModuleType.Engine:
                return("Engine");

            case UnrealModuleType.EnginePlugin:
                if (Settings.ModulesLocation == CodeGeneratorSettings.ManagedModulesLocation.ModulesFolder)
                {
                    return("Plugins");
                }
                else
                {
                    return("EnginePlugins");
                }

            case UnrealModuleType.GamePlugin:
                return("GamePlugins");
            }
            return(null);
        }
Beispiel #5
0
 private void OnCodeGenerated(UnrealModuleInfo module, UnrealModuleType moduleAssetType, string typeName, string path, CSharpTextBuilder code)
 {
     if (codeManager != null)
     {
         codeManager.OnCodeGenerated(module, moduleAssetType, typeName, path, code.ToString());
     }
 }
Beispiel #6
0
 public UnrealModuleInfo(UPackage package, string name, string path)
 {
     Package = package;
     Name    = name;
     Path    = path;
     Type    = GetModuleType(path);
 }
 private string GetUnrealModuleTypeString(UnrealModuleType moduleType, UnrealModuleType assetModuleType)
 {
     if (assetModuleType != UnrealModuleType.Unknown)
     {
         return(assetModuleType.ToString());
     }
     return(moduleType.ToString());
 }
 private string GetModuleNamespace(UnrealModuleType moduleType, string moduleName)
 {
     // This should only be called for Engine/EnginePlugin modules (used for non-UObject types like TArray, TSubclassOf)
     if (moduleType != UnrealModuleType.Engine && moduleType != UnrealModuleType.EnginePlugin)
     {
         return(null);
     }
     return(GetModuleNamespace(moduleType, moduleName, UnrealModuleType.Unknown, false, string.Empty));
 }
Beispiel #9
0
        private bool EmulateGameFolderStructure(UnrealModuleType moduleAssetType)
        {
            switch (moduleAssetType)
            {
            case UnrealModuleType.Game: return(Settings.FolderEmulation.Game);

            case UnrealModuleType.GamePlugin: return(Settings.FolderEmulation.GamePluginAssets);

            case UnrealModuleType.Engine: return(Settings.FolderEmulation.EngineAssets);

            case UnrealModuleType.EnginePlugin: return(Settings.FolderEmulation.EnginePluginAssets);

            default: return(false);
            }
        }
Beispiel #10
0
        private string GetModuleName(UField field, out UnrealModuleType moduleType, out UnrealModuleType moduleAssetType)
        {
            moduleType      = UnrealModuleType.Unknown;
            moduleAssetType = UnrealModuleType.Unknown;
            UPackage package = field.GetOutermost();

            if (package != null)
            {
                CachedNamespace cachedNamespace;
                if (!namespaceCache.TryGetValue(package, out cachedNamespace))
                {
                    GetModuleNamespace(field);
                    namespaceCache.TryGetValue(package, out cachedNamespace);
                }

                if (cachedNamespace != null)
                {
                    moduleType      = cachedNamespace.ModuleType;
                    moduleAssetType = cachedNamespace.ModuleAssetType;
                    return(cachedNamespace.ModuleName);
                }
            }
            return(null);
        }
Beispiel #11
0
        private string GetModuleNamespace(UnrealModuleType moduleType, string moduleName, UnrealModuleType moduleAssetType, bool allowFoldersAsNamespace, string path)
        {
            string namespaceName = null;

            switch (moduleType)
            {
            case UnrealModuleType.Game:
                switch (moduleAssetType)
                {
                case UnrealModuleType.Engine:
                    namespaceName = Settings.Namespaces.EngineAsset;
                    break;

                case UnrealModuleType.GamePlugin:
                    namespaceName = Settings.Namespaces.GamePluginAsset;
                    break;

                case UnrealModuleType.EnginePlugin:
                    namespaceName = Settings.Namespaces.EnginePluginAsset;
                    break;

                default:
                    namespaceName = Settings.Namespaces.Game;
                    break;
                }
                break;

            case UnrealModuleType.GamePlugin:
                namespaceName = Settings.Namespaces.GamePlugin;
                break;

            case UnrealModuleType.Engine:
                namespaceName = Settings.Namespaces.Engine;
                if (moduleName == "CoreUObject")
                {
                    // Allow CoreUObject to be redirected to a common namespace name (UnrealEngine.Runtime)
                    namespaceName = GetEngineObjectNamespace();
                }
                break;

            case UnrealModuleType.EnginePlugin:
                namespaceName = Settings.Namespaces.EnginePlugin;
                break;

            default:
                return(namespaceName);
            }

            if (string.IsNullOrWhiteSpace(namespaceName))
            {
                return(null);
            }

            if (namespaceName.Contains("{Default}"))
            {
                namespaceName = namespaceName.Replace("{Default}", Settings.Namespaces.Default);
            }

            if (namespaceName.Contains("{Game}"))
            {
                string gameName = FPaths.GetBaseFilename(FPaths.ProjectFilePath);
                namespaceName = namespaceName.Replace("{Game}", gameName);
            }

            if (namespaceName.Contains("{Module}"))
            {
                namespaceName = namespaceName.Replace("{Module}", moduleName);
            }

            if (namespaceName.Contains("{Folder}"))
            {
                if (allowFoldersAsNamespace && moduleAssetType != UnrealModuleType.Unknown)
                {
                    // Get the directory of the file and remove root name "/Game/"
                    string directory  = FPackageName.GetLongPackagePath(path);
                    int    slashIndex = directory.IndexOf('/', 1);
                    if (slashIndex >= 0)
                    {
                        directory = directory.Substring(slashIndex + 1);
                    }
                    else
                    {
                        // The path is empty or only the root name
                        directory = string.Empty;
                    }

                    // Make each '/' a part of the namespace
                    string expandedNamespace = directory.Replace("/", ".");

                    namespaceName = namespaceName.Replace("{Folder}", expandedNamespace);
                }
                else
                {
                    namespaceName = namespaceName.Replace("{Folder}", string.Empty);
                }
            }

            // Remove duplicate '.' chars
            StringBuilder result = new StringBuilder(namespaceName);

            for (int i = result.Length - 1; i >= 0; --i)
            {
                if (result[i] == '.')
                {
                    if (i == 0 || result[i - 1] == '.' || i == result.Length - 1)
                    {
                        result.Remove(i, 1);
                    }
                }
            }

            return(result.ToString());
        }
Beispiel #12
0
        private string GetModuleNamespace(UField field, out UnrealModuleType moduleAssetType, bool allowFoldersAsNamespace = true)
        {
            moduleAssetType = UnrealModuleType.Unknown;
            UPackage package = field.GetOutermost();

            if (package != null)
            {
                CachedNamespace cachedNamespace;
                if (namespaceCache.TryGetValue(package, out cachedNamespace))
                {
                    moduleAssetType = cachedNamespace.ModuleAssetType;
                    return(cachedNamespace.Namespace);
                }

                UnrealModuleType moduleType = UnrealModuleType.Unknown;
                moduleAssetType = UnrealModuleType.Unknown;

                string packageFilename = package.FileName.ToString();
                if (string.IsNullOrEmpty(packageFilename.ToString()) || packageFilename == FName.None.ToString())
                {
                    packageFilename = field.GetPathName();
                }

                string moduleName = FPackageName.GetShortName(package.GetName());
                if (packageFilename.StartsWith("/Script"))
                {
                    if (!modulesByName.TryGetValue(new FName(moduleName), out moduleType))
                    {
                        moduleType = UnrealModuleType.Unknown;
                        FMessage.Log(ELogVerbosity.Error, string.Format("Failed to find module for module '{0}'", moduleName));
                    }
                }
                else if (packageFilename.StartsWith("/Game/"))
                {
                    moduleType      = UnrealModuleType.Game;
                    moduleAssetType = UnrealModuleType.Game;
                    moduleName      = FPaths.GetBaseFilename(FPaths.ProjectFilePath);// {Module} same as {Game}
                }
                else if (packageFilename.StartsWith("/Engine/"))
                {
                    moduleType      = UnrealModuleType.Game;
                    moduleAssetType = UnrealModuleType.Engine;
                    moduleName      = Settings.Namespaces.Default;
                }
                else
                {
                    string rootName = null;
                    if (packageFilename.Length > 1 && packageFilename[0] == '/')
                    {
                        int slashIndex = packageFilename.IndexOf('/', 1);
                        if (slashIndex >= 0)
                        {
                            rootName   = packageFilename.Substring(1, slashIndex - 1);
                            moduleName = rootName;// Update ModuleName for {Module}

                            if (!modulesByName.TryGetValue(new FName(rootName), out moduleAssetType))
                            {
                                moduleAssetType = UnrealModuleType.Unknown;
                            }
                        }
                    }

                    if (moduleAssetType == UnrealModuleType.Unknown)
                    {
                        FMessage.Log(ELogVerbosity.Error, string.Format("Unknown module asset type root:'{0}' path:'{1}' name:'{2}' path2:'{3}'",
                                                                        rootName, packageFilename, field.GetName(), field.GetPathName()));
                    }
                    moduleType = UnrealModuleType.Game;
                }

                if (moduleType != UnrealModuleType.Unknown)
                {
                    string namespaceName = GetModuleNamespace(moduleType, moduleName, moduleAssetType, allowFoldersAsNamespace, packageFilename);
                    namespaceCache[package] = new CachedNamespace(namespaceName, moduleName, moduleType, moduleAssetType);
                    return(namespaceName);
                }
                else
                {
                    FMessage.Log(ELogVerbosity.Error, string.Format("Unknown module type {0} {1}", packageFilename, moduleName));
                }
            }
            return(null);
        }
Beispiel #13
0
        public void OnCodeGenerated(CodeGenerator.UnrealModuleInfo module, UnrealModuleType moduleAssetType, string typeName, string path, string code)
        {
            // Note: path will be empty if using combined enums file or global delegates files
            string root, directory, moduleName, assetName, memberName;

            FPackageName.GetPathInfo(path, out root, out directory, out moduleName, out assetName, out memberName);
            //Log("path:'{0}' root:'{1}' directory:'{2}' asset:'{3}' member:'{4}'", path, root, directory, assetName, memberName);

            string rootFolderName = GetRootFolderName(path, root, module.Type, moduleAssetType);

            if (string.IsNullOrEmpty(rootFolderName) && !string.IsNullOrEmpty(path))
            {
                Log(ELogVerbosity.Error, "Unknown asset root '{0}' ModuleType:'{1}' ModuleAssetType:'{2}' Path:'{3}'",
                    root, module.Type, moduleAssetType, path);
                return;
            }

            string name = Settings.UseTypeNameAsSourceFileName || string.IsNullOrEmpty(assetName) ? typeName : assetName;

            string sourceFilePath = null;
            string projPath       = null;
            string slnPath        = null;

            switch (module.Type)
            {
            case UnrealModuleType.Game:
            {
                string relativeSourceFilePath = null;
                if (EmulateGameFolderStructure(moduleAssetType))
                {
                    relativeSourceFilePath = Path.Combine(directory, name + ".cs");
                }
                else
                {
                    relativeSourceFilePath = name + ".cs";
                }
                string baseCodeDir = Settings.GetGeneratedCodeDir(false);
                if (module.IsBlueprint)
                {
                    baseCodeDir = Path.Combine(Settings.GetManagedDir(), Settings.GetProjectName() + ".Managed", "Blueprint", "Generated");
                }
                if (moduleAssetType == UnrealModuleType.Unknown)
                {
                    // Don't use root folders for native game code wrappers as root folders don't make much sense for them
                    sourceFilePath = Path.Combine(baseCodeDir, relativeSourceFilePath);
                }
                else
                {
                    sourceFilePath = Path.Combine(baseCodeDir, rootFolderName, relativeSourceFilePath);
                }
                slnPath  = GameSlnPath;
                projPath = module.IsBlueprint ? GameProjPath : GameNativeGenerationProjPath;
            }
            break;

            case UnrealModuleType.EnginePlugin:
            case UnrealModuleType.Engine:
            {
                bool mergeAsPluginProj = false;
                bool mergeAsUnrealProj = false;
                switch (Settings.EngineProjMerge)
                {
                case CodeGeneratorSettings.ManagedEngineProjMerge.Engine:
                    if (module.Type == UnrealModuleType.Engine)
                    {
                        mergeAsUnrealProj = true;
                    }
                    break;

                case CodeGeneratorSettings.ManagedEngineProjMerge.Plugins:
                    if (module.Type == UnrealModuleType.EnginePlugin)
                    {
                        mergeAsPluginProj = true;
                    }
                    break;

                case CodeGeneratorSettings.ManagedEngineProjMerge.EngineAndPlugins:
                    if (module.Type == UnrealModuleType.EnginePlugin)
                    {
                        mergeAsPluginProj = true;
                    }
                    else
                    {
                        mergeAsUnrealProj = true;
                    }
                    break;

                case CodeGeneratorSettings.ManagedEngineProjMerge.EngineAndPluginsCombined:
                    mergeAsUnrealProj = true;
                    break;
                }
                if (mergeAsPluginProj || mergeAsUnrealProj)
                {
                    string projName = mergeAsUnrealProj ? "UnrealEngine.csproj" : "UnrealEngine.Plugins.csproj";
                    if (Settings.EngineProjMerge == CodeGeneratorSettings.ManagedEngineProjMerge.EngineAndPluginsCombined)
                    {
                        projPath = Path.Combine(Settings.GetManagedModulesDir(), projName);
                    }
                    else
                    {
                        projPath = Path.Combine(Settings.GetManagedModulesDir(), rootFolderName, projName);
                    }
                }
                else
                {
                    projPath = Path.Combine(Settings.GetManagedModulesDir(), rootFolderName, module.Name, module.Name + ".csproj");
                }

                sourceFilePath = Path.Combine(Settings.GetManagedModulesDir(), rootFolderName, module.Name, name + ".cs");

                if (Settings.ModulesLocation == CodeGeneratorSettings.ManagedModulesLocation.GameFolderCombineSln)
                {
                    slnPath = GameSlnPath;
                }
                else if (Settings.ModulesLocation == CodeGeneratorSettings.ManagedModulesLocation.GameFolderCombineSlnProj)
                {
                    slnPath  = GameSlnPath;
                    projPath = GameProjPath;
                }
                else
                {
                    slnPath = Path.Combine(Settings.GetManagedModulesDir(), "UnrealEngine.sln");
                }
            }
            break;

            case UnrealModuleType.GamePlugin:
            {
                if (moduleAssetType == UnrealModuleType.Unknown)
                {
                    // Don't use root folders for native game code wrappers as root folders don't make much sense for them
                    sourceFilePath = Path.Combine(Settings.GetGeneratedCodeDir(true), module.Name, name + ".cs");
                }
                else
                {
                    sourceFilePath = Path.Combine(Settings.GetGeneratedCodeDir(true), rootFolderName, module.Name, name + ".cs");
                }
                slnPath = GameSlnPath;

                if (Settings.GameProjMerge == CodeGeneratorSettings.ManagedGameProjMerge.GameAndPlugins)
                {
                    projPath = GameNativeGenerationProjPath;
                }
                else if (Settings.GameProjMerge == CodeGeneratorSettings.ManagedGameProjMerge.Plugins)
                {
                    projPath = GamePluginGenerationProjPath;
                }
                else
                {
                    projPath = Path.Combine(Settings.GetManagedDir(), rootFolderName, module.Name, module.Name + ".csproj");
                }
            }
            break;
            }

            if (!string.IsNullOrWhiteSpace(sourceFilePath))
            {
                sourceFilePath = Path.GetFullPath(sourceFilePath);
            }
            if (!string.IsNullOrWhiteSpace(projPath))
            {
                projPath = Path.GetFullPath(projPath);
            }
            if (!string.IsNullOrWhiteSpace(slnPath))
            {
                slnPath = Path.GetFullPath(slnPath);
            }

            if (string.IsNullOrWhiteSpace(sourceFilePath) || string.IsNullOrWhiteSpace(projPath) || string.IsNullOrWhiteSpace(slnPath))
            {
                Log(ELogVerbosity.Error, "Unknown output location for '{0}' '{1}'", typeName, path);
            }
            else if (!ValidateOutputPath(sourceFilePath) || !ValidateOutputPath(projPath) || !ValidateOutputPath(slnPath))
            {
                Log(ELogVerbosity.Error, "Invalid output path '{0}'", sourceFilePath);
            }
            else
            {
                //FMessage.Log(ELogVerbosity.Log, sourceFilePath + " | " + projPath + " | " + slnPath);

                try
                {
                    if (UpdateSolutionAndProject(slnPath, projPath))
                    {
                        if (!AddSourceFile(slnPath, projPath, sourceFilePath, code))
                        {
                            Log(ELogVerbosity.Error, "Failed to add source file '{0}'", sourceFilePath);
                        }
                    }
                    else
                    {
                        Log(ELogVerbosity.Error, "Failed to create sln/csproj '{0}' '{1}'", slnPath, projPath);
                    }
                }
                catch (Exception e)
                {
                    Log(ELogVerbosity.Error, "Exception when adding source file '{0}' {1}", sourceFilePath, e);
                }
            }
        }
 public UMetaPathAttribute(string path, string moduleName, UnrealModuleType moduleType)
 {
     Path       = path;
     ModuleName = moduleName;
     ModuleType = moduleType;
 }