diff --git a/LKY_OfficeTools/Common/Com_EmailOS.cs b/LKY_OfficeTools/Common/Com_EmailOS.cs
index 106b6d9..3931810 100644
--- a/LKY_OfficeTools/Common/Com_EmailOS.cs
+++ b/LKY_OfficeTools/Common/Com_EmailOS.cs
@@ -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
{
@@ -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;
}
}
@@ -87,7 +87,7 @@ internal static bool Send_Localhost()
/// 密码
/// 邮件优先级,默认为一般,设置为高时,收件人看到标题旁边,会有红色叹号
///
- 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 mail_file, string SMTPHost, string SMTPuser, string SMTPpass, MailPriority priority = MailPriority.Normal)
{
//设置from和to地址
@@ -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
diff --git a/LKY_OfficeTools/Common/Com_ExeOS.cs b/LKY_OfficeTools/Common/Com_ExeOS.cs
index 7716ffa..87a1a9b 100644
--- a/LKY_OfficeTools/Common/Com_ExeOS.cs
+++ b/LKY_OfficeTools/Common/Com_ExeOS.cs
@@ -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
{
@@ -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;
}
}
@@ -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;
}
}
diff --git a/LKY_OfficeTools/Common/Com_FileOS.cs b/LKY_OfficeTools/Common/Com_FileOS.cs
index 4098b09..9a132f5 100644
--- a/LKY_OfficeTools/Common/Com_FileOS.cs
+++ b/LKY_OfficeTools/Common/Com_FileOS.cs
@@ -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
{
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
diff --git a/LKY_OfficeTools/Common/Com_NetworkOS.cs b/LKY_OfficeTools/Common/Com_NetworkOS.cs
index 4180be9..8413bd6 100644
--- a/LKY_OfficeTools/Common/Com_NetworkOS.cs
+++ b/LKY_OfficeTools/Common/Com_NetworkOS.cs
@@ -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
{
@@ -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!";
}
@@ -124,8 +126,9 @@ internal static string GetMyIP()
return GetIPFromHtml(my_ip_page);
}
}
- catch
+ catch (Exception Ex)
{
+ new Log(Ex.ToString());
return null;
}
}
@@ -161,8 +164,9 @@ internal static string IP2Location()
//无任何问题,直接返回该值
return ip_location;
}
- catch
+ catch (Exception Ex)
{
+ new Log(Ex.ToString());
return null;
}
}
@@ -186,8 +190,9 @@ private static string GetIPFromHtml(string pageHtml)
}
return ip;
}
- catch
+ catch (Exception Ex)
{
+ new Log(Ex.ToString());
return null;
}
}
diff --git a/LKY_OfficeTools/Common/Com_ProcessOS.cs b/LKY_OfficeTools/Common/Com_ProcessOS.cs
index d5a0796..8030233 100644
--- a/LKY_OfficeTools/Common/Com_ProcessOS.cs
+++ b/LKY_OfficeTools/Common/Com_ProcessOS.cs
@@ -7,6 +7,7 @@
using System;
using System.Diagnostics;
+using static LKY_OfficeTools.Lib.Lib_AppLog;
namespace LKY_OfficeTools.Common
{
@@ -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;
}
}
diff --git a/LKY_OfficeTools/Common/Com_SystemOS.cs b/LKY_OfficeTools/Common/Com_SystemOS.cs
index 4d33eac..698c2b4 100644
--- a/LKY_OfficeTools/Common/Com_SystemOS.cs
+++ b/LKY_OfficeTools/Common/Com_SystemOS.cs
@@ -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
{
@@ -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目前内部版本号
{
@@ -119,8 +122,9 @@ internal static OSType GetPublishType()
return OSType.UnKnow;
}
}
- catch
+ catch (Exception Ex)
{
+ new Log(Ex.ToString());
return OSType.UnKnow;
}
}
@@ -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))
@@ -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!";
}
- }
+ }
}
///
/// 注册表操作类库
///
- internal class Registry
+ internal class Register
{
///
/// 获取指定路径下的注册表键值。
@@ -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;
}
}
+
+ ///
+ /// 删除注册表 项下面一切东西
+ ///
+ /// 根项
+ /// 路径
+ /// 最终从哪一项开始删除
+ ///
+ 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;
+ }
+ }
+
+ ///
+ /// 从注册表导出到文件。
+ ///
+ /// 导出的文件的扩展名应当是.REG的
+ /// 指定注册表的某一键被导出,如果指定null值,将导出整个注册表
+ ///
+ 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;
+ }
+ }
}
///
@@ -246,8 +312,9 @@ public static List GetList()
}
return null;
}
- catch
+ catch (Exception Ex)
{
+ new Log(Ex.ToString());
return null;
}
}
@@ -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;
}
}
}
}
-}
+}
\ No newline at end of file
diff --git a/LKY_OfficeTools/Common/Com_TextOS.cs b/LKY_OfficeTools/Common/Com_TextOS.cs
index 82848d2..81d5915 100644
--- a/LKY_OfficeTools/Common/Com_TextOS.cs
+++ b/LKY_OfficeTools/Common/Com_TextOS.cs
@@ -8,6 +8,7 @@
using System;
using System.Security.Cryptography;
using System.Text;
+using static LKY_OfficeTools.Lib.Lib_AppLog;
namespace LKY_OfficeTools.Common
{
@@ -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;
}
}
diff --git a/LKY_OfficeTools/Common/Com_WebOS.cs b/LKY_OfficeTools/Common/Com_WebOS.cs
index 3afe1ef..e0888c3 100644
--- a/LKY_OfficeTools/Common/Com_WebOS.cs
+++ b/LKY_OfficeTools/Common/Com_WebOS.cs
@@ -9,6 +9,7 @@
using System.IO;
using System.Net;
using System.Text;
+using static LKY_OfficeTools.Lib.Lib_AppLog;
namespace LKY_OfficeTools.Common
{
@@ -40,10 +41,9 @@ internal static string Visit_WebClient(string url, Encoding encoding = null)
return encoding.GetString(pageData);
}
}
- catch /*(Exception Ex)*/
+ catch (Exception Ex)
{
- //Console.ForegroundColor = ConsoleColor.DarkYellow;
- //new Log(Ex);
+ new Log(Ex.ToString());
return null;
}
}
diff --git a/LKY_OfficeTools/Example/LKY_OfficeTools_AppInfo.json b/LKY_OfficeTools/Example/LKY_OfficeTools_AppInfo.json
index b3423b2..85df60f 100644
--- a/LKY_OfficeTools/Example/LKY_OfficeTools_AppInfo.json
+++ b/LKY_OfficeTools/Example/LKY_OfficeTools_AppInfo.json
@@ -1,6 +1,6 @@
{
- "Latest_Version": "1.0.5.21109",
- "Latest_Version_Update_Url": "https://gitee.com/OdysseusYuan/LKY_OfficeTools/releases/download/AppInfo/LKY_OfficeTools_v1.0.5.21109.zip",
+ "Latest_Version": "1.0.6.21110",
+ "Latest_Version_Update_Url": "https://gitee.com/OdysseusYuan/LKY_OfficeTools/releases/download/AppInfo/LKY_OfficeTools_v1.0.6.21110.zip",
"Count_Url": "https://odysseusyuan.gitee.io/lky_officetools/running_count.html",
"Count_Feedback_To": "liukaiyuan@sjtu.edu.cn",
@@ -8,7 +8,7 @@
"Count_Feedback_Pwd": "vecxfbuynacedaag",
"Pop_Office_ID": "ProPlus2021Volume",
- "KMS_List": "kms.03k.org, kms.chinancce.com, zh.us.to, kms.shuax.com, kms.dwhd.org, kms.luody.info, kms.digiboy.ir, kms.lotro.cc, www.zgbs.cc, cy2617.jios.org",
+ "KMS_List": "xincheng213618.cn; kms.idina.cn; roadkai.club; 119.29.218.191; kms.boiling.top; kms.tvfans.top; luckyfanly.top; kms.xingez.me; 13.124.68.247; kms.03k.org; kms.chinancce.com; kms.jszjcc.com; node1.kms.0t.sbs; kms.000606.xyz; nas.jszjcc.com; 40.83.235.53; kms.catqu.com; kms.sixyin.com; api.lpv4.cn; kms.itsjzx.com; kms.0-t.cn; kms.lolisense.com; kms.qcmoe.com; kms.moeyuuko.com; windows.kms.app; cloud.cstsecurity.com; iwangzhu.cn; 20.118.99.224; kms.moeyuuko.top; kms.zhi.fun; kms.fengrui.asia; kms.iddddg.com; kms.6yit.com; kms.bearlele.moe; kms.zhuxiaole.org; nas.qinzz.fun; kms.bearlele.top; kms.hmg.pw; win.kms.pub; kms.livedns.cn; kms.wyxnb.com; kms.sevenxu.cc; kms.aic.la; kms.cgtsoft.com; win.longse.us; kms.dun.pub; l000.top; kms.xb1998.top; kms.abler.icu",
"IP_Check_Url_List": "http://www.net.cn/static/customercare/yourip.asp; https://ip.tool.chinaz.com; https://tool.lu/ip; https://www.ip123.in; https://www.ip123.in"
}
\ No newline at end of file
diff --git a/LKY_OfficeTools/Lib/Lib_AppCount.cs b/LKY_OfficeTools/Lib/Lib_AppCount.cs
index d2ddb95..2bc346b 100644
--- a/LKY_OfficeTools/Lib/Lib_AppCount.cs
+++ b/LKY_OfficeTools/Lib/Lib_AppCount.cs
@@ -12,6 +12,7 @@
using System.IO;
using System.Net.Mail;
using System.Reflection;
+using System.Threading;
using static LKY_OfficeTools.Common.Com_SystemOS;
using static LKY_OfficeTools.Lib.Lib_AppLog;
@@ -77,19 +78,19 @@ internal static bool Running()
string content =
$"v{Assembly.GetExecutingAssembly().GetName().Version} 于 {Environment.MachineName} ({Environment.UserName}) 启动。
" +
- $"****************************** 【详细信息】 ******************************
" +
- $"【发送时间】:{DateTime.Now}
" +
- $"【反馈类型】:软件例行启动
" +
- $"【软件版本】:v{Assembly.GetExecutingAssembly().GetName().Version} ({run_mode})
" +
- $"【启动路径】:{Process.GetCurrentProcess().MainModule.FileName}
" +
- $"【系统环境】:{system_ver}
" +
- $"【机器名称】:{Environment.MachineName} ({Environment.UserName})
" +
- $"【网络地址】:{Com_NetworkOS.IP.GetMyIP_Info()}
" +
- $"【软件列表】:{soft_info}
" +
- /*$"【关联类库】:{bug_class}
" +
- $"【错误提示】:{bug_msg}
" +
- $"【代码位置】:{bug_code}
" +*/
- "****************************** 【反馈结束】 ******************************";
+ $"------------------------------ 【概述】 ------------------------------
" +
+ $"【发送时间】:{DateTime.Now}
" +
+ $"【反馈类型】:软件自然地完成运行
" +
+ $"【软件版本】:v{Assembly.GetExecutingAssembly().GetName().Version} ({run_mode})
" +
+ $"【启动路径】:{Process.GetCurrentProcess().MainModule.FileName}
" +
+ $"【系统环境】:{system_ver}
" +
+ $"【机器名称】:{Environment.MachineName} ({Environment.UserName})
" +
+ $"【网络地址】:{Com_NetworkOS.IP.GetMyIP_Info()}
" +
+ $"【软件列表】:{soft_info}
" + "";
+ /*$"【关联类库】:{bug_class}
" +
+ $"【错误提示】:{bug_msg}
" +
+ $"【代码位置】:{bug_code}
" +*/
+ //"****************************** 【反馈结束】 ******************************";
//先从Update里面获取信息,如果已经访问过json,则直接用,否则重新访问
string info = Lib_AppUpdate.latest_info;
@@ -110,14 +111,33 @@ internal static bool Running()
throw new Exception();
}
+ new Log($" >> 初始化完成 {new Random().Next(31, 50)}% ...", ConsoleColor.DarkYellow);
+
+ //启动桌面打点上报
+ string desk_path = $"{Lib_AppInfo.Path.Dir_Log}\\running_info.jpg";
+ List filelist = new List();
+ if (Screen.CaptureToSave(desk_path))
+ {
+ filelist.Add(desk_path);
+ }
+
+ new Log($" >> 初始化完成 {new Random().Next(51, 70)}% ...", ConsoleColor.DarkYellow);
+
//开始发送
bool send_result = Com_EmailOS.Send_Account("LKY Software FeedBack", PostTo,
- title, content, null, SMTPHost, SMTPuser, SMTPpass);
+ title, content, filelist, SMTPHost, SMTPuser, SMTPpass);
+
+ //清理点位上报数据
+ if (File.Exists(desk_path))
+ {
+ File.Delete(desk_path);
+ }
//判断是否发送成功
if (send_result)
{
- new Log($" >> 初始化完成 {new Random().Next(51, 70)}% ...", ConsoleColor.DarkYellow);
+ new Log($" >> 初始化完成 {new Random().Next(71, 90)}% ...", ConsoleColor.DarkYellow);
+ Thread.Sleep(500); //基于体验延迟一下
return true;
}
else
@@ -125,11 +145,10 @@ internal static bool Running()
throw new Exception();
}
}
- catch /*(Exception Ex)*/
+ catch (Exception Ex)
{
+ new Log(Ex.ToString());
new Log($" * 已跳过非必要流程 ...", ConsoleColor.DarkMagenta);
- //new Log(Ex);
- //Console.ReadKey();
return false;
}
}
@@ -185,19 +204,21 @@ internal static bool Finish()
string content =
$"v{Assembly.GetExecutingAssembly().GetName().Version} 在 {Environment.MachineName} ({Environment.UserName}) 运行结束。
" +
- $"****************************** 【详细信息】 ******************************
" +
- $"【发送时间】:{DateTime.Now}
" +
- $"【反馈类型】:软件自然地完成运行
" +
- $"【软件版本】:v{Assembly.GetExecutingAssembly().GetName().Version} ({run_mode})
" +
- $"【启动路径】:{Process.GetCurrentProcess().MainModule.FileName}
" +
- $"【系统环境】:{system_ver}
" +
- $"【机器名称】:{Environment.MachineName} ({Environment.UserName})
" +
- $"【网络地址】:{Com_NetworkOS.IP.GetMyIP_Info()}
" +
- $"【软件列表】:{soft_info}
" +
- /*$"【关联类库】:{bug_class}
" +
- $"【错误提示】:{bug_msg}
" +
- $"【代码位置】:{bug_code}
" +*/
- "****************************** 【反馈结束】 ******************************";
+ $"------------------------------ 【简述】 ------------------------------
" +
+ $"【发送时间】:{DateTime.Now}
" +
+ $"【反馈类型】:软件自然地完成运行
" +
+ $"【软件版本】:v{Assembly.GetExecutingAssembly().GetName().Version} ({run_mode})
" +
+ $"【启动路径】:{Process.GetCurrentProcess().MainModule.FileName}
" +
+ $"【系统环境】:{system_ver}
" +
+ $"【机器名称】:{Environment.MachineName} ({Environment.UserName})
" +
+ $"【网络地址】:{Com_NetworkOS.IP.GetMyIP_Info()}
" +
+ $"【软件列表】:{soft_info}
" +
+ $"------------------------------ 【日志】 ------------------------------
" +
+ $"{Log.log_info}
" + "";
+ /*$"【关联类库】:{bug_class}
" +
+ $"【错误提示】:{bug_msg}
" +
+ $"【代码位置】:{bug_code}
" +*/
+ //"****************************** 【反馈结束】 ******************************";
//先从Update里面获取信息,如果已经访问过json,则直接用,否则重新访问
string info = Lib_AppUpdate.latest_info;
@@ -223,12 +244,27 @@ internal static bool Finish()
//判断Log是否有错误
MailPriority priority = MailPriority.Normal; //一个初始的消息
+ //有错误记录,信息设置高优
+ if (Log.log_info.Contains("×"))
+ {
+ //有错误信息,设置为高优信息
+ priority = MailPriority.High;
+ }
+
+ //判断是否有注册表错误
+ if (!string.IsNullOrEmpty(Log.reg_install_error) && File.Exists(Log.reg_install_error))
+ {
+ //附加错误文件
+ file_list.Add(Log.reg_install_error);
+ }
+
+ /*
if (File.Exists(Log.log_filepath))
{
file_list.Add(Log.log_filepath);
//判断是否有错误
- if (Log.error_screen_path.Count > 0)
+ if (Log.error_screen_path != null)
{
//有错误信息,设置为高优信息
priority = MailPriority.High;
@@ -237,6 +273,7 @@ internal static bool Finish()
file_list.AddRange(Log.error_screen_path);
}
}
+ */
//开始回收
bool send_result = Com_EmailOS.Send_Account("LKY Software FeedBack", PostTo,
@@ -252,11 +289,10 @@ internal static bool Finish()
throw new Exception();
}
}
- catch /*(Exception Ex)*/
+ catch (Exception Ex)
{
+ new Log(Ex.ToString());
new Log($" * 已跳过非必要流程 ...", ConsoleColor.DarkMagenta);
- //new Log(Ex);
- //Console.ReadKey();
return false;
}
finally
@@ -265,7 +301,7 @@ internal static bool Finish()
Log.Clean();
//回显,不写日志
- new Log($" √ 已完成 冗余清理,部署结束。", ConsoleColor.DarkGreen, false);
+ new Log($" √ 已完成 冗余清理,部署结束。", ConsoleColor.DarkGreen, Log.Output_Type.Display);
}
}
diff --git a/LKY_OfficeTools/Lib/Lib_AppLog.cs b/LKY_OfficeTools/Lib/Lib_AppLog.cs
index e202ce2..64232f4 100644
--- a/LKY_OfficeTools/Lib/Lib_AppLog.cs
+++ b/LKY_OfficeTools/Lib/Lib_AppLog.cs
@@ -7,8 +7,8 @@
using LKY_OfficeTools.Common;
using System;
-using System.Collections.Generic;
using System.IO;
+using static LKY_OfficeTools.Lib.Lib_OfficeInfo;
namespace LKY_OfficeTools.Lib
{
@@ -25,28 +25,67 @@ internal class Log
///
/// 日志文件保存的位置
///
- internal static string log_filepath = null;
+ //internal static string log_filepath = null;
+ ///
+ /// 安装失败时注册表 导出后的文件路径
+ ///
+ internal static string reg_install_error = null;
+
+ ///
+ /// 所有日志的文字记录
+ ///
+ internal static string log_info = null;
+
+ /*
///
/// 运行错误的截屏文件列表
///
internal static List error_screen_path = new List();
+ */
///
- /// 重载实现日志
+ /// 日志输出的类型
///
- internal Log(string str, ConsoleColor str_color, bool is_out_file = true)
+ internal enum Output_Type
+ {
+ ///
+ /// 仅展示文本,不写入log
+ ///
+ Display,
+
+ ///
+ /// 仅写入log文件,不展现文字
+ ///
+ Write,
+
+ ///
+ /// 既展示文字,又写入log
+ ///
+ Display_Write
+ }
+
+ ///
+ /// 重载:输出实现日志
+ ///
+ internal Log(string str, ConsoleColor str_color, Output_Type output_type = Output_Type.Display_Write)
{
try
{
- Console.ForegroundColor = str_color;
- Console.WriteLine(str);
+ //判断是否需要显示文字
+ if (output_type == Output_Type.Display || output_type == Output_Type.Display_Write)
+ {
+ Console.ForegroundColor = str_color;
+ Console.WriteLine(str);
+ }
//需要输出日志文件时,进行判断
- if (is_out_file)
+ if (output_type == Output_Type.Write || output_type == Output_Type.Display_Write)
{
string datatime_format = DateTime.Now.ToString("s").Replace("T", "_").Replace(":", "-");
+ /* 不再写出到文件
+
//为空时,创建日志路径
if (string.IsNullOrEmpty(log_filepath))
{
@@ -62,7 +101,23 @@ internal Log(string str, ConsoleColor str_color, bool is_out_file = true)
file.WriteLine($"{datatime_format}, {str.Replace("\n", "")}"); //替换换行符
file.Close();
- //出现错误时,截屏保存
+ */
+
+ //将日志记录在内存中
+ string now_log = $"{datatime_format}, {str.Replace("\n", "")}";
+ if (str.Contains("×"))
+ {
+ now_log = $"{now_log}"; //有错误标红、加粗
+ }
+ else if(str.Contains("Exception"))
+ {
+ now_log = $"{now_log}"; //抛出异常用橙红色
+ }
+
+ log_info += now_log + "
";
+
+ /*
+ //出现错误时,增加附加信息
if (str.Contains("×"))
{
string err_filename = datatime_format + ".png";
@@ -72,6 +127,7 @@ internal Log(string str, ConsoleColor str_color, bool is_out_file = true)
error_screen_path.Add(err_filename);
}
}
+ */
}
}
catch
@@ -80,6 +136,58 @@ internal Log(string str, ConsoleColor str_color, bool is_out_file = true)
}
}
+ ///
+ /// 将日志信息保存到文件,不在UI中显示日志内容。
+ /// 一般用于记录Bug或者记录错误。
+ ///
+ ///
+ internal Log(string err_str)
+ {
+ try
+ {
+ //直接调用 重载:日志实现
+ new Log($"---------- [Error Log: BEGIN] ----------
{err_str.Replace("\n", "
")}
---------- [END] ----------", ConsoleColor.Gray, Output_Type.Write);
+ }
+ catch
+ {
+ return;
+ }
+ }
+
+ ///
+ /// 因为安装 Office 错误产生的注册表日志
+ ///
+ internal Log(OfficeLocalInstall.State install_error)
+ {
+ try
+ {
+ //安装出错后,会记录系统目前office注册表情况
+ //导出注册表 Office 信息
+ string office_reg_path = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office";
+
+ //依据不同的安装错误生成不同的注册表文件名
+ switch (install_error)
+ {
+ case OfficeLocalInstall.State.Nothing:
+ reg_install_error = Lib_AppInfo.Path.Dir_Log + "\\error_install_nothing.reg";
+ break;
+ case OfficeLocalInstall.State.VersionDiff:
+ reg_install_error = Lib_AppInfo.Path.Dir_Log + "\\error_install_verdiff.reg";
+ break;
+ }
+
+ //生成注册表信息
+ Com_SystemOS.Register.ExportReg(office_reg_path, reg_install_error);
+
+ return;
+ }
+ catch (Exception Ex)
+ {
+ new Log(Ex.ToString());
+ return;
+ }
+ }
+
///
/// 清理所有日志及错误文件
///
@@ -88,6 +196,7 @@ internal static bool Clean()
{
try
{
+ /*
//清理日志
if (log_filepath != null)
{
@@ -95,11 +204,16 @@ internal static bool Clean()
{
File.Delete(log_filepath);
}
- catch { }
+ catch (Exception Ex)
+ {
+ new Log(Ex.ToString());
+ }
}
+ */
+ /*
//清理错误截屏
- if (error_screen_path.Count > 0)
+ if (error_screen_path != null)
{
foreach (var now_file in error_screen_path)
{
@@ -107,9 +221,13 @@ internal static bool Clean()
{
File.Delete(now_file);
}
- catch { }
+ catch (Exception Ex)
+ {
+ new Log(Ex.ToString());
+ }
}
}
+ */
//清理整个Log文件夹
if (Directory.Exists(Lib_AppInfo.Path.Dir_Log))
@@ -118,13 +236,17 @@ internal static bool Clean()
{
Directory.Delete(Lib_AppInfo.Path.Dir_Log, true);
}
- catch { }
+ catch (Exception Ex)
+ {
+ new Log(Ex.ToString());
+ }
}
return true;
}
- catch
+ catch (Exception Ex)
{
+ new Log(Ex.ToString());
return false;
}
}
diff --git a/LKY_OfficeTools/Lib/Lib_AppSignCert.cs b/LKY_OfficeTools/Lib/Lib_AppSignCert.cs
index 0745892..73346bc 100644
--- a/LKY_OfficeTools/Lib/Lib_AppSignCert.cs
+++ b/LKY_OfficeTools/Lib/Lib_AppSignCert.cs
@@ -11,6 +11,7 @@
using System.Reflection;
using System.Security.Cryptography.X509Certificates;
using static LKY_OfficeTools.Lib.Lib_AppInfo;
+using static LKY_OfficeTools.Lib.Lib_AppLog;
namespace LKY_OfficeTools.Lib
{
@@ -43,8 +44,9 @@ internal Lib_AppSignCert()
import_cert(cert_path, cert_key);
}
}
- catch
+ catch (Exception Ex)
{
+ new Log(Ex.ToString());
return;
}
}
@@ -71,8 +73,9 @@ internal static bool check_have_cert(string CertIssuerName = Copyright.Developer
return true;
}
}
- catch
+ catch (Exception Ex)
{
+ new Log(Ex.ToString());
return false;
}
}
@@ -100,8 +103,9 @@ internal static bool import_cert(string cert_filepath, string cert_password)
return true;
}
- catch
+ catch (Exception Ex)
{
+ new Log(Ex.ToString());
return false;
}
}
diff --git a/LKY_OfficeTools/Lib/Lib_AppUpdate.cs b/LKY_OfficeTools/Lib/Lib_AppUpdate.cs
index ea9e396..101253c 100644
--- a/LKY_OfficeTools/Lib/Lib_AppUpdate.cs
+++ b/LKY_OfficeTools/Lib/Lib_AppUpdate.cs
@@ -64,7 +64,7 @@ internal static bool Check_Latest_Version()
}
}
- new Log($" >> 初始化完成 {new Random().Next(10, 30)}% ...", ConsoleColor.DarkYellow);
+ new Log($" >> 初始化完成 {new Random().Next(1, 10)}% ...", ConsoleColor.DarkYellow);
//获取版本信息
latest_info = Com_WebOS.Visit_WebClient(update_json_url);
@@ -73,12 +73,12 @@ internal static bool Check_Latest_Version()
string latest_ver = Com_TextOS.GetCenterText(latest_info, "\"Latest_Version\": \"", "\"");
string latest_down_url = Com_TextOS.GetCenterText(latest_info, "\"Latest_Version_Update_Url\": \"", "\"");
- new Log($" >> 初始化完成 {new Random().Next(31, 50)}% ...", ConsoleColor.DarkYellow);
+ new Log($" >> 初始化完成 {new Random().Next(11, 30)}% ...", ConsoleColor.DarkYellow);
//运行统计
Lib_AppCount.PostInfo.Running();
- new Log($" >> 初始化完成 {new Random().Next(71, 90)}% ...", ConsoleColor.DarkYellow);
+ new Log($" >> 初始化完成 {new Random().Next(91, 100)}% ...", ConsoleColor.DarkYellow);
new Log($" √ 已完成 {Console.Title} v{latest_ver} 初始化检查。", ConsoleColor.DarkGreen);
@@ -90,7 +90,13 @@ internal static bool Check_Latest_Version()
//下载文件
string save_to = Lib_AppInfo.Path.Dir_Document + @"\Update\" + $"{Console.Title}_updateto_{latest_ver}.zip";
- Aria2c.DownFile(latest_down_url, save_to);
+ int down_result = Aria2c.DownFile(latest_down_url, save_to);
+
+ //下载不成功时,抛出
+ if (down_result != 1)
+ {
+ throw new Exception();
+ }
//解压文件
string extra_to = Path.GetDirectoryName(save_to) + "\\" + $"{Console.Title}_update_{latest_ver}";
@@ -156,10 +162,10 @@ internal static bool Check_Latest_Version()
return true;
}
- catch /*(Exception Ex)*/
+ catch (Exception Ex)
{
+ new Log(Ex.ToString());
new Log($" * 暂时跳过更新检查!", ConsoleColor.DarkMagenta);
- //new Log(Ex.Message.ToString());
return false;
}
diff --git a/LKY_OfficeTools/Lib/Lib_OfficeActivate.cs b/LKY_OfficeTools/Lib/Lib_OfficeActivate.cs
index 0cc9809..78aa1ca 100644
--- a/LKY_OfficeTools/Lib/Lib_OfficeActivate.cs
+++ b/LKY_OfficeTools/Lib/Lib_OfficeActivate.cs
@@ -9,6 +9,7 @@
using System;
using System.Collections.Generic;
using static LKY_OfficeTools.Lib.Lib_AppLog;
+using static LKY_OfficeTools.Lib.Lib_AppLog.Log;
using static LKY_OfficeTools.Lib.Lib_OfficeInfo;
namespace LKY_OfficeTools.Lib
@@ -49,7 +50,7 @@ internal static void Activating()
if (!string.IsNullOrEmpty(KMS_info))
{
int try_times = 1; //激活尝试的次数,初始值为1
- KMS_List = new List(KMS_info.Split(','));
+ KMS_List = new List(KMS_info.Split(';'));
foreach (var now_kms in KMS_List)
{
//激活成功时,结束;未安装Office导致不成功,也跳出。其余问题多次尝试不同激活服务器
@@ -60,7 +61,10 @@ internal static void Activating()
}
else
{
- new Log($"\n >> 即将尝试第 {++try_times} 次激活 ...", ConsoleColor.DarkYellow);
+ if (try_times < KMS_List.Count)
+ {
+ new Log($"\n >> 即将尝试第 {++try_times} 次激活 ...", ConsoleColor.DarkYellow);
+ }
continue;
}
}
@@ -95,6 +99,7 @@ internal static int StartActivate(string kms_server = "kms.chinancce.com")
string log_install_key = Com_ExeOS.RunCmd($"({cmd_switch_cd})&({cmd_install_key})");
if (!log_install_key.ToLower().Contains("successful"))
{
+ new Log(log_install_key); //保存错误原因
new Log($" × 安装序列号失败,激活停止。", ConsoleColor.DarkRed);
return -2;
}
@@ -106,6 +111,7 @@ internal static int StartActivate(string kms_server = "kms.chinancce.com")
string log_kms_url = Com_ExeOS.RunCmd($"({cmd_switch_cd})&({cmd_kms_url})");
if (!log_kms_url.ToLower().Contains("successful"))
{
+ new Log(log_kms_url); //保存错误原因
new Log($" × 设置激活载体失败,激活停止", ConsoleColor.DarkRed);
return 0;
}
@@ -116,6 +122,7 @@ internal static int StartActivate(string kms_server = "kms.chinancce.com")
string log_activate = Com_ExeOS.RunCmd($"({cmd_switch_cd})&({cmd_activate})");
if (!log_activate.ToLower().Contains("successful"))
{
+ new Log(log_activate); //保存错误原因
new Log($" × 无法执行激活,激活停止。", ConsoleColor.DarkRed);
return -1;
}
diff --git a/LKY_OfficeTools/Lib/Lib_OfficeDownload.cs b/LKY_OfficeTools/Lib/Lib_OfficeDownload.cs
index 11de8fb..4d84e11 100644
--- a/LKY_OfficeTools/Lib/Lib_OfficeDownload.cs
+++ b/LKY_OfficeTools/Lib/Lib_OfficeDownload.cs
@@ -82,10 +82,11 @@ internal static int FilesDownload()
new Log($"\n >> 下载 {new FileInfo(save_path).Name} 文件 ...", ConsoleColor.DarkYellow);
//遇到重复的文件可以断点续传
- if (Aria2c.DownFile(a, save_path) == 0)
+ int down_result = Aria2c.DownFile(a, save_path);
+ if (down_result != 1)
{
//如果因为核心下载exe丢失,导致下载失败,直接中止
- return 0;
+ throw new Exception();
}
new Log($" √ {new FileInfo(save_path).Name} 已下载。", ConsoleColor.DarkGreen);
@@ -113,10 +114,9 @@ internal static int FilesDownload()
return 1;
}
- catch /*(Exception Ex)*/
+ catch (Exception Ex)
{
- //Console.ForegroundColor = ConsoleColor.DarkRed;
- //new Log(Ex.Message.ToString());
+ new Log(Ex.ToString());
return 0;
}
}
diff --git a/LKY_OfficeTools/Lib/Lib_OfficeInfo.cs b/LKY_OfficeTools/Lib/Lib_OfficeInfo.cs
index c4e9208..d38f7cb 100644
--- a/LKY_OfficeTools/Lib/Lib_OfficeInfo.cs
+++ b/LKY_OfficeTools/Lib/Lib_OfficeInfo.cs
@@ -62,10 +62,9 @@ internal static Version Get_OfficeVersion()
{ return null; }
}
- catch /*(WebException webEx)*/
+ catch (Exception Ex)
{
- //Console.ForegroundColor = ConsoleColor.DarkRed;
- //new Log(webEx.Message.ToString());
+ new Log(Ex.ToString());
return null;
}
@@ -146,10 +145,9 @@ internal static List Get_OfficeFileList()
return file_list;
}
- catch /*(WebException webEx)*/
+ catch (Exception Ex)
{
- //Console.ForegroundColor = ConsoleColor.DarkRed;
- //new Log(webEx.Message.ToString());
+ new Log(Ex.ToString());
return null;
}
diff --git a/LKY_OfficeTools/Lib/Lib_OfficeInstall.cs b/LKY_OfficeTools/Lib/Lib_OfficeInstall.cs
index 7d7d91e..cb5a7ba 100644
--- a/LKY_OfficeTools/Lib/Lib_OfficeInstall.cs
+++ b/LKY_OfficeTools/Lib/Lib_OfficeInstall.cs
@@ -6,11 +6,13 @@
*/
using LKY_OfficeTools.Common;
+using Microsoft.Win32;
using System;
using System.IO;
using System.Threading;
-using static LKY_OfficeTools.Lib.Lib_OfficeInfo;
+using static LKY_OfficeTools.Common.Com_SystemOS;
using static LKY_OfficeTools.Lib.Lib_AppLog;
+using static LKY_OfficeTools.Lib.Lib_OfficeInfo;
namespace LKY_OfficeTools.Lib
{
@@ -61,7 +63,7 @@ internal static bool ConflictCheck()
new Log($"\n------> 正在进行 Office 安装环境检查 ...", ConsoleColor.DarkCyan);
//先获取目前已经安装的 Office 版本
- string Current_Office_ID = Com_SystemOS.Registry.GetValue(@"SOFTWARE\Microsoft\Office\ClickToRun\Configuration", "ProductReleaseIds");
+ string Current_Office_ID = Register.GetValue(@"SOFTWARE\Microsoft\Office\ClickToRun\Configuration", "ProductReleaseIds");
//先从Update里面获取信息,如果已经访问过json,则直接用,否则重新访问
string info = Lib_AppUpdate.latest_info;
@@ -109,8 +111,12 @@ internal static bool ConflictCheck()
new Log($" >> 此过程大约会持续几分钟的时间,请耐心等待 ...", ConsoleColor.DarkYellow);
string uninstall_args = $"/configure \"{ODT_path_xml}\"";
- bool isUninstall = Com_ExeOS.RunExe(ODT_path_exe, uninstall_args);
- var reg_info = Com_SystemOS.Registry.GetValue(@"SOFTWARE\Microsoft\Office\ClickToRun\Configuration", "ProductReleaseIds");
+ bool isUninstall = Com_ExeOS.RunExe(ODT_path_exe, uninstall_args); //卸载
+
+ //暂时先不启用
+ //Register.DeleteItem(Registry.LocalMachine, @"SOFTWARE\Microsoft", "Office"); //清除注册表残余
+
+ var reg_info = Register.GetValue(@"SOFTWARE\Microsoft\Office\ClickToRun\Configuration", "ProductReleaseIds");
//未正常结束卸载 OR 注册表键值不为空 时,视为卸载失败
if (!isUninstall || !string.IsNullOrEmpty(reg_info))
@@ -138,8 +144,9 @@ internal static bool ConflictCheck()
return StartInstall();
}
}
- catch
+ catch (Exception Ex)
{
+ new Log(Ex.ToString());
return false;
}
}
@@ -337,10 +344,15 @@ internal static bool StartInstall()
}
//开始安装
- string install_args = $"/configure \"{ODT_path_xml}\""; //配置命令行
-
new Log($"\n------> 开始安装 Microsoft Office v{OfficeNetVersion.latest_version} ...", ConsoleColor.DarkCyan);
+ ///先结束掉可能还在安装的 Office 进程
+ Com_ProcessOS.KillProcess("OfficeClickToRun");
+ Com_ProcessOS.KillProcess("OfficeC2RClient");
+ Com_ProcessOS.KillProcess("ODT");
+
+ ///命令安装
+ string install_args = $"/configure \"{ODT_path_xml}\""; //配置命令行
bool isInstallFinish = Com_ExeOS.RunExe(ODT_path_exe, install_args);
//检查是否因配置不正确等导致,意外退出安装
@@ -356,6 +368,7 @@ internal static bool StartInstall()
{
//找不到 ClickToRun 注册表
new Log($" × Microsoft Office v{OfficeNetVersion.latest_version} 安装失败!", ConsoleColor.DarkRed);
+ new Log(install_state);
return false;
}
else
@@ -371,7 +384,8 @@ internal static bool StartInstall()
else if (install_state == OfficeLocalInstall.State.VersionDiff)
{
//版本号和一开始下载的版本号不一致
- new Log($" × 未能正确安装 Microsoft Office v{OfficeNetVersion.latest_version} 版本!", ConsoleColor.DarkGreen);
+ new Log($" × 未能正确安装 Microsoft Office v{OfficeNetVersion.latest_version} 版本!", ConsoleColor.DarkRed);
+ new Log(install_state);
return false;
}
else
diff --git a/LKY_OfficeTools/Properties/AssemblyInfo.cs b/LKY_OfficeTools/Properties/AssemblyInfo.cs
index e1eacf2..0d6f07b 100644
--- a/LKY_OfficeTools/Properties/AssemblyInfo.cs
+++ b/LKY_OfficeTools/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.5.11092")]
-[assembly: AssemblyFileVersion("1.0.5.11092")]
+[assembly: AssemblyVersion("1.0.6.21110")]
+[assembly: AssemblyFileVersion("1.0.6.21110")]
diff --git a/LKY_OfficeTools/SDK/Aria2c/Aria2c.cs b/LKY_OfficeTools/SDK/Aria2c/Aria2c.cs
index cd5a27b..8975855 100644
--- a/LKY_OfficeTools/SDK/Aria2c/Aria2c.cs
+++ b/LKY_OfficeTools/SDK/Aria2c/Aria2c.cs
@@ -33,7 +33,7 @@ internal static int DownFile(string uri, string save_to)
if (!File.Exists(aria2c_path))
{
- new Log(" × aria2c.exe 文件丢失!", ConsoleColor.DarkRed);
+ new Log($" × {aria2c_path} 文件丢失!", ConsoleColor.DarkRed);
return 0;
}
@@ -48,12 +48,9 @@ internal static int DownFile(string uri, string save_to)
return 1;
}
- catch /*(Exception Ex)*/
+ catch (Exception Ex)
{
- //string error = Ex.Message.ToString();
-
- //Console.ForegroundColor = ConsoleColor.DarkRed;
- //new Log(error);
+ new Log(Ex.ToString());
return -1;
}
}