perf: clean extra

dev_without_third_libraries
DESKTOP-3BO4HSG\ksat 2 years ago
parent 507eec2ded
commit 3bc94bfbe9

@ -1,6 +1,6 @@
<?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" />
</startup> </startup>
</configuration> </configuration>

@ -1,14 +1,13 @@
<Application x:Class="STranslate.App" <Application x:Class="STranslate.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:STranslate"
StartupUri="MainWindow.xaml"> StartupUri="MainWindow.xaml">
<Application.Resources> <Application.Resources>
<ResourceDictionary> <ResourceDictionary>
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml"/> <ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml" />
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml"/> <ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml" />
</ResourceDictionary.MergedDictionaries> </ResourceDictionary.MergedDictionaries>
</ResourceDictionary> </ResourceDictionary>
</Application.Resources> </Application.Resources>
</Application> </Application>

@ -1,10 +1,4 @@
using System; using System.Windows;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace STranslate namespace STranslate
{ {
@ -14,9 +8,10 @@ namespace STranslate
public partial class App : Application public partial class App : Application
{ {
private static System.Threading.Mutex mutex; private static System.Threading.Mutex mutex;
//系统能够识别有名称的互斥,因此可以使用它禁止应用程序启动两次
//第二个参数可以设置为产品的名称:Application.ProductName //系统能够识别有名称的互斥,因此可以使用它禁止应用程序启动两次
// 每次启动应用程序都会验证名称为OnlyRun的互斥是否存在 //第二个参数可以设置为产品的名称:Application.ProductName
// 每次启动应用程序都会验证名称为OnlyRun的互斥是否存在
protected override void OnStartup(StartupEventArgs e) protected override void OnStartup(StartupEventArgs e)
{ {
mutex = new System.Threading.Mutex(true, "CE252DD8-179F-4544-9989-453F5DEA378D"); mutex = new System.Threading.Mutex(true, "CE252DD8-179F-4544-9989-453F5DEA378D");
@ -31,4 +26,4 @@ namespace STranslate
} }
} }
} }
} }

@ -25,9 +25,9 @@
CornerRadius="10"> CornerRadius="10">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="5*"/> <RowDefinition Height="5*" />
<RowDefinition Height="*"/> <RowDefinition Height="*" />
<RowDefinition Height="8*"/> <RowDefinition Height="8*" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<hc:NotifyIcon Text="STranslate" <hc:NotifyIcon Text="STranslate"
@ -39,13 +39,13 @@
<ContextMenu> <ContextMenu>
<ContextMenu.Style> <ContextMenu.Style>
<Style> <Style>
<Setter Property="ContextMenu.Width" Value="100"/> <Setter Property="ContextMenu.Width" Value="100" />
</Style> </Style>
</ContextMenu.Style> </ContextMenu.Style>
<MenuItem Command="hc:ControlCommands.PushMainWindow2Top" <MenuItem Command="hc:ControlCommands.PushMainWindow2Top"
Header="主界面"/> Header="主界面" />
<MenuItem Command="hc:ControlCommands.ShutdownApp" <MenuItem Command="hc:ControlCommands.ShutdownApp"
Header="退出"/> Header="退出" />
</ContextMenu> </ContextMenu>
</hc:NotifyIcon.ContextMenu> </hc:NotifyIcon.ContextMenu>
</hc:NotifyIcon> </hc:NotifyIcon>
@ -74,7 +74,7 @@
AcceptsReturn="True" AcceptsReturn="True"
Text="{Binding InputTxt,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"> Text="{Binding InputTxt,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
<TextBox.InputBindings> <TextBox.InputBindings>
<KeyBinding Command="{Binding TranslateCmd}" Key="Enter"/> <KeyBinding Command="{Binding TranslateCmd}" Key="Enter" />
</TextBox.InputBindings> </TextBox.InputBindings>
</TextBox> </TextBox>
</Border> </Border>
@ -85,28 +85,28 @@
Orientation="Horizontal"> Orientation="Horizontal">
<Label Content="当前语言:" <Label Content="当前语言:"
Background="Transparent" Background="Transparent"
BorderThickness="0"/> BorderThickness="0" />
<ComboBox x:Name="InCombo" <ComboBox x:Name="InCombo"
Background="#f6f6f6" Background="#f6f6f6"
Style="{StaticResource ComboBox.Small}" Style="{StaticResource ComboBox.Small}"
ItemsSource="{Binding InputCombo}" ItemsSource="{Binding InputCombo}"
SelectedItem="{Binding InputComboSelected}"/> SelectedItem="{Binding InputComboSelected}" />
<Label Content="目标语言:" <Label Content="目标语言:"
Margin="10,0" Margin="10,0"
Background="Transparent" Background="Transparent"
BorderThickness="0"/> BorderThickness="0" />
<ComboBox x:Name="OutCombo" <ComboBox x:Name="OutCombo"
Background="#f6f6f6" Background="#f6f6f6"
Style="{StaticResource ComboBox.Small}" Style="{StaticResource ComboBox.Small}"
ItemsSource="{Binding OutputCombo}" ItemsSource="{Binding OutputCombo}"
SelectedItem="{Binding OutputComboSelected}"/> SelectedItem="{Binding OutputComboSelected}" />
<Button Margin="10,0,0,0" <Button Margin="10,0,0,0"
Cursor="Hand" Cursor="Hand"
Command="{Binding CopyTranslateResultCmd}"> Command="{Binding CopyTranslateResultCmd}">
<Image Source="/Images/copy.png"/> <Image Source="/Images/copy.png" />
<hc:FloatingBlock.ContentTemplate> <hc:FloatingBlock.ContentTemplate>
<DataTemplate> <DataTemplate>
<TextBlock Text="复制成功"/> <TextBlock Text="复制成功" />
</DataTemplate> </DataTemplate>
</hc:FloatingBlock.ContentTemplate> </hc:FloatingBlock.ContentTemplate>
</Button> </Button>
@ -136,7 +136,7 @@
VerticalAlignment="Top" VerticalAlignment="Top"
HorizontalAlignment="Left" HorizontalAlignment="Left"
TextWrapping="Wrap" TextWrapping="Wrap"
Text="{Binding OutputTxt}"/> Text="{Binding OutputTxt}" />
</Border> </Border>
<!--<Button Content="复制" <!--<Button Content="复制"
Margin="0,0,10,0" Margin="0,0,10,0"
@ -149,8 +149,8 @@
<Setter Property="Background"> <Setter Property="Background">
<Setter.Value> <Setter.Value>
<LinearGradientBrush EndPoint="1,1" StartPoint="0,0"> <LinearGradientBrush EndPoint="1,1" StartPoint="0,0">
<GradientStop Color="#C0C0C0" Offset="0"/> <GradientStop Color="#C0C0C0" Offset="0" />
<GradientStop Color="#787878" Offset="1"/> <GradientStop Color="#787878" Offset="1" />
</LinearGradientBrush> </LinearGradientBrush>
</Setter.Value> </Setter.Value>
</Setter> </Setter>
@ -159,8 +159,8 @@
<Setter Property="Background"> <Setter Property="Background">
<Setter.Value> <Setter.Value>
<LinearGradientBrush EndPoint="1,1" StartPoint="0,0"> <LinearGradientBrush EndPoint="1,1" StartPoint="0,0">
<GradientStop Color="LightGray" Offset="0"/> <GradientStop Color="LightGray" Offset="0" />
<GradientStop Color="Gray" Offset="1"/> <GradientStop Color="Gray" Offset="1" />
</LinearGradientBrush> </LinearGradientBrush>
</Setter.Value> </Setter.Value>
</Setter> </Setter>
@ -171,13 +171,12 @@
<Button.Template> <Button.Template>
<ControlTemplate TargetType="Button"> <ControlTemplate TargetType="Button">
<Border BorderThickness="1" CornerRadius="4" Background="{TemplateBinding Background}"> <Border BorderThickness="1" CornerRadius="4" Background="{TemplateBinding Background}">
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/> <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" />
</Border> </Border>
</ControlTemplate> </ControlTemplate>
</Button.Template> </Button.Template>
</Button>--> </Button>-->
</Grid> </Grid>
</Grid> </Grid>
</Border> </Border>
</Window> </Window>

@ -1,19 +1,8 @@
using STranslate.Utils; using STranslate.Utils;
using STranslate.ViewModel; using STranslate.ViewModel;
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace STranslate namespace STranslate
{ {
@ -149,4 +138,4 @@ namespace STranslate
MainVM.Instance.OutputTxt = string.Empty; MainVM.Instance.OutputTxt = string.Empty;
} }
} }
} }

@ -1,9 +1,4 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace STranslate.Model namespace STranslate.Model
{ {
@ -16,22 +11,25 @@ namespace STranslate.Model
public string Salt { get; set; } public string Salt { get; set; }
public string Sign { get; set; } public string Sign { get; set; }
} }
public class BaiduResp public class BaiduResp
{ {
[JsonProperty("from")] [JsonProperty("from")]
public string From { get; set; } public string From { get; set; }
[JsonProperty("to")] [JsonProperty("to")]
public string To { get; set; } public string To { get; set; }
[JsonProperty("trans_result")] [JsonProperty("trans_result")]
public TransResult[] TransResult { get; set; } public TransResult[] TransResult { get; set; }
} }
public class TransResult public class TransResult
{ {
[JsonProperty("src")] [JsonProperty("src")]
public string Src { get; set; } public string Src { get; set; }
[JsonProperty("dst")] [JsonProperty("dst")]
public string Dst { get; set; } public string Dst { get; set; }
} }
} }

@ -1,10 +1,4 @@
using System; namespace STranslate.Model
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace STranslate.Model
{ {
public class ConfigModel public class ConfigModel
{ {
@ -18,6 +12,7 @@ namespace STranslate.Model
public string appid { get; set; } public string appid { get; set; }
public string secretKey { get; set; } public string secretKey { get; set; }
} }
public class DeepL public class DeepL
{ {
public string url { get; set; } public string url { get; set; }

@ -1,9 +1,4 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace STranslate.Model namespace STranslate.Model
{ {
@ -27,4 +22,4 @@ namespace STranslate.Model
[JsonProperty("data")] [JsonProperty("data")]
public string Data { get; set; } public string Data { get; set; }
} }
} }

@ -1,9 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace STranslate.Model namespace STranslate.Model
{ {
@ -11,59 +7,84 @@ namespace STranslate.Model
{ {
[Description("自动")] [Description("自动")]
AUTO, //自动 AUTO, //自动
[Description("德语")] [Description("德语")]
DE, //德语 DE, //德语
[Description("英语")] [Description("英语")]
EN, //英语 EN, //英语
[Description("西班牙语")] [Description("西班牙语")]
ES, //西班牙语 ES, //西班牙语
[Description("法语")] [Description("法语")]
FR, //法语 FR, //法语
[Description("意大利语")] [Description("意大利语")]
IT, //意大利语 IT, //意大利语
[Description("日语")] [Description("日语")]
JA, //日语 JA, //日语
[Description("荷兰语")] [Description("荷兰语")]
NL, //荷兰语 NL, //荷兰语
[Description("波兰语")] [Description("波兰语")]
PL, //波兰语 PL, //波兰语
[Description("葡萄牙语")] [Description("葡萄牙语")]
PT, //葡萄牙语 PT, //葡萄牙语
[Description("俄语")] [Description("俄语")]
RU, //俄语 RU, //俄语
[Description("中文")] [Description("中文")]
ZH, //中文 ZH, //中文
[Description("保加利亚语")] [Description("保加利亚语")]
BG, //保加利亚语 BG, //保加利亚语
[Description("捷克语")] [Description("捷克语")]
CS, //捷克语 CS, //捷克语
[Description("丹麦语")] [Description("丹麦语")]
DA, //丹麦语 DA, //丹麦语
[Description("希腊语")] [Description("希腊语")]
EL, //希腊语 EL, //希腊语
[Description("爱沙尼亚语")] [Description("爱沙尼亚语")]
ET, //爱沙尼亚语 ET, //爱沙尼亚语
[Description("芬兰语")] [Description("芬兰语")]
FI, //芬兰语 FI, //芬兰语
[Description("匈牙利语")] [Description("匈牙利语")]
HU, //匈牙利语 HU, //匈牙利语
[Description("立陶宛语")] [Description("立陶宛语")]
LT, //立陶宛语 LT, //立陶宛语
[Description("拉脱维亚语")] [Description("拉脱维亚语")]
LV, //拉脱维亚语 LV, //拉脱维亚语
[Description("罗马尼亚语")] [Description("罗马尼亚语")]
RO, //罗马尼亚语 RO, //罗马尼亚语
[Description("斯洛伐克语")] [Description("斯洛伐克语")]
SK, //斯洛伐克语 SK, //斯洛伐克语
[Description("斯洛文尼亚语")] [Description("斯洛文尼亚语")]
SL, //斯洛文尼亚语 SL, //斯洛文尼亚语
[Description("瑞典语")] [Description("瑞典语")]
SV, //瑞典语 SV, //瑞典语
} }
/// <summary> /// <summary>
/// 获取Description /// 获取Description
/// </summary> /// </summary>
static class EnumExtensions internal static class EnumExtensions
{ {
public static string GetDescription(this Enum val) public static string GetDescription(this Enum val)
{ {
@ -72,4 +93,4 @@ namespace STranslate.Model
return customAttribute == null ? val.ToString() : ((DescriptionAttribute)customAttribute).Description; return customAttribute == null ? val.ToString() : ((DescriptionAttribute)customAttribute).Description;
} }
} }
} }

@ -1,6 +1,4 @@
using System.Reflection; using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Windows; using System.Windows;
@ -30,7 +28,6 @@ using System.Windows;
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
[assembly: ThemeInfo( [assembly: ThemeInfo(
ResourceDictionaryLocation.None, //主题特定资源词典所处位置 ResourceDictionaryLocation.None, //主题特定资源词典所处位置
//(未在页面中找到资源时使用, //(未在页面中找到资源时使用,
@ -40,8 +37,7 @@ using System.Windows;
//、应用程序或任何主题专用资源字典中找到时使用) //、应用程序或任何主题专用资源字典中找到时使用)
)] )]
// 程序集的版本信息由下列四个值组成:
// 程序集的版本信息由下列四个值组成:
// //
// 主版本 // 主版本
// 次版本 // 次版本
@ -53,4 +49,4 @@ using System.Windows;
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.0.2")] [assembly: AssemblyVersion("0.0.0.2")]
[assembly: AssemblyFileVersion("0.0.0.2")] [assembly: AssemblyFileVersion("0.0.0.2")]
[assembly: Guid("CE252DD8-179F-4544-9989-453F5DEA378D")] [assembly: Guid("CE252DD8-179F-4544-9989-453F5DEA378D")]

@ -1,10 +1,6 @@
using STranslate.Model; using STranslate.Model;
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YamlDotNet.Serialization; using YamlDotNet.Serialization;
namespace STranslate.Utils namespace STranslate.Utils
@ -27,7 +23,6 @@ namespace STranslate.Utils
throw ex; throw ex;
} }
} }
} }
public static void WriteConfig(string path, ConfigModel configs) public static void WriteConfig(string path, ConfigModel configs)
@ -42,8 +37,6 @@ namespace STranslate.Utils
{ {
writer.Write(strWriter.ToString()); writer.Write(strWriter.ToString());
} }
} }
} }
} }

@ -11,24 +11,28 @@ namespace STranslate.Utils
/// <summary> /// <summary>
/// 引用自 https://blog.csdn.net/weixin_44879611/article/details/103275347 /// 引用自 https://blog.csdn.net/weixin_44879611/article/details/103275347
/// </summary> /// </summary>
static class HotkeysUtil internal static class HotkeysUtil
{ {
#region 系统api #region 系统api
[DllImport("user32.dll")] [DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
static extern bool RegisterHotKey(IntPtr hWnd, int id, HotkeyModifiers fsModifiers, uint vk); private static extern bool RegisterHotKey(IntPtr hWnd, int id, HotkeyModifiers fsModifiers, uint vk);
[DllImport("user32.dll")] [DllImport("user32.dll")]
static extern bool UnregisterHotKey(IntPtr hWnd, int id); private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
#endregion
#endregion 系统api
public static IntPtr hwnd; public static IntPtr hwnd;
public static void InitialHook(Window window) public static void InitialHook(Window window)
{ {
hwnd = new WindowInteropHelper(window).Handle; hwnd = new WindowInteropHelper(window).Handle;
var _hwndSource = HwndSource.FromHwnd(hwnd); var _hwndSource = HwndSource.FromHwnd(hwnd);
_hwndSource.AddHook(WndProc); _hwndSource.AddHook(WndProc);
} }
/// <summary> /// <summary>
/// 注册快捷键 /// 注册快捷键
/// </summary> /// </summary>
@ -49,7 +53,7 @@ namespace STranslate.Utils
/// <summary> /// <summary>
/// 快捷键消息处理 /// 快捷键消息处理
/// </summary> /// </summary>
static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{ {
if (msg == WM_HOTKEY) if (msg == WM_HOTKEY)
{ {
@ -76,19 +80,18 @@ namespace STranslate.Utils
} }
} }
private const int WM_HOTKEY = 0x312;
const int WM_HOTKEY = 0x312; private static int keyid = 10;
static int keyid = 10; private static Dictionary<int, HotKeyCallBackHanlder> keymap = new Dictionary<int, HotKeyCallBackHanlder>();
static Dictionary<int, HotKeyCallBackHanlder> keymap = new Dictionary<int, HotKeyCallBackHanlder>();
public delegate void HotKeyCallBackHanlder(); public delegate void HotKeyCallBackHanlder();
} }
enum HotkeyModifiers internal enum HotkeyModifiers
{ {
MOD_ALT = 0x1, MOD_ALT = 0x1,
MOD_CONTROL = 0x2, MOD_CONTROL = 0x2,
MOD_SHIFT = 0x4, MOD_SHIFT = 0x4,
MOD_WIN = 0x8 MOD_WIN = 0x8
} }
} }

@ -1,9 +1,7 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using STranslate.Model; using STranslate.Model;
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Text; using System.Text;
@ -40,7 +38,6 @@ namespace STranslate.Utils
/// <returns></returns> /// <returns></returns>
public static async Task<string> PostAsync(string url, string req) public static async Task<string> PostAsync(string url, string req)
{ {
using (var client = new HttpClient()) using (var client = new HttpClient())
{ {
var content = new StringContent(req, Encoding.UTF8, "application/json"); var content = new StringContent(req, Encoding.UTF8, "application/json");
@ -48,10 +45,11 @@ namespace STranslate.Utils
var respContent = await client.PostAsync(url, content); var respContent = await client.PostAsync(url, content);
string respStr = await respContent.Content.ReadAsStringAsync(); string respStr = await respContent.Content.ReadAsStringAsync();
; ;
return respStr; return respStr;
} }
} }
/// <summary> /// <summary>
/// 异步Get请求 /// 异步Get请求
/// </summary> /// </summary>
@ -76,4 +74,4 @@ namespace STranslate.Utils
} }
} }
} }
} }

@ -1,19 +1,15 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security; using System.Security;
using System.Security.Permissions; using System.Security.Permissions;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input; using System.Windows.Input;
namespace STranslate.Utils namespace STranslate.Utils
{ {
#region Operate Mouse Keyboard #region Operate Mouse Keyboard
//引用自: https://www.cnblogs.com/sixty/archive/2009/08/09/1542210.html //引用自: https://www.cnblogs.com/sixty/archive/2009/08/09/1542210.html
/// <summary> /// <summary>
/// Native methods /// Native methods
@ -21,14 +17,18 @@ namespace STranslate.Utils
internal static class NativeMethods internal static class NativeMethods
{ {
//User32 wrappers cover API's used for Mouse input //User32 wrappers cover API's used for Mouse input
#region User32 #region User32
// Two special bitmasks we define to be able to grab // Two special bitmasks we define to be able to grab
// shift and character information out of a VKey. // shift and character information out of a VKey.
internal const int VKeyShiftMask = 0x0100; internal const int VKeyShiftMask = 0x0100;
internal const int VKeyCharMask = 0x00FF; internal const int VKeyCharMask = 0x00FF;
// Various Win32 constants // Various Win32 constants
internal const int KeyeventfExtendedkey = 0x0001; internal const int KeyeventfExtendedkey = 0x0001;
internal const int KeyeventfKeyup = 0x0002; internal const int KeyeventfKeyup = 0x0002;
internal const int KeyeventfScancode = 0x0008; internal const int KeyeventfScancode = 0x0008;
@ -59,6 +59,7 @@ namespace STranslate.Utils
{ {
[FieldOffset(0)] [FieldOffset(0)]
internal MOUSEINPUT mouseInput; internal MOUSEINPUT mouseInput;
[FieldOffset(0)] [FieldOffset(0)]
internal KEYBDINPUT keyboardInput; internal KEYBDINPUT keyboardInput;
}; };
@ -113,10 +114,9 @@ namespace STranslate.Utils
[DllImport("user32.dll", CharSet = CharSet.Auto)] [DllImport("user32.dll", CharSet = CharSet.Auto)]
internal static extern short VkKeyScan(char ch); internal static extern short VkKeyScan(char ch);
#endregion #endregion User32
} }
/// <summary> /// <summary>
/// Exposes a simple interface to common mouse operations, allowing the user to simulate mouse input. /// Exposes a simple interface to common mouse operations, allowing the user to simulate mouse input.
/// </summary> /// </summary>
@ -126,6 +126,7 @@ namespace STranslate.Utils
Mouse.MoveTo(new Point(100, 100)); Mouse.MoveTo(new Point(100, 100));
Mouse.Click(MouseButton.Left); Mouse.Click(MouseButton.Left);
*/ */
/// </code> /// </code>
/// </example> /// </example>
public static class Mouse public static class Mouse
@ -161,18 +162,23 @@ namespace STranslate.Utils
case MouseButton.Left: case MouseButton.Left:
SendMouseInput(0, 0, 0, NativeMethods.SendMouseInputFlags.LeftDown); SendMouseInput(0, 0, 0, NativeMethods.SendMouseInputFlags.LeftDown);
break; break;
case MouseButton.Right: case MouseButton.Right:
SendMouseInput(0, 0, 0, NativeMethods.SendMouseInputFlags.RightDown); SendMouseInput(0, 0, 0, NativeMethods.SendMouseInputFlags.RightDown);
break; break;
case MouseButton.Middle: case MouseButton.Middle:
SendMouseInput(0, 0, 0, NativeMethods.SendMouseInputFlags.MiddleDown); SendMouseInput(0, 0, 0, NativeMethods.SendMouseInputFlags.MiddleDown);
break; break;
case MouseButton.XButton1: case MouseButton.XButton1:
SendMouseInput(0, 0, NativeMethods.XButton1, NativeMethods.SendMouseInputFlags.XDown); SendMouseInput(0, 0, NativeMethods.XButton1, NativeMethods.SendMouseInputFlags.XDown);
break; break;
case MouseButton.XButton2: case MouseButton.XButton2:
SendMouseInput(0, 0, NativeMethods.XButton2, NativeMethods.SendMouseInputFlags.XDown); SendMouseInput(0, 0, NativeMethods.XButton2, NativeMethods.SendMouseInputFlags.XDown);
break; break;
default: default:
throw new InvalidOperationException("Unsupported MouseButton input."); throw new InvalidOperationException("Unsupported MouseButton input.");
} }
@ -242,18 +248,23 @@ namespace STranslate.Utils
case MouseButton.Left: case MouseButton.Left:
SendMouseInput(0, 0, 0, NativeMethods.SendMouseInputFlags.LeftUp); SendMouseInput(0, 0, 0, NativeMethods.SendMouseInputFlags.LeftUp);
break; break;
case MouseButton.Right: case MouseButton.Right:
SendMouseInput(0, 0, 0, NativeMethods.SendMouseInputFlags.RightUp); SendMouseInput(0, 0, 0, NativeMethods.SendMouseInputFlags.RightUp);
break; break;
case MouseButton.Middle: case MouseButton.Middle:
SendMouseInput(0, 0, 0, NativeMethods.SendMouseInputFlags.MiddleUp); SendMouseInput(0, 0, 0, NativeMethods.SendMouseInputFlags.MiddleUp);
break; break;
case MouseButton.XButton1: case MouseButton.XButton1:
SendMouseInput(0, 0, NativeMethods.XButton1, NativeMethods.SendMouseInputFlags.XUp); SendMouseInput(0, 0, NativeMethods.XButton1, NativeMethods.SendMouseInputFlags.XUp);
break; break;
case MouseButton.XButton2: case MouseButton.XButton2:
SendMouseInput(0, 0, NativeMethods.XButton2, NativeMethods.SendMouseInputFlags.XUp); SendMouseInput(0, 0, NativeMethods.XButton2, NativeMethods.SendMouseInputFlags.XUp);
break; break;
default: default:
throw new InvalidOperationException("Unsupported MouseButton input."); throw new InvalidOperationException("Unsupported MouseButton input.");
} }
@ -342,6 +353,7 @@ namespace STranslate.Utils
Keyboard.Type("hello, capitalized world"); Keyboard.Type("hello, capitalized world");
Keyboard.Release(Key.LeftShift); Keyboard.Release(Key.LeftShift);
*/ */
/// </code> /// </code>
/// </example> /// </example>
public static class KeyboardUtil public static class KeyboardUtil
@ -418,7 +430,7 @@ namespace STranslate.Utils
} }
} }
#endregion #endregion Public Members
#region Private Members #region Private Members
@ -493,7 +505,7 @@ namespace STranslate.Utils
// CTRL keys on the right-hand side of the keyboard; the INS, DEL, HOME, END, PAGE UP, // CTRL keys on the right-hand side of the keyboard; the INS, DEL, HOME, END, PAGE UP,
// PAGE DOWN, and arrow keys in the clusters to the left of the numeric keypad; the NUM LOCK // PAGE DOWN, and arrow keys in the clusters to the left of the numeric keypad; the NUM LOCK
// key; the BREAK (CTRL+PAUSE) key; the PRINT SCRN key; and the divide (/) and ENTER keys in // key; the BREAK (CTRL+PAUSE) key; the PRINT SCRN key; and the divide (/) and ENTER keys in
// the numeric keypad. The extended-key flag is set if the key is an extended key. // the numeric keypad. The extended-key flag is set if the key is an extended key.
// //
// - docs appear to be incorrect. Use of Spy++ indicates that break is not an extended key. // - docs appear to be incorrect. Use of Spy++ indicates that break is not an extended key.
// Also, menu key and windows keys also appear to be extended. // Also, menu key and windows keys also appear to be extended.
@ -514,11 +526,13 @@ namespace STranslate.Utils
Key.Apps, Key.Apps,
Key.RWin, Key.RWin,
Key.LWin }; Key.LWin };
// Note that there are no distinct values for the following keys: // Note that there are no distinct values for the following keys:
// numpad divide // numpad divide
// numpad enter // numpad enter
#endregion #endregion Private Members
} }
#endregion
} #endregion Operate Mouse Keyboard
}

@ -1,10 +1,6 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input; using System.Windows.Input;
namespace STranslate.Utils namespace STranslate.Utils
@ -15,6 +11,7 @@ namespace STranslate.Utils
public class BaseVM : INotifyPropertyChanged public class BaseVM : INotifyPropertyChanged
{ {
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
protected void UpdateProperty<T>(ref T properValue, T newValue, [CallerMemberName] string properName = "") protected void UpdateProperty<T>(ref T properValue, T newValue, [CallerMemberName] string properName = "")
{ {
if (object.Equals(properValue, newValue)) if (object.Equals(properValue, newValue))
@ -28,6 +25,7 @@ namespace STranslate.Utils
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
} }
} }
/// <summary> /// <summary>
/// Command /// Command
/// </summary> /// </summary>
@ -65,6 +63,7 @@ namespace STranslate.Utils
public abstract class SingletonMode<T> where T : class public abstract class SingletonMode<T> where T : class
{ {
public static T _Instance; public static T _Instance;
public static T Instance() public static T Instance()
{ {
Type type = typeof(T); Type type = typeof(T);
@ -78,4 +77,4 @@ namespace STranslate.Utils
} }
} }
} }
} }

@ -2,9 +2,7 @@
using STranslate.Model; using STranslate.Model;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Net;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -15,6 +13,7 @@ namespace STranslate.Utils
public class TranslateUtil public class TranslateUtil
{ {
private static readonly string _url = "http://127.0.0.1:8000/translate"; private static readonly string _url = "http://127.0.0.1:8000/translate";
public static string Translate(string input, LanguageEnum source, LanguageEnum target) public static string Translate(string input, LanguageEnum source, LanguageEnum target)
{ {
var req = new DeeplReq() var req = new DeeplReq()
@ -109,6 +108,7 @@ namespace STranslate.Utils
throw ex; throw ex;
} }
} }
// 计算MD5值 // 计算MD5值
public static string EncryptString(string str) public static string EncryptString(string str)
{ {
@ -127,6 +127,7 @@ namespace STranslate.Utils
// 返回加密的字符串 // 返回加密的字符串
return sb.ToString(); return sb.ToString();
} }
/// <summary> /// <summary>
/// 枚举信息 /// 枚举信息
/// </summary> /// </summary>
@ -143,4 +144,4 @@ namespace STranslate.Utils
return dict; return dict;
} }
} }
} }

@ -3,8 +3,6 @@ using STranslate.Utils;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
@ -17,6 +15,7 @@ namespace STranslate.ViewModel
private static Dictionary<string, LanguageEnum> LanguageEnumDict { get => TranslateUtil.GetEnumList<LanguageEnum>(); } private static Dictionary<string, LanguageEnum> LanguageEnumDict { get => TranslateUtil.GetEnumList<LanguageEnum>(); }
private string Text; private string Text;
public MainVM() public MainVM()
{ {
//初始化界面参数 //初始化界面参数
@ -38,7 +37,6 @@ namespace STranslate.ViewModel
Clipboard.SetText(OutputTxt); Clipboard.SetText(OutputTxt);
}); });
TranslateCmd = new RelayCommand((_) => TranslateCmd = new RelayCommand((_) =>
{ {
return string.IsNullOrEmpty(InputTxt) ? false : true; return string.IsNullOrEmpty(InputTxt) ? false : true;
@ -95,6 +93,5 @@ namespace STranslate.ViewModel
private static readonly MainVM _Instance = new MainVM(); private static readonly MainVM _Instance = new MainVM();
public static MainVM Instance { get => _Instance; } public static MainVM Instance { get => _Instance; }
} }
} }

@ -1,6 +1,6 @@
<?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="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" /> <package id="YamlDotNet" version="12.2.1" targetFramework="net48" />
</packages> </packages>
Loading…
Cancel
Save