Skip to content

Commit

Permalink
Merge pull request #14 from ccir2429/main
Browse files Browse the repository at this point in the history
added Quick Search functionality that searches for game path in local registry
  • Loading branch information
Narua2010 authored May 8, 2021
2 parents 05be9a6 + 08378b3 commit 9a1d89c
Show file tree
Hide file tree
Showing 4 changed files with 263 additions and 85 deletions.
107 changes: 107 additions & 0 deletions source/GuiVersion/AmongUsModUpdater.ModFunctions/QuickSearch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.ComponentModel;
using System.IO;
using WinForms.Logger;
using Microsoft.Win32;

namespace AmongUsModUpdater.UpdaterFunctions
{
public class QuickSearch
{
private dynamic mainWindow;
private BackgroundWorker worker;

public QuickSearch(dynamic mainWindow)
{
this.mainWindow = mainWindow;
this.mainWindow.ProgressBarSearch.Visible = true;
this.mainWindow.LabelProcessedDrives.Visible = true;
this.mainWindow.ButtonWorkerCancel.Visible = true;
this.mainWindow.ButtonWorkerCancel.Enabled = true;
this.mainWindow.SettingsButtonQuickSearch.Enabled = false;
this.worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(this.backgroundWorker1_DoWork);
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.backgroundWorker1_RunComplete);
worker.ProgressChanged += new ProgressChangedEventHandler(this.backgroundWorker1_ProgressChanged);
worker.WorkerReportsProgress = true;
worker.WorkerSupportsCancellation = true;
}
public void startAsyncWorker()
{
worker.RunWorkerAsync();
}
public void cancelAsyncWorker()
{
// Cancel the asynchronous operation.
worker.CancelAsync();
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
ProgressArgument progressArgument = (ProgressArgument)e.UserState;
this.mainWindow.LabelProcessedDrives.Text = "Searching in registry " + progressArgument.count + " of " + progressArgument.allDrivesLength;
}
private void backgroundWorker1_RunComplete(object sender, RunWorkerCompletedEventArgs ex)
{
if (ex.Cancelled)
{
this.mainWindow.LabelProcessedDrives.Visible = false;
this.mainWindow.ProgressBarSearch.Visible = false;
this.mainWindow.ButtonWorkerCancel.Visible = false;
this.mainWindow.SettingsButtonQuickSearch.Enabled = true;
this.mainWindow.LabelProcessedDrives.Text = "Searching in registry ...";
worker = new BackgroundWorker();
return;
}
if (ex.Result != null)
{
this.mainWindow.SettingsGamePathTextBox.Text = ex.Result.ToString();
worker = new BackgroundWorker();
}
else
{
string message = "The Among Us.exe could not be found. Please search for it manually or install the game.";
string caption = "Error";
MessageBoxButtons buttons = MessageBoxButtons.OK;
DialogResult response = MessageBox.Show(message, caption, buttons);
this.mainWindow.SettingsGamePathTextBox.Text = "";
worker = new BackgroundWorker();
}
this.mainWindow.LabelProcessedDrives.Visible = false;
this.mainWindow.ProgressBarSearch.Visible = false;
this.mainWindow.ButtonWorkerCancel.Visible = false;
this.mainWindow.SettingsButtonQuickSearch.Enabled = true;
worker = new BackgroundWorker();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs ex)
{
string path = "";
try
{
var options = new EnumerationOptions()
{
IgnoreInaccessible = true,
RecurseSubdirectories = false
};
var installPath = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\Valve\\Steam", false).GetValue("InstallPath");
if (installPath != null && !installPath.Equals(string.Empty))
{
path = installPath + @"\steamapps\common\Among Us";
if(Directory.Exists(path))
if (Directory.GetFiles(path, @"Among Us.exe", options).Any())
ex.Result = path;
}
ex.Result = path;
}
catch (Exception e)
{
Logger.Log(null, e);
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace AmongUsModUpdater.UpdaterFunctions
public class SystemFunctions
{
private static AutomatedSearch automatedSearch;
private static QuickSearch quickSearch;

public static void switchPanelVisibility(int y, Panel[] menuPanels, Button[] menuButtons, Panel panelMenuActive)
{
Expand Down Expand Up @@ -47,6 +48,15 @@ public static void cancelAutomatedSearch()
{
automatedSearch.cancelAsyncWorker();
}
public static void startQuickSearch(dynamic mainWindow)
{
quickSearch = new QuickSearch(mainWindow);
quickSearch.startAsyncWorker();
}
public static void cancelQuickSearch()
{
quickSearch.cancelAsyncWorker();
}
public static async Task<bool> copyFolder(string sourceFolder, string destFolder)
{
if (!Directory.Exists(destFolder))
Expand Down
Loading

0 comments on commit 9a1d89c

Please sign in to comment.