Store data in AppData

This commit is contained in:
Stone_Red
2023-03-19 00:42:48 +01:00
parent cee54c9364
commit ae580599cb
2 changed files with 27 additions and 11 deletions
+18 -7
View File
@@ -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;
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
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);
}
}
+9 -4
View File
@@ -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)