LedControl.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. using HNWD.LatticeScreen;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Concurrent;
  5. using System.Collections.Generic;
  6. using System.Drawing;
  7. using System.Globalization;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Runtime.InteropServices;
  11. using System.Text;
  12. using System.Threading;
  13. using System.Windows.Forms;
  14. using LatticeScreenServer;
  15. namespace HNWD.LatticeScreen
  16. {
  17. public class LedControl
  18. {
  19. public const int JR_OK = 0;
  20. private static readonly ConcurrentDictionary<IntPtr, IntPtr> handle = new ConcurrentDictionary<IntPtr, IntPtr>();
  21. private static readonly ConcurrentDictionary<IntPtr, DomainInfo> domainInfo = new ConcurrentDictionary<IntPtr, DomainInfo>();
  22. private static string configFile = "Config.ini";
  23. private static FileSystemWatcher fileWatcher = null;
  24. private static int randomPtr = 1;
  25. public static string ConfigFile
  26. {
  27. get => configFile;
  28. set
  29. {
  30. configFile = Path.GetFullPath(value);
  31. fileWatcher?.Dispose();
  32. fileWatcher = new FileSystemWatcher(Path.GetDirectoryName(configFile) ?? string.Empty, $"*{Path.GetExtension(configFile)}")
  33. {
  34. EnableRaisingEvents = true
  35. };
  36. fileWatcher.Changed += (sender, e) =>
  37. {
  38. if (e.FullPath == configFile && WatcherChangeTypes.All.HasFlag(e.ChangeType))
  39. {
  40. isPlaySound = null;
  41. soundPerson = null;
  42. soundVolume = null;
  43. soundSpeed = null;
  44. font = null;
  45. fontSize = null;
  46. }
  47. };
  48. }
  49. }
  50. static LedControl()
  51. {
  52. ConfigFile = "Config.ini";
  53. // 将 dll 文件保存到运行根目录
  54. SaveNonFile("bx_sdk_dual.dll", OnbonResources.bx_sdk_dual);
  55. SaveNonFile("cairo-1.14.6.dll", OnbonResources.cairo_1_14_6);
  56. SaveNonFile("freetype.dll", OnbonResources.freetype);
  57. SaveNonFile("freetype265.dll", OnbonResources.freetype265);
  58. SaveNonFile("libpng16.dll", OnbonResources.libpng16);
  59. SaveNonFile("msvcr110.dll", OnbonResources.msvcr110);
  60. SaveNonFile("zlibwapi.dll", OnbonResources.zlibwapi);
  61. }
  62. private static void SaveNonFile(string filePath, byte[] fileData)
  63. {
  64. if (!Path.IsPathRooted(filePath))
  65. {
  66. filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filePath);
  67. }
  68. if (!File.Exists(filePath))
  69. {
  70. using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read, fileData.Length))
  71. {
  72. fileStream.Write(fileData, 0, fileData.Length);
  73. }
  74. }
  75. }
  76. private static bool? isPlaySound = null;
  77. public static bool IsPlaySound
  78. {
  79. get
  80. {
  81. if (isPlaySound.HasValue)
  82. {
  83. return isPlaySound.Value;
  84. }
  85. var result = ReadValue(nameof(IsPlaySound));
  86. if (bool.TryParse(result, out var value))
  87. {
  88. isPlaySound = value;
  89. return value;
  90. }
  91. isPlaySound = false;
  92. return false;
  93. }
  94. }
  95. private static byte? soundPerson = null;
  96. public static byte SoundPerson
  97. {
  98. get
  99. {
  100. if (soundPerson.HasValue)
  101. {
  102. return soundPerson.Value;
  103. }
  104. var result = ReadValue(nameof(SoundPerson));
  105. if (byte.TryParse(result, NumberStyles.Any, CultureInfo.InvariantCulture, out var value))
  106. {
  107. soundPerson = value;
  108. return value;
  109. }
  110. soundPerson = 0;
  111. return 0;
  112. }
  113. }
  114. private static byte? soundVolume = null;
  115. public static byte SoundVolume
  116. {
  117. get
  118. {
  119. if (soundVolume.HasValue)
  120. {
  121. return soundVolume.Value;
  122. }
  123. var result = ReadValue(nameof(SoundVolume));
  124. if (byte.TryParse(result, NumberStyles.Any, CultureInfo.InvariantCulture, out var value))
  125. {
  126. soundVolume = value;
  127. return value;
  128. }
  129. soundVolume = 0;
  130. return 0;
  131. }
  132. }
  133. private static byte? soundSpeed = null;
  134. public static byte SoundSpeed
  135. {
  136. get
  137. {
  138. if (soundSpeed.HasValue)
  139. {
  140. return soundSpeed.Value;
  141. }
  142. var result = ReadValue(nameof(SoundSpeed));
  143. if (byte.TryParse(result, NumberStyles.Any, CultureInfo.InvariantCulture, out var value))
  144. {
  145. soundSpeed = value;
  146. return value;
  147. }
  148. soundSpeed = 0;
  149. return 0;
  150. }
  151. }
  152. private static string font = null;
  153. public static string Font
  154. {
  155. get
  156. {
  157. if (font != null)
  158. {
  159. return font;
  160. }
  161. var result = ReadValue(nameof(Font));
  162. if (string.IsNullOrEmpty(result))
  163. {
  164. font = "宋体";
  165. }
  166. else
  167. {
  168. font = result;
  169. }
  170. return font;
  171. }
  172. }
  173. private static int? fontSize = null;
  174. public static int FontSize
  175. {
  176. get
  177. {
  178. if (fontSize.HasValue)
  179. {
  180. return fontSize.Value;
  181. }
  182. var result = ReadValue(nameof(FontSize));
  183. if (int.TryParse(result, out var value))
  184. {
  185. fontSize = value;
  186. }
  187. else
  188. {
  189. fontSize = 12;
  190. }
  191. return fontSize.Value;
  192. }
  193. }
  194. public static int JHCreateInst(ref IntPtr hdl, ushort serverid)
  195. {
  196. //var tmp = new IntPtr(new Random().Next(100, 1000000));
  197. var tmp = new IntPtr(Interlocked.Increment(ref randomPtr));
  198. hdl = tmp;
  199. handle.AddOrUpdate(hdl, hdl, (key, value) => tmp);
  200. return bx_sdk_dual.InitSdk();
  201. }
  202. public static int JHCommInit()
  203. {
  204. return 0;
  205. }
  206. public static int JHDeleteInst(IntPtr hdl)
  207. {
  208. if (handle.TryGetValue(hdl, out var value))
  209. {
  210. domainInfo.TryRemove(value, out _);
  211. }
  212. return 0;
  213. }
  214. public static int JHCommGetTransportlayer(ref IntPtr ptransportlayer, int dev)
  215. {
  216. return 0;
  217. }
  218. public static int JHCommGetNetArgStruct(ref IntPtr pargs, string ipordomain, ushort port, uint timeout)
  219. {
  220. //var tmp = new IntPtr(new Random().Next(100, 1000000));
  221. var tmp = new IntPtr(Interlocked.Increment(ref randomPtr));
  222. pargs = tmp;
  223. ushort controllerType = 0;
  224. var data = new bx_sdk_dual.Ping_data();
  225. var err = bx_sdk_dual.cmd_tcpPing(Encoding.Default.GetBytes(ipordomain), port, ref data);
  226. if (err == 0)
  227. {
  228. controllerType = data.ControllerType;
  229. }
  230. else
  231. {
  232. var buffer = new byte[Marshal.SizeOf(typeof(bx_sdk_dual.Ping_data))];
  233. err = bx_sdk_dual.cmd_udpPing(buffer);
  234. if (err != 0)
  235. {
  236. return err;
  237. }
  238. if (ipordomain == Encoding.Default.GetString(data.ipAdder).Replace("\0", ""))
  239. {
  240. controllerType = data.ControllerType;
  241. }
  242. else
  243. {
  244. return -1;
  245. }
  246. }
  247. var result = bx_sdk_dual.cmd_check_time(Encoding.Default.GetBytes(ipordomain), port);
  248. var doman = new DomainInfo
  249. {
  250. Address = ipordomain,
  251. Port = port,
  252. Timeout = timeout,
  253. ControllerType = controllerType,
  254. Size = new Size(data.ScreenWidth, data.ScreenHeight),
  255. Sync = new object()
  256. };
  257. domainInfo.AddOrUpdate(tmp, doman, (key, value) => doman);
  258. return 0;
  259. }
  260. public static int JHMountTransportLayer(IntPtr hdl, IntPtr ptl, IntPtr argstruct)
  261. {
  262. handle.AddOrUpdate(hdl, argstruct, (key, value) => argstruct);
  263. return 0;
  264. }
  265. //private static string lastText = string.Empty;
  266. //private static DrawText? lastDateTime;
  267. private static ConcurrentDictionary<string, string> lastTextDic = new ConcurrentDictionary<string, string>();
  268. private static ConcurrentDictionary<string, DrawText?> lastDateTimeDic = new ConcurrentDictionary<string, DrawText?>();
  269. public static int JHDrawText(IntPtr hdl, short x, short y, ushort width, ushort height, uint format, string ptext)
  270. {
  271. if (!handle.TryGetValue(hdl, out var argsPtr))
  272. {
  273. return -1;
  274. }
  275. if (!domainInfo.TryGetValue(argsPtr, out var domain))
  276. {
  277. return -1;
  278. }
  279. lock (domain.Sync)
  280. {
  281. var lastTextTmp = "";
  282. DrawText? lastDateTimeTmp = null;
  283. var hasLastTextTmp = lastTextDic.TryGetValue(domain.Address, out lastTextTmp);
  284. lastDateTimeDic.TryGetValue(domain.Address, out lastDateTimeTmp);
  285. var isDateTime = IsDateTimeText(ptext, out var dateStyle, out var timeStyle);
  286. if (isDateTime)
  287. {
  288. if (width < domain.Size.Width || height < domain.Size.Height)
  289. {
  290. if (!lastDateTimeTmp.HasValue)
  291. {
  292. lastDateTimeTmp = new DrawText()
  293. {
  294. Format = format,
  295. Location = new Point(x, y),
  296. Size = new Size(width, height),
  297. Text = ptext
  298. };
  299. lastDateTimeDic.AddOrUpdate(domain.Address, lastDateTimeTmp, (key, value) => lastDateTimeTmp);
  300. return 0;
  301. }
  302. var tmpText = lastDateTimeTmp.Value.Text;
  303. if (IsDateTimeText(tmpText, out var dateStyleTmp, out var timeStyleTmp))
  304. {
  305. if (dateStyle == dateStyleTmp && timeStyle == timeStyleTmp)
  306. {
  307. return 0;
  308. }
  309. }
  310. if (tmpText.EndsWith(" "))
  311. {
  312. ptext = tmpText + ptext;
  313. }
  314. else
  315. {
  316. ptext = tmpText + " " + ptext;
  317. }
  318. IsDateTimeText(ptext, out dateStyle, out timeStyle);
  319. }
  320. else
  321. {
  322. //lastDateTimeTmp = null;
  323. lastDateTimeDic.TryRemove(domain.Address, out _);
  324. }
  325. if (IsDateTimeText(lastTextTmp, out var tmpDateStyle, out var tmpTimeStyle))
  326. {
  327. if (dateStyle == tmpDateStyle && timeStyle == tmpTimeStyle)
  328. {
  329. return 0;
  330. }
  331. }
  332. }
  333. else
  334. {
  335. if (hasLastTextTmp && lastTextTmp == ptext)
  336. {
  337. return 0;
  338. }
  339. }
  340. bx_sdk_dual.EQprogramHeader_G6 header;
  341. header.FileType = 0x00;
  342. header.ProgramID = 0;
  343. header.ProgramStyle = 0x00;
  344. header.ProgramPriority = 0x00;
  345. header.ProgramPlayTimes = 1;
  346. header.ProgramTimeSpan = 0;
  347. header.SpecialFlag = 0;
  348. header.CommExtendParaLen = 0x00;
  349. header.ScheduNum = 0;
  350. header.LoopValue = 0;
  351. header.Intergrate = 0x00;
  352. header.TimeAttributeNum = 0x00;
  353. header.TimeAttribute0Offset = 0x0000;
  354. header.ProgramWeek = 0xff;
  355. header.ProgramLifeSpan_sy = 0xffff;
  356. header.ProgramLifeSpan_sm = 0x03;
  357. header.ProgramLifeSpan_sd = 0x14;
  358. header.ProgramLifeSpan_ey = 0xffff;
  359. header.ProgramLifeSpan_em = 0x03;
  360. header.ProgramLifeSpan_ed = 0x14;
  361. header.PlayPeriodGrpNum = 1;
  362. IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(bx_sdk_dual.EQprogramHeader_G6)));
  363. Marshal.StructureToPtr(header, ptr, false);
  364. int err = bx_sdk_dual.program_addProgram_G6(ptr);
  365. if (err != 0)
  366. {
  367. return err;
  368. }
  369. ushort areaId = 0;
  370. if (isDateTime)
  371. {
  372. var aheader = new bx_sdk_dual.EQareaHeader_G6();
  373. aheader.AreaX = 0;
  374. aheader.AreaY = 0;
  375. aheader.AreaWidth = (ushort)domain.Size.Width;
  376. aheader.AreaHeight = (ushort)domain.Size.Height;
  377. aheader.Transparency = 101;
  378. aheader.AreaType = (byte)bx_sdk_dual.AreaType.DateTime;
  379. ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(bx_sdk_dual.EQareaHeader_G6)));
  380. Marshal.StructureToPtr(aheader, ptr, false);
  381. err = bx_sdk_dual.program_addArea_G6(areaId, ptr);
  382. if (err != 0)
  383. {
  384. return err;
  385. }
  386. var timeData = new bx_sdk_dual.EQtimeAreaData_G56();
  387. if (timeData.date_enable == 0)
  388. {
  389. if (dateStyle.HasValue)
  390. {
  391. timeData.date_enable = 1;
  392. timeData.datestyle = dateStyle.Value;
  393. }
  394. }
  395. if (timeData.time_enable == 0)
  396. {
  397. if (timeStyle.HasValue)
  398. {
  399. timeData.time_enable = 1;
  400. timeData.timestyle = timeStyle.Value;
  401. }
  402. }
  403. if (lastDateTimeTmp.HasValue)
  404. {
  405. timeData.linestyle = bx_sdk_dual.E_arrMode.eMULTILINE;
  406. //lastDateTime = null;
  407. lastDateTimeDic.TryRemove(domain.Address, out _);
  408. }
  409. else
  410. {
  411. timeData.linestyle = bx_sdk_dual.E_arrMode.eSINGLELINE;
  412. }
  413. timeData.color = (uint)bx_sdk_dual.E_Color_G56.eRED;
  414. timeData.fontName = Font;
  415. timeData.fontSize = (ushort)FontSize;
  416. timeData.fontAlign = GetHalign(format);
  417. if (timeData.fontAlign > 0)
  418. {
  419. timeData.fontAlign--;
  420. }
  421. ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(bx_sdk_dual.EQtimeAreaData_G56)));
  422. Marshal.StructureToPtr(timeData, ptr, false);
  423. err = bx_sdk_dual.program_timeAreaAddContent_G6(areaId, ptr);
  424. if (err != 0)
  425. {
  426. return err;
  427. }
  428. }
  429. else
  430. {
  431. var aheader = new bx_sdk_dual.EQareaHeader_G6();
  432. aheader.AreaX = (ushort)x;
  433. aheader.AreaY = (ushort)y;
  434. aheader.AreaWidth = width;
  435. aheader.AreaHeight = height;
  436. aheader.Transparency = 101;
  437. ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(bx_sdk_dual.EQareaHeader_G6)));
  438. Marshal.StructureToPtr(aheader, ptr, false);
  439. err = bx_sdk_dual.program_addArea_G6(areaId, ptr);
  440. if (err != 0)
  441. {
  442. return err;
  443. }
  444. var str = Encoding.GetEncoding("GBK").GetBytes(ptext);
  445. if (ControlType.HasVoiceModule(domain.ControllerType) && IsPlaySound)
  446. {
  447. var sound = new bx_sdk_dual.EQPicAreaSoundHeader_G6();
  448. sound.SoundPerson = SoundPerson;
  449. sound.SoundVolum = SoundVolume;
  450. sound.SoundSpeed = SoundSpeed;
  451. sound.SoundDataMode = 0;
  452. sound.SoundReplayTimes = 0;
  453. sound.SoundReplayDelay = 1000;
  454. sound.SoundReservedParaLen = 3;
  455. sound.Soundnumdeal = 0;
  456. sound.Soundlanguages = 0;
  457. sound.Soundwordstyle = 0;
  458. bx_sdk_dual.program_pictureAreaEnableSound_G6(0, sound, str);
  459. }
  460. var font = Encoding.Default.GetBytes(Font);
  461. bx_sdk_dual.EQpageHeader_G6 pheader = new bx_sdk_dual.EQpageHeader_G6();
  462. pheader.PageStyle = 0x00;
  463. pheader.DisplayMode = 0x01; //移动模式
  464. pheader.ClearMode = 0x01;
  465. pheader.Speed = 15; //速度
  466. pheader.StayTime = 0; //停留时间
  467. pheader.RepeatTime = 1;
  468. pheader.ValidLen = 0;
  469. pheader.CartoonFrameRate = 0x00;
  470. pheader.BackNotValidFlag = 0x00;
  471. pheader.arrMode = bx_sdk_dual.E_arrMode.eSINGLELINE;
  472. pheader.fontSize = (ushort)FontSize;
  473. pheader.color = (uint)0x01;
  474. pheader.fontBold = 0;
  475. pheader.fontItalic = 0;
  476. pheader.tdirection = bx_sdk_dual.E_txtDirection.pNORMAL;
  477. pheader.txtSpace = 0;
  478. pheader.Valign = GetValign(format);
  479. pheader.Halign = GetHalign(format);
  480. ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(bx_sdk_dual.EQpageHeader_G6)));
  481. Marshal.StructureToPtr(pheader, ptr, false);
  482. err = bx_sdk_dual.program_picturesAreaAddTxt_G6(areaId, str, font, ptr);
  483. if (err != 0)
  484. {
  485. return err;
  486. }
  487. }
  488. bx_sdk_dual.EQprogram_G6 program = new bx_sdk_dual.EQprogram_G6();
  489. program.fileName = Encoding.GetEncoding("GBK").GetBytes("P000");
  490. program.fileType = 0;
  491. program.fileLen = 0;
  492. program.fileAddre = IntPtr.Zero;
  493. program.dfileName = Encoding.GetEncoding("GBK").GetBytes("D000");
  494. program.dfileType = 0;
  495. program.dfileLen = 0;
  496. program.dfileAddre = IntPtr.Zero;
  497. err = bx_sdk_dual.program_IntegrateProgramFile_G6(ref program);
  498. if (err != 0)
  499. {
  500. return err;
  501. }
  502. err = bx_sdk_dual.cmd_ofsStartFileTransf(Encoding.GetEncoding("GBK").GetBytes(domain.Address),
  503. (ushort)domain.Port);
  504. if (err != 0)
  505. {
  506. return err;
  507. }
  508. err = bx_sdk_dual.cmd_ofsWriteFile(Encoding.GetEncoding("GBK").GetBytes(domain.Address),
  509. (ushort)domain.Port, program.dfileName, program.dfileType, program.dfileLen, 1,
  510. program.dfileAddre);
  511. if (err != 0)
  512. {
  513. return err;
  514. }
  515. err = bx_sdk_dual.cmd_ofsWriteFile(Encoding.GetEncoding("GBK").GetBytes(domain.Address),
  516. (ushort)domain.Port, program.fileName, program.fileType, program.fileLen, 1, program.fileAddre);
  517. if (err != 0)
  518. {
  519. return err;
  520. }
  521. err = bx_sdk_dual.cmd_ofsEndFileTransf(Encoding.GetEncoding("GBK").GetBytes(domain.Address),
  522. (ushort)domain.Port);
  523. if (err != 0)
  524. {
  525. return err;
  526. }
  527. bx_sdk_dual.program_deleteProgram_G6();
  528. //lastText = ptext;
  529. lastTextDic.AddOrUpdate(domain.Address, ptext, (key, value) => ptext);
  530. return 0;
  531. }
  532. }
  533. public static int JHDrawMultPixel(IntPtr hdl, ushort[] pdat, ushort poscnt)
  534. {
  535. return 0;
  536. }
  537. private static Thread eraseThread;
  538. public static int JHErase(IntPtr hdl)
  539. {
  540. //return JHDrawText(hdl, 0, 0, ushort.MaxValue, ushort.MaxValue, 0, "");
  541. StopEraseThreead();
  542. eraseThread = new Thread(state =>
  543. {
  544. Thread.Sleep(TimeSpan.FromSeconds(10));
  545. JHDrawText(hdl, 0, 0, ushort.MaxValue, ushort.MaxValue, 0, "");
  546. });
  547. return 0;
  548. }
  549. private static void StopEraseThreead()
  550. {
  551. try
  552. {
  553. eraseThread?.Abort();
  554. eraseThread?.DisableComObjectEagerCleanup();
  555. }
  556. catch
  557. {
  558. }
  559. }
  560. public static int JHDrawBitmap(IntPtr hdl, short x, short y, ushort width, ushort height, uint format, tagBitmapSource pbmpsrc)
  561. {
  562. return 0;
  563. }
  564. public static int JHCommDeinit()
  565. {
  566. return 0;
  567. }
  568. public static int JHCommReleaseArgStruct(IntPtr pargs)
  569. {
  570. domainInfo.TryRemove(pargs, out _);
  571. return 0;
  572. }
  573. private static byte GetHalign(uint format)
  574. {
  575. var value = (int)((format >> 4) & 0x3);
  576. switch (value)
  577. {
  578. case 0b00:
  579. return 1;
  580. case 0b01:
  581. return 2;
  582. case 0b10:
  583. return 3;
  584. default:
  585. return 0;
  586. }
  587. }
  588. private static byte GetValign(uint format)
  589. {
  590. var value = (int)((format >> 6) & 0x3);
  591. switch (value)
  592. {
  593. case 0b00: return 1;
  594. case 0b01: return 2;
  595. case 0b10: return 3;
  596. default: return 0;
  597. }
  598. }
  599. private struct DomainInfo
  600. {
  601. public string Address { get; set; }
  602. public int Port { get; set; }
  603. public uint Timeout { get; set; }
  604. public ushort ControllerType { get; set; }
  605. public Size Size { get; set; }
  606. public object Sync { get; set; }
  607. }
  608. private struct DrawText
  609. {
  610. public Point Location { get; set; }
  611. public Size Size { get; set; }
  612. public string Text { get; set; }
  613. public uint Format { get; set; }
  614. public override bool Equals(object obj)
  615. {
  616. if (obj is DrawText other)
  617. {
  618. if (Location.Equals(other.Location) && Size.Equals(other.Size) && Format == other.Format)
  619. {
  620. if (IsDateTimeText(Text, out var thisDateStyle, out var thisTimeStyle))
  621. {
  622. if (IsDateTimeText(other.Text, out var otherDateStyle, out var otherTimeStyle))
  623. {
  624. return thisDateStyle == otherDateStyle && thisTimeStyle == otherTimeStyle;
  625. }
  626. }
  627. if (!IsDateTimeText(other.Text, out _, out _))
  628. {
  629. return this.Text == other.Text;
  630. }
  631. }
  632. }
  633. return false;
  634. }
  635. public override int GetHashCode()
  636. {
  637. unchecked
  638. {
  639. var hashCode = Location.GetHashCode();
  640. hashCode = (hashCode * 397) ^ Size.GetHashCode();
  641. hashCode = (hashCode * 397) ^ Format.GetHashCode();
  642. if (!IsDateTimeText(Text, out _, out _))
  643. {
  644. hashCode = (hashCode * 397) ^ (Text != null ? Text.GetHashCode() : 0);
  645. }
  646. return hashCode;
  647. }
  648. }
  649. }
  650. private static bool IsDateTimeText(string text, out bx_sdk_dual.E_DateStyle? dateStyle, out bx_sdk_dual.E_TimeStyle? timeStyle)
  651. {
  652. dateStyle = null;
  653. timeStyle = null;
  654. if (DateTime.TryParseExact(text, "HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out _))
  655. {
  656. timeStyle = bx_sdk_dual.E_TimeStyle.eHH_MM_SS_COLON;
  657. return true;
  658. }
  659. if (DateTime.TryParseExact(text, "HH时MM分ss秒", CultureInfo.InvariantCulture, DateTimeStyles.None, out _))
  660. {
  661. timeStyle = bx_sdk_dual.E_TimeStyle.eHH_MM_SS_CHS;
  662. return true;
  663. }
  664. if (DateTime.TryParseExact(text, "HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out _))
  665. {
  666. timeStyle = bx_sdk_dual.E_TimeStyle.eHH_MM_COLON;
  667. return true;
  668. }
  669. if (DateTime.TryParseExact(text, "HH时mm分", CultureInfo.InvariantCulture, DateTimeStyles.None, out _))
  670. {
  671. timeStyle = bx_sdk_dual.E_TimeStyle.eHH_MM_CHS;
  672. return true;
  673. }
  674. if (DateTime.TryParseExact(text, "yy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out _))
  675. {
  676. dateStyle = bx_sdk_dual.E_DateStyle.eYYYY_MM_DD_MINUS;
  677. return true;
  678. }
  679. if (DateTime.TryParseExact(text, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out _))
  680. {
  681. dateStyle = bx_sdk_dual.E_DateStyle.eYYYY_MM_DD_MINUS;
  682. return true;
  683. }
  684. if (DateTime.TryParseExact(text, "yyyy年MM月dd日", CultureInfo.InvariantCulture, DateTimeStyles.None, out _))
  685. {
  686. dateStyle = bx_sdk_dual.E_DateStyle.eYYYY_MM_DD_CHS;
  687. return true;
  688. }
  689. if (DateTime.TryParseExact(text, "yyyy年MM月dd日HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out _))
  690. {
  691. dateStyle = bx_sdk_dual.E_DateStyle.eYYYY_MM_DD_CHS;
  692. timeStyle = bx_sdk_dual.E_TimeStyle.eHH_MM_SS_COLON;
  693. return true;
  694. }
  695. if (DateTime.TryParseExact(text, "yyyy年MM月dd日 HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out _))
  696. {
  697. dateStyle = bx_sdk_dual.E_DateStyle.eYYYY_MM_DD_CHS;
  698. timeStyle = bx_sdk_dual.E_TimeStyle.eHH_MM_SS_COLON;
  699. return true;
  700. }
  701. return false;
  702. }
  703. private static string ReadValue(string key)
  704. {
  705. var builder = new StringBuilder(500);
  706. GetPrivateProfileString("DotScreen", key, "", builder, 500, configFile);
  707. return builder.ToString();
  708. }
  709. [DllImport("kernel32")]
  710. private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
  711. [DllImport("kernel32")]
  712. private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
  713. }
  714. }