Skip to content

Commit

Permalink
* 更新文件结构。
Browse files Browse the repository at this point in the history
  • Loading branch information
OdysseusYuan committed Feb 22, 2024
1 parent 31b542b commit e1c650a
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 254 deletions.
132 changes: 0 additions & 132 deletions LKY_OfficeTools/Common/Com_NetworkOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,137 +31,5 @@ internal static bool IsConnected
}
}
}

internal class IP
{
internal static string GetMyIP_Info()
{
try
{
string ip = GetMyIP();
if (string.IsNullOrEmpty(ip))
{
//没获取到IP,则返回未知
ip = "ip_unknow";
}

string ip_location = IP2Location();
if (string.IsNullOrEmpty(ip_location))
{
//没获取到归属地,则返回未知
ip_location = "location_unknow";
}

return $"{ip} ({ip_location})";
}
catch (Exception Ex)
{
new Log(Ex.ToString());
//意外失败,返回error
return "ip_info_error!";
}
}

internal static string GetMyIP()
{
try
{
//截取服务器列表
string ip_server_info = Com_TextOS.GetCenterText(AppJson.Info, "\"IP_Check_Url_List\": \"", "\"");

//遍历获取ip
if (!string.IsNullOrEmpty(ip_server_info))
{
List<string> ip_server = new List<string>(ip_server_info.Split(';'));
foreach (var now_server in ip_server)
{
//获取成功时结束,否则遍历获取
string my_ip_page = Com_WebOS.Visit_WebClient(now_server.Replace(" ", "")); //替换下无用的空格字符后访问Web
string my_ip = GetIPFromHtml(my_ip_page);
if (string.IsNullOrEmpty(my_ip))
{
//获取失败则继续遍历
continue;
}
else
{
return my_ip;
}
}
//始终没获取到IP,则返回null
return null;
}
else
{
//获取失败时,使用默认值
string req_url = "http://www.net.cn/static/customercare/yourip.asp";
string my_ip_page = Com_WebOS.Visit_WebClient(req_url);
return GetIPFromHtml(my_ip_page);
}
}
catch (Exception Ex)
{
new Log(Ex.ToString());
return null;
}
}

internal static string IP2Location()
{
try
{
string req_url = $"https://{DateTime.UtcNow.Year}.ip138.com";

//访问页面
string ip_page = Com_WebOS.Visit_WebClient(req_url);

//页面非空判断
if (string.IsNullOrEmpty(ip_page))
{
throw new Exception();
}

//拆解html
string ip_location = Com_TextOS.GetCenterText(ip_page, "来自:", "</p>").Replace("\r", "").Replace("\n", "");

//解析非空判断
if (string.IsNullOrEmpty(ip_location))
{
throw new Exception();
}

//无任何问题,直接返回该值
return ip_location;
}
catch (Exception Ex)
{
new Log(Ex.ToString());
return null;
}
}

private static string GetIPFromHtml(string pageHtml)
{
try
{
//验证ipv4地址
string reg = @"(?:(?:(25[0-5])|(2[0-4]\d)|((1\d{2})|([1-9]?\d)))\.){3}(?:(25[0-5])|(2[0-4]\d)|((1\d{2})|([1-9]?\d)))";
string ip = "";
Match m = Regex.Match(pageHtml, reg);
if (m.Success)
{
ip = m.Value;
}
return ip;
}
catch (Exception Ex)
{
new Log(Ex.ToString());
return null;
}
}


}
}
}
120 changes: 0 additions & 120 deletions LKY_OfficeTools/Common/Com_SystemOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using static LKY_OfficeTools.Lib.Lib_AppLog;

namespace LKY_OfficeTools.Common
Expand Down Expand Up @@ -315,121 +311,5 @@ internal static bool ExportReg(string reg_path, string save_to)
}
}
}

internal class SoftWare
{
public static List<string> InstalledList()
{
try
{
//从注册表中获取控制面板“卸载程序”中的程序和功能列表
RegistryKey HK_Root_x32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32); //打开x32系统键
RegistryKey HK_Root_x64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); //打开x64系统键

string soft_path = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
RegistryKey software_x32_list = HK_Root_x32.OpenSubKey(soft_path); //x32软件列表
RegistryKey software_x64_list = null; //x64软件列表。x32系统该值将始终为null

//获取x64软件列表(仅在用户系统是x64的情况下获取)
if (Environment.Is64BitOperatingSystem)
{
software_x64_list = HK_Root_x64.OpenSubKey(soft_path);
}

//整合键位
List<RegistryKey> software_key = new List<RegistryKey>();
if (software_x32_list != null && software_x32_list.SubKeyCount > 0)
{
software_key.Add(software_x32_list);
}
if (software_x64_list != null && software_x64_list.SubKeyCount > 0)
{
software_key.Add(software_x64_list);
}

//开始获取
if (software_key != null && software_key.Count > 0)
{
List<string> software_info = new List<string>();

foreach (var now_bit in software_key) //遍历2个系统位数的注册表
{
foreach (string now_subkeyname in now_bit.GetSubKeyNames()) //遍历每个位数下面,对应的软件列表
{
//打开对应的软件名称
RegistryKey SubKey = now_bit.OpenSubKey(now_subkeyname);
if (SubKey != null)
{
string DisplayName = SubKey.GetValue("DisplayName", "NONE").ToString();

//过滤条件
if (DisplayName != "NONE" && !DisplayName.Contains("vs") && !DisplayName.Contains("Visual C++") &&
!DisplayName.Contains(".NET"))
{
software_info.Add(DisplayName);
}
}
}
}

//元素去重
if (software_info != null && software_info.Count > 0)
{
return software_info.Distinct().ToList();
}
}

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

internal class Screen
{
internal static bool CaptureToSave(string save_to, ImageFormat file_type = null)
{
try
{
//初始化屏幕尺寸
int screenLeft = SystemInformation.VirtualScreen.Left;
int screenTop = SystemInformation.VirtualScreen.Top;
int screenWidth = SystemInformation.VirtualScreen.Width;
int screenHeight = SystemInformation.VirtualScreen.Height;

//接收截图
using (Bitmap bmp = new Bitmap(screenWidth, screenHeight))
{
//抓取
using (Graphics g = Graphics.FromImage(bmp))
{
g.CopyFromScreen(screenLeft, screenTop, 0, 0, bmp.Size);
}

//判断保存格式
if (file_type == null)
{
file_type = ImageFormat.Jpeg;
}

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

bmp.Save(save_to, file_type);
}

return true;
}
catch (Exception Ex)
{
new Log(Ex.ToString());
return false;
}
}
}
}
}
4 changes: 2 additions & 2 deletions LKY_OfficeTools/OfficeTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ private static void Entry()
//欢迎话术
Console.Title = $"{AppAttribute.AppName} v{AppAttribute.AppVersion}";
new Log($"{AppAttribute.AppName} [版本 {AppAttribute.AppVersion}]\n" +
$"版权所有(C)LiuKaiyuan (Odysseus.Yuan)。保留所有权利。\n\n" +
$"探讨 {AppAttribute.AppName} 相关内容,可发送邮件至:[email protected]", ConsoleColor.Gray);
$"版权所有(C)LiuKaiyuan (Odysseus.Yuan)。保留所有权利。\n\n" +
$"探讨 {AppAttribute.AppName} 相关内容,可发送邮件至:[email protected]", ConsoleColor.Gray);

//清理冗余信息
Log.Clean();
Expand Down
Binary file removed LKY_OfficeTools/Resource/LKY_Cert.cer
Binary file not shown.

0 comments on commit e1c650a

Please sign in to comment.