mirror of
https://github.com/muskit/MercuryConverter.git
synced 2026-06-02 20:24:26 -07:00
add settings wrt data path
This commit is contained in:
@@ -19,8 +19,10 @@
|
|||||||
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
||||||
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
|
||||||
<PackageReference Include="Deadpikle.AvaloniaProgressRing" Version="0.10.10" />
|
<PackageReference Include="Deadpikle.AvaloniaProgressRing" Version="0.10.10" />
|
||||||
<PackageReference Include="DialogHost.Avalonia" Version="0.9.3" />
|
<PackageReference Include="DialogHost.Avalonia" Version="0.9.3" />
|
||||||
|
<PackageReference Include="ini-parser" Version="2.5.2" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -1,11 +1,12 @@
|
|||||||
namespace MercuryConverter;
|
namespace MercuryConverter;
|
||||||
|
|
||||||
using Avalonia;
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
using MercuryConverter.UI;
|
using Avalonia;
|
||||||
using Avalonia.Logging;
|
using Avalonia.Logging;
|
||||||
|
|
||||||
|
using MercuryConverter.UI;
|
||||||
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
// Initialization code. Don't use any Avalonia, third-party APIs or any
|
// Initialization code. Don't use any Avalonia, third-party APIs or any
|
||||||
@@ -14,16 +15,15 @@ class Program
|
|||||||
[STAThread]
|
[STAThread]
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
// BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
|
new Settings();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// prepare and run your App here
|
|
||||||
BuildAvaloniaApp()
|
BuildAvaloniaApp()
|
||||||
.StartWithClassicDesktopLifetime(args);
|
.StartWithClassicDesktopLifetime(args);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
// here we can work with the exception, for example add it to our log file
|
|
||||||
Console.WriteLine($"App exception!!\b{e}");
|
Console.WriteLine($"App exception!!\b{e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
Margin="0,15,0,0"/>
|
Margin="0,15,0,0"/>
|
||||||
<StackPanel Margin="0 12 0 0" Name="ButtonGroup" Orientation="Horizontal" Grid.Column="1" HorizontalAlignment="Right" IsVisible="false">
|
<StackPanel Margin="0 12 0 0" Name="ButtonGroup" Orientation="Horizontal" Grid.Column="1" HorizontalAlignment="Right" IsVisible="false">
|
||||||
<Button Name="BtnClose" Margin="6 0 0 0" Content="Close" Click="CloseHandler"/>
|
<Button Name="BtnClose" Margin="6 0 0 0" Content="Close" Click="CloseHandler"/>
|
||||||
<Button Name="BtnSelectFolder" Margin="6 0 0 0" Content="Open Data Folder" Click="OpenDataHandler"/>
|
<Button Name="BtnSelectFolder" Margin="6 0 0 0" Content="Open Data Folder" Click="OpenFolderHandler"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -12,12 +13,12 @@ namespace MercuryConverter.UI.Dialogs;
|
|||||||
|
|
||||||
public partial class DataScanning : UserControl
|
public partial class DataScanning : UserControl
|
||||||
{
|
{
|
||||||
public static DataScanning? Instance { get; private set; }
|
private bool requiresUser;
|
||||||
|
|
||||||
|
public DataScanning(bool requiresUser = true)
|
||||||
public DataScanning()
|
|
||||||
{
|
{
|
||||||
Instance = this;
|
this.requiresUser = requiresUser;
|
||||||
|
Console.WriteLine($"DataScan should stay open: {requiresUser}");
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
if (!Design.IsDesignMode)
|
if (!Design.IsDesignMode)
|
||||||
@@ -28,34 +29,42 @@ public partial class DataScanning : UserControl
|
|||||||
{
|
{
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
var path = ""; // TODO: set to current/saved data path (move to config?)
|
if (Settings.I!.DataPath == "" || requiresUser) // no data path saved
|
||||||
var selectedPath = await BeginDirSelection();
|
{
|
||||||
|
var selectedPath = await BeginDirSelection(Settings.I!.DataPath);
|
||||||
if (selectedPath == "") // cancelled opening folder
|
if (selectedPath == "") // cancelled opening folder
|
||||||
{
|
{
|
||||||
// TODO:
|
// TODO:
|
||||||
// return and go to completed mode if scan already completed
|
// return and go to completed mode if scan already completed
|
||||||
// continue if no scan has been completed
|
// continue if no scan has been completed
|
||||||
// break if we already have a path but somehow not scanned
|
// break if we already have a path but somehow not scanned
|
||||||
|
Dispatcher.UIThread.Post(() => ScanPath.Text = "");
|
||||||
UISetError("No data folder provided.");
|
UISetError("No data folder provided.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!Directory.Exists(selectedPath))
|
Settings.I.DataPath = selectedPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
Dispatcher.UIThread.Post(() => ScanPath.Text = Settings.I.DataPath);
|
||||||
|
if (!Directory.Exists(Settings.I.DataPath))
|
||||||
{
|
{
|
||||||
UISetError("Folder does not exist.");
|
UISetError("Folder does not exist.");
|
||||||
return;
|
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!");
|
UISetError("Missing MusicParameterTable asset files.\nPlease ensure you've set up your data folder properly!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
path = selectedPath;
|
UIScanningMode(Settings.I.DataPath);
|
||||||
|
Database.SetupNew(Settings.I.DataPath);
|
||||||
|
|
||||||
UIScanningMode(path);
|
if (requiresUser) // TODO: or if there are warnings
|
||||||
Database.SetupNew(path);
|
|
||||||
UIScanCompletedMode();
|
UIScanCompletedMode();
|
||||||
|
else
|
||||||
|
Dispatcher.UIThread.Post(() => MainWindow.Instance!.Dialog.IsOpen = false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +74,7 @@ public partial class DataScanning : UserControl
|
|||||||
Dispatcher.UIThread.Post(() =>
|
Dispatcher.UIThread.Post(() =>
|
||||||
{
|
{
|
||||||
ScanStatus.Text = "select your data folder...";
|
ScanStatus.Text = "select your data folder...";
|
||||||
ScanPath.IsVisible = true;
|
ScanPath.IsVisible = false;
|
||||||
ScanInfo.IsVisible = false;
|
ScanInfo.IsVisible = false;
|
||||||
ButtonGroup.IsVisible = false;
|
ButtonGroup.IsVisible = false;
|
||||||
ProgressAnimation.IsVisible = true;
|
ProgressAnimation.IsVisible = true;
|
||||||
@@ -105,6 +114,7 @@ public partial class DataScanning : UserControl
|
|||||||
/// <param name="error"></param>
|
/// <param name="error"></param>
|
||||||
private void UISetError(string? error = null)
|
private void UISetError(string? error = null)
|
||||||
{
|
{
|
||||||
|
requiresUser = true;
|
||||||
Dispatcher.UIThread.Post(() =>
|
Dispatcher.UIThread.Post(() =>
|
||||||
{
|
{
|
||||||
if (error == null)
|
if (error == null)
|
||||||
@@ -115,6 +125,8 @@ public partial class DataScanning : UserControl
|
|||||||
|
|
||||||
ScanError.IsVisible = true;
|
ScanError.IsVisible = true;
|
||||||
ErrorText.Text = error;
|
ErrorText.Text = error;
|
||||||
|
ScanPath.IsVisible = ScanPath.Text == "" ? false : true;
|
||||||
|
ScanInfo.IsVisible = false;
|
||||||
ProgressAnimation.IsVisible = false;
|
ProgressAnimation.IsVisible = false;
|
||||||
ButtonGroup.IsVisible = true;
|
ButtonGroup.IsVisible = true;
|
||||||
ScanStatus.Text = "an error has occurred";
|
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();
|
RunFlow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,6 @@ public partial class Welcome : Window
|
|||||||
|
|
||||||
private void ClickHandler(object sender, RoutedEventArgs args)
|
private void ClickHandler(object sender, RoutedEventArgs args)
|
||||||
{
|
{
|
||||||
MainWindow.Instance!.Dialog.DialogContent = new DataScanning().Content;
|
MainWindow.Instance!.Dialog.DialogContent = new DataScanning(true).Content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,8 @@
|
|||||||
xmlns:local="clr-namespace:MercuryConverter.UI"
|
xmlns:local="clr-namespace:MercuryConverter.UI"
|
||||||
x:Class="MercuryConverter.UI.MainWindow"
|
x:Class="MercuryConverter.UI.MainWindow"
|
||||||
|
|
||||||
|
xmlns:views="clr-namespace:MercuryConverter.UI.Views"
|
||||||
|
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
Title="MercuryConverter"
|
Title="MercuryConverter"
|
||||||
Width="1024" Height="800"
|
Width="1024" Height="800"
|
||||||
@@ -40,7 +42,7 @@
|
|||||||
|
|
||||||
<TabControl>
|
<TabControl>
|
||||||
<TabItem Name="TabSelection" Header="selection">
|
<TabItem Name="TabSelection" Header="selection">
|
||||||
<UserControl Name="SelectionControl"/>
|
<views:Selection />
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
||||||
<TabItem Header="export">
|
<TabItem Header="export">
|
||||||
|
|||||||
@@ -27,9 +27,6 @@ public partial class MainWindow : Window
|
|||||||
RequestedThemeVariant = ThemeVariant.Dark;
|
RequestedThemeVariant = ThemeVariant.Dark;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup tab views
|
|
||||||
SelectionControl.Content = new Selection();
|
|
||||||
|
|
||||||
// Show dialog on startup
|
// Show dialog on startup
|
||||||
Activated += OnActivated;
|
Activated += OnActivated;
|
||||||
|
|
||||||
@@ -42,8 +39,12 @@ public partial class MainWindow : Window
|
|||||||
if (initialShown) return;
|
if (initialShown) return;
|
||||||
initialShown = true;
|
initialShown = true;
|
||||||
|
|
||||||
Dialog.DialogContent = new Welcome().Content;
|
Dispatcher.UIThread.Post(() =>
|
||||||
|
{
|
||||||
Dialog.IsOpen = true;
|
Dialog.IsOpen = true;
|
||||||
|
Dialog.DialogContent = Settings.I!.DataPath == "" ?
|
||||||
|
new Welcome().Content : new DataScanning(false).Content;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDbSelChanged(object? sender, NotifyCollectionChangedEventArgs e)
|
private void OnDbSelChanged(object? sender, NotifyCollectionChangedEventArgs e)
|
||||||
@@ -57,7 +58,7 @@ public partial class MainWindow : Window
|
|||||||
public void OpenDataHandler()
|
public void OpenDataHandler()
|
||||||
{
|
{
|
||||||
Dialog.IsOpen = true;
|
Dialog.IsOpen = true;
|
||||||
Dialog.DialogContent = new DataScanning().Content;
|
Dialog.DialogContent = new DataScanning(true).Content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenDataHOWTO()
|
public void OpenDataHOWTO()
|
||||||
|
|||||||
Reference in New Issue
Block a user