chore(build): 更新项目配置和依赖以支持.NET 8

- 在.settings.local.json中添加dotnet clean命令权限
- 更新项目文件以启用不安全的二进制序列化和禁用平台兼容性警告
- 配置调试和发布模式的编译常量及优化选项
- 在解决方案文件中升级Visual Studio版本并添加多平台配置
- 移除FormLogin构造函数中的MessageBox调试代码
- 为过时的WebRequest、WebClient和ServicePointManager API添加编译警告抑制
- 简化异常处理逻辑并在Program.cs中改进启动流程
- 移除多个未使用的局部变量声明
- 添加launchSettings.json以支持开发环境配置
- 在表单构造函数中初始化components容器
- 优化网络请求超时设置并改善错误处理机制
This commit is contained in:
danial
2025-11-10 19:34:27 +08:00
parent 7203d57370
commit 06b0fcce08
21 changed files with 334 additions and 191 deletions

View File

@@ -3,7 +3,8 @@
"allow": [
"Bash(find:*)",
"Bash(dotnet build:*)",
"Bash(dotnet publish:*)"
"Bash(dotnet publish:*)",
"Bash(dotnet clean:*)"
],
"deny": [],
"ask": []

View File

@@ -83,7 +83,6 @@ namespace AppleBatch_June.ExecuteTasks
{
_action?.Invoke(guidTag, DisplyType.chongzhi, "");
string accountName = "";
bool _flag = false;
AppleChangeItem changeItem2 = new AppleChangeItem
{
newGuojia = changeItem.newGuojia,

View File

@@ -77,7 +77,6 @@ namespace AppleBatch_June.ExecuteTasks
if (((dynamic)obj)["Data"]["integral"] >= AppSysConfig.getTypeById(14).consNum)
{
_action?.Invoke(guidTag, DisplyType.chongzhi, "");
bool _flag = false;
if ((!AppSysConfig.webProtocolS2k) ? new AppleManageWebUtlis(_action, null, this).RetrievePassword(openVpn, appleAcount, newPassWord, guidTag, isCloseAuthen: true, ckTailNumber) : new AppleiForgotWeb(openVpn, _action, null, this).RetrievePassword(appleAcount, newPassWord, guidTag, isCloseAuthen: true, ckTailNumber))
{
APIUtlis.ApiApplyAct(14, "关闭双重认证");

View File

@@ -25,7 +25,6 @@ namespace AppleBatch_June.ExecuteTasks
private int passGetGameByUrl(bool ckQueryMOdel, GetGameUtils itunes, string gameUrl, AppleItunesLogin itunesLogin)
{
int _num = 0;
if (ckQueryMOdel)
{
return itunes.getNewGameByUrl3(gameUrl, itunesLogin);

View File

@@ -651,7 +651,9 @@ namespace AppleBatch_June.ExecuteTasks
{
try
{
#pragma warning disable SYSLIB0014 // WebRequest is obsolete
HttpWebRequest httpWebRequest = WebRequest.Create(AppSysConfig.getConfig("TestingProxyIpUrl")) as HttpWebRequest;
#pragma warning restore SYSLIB0014 // WebRequest is obsolete
httpWebRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
httpWebRequest.Method = "OPTIONS";
httpWebRequest.KeepAlive = false;

View File

@@ -76,7 +76,6 @@ namespace AppleBatch_June.ExecuteTasks
if (((dynamic)obj)["Data"]["integral"] >= AppSysConfig.getTypeById(22).consNum)
{
_action?.Invoke(appleAcount.appleId, DisplyType.chongzhi, "");
bool _flag = false;
if ((!AppSysConfig.webProtocolS2k) ? new AppleManageWebUtlis2(_action, null, this).AppleQueryStoreBalance(appleAcount, openVpn) : new AppleShopWeb(openVpn, appleAcount.appleId, _action, null, this).AppleQueryStoreBalance(appleAcount, actGetCode))
{
APIUtlis.ApiApplyAct(27, "商城余额查询");

View File

@@ -125,6 +125,7 @@ namespace AppleBatch_June.Forms
public FromActiotiCloud()
: base("激活iCloud", ActivateiCloudTask.Instance)
{
components = new Container();
InitializeComponent();
}

View File

@@ -10,7 +10,45 @@
<ApplicationIcon>app.ico</ApplicationIcon>
<RootNamespace />
<GenerateResourceWarnOnBinaryFormatterUse>false</GenerateResourceWarnOnBinaryFormatterUse>
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
<!-- 禁用平台兼容性警告,因为这是 Windows 专用应用 -->
<NoWarn>$(NoWarn);CA1416</NoWarn>
<!-- 调试配置 -->
<DefineConstants Condition=" '$(Configuration)' == 'Debug' ">DEBUG;TRACE</DefineConstants>
<DefineConstants Condition=" '$(Configuration)' == 'Release' ">TRACE</DefineConstants>
<!-- 平台配置 -->
<Platforms>AnyCPU;x64;x86</Platforms>
<PlatformTarget>AnyCPU</PlatformTarget>
<!-- 输出配置 -->
<OutputPath>bin\$(Configuration)\$(TargetFramework)</OutputPath>
<DebugType Condition=" '$(Configuration)' == 'Debug' ">full</DebugType>
<DebugType Condition=" '$(Configuration)' == 'Release' ">pdbonly</DebugType>
<DebugSymbols Condition=" '$(Configuration)' == 'Debug' ">true</DebugSymbols>
<!-- 编译配置 -->
<Optimize Condition=" '$(Configuration)' == 'Debug' ">false</Optimize>
<Optimize Condition=" '$(Configuration)' == 'Release' ">true</Optimize>
</PropertyGroup>
<!-- Debug配置 -->
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
<Optimize>false</Optimize>
</PropertyGroup>
<!-- Release配置 -->
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DefineConstants>TRACE</DefineConstants>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Text.Json" Version="8.0.0" />
<PackageReference Include="System.Management" Version="8.0.0" />

View File

@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.35026.282
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AppleBatch_June", "AppleBatch_June.csproj", "{D7E018FC-0746-4D4E-B8DE-9D854A8D8D24}"
EndProject
@@ -9,12 +9,24 @@ Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Debug|x64 = Debug|x64
Release|x64 = Release|x64
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D7E018FC-0746-4D4E-B8DE-9D854A8D8D24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D7E018FC-0746-4D4E-B8DE-9D854A8D8D24}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D7E018FC-0746-4D4E-B8DE-9D854A8D8D24}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D7E018FC-0746-4D4E-B8DE-9D854A8D8D24}.Release|Any CPU.Build.0 = Release|Any CPU
{D7E018FC-0746-4D4E-B8DE-9D854A8D8D24}.Debug|x64.ActiveCfg = Debug|x64
{D7E018FC-0746-4D4E-B8DE-9D854A8D8D24}.Debug|x64.Build.0 = Debug|x64
{D7E018FC-0746-4D4E-B8DE-9D854A8D8D24}.Release|x64.ActiveCfg = Release|x64
{D7E018FC-0746-4D4E-B8DE-9D854A8D8D24}.Release|x64.Build.0 = Release|x64
{D7E018FC-0746-4D4E-B8DE-9D854A8D8D24}.Debug|x86.ActiveCfg = Debug|x86
{D7E018FC-0746-4D4E-B8DE-9D854A8D8D24}.Debug|x86.Build.0 = Debug|x86
{D7E018FC-0746-4D4E-B8DE-9D854A8D8D24}.Release|x86.ActiveCfg = Release|x86
{D7E018FC-0746-4D4E-B8DE-9D854A8D8D24}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -22,4 +34,7 @@ Global
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CFA3E97F-8263-4AEC-83AD-B2B7A97E4E6E}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = AppleBatch_June.csproj
EndGlobalSection
EndGlobal

View File

@@ -44,7 +44,6 @@ namespace AppleBatch_June
public HttpResult doPost(object postData, string type, bool retry = false)
{
MessageBox.Show(postData.ToString());
using HttpHelper httpHelper = new HttpHelper();
Stopwatch stopwatch = Stopwatch.StartNew();
string text = "";

View File

@@ -124,7 +124,9 @@ namespace AppleBatch_June
private HttpWebRequest SetiTunesHtppHeaders(string string_3, byte[] byte_2, string string_4, string string_5, string string_6, iTunesUserInfo user, string usrage, IWebProxy webProxy = null)
{
#pragma warning disable SYSLIB0014 // WebRequest is obsolete
HttpWebRequest httpWebRequest = WebRequest.Create(new Uri(string_3)) as HttpWebRequest;
#pragma warning restore SYSLIB0014 // WebRequest is obsolete
httpWebRequest.Method = "POST";
httpWebRequest.Headers["User-Agent"] = usrage;
if (string_4.Length > 0)

View File

@@ -60,57 +60,116 @@ namespace AppleBatch_June
public FormLogin()
{
components = new Container();
InitializeComponent();
init();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
// 简化启动检查
if (path.ToLower().Contains("rar$"))
{
MessageBox.Show("检测到程序未解压,请先解压压缩包在打开");
Environment.Exit(0);
return;
}
// 设置安全协议
#pragma warning disable SYSLIB0014 // ServicePointManager is obsolete in .NET 5+
ServicePointManager.DefaultConnectionLimit = 512;
ServicePointManager.Expect100Continue = false;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = (object sender2, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) => true;
#pragma warning restore SYSLIB0014 // ServicePointManager is obsolete in .NET 5+
// 延迟数据文件初始化避免在启动时访问Resources
Task.Run(() => InitializeDataFiles());
// 设置界面颜色
txtPwd.ForeColor = SystemColors.MenuHighlight;
txtUser.ForeColor = SystemColors.MenuHighlight;
// 启用界面
base.Enabled = true;
}
catch (Exception ex)
{
MessageBox.Show($"窗体加载失败: {ex.Message}", "启动错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void InitializeDataFiles()
{
try
{
if (!Directory.Exists(runTimePatch + "/AppleBatch"))
string appDataPath = runTimePatch + "/AppleBatch";
// 确保目录存在
if (!Directory.Exists(appDataPath))
{
Directory.CreateDirectory(runTimePatch + "/AppleBatch");
Directory.CreateDirectory(appDataPath);
}
if (!File.Exists(runTimePatch + "/AppleBatch/AppleDB.db"))
// 延迟创建数据库文件
string dbPath = appDataPath + "/AppleDB.db";
if (!File.Exists(dbPath))
{
File.WriteAllBytes(runTimePatch + "/AppleBatch/AppleDB.db", Resources.AppleDB);
try
{
if (Resources.AppleDB != null && Resources.AppleDB.Length > 0)
{
File.WriteAllBytes(dbPath, Resources.AppleDB);
}
}
catch (Exception ex)
{
APIUtlis.ApiSeriveError(ex);
// 在UI线程上显示错误
this.Invoke(new Action(() => {
MessageBox.Show($"数据库文件创建失败: {ex.Message}", "资源错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}));
}
}
}
catch (Exception ex)
{
// 在UI线程上显示错误
this.Invoke(new Action(() => {
MessageBox.Show($"数据目录初始化失败: {ex.Message}", "初始化错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}));
}
txtPwd.ForeColor = SystemColors.MenuHighlight;
txtUser.ForeColor = SystemColors.MenuHighlight;
base.Enabled = false;
init();
}
public async void init()
{
Task result = Task.Run(delegate
{
try
{
Stopwatch stopwatch = Stopwatch.StartNew();
MachineCode machineCode = new MachineCode();
AppSysConfig.saffMac = Tools.GetMD5_32(machineCode.GetMachineCodeString() + "巴拉拉小魔仙");
AppSysConfig.newSaffMac = Tools.GetMD5_32(machineCode.GetMachineCodeString(moAddress: true) + "LiuYue_Acbse");
stopwatch.Stop();
}
catch (Exception ex)
{
MessageBox.Show($"机器码生成失败: {ex.Message}", "初始化警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
});
try
{
string[] array = new string[3] { "https://gitee.com/liuyueapp/blogsLiuyue/raw/master/assets/aphos.css", "https://meixi2.oss-us-west-1.aliyuncs.com/host.txt", "https://zjzhuanfa.oss-cn-shenzhen.aliyuncs.com/host.txt" };
int count = 1;
int tCount = 1;
string[] array2 = array;
foreach (string hostItem in array2)
{
try
{
HttpHelper http = new HttpHelper();
HttpResult httpResult = await Task.Run(delegate
@@ -119,7 +178,7 @@ namespace AppleBatch_June
{
URL = hostItem,
Method = "GET",
Timeout = 20000,
Timeout = 5000, // 减少超时时间
UserAgent = AppleUtlis.getAppleWenUserAgent()
};
return http.GetHtml(item);
@@ -136,32 +195,58 @@ namespace AppleBatch_June
if (!string.IsNullOrEmpty(text))
{
string text2 = text.Split('\n')[0].Trim().TrimEnd('\r');
try
{
if (http.GetHtml(new HttpItem
{
URL = text2 + "/hosy/addbak",
Method = "GET",
Timeout = 10000
Timeout = 5000
}).StatusCode == HttpStatusCode.NotFound)
{
ApiNetReq.host = text2;
break;
}
}
catch
{
// 继续尝试下一个地址
continue;
}
}
tCount++;
}
break;
}
catch
{
count++;
continue;
}
}
}
catch (Exception ex)
{
MessageBox.Show($"网络初始化失败,将使用离线模式: {ex.Message}", "网络警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
await result;
if (!string.IsNullOrEmpty(ApiNetReq.host))
{
SyncInitConfig();
return;
}
MessageBox.Show("初始化失败了" + count.ToString() + "#" + tCount);
Environment.Exit(0);
// 如果所有网络请求都失败,提供备用方案
MessageBox.Show("网络连接失败,程序将在离线模式下运行。\n如需完整功能请检查网络连接。", "初始化完成", MessageBoxButtons.OK, MessageBoxIcon.Information);
// 设置默认配置,让程序可以继续运行
base.Enabled = true;
}
public async void SyncInitConfig()
{
try
{
_ = Environment.OSVersion.Version;
string WindowsVersion = "Windows 10 专业版";
@@ -174,24 +259,30 @@ namespace AppleBatch_June
}
catch (Exception ex)
{
APIUtlis.ApiSeriveError(ex);
MessageBox.Show($"系统信息获取失败: {ex.Message}", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
if (string.IsNullOrEmpty(WindowsVersion))
{
WindowsVersion = "";
}
try
{
HttpResult httpResult = await Task.Run(() => new ApiNetReq().doPost(new Dictionary<string, object>
{
{ "account", "123" },
{ "pwd", "123" }
}, "ApiSysConfig"));
if (httpResult.StatusCode == HttpStatusCode.OK)
{
base.Enabled = true;
if (!AppSysConfig.loadConfig(httpResult.Html))
{
MessageBox.Show("初始化失败了#2");
Environment.Exit(0);
MessageBox.Show("配置加载失败,将使用默认配置", "配置警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
// 使用默认配置继续运行,而不是退出
base.Enabled = true;
return;
}
string text = AppSysConfig.getConfig("versionsNew").Trim();
if (text != versions && !string.IsNullOrEmpty(text) && MessageBox.Show("发现新版本,是否更新?" + AppSysConfig.getConfig("versionsTip").Replace("\\n", "\n"), "新版本提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
@@ -207,11 +298,27 @@ namespace AppleBatch_June
}
else
{
MessageBox.Show("初始化加载失败了");
Environment.Exit(0);
MessageBox.Show("网络配置获取失败,将使用默认配置继续运行", "网络警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
base.Enabled = true;
}
}
catch (Exception ex)
{
MessageBox.Show($"配置同步失败,将使用默认配置: {ex.Message}", "配置警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
base.Enabled = true;
}
// 确保界面总是启用
base.Enabled = true;
loadConfig();
}
catch (Exception ex)
{
MessageBox.Show($"初始化过程发生错误: {ex.Message}\n\n程序将尝试继续运行", "严重错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
base.Enabled = true;
loadConfig(); // 尝试加载本地配置
}
}
public Task DownLoadSQLiteInterop()
{
@@ -255,10 +362,12 @@ namespace AppleBatch_June
if (!File.Exists(text2))
{
string text3 = text2 + ".tmp";
#pragma warning disable SYSLIB0014 // WebClient is obsolete
using (WebClient webClient = new WebClient())
{
webClient.DownloadFile(address, text3);
}
#pragma warning restore SYSLIB0014 // WebClient is obsolete
File.Move(text3, text2);
}
stopwatch.Stop();

View File

@@ -354,7 +354,9 @@ namespace AppleBatch_June
{
return;
}
#pragma warning disable SYSLIB0014 // ServicePointManager is obsolete in .NET 5+
Console.WriteLine("DefaultConnectionLimit:" + ServicePointManager.DefaultConnectionLimit);
#pragma warning restore SYSLIB0014 // ServicePointManager is obsolete in .NET 5+
ProxyRunService.resetProxyData();
ProxyAccountCache.ReclassifyAccountAll();
int thredSizeNum = 2;

View File

@@ -1365,6 +1365,7 @@ namespace AppleBatch_June
public FromMain()
{
components = new Container();
InitializeComponent();
}
@@ -1547,7 +1548,9 @@ namespace AppleBatch_June
private void FromMain_Load(object sender, EventArgs e)
{
#pragma warning disable SYSLIB0014 // ServicePointManager is obsolete in .NET 5+
ServicePointManager.DefaultConnectionLimit = 512;
#pragma warning restore SYSLIB0014 // ServicePointManager is obsolete in .NET 5+
linkLabel3.Text = AppSysConfig.getConfig("MainInfoBuyLinke");
string[] array = AppSysConfig.getConfig("TutorialLink").Split('|');
if (!string.IsNullOrEmpty(array[0]) && array.Length >= 2)
@@ -1582,8 +1585,10 @@ namespace AppleBatch_June
comLoadAccounts.MouseWheel += ComLoadAccounts_MouseWheel;
ThreadPool.SetMinThreads(Tools.getTaskSize(openVpn: true, 1000) * 2, 5);
Text = Text + " 当前版本:" + FormLogin.versions;
#pragma warning disable SYSLIB0014 // ServicePointManager is obsolete in .NET 5+
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = (object sender2, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) => true;
#pragma warning restore SYSLIB0014 // ServicePointManager is obsolete in .NET 5+
foreach (TabPage tabPage in tabControl1.TabPages)
{
if (tabPage.Text == "个人中心页面")

View File

@@ -1296,7 +1296,6 @@ namespace AppleBatch_June
if (paymentInfos != null && paymentInfos != null)
{
int? num = paymentInfos.data?.attributes?.paymentInfos.Count();
int num2 = 0;
if (num > 0 && paymentInfos != null)
{
PaymentList.Data data = paymentInfos.data;
@@ -1311,7 +1310,6 @@ namespace AppleBatch_June
obj = ((attributes != null) ? new int?(attributes.paymentInfos[0].validationErrors.Count()) : null);
}
num = obj;
num2 = 0;
if (num > 0)
{
string text = "";
@@ -2021,10 +2019,10 @@ namespace AppleBatch_June
public string CancelSubscription(string subscriptionId, AppleItunesLogin itunesLogin, bool isAgent = false)
{
string text = "失败:网络请求失败,无法请求完成";
int serverIndex = itunesLogin.serverIndex;
string ReueId = "";
string guidNow = "";
string text2 = "000000000";
int serverIndex = itunesLogin.serverIndex;
string kbsync = getKbsync(itunesLogin.dsis, ref serverIndex, ref ReueId, ref guidNow);
string postData = "cancelSubscription=true&creditDisplay=" + itunesLogin.Balance + "&guid=" + itunesLogin.Guid + "&hasConfirmedBuySubscription=true&kbsync=" + kbsync + "&machineName=" + itunesLogin.Guid + "&needDiv=1&salableAdamId=" + text2 + "&showIAPExtraDialog=false&showIAPSuccessDialog=false&subscriptionId=" + subscriptionId + "&supportsGpuContentProtection=true";
Dictionary<string, string> dictionary = new Dictionary<string, string>();

View File

@@ -17,7 +17,6 @@ namespace AppleBatch_June
public int Compare(object x, object y)
{
int num = -1;
string text = ((ListViewItem)x).SubItems[col].Text;
string text2 = ((ListViewItem)y).SubItems[col].Text;
if (int.TryParse(text, out var result) && int.TryParse(text2, out var result2))

View File

@@ -2,110 +2,61 @@ using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using AppleBatch_June.Domain;
namespace AppleBatch_June
{
internal static class Program
{
internal class ThreadExceptionHandler
{
public void Form1_UIThreadException(object sender, ThreadExceptionEventArgs t)
{
DialogResult dialogResult = DialogResult.Cancel;
try
{
dialogResult = ShowThreadExceptionDialog("Windows Forms UI错误", t.Exception);
}
catch
{
try
{
MessageBox.Show("严重的错误", "Windows Forms UI错误", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Hand);
}
finally
{
Application.Exit();
}
}
if (dialogResult == DialogResult.Abort)
{
Application.Exit();
}
}
public void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
DialogResult dialogResult = DialogResult.Cancel;
try
{
Exception e2 = (Exception)e.ExceptionObject;
dialogResult = ShowThreadExceptionDialog("非UI线程错误#1", e2);
}
catch (Exception ex)
{
try
{
MessageBox.Show("严重的非UI线程错误" + ex.Message, "非UI线程错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
finally
{
Application.Exit();
}
}
if (dialogResult == DialogResult.Abort)
{
Application.Exit();
}
}
private DialogResult ShowThreadExceptionDialog(string title, Exception e)
{
string text = "应用程序错误,请联系管理员,错误信息:\n\n";
text += e.Message;
if (e.Message.Contains("System.OutOfMemoryException") || e.Message.Contains("内存不足") || e.Message.Contains("没有足够的内存"))
{
text += "\n\n系统运行内存不足请增加系统的 虚拟内存 ";
}
APIUtlis.ApiSeriveError(e, title);
return MessageBox.Show(text, title, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Hand);
}
}
[STAThread]
private static void Main()
{
// 调试断点测试 - 在此处设置断点
Console.WriteLine("程序开始启动 - Debug Breakpoint Test");
try
{
Task.Run(delegate
{
new NationalData().getMation();
});
ThreadExceptionHandler @object = new ThreadExceptionHandler();
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.Automatic);
Application.ThreadException += @object.Form1_UIThreadException;
AppDomain.CurrentDomain.UnhandledException += @object.CurrentDomain_UnhandledException;
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
// 最小化启动过程避免CoreCLR初始化问题
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(defaultValue: false);
Application.SetCompatibleTextRenderingDefault(false);
Console.WriteLine("Windows Forms 样式已启用");
// 设置全局异常处理
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.Automatic);
Application.ThreadException += (sender, e) => {
MessageBox.Show($"UI错误: {e.Exception.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
};
AppDomain.CurrentDomain.UnhandledException += (sender, e) => {
MessageBox.Show($"未处理异常: {(e.ExceptionObject as Exception)?.Message}", "严重错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
};
Console.WriteLine("异常处理已设置");
// 尝试启动主窗体
try
{
Console.WriteLine("正在创建主窗体...");
Application.Run(new FormLogin());
}
catch (Exception ex)
{
APIUtlis.ApiSeriveError(ex);
Console.WriteLine($"窗体启动异常: {ex.Message}");
MessageBox.Show($"程序启动失败: {ex.Message}\n\n堆栈跟踪:\n{ex.StackTrace}", "启动错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private static void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
catch (Exception ex)
{
try
{
_ = "应用程序错误,请联系管理员,错误信息:\n\n" + e.Exception.Message;
APIUtlis.ApiSeriveError(e.Exception, "非UI线程错误#2");
e.SetObserved();
Console.WriteLine($"系统初始化异常: {ex.Message}");
MessageBox.Show($"系统初始化失败: {ex.Message}\n\n这是一个CoreCLR运行时错误可能的原因:\n" +
"1. .NET 8.0 运行时未正确安装\n" +
"2. 程序依赖项缺失\n" +
"3. 系统兼容性问题\n\n" +
"请确保已安装 .NET 8.0 Desktop Runtime。\n\n" +
"详细信息: {ex.StackTrace}", "CoreCLR 错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception)
finally
{
Console.WriteLine("程序执行完成");
}
}
}

View File

@@ -814,7 +814,6 @@ namespace AppleBatch_June
public static string EncodeBase64(byte[] source)
{
string _text = "";
try
{
return Convert.ToBase64String(source);

View File

@@ -83,6 +83,7 @@ namespace AppleBatch_June
public addMaterial()
{
components = new Container();
InitializeComponent();
}

View File

@@ -560,16 +560,30 @@ namespace DotNet.Utilities
{
if (!string.IsNullOrWhiteSpace(item.CerPath))
{
#pragma warning disable SYSLIB0014 // ServicePointManager is obsolete in .NET 5+
ServicePointManager.ServerCertificateValidationCallback = CheckValidationResult;
#pragma warning restore SYSLIB0014 // ServicePointManager is obsolete in .NET 5+
#pragma warning disable SYSLIB0014 // WebRequest is obsolete
request = (HttpWebRequest)WebRequest.Create(item.URL);
#pragma warning restore SYSLIB0014 // WebRequest is obsolete
SetCerList(item);
request.ClientCertificates.Add(new X509Certificate(item.CerPath));
return;
}
#pragma warning disable SYSLIB0014 // WebRequest is obsolete
request = (HttpWebRequest)WebRequest.Create(item.URL);
#pragma warning restore SYSLIB0014 // WebRequest is obsolete
if (item.KeepAlive)
{
request.Headers.GetType().InvokeMember("ChangeInternal", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, Type.DefaultBinder, request.Headers, new object[2] { "Connection", "keep-alive" });
// 在 .NET 8 中使用标准方式设置 Connection 头
try
{
request.Connection = "keep-alive";
}
catch
{
// 如果设置失败,忽略错误,继续执行
}
}
SetCerList(item);
}

View File

@@ -0,0 +1,11 @@
{
"profiles": {
"AppleBatch_June": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"nativeDebugging": false
}
}
}