Skip to content

Commit

Permalink
优化架构逻辑,规范化输出。
Browse files Browse the repository at this point in the history
  • Loading branch information
OdysseusYuan committed Nov 6, 2022
1 parent 733fc97 commit 4790210
Show file tree
Hide file tree
Showing 19 changed files with 282 additions and 143 deletions.
4 changes: 2 additions & 2 deletions LKY_OfficeTools/Common/Com_EmailOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ internal static bool Send_Localhost()
}
catch (SmtpException ex)
{
Console.WriteLine(ex);
new Log(ex);
return false;
}
}
Expand Down Expand Up @@ -137,7 +137,7 @@ public static bool Send_Account( string send_from_username, string send_to_mail,
}
catch /*(Exception err)*/
{
//Console.WriteLine(err);
//new Log(err);
//Console.ReadKey();
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions LKY_OfficeTools/Common/Com_ExeOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal static bool RunExe(string runFilePath, string args)
catch /*(Exception Ex)*/
{
//Console.ForegroundColor = ConsoleColor.DarkRed;
//Console.WriteLine(Ex.Message.ToString());
//new Log(Ex.Message.ToString());
return false;
}
}
Expand Down Expand Up @@ -113,7 +113,7 @@ internal static string RunCmd(string args)
catch /*(Exception Ex)*/
{
//Console.ForegroundColor = ConsoleColor.DarkRed;
//Console.WriteLine(Ex.Message.ToString());
//new Log(Ex.Message.ToString());
return null;
}
}
Expand Down
14 changes: 7 additions & 7 deletions LKY_OfficeTools/Common/Com_FileOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal static bool SetValue(string xml_path, string Key_str, string new_Value)
//判断是否替换成功
if (string.IsNullOrEmpty(xml_new_content))
{
//Console.WriteLine("替换失败!");
//new Log("替换失败!");
return false;
}

Expand All @@ -56,7 +56,7 @@ internal static bool SetValue(string xml_path, string Key_str, string new_Value)
catch /*(Exception Ex)*/
{
//Console.ForegroundColor = ConsoleColor.DarkRed;
//Console.WriteLine(Ex.Message.ToString());
//new Log(Ex.Message.ToString());
return false;
}
}
Expand Down Expand Up @@ -105,11 +105,11 @@ public void GetFilesByExtension(string dirPath, string fileType = "*", bool isRo
if (dir.FullName.Contains("$RECYCLE.BIN") || dir.FullName.Contains("System Volume Information"))
{
//Console.ForegroundColor = ConsoleColor.DarkGray;
//Console.WriteLine("跳过: " + dir.FullName);
//new Log("跳过: " + dir.FullName);
}
else
{
//Console.WriteLine("----->: " + dir.FullName);
//new Log("----->: " + dir.FullName);
GetFilesByExtension(dir.FullName, fileType);
}
}
Expand All @@ -119,15 +119,15 @@ public void GetFilesByExtension(string dirPath, string fileType = "*", bool isRo
//遍历下一个子目录
foreach (DirectoryInfo subFolders in folder.GetDirectories())
{
//Console.WriteLine(subFolders.FullName);
//new Log(subFolders.FullName);
GetFilesByExtension(subFolders.FullName, fileType);
}
}
}
else
{
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine("不存在: " + dirPath);
/*Console.ForegroundColor = ConsoleColor.DarkGray;
new Log("不存在: " + dirPath);*/
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions LKY_OfficeTools/Common/Com_PrivilegeOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using System;
using System.Security.Principal;
using static LKY_OfficeTools.Lib.Lib_SelfLog;

namespace LKY_OfficeTools.Common
{
Expand All @@ -31,23 +32,20 @@ internal static bool IsRunByAdmin()
/// </summary>
internal static void PrivilegeAttention()
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine($"\n\n------> 正在进行 权限检查 ...");
new Log($"\n\n------> 正在进行 权限检查 ...", ConsoleColor.DarkCyan);

//提权检验,非提权,激活会出问题
if (!IsRunByAdmin())
{
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine($" × 权限错误,请以管理员身份运行此文件!");
new Log($" × 权限错误,请以管理员身份运行此文件!", ConsoleColor.DarkRed);

Console.ForegroundColor = ConsoleColor.Gray;
Console.Write("\n请按任意键退出 ...");
Console.Read();
Environment.Exit(-1);
}

Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine($" √ 权限检查通过。");
new Log($" √ 权限检查通过。", ConsoleColor.DarkGreen);
}
}
}
2 changes: 1 addition & 1 deletion LKY_OfficeTools/Common/Com_ProcessOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal static bool KillProcess(string exe_name)
catch /*(Exception Ex)*/
{
//Console.ForegroundColor = ConsoleColor.DarkRed;
//Console.WriteLine(Ex.Message.ToString());
//new Log(Ex.Message.ToString());
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion LKY_OfficeTools/Common/Com_TextOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal static string GetCenterText(string from_text, string left_str, string r
catch /*(Exception Ex)*/
{
//Console.ForegroundColor = ConsoleColor.DarkRed;
//Console.WriteLine(Ex.Message.ToString());
//new Log(Ex.Message.ToString());
return null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion LKY_OfficeTools/Common/Com_WebOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal static string Visit_WebClient(string url, Encoding encoding = null)
catch /*(Exception Ex)*/
{
//Console.ForegroundColor = ConsoleColor.DarkYellow;
//Console.WriteLine(Ex);
//new Log(Ex);
return null;
}
}
Expand Down
4 changes: 2 additions & 2 deletions LKY_OfficeTools/Example/LKY_OfficeTools_AppInfo.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Latest_Version": "1.0.2.21103",
"Latest_Version_Update_Url": "https://gitee.com/OdysseusYuan/LKY_OfficeTools/releases/download/AppInfo/LKY_OfficeTools_v1.0.2.21103.zip",
"Latest_Version": "1.0.3.21107",
"Latest_Version_Update_Url": "https://gitee.com/OdysseusYuan/LKY_OfficeTools/releases/download/AppInfo/LKY_OfficeTools_v1.0.3.21107.zip",

"Count_Url": "https://odysseusyuan.gitee.io/lky_officetools/running_count.html",
"Count_Feedback_To": "[email protected]",
Expand Down
1 change: 1 addition & 0 deletions LKY_OfficeTools/LKY_OfficeTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<Compile Include="Lib\Lib_OfficeInfo.cs" />
<Compile Include="Lib\Lib_OfficeInstall.cs" />
<Compile Include="Lib\Lib_SelfCount.cs" />
<Compile Include="Lib\Lib_SelfLog.cs" />
<Compile Include="Lib\Lib_SelfUpdate.cs" />
<Compile Include="OfficeTools.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
35 changes: 13 additions & 22 deletions LKY_OfficeTools/Lib/Lib_OfficeActivate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System;
using System.Collections.Generic;
using static LKY_OfficeTools.Lib.Lib_OfficeInfo;
using static LKY_OfficeTools.Lib.Lib_SelfLog;

namespace LKY_OfficeTools.Lib
{
Expand Down Expand Up @@ -85,51 +86,41 @@ internal static int StartActivate(string kms_server = "kms.chinancce.com")
string cmd_kms_url = $"cscript ospp.vbs /sethst:{kms_server}"; //设置激活KMS地址
string cmd_activate = "cscript ospp.vbs /act"; //开始激活

Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine($"\n------> 正在激活 Microsoft Office v{OfficeNetVersion.latest_version} ...");
new Log($"\n------> 正在激活 Microsoft Office v{OfficeNetVersion.latest_version} ...", ConsoleColor.DarkCyan);

//执行:安装序列号
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine($"\n >> 安装 Office 序列号 ...");
new Log($"\n >> 安装 Office 序列号 ...", ConsoleColor.DarkYellow);
string log_install_key = Com_ExeOS.RunCmd($"({cmd_switch_cd})&({cmd_install_key})");
if (!log_install_key.ToLower().Contains("successful"))
{
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine($" × 安装序列号失败,激活终止,请稍后重试!如有问题请联系开发者。");
new Log($" × 安装序列号失败,激活终止,请稍后重试!如有问题请联系开发者。", ConsoleColor.DarkRed);
return -2;
}
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine($" √ 安装序列号完成。");
new Log($" √ 安装序列号完成。", ConsoleColor.DarkGreen);

//执行:设置激活KMS地址
string kms_flag = kms_server.Replace("kms.", "");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine($"\n >> 设置 Office [{kms_flag}] 激活载体 ...");
new Log($"\n >> 设置 Office [{kms_flag}] 激活载体 ...", ConsoleColor.DarkYellow);
string log_kms_url = Com_ExeOS.RunCmd($"({cmd_switch_cd})&({cmd_kms_url})");
if (!log_kms_url.ToLower().Contains("successful"))
{
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine($" × 设置激活载体失败,激活终止,请稍后重试!如有问题请联系开发者。");
new Log($" × 设置激活载体失败,激活终止,请稍后重试!如有问题请联系开发者。", ConsoleColor.DarkRed);
return 0;
}
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine($" √ 设置激活载体完成。");
new Log($" √ 设置激活载体完成。", ConsoleColor.DarkGreen);

//执行:开始激活
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine($"\n >> 执行 Office 激活 ...");
new Log($"\n >> 执行 Office 激活 ...", ConsoleColor.DarkYellow);
string log_activate = Com_ExeOS.RunCmd($"({cmd_switch_cd})&({cmd_activate})");
if (!log_activate.ToLower().Contains("successful"))
{
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine($" × 无法执行激活,请稍后重试!如有问题请联系开发者。");
new Log($" × 无法执行激活,请稍后重试!如有问题请联系开发者。", ConsoleColor.DarkRed);
return -1;
}
/*Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($" √ 执行激活完成。");*/
new Log($" √ 执行激活完成。");*/

Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine($" √ Microsoft Office v{OfficeNetVersion.latest_version} 激活成功。");
new Log($" √ Microsoft Office v{OfficeNetVersion.latest_version} 激活成功。", ConsoleColor.DarkGreen);

return 1;

Expand All @@ -139,7 +130,7 @@ internal static int StartActivate(string kms_server = "kms.chinancce.com")
//开始激活
string log_activate = Com_ExeOS.RunCmd(cmd);
Console.WriteLine("结果:" + log_activate);
new Log("结果:" + log_activate);
*/
}
return -10;
Expand Down
27 changes: 10 additions & 17 deletions LKY_OfficeTools/Lib/Lib_OfficeDownload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.IO;
using System.Threading;
using static LKY_OfficeTools.Lib.Lib_OfficeInfo;
using static LKY_OfficeTools.Lib.Lib_SelfLog;

namespace LKY_OfficeTools.Lib
{
Expand Down Expand Up @@ -52,8 +53,7 @@ internal static int FilesDownload()
OfficeLocalInstall.State install_state = OfficeLocalInstall.GetState();
if (install_state == OfficeLocalInstall.State.Installed)
{
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine($"\n * 当前系统已经安装了最新版本,无需重复下载安装!");
new Log($"\n * 当前系统已经安装了最新版本,无需重复下载安装!", ConsoleColor.DarkMagenta);
return -1;
}
///当不存在 \Configuration\ 项 or 不存在 VersionToReport or 其版本与最新版不一致时,需要下载新文件。
Expand All @@ -66,8 +66,7 @@ internal static int FilesDownload()
List<string> save_files = new List<string>();

//下载开始
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine($"\n------> 开始下载 Microsoft Office v{OfficeNetVersion.latest_version} 文件 ...");
new Log($"\n------> 开始下载 Microsoft Office v{OfficeNetVersion.latest_version} 文件 ...", ConsoleColor.DarkCyan);
//延迟,让用户看到开始下载
Thread.Sleep(1000);

Expand All @@ -80,18 +79,15 @@ internal static int FilesDownload()
//保存到List里面,用于后续检查
save_files.Add(save_path);

Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine($"\n >> 下载 {new FileInfo(save_path).Name} 文件 ...");
new Log($"\n >> 下载 {new FileInfo(save_path).Name} 文件 ...", ConsoleColor.DarkYellow);

//遇到重复的文件可以断点续传
Aria2c.DownFile(a, save_path);

Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine($" √ {new FileInfo(save_path).Name} 已下载。\n");
new Log($" √ {new FileInfo(save_path).Name} 已下载。\n", ConsoleColor.DarkGreen);
}

Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine($"\n------> 正在检查 Microsoft Office v{OfficeNetVersion.latest_version} 文件 ...");
new Log($"\n------> 正在检查 Microsoft Office v{OfficeNetVersion.latest_version} 文件 ...", ConsoleColor.DarkCyan);

foreach (var b in save_files)
{
Expand All @@ -100,26 +96,23 @@ internal static int FilesDownload()
//下载完成的标志:文件存在,且不存在临时文件
if (File.Exists(b) && !File.Exists(aria_tmp_file))
{
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine($" >> 检查 {new FileInfo(b).Name} ...");
new Log($" >> 检查 {new FileInfo(b).Name} ...", ConsoleColor.DarkYellow);
}
else
{
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine($" >> 文件 {new FileInfo(b).Name} 存在异常,重试中 ...");
new Log($" >> 文件 {new FileInfo(b).Name} 存在异常,重试中 ...", ConsoleColor.DarkRed);
FilesDownload();
}
}

Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine($" √ Microsoft Office v{OfficeNetVersion.latest_version} 下载完成。\n");
new Log($" √ Microsoft Office v{OfficeNetVersion.latest_version} 下载完成。\n", ConsoleColor.DarkGreen);

return 1;
}
catch /*(Exception Ex)*/
{
//Console.ForegroundColor = ConsoleColor.DarkRed;
//Console.WriteLine(Ex.Message.ToString());
//new Log(Ex.Message.ToString());
return 0;
}
}
Expand Down
Loading

0 comments on commit 4790210

Please sign in to comment.