AppStatic.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  1. using NTMiner.Core;
  2. using NTMiner.MinerClient;
  3. using NTMiner.MinerServer;
  4. using NTMiner.Vms;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Reflection;
  11. using System.Windows;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. namespace NTMiner {
  16. // 注意:这里的成员只应用于绑定,不应在.cs中使用,在IDE中看到的静态源代码应用计数应为0
  17. public static class AppStatic {
  18. public static readonly BitmapImage BigLogoImageSource = new BitmapImage(new Uri((VirtualRoot.IsMinerStudio ? "/NTMinerWpf;component/Styles/Images/cc128.png" : "/NTMinerWpf;component/Styles/Images/logo128.png"), UriKind.RelativeOrAbsolute));
  19. private static string GetUpdaterVersion() {
  20. string updaterVersion = string.Empty;
  21. if (VirtualRoot.LocalAppSettingSet.TryGetAppSetting(NTKeyword.UpdaterVersionAppSettingKey, out IAppSetting setting) && setting.Value != null) {
  22. updaterVersion = setting.Value.ToString();
  23. }
  24. return updaterVersion;
  25. }
  26. private static void SetUpdaterVersion(string value) {
  27. VirtualRoot.Execute(new SetLocalAppSettingCommand(new AppSettingData {
  28. Key = NTKeyword.UpdaterVersionAppSettingKey,
  29. Value = value
  30. }));
  31. }
  32. #region Upgrade
  33. public static void Upgrade(string fileName, Action callback) {
  34. try {
  35. OfficialServer.FileUrlService.GetNTMinerUpdaterUrlAsync((downloadFileUrl, e) => {
  36. try {
  37. string argument = string.Empty;
  38. if (!string.IsNullOrEmpty(fileName)) {
  39. argument = "ntminerFileName=" + fileName;
  40. }
  41. if (VirtualRoot.IsMinerStudio) {
  42. argument += " --minerstudio";
  43. }
  44. if (string.IsNullOrEmpty(downloadFileUrl)) {
  45. if (File.Exists(SpecialPath.UpdaterFileFullName)) {
  46. Windows.Cmd.RunClose(SpecialPath.UpdaterFileFullName, argument);
  47. }
  48. callback?.Invoke();
  49. return;
  50. }
  51. Uri uri = new Uri(downloadFileUrl);
  52. string updaterVersion = GetUpdaterVersion();
  53. if (string.IsNullOrEmpty(updaterVersion) || !File.Exists(SpecialPath.UpdaterFileFullName) || uri.AbsolutePath != updaterVersion) {
  54. VirtualRoot.Execute(new ShowFileDownloaderCommand(downloadFileUrl, "开源矿工更新器", (window, isSuccess, message, saveFileFullName) => {
  55. try {
  56. if (isSuccess) {
  57. File.Copy(saveFileFullName, SpecialPath.UpdaterFileFullName, overwrite: true);
  58. File.Delete(saveFileFullName);
  59. SetUpdaterVersion(uri.AbsolutePath);
  60. window?.Close();
  61. Windows.Cmd.RunClose(SpecialPath.UpdaterFileFullName, argument);
  62. callback?.Invoke();
  63. }
  64. else {
  65. VirtualRoot.ThisLocalError(nameof(AppStatic), message, toConsole: true);
  66. callback?.Invoke();
  67. }
  68. }
  69. catch {
  70. callback?.Invoke();
  71. }
  72. }));
  73. }
  74. else {
  75. Windows.Cmd.RunClose(SpecialPath.UpdaterFileFullName, argument);
  76. callback?.Invoke();
  77. }
  78. }
  79. catch {
  80. callback?.Invoke();
  81. }
  82. });
  83. }
  84. catch {
  85. callback?.Invoke();
  86. }
  87. }
  88. #endregion
  89. #region IsWin10
  90. public static bool IsGEWin10 {
  91. get { return VirtualRoot.IsGEWin10; }
  92. }
  93. public static bool IsLTWin10 {
  94. get { return VirtualRoot.IsLTWin10; }
  95. }
  96. public static Visibility IsGEWin10Visible {
  97. get {
  98. if (VirtualRoot.IsGEWin10) {
  99. return Visibility.Visible;
  100. }
  101. return Visibility.Collapsed;
  102. }
  103. }
  104. public static Visibility IsLTWin10Visible {
  105. get {
  106. if (VirtualRoot.IsLTWin10) {
  107. return Visibility.Visible;
  108. }
  109. return Visibility.Collapsed;
  110. }
  111. }
  112. #endregion
  113. #region InnerProperty
  114. public static string Id {
  115. get { return VirtualRoot.Id.ToString(); }
  116. }
  117. public static string BootOn {
  118. get => NTMinerRoot.Instance.CreatedOn.ToString("yyyy-MM-dd HH:mm:ss");
  119. }
  120. public static string HomeDir {
  121. get => MainAssemblyInfo.HomeDirFullName;
  122. }
  123. public static string TempDir {
  124. get { return MainAssemblyInfo.TempDirFullName; }
  125. }
  126. public static string ServerDbFileFullName {
  127. get {
  128. return SpecialPath.ServerDbFileFullName.Replace(HomeDir, NTKeyword.HomeDirParameterName);
  129. }
  130. }
  131. public static string LocalDbFileFullName {
  132. get => VirtualRoot.LocalDbFileFullName.Replace(HomeDir, NTKeyword.HomeDirParameterName);
  133. }
  134. public static string ServerJsonFileFullName {
  135. get { return SpecialPath.ServerJsonFileFullName.Replace(HomeDir, NTKeyword.HomeDirParameterName); }
  136. }
  137. public static string ServerVersionJsonFileFullName {
  138. get { return MainAssemblyInfo.ServerVersionJsonFileFullName.Replace(HomeDir, NTKeyword.HomeDirParameterName); }
  139. }
  140. public static string PackagesDirFullName {
  141. get { return SpecialPath.PackagesDirFullName.Replace(HomeDir, NTKeyword.HomeDirParameterName); }
  142. }
  143. public static string DaemonFileFullName {
  144. get { return SpecialPath.DaemonFileFullName.Replace(TempDir, NTKeyword.TempDirParameterName); }
  145. }
  146. public static string DevConsoleFileFullName {
  147. get { return SpecialPath.DevConsoleFileFullName.Replace(TempDir, NTKeyword.TempDirParameterName); }
  148. }
  149. public static string DownloadDirFullName {
  150. get {
  151. return SpecialPath.DownloadDirFullName.Replace(TempDir, NTKeyword.TempDirParameterName);
  152. }
  153. }
  154. public static string KernelsDirFullName {
  155. get { return SpecialPath.KernelsDirFullName.Replace(TempDir, NTKeyword.TempDirParameterName); }
  156. }
  157. public static string LogsDirFullName {
  158. get { return SpecialPath.LogsDirFullName.Replace(TempDir, NTKeyword.TempDirParameterName); }
  159. }
  160. public static string AppRuntime {
  161. get {
  162. if (VirtualRoot.IsMinerStudio) {
  163. return "群控客户端";
  164. }
  165. else if (VirtualRoot.IsMinerClient) {
  166. return "挖矿端";
  167. }
  168. return "未知";
  169. }
  170. }
  171. #endregion
  172. #region IsMinerClient
  173. public static bool IsMinerClient {
  174. get => VirtualRoot.IsMinerClient;
  175. }
  176. public static Visibility IsMinerClientVisible {
  177. get {
  178. if (WpfUtil.IsInDesignMode) {
  179. return Visibility.Visible;
  180. }
  181. if (VirtualRoot.IsMinerClient) {
  182. return Visibility.Visible;
  183. }
  184. return Visibility.Collapsed;
  185. }
  186. }
  187. public static bool IsMinerStudio {
  188. get => VirtualRoot.IsMinerStudio;
  189. }
  190. public static Visibility IsMinerStudioVisible {
  191. get {
  192. if (WpfUtil.IsInDesignMode) {
  193. return Visibility.Visible;
  194. }
  195. if (VirtualRoot.IsMinerStudio) {
  196. return Visibility.Visible;
  197. }
  198. return Visibility.Collapsed;
  199. }
  200. }
  201. public static Visibility IsMinerStudioDevVisible {
  202. get {
  203. if (WpfUtil.IsInDesignMode) {
  204. return Visibility.Visible;
  205. }
  206. if (!DevMode.IsDevMode) {
  207. return Visibility.Collapsed;
  208. }
  209. if (VirtualRoot.IsMinerStudio) {
  210. return Visibility.Visible;
  211. }
  212. return Visibility.Collapsed;
  213. }
  214. }
  215. #endregion
  216. #region IsDev
  217. public static bool IsDevMode {
  218. get {
  219. return WpfUtil.IsDevMode;
  220. }
  221. }
  222. public static bool IsNotDevMode => !WpfUtil.IsDevMode;
  223. public static Visibility IsDevModeVisible {
  224. get {
  225. if (WpfUtil.IsDevMode) {
  226. return Visibility.Visible;
  227. }
  228. return Visibility.Collapsed;
  229. }
  230. }
  231. #endregion
  232. #region IsAmd
  233. public static Visibility IsAmdGpuVisible {
  234. get {
  235. if (NTMinerRoot.Instance.GpuSet.GpuType == GpuType.AMD) {
  236. return Visibility.Visible;
  237. }
  238. return Visibility.Collapsed;
  239. }
  240. }
  241. public static bool IsAmdGpu {
  242. get {
  243. return NTMinerRoot.Instance.GpuSet.GpuType == GpuType.AMD;
  244. }
  245. }
  246. #endregion
  247. #region IsBrand
  248. public static bool IsPoolBrand {
  249. get {
  250. return NTMinerRoot.IsPoolBrand;
  251. }
  252. }
  253. public static Visibility IsPoolBrandVisible {
  254. get {
  255. return NTMinerRoot.IsPoolBrand ? Visibility.Visible : Visibility.Collapsed;
  256. }
  257. }
  258. public static Visibility IsPoolBrandCollapsed {
  259. get { return NTMinerRoot.IsPoolBrand ? Visibility.Collapsed : Visibility.Visible; }
  260. }
  261. public static bool IsKernelBrand {
  262. get {
  263. return NTMinerRoot.IsKernelBrand;
  264. }
  265. }
  266. public static Visibility IsKernelBrandVisible {
  267. get {
  268. return NTMinerRoot.IsKernelBrand ? Visibility.Visible : Visibility.Collapsed;
  269. }
  270. }
  271. public static Visibility IsKernelBrandCollapsed {
  272. get { return NTMinerRoot.IsKernelBrand ? Visibility.Collapsed : Visibility.Visible; }
  273. }
  274. public static bool IsBrandSpecified {
  275. get { return NTMinerRoot.IsBrandSpecified; }
  276. }
  277. public static Visibility IsBrandSpecifiedVisible {
  278. get {
  279. return NTMinerRoot.IsBrandSpecified ? Visibility.Visible : Visibility.Collapsed;
  280. }
  281. }
  282. public static Visibility IsBrandSpecifiedCollapsed {
  283. get { return NTMinerRoot.IsBrandSpecified ? Visibility.Collapsed : Visibility.Visible; }
  284. }
  285. #endregion
  286. #region MainWindowHeight MainWindowWidth
  287. public static double MainWindowHeight {
  288. get {
  289. if (SystemParameters.WorkArea.Size.Height >= 620) {
  290. return 620;
  291. }
  292. else if (SystemParameters.WorkArea.Size.Height >= 520) {
  293. return 520;
  294. }
  295. return 480;
  296. }
  297. }
  298. public static double MainWindowWidth {
  299. get {
  300. if (SystemParameters.WorkArea.Size.Width >= 1090) {
  301. return 1090;
  302. }
  303. else if (SystemParameters.WorkArea.Size.Width >= 1000) {
  304. return 1000;
  305. }
  306. else if (SystemParameters.WorkArea.Size.Width >= 860) {
  307. return 860;
  308. }
  309. else if (SystemParameters.WorkArea.Size.Width >= 800) {
  310. return 800;
  311. }
  312. return 640;
  313. }
  314. }
  315. #endregion
  316. #region EnumItems
  317. public static IEnumerable<EnumItem<SupportedGpu>> SupportedGpuEnumItems {
  318. get {
  319. return NTMinerRoot.SupportedGpuEnumItems;
  320. }
  321. }
  322. public static IEnumerable<EnumItem<GpuType>> GpuTypeEnumItems {
  323. get {
  324. return NTMinerRoot.GpuTypeEnumItems;
  325. }
  326. }
  327. public static IEnumerable<EnumItem<PublishStatus>> PublishStatusEnumItems {
  328. get {
  329. return NTMinerRoot.PublishStatusEnumItems;
  330. }
  331. }
  332. public static IEnumerable<EnumItem<MineStatus>> MineStatusEnumItems {
  333. get {
  334. return NTMinerRoot.MineStatusEnumItems;
  335. }
  336. }
  337. public static IEnumerable<EnumItem<ServerMessageType>> ServerMessageTypeEnumItems {
  338. get {
  339. return NTMinerRoot.ServerMessageTypeEnumItems;
  340. }
  341. }
  342. #endregion
  343. #region AppName CurrentVersion VersionTag VersionFullName
  344. public static string AppName {
  345. get {
  346. return VirtualRoot.AppName;
  347. }
  348. }
  349. public static string CurrentVersion {
  350. get {
  351. return MainAssemblyInfo.CurrentVersion.ToString();
  352. }
  353. }
  354. public static string VersionTag {
  355. get {
  356. return MainAssemblyInfo.CurrentVersionTag;
  357. }
  358. }
  359. public static string VersionFullName {
  360. get {
  361. return $"v{MainAssemblyInfo.CurrentVersion}({VersionTag})";
  362. }
  363. }
  364. #endregion
  365. #region Gpu
  366. public static Version MinAmdDriverVersion {
  367. get {
  368. if (WpfUtil.IsInDesignMode) {
  369. return new Version();
  370. }
  371. if (NTMinerRoot.Instance.SysDicItemSet.TryGetDicItem(NTKeyword.ThisSystemSysDicCode, "MinAmdDriverVersion", out ISysDicItem dicItem)) {
  372. if (Version.TryParse(dicItem.Value, out Version version)) {
  373. return version;
  374. }
  375. }
  376. return new Version(17, 10, 2);
  377. }
  378. }
  379. public static Version MinNvidiaDriverVersion {
  380. get {
  381. if (WpfUtil.IsInDesignMode) {
  382. return new Version();
  383. }
  384. if (NTMinerRoot.Instance.SysDicItemSet.TryGetDicItem(NTKeyword.ThisSystemSysDicCode, "MinNvidiaDriverVersion", out ISysDicItem dicItem)) {
  385. if (Version.TryParse(dicItem.Value, out Version version)) {
  386. return version;
  387. }
  388. }
  389. return new Version(399, 24);
  390. }
  391. }
  392. public static string GpuSetInfo {
  393. get {
  394. return NTMinerRoot.Instance.GpuSetInfo;
  395. }
  396. }
  397. public static string DriverVersion {
  398. get {
  399. var gpuSet = NTMinerRoot.Instance.GpuSet;
  400. if (gpuSet.GpuType == GpuType.NVIDIA) {
  401. var cudaVersion = gpuSet.Properties.FirstOrDefault(a => a.Code == NTKeyword.CudaVersionSysDicCode);
  402. if (cudaVersion != null) {
  403. return $"{gpuSet.DriverVersion}_{cudaVersion.Value}";
  404. }
  405. }
  406. return gpuSet.DriverVersion.ToString();
  407. }
  408. }
  409. public static SolidColorBrush DriverVersionColor {
  410. get {
  411. var gpuSet = NTMinerRoot.Instance.GpuSet;
  412. switch (gpuSet.GpuType) {
  413. case GpuType.NVIDIA:
  414. if (gpuSet.DriverVersion < MinNvidiaDriverVersion) {
  415. return WpfUtil.RedBrush;
  416. }
  417. break;
  418. case GpuType.AMD:
  419. if (gpuSet.DriverVersion < MinAmdDriverVersion) {
  420. return WpfUtil.RedBrush;
  421. }
  422. break;
  423. }
  424. return (SolidColorBrush)Application.Current.Resources["LableColor"];
  425. }
  426. }
  427. public static string DriverVersionToolTip {
  428. get {
  429. var gpuSet = NTMinerRoot.Instance.GpuSet;
  430. bool isTooLow = false;
  431. switch (gpuSet.GpuType) {
  432. case GpuType.NVIDIA:
  433. if (gpuSet.DriverVersion < MinNvidiaDriverVersion) {
  434. isTooLow = true;
  435. }
  436. break;
  437. case GpuType.AMD:
  438. if (gpuSet.DriverVersion < MinAmdDriverVersion) {
  439. isTooLow = true;
  440. }
  441. break;
  442. }
  443. if (isTooLow) {
  444. return "显卡驱动版本较低,工具箱里有驱动下载地址";
  445. }
  446. return "显卡驱动版本";
  447. }
  448. }
  449. #endregion
  450. #region Windows
  451. private static readonly string _windowsEdition = Windows.OS.Instance.WindowsEdition?.Replace("Windows ", "Win");
  452. public static string WindowsEdition {
  453. get {
  454. return _windowsEdition;
  455. }
  456. }
  457. public const string LowWinMessage = "Windows版本较低,建议使用Win10系统";
  458. public static string WindowsEditionToolTip {
  459. get {
  460. // Win7下WinDivert.sys文件签名问题
  461. if (VirtualRoot.IsLTWin10) {
  462. return LowWinMessage;
  463. }
  464. return "操作系统";
  465. }
  466. }
  467. public static SolidColorBrush WindowsEditionColor {
  468. get {
  469. // Win7下WinDivert.sys文件签名问题
  470. if (VirtualRoot.IsLTWin10) {
  471. return WpfUtil.RedBrush;
  472. }
  473. return (SolidColorBrush)Application.Current.Resources["LableColor"];
  474. }
  475. }
  476. public static string TotalVirtualMemoryGbText {
  477. get {
  478. return AppContext.Instance.VirtualMemorySetVm.TotalVirtualMemoryGbText;
  479. }
  480. }
  481. #endregion
  482. public static ICommand ShowServerMessages { get; private set; } = new DelegateCommand(() => {
  483. });
  484. public static ICommand ShowServerKernelOutputKeywords { get; private set; } = new DelegateCommand(() => {
  485. });
  486. public static ICommand ShowIcons { get; private set; } = new DelegateCommand(() => {
  487. Views.Ucs.Icons.ShowWindow();
  488. });
  489. public static ICommand OpenDir { get; private set; } = new DelegateCommand<string>((dir) => {
  490. if (dir.StartsWith(NTKeyword.TempDirParameterName)) {
  491. dir = dir.Replace(NTKeyword.TempDirParameterName, MainAssemblyInfo.TempDirFullName);
  492. }
  493. else if (dir.StartsWith(NTKeyword.HomeDirParameterName)) {
  494. dir = dir.Replace(NTKeyword.HomeDirParameterName, MainAssemblyInfo.HomeDirFullName);
  495. }
  496. Process.Start(dir);
  497. });
  498. public static ICommand ViewUrl { get; private set; } = new DelegateCommand<string>(url => {
  499. if (string.IsNullOrEmpty(url)) {
  500. return;
  501. }
  502. Process.Start(url);
  503. });
  504. public static ICommand ConfigControlCenterHost { get; private set; } = new DelegateCommand(() => {
  505. VirtualRoot.Execute(new ShowControlCenterHostConfigCommand());
  506. });
  507. public static string ExportServerJsonMenuName {
  508. get {
  509. return "导出" + MainAssemblyInfo.ServerJsonFileName;
  510. }
  511. }
  512. public static ICommand ExportServerJson { get; private set; } = new DelegateCommand(() => {
  513. try {
  514. NTMinerRoot.ExportServerVersionJson(MainAssemblyInfo.ServerVersionJsonFileFullName);
  515. VirtualRoot.Out.ShowSuccess($"{MainAssemblyInfo.ServerJsonFileName}", "导出成功");
  516. }
  517. catch (Exception e) {
  518. Logger.ErrorDebugLine(e);
  519. }
  520. });
  521. public static string ServerJsonFileName { get; private set; } = MainAssemblyInfo.ServerJsonFileName;
  522. public static ICommand SetServerJsonVersion { get; private set; } = new DelegateCommand(() => {
  523. VirtualRoot.Execute(new ShowDialogWindowCommand(message: $"您确定刷新{MainAssemblyInfo.ServerJsonFileName}吗?", title: "确认", onYes: () => {
  524. try {
  525. VirtualRoot.Execute(new SetServerAppSettingCommand(new AppSettingData {
  526. Key = MainAssemblyInfo.ServerJsonFileName,
  527. Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff")
  528. }));
  529. VirtualRoot.Out.ShowSuccess($"刷新成功");
  530. }
  531. catch (Exception e) {
  532. Logger.ErrorDebugLine(e);
  533. VirtualRoot.Out.ShowError($"刷新失败");
  534. }
  535. }));
  536. });
  537. public static ICommand ShowMessagePathIds { get; private set; } = new DelegateCommand(() => {
  538. VirtualRoot.Execute(new ShowMessagePathIdsCommand());
  539. });
  540. public static ICommand ShowUsers { get; private set; } = new DelegateCommand(() => {
  541. VirtualRoot.Execute(new ShowUserPageCommand());
  542. });
  543. public static ICommand ShowOverClockDatas { get; private set; } = new DelegateCommand(() => {
  544. VirtualRoot.Execute(new ShowOverClockDataPageCommand());
  545. });
  546. public static ICommand ShowNTMinerWallets { get; private set; } = new DelegateCommand(() => {
  547. VirtualRoot.Execute(new ShowNTMinerWalletPageCommand());
  548. });
  549. public static ICommand ShowChartsWindow { get; private set; } = new DelegateCommand(() => {
  550. VirtualRoot.Execute(new ShowChartsWindowCommand());
  551. });
  552. public static ICommand ShowProperty { get; private set; } = new DelegateCommand(() => {
  553. VirtualRoot.Execute(new ShowPropertyCommand());
  554. });
  555. public static ICommand JoinQQGroup { get; private set; } = new DelegateCommand(() => {
  556. string url = "https://jq.qq.com/?_wv=1027&k=5ZPsuCk";
  557. if (NTMinerRoot.Instance.SysDicItemSet.TryGetDicItem(NTKeyword.ThisSystemSysDicCode, "QQGroupJoinUrl", out ISysDicItem dicItem)) {
  558. url = dicItem.Value;
  559. }
  560. Process.Start(url);
  561. });
  562. public static ICommand RunAsAdministrator { get; private set; } = new DelegateCommand(WpfUtil.RunAsAdministrator);
  563. public static ICommand ShowNotificationSample { get; private set; } = new DelegateCommand(() => {
  564. VirtualRoot.Execute(new ShowNotificationSampleCommand());
  565. });
  566. public static ICommand AppExit { get; private set; } = new DelegateCommand(() => {
  567. VirtualRoot.Execute(new CloseNTMinerCommand());
  568. });
  569. public static ICommand ShowRestartWindows { get; private set; } = new DelegateCommand(() => {
  570. VirtualRoot.Execute(new ShowRestartWindowsCommand());
  571. });
  572. public static ICommand ShowVirtualMemory { get; private set; } = new DelegateCommand(() => {
  573. VirtualRoot.Execute(new ShowVirtualMemoryCommand());
  574. });
  575. public static ICommand ShowSysDic { get; private set; } = new DelegateCommand(() => {
  576. VirtualRoot.Execute(new ShowSysDicPageCommand());
  577. });
  578. public static ICommand ShowGroups { get; private set; } = new DelegateCommand(() => {
  579. VirtualRoot.Execute(new ShowGroupPageCommand());
  580. });
  581. public static ICommand ShowCoins { get; private set; } = new DelegateCommand<CoinViewModel>((currentCoin) => {
  582. VirtualRoot.Execute(new ShowCoinPageCommand(currentCoin, "coin"));
  583. });
  584. public static ICommand ShowTagBrand { get; private set; } = new DelegateCommand(() => {
  585. VirtualRoot.Execute(new ShowTagBrandCommand());
  586. });
  587. public static ICommand ManagePools { get; private set; } = new DelegateCommand<CoinViewModel>(coinVm => {
  588. VirtualRoot.Execute(new ShowCoinPageCommand(coinVm, NTKeyword.PoolParameterName));
  589. });
  590. public static ICommand ManageWallet { get; private set; } = new DelegateCommand<CoinViewModel>(coinVm => {
  591. VirtualRoot.Execute(new ShowCoinPageCommand(coinVm, NTKeyword.WalletParameterName));
  592. });
  593. public static ICommand ShowKernelInputs { get; private set; } = new DelegateCommand(() => {
  594. VirtualRoot.Execute(new ShowKernelInputPageCommand());
  595. });
  596. public static ICommand ShowFileWriters { get; private set; } = new DelegateCommand(() => {
  597. VirtualRoot.Execute(new ShowFileWriterPageCommand());
  598. });
  599. public static ICommand ShowFragmentWriters { get; private set; } = new DelegateCommand(() => {
  600. VirtualRoot.Execute(new ShowFragmentWriterPageCommand());
  601. });
  602. public static ICommand ShowKernelOutputs { get; private set; } = new DelegateCommand<KernelOutputViewModel>((selectedKernelOutputVm) => {
  603. VirtualRoot.Execute(new ShowKernelOutputPageCommand(selectedKernelOutputVm));
  604. });
  605. public static ICommand ShowKernels { get; private set; } = new DelegateCommand(() => {
  606. VirtualRoot.Execute(new ShowKernelsWindowCommand());
  607. });
  608. public static ICommand ShowAbout { get; private set; } = new DelegateCommand(() => {
  609. VirtualRoot.Execute(new ShowAboutPageCommand());
  610. });
  611. public static ICommand ShowSpeedChart { get; private set; } = new DelegateCommand(() => {
  612. VirtualRoot.Execute(new ShowSpeedChartsCommand());
  613. });
  614. public static ICommand ShowNTMinerUpdaterConfig { get; private set; } = new DelegateCommand(() => {
  615. VirtualRoot.Execute(new ShowNTMinerUpdaterConfigCommand());
  616. });
  617. public static ICommand ShowOnlineUpdate { get; private set; } = new DelegateCommand(() => {
  618. VirtualRoot.Execute(new UpgradeCommand(string.Empty, null));
  619. });
  620. public static ICommand ShowHelp { get; private set; } = new DelegateCommand(() => {
  621. string url = "http://ntminer.com/";
  622. if (NTMinerRoot.Instance.SysDicItemSet.TryGetDicItem(NTKeyword.ThisSystemSysDicCode, "HelpUrl", out ISysDicItem dicItem)) {
  623. url = dicItem.Value;
  624. }
  625. Process.Start(url);
  626. });
  627. public static ICommand ShowMinerClients { get; private set; } = new DelegateCommand(() => {
  628. VirtualRoot.Execute(new ShowMinerClientsWindowCommand());
  629. });
  630. public static ICommand ShowCalcConfig { get; private set; } = new DelegateCommand(() => {
  631. VirtualRoot.Execute(new ShowCalcConfigCommand());
  632. });
  633. public static ICommand ShowHomeDir { get; private set; } = new DelegateCommand(() => {
  634. Process.Start(MainAssemblyInfo.HomeDirFullName);
  635. });
  636. public static ICommand OpenLocalLiteDb { get; private set; } = new DelegateCommand(() => {
  637. OpenLiteDb(VirtualRoot.LocalDbFileFullName);
  638. });
  639. public static ICommand OpenServerLiteDb { get; private set; } = new DelegateCommand(() => {
  640. OpenLiteDb(SpecialPath.ServerDbFileFullName);
  641. });
  642. #region private method OpenLiteDb
  643. private static void OpenLiteDb(string dbFileFullName) {
  644. string liteDbExplorerDir = Path.Combine(SpecialPath.ToolsDirFullName, "LiteDBExplorerPortable");
  645. string liteDbExplorerFileFullName = Path.Combine(liteDbExplorerDir, "LiteDbExplorer.exe");
  646. if (!Directory.Exists(liteDbExplorerDir)) {
  647. Directory.CreateDirectory(liteDbExplorerDir);
  648. }
  649. if (!File.Exists(liteDbExplorerFileFullName)) {
  650. OfficialServer.FileUrlService.GetLiteDbExplorerUrlAsync((downloadFileUrl, e) => {
  651. if (string.IsNullOrEmpty(downloadFileUrl)) {
  652. return;
  653. }
  654. VirtualRoot.Execute(new ShowFileDownloaderCommand(downloadFileUrl, "LiteDB数据库管理工具", (window, isSuccess, message, saveFileFullName) => {
  655. if (isSuccess) {
  656. ZipUtil.DecompressZipFile(saveFileFullName, liteDbExplorerDir);
  657. File.Delete(saveFileFullName);
  658. window?.Close();
  659. Windows.Cmd.RunClose(liteDbExplorerFileFullName, dbFileFullName);
  660. }
  661. }));
  662. });
  663. }
  664. else {
  665. Windows.Cmd.RunClose(liteDbExplorerFileFullName, dbFileFullName);
  666. }
  667. }
  668. #endregion
  669. public static ICommand OpenLogfile { get; private set; } = new DelegateCommand<string>((logfileFullName) => {
  670. OpenTxtFile(logfileFullName);
  671. });
  672. public static string NppPackageUrl {
  673. get {
  674. if (WpfUtil.IsDevMode) {
  675. return "https://minerjson.oss-cn-beijing.aliyuncs.com/npp.zip";
  676. }
  677. if (NTMinerRoot.Instance.SysDicItemSet.TryGetDicItem("Tool", "npp", out ISysDicItem dicItem)) {
  678. return dicItem.Value;
  679. }
  680. return "https://minerjson.oss-cn-beijing.aliyuncs.com/npp.zip";
  681. }
  682. }
  683. #region private method OpenTxtFile
  684. private static void OpenTxtFile(string fileFullName) {
  685. string nppDir = Path.Combine(SpecialPath.ToolsDirFullName, "Npp");
  686. string nppFileFullName = Path.Combine(nppDir, "notepad++.exe");
  687. if (!Directory.Exists(nppDir)) {
  688. Directory.CreateDirectory(nppDir);
  689. }
  690. if (!File.Exists(nppFileFullName)) {
  691. VirtualRoot.Execute(new ShowFileDownloaderCommand(NppPackageUrl, "Notepad++", (window, isSuccess, message, saveFileFullName) => {
  692. if (isSuccess) {
  693. ZipUtil.DecompressZipFile(saveFileFullName, nppDir);
  694. File.Delete(saveFileFullName);
  695. window?.Close();
  696. Windows.Cmd.RunClose(nppFileFullName, fileFullName);
  697. }
  698. }));
  699. }
  700. else {
  701. Windows.Cmd.RunClose(nppFileFullName, fileFullName);
  702. }
  703. }
  704. #endregion
  705. public static ICommand ShowCalc { get; private set; } = new DelegateCommand<CoinViewModel>(coinVm => {
  706. VirtualRoot.Execute(new ShowCalcCommand(coinVm));
  707. });
  708. public static ICommand ShowLocalIps { get; private set; } = new DelegateCommand(() => {
  709. VirtualRoot.Execute(new ShowLocalIpsCommand());
  710. });
  711. public static ICommand ShowEthNoDevFee { get; private set; } = new DelegateCommand(() => {
  712. VirtualRoot.Execute(new ShowEthNoDevFeeCommand());
  713. });
  714. public static ICommand OpenOfficialSite { get; private set; } = new DelegateCommand(() => {
  715. string url = "http://ntminer.com/";
  716. if (NTMinerRoot.Instance.SysDicItemSet.TryGetDicItem(NTKeyword.ThisSystemSysDicCode, "HomePageUrl", out ISysDicItem dicItem)) {
  717. url = dicItem.Value;
  718. }
  719. Process.Start(url);
  720. });
  721. public static string QQGroup {
  722. get {
  723. if (WpfUtil.IsInDesignMode) {
  724. return string.Empty;
  725. }
  726. if (NTMinerRoot.Instance.SysDicItemSet.TryGetDicItem(NTKeyword.ThisSystemSysDicCode, "QQGroup", out ISysDicItem dicItem)) {
  727. return dicItem.Value;
  728. }
  729. return "863725136";
  730. }
  731. }
  732. public static string OfficialSiteName {
  733. get {
  734. if (WpfUtil.IsDevMode) {
  735. return "NTMiner.com";
  736. }
  737. if (NTMinerRoot.Instance.SysDicItemSet.TryGetDicItem(NTKeyword.ThisSystemSysDicCode, "HomePageUrl", out ISysDicItem dicItem) && !string.IsNullOrEmpty(dicItem.Value)) {
  738. if (dicItem.Value.StartsWith("https://")) {
  739. return dicItem.Value.Substring("https://".Length);
  740. }
  741. if (dicItem.Value.StartsWith("http://")) {
  742. return dicItem.Value.Substring("http://".Length);
  743. }
  744. }
  745. return "NTMiner.com";
  746. }
  747. }
  748. public static string AppMinerName {
  749. get {
  750. if (WpfUtil.IsDevMode) {
  751. return "开源矿工";
  752. }
  753. if (NTMinerRoot.Instance.SysDicItemSet.TryGetDicItem(NTKeyword.ThisSystemSysDicCode, "AppMinerName", out ISysDicItem dicItem)) {
  754. return dicItem.Value;
  755. }
  756. return "开源矿工";
  757. }
  758. }
  759. public static string AppMinerDescription {
  760. get {
  761. if (WpfUtil.IsDevMode) {
  762. return " - 做最好的矿工";
  763. }
  764. if (NTMinerRoot.Instance.SysDicItemSet.TryGetDicItem(NTKeyword.ThisSystemSysDicCode, "AppMinerName", out ISysDicItem dicItem)) {
  765. return " - " + dicItem.Description;
  766. }
  767. return " - 做最好的矿工";
  768. }
  769. }
  770. public static string AppMinerIntro {
  771. get {
  772. if (WpfUtil.IsDevMode) {
  773. return "开源、开放、安全、专业、最高收益。QQ群863725136";
  774. }
  775. if (NTMinerRoot.Instance.SysDicItemSet.TryGetDicItem(NTKeyword.ThisSystemSysDicCode, "AppMinerIntro", out ISysDicItem dicItem)) {
  776. return dicItem.Value;
  777. }
  778. return "开源、开放、安全、专业、最高收益。QQ群863725136";
  779. }
  780. }
  781. public static ICommand BusinessModel { get; private set; } = new DelegateCommand(() => {
  782. string url = "https://www.loserhub.cn/posts/details/52";
  783. if (NTMinerRoot.Instance.SysDicItemSet.TryGetDicItem(NTKeyword.ThisSystemSysDicCode, "BusinessModelUrl", out ISysDicItem dicItem)) {
  784. url = dicItem.Value;
  785. }
  786. Process.Start(url);
  787. });
  788. public static ICommand OpenGithub { get; private set; } = new DelegateCommand(() => {
  789. string url = "https://github.com/ntminer/ntminer";
  790. if (NTMinerRoot.Instance.SysDicItemSet.TryGetDicItem(NTKeyword.ThisSystemSysDicCode, "GithubUrl", out ISysDicItem dicItem)) {
  791. url = dicItem.Value;
  792. }
  793. Process.Start(url);
  794. });
  795. public static ICommand OpenDiscussSite { get; private set; } = new DelegateCommand(() => {
  796. string url = "https://github.com/ntminer/ntminer/issues";
  797. if (NTMinerRoot.Instance.SysDicItemSet.TryGetDicItem(NTKeyword.ThisSystemSysDicCode, "DiscussUrl", out ISysDicItem dicItem)) {
  798. url = dicItem.Value;
  799. }
  800. Process.Start(url);
  801. });
  802. public static ICommand DownloadMinerStudio { get; private set; } = new DelegateCommand(() => {
  803. Process.Start($"{OfficialServer.MinerJsonBucket}MinerStudio.exe?t={DateTime.Now.Ticks}");
  804. });
  805. public static ICommand ShowQQGroupQrCode { get; private set; } = new DelegateCommand(() => {
  806. VirtualRoot.Execute(new ShowQQGroupQrCodeCommand());
  807. });
  808. }
  809. }