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

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

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

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

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

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

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

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

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

@ -1,6 +1,4 @@
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
@ -30,7 +28,6 @@ using System.Windows;
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //主题特定资源词典所处位置
//(未在页面中找到资源时使用,
@ -40,8 +37,7 @@ using System.Windows;
//、应用程序或任何主题专用资源字典中找到时使用)
)]
// 程序集的版本信息由下列四个值组成:
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
@ -53,4 +49,4 @@ using System.Windows;
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("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 System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YamlDotNet.Serialization;
namespace STranslate.Utils
@ -27,7 +23,6 @@ namespace STranslate.Utils
throw ex;
}
}
}
public static void WriteConfig(string path, ConfigModel configs)
@ -42,8 +37,6 @@ namespace STranslate.Utils
{
writer.Write(strWriter.ToString());
}
}
}
}
}

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

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

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

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

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

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

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