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>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>

@ -3,11 +3,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<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>

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

@ -15,8 +15,6 @@ namespace STranslate
public partial class MainWindow : Window
{
private MainVM vm;
private Process process = new Process();
public MainWindow()
{
InitializeComponent();
@ -27,8 +25,6 @@ namespace STranslate
InitialTray();
DeepLStart();
//if (HotKeys.InputTranslate.Conflict || HotKeys.CrosswordTranslate.Conflict || HotKeys.ScreenShotTranslate.Conflict)
//{
// MessageBox.Show("全局快捷键有冲突,请您到设置中重新设置");
@ -37,8 +33,6 @@ namespace STranslate
private void InitialTray()
{
//notifyIcon.BalloonTipText = "STranslate已运行";
//notifyIcon.ShowBalloonTip(1000);
notifyIcon.Text = "STranslate";
notifyIcon.Icon = new System.Drawing.Icon(System.Windows.Application.GetResourceStream(new Uri("Images/translate.ico", UriKind.Relative)).Stream);
notifyIcon.Visible = true;
@ -240,7 +234,7 @@ namespace STranslate
/// <param name="e"></param>
private void ScreenshotTranslateMenuItem_Click(object sender, EventArgs e)
{
HandyControl.Controls.MessageBox.Show("开发中");
MessageBox.Show("开发中");
}
/// <summary>
@ -261,7 +255,6 @@ namespace STranslate
{
notifyIcon.Dispose();
DeepLStop();
Environment.Exit(0);
}
private void InitView()
@ -274,30 +267,5 @@ namespace STranslate
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 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 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /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.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {

@ -1,27 +1,24 @@
//------------------------------------------------------------------------------
// <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>
//------------------------------------------------------------------------------
namespace STranslate.Properties {
namespace STranslate.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.4.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
public static Settings Default {
get {
return defaultInstance;
}
}

@ -29,9 +29,10 @@
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x64</PlatformTarget>
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
@ -42,21 +43,19 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>x64</PlatformTarget>
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Images\translate.ico</ApplicationIcon>
</PropertyGroup>
<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">
<HintPath>..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
@ -77,9 +76,6 @@
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<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>
<ApplicationDefinition Include="App.xaml">
@ -92,7 +88,6 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Utils\ConfigUtil.cs" />
<Compile Include="Utils\GetWordsUtil.cs" />
<Compile Include="Utils\HotKeysUtil.cs" />
<Compile Include="Utils\HttpUtil.cs" />
@ -168,12 +163,6 @@
<Resource Include="Images\copy_s.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</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>
<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")]
//extern static void run();
public string defaultApi = "http://127.0.0.1:8000/translate"; //https://deepl.deno.dev/translate
private string ConfigPath => $"{AppDomain.CurrentDomain.BaseDirectory}STranslate.yml";
public ConfigModel config = new ConfigModel();
public string defaultApi = "https://zggsong.cn/tt"; //https://deepl.deno.dev/translate、https://zggsong.cn/tt、http://127.0.0.1:8000/translate
private static Dictionary<string, LanguageEnum> LanguageEnumDict { get => TranslateUtil.GetEnumList<LanguageEnum>(); }
public MainVM()
{
//启动deepl
//Task.Run(() => RunCmdUtil.RunCmd(AppDomain.CurrentDomain.BaseDirectory + "\\deepl-x86_64-pc-windows-gnu.exe"));
//初始化界面参数
InputCombo = LanguageEnumDict.Keys.ToList();
InputComboSelected = LanguageEnum.AUTO.GetDescription();
OutputCombo = LanguageEnumDict.Keys.ToList();
OutputComboSelected = LanguageEnum.AUTO.GetDescription();
config = ConfigUtil.ReadConfig(ConfigPath);
//复制输入
CopyInputCmd = new RelayCommand((_) => true, (_) =>
{
@ -109,11 +102,11 @@ namespace STranslate.ViewModel
{
var autoRet = AutomaticLanguageRecognition(InputTxt);
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
{
translateResp = await TranslateUtil.TranslateDeepLAsync(config.deepl?.url ?? defaultApi, InputTxt, LanguageEnumDict[OutputComboSelected], LanguageEnumDict[InputComboSelected]);
translateResp = await TranslateUtil.TranslateDeepLAsync(defaultApi, InputTxt, LanguageEnumDict[OutputComboSelected], LanguageEnumDict[InputComboSelected]);
}
//百度 Api

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