Skip to content

Commit

Permalink
增加数字签名机制,优化安装策略,提升激活成功率。
Browse files Browse the repository at this point in the history
  • Loading branch information
OdysseusYuan committed Nov 11, 2022
1 parent 17932ce commit 22487d3
Show file tree
Hide file tree
Showing 19 changed files with 393 additions and 133 deletions.
13 changes: 6 additions & 7 deletions LKY_OfficeTools/Common/Com_EmailOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Windows.Documents;
using static LKY_OfficeTools.Lib.Lib_AppLog;

namespace LKY_OfficeTools.Common
{
Expand Down Expand Up @@ -65,9 +65,9 @@ internal static bool Send_Localhost()
return true;
}
catch (SmtpException ex)
catch (Exception Ex)
{
new Log(ex);
new Log(Ex.ToString());
return false;
}
}
Expand All @@ -87,7 +87,7 @@ internal static bool Send_Localhost()
/// <param name="SMTPpass">密码</param>
/// <param name="priority">邮件优先级,默认为一般,设置为高时,收件人看到标题旁边,会有红色叹号</param>
/// <returns></returns>
public static bool Send_Account( string send_from_username, string send_to_mail, string mail_subject,
public static bool Send_Account(string send_from_username, string send_to_mail, string mail_subject,
string mail_body, List<string> mail_file, string SMTPHost, string SMTPuser, string SMTPpass, MailPriority priority = MailPriority.Normal)
{
//设置from和to地址
Expand Down Expand Up @@ -144,10 +144,9 @@ public static bool Send_Account( string send_from_username, string send_to_mail,

return true;
}
catch /*(Exception err)*/
catch (Exception Ex)
{
//new Log(err);
//Console.ReadKey();
new Log(Ex.ToString());
return false;
}
finally
Expand Down
11 changes: 5 additions & 6 deletions LKY_OfficeTools/Common/Com_ExeOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Net;
using System.Text;
using System.Threading.Tasks;
using static LKY_OfficeTools.Lib.Lib_AppLog;

namespace LKY_OfficeTools.Common
{
Expand Down Expand Up @@ -55,10 +56,9 @@ internal static bool RunExe(string runFilePath, string args)

return true;
}
catch /*(Exception Ex)*/
catch (Exception Ex)
{
//Console.ForegroundColor = ConsoleColor.DarkRed;
//new Log(Ex.Message.ToString());
new Log(Ex.ToString());
return false;
}
}
Expand Down Expand Up @@ -110,10 +110,9 @@ internal static string RunCmd(string args)

return strOuput;
}
catch /*(Exception Ex)*/
catch (Exception Ex)
{
//Console.ForegroundColor = ConsoleColor.DarkRed;
//new Log(Ex.Message.ToString());
new Log(Ex.ToString());
return null;
}
}
Expand Down
12 changes: 7 additions & 5 deletions LKY_OfficeTools/Common/Com_FileOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using static LKY_OfficeTools.Lib.Lib_AppLog;

namespace LKY_OfficeTools.Common
{
Expand Down Expand Up @@ -53,10 +54,9 @@ internal static bool SetValue(string xml_path, string Key_str, string new_Value)

return true;
}
catch /*(Exception Ex)*/
catch (Exception Ex)
{
//Console.ForegroundColor = ConsoleColor.DarkRed;
//new Log(Ex.Message.ToString());
new Log(Ex.ToString());
return false;
}
}
Expand Down Expand Up @@ -218,8 +218,9 @@ internal static bool FromAllText(string all_text, string to_path)
File.WriteAllText(to_path, all_text, Encoding.UTF8);
return true;
}
catch
catch (Exception Ex)
{
new Log(Ex.ToString());
return false;
}
}
Expand All @@ -243,8 +244,9 @@ internal static bool FromStream(Stream stream, string to_path)

return true;
}
catch
catch (Exception Ex)
{
new Log(Ex.ToString());
return false;
}
}
Expand Down
13 changes: 9 additions & 4 deletions LKY_OfficeTools/Common/Com_NetworkOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using static LKY_OfficeTools.Lib.Lib_AppLog;

namespace LKY_OfficeTools.Common
{
Expand Down Expand Up @@ -69,8 +70,9 @@ internal static string GetMyIP_Info()

return $"{ip} ({ip_location})";
}
catch
catch (Exception Ex)
{
new Log(Ex.ToString());
//意外失败,返回error
return "ip_info_error!";
}
Expand Down Expand Up @@ -124,8 +126,9 @@ internal static string GetMyIP()
return GetIPFromHtml(my_ip_page);
}
}
catch
catch (Exception Ex)
{
new Log(Ex.ToString());
return null;
}
}
Expand Down Expand Up @@ -161,8 +164,9 @@ internal static string IP2Location()
//无任何问题,直接返回该值
return ip_location;
}
catch
catch (Exception Ex)
{
new Log(Ex.ToString());
return null;
}
}
Expand All @@ -186,8 +190,9 @@ private static string GetIPFromHtml(string pageHtml)
}
return ip;
}
catch
catch (Exception Ex)
{
new Log(Ex.ToString());
return null;
}
}
Expand Down
6 changes: 3 additions & 3 deletions LKY_OfficeTools/Common/Com_ProcessOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using System;
using System.Diagnostics;
using static LKY_OfficeTools.Lib.Lib_AppLog;

namespace LKY_OfficeTools.Common
{
Expand Down Expand Up @@ -52,10 +53,9 @@ internal static bool KillProcess(string exe_name)
}
return true;
}
catch /*(Exception Ex)*/
catch (Exception Ex)
{
//Console.ForegroundColor = ConsoleColor.DarkRed;
//new Log(Ex.Message.ToString());
new Log(Ex.ToString());
return false;
}
}
Expand Down
95 changes: 83 additions & 12 deletions LKY_OfficeTools/Common/Com_SystemOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using static LKY_OfficeTools.Lib.Lib_OfficeInfo;
using static LKY_OfficeTools.Lib.Lib_AppLog;

namespace LKY_OfficeTools.Common
{
Expand Down Expand Up @@ -103,7 +106,7 @@ internal static OSType GetPublishType()
else if (ver.Major == 10 && ver.Minor == 0) //正确获取win10版本号,需要在exe里面加入app.manifest
{
//检查注册表,因为win10和11的主版本号都为10,只能用buildID来判断了
string curr_ver = Registry.GetValue(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentBuild");
string curr_ver = Register.GetValue(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentBuild");

if (!string.IsNullOrEmpty(curr_ver) && int.Parse(curr_ver) < 22000) //Win11目前内部版本号
{
Expand All @@ -119,8 +122,9 @@ internal static OSType GetPublishType()
return OSType.UnKnow;
}
}
catch
catch (Exception Ex)
{
new Log(Ex.ToString());
return OSType.UnKnow;
}
}
Expand All @@ -134,7 +138,7 @@ internal static string GetBuildNumber(bool isCoreVersion = true)
try
{
//检查注册表
string curr_mode = Registry.GetValue(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentBuild");
string curr_mode = Register.GetValue(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentBuild");

//为空返回未知
if (string.IsNullOrEmpty(curr_mode))
Expand All @@ -152,17 +156,18 @@ internal static string GetBuildNumber(bool isCoreVersion = true)
return WinPublishType[curr_mode];
}
}
catch
catch (Exception Ex)
{
new Log(Ex.ToString());
return "error!";
}
}
}
}

/// <summary>
/// 注册表操作类库
/// </summary>
internal class Registry
internal class Register
{
/// <summary>
/// 获取指定路径下的注册表键值。
Expand Down Expand Up @@ -198,11 +203,72 @@ internal static string GetValue(string path, string key, RegistryHive root = Reg
}
}
}
catch
catch (Exception Ex)
{
new Log(Ex.ToString());
return null;
}
}

/// <summary>
/// 删除注册表 项下面一切东西
/// </summary>
/// <param name="registry">根项</param>
/// <param name="reg_path">路径</param>
/// <param name="reg_item">最终从哪一项开始删除</param>
/// <returns></returns>
internal static bool DeleteItem(RegistryKey registry, string reg_path, string reg_item)
{
try
{
RegistryKey key = Registry.LocalMachine;
RegistryKey software = key.OpenSubKey(reg_path, true);
software.DeleteSubKeyTree(reg_item, false);

return true;
}
catch (Exception Ex)
{
new Log(Ex.ToString());
return false;
}
}

/// <summary>
/// 从注册表导出到文件。
/// </summary>
/// <param name="save_to">导出的文件的扩展名应当是.REG的</param>
/// <param name="reg_path">指定注册表的某一键被导出,如果指定null值,将导出整个注册表</param>
/// <returns></returns>
internal static bool ExportReg(string reg_path, string save_to)
{
try
{
//先删除已经存在的文件
if (File.Exists(save_to))
{
File.Delete(save_to);
}

//开始导出
Directory.CreateDirectory(new FileInfo(save_to).DirectoryName); //先创建文件所在目录
Process.Start("regedit", $" /E \"{save_to}\" \"{reg_path}\"").WaitForExit();

if (File.Exists(save_to))
{
return true;
}
else
{
return false;
}
}
catch (Exception Ex)
{
new Log(Ex.ToString());
return false;
}
}
}

/// <summary>
Expand Down Expand Up @@ -246,8 +312,9 @@ public static List<string> GetList()
}
return null;
}
catch
catch (Exception Ex)
{
new Log(Ex.ToString());
return null;
}
}
Expand Down Expand Up @@ -286,19 +353,23 @@ internal static bool CaptureToSave(string save_to, ImageFormat file_type = null)
//判断保存格式
if (file_type == null)
{
file_type = ImageFormat.Png;
file_type = ImageFormat.Jpeg;
}

//创建日志目录
Directory.CreateDirectory(new FileInfo(save_to).DirectoryName);

bmp.Save(save_to, file_type);
}

return true;
}
catch
catch (Exception Ex)
{
new Log(Ex.ToString());
return false;
}
}
}
}
}
}
6 changes: 3 additions & 3 deletions LKY_OfficeTools/Common/Com_TextOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System;
using System.Security.Cryptography;
using System.Text;
using static LKY_OfficeTools.Lib.Lib_AppLog;

namespace LKY_OfficeTools.Common
{
Expand All @@ -33,10 +34,9 @@ internal static string GetCenterText(string from_text, string left_str, string r
string result = from_text.Substring(0, right_str_Index); //获取最终值
return result;
}
catch /*(Exception Ex)*/
catch (Exception Ex)
{
//Console.ForegroundColor = ConsoleColor.DarkRed;
//new Log(Ex.Message.ToString());
new Log(Ex.ToString());
return null;
}
}
Expand Down
Loading

0 comments on commit 22487d3

Please sign in to comment.