CollectInformation.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #include "SerialNumberGenerator.hpp"
  2. #include <ExceptionUser.hpp>
  3. #include <iostream>
  4. #undef NKG_CURRENT_SOURCE_FILE
  5. #undef NKG_CURRENT_SOURCE_LINE
  6. #define NKG_CURRENT_SOURCE_FILE() TEXT(".\\navicat-keygen\\CollectInformation.cpp")
  7. #define NKG_CURRENT_SOURCE_LINE() __LINE__
  8. namespace std {
  9. #if defined(_UNICODE) || defined(UNICODE)
  10. static auto& xcin = wcin;
  11. static auto& xcout = wcout;
  12. static auto& xcerr = wcerr;
  13. #else
  14. static auto& xcin = cin;
  15. static auto& xcout = cout;
  16. static auto& xcerr = cerr;
  17. #endif
  18. }
  19. namespace nkg {
  20. [[nodiscard]]
  21. static int ReadInt(int MinVal, int MaxVal, PCTSTR lpszPrompt, PCTSTR lpszErrorMessage) {
  22. int val;
  23. std::xstring s;
  24. while (true) {
  25. std::xcout << lpszPrompt;
  26. if (!std::getline(std::xcin, s)) {
  27. throw UserAbortionError(NKG_CURRENT_SOURCE_FILE(), NKG_CURRENT_SOURCE_LINE(), TEXT("Abort."));
  28. }
  29. if (s.empty())
  30. continue;
  31. try {
  32. val = std::stoi(s, nullptr, 0);
  33. if (MinVal <= val && val <= MaxVal) {
  34. return val;
  35. } else {
  36. throw std::invalid_argument("");
  37. }
  38. } catch (std::invalid_argument&) {
  39. std::xcout << lpszErrorMessage << std::endl;
  40. }
  41. }
  42. }
  43. [[nodiscard]]
  44. static int ReadInt(int MinVal, int MaxVal, int DefaultVal, PCTSTR lpszPrompt, PCTSTR lpszErrorMessage) {
  45. int val;
  46. std::xstring s;
  47. while (true) {
  48. std::xcout << lpszPrompt;
  49. if (!std::getline(std::xcin, s)) {
  50. throw UserAbortionError(NKG_CURRENT_SOURCE_FILE(), NKG_CURRENT_SOURCE_LINE(), TEXT("Abort."));
  51. }
  52. if (s.empty()) {
  53. return DefaultVal;
  54. }
  55. try {
  56. val = std::stoi(s, nullptr, 0);
  57. if (MinVal <= val && val <= MaxVal) {
  58. return val;
  59. } else {
  60. throw std::invalid_argument("");
  61. }
  62. } catch (std::invalid_argument&) {
  63. std::xcout << lpszErrorMessage << std::endl;
  64. }
  65. }
  66. }
  67. [[nodiscard]]
  68. SerialNumberGenerator CollectInformationNormal() {
  69. SerialNumberGenerator Generator;
  70. std::xcout << TEXT("[*] Select Navicat product:") << std::endl;
  71. std::xcout << TEXT(" 0. DataModeler") << std::endl;
  72. std::xcout << TEXT(" 1. Premium") << std::endl;
  73. std::xcout << TEXT(" 2. MySQL") << std::endl;
  74. std::xcout << TEXT(" 3. PostgreSQL") << std::endl;
  75. std::xcout << TEXT(" 4. Oracle") << std::endl;
  76. std::xcout << TEXT(" 5. SQLServer") << std::endl;
  77. std::xcout << TEXT(" 6. SQLite") << std::endl;
  78. std::xcout << TEXT(" 7. MariaDB") << std::endl;
  79. std::xcout << TEXT(" 8. MongoDB") << std::endl;
  80. std::xcout << TEXT(" 9. ReportViewer") << std::endl;
  81. std::xcout << std::endl;
  82. Generator.SetProductSignature(
  83. static_cast<NavicatProductType>(ReadInt(0, 9, TEXT("(Input index)> "), TEXT("Invalid index.")))
  84. );
  85. std::xcout << std::endl;
  86. std::xcout << TEXT("[*] Select product language:") << std::endl;
  87. std::xcout << TEXT(" 0. English") << std::endl;
  88. std::xcout << TEXT(" 1. Simplified Chinese") << std::endl;
  89. std::xcout << TEXT(" 2. Traditional Chinese") << std::endl;
  90. std::xcout << TEXT(" 3. Japanese") << std::endl;
  91. std::xcout << TEXT(" 4. Polish") << std::endl;
  92. std::xcout << TEXT(" 5. Spanish") << std::endl;
  93. std::xcout << TEXT(" 6. French") << std::endl;
  94. std::xcout << TEXT(" 7. German") << std::endl;
  95. std::xcout << TEXT(" 8. Korean") << std::endl;
  96. std::xcout << TEXT(" 9. Russian") << std::endl;
  97. std::xcout << TEXT(" 10. Portuguese") << std::endl;
  98. std::xcout << std::endl;
  99. Generator.SetLanguageSignature(
  100. static_cast<NavicatLanguage>(ReadInt(0, 10, TEXT("(Input index)> "), TEXT("Invalid index.")))
  101. );
  102. std::xcout << std::endl;
  103. std::xcout << TEXT("[*] Input major version number:") << std::endl;
  104. Generator.SetVersion(
  105. static_cast<BYTE>(ReadInt(0, 15, 12, TEXT("(range: 0 ~ 15, default: 12)> "), TEXT("Invalid number.")))
  106. );
  107. std::xcout << std::endl;
  108. return Generator;
  109. }
  110. [[nodiscard]]
  111. SerialNumberGenerator CollectInformationAdvanced() {
  112. SerialNumberGenerator Generator;
  113. std::xcout << TEXT("[*] Navicat Product Signature:") << std::endl;
  114. Generator.SetProductSignature(
  115. static_cast<BYTE>(ReadInt(0x00, 0xff, TEXT("(range: 0x00 ~ 0xFF)> "), TEXT("Invalid number.")))
  116. );
  117. std::xcout << std::endl;
  118. std::xcout << TEXT("[*] Navicat Language Signature 0:") << std::endl;
  119. auto s1 = static_cast<BYTE>(ReadInt(0x00, 0xff, TEXT("(range: 0x00 ~ 0xFF)> "), TEXT("Invalid number.")));
  120. std::xcout << std::endl;
  121. std::xcout << TEXT("[*] Navicat Language Signature 1:") << std::endl;
  122. auto s2 = static_cast<BYTE>(ReadInt(0x00, 0xff, TEXT("(range: 0x00 ~ 0xFF)> "), TEXT("Invalid number.")));
  123. Generator.SetLanguageSignature(s1, s2);
  124. std::xcout << std::endl;
  125. std::xcout << TEXT("[*] Input major version number:") << std::endl;
  126. Generator.SetVersion(
  127. static_cast<BYTE>(ReadInt(0, 15, 12, TEXT("(range: 0 ~ 15, default: 12)> "), TEXT("Invalid number.")))
  128. );
  129. std::xcout << std::endl;
  130. return Generator;
  131. }
  132. }