Пример #1
0
        public void Init(Action callback)
        {
            Task.Factory.StartNew(() => {
                OfficialServer.GetJsonFileVersionAsync(AssemblyInfo.ServerJsonFileName, (jsonFileVersion) => {
                    if (!string.IsNullOrEmpty(jsonFileVersion))
                    {
                        JsonFileVersion = jsonFileVersion;
                    }
                });
                GpuProfileSet.Instance.Register(this);
                bool isWork = Environment.GetCommandLineArgs().Contains("--work", StringComparer.OrdinalIgnoreCase);
                if (DevMode.IsDebugMode && !VirtualRoot.IsMinerStudio && !isWork)
                {
                    DoInit(isWork: false, callback: callback);
                    return;
                }

                string langJson  = ClientId.ReadLocalLangJsonFile();
                int initialCount = 2;
                if (isWork)
                {
                    initialCount = 1;
                }
                CountdownEvent countdown = new CountdownEvent(initialCount);
                if (!isWork)
                {
                    SpecialPath.GetAliyunServerJson((data) => {
                        // 如果server.json未下载成功则不覆写本地server.json
                        if (data != null && data.Length != 0)
                        {
                            var serverJson = Encoding.UTF8.GetString(data);
                            if (!string.IsNullOrEmpty(serverJson))
                            {
                                SpecialPath.WriteServerJsonFile(serverJson);
                            }
                        }
                        countdown.Signal();
                    });
                }
                SpecialPath.GetAliyunLangJson((data) => {
                    langJson = Encoding.UTF8.GetString(data);
                    countdown.Signal();
                });
                Task.Factory.StartNew(() => {
                    if (countdown.Wait(30 * 1000))
                    {
                        Logger.InfoDebugLine("json下载完成");
                        Language.Impl.LangJson.Instance.Init(langJson);
                        DoInit(isWork, callback);
                    }
                    else
                    {
                        Logger.InfoDebugLine("启动json下载超时");
                        Language.Impl.LangJson.Instance.Init(langJson);
                        DoInit(isWork, callback);
                    }
                });
            });
        }
Пример #2
0
 public void Init(Action callback)
 {
     Task.Factory.StartNew(() => {
         bool isWork = Environment.GetCommandLineArgs().Contains("--work", StringComparer.OrdinalIgnoreCase);
         if (isWork)   // 是作业
         {
             DoInit(isWork, callback);
             if (VirtualRoot.IsMinerClient)
             {
                 NTMinerRegistry.SetIsLastIsWork(true);
             }
         }
         else   // 不是作业
         {
             if (VirtualRoot.IsMinerClient)
             {
                 NTMinerRegistry.SetIsLastIsWork(false);
             }
             // 如果是Debug模式且不是群控客户端则使用本地数据库初始化
             bool useLocalDb = DevMode.IsDebugMode && !VirtualRoot.IsMinerStudio;
             if (useLocalDb)
             {
                 DoInit(isWork: false, callback: callback);
             }
             else
             {
                 Logger.InfoDebugLine("开始下载server.json");
                 GetAliyunServerJson((data) => {
                     // 如果server.json未下载成功则不覆写本地server.json
                     if (data != null && data.Length != 0)
                     {
                         Logger.InfoDebugLine("GetAliyunServerJson下载成功");
                         var serverJson = Encoding.UTF8.GetString(data);
                         if (!string.IsNullOrEmpty(serverJson))
                         {
                             SpecialPath.WriteServerJsonFile(serverJson);
                         }
                         OfficialServer.GetJsonFileVersionAsync(AssemblyInfo.ServerJsonFileName, (serverJsonFileVersion, minerClientVersion) => {
                             SetServerJsonVersion(serverJsonFileVersion);
                             AppVersionChangedEvent.PublishIfNewVersion(minerClientVersion);
                         });
                     }
                     else
                     {
                         Logger.InfoDebugLine("GetAliyunServerJson下载失败");
                     }
                     DoInit(isWork, callback);
                 });
                 #region 发生了用户活动时检查serverJson是否有新版本
                 VirtualRoot.On <UserActionEvent>("发生了用户活动时检查serverJson是否有新版本", LogEnum.DevConsole,
                                                  action: message => {
                     RefreshServerJsonFile();
                 });
                 #endregion
             }
         }
     });
 }
Пример #3
0
 private void RefreshServerJsonFile()
 {
     OfficialServer.GetJsonFileVersionAsync(MainAssemblyInfo.ServerJsonFileName, serverState => {
         AppVersionChangedEvent.PublishIfNewVersion(serverState.MinerClientVersion);
         string localServerJsonFileVersion = GetServerJsonVersion();
         if (!string.IsNullOrEmpty(serverState.JsonFileVersion) && localServerJsonFileVersion != serverState.JsonFileVersion)
         {
             GetAliyunServerJson((data) => {
                 string rawJson = Encoding.UTF8.GetString(data);
                 SpecialPath.WriteServerJsonFile(rawJson);
                 SetServerJsonVersion(serverState.JsonFileVersion);
                 ReInitServerJson();
                 // 作业模式下界面是禁用的,所以这里的初始化isWork必然是false
                 ContextReInit(isWork: VirtualRoot.IsMinerStudio);
                 VirtualRoot.ThisLocalInfo(nameof(NTMinerRoot), $"刷新server.json配置", toConsole: true);
             });
         }
         else
         {
             Write.DevDebug("server.json没有新版本");
         }
     });
 }
Пример #4
0
 private void RefreshServerJsonFile()
 {
     OfficialServer.GetJsonFileVersionAsync(AssemblyInfo.ServerJsonFileName, (serverJsonFileVersion, minerClientVersion) => {
         AppVersionChangedEvent.PublishIfNewVersion(minerClientVersion);
         string localServerJsonFileVersion = GetServerJsonVersion();
         if (!string.IsNullOrEmpty(serverJsonFileVersion) && localServerJsonFileVersion != serverJsonFileVersion)
         {
             GetAliyunServerJson((data) => {
                 Write.UserInfo($"更新配置{localServerJsonFileVersion}->{serverJsonFileVersion}");
                 string rawJson = Encoding.UTF8.GetString(data);
                 SpecialPath.WriteServerJsonFile(rawJson);
                 SetServerJsonVersion(serverJsonFileVersion);
                 ReInitServerJson();
                 // 作业模式下界面是禁用的,所以这里的初始化isWork必然是false
                 ContextReInit(isWork: VirtualRoot.IsMinerStudio);
                 Write.UserInfo("更新成功");
             });
         }
         else
         {
             Write.DevDebug("server.json没有新版本");
         }
     });
 }
Пример #5
0
 public void Init(Action callback)
 {
     Task.Factory.StartNew(() => {
         bool isWork = Environment.GetCommandLineArgs().Contains("--work", StringComparer.OrdinalIgnoreCase);
         if (isWork)   // 是作业
         {
             DoInit(isWork, callback);
             if (VirtualRoot.IsMinerClient)
             {
                 NTMinerRegistry.SetIsLastIsWork(true);
             }
         }
         else   // 不是作业
         {
             if (VirtualRoot.IsMinerClient)
             {
                 NTMinerRegistry.SetIsLastIsWork(false);
             }
             // 如果是Debug模式且不是群控客户端则使用本地数据库初始化
             bool useLocalDb = DevMode.IsDebugMode && !VirtualRoot.IsMinerStudio;
             if (useLocalDb)
             {
                 DoInit(isWork: false, callback: callback);
             }
             else
             {
                 Logger.InfoDebugLine(nameof(GetAliyunServerJson));
                 GetAliyunServerJson((data) => {
                     // 如果server.json未下载成功则不覆写本地server.json
                     if (data != null && data.Length != 0)
                     {
                         Logger.InfoDebugLine($"{nameof(GetAliyunServerJson)}成功");
                         var serverJson = Encoding.UTF8.GetString(data);
                         if (!string.IsNullOrEmpty(serverJson))
                         {
                             SpecialPath.WriteServerJsonFile(serverJson);
                         }
                         OfficialServer.GetJsonFileVersionAsync(MainAssemblyInfo.ServerJsonFileName, serverState => {
                             SetServerJsonVersion(serverState.JsonFileVersion);
                             AppVersionChangedEvent.PublishIfNewVersion(serverState.MinerClientVersion);
                             if (Math.Abs((long)Timestamp.GetTimestamp() - (long)serverState.Time) < Timestamp.DesyncSeconds)
                             {
                                 Logger.OkDebugLine($"本机和服务器时间一致或相差不超过 {Timestamp.DesyncSeconds.ToString()} 秒");
                             }
                             else
                             {
                                 Write.UserWarn($"本机和服务器时间不同步,请调整,本地:{DateTime.Now.ToString()},服务器:{Timestamp.FromTimestamp(serverState.Time).ToString()}。此问题不影响挖矿。");
                             }
                         });
                     }
                     else
                     {
                         if (!File.Exists(SpecialPath.ServerJsonFileFullName))
                         {
                             VirtualRoot.ThisLocalError(nameof(NTMinerRoot), "配置文件下载失败,这是第一次运行开源矿工,配置文件至少需要成功下载一次,请检查网络是否可用", OutEnum.Warn);
                         }
                         else
                         {
                             VirtualRoot.ThisLocalWarn(nameof(NTMinerRoot), "配置文件下载失败,使用最近一次成功下载的配置文件", OutEnum.Warn);
                         }
                     }
                     DoInit(isWork, callback);
                 });
                 #region 发生了用户活动时检查serverJson是否有新版本
                 VirtualRoot.BuildEventPath <UserActionEvent>("发生了用户活动时检查serverJson是否有新版本", LogEnum.DevConsole,
                                                              action: message => {
                     RefreshServerJsonFile();
                 });
                 #endregion
             }
         }
         VirtualRoot.ThisLocalInfo(nameof(NTMinerRoot), $"启动{VirtualRoot.AppName}");
     });
 }
Пример #6
0
 public void Init(Action callback)
 {
     Task.Factory.StartNew(() => {
         bool isWork = Environment.GetCommandLineArgs().Contains("--work", StringComparer.OrdinalIgnoreCase);
         if (isWork)
         {
             DoInit(isWork, callback);
             if (IsMinerClient)
             {
                 NTMinerRegistry.SetIsLastIsWork(true);
             }
             return;
         }
         else
         {
             if (IsMinerClient)
             {
                 NTMinerRegistry.SetIsLastIsWork(false);
             }
         }
         // 如果是Debug模式且不是群控客户端且不是作业则使用本地数据库初始化
         if (DevMode.IsDebugMode && !VirtualRoot.IsMinerStudio)
         {
             DoInit(isWork: false, callback: callback);
             return;
         }
         Logger.InfoDebugLine("开始下载server.json");
         SpecialPath.GetAliyunServerJson((data) => {
             // 如果server.json未下载成功则不覆写本地server.json
             if (data != null && data.Length != 0)
             {
                 Logger.InfoDebugLine("GetAliyunServerJson下载成功");
                 var serverJson = Encoding.UTF8.GetString(data);
                 if (!string.IsNullOrEmpty(serverJson))
                 {
                     SpecialPath.WriteServerJsonFile(serverJson);
                 }
                 OfficialServer.GetJsonFileVersionAsync(AssemblyInfo.ServerJsonFileName, (serverJsonFileVersion, minerClientVersion) => {
                     SetServerJsonVersion(serverJsonFileVersion);
                     AppVersionChangedEvent.PublishIfNewVersion(minerClientVersion);
                 });
             }
             else
             {
                 Logger.InfoDebugLine("GetAliyunServerJson下载失败");
             }
             DoInit(isWork, callback);
         });
         #region 发生了用户活动时检查serverJson是否有新版本
         VirtualRoot.On <UserActionEvent>("发生了用户活动时检查serverJson是否有新版本", LogEnum.DevConsole,
                                          action: message => {
             OfficialServer.GetJsonFileVersionAsync(AssemblyInfo.ServerJsonFileName, (serverJsonFileVersion, minerClientVersion) => {
                 AppVersionChangedEvent.PublishIfNewVersion(minerClientVersion);
                 string localServerJsonFileVersion = GetServerJsonVersion();
                 if (!string.IsNullOrEmpty(serverJsonFileVersion) && localServerJsonFileVersion != serverJsonFileVersion)
                 {
                     SpecialPath.GetAliyunServerJson((data) => {
                         Write.UserInfo($"server.json配置文件有新版本{localServerJsonFileVersion}->{serverJsonFileVersion}");
                         string rawJson = Encoding.UTF8.GetString(data);
                         SpecialPath.WriteServerJsonFile(rawJson);
                         SetServerJsonVersion(serverJsonFileVersion);
                         ReInitServerJson();
                         bool isUseJson = !DevMode.IsDebugMode || VirtualRoot.IsMinerStudio;
                         if (isUseJson)
                         {
                             // 作业模式下界面是禁用的,所以这里的初始化isWork必然是false
                             ContextReInit(isWork: VirtualRoot.IsMinerStudio);
                             Write.UserInfo("刷新完成");
                         }
                         else
                         {
                             Write.UserInfo("不是使用的server.json,无需刷新");
                         }
                     });
                 }
                 else
                 {
                     Write.DevDebug("server.json没有新版本");
                 }
             });
         });
         #endregion
     });
     // 因为这个操作大概需要200毫秒
     Task.Factory.StartNew(() => {
         NVIDIAGpuSet.NvmlInit();
     });
 }
Пример #7
0
        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();
        }