Preview2Context.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using PaintDotNet.Base.CommTool;
  2. using System;
  3. using System.IO;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using PaintDotNet.Base.SettingModel;
  9. using System.Drawing;
  10. using System.Windows.Forms;
  11. namespace PaintDotNet.Preview2
  12. {
  13. public static class CommonDefine
  14. {
  15. public static readonly string Preview2Root = Application.StartupPath + @"\Preview2\";
  16. public static readonly string Preview2ConfigFile = Preview2Root + "Preview2Config.xml";
  17. public static readonly string ToolkitPathLeft = Preview2Root + "ToolkitLeft.xml";
  18. public static readonly string ToolkitPathRight = Preview2Root + "ToolkitRight.xml";
  19. public static readonly string ToolkitLibPath = Preview2Root + "ToolkitLib.txt";
  20. public static readonly string ToolkitLibTxt = "1200,1211,700,701,702,704,705,706,707,708,7080,7081,7082,7083,7084,709,7090,7092,7091,7093,710,7100,7101,7102,711,7110,7111,7112,7113,7114,7115,7116,712,7120,7121,7122,7123,7124,7125,715,7150,7151,7152,7153,7154,713,7130,7131,7132,7133,714,7140,7141,7142,7143,7144,7145,7146,716,717,720,721,722,718";
  21. public static Color Blue = Color.FromArgb(0, 174, 219);
  22. public const string DefaultCamCfg = "CameraParam";
  23. }
  24. internal static class Preview2Context
  25. {
  26. internal static int ShandingCorrectionState = 0;
  27. static Preview2Context()
  28. {
  29. if (!Directory.Exists(CommonDefine.Preview2Root))
  30. {
  31. Directory.CreateDirectory(CommonDefine.Preview2Root);
  32. }
  33. }
  34. private static Preview2Config _p2Config;
  35. public static Preview2Config P2Config
  36. {
  37. get
  38. {
  39. if (_p2Config == null)
  40. {
  41. _p2Config = new Preview2Config();
  42. if (System.IO.File.Exists(CommonDefine.Preview2ConfigFile))
  43. _p2Config = XmlSerializeHelper.Load<Preview2Config>(CommonDefine.Preview2ConfigFile);
  44. }
  45. return _p2Config;
  46. }
  47. }
  48. static string[] _toolLibArray;
  49. public static string[] ToolLibArray
  50. {
  51. get
  52. {
  53. if (_toolLibArray == null)
  54. {
  55. if (!System.IO.File.Exists(CommonDefine.ToolkitLibPath))
  56. {
  57. System.IO.File.WriteAllText(CommonDefine.ToolkitLibPath, CommonDefine.ToolkitLibTxt);
  58. }
  59. _toolLibArray = System.IO.File.ReadAllText(CommonDefine.ToolkitLibPath).Split(',');
  60. }
  61. return _toolLibArray;
  62. }
  63. }
  64. static ShortcutbarModel _toolbarModelLeft;
  65. public static ShortcutbarModel ToolbarModelLeft
  66. {
  67. get
  68. {
  69. if (_toolbarModelLeft == null)
  70. {
  71. if (System.IO.File.Exists(CommonDefine.ToolkitPathLeft))
  72. _toolbarModelLeft = XmlSerializeHelper.Load<ShortcutbarModel>(CommonDefine.ToolkitPathLeft);
  73. else
  74. {
  75. _toolbarModelLeft = new ShortcutbarModel();
  76. _toolbarModelLeft.Menus = new List<ShortcutbarModel.Item>();
  77. }
  78. }
  79. return _toolbarModelLeft;
  80. }
  81. }
  82. static ShortcutbarModel _toolbarModelRight;
  83. public static ShortcutbarModel ToolbarModelRight
  84. {
  85. get
  86. {
  87. if (_toolbarModelRight == null)
  88. {
  89. if (System.IO.File.Exists(CommonDefine.ToolkitPathRight))
  90. _toolbarModelRight = XmlSerializeHelper.Load<ShortcutbarModel>(CommonDefine.ToolkitPathRight);
  91. else
  92. {
  93. _toolbarModelRight = new ShortcutbarModel();
  94. _toolbarModelRight.Menus = new List<ShortcutbarModel.Item>();
  95. }
  96. }
  97. return _toolbarModelRight;
  98. }
  99. }
  100. public static void SaveP2Config()
  101. {
  102. XmlSerializeHelper.Save(P2Config, CommonDefine.Preview2ConfigFile);
  103. }
  104. public static void SaveToolkit()
  105. {
  106. XmlSerializeHelper.Save(ToolbarModelLeft, CommonDefine.ToolkitPathLeft);
  107. XmlSerializeHelper.Save(ToolbarModelRight, CommonDefine.ToolkitPathRight);
  108. }
  109. }
  110. }