diff --git a/Editor/Core/MkpsxisoDownloader.cs b/Editor/Core/MkpsxisoDownloader.cs index 60f1519..73a1854 100644 --- a/Editor/Core/MkpsxisoDownloader.cs +++ b/Editor/Core/MkpsxisoDownloader.cs @@ -37,7 +37,7 @@ namespace SplashEdit.EditorCode { if (Application.platform == RuntimePlatform.WindowsEditor) return Path.Combine(MkpsxisoDir, "mkpsxiso.exe"); - return Path.Combine(MkpsxisoDir, "mkpsxiso"); + return Path.Combine(MkpsxisoDir, "bin", "mkpsxiso"); } } @@ -76,30 +76,18 @@ namespace SplashEdit.EditorCode string tempFile = Path.Combine(Path.GetTempPath(), archiveName); EditorUtility.DisplayProgressBar("Downloading mkpsxiso", "Downloading...", 0.1f); - using (var response = await _http.GetAsync(downloadUrl, - HttpCompletionOption.ResponseHeadersRead)) + using (var client = new System.Net.WebClient()) { - response.EnsureSuccessStatusCode(); - long? totalBytes = response.Content.Headers.ContentLength; - long downloaded = 0; + client.Headers.Add("User-Agent", "SplashEdit/1.0"); - using (var fs = File.Create(tempFile)) - using (var stream = await response.Content.ReadAsStreamAsync()) + client.DownloadProgressChanged += (s, e) => { - byte[] buffer = new byte[81920]; - int bytesRead; - while ((bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length)) > 0) - { - await fs.WriteAsync(buffer, 0, bytesRead); - downloaded += bytesRead; - if (totalBytes.HasValue) - { - float progress = (float)downloaded / totalBytes.Value; - EditorUtility.DisplayProgressBar("Downloading mkpsxiso", - $"{downloaded / 1024}/{totalBytes.Value / 1024} KB", progress); - } - } - } + float progress = 0.1f + 0.8f * (e.ProgressPercentage / 100f); + string sizeMB = $"{e.BytesReceived / (1024 * 1024)}/{e.TotalBytesToReceive / (1024 * 1024)} MB"; + EditorUtility.DisplayProgressBar("Downloading mkpsxiso", $"Downloading... {sizeMB}", progress); + }; + + await client.DownloadFileTaskAsync(new Uri(downloadUrl), tempFile); } log?.Invoke("Extracting..."); @@ -121,7 +109,7 @@ namespace SplashEdit.EditorCode if (IsInstalled()) { - // Make executable on Linux/Mac + // Make executable on Linux if (Application.platform != RuntimePlatform.WindowsEditor) { var chmod = Process.Start("chmod", $"+x \"{MkpsxisoBinary}\""); diff --git a/Editor/Core/PCSXReduxDownloader.cs b/Editor/Core/PCSXReduxDownloader.cs index 125e12e..35d2101 100644 --- a/Editor/Core/PCSXReduxDownloader.cs +++ b/Editor/Core/PCSXReduxDownloader.cs @@ -94,34 +94,20 @@ namespace SplashEdit.EditorCode // Step 3: Download the file string tempFile = Path.Combine(Path.GetTempPath(), $"pcsx-redux-{latestBuildId}.zip"); - EditorUtility.DisplayProgressBar("Downloading PCSX-Redux", "Downloading...", 0.1f); - using (var response = await _http.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead)) + using (var client = new System.Net.WebClient()) { - response.EnsureSuccessStatusCode(); - long? totalBytes = response.Content.Headers.ContentLength; - long downloadedBytes = 0; - - using (var fileStream = File.Create(tempFile)) - using (var downloadStream = await response.Content.ReadAsStreamAsync()) + client.Headers.Add("User-Agent", "SplashEdit/1.0"); + + client.DownloadProgressChanged += (s, e) => { - byte[] buffer = new byte[81920]; - int bytesRead; - while ((bytesRead = await downloadStream.ReadAsync(buffer, 0, buffer.Length)) > 0) - { - await fileStream.WriteAsync(buffer, 0, bytesRead); - downloadedBytes += bytesRead; + float progress = 0.1f + 0.8f * (e.ProgressPercentage / 100f); + string sizeMB = $"{e.BytesReceived / (1024 * 1024)}/{e.TotalBytesToReceive / (1024 * 1024)} MB"; + EditorUtility.DisplayProgressBar("Downloading PCSX-Redux", $"Downloading... {sizeMB}", progress); + }; - if (totalBytes.HasValue) - { - float progress = (float)downloadedBytes / totalBytes.Value; - string sizeMB = $"{downloadedBytes / (1024 * 1024)}/{totalBytes.Value / (1024 * 1024)} MB"; - EditorUtility.DisplayProgressBar("Downloading PCSX-Redux", - $"Downloading... {sizeMB}", progress); - } - } - } + await client.DownloadFileTaskAsync(new Uri(downloadUrl), tempFile); } log?.Invoke($"Downloaded to {tempFile}"); @@ -144,6 +130,7 @@ namespace SplashEdit.EditorCode }; var proc = Process.Start(psi); proc?.WaitForExit(); + } else { @@ -151,6 +138,20 @@ namespace SplashEdit.EditorCode log?.Invoke($"Extracted to {installDir}"); } + // Make executable + + if(Application.platform == RuntimePlatform.LinuxEditor) { + var psi = new ProcessStartInfo + { + FileName = "chmod", + Arguments = $"+x \"{SplashBuildPaths.PCSXReduxBinary}\"", + UseShellExecute = false, + CreateNoWindow = true + }; + var proc = Process.Start(psi); + proc?.WaitForExit(); + } + // Clean up temp file try { File.Delete(tempFile); } catch { } diff --git a/Editor/Core/PSXAudioConverter.cs b/Editor/Core/PSXAudioConverter.cs index 6571642..00dcb52 100644 --- a/Editor/Core/PSXAudioConverter.cs +++ b/Editor/Core/PSXAudioConverter.cs @@ -74,29 +74,18 @@ namespace SplashEdit.EditorCode string tempFile = Path.Combine(Path.GetTempPath(), archiveName); EditorUtility.DisplayProgressBar("Downloading psxavenc", "Downloading...", 0.1f); - using (var response = await _http.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead)) + using (var client = new System.Net.WebClient()) { - response.EnsureSuccessStatusCode(); - long? totalBytes = response.Content.Headers.ContentLength; - long downloaded = 0; + client.Headers.Add("User-Agent", "SplashEdit/1.0"); - using (var fs = File.Create(tempFile)) - using (var stream = await response.Content.ReadAsStreamAsync()) + client.DownloadProgressChanged += (s, e) => { - byte[] buffer = new byte[81920]; - int bytesRead; - while ((bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length)) > 0) - { - await fs.WriteAsync(buffer, 0, bytesRead); - downloaded += bytesRead; - if (totalBytes.HasValue) - { - float progress = (float)downloaded / totalBytes.Value; - EditorUtility.DisplayProgressBar("Downloading psxavenc", - $"{downloaded / 1024}/{totalBytes.Value / 1024} KB", progress); - } - } - } + float progress = 0.1f + 0.8f * (e.ProgressPercentage / 100f); + string sizeMB = $"{e.BytesReceived / (1024 * 1024)}/{e.TotalBytesToReceive / (1024 * 1024)} MB"; + EditorUtility.DisplayProgressBar("Downloading psxavenc", $"Downloading... {sizeMB}", progress); + }; + + await client.DownloadFileTaskAsync(new Uri(downloadUrl), tempFile); } log?.Invoke("Extracting..."); diff --git a/Editor/Core/SplashBuildPaths.cs b/Editor/Core/SplashBuildPaths.cs index 4f034ff..b666720 100644 --- a/Editor/Core/SplashBuildPaths.cs +++ b/Editor/Core/SplashBuildPaths.cs @@ -41,7 +41,7 @@ namespace SplashEdit.EditorCode case RuntimePlatform.WindowsEditor: return Path.Combine(PCSXReduxDir, "pcsx-redux.exe"); case RuntimePlatform.LinuxEditor: - return Path.Combine(ToolsDir, "PCSX-Redux-HEAD-x86_64.AppImage"); + return Path.Combine(PCSXReduxDir, "PCSX-Redux-HEAD-x86_64.AppImage"); default: return Path.Combine(PCSXReduxDir, "pcsx-redux"); }