diff --git a/ClipCMD/App.xaml.cs b/ClipCMD/App.xaml.cs index cbe8a7e..7680b24 100644 --- a/ClipCMD/App.xaml.cs +++ b/ClipCMD/App.xaml.cs @@ -1,15 +1,26 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Data; -using System.Linq; -using System.Threading.Tasks; +using System.Threading; using System.Windows; namespace ClipCMD; + /// /// Interaction logic for App.xaml /// public partial class App : Application { -} + protected override void OnStartup(StartupEventArgs e) + { + const string appName = "ClipCMD"; + + _ = new Mutex(true, appName, out bool createdNew); + + if (!createdNew) + { + //App is already running! Exiting the application + _ = MessageBox.Show($"Another instance of {appName} already running!", $"{appName} is already running!", MessageBoxButton.OK, MessageBoxImage.Exclamation); + Current.Shutdown(); + } + + base.OnStartup(e); + } +} \ No newline at end of file diff --git a/ClipCMD/MainWindow.xaml.cs b/ClipCMD/MainWindow.xaml.cs index 6cf7d13..f86d16b 100644 --- a/ClipCMD/MainWindow.xaml.cs +++ b/ClipCMD/MainWindow.xaml.cs @@ -44,11 +44,16 @@ public partial class MainWindow : Window InitializeComponent(); - string filePath = System.Reflection.Assembly.GetExecutingAssembly().Location; - string workPath = Path.GetDirectoryName(filePath) ?? "/"; + string applicationDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); + string folderPath = Path.Combine(applicationDataPath, "ClipCMD"); - cmdPath = Path.Combine(workPath, "cmd.txt"); - fixPath = Path.Combine(workPath, "fix.txt"); + if (!Directory.Exists(folderPath)) + { + _ = Directory.CreateDirectory(folderPath); + } + + cmdPath = Path.Combine(folderPath, "cmd.txt"); + fixPath = Path.Combine(folderPath, "fix.txt"); } protected override void OnSourceInitialized(EventArgs e)