Revamped psxsplash installer

This commit is contained in:
2026-03-28 13:51:55 +01:00
parent eff03e0e1a
commit 132ab479c2
2 changed files with 555 additions and 139 deletions

View File

@@ -60,6 +60,13 @@ namespace SplashEdit.EditorCode
private string _nativeInstallStatus = "";
private string _manualNativePath = "";
// ───── Release selector ─────
private int _selectedReleaseIndex = 0;
private string[] _releaseDisplayNames = new string[0];
private bool _isFetchingReleases;
private string _currentTag = "";
private bool _isSwitchingRelease;
// PCdrv serial host instance (for real hardware file serving)
private static PCdrvSerialHost _pcdrvHost;
@@ -89,6 +96,8 @@ namespace SplashEdit.EditorCode
RefreshToolchainStatus();
LoadSceneList();
_manualNativePath = SplashSettings.NativeProjectPath;
FetchGitHubReleases();
RefreshCurrentTag();
}
private void OnDisable()
@@ -215,44 +224,106 @@ namespace SplashEdit.EditorCode
}
else
{
GUILayout.Label("Not found — clone from GitHub or set path manually", EditorStyles.miniLabel);
GUILayout.Label("Not found — download from GitHub or set path manually", EditorStyles.miniLabel);
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space(6);
// ── Option 1: Auto-clone from GitHub ──
// ── Option 1: Download a release from GitHub ──
PSXEditorStyles.DrawSeparator(4, 4);
GUILayout.Label("Clone from GitHub", PSXEditorStyles.SectionHeader);
EditorGUILayout.BeginHorizontal();
GUILayout.Label(PSXSplashInstaller.RepoUrl, EditorStyles.miniLabel);
GUILayout.FlexibleSpace();
EditorGUI.BeginDisabledGroup(_isInstallingNative || PSXSplashInstaller.IsInstalled());
if (GUILayout.Button(PSXSplashInstaller.IsInstalled() ? "Installed" : "Clone", GUILayout.Width(80)))
GUILayout.Label("Download from GitHub", PSXEditorStyles.SectionHeader);
// Git availability check
if (!PSXSplashInstaller.IsGitAvailable())
{
CloneNativeProject();
EditorGUILayout.HelpBox(
"git is required to download the native project (submodules need recursive clone).\n" +
"Install git from: https://git-scm.com/downloads",
MessageType.Warning);
}
// Release selector
EditorGUILayout.BeginHorizontal();
GUILayout.Label("Release:", GUILayout.Width(55));
if (_isFetchingReleases)
{
GUILayout.Label("Fetching releases...", EditorStyles.miniLabel);
}
else if (_releaseDisplayNames.Length == 0)
{
GUILayout.Label("No releases found", EditorStyles.miniLabel);
if (GUILayout.Button("Refresh", EditorStyles.miniButton, GUILayout.Width(60)))
FetchGitHubReleases();
}
else
{
_selectedReleaseIndex = EditorGUILayout.Popup(_selectedReleaseIndex, _releaseDisplayNames);
if (GUILayout.Button("↻", EditorStyles.miniButton, GUILayout.Width(22)))
FetchGitHubReleases();
}
EditorGUI.EndDisabledGroup();
EditorGUILayout.EndHorizontal();
if (_isInstallingNative)
// Current version display (when installed)
if (PSXSplashInstaller.IsInstalled() && !string.IsNullOrEmpty(_currentTag))
{
GUILayout.Label(_nativeInstallStatus, PSXEditorStyles.InfoBox);
var prevColor = GUI.contentColor;
GUI.contentColor = PSXEditorStyles.Success;
GUILayout.Label($"Current version: {_currentTag}", EditorStyles.miniLabel);
GUI.contentColor = prevColor;
}
// If already cloned, show version management
if (PSXSplashInstaller.IsInstalled())
// Clone / Switch / Open buttons
EditorGUILayout.BeginHorizontal();
if (!PSXSplashInstaller.IsInstalled())
{
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Fetch Latest", EditorStyles.miniButton, GUILayout.Width(90)))
// Not installed yet — show Clone button
EditorGUI.BeginDisabledGroup(
_isInstallingNative || _releaseDisplayNames.Length == 0 ||
!PSXSplashInstaller.IsGitAvailable());
if (GUILayout.Button("Download Release", GUILayout.Width(130)))
{
FetchNativeLatest();
CloneNativeProject();
}
EditorGUI.EndDisabledGroup();
}
else
{
// Already installed — show Switch and Open buttons
EditorGUI.BeginDisabledGroup(
_isSwitchingRelease || _isInstallingNative ||
_releaseDisplayNames.Length == 0 || !PSXSplashInstaller.IsGitAvailable());
if (GUILayout.Button("Switch Release", EditorStyles.miniButton, GUILayout.Width(100)))
{
SwitchNativeRelease();
}
EditorGUI.EndDisabledGroup();
if (GUILayout.Button("Open Folder", EditorStyles.miniButton, GUILayout.Width(90)))
{
EditorUtility.RevealInFinder(PSXSplashInstaller.FullInstallPath);
}
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.EndHorizontal();
// Progress / status message
if (_isInstallingNative || _isSwitchingRelease)
{
GUILayout.Label(_nativeInstallStatus, PSXEditorStyles.InfoBox);
}
// Show release notes for selected release
if (_releaseDisplayNames.Length > 0 && _selectedReleaseIndex < PSXSplashInstaller.CachedReleases.Count)
{
var selected = PSXSplashInstaller.CachedReleases[_selectedReleaseIndex];
if (!string.IsNullOrEmpty(selected.Body))
{
EditorGUILayout.Space(2);
string trimmedNotes = selected.Body.Length > 200
? selected.Body.Substring(0, 200) + "..."
: selected.Body;
GUILayout.Label(trimmedNotes, EditorStyles.wordWrappedMiniLabel);
}
}
EditorGUILayout.Space(6);
@@ -1840,34 +1911,99 @@ namespace SplashEdit.EditorCode
}
}
// ───── Native Project Clone/Fetch ─────
// ───── Release fetching & management ─────
private async void CloneNativeProject()
private async void FetchGitHubReleases()
{
_isInstallingNative = true;
_nativeInstallStatus = "Cloning psxsplash repository (this may take a minute)...";
_isFetchingReleases = true;
Repaint();
Log("Cloning psxsplash native project from GitHub...", LogType.Log);
try
{
bool success = await PSXSplashInstaller.Install();
if (success)
var releases = await PSXSplashInstaller.FetchReleasesAsync();
if (releases.Count > 0)
{
Log("psxsplash cloned successfully!", LogType.Log);
_nativeInstallStatus = "";
RefreshToolchainStatus();
_releaseDisplayNames = releases
.Select(r =>
{
string label = r.TagName;
if (!string.IsNullOrEmpty(r.Name) && r.Name != r.TagName)
label += $" — {r.Name}";
if (r.IsPrerelease)
label += " (pre-release)";
return label;
})
.ToArray();
// Try to select the currently checked-out tag
if (!string.IsNullOrEmpty(_currentTag))
{
int idx = releases.FindIndex(r => r.TagName == _currentTag);
if (idx >= 0) _selectedReleaseIndex = idx;
}
_selectedReleaseIndex = Mathf.Clamp(_selectedReleaseIndex, 0, _releaseDisplayNames.Length - 1);
}
else
{
Log("Clone failed. Check console for errors.", LogType.Error);
_nativeInstallStatus = "Clone failed — check console for details.";
_releaseDisplayNames = new string[0];
}
}
catch (Exception ex)
{
Log($"Clone error: {ex.Message}", LogType.Error);
Log($"Failed to fetch releases: {ex.Message}", LogType.Warning);
}
finally
{
_isFetchingReleases = false;
Repaint();
}
}
private void RefreshCurrentTag()
{
_currentTag = PSXSplashInstaller.GetCurrentTag() ?? "";
}
// ───── Native Project Clone/Switch ─────
private async void CloneNativeProject()
{
if (_selectedReleaseIndex < 0 || _selectedReleaseIndex >= PSXSplashInstaller.CachedReleases.Count)
return;
string tag = PSXSplashInstaller.CachedReleases[_selectedReleaseIndex].TagName;
_isInstallingNative = true;
_nativeInstallStatus = $"Downloading psxsplash {tag} (this may take a minute)...";
Repaint();
Log($"Downloading psxsplash {tag} from GitHub...", LogType.Log);
try
{
bool success = await PSXSplashInstaller.InstallRelease(tag, msg =>
{
_nativeInstallStatus = msg;
Repaint();
});
if (success)
{
Log($"psxsplash {tag} downloaded successfully!", LogType.Log);
_nativeInstallStatus = "";
RefreshToolchainStatus();
RefreshCurrentTag();
}
else
{
Log("Download failed. Check console for errors.", LogType.Error);
_nativeInstallStatus = "Download failed — check console for details.";
}
}
catch (Exception ex)
{
Log($"Download error: {ex.Message}", LogType.Error);
_nativeInstallStatus = $"Error: {ex.Message}";
}
finally
@@ -1877,22 +2013,55 @@ namespace SplashEdit.EditorCode
}
}
private async void FetchNativeLatest()
private async void SwitchNativeRelease()
{
Log("Fetching latest changes...", LogType.Log);
if (_selectedReleaseIndex < 0 || _selectedReleaseIndex >= PSXSplashInstaller.CachedReleases.Count)
return;
string tag = PSXSplashInstaller.CachedReleases[_selectedReleaseIndex].TagName;
if (tag == _currentTag)
{
Log($"Already on {tag}.", LogType.Log);
return;
}
_isSwitchingRelease = true;
_nativeInstallStatus = $"Switching to {tag}...";
Repaint();
Log($"Switching native project to {tag}...", LogType.Log);
try
{
bool success = await PSXSplashInstaller.FetchLatestAsync();
bool success = await PSXSplashInstaller.SwitchToReleaseAsync(tag, msg =>
{
_nativeInstallStatus = msg;
Repaint();
});
if (success)
Log("Fetch complete. Use 'git pull' to apply updates.", LogType.Log);
{
Log($"Switched to {tag}.", LogType.Log);
_nativeInstallStatus = "";
RefreshCurrentTag();
}
else
Log("Fetch failed.", LogType.Warning);
{
Log($"Failed to switch to {tag}.", LogType.Error);
_nativeInstallStatus = "Switch failed — check console for details.";
}
}
catch (Exception ex)
{
Log($"Fetch error: {ex.Message}", LogType.Error);
Log($"Switch error: {ex.Message}", LogType.Error);
_nativeInstallStatus = $"Error: {ex.Message}";
}
finally
{
_isSwitchingRelease = false;
Repaint();
}
Repaint();
}
// ═══════════════════════════════════════════════════════════════