diff --git a/src/MercuryConverter.csproj b/src/MercuryConverter.csproj
index 684364a..04eddad 100644
--- a/src/MercuryConverter.csproj
+++ b/src/MercuryConverter.csproj
@@ -19,8 +19,10 @@
None
All
+
+
diff --git a/src/Program.cs b/src/Program.cs
index 17e17b1..c10c255 100644
--- a/src/Program.cs
+++ b/src/Program.cs
@@ -1,11 +1,12 @@
namespace MercuryConverter;
-using Avalonia;
using System;
-using MercuryConverter.UI;
+using Avalonia;
using Avalonia.Logging;
+using MercuryConverter.UI;
+
class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
@@ -14,16 +15,15 @@ class Program
[STAThread]
public static void Main(string[] args)
{
- // BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
+ new Settings();
+
try
{
- // prepare and run your App here
BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
}
catch (Exception e)
{
- // here we can work with the exception, for example add it to our log file
Console.WriteLine($"App exception!!\b{e}");
}
}
diff --git a/src/Settings.cs b/src/Settings.cs
new file mode 100644
index 0000000..bd5b41a
--- /dev/null
+++ b/src/Settings.cs
@@ -0,0 +1,94 @@
+using System;
+using System.ComponentModel;
+using System.IO;
+using CommunityToolkit.Mvvm.ComponentModel;
+using IniParser;
+using IniParser.Model;
+
+namespace MercuryConverter;
+
+public enum Theme
+{
+ Light, Dark, System
+}
+
+public partial class Settings : ObservableObject
+{
+ public static Settings? I;
+
+ private string iniPath;
+
+ public string AppDataPath =>
+ Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "muskit", "MercuryConverter");
+
+ [ObservableProperty]
+ private string dataPath = "";
+ [ObservableProperty]
+ private Theme theme = Theme.System;
+
+ protected override void OnPropertyChanged(PropertyChangedEventArgs e)
+ {
+ Console.Write($"Setting {e.PropertyName} changed to ");
+ switch (e.PropertyName)
+ {
+ case nameof(DataPath):
+ Console.WriteLine(DataPath);
+ break;
+ default:
+ Console.WriteLine("unknown variable");
+ break;
+ }
+ SaveToIni();
+
+ base.OnPropertyChanged(e);
+ }
+
+ public Settings()
+ {
+ I = this;
+
+ Console.WriteLine($"Settings path: {AppDataPath}");
+ iniPath = Path.Combine(AppDataPath, "settings.ini");
+
+ // Attempt to read settings; try to create new if unable to
+ try
+ {
+ LoadFromIni();
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine($"Couldn't read {iniPath}!\n{e.Message}");
+ Console.WriteLine("Attempting to create new settings file.");
+ SaveToIni();
+ }
+ }
+
+ private void SaveToIni()
+ {
+ var data = new IniData();
+ data["paths"]["data"] = DataPath;
+ data["ui"]["theme"] = Theme.ToString();
+
+ try
+ {
+ Directory.CreateDirectory(Path.GetDirectoryName(iniPath)!);
+ FileIniDataParser parser = new();
+ parser.WriteFile(iniPath, data);
+ Console.WriteLine($"Settings saved to {iniPath}.");
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine($"Could not save settings to {iniPath}!\n{e.Message}");
+ }
+ }
+
+ private void LoadFromIni()
+ {
+ FileIniDataParser parser = new();
+ var iniData = parser.ReadFile(iniPath);
+
+ DataPath = iniData["paths"]["data"];
+ if (Enum.TryParse(iniData["ui"]["theme"], out Theme loadedTheme))
+ Theme = loadedTheme;
+ }
+}
\ No newline at end of file
diff --git a/src/UI/Dialogs/DataScanning.axaml b/src/UI/Dialogs/DataScanning.axaml
index 39a12b2..8d77377 100644
--- a/src/UI/Dialogs/DataScanning.axaml
+++ b/src/UI/Dialogs/DataScanning.axaml
@@ -37,7 +37,7 @@
Margin="0,15,0,0"/>
-
+
diff --git a/src/UI/Dialogs/DataScanning.axaml.cs b/src/UI/Dialogs/DataScanning.axaml.cs
index 2a8f09c..7ea0b89 100644
--- a/src/UI/Dialogs/DataScanning.axaml.cs
+++ b/src/UI/Dialogs/DataScanning.axaml.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -12,12 +13,12 @@ namespace MercuryConverter.UI.Dialogs;
public partial class DataScanning : UserControl
{
- public static DataScanning? Instance { get; private set; }
+ private bool requiresUser;
-
- public DataScanning()
+ public DataScanning(bool requiresUser = true)
{
- Instance = this;
+ this.requiresUser = requiresUser;
+ Console.WriteLine($"DataScan should stay open: {requiresUser}");
InitializeComponent();
if (!Design.IsDesignMode)
@@ -28,34 +29,42 @@ public partial class DataScanning : UserControl
{
Task.Run(async () =>
{
- var path = ""; // TODO: set to current/saved data path (move to config?)
- var selectedPath = await BeginDirSelection();
-
- if (selectedPath == "") // cancelled opening folder
+ if (Settings.I!.DataPath == "" || requiresUser) // no data path saved
{
- // TODO:
- // return and go to completed mode if scan already completed
- // continue if no scan has been completed
- // break if we already have a path but somehow not scanned
- UISetError("No data folder provided.");
- return;
+ var selectedPath = await BeginDirSelection(Settings.I!.DataPath);
+ if (selectedPath == "") // cancelled opening folder
+ {
+ // TODO:
+ // return and go to completed mode if scan already completed
+ // continue if no scan has been completed
+ // break if we already have a path but somehow not scanned
+ Dispatcher.UIThread.Post(() => ScanPath.Text = "");
+ UISetError("No data folder provided.");
+ return;
+ }
+ Settings.I.DataPath = selectedPath;
}
- if (!Directory.Exists(selectedPath))
+
+ Dispatcher.UIThread.Post(() => ScanPath.Text = Settings.I.DataPath);
+ if (!Directory.Exists(Settings.I.DataPath))
{
UISetError("Folder does not exist.");
return;
}
- if (!(File.Exists(Path.Combine(selectedPath, "MusicParameterTable.uasset")) && File.Exists(Path.Combine(selectedPath, "MusicParameterTable.uexp"))))
+ if (!(File.Exists(Path.Combine(Settings.I.DataPath, "MusicParameterTable.uasset"))
+ && File.Exists(Path.Combine(Settings.I.DataPath, "MusicParameterTable.uexp"))))
{
UISetError("Missing MusicParameterTable asset files.\nPlease ensure you've set up your data folder properly!");
return;
}
- path = selectedPath;
+ UIScanningMode(Settings.I.DataPath);
+ Database.SetupNew(Settings.I.DataPath);
- UIScanningMode(path);
- Database.SetupNew(path);
- UIScanCompletedMode();
+ if (requiresUser) // TODO: or if there are warnings
+ UIScanCompletedMode();
+ else
+ Dispatcher.UIThread.Post(() => MainWindow.Instance!.Dialog.IsOpen = false);
});
}
@@ -65,7 +74,7 @@ public partial class DataScanning : UserControl
Dispatcher.UIThread.Post(() =>
{
ScanStatus.Text = "select your data folder...";
- ScanPath.IsVisible = true;
+ ScanPath.IsVisible = false;
ScanInfo.IsVisible = false;
ButtonGroup.IsVisible = false;
ProgressAnimation.IsVisible = true;
@@ -105,6 +114,7 @@ public partial class DataScanning : UserControl
///
private void UISetError(string? error = null)
{
+ requiresUser = true;
Dispatcher.UIThread.Post(() =>
{
if (error == null)
@@ -115,6 +125,8 @@ public partial class DataScanning : UserControl
ScanError.IsVisible = true;
ErrorText.Text = error;
+ ScanPath.IsVisible = ScanPath.Text == "" ? false : true;
+ ScanInfo.IsVisible = false;
ProgressAnimation.IsVisible = false;
ButtonGroup.IsVisible = true;
ScanStatus.Text = "an error has occurred";
@@ -159,8 +171,9 @@ public partial class DataScanning : UserControl
});
}
- private void OpenDataHandler(object sender, RoutedEventArgs args)
+ private void OpenFolderHandler(object sender, RoutedEventArgs args)
{
+ requiresUser = true;
RunFlow();
}
}
\ No newline at end of file
diff --git a/src/UI/Dialogs/Welcome.axaml.cs b/src/UI/Dialogs/Welcome.axaml.cs
index 1616e4d..cca56e4 100644
--- a/src/UI/Dialogs/Welcome.axaml.cs
+++ b/src/UI/Dialogs/Welcome.axaml.cs
@@ -14,6 +14,6 @@ public partial class Welcome : Window
private void ClickHandler(object sender, RoutedEventArgs args)
{
- MainWindow.Instance!.Dialog.DialogContent = new DataScanning().Content;
+ MainWindow.Instance!.Dialog.DialogContent = new DataScanning(true).Content;
}
}
\ No newline at end of file
diff --git a/src/UI/MainWindow.axaml b/src/UI/MainWindow.axaml
index eb382ac..de17327 100644
--- a/src/UI/MainWindow.axaml
+++ b/src/UI/MainWindow.axaml
@@ -5,6 +5,8 @@
xmlns:dialogHost="clr-namespace:DialogHostAvalonia;assembly=DialogHost.Avalonia"
xmlns:local="clr-namespace:MercuryConverter.UI"
x:Class="MercuryConverter.UI.MainWindow"
+
+ xmlns:views="clr-namespace:MercuryConverter.UI.Views"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
Title="MercuryConverter"
@@ -40,7 +42,7 @@
-
+
diff --git a/src/UI/MainWindow.axaml.cs b/src/UI/MainWindow.axaml.cs
index 3c4da04..fbcc628 100644
--- a/src/UI/MainWindow.axaml.cs
+++ b/src/UI/MainWindow.axaml.cs
@@ -27,9 +27,6 @@ public partial class MainWindow : Window
RequestedThemeVariant = ThemeVariant.Dark;
}
- // Setup tab views
- SelectionControl.Content = new Selection();
-
// Show dialog on startup
Activated += OnActivated;
@@ -42,8 +39,12 @@ public partial class MainWindow : Window
if (initialShown) return;
initialShown = true;
- Dialog.DialogContent = new Welcome().Content;
- Dialog.IsOpen = true;
+ Dispatcher.UIThread.Post(() =>
+ {
+ Dialog.IsOpen = true;
+ Dialog.DialogContent = Settings.I!.DataPath == "" ?
+ new Welcome().Content : new DataScanning(false).Content;
+ });
}
private void OnDbSelChanged(object? sender, NotifyCollectionChangedEventArgs e)
@@ -57,7 +58,7 @@ public partial class MainWindow : Window
public void OpenDataHandler()
{
Dialog.IsOpen = true;
- Dialog.DialogContent = new DataScanning().Content;
+ Dialog.DialogContent = new DataScanning(true).Content;
}
public void OpenDataHOWTO()