diff --git a/AboutDialog/About1.xaml b/AboutDialog/About1.xaml index ed67961..5c53078 100644 --- a/AboutDialog/About1.xaml +++ b/AboutDialog/About1.xaml @@ -11,7 +11,7 @@ - + My GitHub diff --git a/App.xaml.cs b/App.xaml.cs index 3c27778..f15a2e9 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,5 +1,4 @@ -using Lierda.WPFHelper; -using System.Windows; +using System.Windows; using Zerolauncher.Manager; namespace Zerolauncher @@ -9,11 +8,8 @@ namespace Zerolauncher /// public partial class App : Application { - LierdaCracker cracker = new LierdaCracker(); - protected override void OnStartup(StartupEventArgs e) { - cracker.Cracker(100);//垃圾回收间隔时间 base.OnStartup(e); _ = UpDateManager.TakeQMessage(); DataStream.Load(); diff --git a/Manager/DownloadManager.cs b/Manager/DownloadManager.cs deleted file mode 100644 index b2ce01d..0000000 --- a/Manager/DownloadManager.cs +++ /dev/null @@ -1,374 +0,0 @@ -using System.Net; -using System.IO; - -namespace Zerolauncher.Manager -{ - - public class DownloadManager - { - /// - /// 主线程 - /// - private SynchronizationContext _mainThreadSynContext; - - /// - /// 下载网址 - /// - public string Url; - - public event Action OnError; - - private static object errorlock = new object(); - - /// - /// 主要用于关闭线程 - /// - private bool _isDownload = false; - public DownloadManager(string url) - { - // 主线程赋值 - _mainThreadSynContext = SynchronizationContext.Current; - // 突破Http协议的并发连接数限制 - ServicePointManager.DefaultConnectionLimit = 512; - - Url = url; - } - /// - /// 查询文件大小 - /// - /// - public long GetFileSize() - { - HttpWebRequest request; - HttpWebResponse response; - try - { - request = (HttpWebRequest)WebRequest.CreateHttp(new Uri(Url)); - request.Method = "HEAD"; - response = (HttpWebResponse)request.GetResponse(); - // 获得文件长度 - long contentLength = response.ContentLength; - - response.Close(); - request.Abort(); - - return contentLength; - } - catch (Exception ex) - { - onError(ex); - // throw; - return -1; - } - } - /// - /// 异步查询文件大小 - /// - /// - public void GetFileSizeAsyn(Action onTrigger = null) - { - ThreadStart threadStart = new ThreadStart(() => - { - PostMainThreadAction(onTrigger, GetFileSize()); - }); - Thread thread = new Thread(threadStart); - thread.Start(); - } - /// - /// 多线程下载文件至本地 - /// - /// 线程总数 - /// 保存文件路径 - /// 下载过程回调(已下载文件大小、总文件大小) - /// 下载完毕回调(下载文件数据) - public void DownloadToFile(int threadCount, string filePath, Action onDownloading = null, Action onTrigger = null) - { - _isDownload = true; - - long csize = 0; //已下载大小 - int ocnt = 0; //完成线程数 - - - // 下载逻辑 - GetFileSizeAsyn((size) => - { - if (size == -1) return; - // 准备工作 - var tempFilePaths = new string[threadCount]; - var tempFileFileStreams = new FileStream[threadCount]; - var dirPath = Path.GetDirectoryName(filePath); - var fileName = Path.GetFileName(filePath); - // 下载根目录不存在则创建 - if (!Directory.Exists(dirPath)) - { - Directory.CreateDirectory(dirPath); - } - // 查看下载临时文件是否可以继续断点续传 - var fileInfos = new DirectoryInfo(dirPath).GetFiles(fileName + "*.temp"); - if (fileInfos.Length != threadCount) - { - // 下载临时文件数量不相同,则清理 - foreach (var info in fileInfos) - { - info.Delete(); - } - } - // 创建下载临时文件,并创建文件流 - for (int i = 0; i < threadCount; i++) - { - tempFilePaths[i] = filePath + i + ".temp"; - if (!File.Exists(tempFilePaths[i])) - { - File.Create(tempFilePaths[i]).Dispose(); - } - tempFileFileStreams[i] = File.OpenWrite(tempFilePaths[i]); - tempFileFileStreams[i].Seek(tempFileFileStreams[i].Length, System.IO.SeekOrigin.Current); - - csize += tempFileFileStreams[i].Length; - } - // 单线程下载过程回调函数 - Action t_onDownloading = (index, rsize, rbytes, data) => - { - csize += rsize; - tempFileFileStreams[index].Write(rbytes, 0, (int)rsize); - PostMainThreadAction(onDownloading, csize, size); - }; - // 单线程下载完毕回调函数 - Action t_onTrigger = (index, data) => - { - // 关闭文件流 - tempFileFileStreams[index].Close(); - ocnt++; - if (ocnt >= threadCount) - { - // 将临时文件转为下载文件 - if (!File.Exists(filePath)) - { - File.Create(filePath).Dispose(); - } - else - { - File.WriteAllBytes(filePath, new byte[] { }); - } - FileStream fs = File.OpenWrite(filePath); - fs.Seek(fs.Length, System.IO.SeekOrigin.Current); - foreach (var tempPath in tempFilePaths) - { - var tempData = File.ReadAllBytes(tempPath); - fs.Write(tempData, 0, tempData.Length); - File.Delete(tempPath); - } - fs.Close(); - PostMainThreadAction(onTrigger, File.ReadAllBytes(filePath)); - } - }; - // 分割文件尺寸,多线程下载 - long[] sizes = SplitFileSize(size, threadCount); - for (int i = 0; i < sizes.Length; i = i + 2) - { - long from = sizes[i]; - long to = sizes[i + 1]; - - // 断点续传 - from += tempFileFileStreams[i / 2].Length; - if (from >= to) - { - t_onTrigger(i / 2, null); - continue; - } - - _threadDownload(i / 2, from, to, t_onDownloading, t_onTrigger); - } - }); - } - /// - /// 多线程下载文件至内存 - /// - /// 线程总数 - /// 下载过程回调(已下载文件大小、总文件大小) - /// 下载完毕回调(下载文件数据) - public void DownloadToMemory(int threadCount, Action onDownloading = null, Action onTrigger = null) - { - _isDownload = true; - - long csize = 0; // 已下载大小 - int ocnt = 0; // 完成线程数 - byte[] cdata; // 已下载数据 - // 下载逻辑 - GetFileSizeAsyn((size) => - { - cdata = new byte[size]; - // 单线程下载过程回调函数 - Action t_onDownloading = (index, rsize, rbytes, data) => - { - csize += rsize; - PostMainThreadAction(onDownloading, csize, size); - }; - // 单线程下载完毕回调函数 - Action t_onTrigger = (index, data) => - { - long dIndex = (long)Math.Ceiling((double)(size * index / threadCount)); - Array.Copy(data, 0, cdata, dIndex, data.Length); - - ocnt++; - if (ocnt >= threadCount) - { - PostMainThreadAction(onTrigger, cdata); - } - }; - // 分割文件尺寸,多线程下载 - long[] sizes = SplitFileSize(size, threadCount); - for (int i = 0; i < sizes.Length; i = i + 2) - { - long from = sizes[i]; - long to = sizes[i + 1]; - _threadDownload(i / 2, from, to, t_onDownloading, t_onTrigger); - } - }); - } - /// - /// 单线程下载 - /// - /// 线程ID - /// 下载起始位置 - /// 下载结束位置 - /// 下载过程回调(线程ID、单次下载数据大小、单次下载数据缓存区、已下载文件数据) - /// 下载完毕回调(线程ID、下载文件数据) - private void _threadDownload(int index, long from, long to, Action onDownloading = null, Action onTrigger = null) - { - Thread thread = new Thread(new ThreadStart(() => - { - try - { - var request = (HttpWebRequest)WebRequest.Create(new Uri(Url)); - request.AddRange(from, to); - - HttpWebResponse response = (HttpWebResponse)request.GetResponse(); - Stream ns = response.GetResponseStream(); - - byte[] rbytes = new byte[8 * 1024]; - int rSize = 0; - MemoryStream ms = new MemoryStream(); - while (true) - { - if (!_isDownload) return; - rSize = ns.Read(rbytes, 0, rbytes.Length); - if (rSize <= 0) break; - ms.Write(rbytes, 0, rSize); - if (onDownloading != null) onDownloading(index, rSize, rbytes, ms.ToArray()); - } - - ns.Close(); - response.Close(); - request.Abort(); - - if (ms.Length == (to - from) + 1) - { - if (onTrigger != null) onTrigger(index, ms.ToArray()); - } - else - { - lock (errorlock) - { - if (_isDownload) - { - onError(new Exception("文件大小校验不通过")); - } - } - } - - } - catch (Exception ex) - { - onError(ex); - } - - - })); - thread.Start(); - } - - public void Close() - { - _isDownload = false; - } - - /// - /// 分割文件大小 - /// - /// - private long[] SplitFileSize(long size, int count) - { - long[] result = new long[count * 2]; - for (int i = 0; i < count; i++) - { - long from = (long)Math.Ceiling((double)(size * i / count)); - long to = (long)Math.Ceiling((double)(size * (i + 1) / count)) - 1; - result[i * 2] = from; - result[i * 2 + 1] = to; - } - - return result; - } - - private void onError(Exception ex) - { - Close(); - PostMainThreadAction(OnError, ex); - } - - /// - /// 通知主线程回调 - /// - private void PostMainThreadAction(Action action) - { - _mainThreadSynContext.Post(new SendOrPostCallback((o) => - { - Action e = (Action)o.GetType().GetProperty("action").GetValue(o); - if (e != null) e(); - }), new { action = action }); - } - private void PostMainThreadAction(Action action, T arg1) - { - _mainThreadSynContext.Post(new SendOrPostCallback((o) => - { - Action e = (Action)o.GetType().GetProperty("action").GetValue(o); - T t1 = (T)o.GetType().GetProperty("arg1").GetValue(o); - if (e != null) e(t1); - }), new { action = action, arg1 = arg1 }); - } - public void PostMainThreadAction(Action action, T1 arg1, T2 arg2) - { - _mainThreadSynContext.Post(new SendOrPostCallback((o) => - { - Action e = (Action)o.GetType().GetProperty("action").GetValue(o); - T1 t1 = (T1)o.GetType().GetProperty("arg1").GetValue(o); - T2 t2 = (T2)o.GetType().GetProperty("arg2").GetValue(o); - if (e != null) e(t1, t2); - }), new { action = action, arg1 = arg1, arg2 = arg2 }); - } - public void PostMainThreadAction(Action action, T1 arg1, T2 arg2, T3 arg3) - { - _mainThreadSynContext.Post(new SendOrPostCallback((o) => - { - Action e = (Action)o.GetType().GetProperty("action").GetValue(o); - T1 t1 = (T1)o.GetType().GetProperty("arg1").GetValue(o); - T2 t2 = (T2)o.GetType().GetProperty("arg2").GetValue(o); - T3 t3 = (T3)o.GetType().GetProperty("arg3").GetValue(o); - if (e != null) e(t1, t2, t3); - }), new { action = action, arg1 = arg1, arg2 = arg2, arg3 = arg3 }); - } - public void PostMainThreadAction(Action action, T1 arg1, T2 arg2, T3 arg3, T4 arg4) - { - _mainThreadSynContext.Post(new SendOrPostCallback((o) => - { - Action e = (Action)o.GetType().GetProperty("action").GetValue(o); - T1 t1 = (T1)o.GetType().GetProperty("arg1").GetValue(o); - T2 t2 = (T2)o.GetType().GetProperty("arg2").GetValue(o); - T3 t3 = (T3)o.GetType().GetProperty("arg3").GetValue(o); - T4 t4 = (T4)o.GetType().GetProperty("arg4").GetValue(o); - if (e != null) e(t1, t2, t3, t4); - }), new { action = action, arg1 = arg1, arg2 = arg2, arg3 = arg3, arg4 = arg4 }); - } - } -} diff --git a/Manager/EngineManager.cs b/Manager/EngineManager.cs index 8d3a909..7c6de48 100644 --- a/Manager/EngineManager.cs +++ b/Manager/EngineManager.cs @@ -49,11 +49,7 @@ namespace Zerolauncher.Manager public static bool CreateGame(int memberId) { - var account = AccountManager.accountsList[memberId]; - var key = AccToKey(account); - if (mGame.ContainsKey(key)) { return false; } - mGame[key] = new SingleGame(account); - return true; + return CreateGame(AccountManager.accountsList[memberId]); } public static int CheckGameState(Account account) @@ -210,7 +206,7 @@ namespace Zerolauncher.Manager const string engine_file = @"ZeroEngine.exe"; public static Process CheckEngineSafe() { - if (is_check && EngineManager.CheckEmpy()) + if (!is_check && EngineManager.CheckEmpy()) { string? now_bit; using (SHA256 sha256 = SHA256.Create()) diff --git a/Manager/HashHelper.cs b/Manager/HashHelper.cs deleted file mode 100644 index 717c39e..0000000 --- a/Manager/HashHelper.cs +++ /dev/null @@ -1,201 +0,0 @@ -using System.Text; - -namespace Zerolauncher.Manager -{ - /// - /// 提供用于计算指定文件哈希值的方法 - /// 例如计算文件的MD5值: - /// - /// String hashMd5=HashHelper.ComputeMD5("MyFile.txt"); - /// - /// - /// 例如计算文件的CRC32值: - /// - /// String hashCrc32 = HashHelper.ComputeCRC32("MyFile.txt"); - /// - /// - /// 例如计算文件的SHA1值: - /// - /// String hashSha1 =HashHelper.ComputeSHA1("MyFile.txt"); - /// - /// - /// - public sealed class HashHelper - { - /// - /// 计算指定文件的MD5值 - /// - /// 指定文件的完全限定名称 - /// 返回值的字符串形式 - public static String ComputeMD5(String fileName) - { - String hashMD5 = String.Empty; - //检查文件是否存在,如果文件存在则进行计算,否则返回空值 - if (System.IO.File.Exists(fileName)) - { - using (System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read)) - { - //计算文件的MD5值 - System.Security.Cryptography.MD5 calculator = System.Security.Cryptography.MD5.Create(); - Byte[] buffer = calculator.ComputeHash(fs); - calculator.Clear(); - //将字节数组转换成十六进制的字符串形式 - StringBuilder stringBuilder = new StringBuilder(); - for (int i = 0; i < buffer.Length; i++) - { - stringBuilder.Append(buffer[i].ToString("x2")); - } - hashMD5 = stringBuilder.ToString(); - }//关闭文件流 - }//结束计算 - return hashMD5; - }//ComputeMD5 - /// - /// 计算指定文件的CRC32值 - /// - /// 指定文件的完全限定名称 - /// 返回值的字符串形式 - public static String ComputeCRC32(String fileName) - { - String hashCRC32 = String.Empty; - //检查文件是否存在,如果文件存在则进行计算,否则返回空值 - if (System.IO.File.Exists(fileName)) - { - using (System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read)) - { - //计算文件的CSC32值 - Crc32 calculator = new Crc32(); - Byte[] buffer = calculator.ComputeHash(fs); - calculator.Clear(); - //将字节数组转换成十六进制的字符串形式 - StringBuilder stringBuilder = new StringBuilder(); - for (int i = 0; i < buffer.Length; i++) - { - stringBuilder.Append(buffer[i].ToString("x2")); - } - hashCRC32 = stringBuilder.ToString(); - }//关闭文件流 - } - return hashCRC32; - }//ComputeCRC32 - /// - /// 计算指定文件的SHA1值 - /// - /// 指定文件的完全限定名称 - /// 返回值的字符串形式 - public static String ComputeSHA1(String fileName) - { - String hashSHA1 = String.Empty; - //检查文件是否存在,如果文件存在则进行计算,否则返回空值 - if (System.IO.File.Exists(fileName)) - { - using (System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read)) - { - //计算文件的SHA1值 - System.Security.Cryptography.SHA1 calculator = System.Security.Cryptography.SHA1.Create(); - Byte[] buffer = calculator.ComputeHash(fs); - calculator.Clear(); - //将字节数组转换成十六进制的字符串形式 - StringBuilder stringBuilder = new StringBuilder(); - for (int i = 0; i < buffer.Length; i++) - { - stringBuilder.Append(buffer[i].ToString("x2")); - } - hashSHA1 = stringBuilder.ToString(); - }//关闭文件流 - } - return hashSHA1; - }//ComputeSHA1 - }//end class: HashHelper - /// - /// 提供 CRC32 算法的实现 - /// - public class Crc32 : System.Security.Cryptography.HashAlgorithm - { - public const UInt32 DefaultPolynomial = 0xedb88320; - public const UInt32 DefaultSeed = 0xffffffff; - private UInt32 hash; - private UInt32 seed; - private UInt32[] table; - private static UInt32[] defaultTable; - public Crc32() - { - table = InitializeTable(DefaultPolynomial); - seed = DefaultSeed; - Initialize(); - } - public Crc32(UInt32 polynomial, UInt32 seed) - { - table = InitializeTable(polynomial); - this.seed = seed; - Initialize(); - } - public override void Initialize() - { - hash = seed; - } - protected override void HashCore(byte[] buffer, int start, int length) - { - hash = CalculateHash(table, hash, buffer, start, length); - } - protected override byte[] HashFinal() - { - byte[] hashBuffer = UInt32ToBigEndianBytes(~hash); - this.HashValue = hashBuffer; - return hashBuffer; - } - public static UInt32 Compute(byte[] buffer) - { - return ~CalculateHash(InitializeTable(DefaultPolynomial), DefaultSeed, buffer, 0, buffer.Length); - } - public static UInt32 Compute(UInt32 seed, byte[] buffer) - { - return ~CalculateHash(InitializeTable(DefaultPolynomial), seed, buffer, 0, buffer.Length); - } - public static UInt32 Compute(UInt32 polynomial, UInt32 seed, byte[] buffer) - { - return ~CalculateHash(InitializeTable(polynomial), seed, buffer, 0, buffer.Length); - } - private static UInt32[] InitializeTable(UInt32 polynomial) - { - if (polynomial == DefaultPolynomial && defaultTable != null) - { - return defaultTable; - } - UInt32[] createTable = new UInt32[256]; - for (int i = 0; i < 256; i++) - { - UInt32 entry = (UInt32)i; - for (int j = 0; j < 8; j++) - { - if ((entry & 1) == 1) - entry = (entry >> 1) ^ polynomial; - else - entry = entry >> 1; - } - createTable[i] = entry; - } - if (polynomial == DefaultPolynomial) - { - defaultTable = createTable; - } - return createTable; - } - private static UInt32 CalculateHash(UInt32[] table, UInt32 seed, byte[] buffer, int start, int size) - { - UInt32 crc = seed; - for (int i = start; i < size; i++) - { - unchecked - { - crc = (crc >> 8) ^ table[buffer[i] ^ crc & 0xff]; - } - } - return crc; - } - private byte[] UInt32ToBigEndianBytes(UInt32 x) - { - return new byte[] { (byte)((x >> 24) & 0xff), (byte)((x >> 16) & 0xff), (byte)((x >> 8) & 0xff), (byte)(x & 0xff) }; - } - }//end class: Crc32 -} diff --git a/Manager/UpDateManager.cs b/Manager/UpDateManager.cs index d76cad0..34f2018 100644 --- a/Manager/UpDateManager.cs +++ b/Manager/UpDateManager.cs @@ -19,7 +19,7 @@ namespace Zerolauncher.Manager try { client.Timeout = TimeSpan.FromMinutes(3); - response = await client.GetAsync($"https://sharechain.qq.com/13111bbd6ffbffa3057878431bef103e"); + response = await client.GetAsync("https://sharechain.qq.com/037846c482eddc948612b0d0f8ed98d5"); // 初夏 }catch (Exception _ex) { EngineCacheSha.errorCode = 1; diff --git a/Manager/VersionManager.cs b/Manager/VersionManager.cs deleted file mode 100644 index cfe7e64..0000000 --- a/Manager/VersionManager.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Zerolauncher.Manager -{ - class VersionManager - { - public static int GetMainVer() { return 10001; } - - } -} diff --git a/Zerolauncher.csproj b/Zerolauncher.csproj index ef6538f..4323124 100644 --- a/Zerolauncher.csproj +++ b/Zerolauncher.csproj @@ -37,7 +37,6 @@ -