task test 1

This commit is contained in:
Dagg 2023-03-18 22:13:32 -07:00
commit d9c1ff7b40
No known key found for this signature in database
GPG key ID: 35F1082DE618E967
2 changed files with 159 additions and 137 deletions

1
.gitignore vendored
View file

@ -9,6 +9,7 @@
*.user
*.userosscache
*.sln.docstates
.vscode
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

View file

@ -5,6 +5,7 @@ using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using LBPUnion.UnionPatcher.Communication;
namespace LBPUnion.UnionPatcher;
@ -13,10 +14,12 @@ public class RemotePatch
{
private readonly PS3MAPI _ps3Mapi = new();
private static Dictionary<string, string> GetUsers(string ps3Ip, string user, string pass)
private static Dictionary<string, string> GetUsersAsync(string ps3Ip, string user, string pass)
{
Console.WriteLine("Getting users...");
Task<Dictionary<string, string>> users = Task.Run(() =>
{
Dictionary<string, string> users = new();
string[] userFolders = FTP.ListDirectory($"ftp://{ps3Ip}/dev_hdd0/home/", user, pass);
@ -33,6 +36,9 @@ public class RemotePatch
}
return users;
});
return users.Result;
}
public static void LaunchSCETool(string args)
@ -44,13 +50,15 @@ public class RemotePatch
platformExecutable = "scetool/win64/scetool.exe";
break;
case OSPlatform.Linux:
if(RuntimeInformation.ProcessArchitecture == Architecture.X64)
if (RuntimeInformation.ProcessArchitecture == Architecture.X64)
{
platformExecutable = "scetool/linux64/scetool";
} else if (RuntimeInformation.ProcessArchitecture == Architecture.Arm)
}
else if (RuntimeInformation.ProcessArchitecture == Architecture.Arm)
{
platformExecutable = "scetool/linuxarm/scetool";
} else if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
}
else if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
{
platformExecutable = "scetool/linuxarm64/scetool";
}
@ -91,6 +99,8 @@ public class RemotePatch
{
Console.WriteLine("Restoring original EBOOT.BIN from EBOOT.BIN.BAK");
Task.Run(() =>
{
// Create a simple directory structure
Directory.CreateDirectory(@"eboot");
Directory.CreateDirectory($@"eboot/{gameID}");
@ -99,19 +109,25 @@ public class RemotePatch
// Now we'll check and see if a backup exists on the server, if so download it and then upload it back as EBOOT.BIN
if (FTP.FileExists($"ftp://{ps3ip}/dev_hdd0/game/{gameID}/USRDIR/EBOOT.BIN.BAK", user, pass))
{
FTP.DownloadFile($"ftp://{ps3ip}/dev_hdd0/game/{gameID}/USRDIR/EBOOT.BIN.BAK", @$"eboot/{gameID}/original/EBOOT.BIN.BAK", user, pass);
FTP.UploadFile(@$"eboot/{gameID}/original/EBOOT.BIN.BAK", $"ftp://{ps3ip}/dev_hdd0/game/{gameID}/USRDIR/EBOOT.BIN", user, pass);
}
else
{
throw new WebException("Could not find EBOOT.BIN.BAK on server.");
}
}).Wait();
}
public void PSNEBOOTRemotePatch(string ps3ip, string gameID, string serverURL, string user, string pass)
{
Console.WriteLine("Detected Digital Copy - Running in Full Mode");
// Create a new thread so we don't occupy the UI thread.
Task.Run(() =>
{
string idps = "";
string contentID = "";
Dictionary<string, string> users;
@ -142,7 +158,7 @@ public class RemotePatch
File.WriteAllBytes(@"data/idps", IDPSHelper.StringToByteArray(idps));
// Scan the users on the system
users = GetUsers(ps3ip, user, pass);
users = GetUsersAsync(ps3ip, user, pass);
// Scan the system for a license for the game
foreach (string currentUser in users.Keys.ToArray())
@ -196,6 +212,7 @@ public class RemotePatch
// And upload the encrypted, patched EBOOT to the system.
FTP.UploadFile(@$"eboot/{gameID}/patched/EBOOT.BIN",
$"ftp://{ps3ip}/dev_hdd0/game/{gameID}/USRDIR/EBOOT.BIN", user, pass);
});
}
// Cut-down version that only patches disc copies
@ -203,6 +220,9 @@ public class RemotePatch
{
Console.WriteLine("Detected Disc Copy - Running in Simplified Mode");
// Create a new thread so we don't occupy the UI thread.
Task.Run(() =>
{
// Create a simple directory structure
Directory.CreateDirectory(@"eboot");
Directory.CreateDirectory($@"eboot/{gameID}");
@ -236,5 +256,6 @@ public class RemotePatch
// And upload the encrypted, patched EBOOT to the system.
FTP.UploadFile(@$"eboot/{gameID}/patched/EBOOT.BIN",
$"ftp://{ps3ip}/dev_hdd0/game/{gameID}/USRDIR/EBOOT.BIN", user, pass);
});
}
}