Skip to content

Commit

Permalink
Fixed install.txt AGAIN. The spaghetti code is spaghetti code.
Browse files Browse the repository at this point in the history
  • Loading branch information
harryeffinpotter committed Jun 20, 2021
1 parent bd511d2 commit a7ad7c0
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 68 deletions.
90 changes: 66 additions & 24 deletions ADB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ class ADB
public static string adbFolderPath = Environment.CurrentDirectory + "\\adb";
public static string adbFilePath = adbFolderPath + "\\adb.exe";
public static string DeviceID = "";

public static string package = "";
public static ProcessOutput RunAdbCommandToString(string command)
{
Properties.Settings.Default.ADBPath = adbFilePath;
Properties.Settings.Default.Save();
if (DeviceID.Length > 1)
command = $" -s {DeviceID} {command}";
Logger.Log($"Running command {command}");
Expand Down Expand Up @@ -60,12 +62,14 @@ public static ProcessOutput RunAdbCommandToString(string command)
public static ProcessOutput RunAdbCommandToStringWOADB(string result, string path)
{
string command = result;
if (DeviceID.Length > 1)
command = $" -s {DeviceID} {command}";

Properties.Settings.Default.ADBPath = adbFilePath;
Properties.Settings.Default.Save();
;



Logger.Log($"Running command {command}");
adb.StartInfo.FileName = @"C:\windows\system32\cmd.exe";
adb.StartInfo.Arguments = @"/c " + command;
adb.StartInfo.FileName = "cmd.exe";
adb.StartInfo.RedirectStandardError = true;
adb.StartInfo.RedirectStandardInput = true;
adb.StartInfo.RedirectStandardOutput = true;
Expand Down Expand Up @@ -104,6 +108,52 @@ public static ProcessOutput RunAdbCommandToStringWOADB(string result, string pat
return new ProcessOutput(output, error);
}

public static ProcessOutput RunCommandToString(string result, string path)
{
string command = result;


Logger.Log($"Running command {command}");
adb.StartInfo.FileName = @"C:\windows\system32\cmd.exe";
adb.StartInfo.Arguments = command;
adb.StartInfo.RedirectStandardError = true;
adb.StartInfo.RedirectStandardInput = true;
adb.StartInfo.RedirectStandardOutput = true;
adb.StartInfo.CreateNoWindow = true;
adb.StartInfo.UseShellExecute = false;
adb.StartInfo.WorkingDirectory = Path.GetDirectoryName(path);
adb.Start();
adb.StandardInput.WriteLine(command);
adb.StandardInput.Flush();
adb.StandardInput.Close();


string output = "";
string error = "";

try
{
output += adb.StandardOutput.ReadToEnd();
error += adb.StandardError.ReadToEnd();
}
catch { }
if (command.Contains("connect"))
{
bool graceful = adb.WaitForExit(3000);
if (!graceful)
{
adb.Kill();
}
}
else
adb.WaitForExit();
if (error.Contains("ADB_VENDOR_KEYS"))
MessageBox.Show("Please check inside your headset for ADB DEBUGGING prompt, check box to \"Always allow from this computer.\" and hit OK.");
Logger.Log(output);
Logger.Log(error);
return new ProcessOutput(output, error);
}


public static ProcessOutput UninstallPackage(string package)
{
Expand Down Expand Up @@ -235,6 +285,7 @@ public static ProcessOutput Sideload(string path, string packagename = "")
WakeDevice();

ProcessOutput ret = new ProcessOutput();
package = packagename;

Program.form.ChangeTitle($"Sideloading {path}");
ret += RunAdbCommandToString($"install -g -r \"{path}\"");
Expand Down Expand Up @@ -276,23 +327,21 @@ public static ProcessOutput Sideload(string path, string packagename = "")
}
}
ADB.WakeDevice();
ret += ADB.RunAdbCommandToString("shell pm uninstall " + packagename);
ret += ADB.RunAdbCommandToString("shell pm uninstall " + package);
ret += RunAdbCommandToString($"install -g -r \"{path}\"");
return ret;
}
ret += RunAdbCommandToString($"install -g -r \"{path}\"");
}
if (File.Exists($"{Properties.Settings.Default.MainDir}\\Config.Json"))
{
if (packagename.Contains("com.*") || Properties.Settings.Default.CurrPckg.Contains("com"))
{
if (Properties.Settings.Default.CurrPckg.Contains("com"))
packagename = Properties.Settings.Default.CurrPckg;


Program.form.ChangeTitle("Pushing Custom QU s3 Patch JSON.");
if (!Directory.Exists($"/sdcard/android/data/{packagename}"))
RunAdbCommandToString($"shell mkdir /sdcard/android/data/{packagename}");
if (!Directory.Exists($"/sdcard/android/data/{packagename}/private"))
RunAdbCommandToString($"shell mkdir /sdcard/android/data/{packagename}/private");
if (!Directory.Exists($"/sdcard/android/data/{package}"))
RunAdbCommandToString($"shell mkdir /sdcard/android/data/{package}");
if (!Directory.Exists($"/sdcard/android/data/{package}/private"))
RunAdbCommandToString($"shell mkdir /sdcard/android/data/{package}/private");

Random r = new Random();
int x = r.Next(999999999);
Expand All @@ -311,15 +360,8 @@ public static ProcessOutput Sideload(string path, string packagename = "")
File.WriteAllText("config.json", boff);
string blank = "";
File.WriteAllText("delete_settings", blank);
ret += ADB.RunAdbCommandToString($"push \"{Environment.CurrentDirectory}\\delete_settings\" /sdcard/android/data/{packagename}/private/delete_settings");
ret += ADB.RunAdbCommandToString($"push \"{Environment.CurrentDirectory}\\config.json\" /sdcard/android/data/{packagename}/private/config.json");


}
else
ret.Output += "QU Settings could not be automatically applied.\nPlease restart Rookie to refresh installed apps.\nThen select the app from the installed apps (Dropdown list above Device ID).\nThen click Install QU Setting";


ret += ADB.RunAdbCommandToString($"push \"{Environment.CurrentDirectory}\\delete_settings\" /sdcard/android/data/{package}/private/delete_settings");
ret += ADB.RunAdbCommandToString($"push \"{Environment.CurrentDirectory}\\config.json\" /sdcard/android/data/{package}/private/config.json");

}
Program.form.ChangeTitle("Sideload done");
Expand Down
75 changes: 37 additions & 38 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -632,62 +632,57 @@ private async void Form1_DragDrop(object sender, DragEventArgs e)
//if is directory
string dir = Path.GetDirectoryName(data);
string path = $"{dir}\\Install.txt";
if (data.StartsWith("com."))
if (Directory.Exists(data))
{
output += ADB.CopyOBB(data);

}
string extension = Path.GetExtension(data);
if (extension == ".apk")
{
output += ADB.Sideload(data);
if (File.Exists($"{Environment.CurrentDirectory}\\Install.txt"))
string extension = Path.GetExtension(data);
if (extension == ".apk")
{

DialogResult dialogResult = MessageBox.Show("Special instructions have been found with this file, would you like to run them automatically?", "Special Instructions found!", MessageBoxButtons.OKCancel);
if (dialogResult == DialogResult.Cancel)
return;
else
ChangeTitle("Sideloading custom install.txt automatically.");
output += Sideloader.RunADBCommandsFromFile(path);
if (output.Error.Contains("mkdir"))
output.Error = "";
if (output.Error.Contains("reserved"))
output.Output = "";
ChangeTitle("Done.");
if (File.Exists($"{Environment.CurrentDirectory}\\Install.txt"))
{

}


string[] files = Directory.GetFiles(data);
foreach (string file in files)
{
DialogResult dialogResult = MessageBox.Show("Special instructions have been found with this file, would you like to run them automatically?", "Special Instructions found!", MessageBoxButtons.OKCancel);
if (dialogResult == DialogResult.Cancel)
return;
else
ChangeTitle("Sideloading custom install.txt automatically.");
output += Sideloader.RunADBCommandsFromFile(path);
if (output.Error.Contains("mkdir"))
output.Error = "";
if (output.Error.Contains("reserved"))
output.Output = "";
ChangeTitle("Done.");
}
}
string[] files = Directory.GetFiles(data);
foreach (string file in files)
{
if (File.Exists(file))
if (file.EndsWith(".apk"))
{
output += ADB.Sideload(file);
}
}
string[] folders = Directory.GetDirectories(data);
foreach (string folder in folders)
{
output += ADB.CopyOBB(folder);
Properties.Settings.Default.CurrPckg = dir;
Properties.Settings.Default.Save();
}
}
string[] folders = Directory.GetDirectories(data);
foreach (string folder in folders)
{
output += ADB.CopyOBB(folder);
Properties.Settings.Default.CurrPckg = dir;
Properties.Settings.Default.Save();
}
}
//if it's a file
else if (File.Exists(data))
{

string extension2 = Path.GetExtension(data);
if (extension2 == ".apk")
string extension = Path.GetExtension(data);
if (extension == ".apk")
{
output += ADB.Sideload(data);

if (File.Exists($"{dir}\\Install.txt"))
{

DialogResult dialogResult = MessageBox.Show("Special instructions have been found with this file, would you like to run them automatically?", "Special Instructions found!", MessageBoxButtons.OKCancel);
if (dialogResult == DialogResult.Cancel)
return;
Expand All @@ -698,6 +693,10 @@ private async void Form1_DragDrop(object sender, DragEventArgs e)
ChangeTitle("Done.");
}
}
else
{
output += ADB.Sideload(data);
}
}
else if (extension == ".obb")
{
Expand Down Expand Up @@ -1479,7 +1478,7 @@ private void UpdateGamesButton_Click(object sender, EventArgs e)
FlexibleMessageBox.Show("There are no games in rclone, please check your internet connection and check if the config is working properly");
return;
}
string gamesToUpdate = "";

foreach (string packagename in Sideloader.InstalledPackages.Keys)
{
foreach (var release in SideloaderRCLONE.games)
Expand Down
10 changes: 7 additions & 3 deletions Sideloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,20 @@ public static ProcessOutput RunADBCommandsFromFile(string path)
var commands = File.ReadAllLines(path);
foreach (string cmd in commands)
{
if (cmd.StartsWith("\"7z.exe\""))
if (cmd.Contains("7z.exe"))
{
Program.form.ChangeTitle($"Running {cmd}");
Logger.Log($"Logging command: {cmd} from file: {path}");
output += ADB.RunAdbCommandToStringWOADB(cmd, path);
output += ADB.RunCommandToString(cmd, path);
}
if (cmd.StartsWith("adb"))
{
string replacement = "";
string pattern = "adb";
string replacement = $"{Properties.Settings.Default.ADBPath}";
if (ADB.DeviceID.Length > 1)
replacement = $"{Properties.Settings.Default.ADBPath} -s {ADB.DeviceID}";
else
replacement = $"{Properties.Settings.Default.ADBPath}";
Regex rgx = new Regex(pattern);
string result = rgx.Replace(cmd, replacement);
Program.form.ChangeTitle($"Running {result}");
Expand Down
2 changes: 1 addition & 1 deletion Sideloader/RCLONE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static long GetFolderSize(string FolderName, string remote)
catch { return 0; }
}

public static async Task updateConfig(string remote)
public static void updateConfig(string remote)
{
string localHash = "";
try { localHash = File.ReadAllText(Environment.CurrentDirectory + "\\rclone\\hash.txt"); } catch { } //file may not exist
Expand Down
4 changes: 2 additions & 2 deletions Sideloader/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ class SideloaderUtilities
{
public static bool CheckFolderIsObb(string path)
{
string[] files = Directory.GetDirectories(path);
string[] files = Directory.GetFiles(path);

foreach (string file in files)
if (file.StartsWith("com."))
if (file.EndsWith(".obb"))
return true;
return false;
}
Expand Down

0 comments on commit a7ad7c0

Please sign in to comment.