mirror of
https://github.com/muskit/MercuryConverter.git
synced 2026-06-02 20:24:26 -07:00
move source files
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:progRing="clr-namespace:AvaloniaProgressRing;assembly=AvaloniaProgressRing"
|
||||
xmlns:local="clr-namespace:MercuryConverter.UI.Dialogs"
|
||||
x:Class="MercuryConverter.UI.Dialogs.DataScanning"
|
||||
>
|
||||
<Panel Margin="12">
|
||||
<StackPanel>
|
||||
<TextBlock Name="ScanStatus" FontSize="24" FontWeight="Light" Text="select your data folder..."/>
|
||||
<TextBlock Name="ScanPath" IsVisible="false"/>
|
||||
|
||||
<StackPanel Margin="0 6 0 0" Name="ScanError" IsVisible="False">
|
||||
<TextBlock>
|
||||
<Run FontWeight="DemiBold" Text="ERROR" Foreground="Red"/>
|
||||
<LineBreak/>
|
||||
<Run Name="ErrorText" Text="Data pooped its pants"/>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Name="ScanInfo" Margin="0 12 0 12">
|
||||
<TextBlock>
|
||||
<Run FontWeight="Bold" Name="ScanInfoCountText"/>
|
||||
<Run Text="songs added."/>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
|
||||
<Grid ColumnDefinitions="Auto, *" HorizontalAlignment="Stretch">
|
||||
<progRing:ProgressRing Foreground="{DynamicResource SystemBaseMediumColor}"
|
||||
Name="ProgressAnimation"
|
||||
Grid.Column="0"
|
||||
Width="36"
|
||||
Height="36"
|
||||
IsActive="True"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="0,15,0,0"/>
|
||||
<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="BtnSelectFolder" Margin="6 0 0 0" Content="Open Data Folder" Click="OpenDataHandler"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
<!-- <StackPanel Name="SelectErrorView" IsVisible="true">
|
||||
<TextBlock FontSize="24" FontWeight="Light" Text="couldn't fully open data folder"/>
|
||||
<TextBlock Text="Unable to open PATH: ERROR"/>
|
||||
<Button HorizontalAlignment="Right" Margin="0 12 0 0" Content="Open Data Folder" />
|
||||
</StackPanel> -->
|
||||
</Panel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,166 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Platform.Storage;
|
||||
using Avalonia.Threading;
|
||||
using MercuryConverter.Data;
|
||||
|
||||
namespace MercuryConverter.UI.Dialogs;
|
||||
|
||||
public partial class DataScanning : UserControl
|
||||
{
|
||||
public static DataScanning? Instance { get; private set; }
|
||||
|
||||
|
||||
public DataScanning()
|
||||
{
|
||||
Instance = this;
|
||||
InitializeComponent();
|
||||
|
||||
if (!Design.IsDesignMode)
|
||||
RunFlow();
|
||||
}
|
||||
|
||||
public void RunFlow()
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var path = ""; // TODO: set to current/saved data path (move to config?)
|
||||
var selectedPath = await BeginDirSelection();
|
||||
|
||||
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
|
||||
UISetError("No data folder provided.");
|
||||
return;
|
||||
}
|
||||
if (!Directory.Exists(selectedPath))
|
||||
{
|
||||
UISetError("Folder does not exist.");
|
||||
return;
|
||||
}
|
||||
if (!(File.Exists(Path.Combine(selectedPath, "MusicParameterTable.uasset")) && File.Exists(Path.Combine(selectedPath, "MusicParameterTable.uexp"))))
|
||||
{
|
||||
UISetError("Missing MusicParameterTable asset files.\nPlease ensure you've set up your data folder properly!");
|
||||
return;
|
||||
}
|
||||
|
||||
path = selectedPath;
|
||||
|
||||
UIScanningMode(path);
|
||||
Database.SetupNew(path);
|
||||
UIScanCompletedMode();
|
||||
});
|
||||
}
|
||||
|
||||
private void UISelectMode()
|
||||
{
|
||||
UISetError();
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
ScanStatus.Text = "select your data folder...";
|
||||
ScanPath.IsVisible = true;
|
||||
ScanInfo.IsVisible = false;
|
||||
ButtonGroup.IsVisible = false;
|
||||
ProgressAnimation.IsVisible = true;
|
||||
});
|
||||
}
|
||||
|
||||
private void UIScanningMode(string path)
|
||||
{
|
||||
UISetError();
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
ScanStatus.Text = "scanning...";
|
||||
ScanPath.IsVisible = true;
|
||||
ScanPath.Text = path;
|
||||
ScanInfo.IsVisible = false;
|
||||
ButtonGroup.IsVisible = false;
|
||||
ProgressAnimation.IsVisible = true;
|
||||
});
|
||||
}
|
||||
|
||||
private void UIScanCompletedMode()
|
||||
{
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
ScanStatus.Text = "scan complete";
|
||||
ScanPath.IsVisible = true;
|
||||
ScanInfo.IsVisible = true;
|
||||
ScanInfoCountText.Text = Database.Songs.Count.ToString();
|
||||
ButtonGroup.IsVisible = true;
|
||||
ProgressAnimation.IsVisible = false;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use only when a scan is no longer running.
|
||||
/// </summary>
|
||||
/// <param name="error"></param>
|
||||
private void UISetError(string? error = null)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
if (error == null)
|
||||
{
|
||||
ScanError.IsVisible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
ScanError.IsVisible = true;
|
||||
ErrorText.Text = error;
|
||||
ProgressAnimation.IsVisible = false;
|
||||
ButtonGroup.IsVisible = true;
|
||||
ScanStatus.Text = "an error has occurred";
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private async Task<string> BeginDirSelection(string? startDir = null)
|
||||
{
|
||||
IReadOnlyList<IStorageFolder>? dirSelection = null;
|
||||
|
||||
UISelectMode();
|
||||
|
||||
await Dispatcher.UIThread.Invoke(async () =>
|
||||
{
|
||||
await Task.Delay(250);
|
||||
var tl = TopLevel.GetTopLevel(MainWindow.Instance)!;
|
||||
dirSelection = await tl.StorageProvider.OpenFolderPickerAsync
|
||||
(
|
||||
new FolderPickerOpenOptions
|
||||
{
|
||||
Title = "Locate Data Folder",
|
||||
AllowMultiple = false,
|
||||
SuggestedStartLocation = startDir == null ? null : await tl.StorageProvider.TryGetFolderFromPathAsync(startDir),
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
if (dirSelection!.Count <= 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
return dirSelection!.First().TryGetLocalPath()!;
|
||||
}
|
||||
|
||||
private void CloseHandler(object sender, RoutedEventArgs args)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
MainWindow.Instance!.Dialog.IsOpen = false;
|
||||
});
|
||||
}
|
||||
|
||||
private void OpenDataHandler(object sender, RoutedEventArgs args)
|
||||
{
|
||||
RunFlow();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:MercuryConverter.UI.Dialogs"
|
||||
x:Class="MercuryConverter.UI.Dialogs.Welcome"
|
||||
>
|
||||
<StackPanel Margin="12">
|
||||
<TextBlock FontSize="24" FontWeight="Light">
|
||||
welcome to <Run FontWeight="SemiBold" Text="mercury"/>converter!
|
||||
</TextBlock>
|
||||
<TextBlock HorizontalAlignment="Left" Padding="0 6 0 0">
|
||||
<InlineUIContainer>
|
||||
<HyperlinkButton Content="Setup your data folder" Padding="0" NavigateUri="https://github.com/muskit/MercuryConverter/blob/main/HOWTO.md" />
|
||||
</InlineUIContainer>
|
||||
before proceeding.
|
||||
</TextBlock>
|
||||
<Button Content="Open Data Folder" Click="ClickHandler" HorizontalAlignment="Right" Margin="0 24 0 0" />
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using DialogHostAvalonia;
|
||||
|
||||
namespace MercuryConverter.UI.Dialogs;
|
||||
|
||||
public partial class Welcome : Window
|
||||
{
|
||||
public Welcome()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void ClickHandler(object sender, RoutedEventArgs args)
|
||||
{
|
||||
MainWindow.Instance!.Dialog.DialogContent = new DataScanning().Content;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user