perf: remove handycontrol and local exe

dev_without_third_libraries
SONGE9B3\song_pd_win11 2 years ago
parent fc92ba7263
commit 2d63969503

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>

@ -3,11 +3,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml"> StartupUri="MainWindow.xaml">
<Application.Resources> <Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml" />
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources> </Application.Resources>
</Application> </Application>

@ -5,7 +5,6 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:STranslate.ViewModel" xmlns:vm="clr-namespace:STranslate.ViewModel"
xmlns:model="clr-namespace:STranslate.Model" xmlns:model="clr-namespace:STranslate.Model"
xmlns:hc="https://handyorg.github.io/handycontrol"
mc:Ignorable="d" mc:Ignorable="d"
Background="Transparent" Background="Transparent"
WindowStartupLocation="CenterScreen" WindowStartupLocation="CenterScreen"
@ -91,11 +90,6 @@
BorderThickness="0" BorderThickness="0"
Command="{Binding CopyInputCmd}"> Command="{Binding CopyInputCmd}">
<Image Source="/Images/copy2.png"/> <Image Source="/Images/copy2.png"/>
<hc:FloatingBlock.ContentTemplate>
<DataTemplate>
<TextBlock Text="copied" />
</DataTemplate>
</hc:FloatingBlock.ContentTemplate>
</Button> </Button>
<Border Margin="10,0,0,0" <Border Margin="10,0,0,0"
Background="#eaeaea" Background="#eaeaea"
@ -125,7 +119,6 @@
BorderThickness="0" /> BorderThickness="0" />
<ComboBox x:Name="InCombo" <ComboBox x:Name="InCombo"
Background="#f6f6f6" Background="#f6f6f6"
Style="{StaticResource ComboBox.Small}"
ItemsSource="{Binding InputCombo}" ItemsSource="{Binding InputCombo}"
SelectedItem="{Binding InputComboSelected}" /> SelectedItem="{Binding InputComboSelected}" />
<Separator Margin="20,0"/> <Separator Margin="20,0"/>
@ -134,7 +127,6 @@
BorderThickness="0" /> BorderThickness="0" />
<ComboBox x:Name="OutCombo" <ComboBox x:Name="OutCombo"
Background="#f6f6f6" Background="#f6f6f6"
Style="{StaticResource ComboBox.Small}"
ItemsSource="{Binding OutputCombo}" ItemsSource="{Binding OutputCombo}"
SelectedItem="{Binding OutputComboSelected}" /> SelectedItem="{Binding OutputComboSelected}" />
</StackPanel> </StackPanel>
@ -152,8 +144,7 @@
Margin="5" Margin="5"
Height="{Binding ElementName=Output, Path=Height}"> Height="{Binding ElementName=Output, Path=Height}">
<Grid> <Grid>
<hc:TextBox x:Name="TextBoxOutput" <TextBox x:Name="TextBoxOutput"
hc:InfoElement.Placeholder="翻译结果"
Background="Transparent" Background="Transparent"
BorderBrush="{x:Null}" BorderBrush="{x:Null}"
BorderThickness="0" BorderThickness="0"
@ -180,11 +171,6 @@
Visibility="{Binding OutputTxt,Converter={StaticResource String2VisibilityConverter}}" Visibility="{Binding OutputTxt,Converter={StaticResource String2VisibilityConverter}}"
Command="{Binding CopyResultCmd}"> Command="{Binding CopyResultCmd}">
<Image Source="/Images/copy2.png"/> <Image Source="/Images/copy2.png"/>
<hc:FloatingBlock.ContentTemplate>
<DataTemplate>
<TextBlock Text="copied" />
</DataTemplate>
</hc:FloatingBlock.ContentTemplate>
</Button> </Button>
<!--蛇形复制--> <!--蛇形复制-->
<Button Cursor="Hand" <Button Cursor="Hand"
@ -198,11 +184,6 @@
Visibility="{Binding SnakeRet,Converter={StaticResource String2VisibilityConverter}}" Visibility="{Binding SnakeRet,Converter={StaticResource String2VisibilityConverter}}"
Command="{Binding CopySnakeResultCmd}"> Command="{Binding CopySnakeResultCmd}">
<Image Source="/Images/copy_s.png"/> <Image Source="/Images/copy_s.png"/>
<hc:FloatingBlock.ContentTemplate>
<DataTemplate>
<TextBlock Text="copied" />
</DataTemplate>
</hc:FloatingBlock.ContentTemplate>
</Button> </Button>
<!--驼峰复制--> <!--驼峰复制-->
<Button Cursor="Hand" <Button Cursor="Hand"
@ -215,11 +196,6 @@
Visibility="{Binding SmallHumpRet,Converter={StaticResource String2VisibilityConverter}}" Visibility="{Binding SmallHumpRet,Converter={StaticResource String2VisibilityConverter}}"
Command="{Binding CopySmallHumpResultCmd}"> Command="{Binding CopySmallHumpResultCmd}">
<Image Source="/Images/copy_h.png"/> <Image Source="/Images/copy_h.png"/>
<hc:FloatingBlock.ContentTemplate>
<DataTemplate>
<TextBlock Text="copied" />
</DataTemplate>
</hc:FloatingBlock.ContentTemplate>
</Button> </Button>
<!--驼峰复制--> <!--驼峰复制-->
<Button Cursor="Hand" <Button Cursor="Hand"
@ -233,11 +209,6 @@
Visibility="{Binding LargeHumpRet,Converter={StaticResource String2VisibilityConverter}}" Visibility="{Binding LargeHumpRet,Converter={StaticResource String2VisibilityConverter}}"
Command="{Binding CopyLargeHumpResultCmd}"> Command="{Binding CopyLargeHumpResultCmd}">
<Image Source="/Images/copy_h2.png"/> <Image Source="/Images/copy_h2.png"/>
<hc:FloatingBlock.ContentTemplate>
<DataTemplate>
<TextBlock Text="copied" />
</DataTemplate>
</hc:FloatingBlock.ContentTemplate>
</Button> </Button>
</StackPanel> </StackPanel>
</Grid> </Grid>

@ -15,8 +15,6 @@ namespace STranslate
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
private MainVM vm; private MainVM vm;
private Process process = new Process();
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
@ -27,8 +25,6 @@ namespace STranslate
InitialTray(); InitialTray();
DeepLStart();
//if (HotKeys.InputTranslate.Conflict || HotKeys.CrosswordTranslate.Conflict || HotKeys.ScreenShotTranslate.Conflict) //if (HotKeys.InputTranslate.Conflict || HotKeys.CrosswordTranslate.Conflict || HotKeys.ScreenShotTranslate.Conflict)
//{ //{
// MessageBox.Show("全局快捷键有冲突,请您到设置中重新设置"); // MessageBox.Show("全局快捷键有冲突,请您到设置中重新设置");
@ -37,8 +33,6 @@ namespace STranslate
private void InitialTray() private void InitialTray()
{ {
//notifyIcon.BalloonTipText = "STranslate已运行";
//notifyIcon.ShowBalloonTip(1000);
notifyIcon.Text = "STranslate"; notifyIcon.Text = "STranslate";
notifyIcon.Icon = new System.Drawing.Icon(System.Windows.Application.GetResourceStream(new Uri("Images/translate.ico", UriKind.Relative)).Stream); notifyIcon.Icon = new System.Drawing.Icon(System.Windows.Application.GetResourceStream(new Uri("Images/translate.ico", UriKind.Relative)).Stream);
notifyIcon.Visible = true; notifyIcon.Visible = true;
@ -240,7 +234,7 @@ namespace STranslate
/// <param name="e"></param> /// <param name="e"></param>
private void ScreenshotTranslateMenuItem_Click(object sender, EventArgs e) private void ScreenshotTranslateMenuItem_Click(object sender, EventArgs e)
{ {
HandyControl.Controls.MessageBox.Show("开发中"); MessageBox.Show("开发中");
} }
/// <summary> /// <summary>
@ -261,7 +255,6 @@ namespace STranslate
{ {
notifyIcon.Dispose(); notifyIcon.Dispose();
DeepLStop();
Environment.Exit(0); Environment.Exit(0);
} }
private void InitView() private void InitView()
@ -274,30 +267,5 @@ namespace STranslate
private BitmapImage LockImgPath = new BitmapImage(new Uri("pack://application:,,,/Images/lock3.png")); private BitmapImage LockImgPath = new BitmapImage(new Uri("pack://application:,,,/Images/lock3.png"));
private BitmapImage UnLockImgPath = new BitmapImage(new Uri("pack://application:,,,/Images/unlock3.png")); private BitmapImage UnLockImgPath = new BitmapImage(new Uri("pack://application:,,,/Images/unlock3.png"));
private System.Windows.Forms.NotifyIcon notifyIcon = new System.Windows.Forms.NotifyIcon(); private System.Windows.Forms.NotifyIcon notifyIcon = new System.Windows.Forms.NotifyIcon();
/// <summary>
/// 新进程开启DeepL
/// </summary>
private void DeepLStart()
{
if (!string.IsNullOrEmpty(vm.config.deepl?.url) && vm.config.deepl?.url != vm.defaultApi) return;
string strPathExe = AppDomain.CurrentDomain.BaseDirectory + "\\Static\\deepl-x86_64-pc-windows-gnu.exe";
process.StartInfo.FileName = strPathExe;
process.StartInfo.Arguments = null;//-s -t 可以用来关机、开机或重启
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = false; //true
process.StartInfo.RedirectStandardOutput = false; //true
process.StartInfo.RedirectStandardError = false;
process.StartInfo.CreateNoWindow = true;
process.Start();//启动
}
/// <summary>
/// 关闭DeepL进程
/// </summary>
private void DeepLStop()
{
if (!string.IsNullOrEmpty(vm.config.deepl?.url) && vm.config.deepl?.url != vm.defaultApi) return;
process.Kill();//等待退出。
}
} }
} }

@ -19,7 +19,7 @@ namespace STranslate.Properties {
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。 // (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources { internal class Resources {

@ -1,27 +1,24 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// This code was generated by a tool. // 此代码由工具生成。
// Runtime Version:4.0.30319.42000 // 运行时版本:4.0.30319.42000
// //
// Changes to this file may cause incorrect behavior and will be lost if // 对此文件的更改可能会导致不正确的行为,并且如果
// the code is regenerated. // 重新生成代码,这些更改将会丢失。
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace STranslate.Properties {
namespace STranslate.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.4.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default public static Settings Default {
{ get {
get
{
return defaultInstance; return defaultInstance;
} }
} }

@ -29,9 +29,10 @@
<IsWebBootstrapper>false</IsWebBootstrapper> <IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust> <UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled> <BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
@ -42,21 +43,19 @@
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath> <OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<ApplicationIcon>Images\translate.ico</ApplicationIcon> <ApplicationIcon>Images\translate.ico</ApplicationIcon>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="HandyControl, Version=3.4.0.0, Culture=neutral, PublicKeyToken=45be8712787a1e5b, processorArchitecture=MSIL">
<HintPath>..\packages\HandyControl.3.4.0\lib\net48\HandyControl.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll</HintPath> <HintPath>..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
@ -77,9 +76,6 @@
<Reference Include="WindowsBase" /> <Reference Include="WindowsBase" />
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />
<Reference Include="YamlDotNet, Version=12.0.0.0, Culture=neutral, PublicKeyToken=ec19458f3c15af5e, processorArchitecture=MSIL">
<HintPath>..\packages\YamlDotNet.12.2.1\lib\net47\YamlDotNet.dll</HintPath>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ApplicationDefinition Include="App.xaml"> <ApplicationDefinition Include="App.xaml">
@ -92,7 +88,6 @@
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
<Compile Include="Utils\ConfigUtil.cs" />
<Compile Include="Utils\GetWordsUtil.cs" /> <Compile Include="Utils\GetWordsUtil.cs" />
<Compile Include="Utils\HotKeysUtil.cs" /> <Compile Include="Utils\HotKeysUtil.cs" />
<Compile Include="Utils\HttpUtil.cs" /> <Compile Include="Utils\HttpUtil.cs" />
@ -168,12 +163,6 @@
<Resource Include="Images\copy_s.png"> <Resource Include="Images\copy_s.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource> </Resource>
<Content Include="Static\deepl-x86_64-pc-windows-gnu.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="STranslate.yml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config" /> <None Include="App.config" />

@ -1,6 +0,0 @@
service: deepl
baidu:
appid:
secretKey:
deepl:
url: https://zggsong.cn/tt

@ -1,42 +0,0 @@
using STranslate.Model;
using System;
using System.IO;
using YamlDotNet.Serialization;
namespace STranslate.Utils
{
public class ConfigUtil
{
public static ConfigModel ReadConfig(string path)
{
using (TextReader reader = File.OpenText(path))
{
try
{
var config = new ConfigModel();
var deserializer = new Deserializer();
config = deserializer.Deserialize<ConfigModel>(reader);
return config;
}
catch (Exception ex)
{
throw ex;
}
}
}
public static void WriteConfig(string path, ConfigModel configs)
{
var serializer = new Serializer();
StringWriter strWriter = new StringWriter();
serializer.Serialize(strWriter, configs);
serializer.Serialize(Console.Out, configs);
using (TextWriter writer = File.CreateText(path))
{
writer.Write(strWriter.ToString());
}
}
}
}

@ -18,24 +18,17 @@ namespace STranslate.ViewModel
//[System.Runtime.InteropServices.DllImport("deepl.dll", EntryPoint = "run")] //[System.Runtime.InteropServices.DllImport("deepl.dll", EntryPoint = "run")]
//extern static void run(); //extern static void run();
public string defaultApi = "http://127.0.0.1:8000/translate"; //https://deepl.deno.dev/translate public string defaultApi = "https://zggsong.cn/tt"; //https://deepl.deno.dev/translate、https://zggsong.cn/tt、http://127.0.0.1:8000/translate
private string ConfigPath => $"{AppDomain.CurrentDomain.BaseDirectory}STranslate.yml";
public ConfigModel config = new ConfigModel();
private static Dictionary<string, LanguageEnum> LanguageEnumDict { get => TranslateUtil.GetEnumList<LanguageEnum>(); } private static Dictionary<string, LanguageEnum> LanguageEnumDict { get => TranslateUtil.GetEnumList<LanguageEnum>(); }
public MainVM() public MainVM()
{ {
//启动deepl
//Task.Run(() => RunCmdUtil.RunCmd(AppDomain.CurrentDomain.BaseDirectory + "\\deepl-x86_64-pc-windows-gnu.exe"));
//初始化界面参数 //初始化界面参数
InputCombo = LanguageEnumDict.Keys.ToList(); InputCombo = LanguageEnumDict.Keys.ToList();
InputComboSelected = LanguageEnum.AUTO.GetDescription(); InputComboSelected = LanguageEnum.AUTO.GetDescription();
OutputCombo = LanguageEnumDict.Keys.ToList(); OutputCombo = LanguageEnumDict.Keys.ToList();
OutputComboSelected = LanguageEnum.AUTO.GetDescription(); OutputComboSelected = LanguageEnum.AUTO.GetDescription();
config = ConfigUtil.ReadConfig(ConfigPath);
//复制输入 //复制输入
CopyInputCmd = new RelayCommand((_) => true, (_) => CopyInputCmd = new RelayCommand((_) => true, (_) =>
{ {
@ -109,11 +102,11 @@ namespace STranslate.ViewModel
{ {
var autoRet = AutomaticLanguageRecognition(InputTxt); var autoRet = AutomaticLanguageRecognition(InputTxt);
IdentifyLanguage = autoRet.Item1; IdentifyLanguage = autoRet.Item1;
translateResp = await TranslateUtil.TranslateDeepLAsync(config.deepl?.url ?? defaultApi, InputTxt, LanguageEnumDict[autoRet.Item2], LanguageEnumDict[InputComboSelected]); translateResp = await TranslateUtil.TranslateDeepLAsync(defaultApi, InputTxt, LanguageEnumDict[autoRet.Item2], LanguageEnumDict[InputComboSelected]);
} }
else else
{ {
translateResp = await TranslateUtil.TranslateDeepLAsync(config.deepl?.url ?? defaultApi, InputTxt, LanguageEnumDict[OutputComboSelected], LanguageEnumDict[InputComboSelected]); translateResp = await TranslateUtil.TranslateDeepLAsync(defaultApi, InputTxt, LanguageEnumDict[OutputComboSelected], LanguageEnumDict[InputComboSelected]);
} }
//百度 Api //百度 Api

@ -1,6 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="HandyControl" version="3.4.0" targetFramework="net48" />
<package id="Newtonsoft.Json" version="13.0.2" targetFramework="net48" /> <package id="Newtonsoft.Json" version="13.0.2" targetFramework="net48" />
<package id="YamlDotNet" version="12.2.1" targetFramework="net48" />
</packages> </packages>
Loading…
Cancel
Save