KeyMacro.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using System;
  2. using System.IO;
  3. using NTERA.EmuEra.Game.EraEmu.Sub;
  4. namespace NTERA.EmuEra.Game.EraEmu.Config
  5. {
  6. internal static class KeyMacro
  7. {
  8. static readonly string macroPath = Program.ExeDir + "macro.txt";
  9. public const string gID = "グループ";
  10. public const int MaxGroup = 10;
  11. public const int MaxFkey = 12;
  12. public const int MaxMacro = MaxFkey * MaxGroup;
  13. /// <summary>
  14. /// マクロの内容
  15. /// </summary>
  16. static string[] macro = new string[MaxMacro];
  17. /// <summary>
  18. /// マクロキー
  19. /// </summary>
  20. static string[] macroName = new string[MaxMacro];
  21. static string[] groupName = new string[MaxGroup];
  22. static bool isMacroChanged;
  23. static KeyMacro()
  24. {
  25. for (int g = 0; g < MaxGroup; g++)
  26. {
  27. groupName[g] = "マクログループ" + g + "に設定";
  28. for (int f = 0; f < MaxFkey; f++)
  29. {
  30. int i = f + g * MaxFkey;
  31. macro[i] = "";
  32. if (g == 0)
  33. macroName[i] = "マクロキーF" + (f + 1) + ":";
  34. else
  35. macroName[i] = "G" + g + ":マクロキーF" + (f + 1) + ":";
  36. }
  37. }
  38. }
  39. public static bool SaveMacro()
  40. {
  41. if (!isMacroChanged)
  42. return true;
  43. StreamWriter writer = null;
  44. try
  45. {
  46. writer = new StreamWriter(macroPath, false, Config.Encode);
  47. for (int g = 0; g < MaxGroup; g++)
  48. {
  49. writer.WriteLine(gID + g + ":" + groupName[g]);
  50. }
  51. for (int i = 0; i < MaxMacro; i++)
  52. {
  53. writer.WriteLine(macroName[i] + macro[i]);
  54. }
  55. }
  56. catch (Exception)
  57. {
  58. return false;
  59. }
  60. finally
  61. {
  62. if (writer != null)
  63. writer.Close();
  64. }
  65. return true;
  66. }
  67. public static void LoadMacroFile(string filename)
  68. {
  69. EraStreamReader eReader = new EraStreamReader(false);
  70. if (!eReader.Open(filename))
  71. return;
  72. try
  73. {
  74. string line = null;
  75. while ((line = eReader.ReadLine()) != null)
  76. {
  77. if ((line.Length == 0) || (line[0] == ';'))
  78. continue;
  79. if (line.StartsWith(gID))
  80. {
  81. if (line.Length < gID.Length + 4)
  82. continue;
  83. int num = line[gID.Length] - '0';
  84. if (num < 0 || num > 9)
  85. continue;
  86. if (line[gID.Length + 1] != ':')
  87. continue;
  88. groupName[num] = line.Substring(gID.Length + 2);
  89. }
  90. for (int i = 0; i < MaxMacro; i++)
  91. {
  92. if (line.StartsWith(macroName[i]))
  93. {
  94. macro[i] = line.Substring(macroName[i].Length);
  95. break;
  96. }
  97. }
  98. }
  99. }
  100. catch {
  101. }
  102. finally { eReader.Dispose(); }
  103. }
  104. public static void SetMacro(int FkeyNum, int groupNum, string macroStr)
  105. {
  106. isMacroChanged = true;
  107. macro[FkeyNum + groupNum * MaxFkey] = macroStr;
  108. }
  109. public static string GetMacro(int FkeyNum, int groupNum)
  110. {
  111. return macro[FkeyNum + groupNum * MaxFkey];
  112. }
  113. public static string GetGroupName(int groupNum)
  114. {
  115. return groupName[groupNum];
  116. }
  117. }
  118. }