PageRenderTime 62ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/GearFoundry/Initializers/FilesAndSettings.cs

https://github.com/AlincoRecoders/GearFoundry
C# | 665 lines | 569 code | 47 blank | 49 comment | 10 complexity | baf2da1020ac172f238399d6ef7c70ca MD5 | raw file
  1. using System;
  2. using System.Text;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Diagnostics;
  7. using System.Linq;
  8. using Decal.Adapter;
  9. using System.IO;
  10. using System.Xml.Serialization;
  11. using Microsoft.Win32;
  12. using Decal.Filters;
  13. using Decal.Interop;
  14. using System.Runtime.InteropServices;
  15. using Decal.Adapter.Wrappers;
  16. using System.Drawing;
  17. using System.Xml;
  18. using System.Xml.Linq;
  19. using System.ComponentModel;
  20. using VirindiViewService;
  21. using System.Windows.Forms;
  22. using ProtoBuf;
  23. namespace GearFoundry
  24. {
  25. public partial class PluginCore
  26. {
  27. private MasterSettings mMasterSettings = new MasterSettings();
  28. private AccountSettings mAccountSettings = new AccountSettings();
  29. private CharacterSettings mCharacterSettings = new CharacterSettings();
  30. private void SaveMasterSettingsFile()
  31. {
  32. try
  33. {
  34. if(File.Exists(GearFiles.MasterSettingsFilename))
  35. {
  36. File.Copy(GearFiles.MasterSettingsFilename, GearFiles.BackupMasterSettingsFilename);
  37. }
  38. using (FileStream file = File.Create(GearFiles.MasterSettingsFilename))
  39. {
  40. Serializer.Serialize(file, mMasterSettings);
  41. }
  42. }catch(Exception ex){LogError(ex);}
  43. }
  44. private void SaveAccountSettingsFile()
  45. {
  46. try
  47. {
  48. if(File.Exists(GearFiles.AccountSettingsFilename))
  49. {
  50. File.Copy(GearFiles.AccountSettingsFilename, GearFiles.BackupAccountSettingsFilename);
  51. }
  52. using (FileStream file = File.Create(GearFiles.AccountSettingsFilename))
  53. {
  54. Serializer.Serialize(file, mAccountSettings);
  55. }
  56. }catch(Exception ex){LogError(ex);}
  57. }
  58. private void ReadMasterSettingsFile()
  59. {
  60. try
  61. {
  62. if(File.Exists(GearFiles.MasterSettingsFilename))
  63. {
  64. using (FileStream file = File.OpenRead(GearFiles.MasterSettingsFilename))
  65. {
  66. mMasterSettings = Serializer.Deserialize<MasterSettings>(file);
  67. }
  68. }
  69. else if(File.Exists(GearFiles.BackupMasterSettingsFilename))
  70. {
  71. using (FileStream file = File.OpenRead(GearFiles.BackupMasterSettingsFilename))
  72. {
  73. mMasterSettings = Serializer.Deserialize<MasterSettings>(file);
  74. }
  75. }
  76. else
  77. {
  78. mMasterSettings = new MasterSettings();
  79. BuildCollectionTaskList();
  80. BuildKillTaskList();
  81. SaveMasterSettingsFile();
  82. }
  83. }
  84. catch
  85. {
  86. if(File.Exists(GearFiles.BackupMasterSettingsFilename))
  87. {
  88. using (FileStream file = File.OpenRead(GearFiles.BackupMasterSettingsFilename))
  89. {
  90. mMasterSettings = Serializer.Deserialize<MasterSettings>(file);
  91. }
  92. }
  93. else
  94. {
  95. mMasterSettings = new MasterSettings();
  96. BuildCollectionTaskList();
  97. BuildKillTaskList();
  98. SaveMasterSettingsFile();
  99. }
  100. }
  101. }
  102. private void ReadAccountSettingsFile()
  103. {
  104. try
  105. {
  106. if(File.Exists(GearFiles.AccountSettingsFilename))
  107. {
  108. using (FileStream file = File.OpenRead(GearFiles.AccountSettingsFilename))
  109. {
  110. mAccountSettings = Serializer.Deserialize<AccountSettings>(file);
  111. }
  112. }
  113. else if(File.Exists(GearFiles.BackupAccountSettingsFilename))
  114. {
  115. using (FileStream file = File.OpenRead(GearFiles.BackupAccountSettingsFilename))
  116. {
  117. mAccountSettings = Serializer.Deserialize<AccountSettings>(file);
  118. }
  119. }
  120. else
  121. {
  122. mAccountSettings = new AccountSettings();
  123. SaveAccountSettingsFile();
  124. }
  125. }
  126. catch
  127. {
  128. if(File.Exists(GearFiles.BackupAccountSettingsFilename))
  129. {
  130. using (FileStream file = File.OpenRead(GearFiles.BackupAccountSettingsFilename))
  131. {
  132. mAccountSettings = Serializer.Deserialize<AccountSettings>(file);
  133. }
  134. }
  135. else
  136. {
  137. mAccountSettings = new AccountSettings();
  138. SaveAccountSettingsFile();
  139. }
  140. }
  141. }
  142. [ProtoContract]
  143. public class MasterSettings
  144. {
  145. [ProtoMember(1)]
  146. public GearWindowSettings GearWindowSettings = new GearWindowSettings();
  147. [ProtoMember(2)]
  148. public FoundrySettings FoundrySettings = new FoundrySettings();
  149. [ProtoMember(3)]
  150. public RemoteGearSettings RemoteGearSettings = new RemoteGearSettings();
  151. [ProtoMember(4)]
  152. public GearTacticianSettings GearTacticianSettings = new GearTacticianSettings();
  153. [ProtoMember(5)]
  154. public SoundSettings SoundSettings = new SoundSettings();
  155. [ProtoMember(6)]
  156. public GearVisectionSettings GearVisectionSettings = new GearVisectionSettings();
  157. [ProtoMember(7)]
  158. public GearInspectorSettings GearInspectorSettings = new GearInspectorSettings();
  159. [ProtoMember(8)]
  160. public GearSenseSettings GearSenseSettings = new GearSenseSettings();
  161. [ProtoMember(10)]
  162. public GearTaskerSettings GearTaskerSettings = new GearTaskerSettings();
  163. //Character Specific Settings Lists
  164. }
  165. [ProtoContract]
  166. public class AccountSettings
  167. {
  168. [ProtoMember(30)]
  169. public HashSet<CharacterSettings> CharacterSettingsHash = new HashSet<CharacterSettings>();
  170. }
  171. [ProtoContract]
  172. public class CharacterSettings //Points inside mMasterSettings
  173. {
  174. [ProtoMember(50)]
  175. public string CharacterKey = String.Empty;
  176. [ProtoMember(51)]
  177. public SpellComponentsToFill CharacterSpellComponents = new SpellComponentsToFill();
  178. [ProtoMember(52)]
  179. public HashSet<TaskStatus> KillTaskStatus = new HashSet<TaskStatus>();
  180. [ProtoMember(53)]
  181. public HashSet<TaskStatus> CollectTaskStatus = new HashSet<TaskStatus>();
  182. [ProtoMember(54)]
  183. public List<ValetSuit> ValetSuitList = new List<ValetSuit>();
  184. [ProtoMember(55)]
  185. public List<int> ValetSlotsList = new List<int>();
  186. [ProtoMember(56)]
  187. public PortalGearSettings PortalGearSettings = new PortalGearSettings();
  188. [ProtoMember(57)]
  189. public List<QuickSlots> vQuickSlotsSettings = new List<QuickSlots>();
  190. [ProtoMember(58)]
  191. public List<QuickSlots> hQuickSlotsSettings = new List<QuickSlots>();
  192. }
  193. [ProtoContract]
  194. public class GearWindowSettings
  195. {
  196. [ProtoMember(100)]
  197. public int ButlerHudWidth = 300;
  198. [ProtoMember(101)]
  199. public int ButlerHudHeight = 500;
  200. [ProtoMember(102)]
  201. public int TaskHudHeight = 125;
  202. [ProtoMember(103)]
  203. public int TaskHudWidth = 300;
  204. }
  205. [ProtoContract]
  206. public class FoundrySettings
  207. {
  208. [ProtoMember(200)]
  209. public bool FoundyEnabled = true;
  210. [ProtoMember(201)]
  211. public bool AutoStack = true;
  212. [ProtoMember(202)]
  213. public bool AutoCram = true;
  214. [ProtoMember(203)]
  215. public bool AutoMoveToPack = true;
  216. [ProtoMember(204)]
  217. public bool AutoReadScrolls = true;
  218. [ProtoMember(205)]
  219. public bool AutoDessicateJunkLootAetheria = true;
  220. [ProtoMember(206)]
  221. public bool AutoRevealAetheria = true;
  222. [ProtoMember(207)]
  223. public bool AutoDrainMana = true;
  224. [ProtoMember(208)]
  225. public bool AutoCraftCombine = true;
  226. [ProtoMember(209)]
  227. public bool AutoCraftCarve = true;
  228. [ProtoMember(210)]
  229. public bool AutoRingKeys = true;
  230. [ProtoMember(211)]
  231. public bool AutoSalvage = true;
  232. [ProtoMember(212)]
  233. public bool AutoSalvageCombine = true;
  234. [ProtoMember(213)]
  235. public List<string> CraftingCombineList = new List<string>();
  236. [ProtoMember(214)]
  237. public List<string> CraftingCarveList = new List<string>();
  238. [ProtoMember(215)]
  239. public List<KeyRingMatch> KeyRingMatchList = new List<KeyRingMatch>();
  240. [ProtoMember(216)]
  241. public List<ChestKeyMatch> ChestKeyMatchList = new List<ChestKeyMatch>();
  242. }
  243. [ProtoContract]
  244. public class KeyRingMatch
  245. {
  246. [ProtoMember(220)]
  247. public string KeyName = String.Empty;
  248. [ProtoMember(221)]
  249. public string RingName = String.Empty;
  250. }
  251. [ProtoContract]
  252. public class ChestKeyMatch
  253. {
  254. [ProtoMember(230)]
  255. public string ChestName = String.Empty;
  256. [ProtoMember(231)]
  257. public List<string> KeyNames = new List<string>();
  258. }
  259. [ProtoContract]
  260. public class SoundSettings
  261. {
  262. [ProtoMember(250)]
  263. public bool MuteSounds = false;
  264. [ProtoMember(251)]
  265. public int LandscapeTrophies = 0;
  266. [ProtoMember(252)]
  267. public int LandscapeMobs = 0;
  268. [ProtoMember(253)]
  269. public int LandscapePlayers = 0;
  270. [ProtoMember(254)]
  271. public int CorpseRare = 0;
  272. [ProtoMember(255)]
  273. public int CorpseSelfKill = 0;
  274. [ProtoMember(256)]
  275. public int CorpseFellowKill = 0;
  276. [ProtoMember(257)]
  277. public int DeadMe = 0;
  278. [ProtoMember(258)]
  279. public int DeadPermitted = 0;
  280. [ProtoMember(259)]
  281. public int CorpseTrophy = 0;
  282. [ProtoMember(260)]
  283. public int CorpseRule = 0;
  284. [ProtoMember(261)]
  285. public int CorpseSalvage = 0;
  286. }
  287. [ProtoContract]
  288. public class RemoteGearSettings
  289. {
  290. [ProtoMember(300)]
  291. public bool GearTacticianRendered = false;
  292. [ProtoMember(301)]
  293. public bool GearSenseRendered = false;
  294. [ProtoMember(302)]
  295. public bool GearVisectionRendered = false;
  296. [ProtoMember(303)]
  297. public bool GearTaskerRendered = false;
  298. [ProtoMember(304)]
  299. public bool GearButlerRendered = false;
  300. [ProtoMember(305)]
  301. public bool GearInspectorRendered = false;
  302. [ProtoMember(306)]
  303. public bool GearPortalRendered = false;
  304. [ProtoMember(307)]
  305. public bool hSwitchGearEnabled = false;
  306. [ProtoMember(308)]
  307. public bool vSwitchGearEnabled = false;
  308. [ProtoMember(309)]
  309. public bool GearInventoryRendered = false;
  310. [ProtoMember(310)]
  311. public bool GearArmorRendered = false;
  312. [ProtoMember(311)]
  313. public bool WormGearRendered = false;
  314. }
  315. [ProtoContract]
  316. public class GearTacticianSettings
  317. {
  318. [ProtoMember(330)]
  319. public bool bCombatHudTrackLifeDebuffs = true;
  320. [ProtoMember(331)]
  321. public bool bCombatHudTrackCreatureDebuffs = true;
  322. [ProtoMember(332)]
  323. public bool bCombatHudTrackItemDebuffs = true;
  324. [ProtoMember(333)]
  325. public bool bCombatHudTrackVoidDebuffs = true;
  326. [ProtoMember(334)]
  327. public bool bShowAll = false;
  328. [ProtoMember(335)]
  329. public int CombatHudWidth = 305;
  330. [ProtoMember(336)]
  331. public int CombatHudHeight = 220;
  332. [ProtoMember(337)]
  333. public bool RenderCurrentTargetDebuffView = false;
  334. }
  335. [ProtoContract]
  336. public class GearVisectionSettings
  337. {
  338. [ProtoMember(350)]
  339. public bool bAllCorpses = true;
  340. [ProtoMember(351)]
  341. public bool bKillsBySelf = true;
  342. [ProtoMember(352)]
  343. public bool bKillsByFellows = true;
  344. [ProtoMember(353)]
  345. public bool bDeadMes = true;
  346. [ProtoMember(354)]
  347. public bool Permitteds = true;
  348. [ProtoMember(355)]
  349. public bool RenderMini = false;
  350. [ProtoMember(356)]
  351. public List<MyCorpses> DeadMeList = new List<PluginCore.MyCorpses>();
  352. [ProtoMember(357)]
  353. public int CorpseHudWidth = 300;
  354. [ProtoMember(358)]
  355. public int CorpseHudHeight = 220;
  356. }
  357. [ProtoContract]
  358. public class MyCorpses
  359. {
  360. [ProtoMember(375)]
  361. public int GUID;
  362. [ProtoMember(376)]
  363. public string Name;
  364. [ProtoMember(377)]
  365. public string Coordinates;
  366. [ProtoMember(378)]
  367. public int IconID;
  368. }
  369. [ProtoContract]
  370. public class GearInspectorSettings
  371. {
  372. [ProtoMember(400)]
  373. public bool IdentifySalvage = true;
  374. [ProtoMember(401)]
  375. public bool CheckForL7Scrolls = false;
  376. [ProtoMember(402)]
  377. public bool SalvageHighValue = false;
  378. [ProtoMember(403)]
  379. public bool RenderMini = false;
  380. [ProtoMember(404)]
  381. public bool GSStrings = true;
  382. [ProtoMember(405)]
  383. public bool AlincoStrings = true;
  384. [ProtoMember(406)]
  385. public int ItemHudWidth = 300;
  386. [ProtoMember(407)]
  387. public int ItemHudHeight = 220;
  388. [ProtoMember(408)]
  389. public int LootByValue = 0;
  390. [ProtoMember(409)]
  391. public int LootByMana = 0;
  392. }
  393. [ProtoContract]
  394. public class GearSenseSettings
  395. {
  396. [ProtoMember(425)]
  397. public bool bShowAllMobs = true;
  398. [ProtoMember(426)]
  399. public bool bShowSelectedMobs = true;
  400. [ProtoMember(427)]
  401. public bool bShowAllPlayers = true;
  402. [ProtoMember(428)]
  403. public bool bShowAllegancePlayers = true;
  404. [ProtoMember(429)]
  405. public bool bShowFellowPlayers = true;
  406. [ProtoMember(430)]
  407. public bool bShowTrophies = true;
  408. [ProtoMember(431)]
  409. public bool bShowLifeStones = true;
  410. [ProtoMember(432)]
  411. public bool bShowAllPortals = true;
  412. [ProtoMember(433)]
  413. public bool bShowAllNPCs = true;
  414. [ProtoMember(434)]
  415. public bool bRenderMini = false;
  416. [ProtoMember(435)]
  417. public int LandscapeForgetDistance = 100;
  418. [ProtoMember(436)]
  419. public int LandscapeHudWidth = 300;
  420. [ProtoMember(437)]
  421. public int LandscapeHudHeight = 220;
  422. }
  423. [ProtoContract]
  424. public class GearTaskerSettings
  425. {
  426. [ProtoMember(450)]
  427. public int HudWidth = 300;
  428. [ProtoMember(451)]
  429. public int HudHeight = 125;
  430. [ProtoMember(452)]
  431. public bool RenderMini = false;
  432. [ProtoMember(453)]
  433. public bool SquelchTaskReporting = false;
  434. [ProtoMember(454)]
  435. public HashSet<KillTask> MasterKillTaskList = new HashSet<KillTask>();
  436. [ProtoMember(455)]
  437. public HashSet<CollectTask> MasterCollectTaskList = new HashSet<CollectTask>();
  438. }
  439. [ProtoContract]
  440. public class KillTask
  441. {
  442. [ProtoMember(475)]
  443. public int KillTaskId = -1;
  444. [ProtoMember(476)]
  445. public string TaskName = String.Empty;
  446. [ProtoMember(477)]
  447. public List<string> MobNames = new List<string>();
  448. [ProtoMember(478)]
  449. public List<string> NPCNames = new List<string>();
  450. [ProtoMember(479)]
  451. public string NPCInfo = String.Empty;
  452. [ProtoMember(480)]
  453. public string NPCCoords = String.Empty;
  454. [ProtoMember(481)]
  455. public string NPCYellowFlagText = String.Empty;
  456. [ProtoMember(482)]
  457. public string NPCYellowCompleteText = String.Empty;
  458. [ProtoMember(583)]
  459. public int CompleteCount = 0;
  460. }
  461. [ProtoContract]
  462. public class CollectTask
  463. {
  464. [ProtoMember(500)]
  465. public int CollectTaskId = -1;
  466. [ProtoMember(501)]
  467. public string TaskName = String.Empty;
  468. [ProtoMember(502)]
  469. public string Item = String.Empty;
  470. [ProtoMember(503)]
  471. public List<string> MobNames = new List<string>();
  472. [ProtoMember(504)]
  473. public List<string> NPCNames = new List<string>();
  474. [ProtoMember(505)]
  475. public string NPCInfo = String.Empty;
  476. [ProtoMember(506)]
  477. public string NPCCoords = String.Empty;
  478. [ProtoMember(507)]
  479. public string NPCYellowFlagText = String.Empty;
  480. [ProtoMember(508)]
  481. public string NPCYellowCompleteText = String.Empty;
  482. [ProtoMember(509)]
  483. public int CompleteCount = 0;
  484. }
  485. [ProtoContract]
  486. public class SpellComponentsToFill
  487. {
  488. [ProtoMember(1000)]
  489. public int ManaScarabs = 0;
  490. [ProtoMember(1001)]
  491. public int PlatinumScarabs = 0;
  492. [ProtoMember(1002)]
  493. public int PyrealScarabs = 0;
  494. [ProtoMember(1003)]
  495. public int GoldScarabs = 0;
  496. [ProtoMember(1004)]
  497. public int SilverScarabs = 0;
  498. [ProtoMember(1005)]
  499. public int CopperScarabs = 0;
  500. [ProtoMember(1006)]
  501. public int IronScarabs = 0;
  502. [ProtoMember(1007)]
  503. public int LeadScarabs = 0;
  504. [ProtoMember(1008)]
  505. public int PrismaticTapers= 0;
  506. }
  507. [ProtoContract]
  508. public class ValetSuit
  509. {
  510. [ProtoMember(1030)]
  511. public int TicketStub = 0;
  512. [ProtoMember(1031)]
  513. public string SuitName = String.Empty;
  514. [ProtoMember(1032)]
  515. public int Icon = 0;
  516. [ProtoMember(1033)]
  517. public List<ValetTicket> SuitPieces = new List<ValetTicket>();
  518. [ProtoMember(1034)]
  519. public List<int> ClearSlotList = new List<int>();
  520. }
  521. [ProtoContract]
  522. public class ValetTicket
  523. {
  524. [ProtoMember(1040)]
  525. public int ItemId = 0;
  526. [ProtoMember(1041)]
  527. public int SlotId = 0;
  528. [ProtoMember(1042)]
  529. public int Priority = 1;
  530. }
  531. [ProtoContract]
  532. public class TaskStatus
  533. {
  534. [ProtoMember(1050)]
  535. public int TaskId = -1;
  536. [ProtoMember(1051)]
  537. public int CurrentCount = 0;
  538. [ProtoMember(1052)]
  539. public bool track = false;
  540. [ProtoMember(1053)]
  541. public bool detect = false;
  542. [ProtoMember(1054)]
  543. public bool active = false;
  544. [ProtoMember(1055)]
  545. public bool complete = false;
  546. }
  547. [ProtoContract]
  548. public class PortalGearSettings
  549. {
  550. [ProtoMember(1075)]
  551. public int nOrbGuid = 0;
  552. [ProtoMember(1076)]
  553. public int nOrbIcon = 0x2A38;
  554. [ProtoMember(1077)]
  555. public int nFacilityHubGemID = 0;
  556. }
  557. [ProtoContract]
  558. public class QuickSlots
  559. {
  560. [ProtoMember(1080)]
  561. public int ItemId = 0;
  562. [ProtoMember(1081)]
  563. public int ItemIcon = 0;
  564. [ProtoMember(1082)]
  565. public int IconOverlay = 0;
  566. [ProtoMember(1083)]
  567. public int IconUnderlay = 0;
  568. }
  569. //[ProtoContract]
  570. //public class QuickSlots
  571. //{
  572. // [ProtoMember(1080)]
  573. // public string Name;
  574. // [ProtoMember(1081)]
  575. // public int ItemId = 0;
  576. // [ProtoMember(1082)]
  577. // public string objClass;
  578. // [ProtoMember(1083)]
  579. // public int ImbueId;
  580. // [ProtoMember(1084)]
  581. // public int ItemIcon = 0;
  582. // [ProtoMember(1085)]
  583. // public int IconOverlay = 0;
  584. // [ProtoMember(1086)]
  585. // public int IconUnderlay = 0;
  586. //}
  587. // public static void StartService(string serviceName, int timeoutMilliseconds)
  588. // {
  589. // ServiceController service = new ServiceController(serviceName);
  590. // try
  591. // {
  592. // TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);
  593. //
  594. // service.Start();
  595. // service.WaitForStatus(ServiceControllerStatus.Running, timeout);
  596. // }
  597. // catch
  598. // {
  599. // // ...
  600. // }
  601. // }
  602. // public static void StopService(string serviceName, int timeoutMilliseconds)
  603. //{
  604. // ServiceController service = new ServiceController(serviceName);
  605. // try
  606. // {
  607. // TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);
  608. //
  609. // service.Stop();
  610. // service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
  611. // }
  612. // catch
  613. // {
  614. // // ...
  615. // }
  616. //}
  617. }
  618. }