private void DoInit(bool isWork, Action callback) { this.PackageDownloader = new PackageDownloader(this); this.AppSettingSet = new AppSettingSet(this); this.CalcConfigSet = new CalcConfigSet(this); ContextInit(isWork); if (!string.IsNullOrEmpty(CommandLineArgs.KernelBrand)) { if (SysDicItemSet.TryGetDicItem("KernelBrand", CommandLineArgs.KernelBrand, out ISysDicItem brandItem)) { #region KernelBrandId string brand = $"KernelBrandId{brandItem.GetId()}KernelBrandId"; byte[] data = Encoding.UTF8.GetBytes(brand); if (data.Length != KernelBrandRaw.Length) { throw new InvalidProgramException(); } byte[] source = File.ReadAllBytes(ClientId.AppFileFullName); int index = 0; for (int i = 0; i < source.Length - KernelBrandRaw.Length; i++) { int j = 0; for (; j < KernelBrandRaw.Length; j++) { if (source[i + j] != KernelBrandRaw[j]) { break; } } if (j == KernelBrandRaw.Length) { index = i; break; } } for (int i = index; i < index + data.Length; i++) { source[i] = data[i - index]; } string brandExeFullName = Path.Combine(Path.GetDirectoryName(ClientId.AppFileFullName), Path.GetFileNameWithoutExtension(ClientId.AppFileFullName) + $"_{CommandLineArgs.KernelBrand}.exe"); File.WriteAllBytes(brandExeFullName, source); #endregion Environment.Exit(0); return; } } this.UserSet = new UserSet(); this.KernelProfileSet = new KernelProfileSet(this); this.GpusSpeed = new GpusSpeed(this); this.CoinShareSet = new CoinShareSet(this); this.MineWorkSet = new MineWorkSet(this); this.MinerGroupSet = new MinerGroupSet(this); this.OverClockDataSet = new OverClockDataSet(this); this.ColumnsShowSet = new ColumnsShowSet(this); MineWorkData mineWorkData = null; if (isWork) { mineWorkData = LocalJson.MineWork; } this._minerProfile = new MinerProfile(this, mineWorkData); NTMinerRegistry.SetLocation(ClientId.AppFileFullName); NTMinerRegistry.SetArguments(string.Join(" ", CommandLineArgs.Args)); NTMinerRegistry.SetCurrentVersion(CurrentVersion.ToString()); NTMinerRegistry.SetCurrentVersionTag(CurrentVersionTag); callback?.Invoke(); }
private void DoInit(bool isWork, Action callback) { this.PackageDownloader = new PackageDownloader(this); this.AppSettingSet = new AppSettingSet(this); this.CalcConfigSet = new CalcConfigSet(this); ContextInit(isWork); // 打码支持内核品牌 if (!string.IsNullOrEmpty(CommandLineArgs.KernelBrand)) { if (SysDicItemSet.TryGetDicItem("KernelBrand", CommandLineArgs.KernelBrand, out ISysDicItem brandItem)) { #region KernelBrandId string brand = $"KernelBrandId{brandItem.GetId()}KernelBrandId"; byte[] data = Encoding.UTF8.GetBytes(brand); if (data.Length != KernelBrandRaw.Length) { throw new InvalidProgramException(); } byte[] source = File.ReadAllBytes(ClientId.AppFileFullName); int index = 0; for (int i = 0; i < source.Length - KernelBrandRaw.Length; i++) { int j = 0; for (; j < KernelBrandRaw.Length; j++) { if (source[i + j] != KernelBrandRaw[j]) { break; } } if (j == KernelBrandRaw.Length) { index = i; break; } } for (int i = index; i < index + data.Length; i++) { source[i] = data[i - index]; } string brandExeFullName = Path.Combine(Path.GetDirectoryName(ClientId.AppFileFullName), Path.GetFileNameWithoutExtension(ClientId.AppFileFullName) + $"_{CommandLineArgs.KernelBrand}.exe"); File.WriteAllBytes(brandExeFullName, source); #endregion Environment.Exit(0); return; } } this.UserSet = new UserSet(); this.KernelProfileSet = new KernelProfileSet(this); this.GpusSpeed = new GpusSpeed(this); this.CoinShareSet = new CoinShareSet(this); this.MineWorkSet = new MineWorkSet(this); this.MinerGroupSet = new MinerGroupSet(this); this.OverClockDataSet = new OverClockDataSet(this); this.ColumnsShowSet = new ColumnsShowSet(this); MineWorkData mineWorkData = null; if (isWork) { mineWorkData = LocalJson.MineWork; } this._minerProfile = new MinerProfile(this, mineWorkData); // 这几个注册表内部区分挖矿端和群控客户端 NTMinerRegistry.SetLocation(ClientId.AppFileFullName); NTMinerRegistry.SetArguments(string.Join(" ", CommandLineArgs.Args)); NTMinerRegistry.SetCurrentVersion(CurrentVersion.ToString()); NTMinerRegistry.SetCurrentVersionTag(CurrentVersionTag); #region 发生了用户活动时检查serverJson是否有新版本 VirtualRoot.On <UserActionEvent>("发生了用户活动时检查serverJson是否有新版本", LogEnum.DevConsole, action: message => { OfficialServer.GetJsonFileVersionAsync(AssemblyInfo.ServerJsonFileName, (jsonFileVersion) => { if (!string.IsNullOrEmpty(jsonFileVersion) && JsonFileVersion != jsonFileVersion) { SpecialPath.GetAliyunServerJson((data) => { Write.DevLine($"有新版本{JsonFileVersion}->{jsonFileVersion}"); string rawJson = Encoding.UTF8.GetString(data); SpecialPath.WriteServerJsonFile(rawJson); ReInitServerJson(); bool isUseJson = !DevMode.IsDebugMode || VirtualRoot.IsMinerStudio; if (isUseJson) { // 作业模式下界面是禁用的,所以这里的初始化isWork必然是false ContextReInit(isWork: false); Logger.InfoDebugLine("刷新完成"); } else { Write.DevLine("不是使用的json,无需刷新"); } JsonFileVersion = jsonFileVersion; }); } else { Write.DevLine("server.json没有新版本", ConsoleColor.Green); } }); }); #endregion callback?.Invoke(); }