Skip to content

Commit 0ca0325

Browse files
committed
Many fixes, improvements and updates
Please check the v16.1 release notes for all changes.
1 parent b96f9cd commit 0ca0325

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+3318
-1178
lines changed

PSMultiTools/Classes/PS2Game.cs

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Diagnostics;
66
using System.IO;
77
using System.Runtime.CompilerServices;
8+
using System.Threading.Tasks;
89

910
namespace PSMultiTools.Classes
1011
{
@@ -198,50 +199,51 @@ public static string GetGameRegionByGameID(string GameID)
198199
}
199200
}
200201

201-
public static string GetPS2GameID(string GameISO)
202+
public static async Task<string> GetPS2GameIDAsync(string GameISO)
202203
{
203204
string GameID = "";
204205

205206
try
206207
{
207-
using (var SevenZip = new Process())
208+
Process SevenZip = new();
209+
SevenZip.StartInfo.FileName = OperatingSystem.IsWindows() ? Path.Combine(Environment.CurrentDirectory, "Tools", "7z.exe") : Path.Combine(Environment.CurrentDirectory, "Tools", "7zz");
210+
SevenZip.StartInfo.Arguments = "l -ba \"" + GameISO + "\"";
211+
SevenZip.StartInfo.RedirectStandardOutput = true;
212+
SevenZip.StartInfo.UseShellExecute = false;
213+
SevenZip.StartInfo.CreateNoWindow = true;
214+
SevenZip.Start();
215+
216+
// Read the output
217+
var OutputReader = SevenZip.StandardOutput;
218+
string[] ProcessOutput = OutputReader.ReadToEnd().Split([Environment.NewLine], StringSplitOptions.None);
219+
220+
await SevenZip.WaitForExitAsync();
221+
SevenZip.Close();
222+
223+
if (ProcessOutput.Length > 0)
208224
{
209-
SevenZip.StartInfo.FileName = OperatingSystem.IsWindows() ? Path.Combine(Environment.CurrentDirectory, "Tools", "7z.exe") : Path.Combine(Environment.CurrentDirectory, "Tools", "7zz");
210-
SevenZip.StartInfo.Arguments = "l -ba \"" + GameISO + "\"";
211-
SevenZip.StartInfo.RedirectStandardOutput = true;
212-
SevenZip.StartInfo.UseShellExecute = false;
213-
SevenZip.StartInfo.CreateNoWindow = true;
214-
SevenZip.Start();
215-
216-
// Read the output
217-
var OutputReader = SevenZip.StandardOutput;
218-
string[] ProcessOutput = OutputReader.ReadToEnd().Split([Environment.NewLine], StringSplitOptions.None);
219-
220-
if (ProcessOutput.Length > 0)
225+
foreach (string Line in ProcessOutput)
221226
{
222-
foreach (string Line in ProcessOutput)
227+
if (Line.Contains("SLES_") | Line.Contains("SLUS_") | Line.Contains("SCES_") | Line.Contains("SCUS_"))
223228
{
224-
if (Line.Contains("SLES_") | Line.Contains("SLUS_") | Line.Contains("SCES_") | Line.Contains("SCUS_"))
229+
if (Line.Contains("Volume:")) // ID found in the ISO Header
225230
{
226-
if (Line.Contains("Volume:")) // ID found in the ISO Header
231+
if (Line.Split(["Volume: "], StringSplitOptions.RemoveEmptyEntries).Length > 0)
227232
{
228-
if (Line.Split(["Volume: "], StringSplitOptions.RemoveEmptyEntries).Length > 0)
229-
{
230-
GameID = Line.Split(["Volume: "], StringSplitOptions.RemoveEmptyEntries)[1];
231-
break;
232-
}
233-
}
234-
else if (string.Join(" ", Line.Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries)).Split(' ').Length > 4) // ID found in the ISO files
235-
{
236-
GameID = string.Join(" ", Line.Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries)).Split(' ')[5].Trim();
233+
GameID = Line.Split(["Volume: "], StringSplitOptions.RemoveEmptyEntries)[1];
237234
break;
238235
}
239236
}
237+
else if (string.Join(" ", Line.Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries)).Split(' ').Length > 4) // ID found in the ISO files
238+
{
239+
GameID = string.Join(" ", Line.Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries)).Split(' ')[5].Trim();
240+
break;
241+
}
240242
}
241243
}
242244
}
243245
}
244-
catch { }
246+
catch { return ""; }
245247

246248
return GameID;
247249
}

PSMultiTools/Classes/PS5Game.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public enum RootLocation
7373

7474
public string? GameVersionFileURI { get; set; }
7575

76+
public bool? IsInstalled { get; set; }
77+
7678
public static string GetGameRegion(string GameID)
7779
{
7880
if (GameID.StartsWith("PPSA"))

PSMultiTools/Classes/Utils.cs

Lines changed: 110 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using DiscUtils.Iso9660;
77
using FluentFTP;
88
using IronSoftware.Drawing;
9+
using Microsoft.Data.Sqlite;
910
using MsBox.Avalonia;
1011
using MsBox.Avalonia.Enums;
1112
using PSMultiTools.PS5.Tools.Editors;
@@ -773,16 +774,57 @@ public static long GetFTPDirectorySize(FtpClient client, string path)
773774
return FolderSize;
774775
}
775776

777+
public static string GetPSMultiToolsVersion()
778+
{
779+
// Try different methods if one fails on a specific Linux distro, FreeBSD or in macOS
780+
var GetAssembly = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly();
781+
try
782+
{
783+
var infoAttr = GetAssembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
784+
if (!string.IsNullOrWhiteSpace(infoAttr?.InformationalVersion))
785+
return infoAttr.InformationalVersion;
786+
}
787+
catch { }
788+
789+
try
790+
{
791+
var path = GetAssembly.Location;
792+
if (string.IsNullOrWhiteSpace(path))
793+
path = Process.GetCurrentProcess().MainModule?.FileName;
794+
if (!string.IsNullOrWhiteSpace(path) && File.Exists(path))
795+
{
796+
var fvi = FileVersionInfo.GetVersionInfo(path);
797+
if (!string.IsNullOrWhiteSpace(fvi.ProductVersion))
798+
return fvi.ProductVersion;
799+
}
800+
}
801+
catch { }
802+
803+
try
804+
{
805+
var asmVer = GetAssembly.GetName().Version;
806+
if (asmVer != null)
807+
return asmVer.ToString();
808+
}
809+
catch { }
810+
811+
// Return current version if one of the methods above failed - Requires change every build!
812+
return "16.1.0";
813+
}
814+
776815
public static async Task<bool> IsPSMultiToolsUpdateAvailable()
777816
{
778817
if (await IsURLValid("https://github.com/SvenGDK/PS-Multi-Tools/raw/main/LatestBuild.txt"))
779818
{
780-
var GetAssembly = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly();
781-
var PSMultiToolsVersion = GetAssembly?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
819+
var PSMultiToolsVersion = GetPSMultiToolsVersion();
820+
821+
Console.WriteLine($"Current version: " + PSMultiToolsVersion); // Output in terminal
782822

783823
using var VerCheckClient = new HttpClient();
784824
string NewPSMultiToolsVersion = await VerCheckClient.GetStringAsync("https://github.com/SvenGDK/PS-Multi-Tools/raw/main/LatestBuild.txt");
785825

826+
Console.WriteLine($"Latest available version: " + NewPSMultiToolsVersion); // Output in terminal
827+
786828
if (string.Compare(PSMultiToolsVersion, NewPSMultiToolsVersion, false) < 0)
787829
{
788830
return true;
@@ -800,7 +842,7 @@ public static async Task<bool> IsPSMultiToolsUpdateAvailable()
800842

801843
public static async void DownloadAndExecuteUpdater()
802844
{
803-
// Check if updater exists
845+
// Check if any updater exists
804846
if (!File.Exists(Path.Combine(Environment.CurrentDirectory, "PSMT-Update.exe")) | !File.Exists(Path.Combine(Environment.CurrentDirectory, "PSMTUpdate.sh")))
805847
{
806848
// Download if not exists
@@ -876,6 +918,71 @@ public static async void DownloadAndExecuteUpdater()
876918

877919
#endregion
878920

921+
#region PS5 Related
922+
923+
public static int BlockAppOrGameUpdates(string connectionString, string titleId, string contentVersion, string versionFileUri)
924+
{
925+
using var connection = new SqliteConnection(connectionString);
926+
connection.Open();
927+
928+
using var transaction = connection.BeginTransaction();
929+
try
930+
{
931+
int totalRows = 0;
932+
933+
// Update JSON inside tbl_contentinfo.AppInfoJson using json_set
934+
using (var cmd = connection.CreateCommand())
935+
{
936+
cmd.Transaction = transaction;
937+
cmd.CommandText = @"
938+
UPDATE tbl_contentinfo
939+
SET AppInfoJson = json_set(
940+
AppInfoJson,
941+
'$.CONTENT_VERSION', $contentVersion,
942+
'$.VERSION_FILE_URI', $versionFileUri
943+
)
944+
WHERE titleId = $titleId;
945+
";
946+
cmd.Parameters.AddWithValue("$contentVersion", contentVersion ?? string.Empty);
947+
cmd.Parameters.AddWithValue("$versionFileUri", versionFileUri ?? string.Empty);
948+
cmd.Parameters.AddWithValue("$titleId", titleId);
949+
950+
totalRows += cmd.ExecuteNonQuery();
951+
}
952+
953+
// Update tbl_appinfo columns
954+
using (var cmd = connection.CreateCommand())
955+
{
956+
cmd.Transaction = transaction;
957+
cmd.CommandText = @"
958+
UPDATE tbl_appinfo
959+
SET VERSION_FILE_URI = $versionFileUri,
960+
CONTENT_VERSION = $contentVersion
961+
WHERE titleId = $titleId;
962+
";
963+
cmd.Parameters.AddWithValue("$versionFileUri", versionFileUri ?? string.Empty);
964+
cmd.Parameters.AddWithValue("$contentVersion", contentVersion ?? string.Empty);
965+
cmd.Parameters.AddWithValue("$titleId", titleId);
966+
967+
totalRows += cmd.ExecuteNonQuery();
968+
}
969+
970+
transaction.Commit();
971+
return totalRows;
972+
}
973+
catch
974+
{
975+
try { transaction.Rollback(); } catch { }
976+
throw;
977+
}
978+
finally
979+
{
980+
connection.Close();
981+
}
982+
}
983+
984+
#endregion
985+
879986
public static bool IncrementArray(ref byte[] sourceArray, int position)
880987
{
881988
if (sourceArray[position] == 255)

PSMultiTools/Dialogs/Downloader.axaml.cs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public async Task DownloadFileWithProgressAsync(string FileUrl, string SavePath)
207207

208208
using var NewFileStream = new FileStream(SavePath, FileMode.Create, FileAccess.Write, FileShare.None, 8192, true);
209209
var Buffer = new byte[8192];
210-
long TotalBytesRead = 0L;
210+
long TotalBytesRead = 0;
211211
int BytesRead;
212212

213213
var NewStopwatch = new Stopwatch();
@@ -225,13 +225,13 @@ public async Task DownloadFileWithProgressAsync(string FileUrl, string SavePath)
225225

226226
double ElapsedSeconds = NewStopwatch.Elapsed.TotalSeconds;
227227
double DownloadSpeed = TotalBytesRead / ElapsedSeconds;
228-
double SpeedInKbps = DownloadSpeed / 1024d;
229-
double ETAInSeconds = TotalBytes > 0L ? (TotalBytes - TotalBytesRead) / DownloadSpeed : 0;
228+
double SpeedInKbps = DownloadSpeed / 1024;
229+
double ETAInSeconds = TotalBytes > 0 ? (TotalBytes - TotalBytesRead) / DownloadSpeed : 0;
230230

231231
// Display progress
232-
if (TotalBytes > 0L)
232+
if (TotalBytes > 0)
233233
{
234-
double DLProgress = TotalBytesRead * 100L / (double)TotalBytes;
234+
double DLProgress = TotalBytesRead * 100 / (double)TotalBytes;
235235

236236
if (Dispatcher.UIThread.CheckAccess() == false)
237237
{
@@ -285,7 +285,6 @@ public async Task DownloadFileWithProgressAsync(string FileUrl, string SavePath)
285285
break;
286286
}
287287
}
288-
break;
289288
}
290289
}
291290
}
@@ -300,7 +299,7 @@ public async Task DownloadFileWithProgressAsync(string FileUrl, string SavePath)
300299
IsDownloadClientBusy = false;
301300

302301
// Prompt for extracting a downloaded archive and opening the downloads folder
303-
if (DownloadFileName.EndsWith(".zip") | DownloadFileName.EndsWith(".7z") | DownloadFileName.EndsWith(".rar"))
302+
if (DownloadFileName.EndsWith(".zip") || DownloadFileName.EndsWith(".7z") || DownloadFileName.EndsWith(".rar"))
304303
{
305304
var box = MessageBoxManager.GetMessageBoxStandard("Extract download ?", "Download completed!" + Environment.NewLine + "The downloaded file is an archive that can be extracted, do you want to extract it now ?", ButtonEnum.YesNo, MsBox.Avalonia.Enums.Icon.Question);
306305
var boxresult = await box.ShowWindowDialogAsync(this);
@@ -312,15 +311,14 @@ public async Task DownloadFileWithProgressAsync(string FileUrl, string SavePath)
312311
if (File.Exists(DownloadedFile))
313312
{
314313

315-
using (var ArchiveExtractor = new Process())
316-
{
317-
ArchiveExtractor.StartInfo.FileName = OperatingSystem.IsWindows() ? Path.Combine(Environment.CurrentDirectory, "Tools", "7z.exe") : Path.Combine(Environment.CurrentDirectory, "Tools", "7zz");
318-
ArchiveExtractor.StartInfo.Arguments = $"x \"{DownloadedFile}\" -o\"{Utils.EnsureTrailingSeparator(Utils.GetDownloadsFolderPath())}\" -y";
319-
ArchiveExtractor.StartInfo.UseShellExecute = false;
320-
ArchiveExtractor.StartInfo.CreateNoWindow = true;
321-
ArchiveExtractor.Start();
322-
ArchiveExtractor.WaitForExit();
323-
}
314+
Process ArchiveExtractor = new();
315+
ArchiveExtractor.StartInfo.FileName = OperatingSystem.IsWindows() ? Path.Combine(Environment.CurrentDirectory, "Tools", "7z.exe") : Path.Combine(Environment.CurrentDirectory, "Tools", "7zz");
316+
ArchiveExtractor.StartInfo.Arguments = $"x \"{DownloadedFile}\" -o\"{Utils.EnsureTrailingSeparator(Utils.GetDownloadsFolderPath())}\" -y";
317+
ArchiveExtractor.StartInfo.UseShellExecute = false;
318+
ArchiveExtractor.StartInfo.CreateNoWindow = true;
319+
ArchiveExtractor.Start();
320+
await ArchiveExtractor.WaitForExitAsync();
321+
ArchiveExtractor.Close();
324322

325323
var box2 = MessageBoxManager.GetMessageBoxStandard("Completed", "Extraction done!" + Environment.NewLine + "Do you want to open the Downloads folder ?", ButtonEnum.YesNo, MsBox.Avalonia.Enums.Icon.Question);
326324
var boxresult2 = await box2.ShowWindowDialogAsync(this);

0 commit comments

Comments
 (0)