Skip to content

Commit

Permalink
Merge pull request #156 from Chax1/fix/QualityOfLife
Browse files Browse the repository at this point in the history
Quality of Life Changes
  • Loading branch information
Fenopy authored May 23, 2023
2 parents c010fda + b705c56 commit f8724ba
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 81 deletions.
25 changes: 15 additions & 10 deletions ADB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public static ProcessOutput RunAdbCommandToString(string command)
}
if (!command.Contains("dumpsys") && !command.Contains("shell pm list packages") && !command.Contains("KEYCODE_WAKEUP"))
{

string logcmd = command;

if (logcmd.Contains(Environment.CurrentDirectory))
Expand All @@ -37,15 +36,11 @@ public static ProcessOutput RunAdbCommandToString(string command)
adb.StartInfo.FileName = adbFilePath;
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 = adbFolderPath;
_ = adb.Start();
adb.StandardInput.WriteLine(command);
adb.StandardInput.Flush();
adb.StandardInput.Close();

string output = "";
string error = "";
Expand All @@ -56,9 +51,10 @@ public static ProcessOutput RunAdbCommandToString(string command)
error = adb.StandardError.ReadToEnd();
}
catch { }

if (command.Contains("connect"))
{
bool graceful = adb.WaitForExit(3000); //Wait 3 secs.
bool graceful = adb.WaitForExit(3000); // Wait 3 secs.
if (!graceful)
{
adb.Kill();
Expand Down Expand Up @@ -94,6 +90,7 @@ public static ProcessOutput RunAdbCommandToString(string command)
_ = Logger.Log(error, "ERROR");
return new ProcessOutput(output, error);
}

public static ProcessOutput RunAdbCommandToStringWOADB(string result, string path)
{
string command = result;
Expand Down Expand Up @@ -325,12 +322,20 @@ public static ProcessOutput Sideload(string path, string packagename = "")
ADB.WakeDevice();
if (!Properties.Settings.Default.AutoReinstall)
{
DialogResult dialogResult1 = FlexibleMessageBox.Show(Program.form, "In place upgrade has failed. Rookie can attempt to backup your save data and\nreinstall the game automatically, however " +
"some games do not store their saves\nin an accessible location(less than 5%). Continue with reinstall?", "In place upgrade failed.", MessageBoxButtons.OKCancel);
if (dialogResult1 == DialogResult.Cancel)
bool cancelClicked = false;

if (!Properties.Settings.Default.AutoReinstall)
{
return ret;
Program.form.Invoke((MethodInvoker)(() =>
{
DialogResult dialogResult1 = FlexibleMessageBox.Show(Program.form, "In place upgrade has failed. Rookie can attempt to backup your save data and reinstall the game automatically, however some games do not store their saves in an accessible location (less than 5%). Continue with reinstall?", "In place upgrade failed.", MessageBoxButtons.OKCancel);
if (dialogResult1 == DialogResult.Cancel)
cancelClicked = true;
}));
}

if (cancelClicked)
return ret;
}

Program.form.ChangeTitle("Performing reinstall, please wait...");
Expand Down
123 changes: 54 additions & 69 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2094,27 +2094,14 @@ private void initMirrors(bool random)
private void sideloadContainer_Click(object sender, EventArgs e)
{
ShowSubMenu(sideloadContainer);
if (sideloadDrop.Text == "▼ SIDELOAD ▼")
{
sideloadDrop.Text = "▶ SIDELOAD ◀";
}
else if (sideloadDrop.Text == "▶ SIDELOAD ◀")
{
sideloadDrop.Text = "▼ SIDELOAD ▼";
}
sideloadDrop.Text = (sideloadDrop.Text == "▼ SIDELOAD ▼") ? "▶ SIDELOAD ◀" : "▼ SIDELOAD ▼";
}


private void backupDrop_Click(object sender, EventArgs e)
{
ShowSubMenu(backupContainer);
if (backupDrop.Text == "▼ BACKUP / RESTORE ▼")
{
backupDrop.Text = "▶ BACKUP / RESTORE ◀";
}
else if (backupDrop.Text == "▶ BACKUP / RESTORE ◀")
{
backupDrop.Text = "▼ BACKUP / RESTORE ▼";
}
backupDrop.Text = (backupDrop.Text == "▼ BACKUP / RESTORE ▼") ? "▶ BACKUP / RESTORE ◀" : "▼ BACKUP / RESTORE ▼";
}

private void settingsButton_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -2497,39 +2484,31 @@ public async void downloadInstallGameButton_Click(object sender, EventArgs e)
try
{
HttpResponseMessage response = await client.PostAsync("http://127.0.0.1:5572/core/stats", null);

string foo = await response.Content.ReadAsStringAsync();

Debug.WriteLine("RESP CONTENT " + foo);
dynamic results = JsonConvert.DeserializeObject<dynamic>(foo);

float downloadSpeed = results.speed.ToObject<float>();

long allSize = 0;

long downloaded = 0;

dynamic check = results.transferring;

if (results["transferring"] != null)
{
long allSize = 0;
long downloaded = 0;

foreach (dynamic obj in results.transferring)
{
allSize += obj["size"].ToObject<long>();
downloaded += obj["bytes"].ToObject<long>();
}

float downloadSpeed = results.speed.ToObject<float>() / 1000000;
allSize /= 1000000;
downloaded /= 1000000;

Debug.WriteLine("Allsize: " + allSize + "\nDownloaded: " + downloaded + "\nValue: " + (downloaded / (double)allSize * 100));
try
{
progressBar.Style = ProgressBarStyle.Continuous;
progressBar.Value = Convert.ToInt32(downloaded / (double)allSize * 100);
}
catch { }

progressBar.Style = ProgressBarStyle.Continuous;
progressBar.Value = Convert.ToInt32(downloaded / (double)allSize * 100);

i++;
downloadSpeed /= 1000000;
if (i == 4)
{
i = 0;
Expand All @@ -2545,7 +2524,6 @@ public async void downloadInstallGameButton_Click(object sender, EventArgs e)

await Task.Delay(100);


}

if (removedownloading)
Expand Down Expand Up @@ -2611,8 +2589,22 @@ public async void downloadInstallGameButton_Click(object sender, EventArgs e)
{
try
{
ChangeTitle("Extracting " + gameName, false);
Zip.ExtractFile($"{Properties.Settings.Default.downloadDir}\\{gameNameHash}\\{gameNameHash}.7z.001", $"{Properties.Settings.Default.downloadDir}", PublicConfigFile.Password);
Thread extractionThread = new Thread(() =>
{
ChangeTitle("Extracting " + gameName, false);
Zip.ExtractFile($"{Properties.Settings.Default.downloadDir}\\{gameNameHash}\\{gameNameHash}.7z.001", $"{Properties.Settings.Default.downloadDir}", PublicConfigFile.Password);
Program.form.ChangeTitle("");
})
{
IsBackground = true
};
extractionThread.Start();

while (extractionThread.IsAlive)
{
await Task.Delay(100);
}

if (Directory.Exists($"{Properties.Settings.Default.downloadDir}\\{gameNameHash}"))
{
Directory.Delete($"{Properties.Settings.Default.downloadDir}\\{gameNameHash}", true);
Expand Down Expand Up @@ -2677,7 +2669,7 @@ public async void downloadInstallGameButton_Click(object sender, EventArgs e)
}
else
{
output.Output += "All tasks finished. ";
output.Output += "All tasks finished. \n";
}
}
if (!isinstalltxt)
Expand Down Expand Up @@ -2749,7 +2741,7 @@ public async void downloadInstallGameButton_Click(object sender, EventArgs e)
}
else
{
output.Output += "All tasks finished. ";
output.Output += "All tasks finished. \n";
}
}
ChangeTitle($"Installation of {gameName} completed.");
Expand Down Expand Up @@ -2777,7 +2769,10 @@ public async void downloadInstallGameButton_Click(object sender, EventArgs e)
ChangeTitle("Refreshing games list, please wait... \n");
showAvailableSpace();
listappsbtn();
initListView();
if (!updateAvailableClicked && !upToDate_Clicked && !NeedsDonation_Clicked)
{
initListView();
}
ShowPrcOutput(output);
progressBar.Style = ProgressBarStyle.Continuous;
etaLabel.Text = "ETA: Finished Queue";
Expand Down Expand Up @@ -3076,15 +3071,9 @@ private async void killRcloneButton_Click(object sender, EventArgs e)
private void otherDrop_Click(object sender, EventArgs e)
{
ShowSubMenu(otherContainer);
if (otherDrop.Text == "▼ OTHER ▼")
{
otherDrop.Text = "▶ OTHER ◀";
}
else if (otherDrop.Text == "▶ OTHER ◀")
{
otherDrop.Text = "▼ OTHER ▼";
}
otherDrop.Text = (otherDrop.Text == "▼ OTHER ▼") ? "▶ OTHER ◀" : "▼ OTHER ▼";
}

private void gamesQueListBox_MouseClick(object sender, MouseEventArgs e)
{
if (gamesQueListBox.SelectedIndex == 0 && gamesQueueList.Count == 1)
Expand Down Expand Up @@ -3185,6 +3174,7 @@ private void CheckEnter(object sender, System.Windows.Forms.KeyPressEventArgs e)
label2.Visible = false;
}
}

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.Control | Keys.F))
Expand Down Expand Up @@ -3363,17 +3353,14 @@ public bool FullScreen

static string ExtractVideoUrl(string html)
{
// Use the regular expression to find the first video URL in the search results page HTML
string pattern = @"url""\:\""/watch\?v\=(.*?(?=""))";
Match match = Regex.Match(html, pattern);
Match match = Regex.Match(html, @"url""\:\""/watch\?v\=(.*?(?=""))");
if (!match.Success)
{
return "";
}
// Extract the video URL from the match

string url = match.Groups[1].Value;
// Create the embed URL
return "https://www.youtube.com/embed/" + url + "?autoplay=1&mute=1&enablejsapi=1&modestbranding=1";
return $"https://www.youtube.com/embed/{url}?autoplay=1&mute=1&enablejsapi=1&modestbranding=1";
}

private async Task CreateEnviroment()
Expand Down Expand Up @@ -3425,14 +3412,17 @@ public async void gamesListView_SelectedIndexChanged(object sender, EventArgs e)
keyheld = true;
}

string[] imageExtensions = { ".jpg", ".png" };
string ImagePath = "";
if (File.Exists($"{SideloaderRCLONE.ThumbnailsFolder}\\{CurrentPackageName}.jpg"))
{
ImagePath = $"{SideloaderRCLONE.ThumbnailsFolder}\\{CurrentPackageName}.jpg";
}
else if (File.Exists($"{SideloaderRCLONE.ThumbnailsFolder}\\{CurrentPackageName}.png"))

foreach (string extension in imageExtensions)
{
ImagePath = $"{SideloaderRCLONE.ThumbnailsFolder}\\{CurrentPackageName}.png";
string path = Path.Combine(SideloaderRCLONE.ThumbnailsFolder, $"{CurrentPackageName}{extension}");
if (File.Exists(path))
{
ImagePath = path;
break;
}
}

if (gamesPictureBox.BackgroundImage != null)
Expand Down Expand Up @@ -3472,20 +3462,15 @@ public async void gamesListView_SelectedIndexChanged(object sender, EventArgs e)
enviromentCreated = true;
}
webView21.Show();
string query = CurrentGameName + " VR trailer";
// Encode the search query for use in a URL
string query = $"{CurrentGameName} VR trailer"; // Create the search query by appending " VR trailer" to the current game name
string encodedQuery = WebUtility.UrlEncode(query);
// Construct the YouTube search URL
string url = "https://www.youtube.com/results?search_query=" + encodedQuery;
string url = $"https://www.youtube.com/results?search_query={encodedQuery}";

// Download the search results page HTML
string html;
using (var client = new WebClient())
string videoUrl;
using (var client = new WebClient()) // Create a WebClient to download the search results page HTML
{
html = client.DownloadString(url);
videoUrl = ExtractVideoUrl(client.DownloadString(url)); // Download the HTML and extract the first video URL
}
// Extract the first video URL from the HTML
string videoUrl = ExtractVideoUrl(html);
if (videoUrl == "")
{
MessageBox.Show("No video URL found in search results.");
Expand Down
24 changes: 22 additions & 2 deletions RCLONE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Management;
using System.Text;
using System.Windows.Forms;

Expand All @@ -12,9 +13,28 @@ internal class RCLONE
//Kill all rclone, using a static rclone variable doesn't work for some reason #tofix
public static void killRclone()
{
foreach (var process in Process.GetProcessesByName("rclone"))
var parentProcessId = Process.GetCurrentProcess().Id;
var processes = Process.GetProcessesByName("rclone");

foreach (var process in processes)
{
process.Kill();
try
{
using (ManagementObject obj = new ManagementObject($"win32_process.handle='{process.Id}'"))
{
obj.Get();
var ppid = Convert.ToInt32(obj["ParentProcessId"]);

if (ppid == parentProcessId)
{
process.Kill();
}
}
}
catch (Exception ex)
{
// Handle exception if the process no longer exists
}
}
}

Expand Down

0 comments on commit f8724ba

Please sign in to comment.