This repository was archived by the owner on Feb 24, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
132 lines (128 loc) · 5.36 KB
/
Copy pathProgram.cs
File metadata and controls
132 lines (128 loc) · 5.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using System;
using System.IO;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace CoreDownloader
{
internal class Program
{
static void Main(string[] args)
{
string tempDirectory = Path.GetTempPath();
string customDirectory = Path.Combine(tempDirectory, "MCZLFAPP", "Temp");
Directory.CreateDirectory(customDirectory);
Directory.SetCurrentDirectory(customDirectory);
string fileName = "main.exe";
string fileMd5 = "886c8ef10288d546fe254b531870318d";
string fileMd532 = "e8f1007a43eb520eecf9c0fade0300b0";
bool needsDownload = false;
if (File.Exists(fileName))
{
string md5Hash = GetFileMD5Hash(fileName);
if (md5Hash == fileMd5)
{
Console.Write("64位核心已存在且安全校验通过\n");
MessageBox.Show("64位核心已存在且安全校验通过", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
needsDownload = false;
}
else
{
if (md5Hash == fileMd532)
{
Console.Write("32位核心已存在且安全校验通过\n");
MessageBox.Show("32位核心已存在且安全校验通过", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
needsDownload = false;
}
else
{
Console.Write("核心不存在或安全校验不通过,重新Download中\n");
needsDownload = true;
}
}
}
else
{
Console.Write("核心不存在或安全校验不通过,重新Download中\n");
needsDownload = true;
}
if (needsDownload)
{
Console.Write("当前下载器版本 0.0.1.024 MinecraftConnectToolP2PMode适用\n");
string url = GetDownloadUrl();
string tempPath = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), "MCZLFAPP", "Temp");
if (!Directory.Exists(tempPath)) Directory.CreateDirectory(tempPath);
string downloadFilePath = Path.Combine(tempPath, "main.exe");
using (WebClient webClient = new WebClient())
{
webClient.DownloadProgressChanged += DownloadProgressCallback;
webClient.DownloadFileAsync(new Uri(url), downloadFilePath);
ManualResetEvent downloadCompleted = new ManualResetEvent(false);
webClient.DownloadFileCompleted += (sender, e) =>
{
if (e.Error != null) Console.WriteLine("\n下载失败:" + e.Error.Message);
else Console.WriteLine("\ncomplete");
downloadCompleted.Set();
};
downloadCompleted.WaitOne();
}
}
}
static void DownloadProgressCallback(object sender, DownloadProgressChangedEventArgs e)
{
Console.Write("\r下载进度: {0}%", e.ProgressPercentage);
}
public static string GetFileMD5Hash(string filePath)
{
try
{
using (FileStream stream = File.OpenRead(filePath))
{
MD5 md5 = MD5.Create();
byte[] hashValue = md5.ComputeHash(stream);
StringBuilder hex = new StringBuilder(hashValue.Length * 2);
foreach (byte b in hashValue)
{
hex.AppendFormat("{0:x2}", b);
}
return hex.ToString();
}
}
catch (Exception ex)
{
throw new Exception("计算MD5时出现错误 " + filePath, ex);
}
}
static string GetDownloadUrl()
{
string official64 = "https://mczlf.loft.games/ConnectTool/main.exe";
string official32 = "https://mczlf.loft.games/ConnectTool/main32.exe";
string mirror64 = "https://pan.29o.cn/down.php/886c8ef10288d546fe254b531870318d.exe";
string mirror32 = "https://pan.29o.cn/down.php/e8f1007a43eb520eecf9c0fade0300b0.exe";
Console.WriteLine("\n请选择下载方式:");
Console.WriteLine("1. 官网下载(默认)");
Console.WriteLine("2. 镜像下载");
while (true)
{
Console.Write("请输入选项(1 或 2):");
string input = Console.ReadLine();
if (input == "1")
{
return Environment.Is64BitOperatingSystem ? official64 : official32;
}
else if (input == "2")
{
return Environment.Is64BitOperatingSystem ? mirror64 : mirror32;
}
else
{
Console.WriteLine("使用默认下载方式\n");
return Environment.Is64BitOperatingSystem ? official64 : official32;
}
}
//此后代码不会大改,功能正常就行了
}
}
}