diff --git a/WindowsFormsApp1/Form2.cs b/WindowsFormsApp1/Form2.cs index c7db085..5849b01 100644 --- a/WindowsFormsApp1/Form2.cs +++ b/WindowsFormsApp1/Form2.cs @@ -9,6 +9,7 @@ using System.Windows.Forms; using System; using System.IO; + namespace WindowsFormsApp1 { public partial class Form2 : Form @@ -31,10 +32,22 @@ private void button3_Click(object sender, EventArgs e) private void button1_Click(object sender, EventArgs e) { - string appDataLocalPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); - // Construct the full path to your directory - string yourDirectoryPath = Path.Combine(appDataLocalPath, "FiveM", "FiveM.app", "data"); + string fivemPath = Utils.GetFiveMPath(); + + if (string.IsNullOrEmpty(fivemPath)) + { + MessageBox.Show("Could not find FiveM installation. Cancelling auto clean up."); + return; + } + + if (!Directory.Exists(fivemPath)) + { + MessageBox.Show("FiveM directory does not exist. Cancelling auto clean up."); + return; + } + + string yourDirectoryPath = Path.Combine(fivemPath, "FiveM.app", "data"); // Check if the main directory exists if (Directory.Exists(yourDirectoryPath)) diff --git a/WindowsFormsApp1/Utils.cs b/WindowsFormsApp1/Utils.cs new file mode 100644 index 0000000..aef3cd0 --- /dev/null +++ b/WindowsFormsApp1/Utils.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WindowsFormsApp1 +{ + internal class Utils + { + public static string GetFiveMPath() + { + string startMenuPath = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu); + string shortcutPath = Path.Combine(startMenuPath, "Programs", "FiveM.lnk"); + + if (!File.Exists(shortcutPath)) + { + return null; + } + + // COM access is a bit gross, but meh + dynamic shell = Activator.CreateInstance(Type.GetTypeFromProgID("WScript.Shell")); + dynamic shortcut = shell.CreateShortcut(shortcutPath); + + string directoryPath = Path.GetDirectoryName(shortcut.TargetPath); + + return directoryPath; + } + } +} diff --git a/WindowsFormsApp1/WindowsFormsApp1.csproj b/WindowsFormsApp1/WindowsFormsApp1.csproj index 1c5401e..9ecab0b 100644 --- a/WindowsFormsApp1/WindowsFormsApp1.csproj +++ b/WindowsFormsApp1/WindowsFormsApp1.csproj @@ -66,6 +66,7 @@ Component + Form1.cs