using System.IO; using UnityEngine; namespace SplashEdit.EditorCode { /// /// Manages all build-related paths for the SplashEdit pipeline. /// All output goes outside Assets/ to avoid Unity import overhead. /// public static class SplashBuildPaths { /// /// The build output directory at the Unity project root. /// Contains exported splashpacks, manifest, compiled .ps-exe, ISO, build log. /// public static string BuildOutputDir => Path.Combine(ProjectRoot, "PSXBuild"); /// /// The tools directory at the Unity project root. /// Contains auto-downloaded tools like PCSX-Redux. /// public static string ToolsDir => Path.Combine(ProjectRoot, ".tools"); /// /// PCSX-Redux install directory inside .tools/. /// public static string PCSXReduxDir => Path.Combine(ToolsDir, "pcsx-redux"); /// /// Platform-specific PCSX-Redux binary path. /// public static string PCSXReduxBinary { get { switch (Application.platform) { case RuntimePlatform.WindowsEditor: return Path.Combine(PCSXReduxDir, "pcsx-redux.exe"); case RuntimePlatform.LinuxEditor: return Path.Combine(ToolsDir, "PCSX-Redux-HEAD-x86_64.AppImage"); default: return Path.Combine(PCSXReduxDir, "pcsx-redux"); } } } /// /// The Unity project root (parent of Assets/). /// public static string ProjectRoot => Directory.GetParent(Application.dataPath).FullName; /// /// Path to the native psxsplash source. /// First checks SplashSettings override, then looks for common locations. /// public static string NativeSourceDir { get { // 1. Check the user-configured path from SplashSettings string custom = SplashSettings.NativeProjectPath; if (!string.IsNullOrEmpty(custom) && Directory.Exists(custom)) return custom; // 2. Look inside the Unity project's Assets/ folder (git clone location) string assetsClone = Path.Combine(UnityEngine.Application.dataPath, "psxsplash"); if (Directory.Exists(assetsClone) && File.Exists(Path.Combine(assetsClone, "Makefile"))) return assetsClone; // 3. Look for Native/ inside the package string packageNative = Path.GetFullPath( Path.Combine("Packages", "net.psxsplash.splashedit", "Native")); if (Directory.Exists(packageNative)) return packageNative; return ""; } } /// /// The compiled .ps-exe output from the native build. /// public static string CompiledExePath => Path.Combine(BuildOutputDir, "psxsplash.ps-exe"); /// /// The scene manifest file path. /// public static string ManifestPath => Path.Combine(BuildOutputDir, "manifest.bin"); /// /// Build log file path. /// public static string BuildLogPath => Path.Combine(BuildOutputDir, "build.log"); /// /// Gets the splashpack output path for a scene by index. /// Uses a deterministic naming scheme: scene_0.splashpack, scene_1.splashpack, etc. /// public static string GetSceneSplashpackPath(int sceneIndex, string sceneName) { return Path.Combine(BuildOutputDir, $"scene_{sceneIndex}.splashpack"); } /// /// ISO output path for release builds. /// public static string ISOOutputPath => Path.Combine(BuildOutputDir, "psxsplash.bin"); /// /// CUE sheet path for release builds. /// public static string CUEOutputPath => Path.Combine(BuildOutputDir, "psxsplash.cue"); /// /// Ensures the build output and tools directories exist. /// Also appends entries to the project .gitignore if not present. /// public static void EnsureDirectories() { Directory.CreateDirectory(BuildOutputDir); Directory.CreateDirectory(ToolsDir); EnsureGitIgnore(); } /// /// Checks if PCSX-Redux is installed in the tools directory. /// public static bool IsPCSXReduxInstalled() { return File.Exists(PCSXReduxBinary); } private static void EnsureGitIgnore() { string gitignorePath = Path.Combine(ProjectRoot, ".gitignore"); string[] entriesToAdd = new[] { "/PSXBuild/", "/.tools/" }; string existingContent = ""; if (File.Exists(gitignorePath)) { existingContent = File.ReadAllText(gitignorePath); } bool modified = false; string toAppend = ""; foreach (string entry in entriesToAdd) { // Check if entry already exists (exact line match) if (!existingContent.Contains(entry)) { if (!modified) { toAppend += "\n# SplashEdit build output\n"; modified = true; } toAppend += entry + "\n"; } } if (modified) { File.AppendAllText(gitignorePath, toAppend); } } } }