Skip to content

Commit

Permalink
Fix & Enhance
Browse files Browse the repository at this point in the history
- Use NuGet GeneratePathProperty
- #24
- #181
- #239
  • Loading branch information
AndromedaMelody committed May 30, 2023
1 parent 90d74ab commit 99b0565
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 105 deletions.
81 changes: 35 additions & 46 deletions MisakaTranslator-WPF/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,42 +1,21 @@
<hc:Window x:Class="MisakaTranslator_WPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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:hc="https://handyorg.github.io/handycontrol"
xmlns:fa="http://schemas.fontawesome.io/icons/"
mc:Ignorable="d"
Title="MisakaTranslator"
WindowStartupLocation="CenterScreen"
ShowTitle="True"
Height="540"
Width="960" Closing="BlurWindow_Closing"
ContentRendered="BlurWindow_ContentRendered"
Background="White">
<Window
x:Class="MisakaTranslator_WPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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:hc="https://handyorg.github.io/handycontrol"
xmlns:fa="http://schemas.fontawesome.io/icons/"
mc:Ignorable="d"
d:Height="540" d:Width="960"
Title="MisakaTranslator" Background="White" WindowStartupLocation="CenterScreen"
Closing="BlurWindow_Closing" ContentRendered="BlurWindow_ContentRendered">

<Window.Resources>
<ResourceDictionary Source = "Appearance.xaml"/>
</Window.Resources>
<hc:Window.NonClientAreaContent>
<StackPanel Height="29">
<Menu HorizontalAlignment="Right">
<MenuItem>
<MenuItem.Header>
<fa:FontAwesome Icon="Language" FontSize="16" VerticalAlignment="Center" HorizontalAlignment="Center"></fa:FontAwesome>
</MenuItem.Header>
<MenuItem Header="中文" Click="Language_MenuItem_Click" Tag="zh-cn"/>
<MenuItem Header="English" Click="Language_MenuItem_Click" Tag="en-us"/>
</MenuItem>
</Menu>
</StackPanel>
</hc:Window.NonClientAreaContent>
<Grid Margin="5">
<Grid.Resources>
</Grid.Resources>
<Grid.RowDefinitions>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
</Grid.ColumnDefinitions>

<Grid Margin="5">
<hc:ScrollViewer Grid.Row="0" Grid.Column="1" Margin="10,10,10,10.5" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden" hc:ScrollViewerAttach.Orientation="Horizontal" Grid.ColumnSpan="2">
<hc:WaterfallPanel Name="GameLibraryPanel" VerticalAlignment="Center" HorizontalAlignment="Center" Height="250" Groups="2" Orientation="Vertical" hc:PanelElement.FluidMoveBehavior="{StaticResource BehaviorXY200}">

Expand All @@ -45,26 +24,35 @@


<StackPanel Orientation="Horizontal" Grid.Column="2">
<Button fa:Awesome.Content="Rocket" Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Bottom" Foreground="{DynamicResource MainBtnColor}" FontSize="40" Background="#01FFFFFF" Height="Auto" Width="Auto" Effect="{StaticResource EffectShadow5}" Click="AutoStart_BtnClick" Margin="0,0,0,0.5">
<Button fa:Awesome.Content="Rocket" Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Bottom" Foreground="{DynamicResource MainBtnColor}" FontSize="40" Background="#01FFFFFF" Height="64" Width="64" Effect="{StaticResource EffectShadow5}" Click="AutoStart_BtnClick" Margin="0,0,0,0.5">
<hc:Poptip.Instance>
<hc:Poptip FontSize="15" Foreground="Black" FontFamily="微软雅黑" Content="{StaticResource MainWindow_Tip_AutoStart}" Placement="Right"/>
</hc:Poptip.Instance>
</Button>

<Button fa:Awesome.Content="Book" Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Bottom" Foreground="{DynamicResource MainBtnColor}" FontSize="40" Background="#01FFFFFF" Height="Auto" Width="Auto" Effect="{StaticResource EffectShadow5}" Click="ComicTransBtn_Click" Margin="20,0,0,0.5">
<Button fa:Awesome.Content="Book" Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Bottom" Foreground="{DynamicResource MainBtnColor}" FontSize="40" Background="#01FFFFFF" Height="64" Width="64" Effect="{StaticResource EffectShadow5}" Click="ComicTransBtn_Click" Margin="20,0,0,0.5">
<hc:Poptip.Instance>
<hc:Poptip FontSize="15" Foreground="Black" FontFamily="微软雅黑" Content="{StaticResource MainWindow_Tip_ComicTrans}" Placement="Right"/>
</hc:Poptip.Instance>
</Button>

</StackPanel>


<Button fa:Awesome.Content="Cog" Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Bottom" Foreground="{DynamicResource MainBtnColor}" FontSize="40" Background="#01FFFFFF" Height="Auto" Width="Auto" Effect="{StaticResource EffectShadow5}" Click="SettingsBtn_Click" Margin="0,0,0,0.5">
<hc:Poptip.Instance>
<hc:Poptip FontSize="15" Foreground="Black" FontFamily="微软雅黑" Content="{StaticResource MainWindow_Tip_Settings}" Placement="Left"/>
</hc:Poptip.Instance>
</Button>

<StackPanel Orientation="Horizontal" Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Bottom">
<Button fa:Awesome.Content="Language" Foreground="{DynamicResource MainBtnColor}" FontSize="40" Background="#01FFFFFF" Height="64" Width="64" Effect="{StaticResource EffectShadow5}" Margin="0,0,20,0.5" Click="LanguageBtn_Click">
<Button.ContextMenu>
<ContextMenu x:Name="LanguageContextMenu">
<MenuItem Header="中文" Click="Language_MenuItem_Click" Tag="zh-cn"/>
<MenuItem Header="English" Click="Language_MenuItem_Click" Tag="en-us"/>
</ContextMenu>
</Button.ContextMenu>
</Button>
<Button fa:Awesome.Content="Cog" Foreground="{DynamicResource MainBtnColor}" FontSize="40" Background="#01FFFFFF" Height="64" Width="64" Effect="{StaticResource EffectShadow5}" Click="SettingsBtn_Click" Margin="0,0,0,0.5">
<hc:Poptip.Instance>
<hc:Poptip FontSize="15" Foreground="Black" FontFamily="微软雅黑" Content="{StaticResource MainWindow_Tip_Settings}" Placement="Left"/>
</hc:Poptip.Instance>
</Button>
</StackPanel>

<hc:Drawer Name="AddNewGameDrawer" ShowMode="Press" MaskCanClose="True" Dock="Top">

Expand Down Expand Up @@ -104,7 +92,7 @@
<Button Content="{StaticResource MainWindow_Drawer_Start}" Height="50" Margin="5" Foreground="White" Background="{DynamicResource SuccessBrush}" Click="StartBtn_Click"/>
<Button Content="{StaticResource MainWindow_Drawer_LEStart}" Height="50" Margin="5" Foreground="White" Background="{DynamicResource InfoBrush}" Click="LEStartBtn_Click"/>
<Button Content="{StaticResource MainWindow_Drawer_DeleteGame}" Height="50" Margin="5" Foreground="White" Background="{DynamicResource DangerBrush}" Click="DeleteGameBtn_Click"/>
<Button Content="{StaticResource MainWindow_Drawer_UpdateName}" Height="50" Margin="5" Foreground="White" Background="{DynamicResource WarningBrush}" Click="UpdateNameBtn_Click"/>
<Button Content="{StaticResource MainWindow_Drawer_UpdateName}" Height="50" Margin="5" Foreground="White" Background="{DynamicResource WarningBrush}" Click="UpdateNameBtn_Click"/>
</hc:ButtonGroup>
</Border>

Expand Down Expand Up @@ -134,4 +122,5 @@
</hc:Interaction.Triggers>
</hc:NotifyIcon>
</Grid>
</hc:Window>

</Window>
5 changes: 5 additions & 0 deletions MisakaTranslator-WPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -440,5 +440,10 @@ void GrowlDisableSwitch() {
this.Closing += (o, e) => gw.GetType().GetMethod("Close").Invoke(gw, null); // 关闭主窗口时关闭GrowlWindow否则程序无法退出
}
}

private void LanguageBtn_Click(object sender, RoutedEventArgs e)
{
LanguageContextMenu.IsOpen = true;
}
}
}
26 changes: 16 additions & 10 deletions MisakaTranslator-WPF/MisakaTranslator-WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
<EnableMsixTooling>true</EnableMsixTooling>
<WindowsPackageType>MSIX</WindowsPackageType>
<AllowNeutralPackageWithAppHost>true</AllowNeutralPackageWithAppHost>
<WindowsAppSDKCopyXamlToolingLibs>false</WindowsAppSDKCopyXamlToolingLibs>
<WindowsAppSDKFrameworkPackageReference>false</WindowsAppSDKFrameworkPackageReference>

<WindowsAppSdkBootstrapInitialize>false</WindowsAppSdkBootstrapInitialize>
<WindowsAppSdkDeploymentManagerInitialize>false</WindowsAppSdkDeploymentManagerInitialize>
<WindowsAppSdkFoundation>false</WindowsAppSdkFoundation>
<WindowsAppSdkUndockedRegFreeWinRTInitialize>false</WindowsAppSdkUndockedRegFreeWinRTInitialize>
<WindowsAppSDKWinUI>false</WindowsAppSDKWinUI>
<CustomBeforeMicrosoftCommonTargets>
$(CustomBeforeMicrosoftCommonTargets);
$(PkgMicrosoft_WindowsAppSDK)\build\Microsoft.Build.Msix.props
</CustomBeforeMicrosoftCommonTargets>
<CustomAfterMicrosoftCommonTargets>
$(CustomAfterMicrosoftCommonTargets);
$(PkgMicrosoft_WindowsAppSDK)\build\Microsoft.Build.Msix.targets
</CustomAfterMicrosoftCommonTargets>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -55,14 +56,19 @@
<PackageReference Include="FontAwesome.WPF" Version="4.7.0.9" />
<PackageReference Include="HandyControl" Version="3.4.0" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="$([System.Version]::Parse('$(TargetPlatformVersion)').ToString(3)).*" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.2.230217.4" IncludeAssets="buildTransitive" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.3.230502000" IncludeAssets="none" ExcludeAssets="all" PrivateAssets="all" GeneratePathProperty="true" />
<PackageReference Include="TesseractOCR" Version="5.2.14" Aliases="Tesseract" />
</ItemGroup>

<!-- Workaround for Desktop Bridge -->
<Target Name="BeforeGenerateCurrentProjectAppxManifest" BeforeTargets="_GenerateCurrentProjectAppxManifest">
<PropertyGroup>
<!-- Workaround for Desktop Bridge -->
<TargetPlatformMinVersion Condition="$([System.Version]::Parse('$(TargetPlatformMinVersion)').ToString(2)) &lt; 10.0">10.0.14393.0</TargetPlatformMinVersion>
<TargetPlatformMinVersion Condition="$([System.Version]::Parse('$(TargetPlatformMinVersion)').ToString(2)) &lt; 10.0">10.0.14257.0</TargetPlatformMinVersion>
</PropertyGroup>
</Target>
<Target Name="AfterGenerateCurrentProjectAppxManifest" AfterTargets="_GenerateCurrentProjectAppxManifest">
<PropertyGroup>
<TargetPlatformMinVersion Condition="$(TargetPlatformMinVersion) == '10.0.14257.0'">$(SupportedOSPlatformVersion)</TargetPlatformMinVersion>
</PropertyGroup>
</Target>

Expand Down
2 changes: 1 addition & 1 deletion MisakaTranslator-WPF/Properties/LaunchSettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"profiles": {
"MisakaTranslator (Unpackaged)": {
"MisakaTranslator (Unpackage)": {
"commandName": "Project",
"nativeDebugging": true
},
Expand Down
4 changes: 2 additions & 2 deletions MisakaTranslator-WPF/Properties/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

<Dependencies>
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
<TargetDeviceFamily Name="MSIXCore.Desktop" MinVersion="6.1.7601.0" MaxVersionTested="10.0.10586.0" />
<TargetDeviceFamily Name="MSIXCore.Server" MinVersion="6.1.7601.0" MaxVersionTested="10.0.10586.0" />
<TargetDeviceFamily Name="MSIXCore.Desktop" MinVersion="6.1.7601.0" MaxVersionTested="10.0.14256.0" />
<TargetDeviceFamily Name="MSIXCore.Server" MinVersion="6.1.7601.0" MaxVersionTested="10.0.14256.0" />
</Dependencies>

<Resources>
Expand Down
13 changes: 12 additions & 1 deletion MisakaTranslator-WPF/TranslateWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,14 @@ private void UpdateSource(string repairedText)
stackPanel.Orientation = Orientation.Vertical;
stackPanel.Margin = new Thickness(10, 0, 0, 10);

TextBlock textBlock = new TextBlock();
System.Windows.Controls.TextBox textBlock = new()
{
IsReadOnly = true,
Background = new SolidColorBrush(Colors.Transparent),
BorderBrush = new SolidColorBrush(Colors.Transparent),
Padding = new Thickness(0),
Margin = new Thickness(0)
};
if (!string.IsNullOrEmpty(SourceTextFont))
{
FontFamily fontFamily = new FontFamily(SourceTextFont);
Expand Down Expand Up @@ -771,6 +778,8 @@ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs
dtimer.Stop();

_mecabHelper.Dispose();

Common.mainWin.Visibility = Visibility.Visible;
}


Expand Down Expand Up @@ -866,6 +875,8 @@ private void TransWin_Loaded(object sender, RoutedEventArgs e)
dtimer.Interval = TimeSpan.FromMilliseconds(10);
dtimer.Tick += dtimer_Tick;
dtimer.Start();

Common.mainWin.Visibility = Visibility.Collapsed;
}

void dtimer_Tick(object sender, EventArgs e)
Expand Down
35 changes: 3 additions & 32 deletions SQLHelperLibrary/GameLibraryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,13 @@ public static class GameLibraryHelper
/// <summary>
/// 创建一个新游戏列表库
/// </summary>
public static bool CreateNewGameList()
static GameLibraryHelper()
{
var id = sqlHelper.ExecuteSql("CREATE TABLE IF NOT EXISTS game_library(gameid INTEGER PRIMARY KEY AUTOINCREMENT,gamename TEXT,gamefilepath TEXT,transmode INTEGER,src_lang TEXT,dst_lang TEXT,repair_func TEXT,repair_param_a TEXT,repair_param_b TEXT,hookcode TEXT,isMultiHook TEXT,isx64 TEXT,hookcode_custom TEXT);");
if (id == -1)
{
MessageBox.Show("新建游戏库时发生错误,错误代码:\n" + sqlHelper.GetLastError(), "数据库错误");
return false;
}
else
{
return true;
MessageBox.Show($"初始化游戏库发生错误,数据库错误代码:\n{sqlHelper.GetLastError()}");
throw new Exception(sqlHelper.GetLastError());
}
}

Expand All @@ -105,15 +101,6 @@ public static bool CreateNewGameList()
/// <returns>返回游戏ID</returns>
public static int GetGameID(string gamePath)
{

if (File.Exists(Environment.CurrentDirectory + "\\MisakaGameLibrary.sqlite") == false)
{
if (CreateNewGameList() == false)
{
return -1;
}
}

var ls = sqlHelper.ExecuteReader_OneLine(
$"SELECT gameid FROM game_library WHERE gamefilepath = '{gamePath}';", 1);

Expand All @@ -140,14 +127,6 @@ public static int GetGameID(string gamePath)
/// </summary>
public static List<GameInfo> GetAllGameLibrary()
{
if (File.Exists($"{Environment.CurrentDirectory}\\MisakaGameLibrary.sqlite") == false)
{
if (CreateNewGameList() == false)
{
return null;
}
}

var ls = sqlHelper.ExecuteReader("SELECT * FROM game_library;", 13);

if (ls == null)
Expand Down Expand Up @@ -199,14 +178,6 @@ public static List<GameInfo> GetAllGameLibrary()
/// <param name="gameID"></param>
/// <returns></returns>
public static GameInfo GetGameInfoByID(int gameID) {
if (File.Exists(Environment.CurrentDirectory + "\\MisakaGameLibrary.sqlite") == false)
{
if (CreateNewGameList() == false)
{
return null;
}
}

var ls = sqlHelper.ExecuteReader_OneLine($"SELECT * FROM game_library WHERE gameid = {gameID};", 13);

if (ls == null)
Expand Down
19 changes: 6 additions & 13 deletions SQLHelperLibrary/SQLHelperLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@

<ItemGroup>
<PackageReference Include="Microsoft.Data.SQLite.Core" Version="7.0.4" />
<PackageReference Include="SQLitePCLRaw.lib.e_sqlite3" Version="2.1.4" IncludeAssets="none" ExcludeAssets="all" PrivateAssets="all" />
<PackageReference Include="SQLitePCLRaw.lib.e_sqlite3" Version="2.1.4" IncludeAssets="none" ExcludeAssets="all" PrivateAssets="all" GeneratePathProperty="true" />
<PackageReference Include="SQLitePCLRaw.provider.e_sqlite3" Version="2.1.4" />
<PackageReference Include="SQLitePCLRaw.provider.winsqlite3" Version="2.1.4" />
</ItemGroup>

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<ItemGroup>
<Content Include="$(NuGetPackageRoot)\sqlitepclraw.lib.e_sqlite3\2.1.4\runtimes\win-x86\native\e_sqlite3.dll">
<Link>runtimes\win-x86\native\e_sqlite3.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="$(NuGetPackageRoot)\sqlitepclraw.lib.e_sqlite3\2.1.4\runtimes\win-x64\native\e_sqlite3.dll">
<Link>runtimes\win-x64\native\e_sqlite3.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Target>
<ItemGroup>
<Content Include="$(PkgSQLitePCLRaw_lib_e_sqlite3)\runtimes\win-x86\native\e_sqlite3.dll" Link="runtimes\win-x86\native\e_sqlite3.dll" Visible="false" CopyToOutputDirectory="PreserveNewest" />
<Content Include="$(PkgSQLitePCLRaw_lib_e_sqlite3)\runtimes\win-x64\native\e_sqlite3.dll" Link="runtimes\win-x64\native\e_sqlite3.dll" Visible="false" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>

0 comments on commit 99b0565

Please sign in to comment.