Skip to content

Commit

Permalink
版本 1.0.6 更新
Browse files Browse the repository at this point in the history
1. 支持记忆窗口位置、尺寸和状态
2. 支持保存上一次选择的输入输出格式
3. 更换滚动条样式,优化 UI 细节
4. 修复因缺少依赖项导致转换失败的 bug
  • Loading branch information
yqzhishen committed Apr 25, 2022
1 parent c4fe45f commit 61cfa7e
Show file tree
Hide file tree
Showing 12 changed files with 511 additions and 117 deletions.
8 changes: 4 additions & 4 deletions csharp/GUI/AboutDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
<TextBlock Text="OpenSVIP" FontSize="40" FontWeight="Bold"/>
<TextBlock d:Text="框架版本:1.2.0" FontSize="16">
<TextBlock.Text>
<Binding Path="FrameworkVersion" StringFormat="{}框架版本:{0}"/>
<Binding Path="Information.FrameworkVersion" StringFormat="{}框架版本:{0}"/>
</TextBlock.Text>
</TextBlock>
<TextBlock d:Text="应用程序版本:1.0.0 (Preview)" FontSize="16">
<TextBlock.Text>
<Binding Path="Version" StringFormat="{}应用程序版本:{0}"/>
<Binding Path="Information.Version" StringFormat="{}应用程序版本:{0}"/>
</TextBlock.Text>
</TextBlock>
<TextBlock Text="预览版本 暂勿传播" Foreground="#f44336"/>
Expand All @@ -48,13 +48,13 @@
<EventSetter Event="Click" Handler="OpenLinkButton_Click"/>
</Style>
</StackPanel.Resources>
<Button ToolTip="{Binding AuthorHomePage}">
<Button ToolTip="{Binding Information.AuthorHomePage}">
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<materialDesign:PackIcon Kind="User" VerticalAlignment="Center" Margin="-3 0 2 0"/>
<TextBlock Text="作者主页" FontSize="14" Margin="2 0 2 0"/>
</StackPanel>
</Button>
<Button ToolTip="{Binding GitHubRepository}">
<Button ToolTip="{Binding Information.GitHubRepository}">
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<materialDesign:PackIcon Kind="Github" VerticalAlignment="Center" Margin="-3 0 2 0"/>
<TextBlock Text="项目仓库" FontSize="14" Margin="2 0 2 0"/>
Expand Down
1 change: 1 addition & 0 deletions csharp/GUI/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/themes/materialdesigntheme.popupbox.xaml"/>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/themes/materialdesigntheme.chip.xaml"/>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/primary/materialdesigncolor.indigo.xaml"/>
<ResourceDictionary Source="ScrollBarDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
<local:NotNullConverter x:Key="NotNullConverter"/>
<local:IndexToBooleanConverter x:Key="IndexToBooleanConverter"/>
Expand Down
138 changes: 138 additions & 0 deletions csharp/GUI/Configurations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using Tomlet;
using Tomlet.Attributes;
using Tomlet.Models;

namespace OpenSvip.GUI.Config
{
public class AppConfig
{
private const string CONFIG_FOLDER = "Config";

private const string CONFIG_FILENAME = "Configurations.toml";

private static readonly string ActualConfigFolder = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), CONFIG_FOLDER);

private static readonly string ActualConfigFile = Path.Combine(ActualConfigFolder, CONFIG_FILENAME);

[TomlProperty("Restoration")]
public Properties Properties { get; set; } = new Properties();

[TomlProperty("Preference")]
public Settings Settings { get; set; } = new Settings();

static AppConfig()
{
TomletMain.RegisterMapper(
rect => new TomlArray { rect.Left, rect.Top, rect.Width, rect.Height },
tomlValue =>
{
if (!(tomlValue is TomlArray tomlArray))
{
return new Rect();
}
try
{
var arr = tomlArray.Select(val => ((TomlDouble)val).Value).ToArray();
return new Rect(arr[0], arr[1], arr[2], arr[3]);
}
catch
{
return new Rect();
}
});
}

public static AppConfig LoadFromFile()
{
try
{
var stream = new FileStream(ActualConfigFile, FileMode.Open, FileAccess.Read);
var reader = new StreamReader(stream);
var config = TomletMain.To<AppConfig>(reader.ReadToEnd());
reader.Close();
stream.Close();
return config;
}
catch
{
return new AppConfig();
}
}

public void SaveToFile()
{
try
{
Directory.CreateDirectory(ActualConfigFolder);
var stream = new FileStream(ActualConfigFile, FileMode.Create, FileAccess.Write);
var writer = new StreamWriter(stream);
writer.Write(TomletMain.TomlStringFrom(this));
writer.Flush();
stream.Flush();
writer.Close();
stream.Close();
}
catch
{
// ignored
}
}
}

public class Information
{
public string Version { get; set; } = "1.0.6 (Preview)";

public string FrameworkVersion { get; set; } = "1.2.2";

public string Author { get; set; } = "YQ之神";

public string AuthorHomePage { get; set; } = "https://space.bilibili.com/102844209";

public string GitHubRepository { get; set; } = "https://github.com/yqzhishen/opensvip";
}

[TomlDoNotInlineObject]
public class Properties
{
public Rect MainRestoreBounds { get; set; } = new Rect();

public WindowState MainWindowState { get; set; } = WindowState.Normal;
}

public class Settings
{
public string ImportPluginId { get; set; }

public string ExportPluginId { get; set; }

public bool AutoDetectFormat { get; set; } = true;

public bool AutoResetTasks { get; set; } = true;

public bool AutoExtension { get; set; } = true;

public bool OpenExportFolder { get; set; } = false;

public OverwriteOptions OverwriteOption { get; set; } = OverwriteOptions.Overwrite;

public ExportPaths DefaultExportPath { get; set; } = ExportPaths.Unset;

public string[] CustomExportPaths { get; set; } = Array.Empty<string>();
}

public enum OverwriteOptions
{
Overwrite, Skip, Ask
}

public enum ExportPaths
{
Unset, Source, Desktop, Custom
}
}
29 changes: 16 additions & 13 deletions csharp/GUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:OpenSvip.GUI"
xmlns:config="clr-namespace:OpenSvip.GUI.Config"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
Title="OpenSVIP - 歌声合成工程文件转换器(预览版本)"
Expand Down Expand Up @@ -38,11 +39,11 @@
</Grid.RowDefinitions>
<Border Grid.Row="0" Background="WhiteSmoke">
<Border.Resources>
<x:Array x:Key="DefaultExportEnumValues" Type="local:DefaultExport">
<local:DefaultExport>None</local:DefaultExport>
<local:DefaultExport>Source</local:DefaultExport>
<local:DefaultExport>Desktop</local:DefaultExport>
<local:DefaultExport>Custom</local:DefaultExport>
<x:Array x:Key="DefaultExportEnumValues" Type="config:ExportPaths">
<config:ExportPaths>Unset</config:ExportPaths>
<config:ExportPaths>Source</config:ExportPaths>
<config:ExportPaths>Desktop</config:ExportPaths>
<config:ExportPaths>Custom</config:ExportPaths>
</x:Array>
</Border.Resources>
<ComboBox
Expand All @@ -51,7 +52,7 @@
Height="0"
Width="0"
ItemsSource="{StaticResource DefaultExportEnumValues}"
SelectedIndex="{Binding DefaultExportPath, Converter={StaticResource IndexToEnumValueConverter}, ConverterParameter={x:Type local:DefaultExport}}"/>
SelectedIndex="{Binding DefaultExportPath, Converter={StaticResource IndexToEnumValueConverter}, ConverterParameter={x:Type config:ExportPaths}}"/>
</Border>
<DockPanel x:Name="MenuPanel" Grid.Row="0">
<Menu IsMainMenu="True" Margin="20 0 0 0" Height="25" FontFamily="Microsoft YaHei UI" FontSize="13" FontWeight="Normal">
Expand Down Expand Up @@ -386,7 +387,7 @@
DragLeave="FileMaskPanel_UnFocus">
<ItemsControl
x:Name="TaskListView"
Margin="6 5 -5 5"
Margin="6 5 10 5"
ItemsSource="{Binding TaskList}"
Visibility="{Binding HasItems, ElementName=TaskListView, Converter={StaticResource BooleanToVisibilityConverter}}"
IsEnabled="{Binding ExecutionInProgress, Converter={StaticResource InvertBooleanConverter}}"
Expand Down Expand Up @@ -486,6 +487,7 @@
</MultiBinding>
</StackPanel.Visibility>
<StackPanel.Resources>
<Style TargetType="ScrollViewer" BasedOn="{StaticResource MaterialDesignScrollViewer}"/>
<Style TargetType="TreeView" BasedOn="{StaticResource MaterialDesignTreeView}">
<Setter Property="ScrollViewer.PanningMode" Value="None"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled"/>
Expand All @@ -502,10 +504,10 @@
<Setter Property="MaxWidth">
<Setter.Value>
<Binding
RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=TreeView}"
RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=materialDesign:Card}"
Path="ActualWidth"
Converter="{StaticResource DoubleConstantSubConverter}"
ConverterParameter="140"/>
ConverterParameter="160"/>
</Setter.Value>
</Setter>
</Style>
Expand All @@ -531,7 +533,7 @@
<WrapPanel
Grid.Row="1"
Orientation="Horizontal"
Width="{Binding ActualWidth, ElementName=ConverterOptionsCard, Converter={StaticResource DoubleConstantSubConverter}, ConverterParameter=70}">
Width="{Binding ActualWidth, ElementName=ConverterOptionsCard, Converter={StaticResource DoubleConstantSubConverter}, ConverterParameter=64}">
<local:OptionTreeViewItem DataContext="{Binding}" VerticalAlignment="Center" HorizontalAlignment="Stretch"/>
</WrapPanel>
</Grid>
Expand All @@ -554,7 +556,7 @@
<TextBlock Style="{StaticResource TreeViewHeaderComment}" Text="["/>
<TextBlock Style="{StaticResource TreeViewHeaderComment}" Margin="7 2 0 0">
<TextBlock.Text>
<Binding Path="SelectedInputPlugin.Format" StringFormat="{}导入自 {0}"/>
<Binding Path="SelectedInputFormat" StringFormat="{}导入自 {0}" Mode="OneWay"/>
</TextBlock.Text>
</TextBlock>
<TextBlock Style="{StaticResource TreeViewHeaderComment}" Text="]" Margin="7 2 0 0"/>
Expand Down Expand Up @@ -582,7 +584,7 @@
<TextBlock Style="{StaticResource TreeViewHeaderComment}" Text="["/>
<TextBlock Style="{StaticResource TreeViewHeaderComment}" Margin="7 2 0 0">
<TextBlock.Text>
<Binding Path="SelectedOutputPlugin.Format" StringFormat="{}导出为 {0}"/>
<Binding Path="SelectedOutputFormat" StringFormat="{}导出为 {0}" Mode="OneWay"/>
</TextBlock.Text>
</TextBlock>
<TextBlock Style="{StaticResource TreeViewHeaderComment}" Text="]" Margin="7 2 0 0"/>
Expand Down Expand Up @@ -654,6 +656,7 @@
<TextBox
VerticalAlignment="Center"
Margin="10 0"
Padding="0 2"
materialDesign:HintAssist.Hint="{Binding IsChecked, ElementName=ExportToSourceMenuItem, Converter={StaticResource BooleanSwitchOperationConverter}, ConverterParameter=输出路径(本次);输出路径}"
Text="{Binding ExportPath}"
FontSize="16"
Expand Down Expand Up @@ -684,7 +687,7 @@
FontSize="14"
materialDesign:ComboBoxAssist.ShowSelectedItem="False"
IsEnabled="{Binding ExecutionInProgress, Converter={StaticResource InvertBooleanConverter}}"
SelectedIndex="{Binding OverWriteOption, Converter={StaticResource IndexToEnumValueConverter}, ConverterParameter={x:Type local:OverwriteOptions}}">
SelectedIndex="{Binding OverWriteOption, Converter={StaticResource IndexToEnumValueConverter}, ConverterParameter={x:Type config:OverwriteOptions}}">
<ComboBoxItem IsSelected="True" Content="覆盖"/>
<ComboBoxItem Content="跳过"/>
<ComboBoxItem Content="询问"/>
Expand Down
Loading

0 comments on commit 61cfa7e

Please sign in to comment.