perf: clean extra

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

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

@ -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,6 +8,7 @@ namespace STranslate
public partial class App : Application
{
private static System.Threading.Mutex mutex;
//系统能够识别有名称的互斥,因此可以使用它禁止应用程序启动两次
//第二个参数可以设置为产品的名称:Application.ProductName
// 每次启动应用程序都会验证名称为OnlyRun的互斥是否存在

@ -178,6 +178,5 @@
</Button>-->
</Grid>
</Grid>
</Border>
</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
{

@ -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,21 +11,24 @@ 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
{

@ -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)
{

@ -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,7 +37,6 @@ using System.Windows;
//、应用程序或任何主题专用资源字典中找到时使用)
)]
// 程序集的版本信息由下列四个值组成:
//
// 主版本

@ -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,15 +80,14 @@ 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,

@ -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");
@ -52,6 +49,7 @@ namespace STranslate.Utils
return respStr;
}
}
/// <summary>
/// 异步Get请求
/// </summary>

@ -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
@ -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);

@ -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>

@ -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; }
}
}
Loading…
Cancel
Save