I am using WPF Core on VS Community 2019 on Windows. I am creating a game .exe launcher for 'AoK HD.exe'. And am using this video as a base guide:
https://www.youtube.com/watch?v=tDopNcE9lOU. The path of the file is usually in Program Files or Program Files (x86). Although the launcher will most likely be in the same directory as 'AoK HD.exe', it may vary. I would need it to automatically find the .exe only only with the given name. Here is my code so far. I have the MainWindow.xaml.cs, and another class called 'ButtonLauncher.cs', and of course, MainWindow.xaml, where the button is already added.
'MainWindow.xaml.cs':
private void Button_Click(object sender, RoutedEventArgs e)
{
ButtonLauncher.PlayGame();
}
'ButtonLauncher.cs':
using System.Diagnostics;
namespace AoE_II_E_Launcher_EXE
{
class ButtonLauncher
{
public static void PlayGame()
{
Process.Start("AoK HD.exe");
}
What I have tried:
I have tried many things, but none seem to work, and I end up with many errors. My problem is perhaps only me not understanding how to use them in my context.
For example:
string rootDirectory = System.IO.DriveInfo.GetDrives()[0].RootDirectory.FullName;
string[] files = System.IO.Directory.GetFiles(
rootDirectory,
"AoK HD.exe", System.IO.SearchOption.AllDirectories);
The 'rootDirectory' shoves back this error:
Severity Code Description Project File Line Suppression State
Error CS0236 A field initializer cannot reference the non-static field, method, or property 'MainWindow.rootDirectory' AoE II E Launcher EXE C:\Program Files (x86)\Steam\steamapps\common\Age2HD\mods\Interface Evolved\Launcher\AoE II E Launcher EXE\MainWindow.xaml.cs 85 Active
And this:
FileInfo[] subFiles = di.GetFiles("AoK HD.exe", SearchOption.AllDirectories);
FileInfo gives this error:
Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'FileInfo' could not be found (are you missing a using directive or an assembly reference?) AoE II E Launcher EXE C:\Program Files (x86)\Steam\steamapps\common\Age2HD\mods\Interface Evolved\Launcher\AoE II E Launcher EXE\MainWindow.xaml.cs 82 Active
di gives this error:
Severity Code Description Project File Line Suppression State
Error CS0103 The name 'di' does not exist in the current context AoE II E Launcher EXE C:\Program Files (x86)\Steam\steamapps\common\Age2HD\mods\Interface Evolved\Launcher\AoE II E Launcher EXE\MainWindow.xaml.cs 82 Active
And SearchOption gives back this error:
Severity Code Description Project File Line Suppression State
Error CS0103 The name 'SearchOption' does not exist in the current context AoE II E Launcher EXE C:\Program Files (x86)\Steam\steamapps\common\Age2HD\mods\Interface Evolved\Launcher\AoE II E Launcher EXE\MainWindow.xaml.cs 82 Active
I have tried many other things, and am really unsure at this point. As I said, I think the problem is that I don't know where to put this code. I found these snippets of code here:
https://stackoverflow.com/questions/2698801/find-a-application-path
and also how to use them.
Also, I presume that in Process.Start, it would have to include the path name as well, so would the path name have to be a string? Something like this (assuming that the string idea is valid and the string name is AppPath):
'ButtonLauncher.cs':
using System.Diagnostics;
namespace AoE_II_E_Launcher_EXE
{
class ButtonLauncher
{
public static void PlayGame()
{
Process.Start(AppPath + "AoK HD.exe");
}
Do registries come into this also?
I want to make it like this launcher, it has the same premise:
https://www.moddb.com/games/age-of-empires-ii-hd/downloads/age-of-empires-ii-hd-custom-launcher
However, this launcher is outdated and the commands are useless at this point. I would like to update it with new commands and new UI. I used dotPeek to decompile, but did not get much from it, which only led to more confusion, perhaps someone can help me with this?