Skip to content

Commit

Permalink
+ 更新版本至 v1.2.1.621,更新程序Logo。
Browse files Browse the repository at this point in the history
+ 允许高于官方最新版本号的产品激活。此举主要用于解决安装官方补丁后,版本号可能变化的情况。
* 调整交互信息。删除下载中冗余的提示信息。控制台输出文字后重置默认颜色。
! 修正其它逻辑隐患。
  • Loading branch information
OdysseusYuan committed Jun 21, 2023
1 parent 0945ac2 commit cc00c6e
Show file tree
Hide file tree
Showing 12 changed files with 384 additions and 299 deletions.
2 changes: 1 addition & 1 deletion LKY_OfficeTools/Lib/Lib_AppInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal class AppAttribute
/// <summary>
/// APP 版本号
/// </summary>
internal const string AppVersion = "1.2.1.526";
internal const string AppVersion = "1.2.1.621";

/// <summary>
/// 开发者拼音全拼
Expand Down
5 changes: 4 additions & 1 deletion LKY_OfficeTools/Lib/Lib_AppLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System;
using System.IO;
using static LKY_OfficeTools.Lib.Lib_AppInfo.AppPath;
using static LKY_OfficeTools.Lib.Lib_OfficeInfo.OfficeLocalInstall;
using static LKY_OfficeTools.Lib.Lib_OfficeInfo.OfficeLocalInfo;

namespace LKY_OfficeTools.Lib
{
Expand Down Expand Up @@ -78,6 +78,9 @@ internal Log(string str, ConsoleColor str_color, Output_Type output_type = Outpu
{
Console.ForegroundColor = str_color;
Console.WriteLine(str);

//输出后恢复颜色
Console.ForegroundColor = ConsoleColor.Gray;
}

//需要输出日志文件时,进行判断
Expand Down
12 changes: 6 additions & 6 deletions LKY_OfficeTools/Lib/Lib_AppReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ internal class Lib_AppReport
/// <returns></returns>
internal static bool Pointing(ProcessStage point_type, bool show_info = false)
{
try
//Passive不打点
if (Current_RunMode == RunMode.Passive)
{
//Passive不打点
if (Current_RunMode == RunMode.Passive)
{
return true;
}
return true;
}

try
{
if (show_info && point_type != ProcessStage.Starting)
{
new Log($"\n------> 正在清理 冗余数据,请勿关闭或重启电脑 ...", ConsoleColor.DarkCyan);
Expand Down
4 changes: 2 additions & 2 deletions LKY_OfficeTools/Lib/Lib_AppUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ internal static bool Check()

//升级成功打点
Current_StageType = ProcessStage.Update_Success;
Pointing(Current_StageType);
Pointing(ProcessStage.Update_Success);

//延迟稍许
Thread.Sleep(2000);
Expand Down Expand Up @@ -263,7 +263,7 @@ static void ManualUpdate()

//自动升级失败
Current_StageType = ProcessStage.Update_Fail; //设置为失败
Pointing(Current_StageType, true); //回收
Pointing(ProcessStage.Update_Fail, true); //回收

KeyMsg.Quit(-20);
}
Expand Down
3 changes: 2 additions & 1 deletion LKY_OfficeTools/Lib/Lib_Aria2c.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ internal static int DownFile(string uri, string save_to)
string filename = new FileInfo(save_to).Name; //保存的文件名

//设置命令行
string aria2c_params = $"{uri} --dir=\"{file_path}\" --out=\"{filename}\" --continue=true --max-connection-per-server=5 --check-integrity=true --file-allocation=none";
string aria2c_params = $"{uri} --dir=\"{file_path}\" --out=\"{filename}\"" +
$" --continue=true --max-connection-per-server=5 --check-integrity=true --file-allocation=none --console-log-level=error";
//new Log(aria2c_params);

var down_result = Com_ExeOS.Run.Exe(aria2c_path, aria2c_params);
Expand Down
14 changes: 3 additions & 11 deletions LKY_OfficeTools/Lib/Lib_OfficeActivate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using static LKY_OfficeTools.Lib.Lib_AppInfo.AppPath;
using static LKY_OfficeTools.Lib.Lib_AppLog;
using static LKY_OfficeTools.Lib.Lib_OfficeInfo;
using static LKY_OfficeTools.Lib.Lib_OfficeInfo.OfficeLocalInstall;
using static LKY_OfficeTools.Lib.Lib_OfficeInfo.OfficeLocalInfo;

namespace LKY_OfficeTools.Lib
{
Expand All @@ -24,14 +24,6 @@ namespace LKY_OfficeTools.Lib
/// </summary>
internal class Lib_OfficeActivate
{
/// <summary>
/// 重载实现激活
/// </summary>
internal Lib_OfficeActivate()
{
Activating();
}

/// <summary>
/// KMS 服务器列表
/// </summary>
Expand Down Expand Up @@ -97,7 +89,7 @@ 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"; //开始激活

new Log($"\n------> 正在激活 Office v{OfficeNetVersion.latest_version} ...", ConsoleColor.DarkCyan);
new Log($"\n------> 正在激活 Office v{OfficeNetInfo.OfficeLatestVersion} ...", ConsoleColor.DarkCyan);

//执行:设置激活KMS地址
string kms_flag = kms_server.Replace("kms.", "");
Expand Down Expand Up @@ -225,7 +217,7 @@ internal static int StartActivate(string kms_server = "kms.chinancce.com")
return -1;
}

new Log($" √ 已完成 Office v{OfficeNetVersion.latest_version} 正版激活。", ConsoleColor.DarkGreen);
new Log($" √ 已完成 Office v{OfficeNetInfo.OfficeLatestVersion} 正版激活。", ConsoleColor.DarkGreen);
Lib_AppState.Current_StageType = Lib_AppState.ProcessStage.Finish_Success; //设置整体运行状态为成功

return 1;
Expand Down
14 changes: 7 additions & 7 deletions LKY_OfficeTools/Lib/Lib_OfficeClean.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ internal static bool RemoveAllOffice()
Uninstall.BySaRA();

//无论哪种方式清理,都要再检查一遍是否卸载干净。如果 当前系统 Office 版本数量 > 0,启动强制模式
var installed_office = OfficeLocalInstall.GetArchiDir();
var license_list = OfficeLocalInstall.LicenseInfo();
var installed_office = OfficeLocalInfo.GetArchiDir();
var license_list = OfficeLocalInfo.LicenseInfo();
if (
(installed_office != null && installed_office.Count > 0) || //存在残留的Office注册表/文件目录
license_list != null && license_list.Count > 0 //存在残留的许可证信息
Expand Down Expand Up @@ -86,7 +86,7 @@ internal static bool Delete()
try
{
//获取激活信息
var office_installed_key = OfficeLocalInstall.LicenseInfo();
var office_installed_key = OfficeLocalInfo.LicenseInfo();

if (office_installed_key != null && office_installed_key.Count > 0)
{
Expand All @@ -108,7 +108,7 @@ internal static bool Delete()
}

//逐一卸载后,若都为 success,则再执行一次检查
office_installed_key = OfficeLocalInstall.LicenseInfo(); //再度获取list
office_installed_key = OfficeLocalInfo.LicenseInfo(); //再度获取list
if (office_installed_key.Count == 0) //为0,视为成功
{
return true;
Expand Down Expand Up @@ -151,7 +151,7 @@ internal static bool ForceDelete()
try
{
//有些文件可能无法彻底删除,但如果后面复查时,不影响安装,则不会返回 false
var office_installed_dir = OfficeLocalInstall.GetArchiDir();
var office_installed_dir = OfficeLocalInfo.GetArchiDir();
if (office_installed_dir != null && office_installed_dir.Count > 0)
{
foreach (var now_dir in office_installed_dir) //遍历查询所有目录,将其删除
Expand Down Expand Up @@ -213,7 +213,7 @@ internal static bool ForceDelete()
}

//复查是否干净了
var installed_info = OfficeLocalInstall.GetArchiDir();
var installed_info = OfficeLocalInfo.GetArchiDir();
if (installed_info != null && installed_info.Count > 0)
{
throw new Exception();
Expand Down Expand Up @@ -372,7 +372,7 @@ internal static bool BySaRA()
new Log($"\n------> 正在卸载 Office 冗余版本 ...", ConsoleColor.DarkCyan);

//获取目前存留的版本
var install_list = OfficeLocalInstall.GetArchiDir();
var install_list = OfficeLocalInfo.GetArchiDir();
if (install_list == null || install_list.Count == 0)
{
//已经不存在残留版本时,直接返回卸载成功
Expand Down
52 changes: 10 additions & 42 deletions LKY_OfficeTools/Lib/Lib_OfficeDownload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using static LKY_OfficeTools.Lib.Lib_AppInfo;
using static LKY_OfficeTools.Lib.Lib_AppLog;
using static LKY_OfficeTools.Lib.Lib_OfficeInfo;
using static LKY_OfficeTools.Lib.Lib_OfficeInfo.OfficeLocalInstall;

namespace LKY_OfficeTools.Lib
{
Expand All @@ -21,61 +20,30 @@ namespace LKY_OfficeTools.Lib
/// </summary>
internal class Lib_OfficeDownload
{
/// <summary>
/// 下载文件列表
/// </summary>
static List<string> down_list = null;

/// <summary>
/// 重载实现下载
/// </summary>
internal Lib_OfficeDownload()
{
//FilesDownload();
}

/// <summary>
/// 下载所有文件(Aria2c)
/// 返回值:-1【用户终止】,0【下载失败】,1【下载成功】,2【无需下载】
/// 返回值:-1【用户终止】,0【下载失败】,1【下载成功】
/// </summary>
internal static int FilesDownload()
internal static int StartDownload()
{
try
{
//获取下载列表
down_list = OfficeNetVersion.GetOfficeFileList();
if (down_list == null)
{
//因列表获取异常,停止下载
return 0;
}

//判断是否已经安装了当前版本
InstallState install_state = GetOfficeState();
if (install_state==InstallState.Correct) //已安装最新版,无需下载
{
new Log($"\n * 当前系统安装了最新 Office 版本,已跳过下载、安装流程。", ConsoleColor.DarkMagenta);
return 2;
}
///当不存在 VersionToReport or 其版本与最新版不一致 or 产品ID不一致 or 安装位数与系统不一致时,需要下载新文件。

//定义下载目标地
string save_to = AppPath.ExecuteDir + @"\Office\Data\"; //文件必须位于 \Office\Data\ 下,
//ODT安装必须在 Office 上一级目录上执行。
//定义下载目标地。文件必须位于 \Office\Data\下。ODT安装必须在 Office 上一级目录上执行。
string save_to = AppPath.ExecuteDir + @"\Office\Data\";

//计划保存的地址
List<string> save_files = new List<string>();

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

//轮询下载所有文件
foreach (var a in down_list)
foreach (var a in OfficeNetInfo.OfficeFileList)
{
//根据官方目录,来调整下载保存位置
string save_path = save_to + a.Substring(OfficeNetVersion.office_file_root_url.Length).Replace("/", "\\");
string save_path = save_to + a.Substring(OfficeNetInfo.OfficeUrlRoot.Length).Replace("/", "\\");

//保存到List里面,用于后续检查
save_files.Add(save_path);
Expand All @@ -99,7 +67,7 @@ internal static int FilesDownload()
new Log($" √ 已下载 {new FileInfo(save_path).Name} 文件。", ConsoleColor.DarkGreen);
}

new Log($"\n------> 正在检查 Office v{OfficeNetVersion.latest_version} 文件 ...", ConsoleColor.DarkCyan);
new Log($"\n------> 正在检查 Office v{OfficeNetInfo.OfficeLatestVersion} 文件 ...", ConsoleColor.DarkCyan);

foreach (var b in save_files)
{
Expand All @@ -113,11 +81,11 @@ internal static int FilesDownload()
else
{
new Log($" >> 文件 {new FileInfo(b).Name} 存在异常,重试中 ...", ConsoleColor.DarkRed);
return FilesDownload();
return StartDownload();
}
}

new Log($" √ 已完成 Office v{OfficeNetVersion.latest_version} 下载。", ConsoleColor.DarkGreen);
new Log($" √ 已完成 Office v{OfficeNetInfo.OfficeLatestVersion} 下载。", ConsoleColor.DarkGreen);

return 1;
}
Expand Down
Loading

0 comments on commit cc00c6e

Please sign in to comment.