protected string[] GetSolutionContents(string slnPath, string projName, string projPath, Guid projectGuid) { string relativeProjPath = NormalizePath(FPaths.MakePathRelativeTo(projPath, slnPath)); Guid projectTypeGuid = new Guid(@"FAE04EC0-301F-11D3-BF4B-00C04F79EFBC");// C# project type guid Guid solutionGuid = Guid.NewGuid(); return(new string[] { @"Microsoft Visual Studio Solution File, Format Version 12.00", @"# Visual Studio 15", @"VisualStudioVersion = 15.0.28010.2041", @"MinimumVisualStudioVersion = 10.0.40219.1", @"Project(""{" + GuidToString(projectTypeGuid) + @"}"") = """ + projName + @""", """ + relativeProjPath + @""", ""{" + GuidToString(projectGuid) + @"}""", @"EndProject", @"Global", @" GlobalSection(SolutionConfigurationPlatforms) = preSolution", @" Debug|Any CPU = Debug|Any CPU", @" EndGlobalSection", @" GlobalSection(ProjectConfigurationPlatforms) = postSolution", @" {"+ GuidToString(projectGuid) + @"}.Debug|Any CPU.ActiveCfg = Debug|Any CPU", @" {"+ GuidToString(projectGuid) + @"}.Debug|Any CPU.Build.0 = Debug|Any CPU", @" EndGlobalSection", @" GlobalSection(SolutionProperties) = preSolution", @" HideSolutionNode = FALSE", @" EndGlobalSection", @" GlobalSection(ExtensibilityGlobals) = postSolution", @" SolutionGuid = {"+ GuidToString(solutionGuid) + @"}", @" EndGlobalSection", @"EndGlobal" }); }
public static UnrealModuleType GetModuleType(string modulePath) { if (File.Exists(modulePath)) { string moduleDir = FPaths.GetPath(modulePath); string subDir; if (FPaths.DirectoryExists(moduleDir)) { if (FPaths.IsSameOrSubDirectory(FPaths.EnginePluginsDir, moduleDir)) { return(UnrealModuleType.EnginePlugin); } else if (FPaths.IsSameOrSubDirectory(FPaths.Combine(FPaths.EngineDir, "Binaries"), moduleDir)) { return(UnrealModuleType.Engine); } else if (FPaths.IsSameOrSubDirectory(FPaths.ProjectPluginsDir, moduleDir)) { return(UnrealModuleType.GamePlugin); } else if (FPaths.IsSameOrSubDirectory(FPaths.ProjectDir, moduleDir, out subDir) && string.IsNullOrEmpty(subDir)) { // Game module path is being treated as the .uproject path return(UnrealModuleType.Game); } } } return(UnrealModuleType.Unknown); }
private void AssetLog(bool clear, bool newline, string log, params object[] args) { string file = FPaths.Combine(Settings.GetManagedIntermediateDir(), "AssetLog.txt"); if (Settings.LogAssetLoading) { try { if (clear && File.Exists(file)) { File.Delete(file); } } catch { } try { File.AppendAllText(file, string.Format(log, args) + (newline ? Environment.NewLine : string.Empty)); } catch { } } }
/// <summary> /// Returns /USharp/Binaries/ /// </summary> public string GetBinDir() { // This gives "/Binaries/XXXX/" where XXXX is the platform (Win32, Win64, Android, etc) string path = FPaths.GetPath(FModuleManager.Get().GetModuleFilename(new FName(ModuleName))); // Move this up to "/Binaries/" return(Path.Combine(path, "../")); }
private void UpdateSolutionWithNewProjectFile(string slnPath, string projPath, string projectName, Guid projectGUID, string[] solutionContent, bool bProjectRefExists) { //Don't Update If Solution Doesn't Have Content if (solutionContent.Length <= 0) { return; } List <string> newSlnContent = solutionContent.ToList(); Guid projectTypeGuid = new Guid(@"FAE04EC0-301F-11D3-BF4B-00C04F79EFBC");// C# project type guid string relativeProjPath = NormalizePath(FPaths.MakePathRelativeTo(projPath, slnPath)); string projRefInclude = @"Project(""{" + GuidToString(projectTypeGuid) + @"}"") = """ + projectName + @""", """ + relativeProjPath + @""", ""{" + GuidToString(projectGUID) + @"}"""; int endProjectIndex = -1; int endGlobalSectionIndex = -1; int projRefIncludeIndex = -1; if (bProjectRefExists) { //Update SlnContent With New Content With All Proj Refs Removed newSlnContent = ObtainSolutionWithAllOldProjRefsRemoved(newSlnContent, projectName, projectGUID); } for (int i = 0; i < newSlnContent.Count; i++) { //Update Indexes For Solution Content if (newSlnContent[i].Contains("EndProject")) { endProjectIndex = i; } else if (newSlnContent[i].Contains("EndGlobalSection")) { endGlobalSectionIndex = i; } else if (newSlnContent[i].Contains(projRefInclude)) { projRefIncludeIndex = i; } } //If EndProject and EndGlobalSection Sections Exist In Solution //But Project Ref To Include Hasn't Been Added Yet if (endProjectIndex != -1 && endGlobalSectionIndex != -1 && projRefIncludeIndex == -1) { string[] endProjectContent = new string[] { projRefInclude, @"EndProject" }; newSlnContent.InsertRange(endProjectIndex + 1, endProjectContent); //Update Solution File File.WriteAllLines(slnPath, newSlnContent.ToArray()); } }
private bool ValidateOutputPath(string path) { if (FPaths.IsFileInDirectoryOrSubDirectory(path, Settings.GetManagedDir())) { return(true); } if (FPaths.IsFileInDirectoryOrSubDirectory(path, Settings.GetManagedModulesDir())) { return(true); } return(false); }
public static UnrealModuleType GetModuleType(string moduleName, string modulePath, IPlugin[] plugins) { if (File.Exists(modulePath)) { string moduleDir = FPaths.GetPath(modulePath); if (FPaths.DirectoryExists(moduleDir)) { if (FPaths.IsSameOrSubDirectory(FPaths.EnginePluginsDir, moduleDir)) { return(UnrealModuleType.EnginePlugin); } else if (FPaths.IsSameOrSubDirectory(FPaths.Combine(FPaths.EngineDir, "Binaries"), moduleDir)) { return(UnrealModuleType.Engine); } else if (FPaths.IsSameOrSubDirectory(FPaths.ProjectPluginsDir, moduleDir)) { return(UnrealModuleType.GamePlugin); } else { foreach (IPlugin plugin in plugins) { if (plugin.Name == moduleName) { switch (plugin.PluginType) { case EPluginType.Engine: case EPluginType.Enterprise: case EPluginType.External: return(UnrealModuleType.EnginePlugin); case EPluginType.Mod: case EPluginType.Project: return(UnrealModuleType.GamePlugin); } } } if (FPaths.IsSameOrSubDirectory(FPaths.ProjectDir, moduleDir) && moduleName.Equals(FApp.GetProjectName(), StringComparison.OrdinalIgnoreCase)) { return(UnrealModuleType.Game); } } } } return(UnrealModuleType.Unknown); }
private List <string> LoadAssetBlacklist() { List <string> assetBlacklist = new List <string>(); string assetBlacklistFile = FPaths.Combine(Settings.GetManagedProjectSettingsDir(), "AssetBlacklist.txt"); try { if (File.Exists(assetBlacklistFile)) { assetBlacklist = File.ReadAllLines(assetBlacklistFile).ToList(); assetBlacklist.RemoveAll(x => string.IsNullOrWhiteSpace(x)); } } catch { } return(assetBlacklist); }
private void UpdateGameProjectWithGenReference(string projPath, string projectName, Guid projectGuid) { if (!File.Exists(GameProjPath)) { return; } List <string> projContent = File.ReadAllLines(GameProjPath).ToList(); string projectEndTag = "</Project>"; int projectEndIndex = -1; int projectRefIncludeIndex = -1; string relativeProjPath = NormalizePath(FPaths.MakePathRelativeTo(projPath, GameProjPath)); string projectRefInclude = @" <ProjectReference Include=" + @"""" + relativeProjPath + @"""" + ">"; for (int i = 0; i < projContent.Count; i++) { if (projContent[i].Contains(projectEndTag) && i > 1) { projectEndIndex = i; } if (projContent[i].Contains(projectRefInclude)) { projectRefIncludeIndex = i; } } //If Project End Tag Was Found And //Project Ref Doesn't Already Exist if (projectEndIndex != -1 && projectRefIncludeIndex == -1) { projContent.InsertRange(projectEndIndex, new string[] { " <ItemGroup>", projectRefInclude, " <Project>{" + GuidToString(projectGuid) + "}</Project>", " <Name>" + Path.GetFileNameWithoutExtension(relativeProjPath) + "</Name>", " </ProjectReference>", " </ItemGroup>" } ); File.WriteAllLines(GameProjPath, projContent.ToArray()); } }
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()); }
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); }
private string GetAssetCacheFile() { return(FPaths.Combine(codeGenerator.Settings.GetManagedIntermediateDir(), "AssetCache.bin")); }
public void GenerateCodeForBlueprints(AssetLoadMode loadMode, bool clearAssetCache, bool skipLevels) { BeginGenerateModules(); string projectPath = FPaths.ProjectFilePath; string projectName = FPaths.GetBaseFilename(projectPath); UnrealModuleInfo module = new UnrealModuleInfo(null, projectName, projectPath); BeginGenerateModule(module); UClass worldClass = GCHelper.Find <UClass>(Classes.UWorld); AssetCache assetCache = new AssetCache(this); if (!clearAssetCache) { assetCache.Load(); } List <string> assetBlacklist = LoadAssetBlacklist(); AssetLogClear(); AssetLogLine("Load assets {0}", DateTime.Now); bool registeredCrashHandler = false; if (Settings.CatchCrashOnAssetLoading) { FCoreDelegates.OnHandleSystemError.Bind(OnAssetLoadingCrash); registeredCrashHandler = true; } using (FARFilter filter = new FARFilter()) { filter.RecursiveClasses = true; filter.ClassNames.Add(UClass.GetClass <UBlueprint>().GetFName()); filter.ClassNames.Add(UClass.GetClass <UBlueprintGeneratedClass>().GetFName()); filter.ClassNames.Add(UClass.GetClass <UUserDefinedStruct>().GetFName()); filter.ClassNames.Add(UClass.GetClass <UUserDefinedEnum>().GetFName()); if (!skipLevels && worldClass != null) { filter.ClassNames.Add(worldClass.GetFName()); } List <FAssetData> assets = FAssetData.Load(filter); SlowTaskSetModuleCount(1); SlowTaskBeginModule("Blueprints", assets.Count); foreach (FAssetData asset in assets) { SlowTaskStep(null); string assetFileName, assetFileNameError; if (!asset.TryGetFilename(out assetFileName, out assetFileNameError)) { FMessage.Log(string.Format("FAssetData.TryGetFilename failed. ObjectPath:'{0}' reason:'{1}'", asset.ObjectPath.ToString(), assetFileNameError)); continue; } bool isEngineAsset = FPaths.IsSameOrSubDirectory(FPaths.EngineContentDir, FPaths.GetPath(assetFileName)); if (loadMode != AssetLoadMode.All) { if ((isEngineAsset && loadMode != AssetLoadMode.Engine) || (!isEngineAsset && loadMode != AssetLoadMode.Game)) { continue; } } if (!assetCache.HasAssetChanged(asset, assetFileName)) { if (Settings.LogAssetLoadingVerbose) { AssetLogLine("'{0}' unchanged", assetFileName); } continue; } // Log that we are loading this asset so we know which assets crash on load AssetLog("'{0}' - ", asset.ObjectPath.ToString()); if (assetBlacklist.Contains(asset.ObjectPath.ToString())) { AssetLogLine("blacklisted"); continue; } loadingAsset = asset.ObjectPath.ToString(); UObject obj = asset.GetAsset(); loadingAsset = null; UClass unrealClass = asset.GetClass(); if (obj == null || unrealClass == null) { AssetLogLine("null"); continue; } AssetLogLine("done"); if (unrealClass.IsChildOf <UBlueprint>()) { UBlueprint blueprint = obj as UBlueprint; if (blueprint != null) { UBlueprintGeneratedClass blueprintGeneratedClass = blueprint.GeneratedClass as UBlueprintGeneratedClass; if (blueprintGeneratedClass != null) { GenerateCodeForStruct(module, blueprintGeneratedClass); } } } else if (unrealClass.IsChildOf <UBlueprintGeneratedClass>()) { UBlueprintGeneratedClass blueprintGeneratedClass = obj as UBlueprintGeneratedClass; if (blueprintGeneratedClass != null) { GenerateCodeForStruct(module, blueprintGeneratedClass); } } else if (unrealClass.IsChildOf <UUserDefinedStruct>()) { UUserDefinedStruct unrealStruct = obj as UUserDefinedStruct; if (unrealStruct != null) { GenerateCodeForStruct(module, unrealStruct); } } else if (unrealClass.IsChildOf <UUserDefinedEnum>()) { UUserDefinedEnum unrealEnum = obj as UUserDefinedEnum; if (unrealEnum != null) { GenerateCodeForEnum(module, unrealEnum); } } else if (unrealClass.IsChildOf(worldClass)) { TArrayUnsafeRef <UObject> levels = new TArrayUnsafeRef <UObject>(Native.Native_UWorld.GetLevels(obj.Address)); foreach (UObject level in levels) { using (TArrayUnsafe <UBlueprint> levelBlueprints = new TArrayUnsafe <UBlueprint>()) { Native.Native_ULevel.GetLevelBlueprints(level.Address, levelBlueprints.Address); foreach (UBlueprint blueprint in levelBlueprints) { UBlueprintGeneratedClass blueprintGeneratedClass = blueprint.GeneratedClass as UBlueprintGeneratedClass; if (blueprintGeneratedClass != null) { //GenerateCodeForStruct(blueprintGeneratedClass); } } } } } } } if (registeredCrashHandler) { FCoreDelegates.OnHandleSystemError.Unbind(OnAssetLoadingCrash); } assetCache.Save(); EndGenerateModule(module); EndGenerateModules(); }
public bool TryGetFilename(out string fileName, out string error) { error = null; // Get the filename without the valid file extension e.g. "../../../Engine/Test/AssetName.AssetName" if (!FPackageName.TryConvertLongPackageNameToFilename(ObjectPath.ToString(), out fileName)) { error = "Couldn't find package for asset " + ObjectPath.ToString(); return(false); } // Remove the dummy extension "AssetName.AssetName" -> "AssetName" int LastDot = fileName.LastIndexOf('.'); if (LastDot <= 0) { error = "Bad filename: " + fileName; return(false); } fileName = fileName.Substring(0, LastDot); // Get the filename with the correct file extension ("WithoutExtension" means the input doesn't have an extension) if (!FPackageName.FindPackageFileWithoutExtension(fileName, out fileName) || !FPaths.FileExists(fileName)) { error = "Couldn't find asset: " + fileName; return(false); } return(true); }
public override bool AddSourceFile(string slnPath, string projPath, string sourceFilePath, string code) { if (!File.Exists(slnPath) || !File.Exists(projPath)) { return(false); } CreateFileDirectoryIfNotExists(sourceFilePath); File.WriteAllText(sourceFilePath, code); lock (this) { try { if (sourceFileContentList.Count <= 0) { sourceFileContentList = File.ReadAllLines(projPath).ToList(); } string _itemGroupTag = "<ItemGroup>"; string _projectEndTag = "</Project>"; int _itemGroupIndex = -1; int _insertCodeIndex = -1; int _projectEndIndex = -1; string _insertCode = " <Compile Include=\"" + NormalizePath(FPaths.MakePathRelativeTo(sourceFilePath, projPath)) + "\" />"; for (int i = 0; i < sourceFileContentList.Count; i++) { if (sourceFileContentList[i].Contains(_itemGroupTag)) { _itemGroupIndex = i; } if (sourceFileContentList[i].Contains(_insertCode)) { _insertCodeIndex = i; } if (sourceFileContentList[i].Contains(_projectEndTag) && i > 1) { _projectEndIndex = i; } if (_itemGroupIndex != -1 && _insertCodeIndex != -1) { break; } } //If Item Group Tag Wasn't Found, The Inserted Code Wasn't Already Created //And The Project End Tag Exist and Isn't the Beginning Tag //Insert the Item Group Tags Before The Project End Tag if (_itemGroupIndex == -1 && _insertCodeIndex == -1 && _projectEndIndex != -1 && _projectEndTag.Contains("/") && _projectEndIndex > 1) { sourceFileContentList.InsertRange(_projectEndIndex, new string[] { " <ItemGroup>", "", " </ItemGroup>" } ); //Check Again For Item Group Tag for (int i = 0; i < sourceFileContentList.Count; i++) { if (sourceFileContentList[i].Contains(_itemGroupTag)) { _itemGroupIndex = i; break; } } } //Only Insert if Group Tag Exists and //File Path Include Doesn't Exists if (_itemGroupIndex != -1 && _insertCodeIndex == -1) { sourceFileContentList.Insert(_itemGroupIndex + 1, _insertCode); } }catch (Exception e) { Log(ELogVerbosity.Error, e.Message, e); return(false); } } return(true); }