CollectInformation.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #include <iostream>
  2. #include "navicat_serial_generator.hpp"
  3. #include "exceptions/operation_canceled_exception.hpp"
  4. #define NKG_CURRENT_SOURCE_FILE() u8".\\navicat-keygen\\CollectInformation.cpp"
  5. #define NKG_CURRENT_SOURCE_LINE() __LINE__
  6. namespace nkg {
  7. [[nodiscard]]
  8. static int read_int(int min_val, int max_val, std::string_view prompt, std::string_view error_msg) {
  9. int val;
  10. for (std::string s;;) {
  11. std::cout << prompt;
  12. if (!std::getline(std::cin, s)) {
  13. throw exceptions::operation_canceled_exception(NKG_CURRENT_SOURCE_FILE(), NKG_CURRENT_SOURCE_LINE(), u8"Operation is canceled by user.");
  14. }
  15. if (s.empty())
  16. continue;
  17. try {
  18. val = std::stoi(s, nullptr, 0);
  19. if (min_val <= val && val <= max_val) {
  20. return val;
  21. } else {
  22. throw std::invalid_argument("Out of range.");
  23. }
  24. } catch (std::invalid_argument&) {
  25. std::cout << error_msg << std::endl;
  26. }
  27. }
  28. }
  29. [[nodiscard]]
  30. static int read_int(int min_val, int max_val, int default_val, std::string_view prompt, std::string_view error_msg) {
  31. int val;
  32. for (std::string s;;) {
  33. std::cout << prompt;
  34. if (!std::getline(std::cin, s)) {
  35. throw exceptions::operation_canceled_exception(NKG_CURRENT_SOURCE_FILE(), NKG_CURRENT_SOURCE_LINE(), u8"Operation is canceled by user.");
  36. }
  37. if (s.empty()) {
  38. return default_val;
  39. }
  40. try {
  41. val = std::stoi(s, nullptr, 0);
  42. if (min_val <= val && val <= max_val) {
  43. return val;
  44. } else {
  45. throw std::invalid_argument("Out of range.");
  46. }
  47. } catch (std::invalid_argument&) {
  48. std::cout << error_msg << std::endl;
  49. }
  50. }
  51. }
  52. [[nodiscard]]
  53. navicat_serial_generator CollectInformationNormal() {
  54. navicat_serial_generator sn_generator;
  55. std::cout << "[*] Select Navicat product:" << std::endl;
  56. std::cout << " 0. DataModeler" << std::endl;
  57. std::cout << " 1. Premium" << std::endl;
  58. std::cout << " 2. MySQL" << std::endl;
  59. std::cout << " 3. PostgreSQL" << std::endl;
  60. std::cout << " 4. Oracle" << std::endl;
  61. std::cout << " 5. SQLServer" << std::endl;
  62. std::cout << " 6. SQLite" << std::endl;
  63. std::cout << " 7. MariaDB" << std::endl;
  64. std::cout << " 8. MongoDB" << std::endl;
  65. std::cout << " 9. ReportViewer" << std::endl;
  66. std::cout << std::endl;
  67. sn_generator.set_software_type(static_cast<navicat_software_type>(read_int(0, 9, "(Input index)> ", "Invalid index.")));
  68. std::cout << std::endl;
  69. std::cout << "[*] Select product language:" << std::endl;
  70. std::cout << " 0. English" << std::endl;
  71. std::cout << " 1. Simplified Chinese" << std::endl;
  72. std::cout << " 2. Traditional Chinese" << std::endl;
  73. std::cout << " 3. Japanese" << std::endl;
  74. std::cout << " 4. Polish" << std::endl;
  75. std::cout << " 5. Spanish" << std::endl;
  76. std::cout << " 6. French" << std::endl;
  77. std::cout << " 7. German" << std::endl;
  78. std::cout << " 8. Korean" << std::endl;
  79. std::cout << " 9. Russian" << std::endl;
  80. std::cout << " 10. Portuguese" << std::endl;
  81. std::cout << std::endl;
  82. sn_generator.set_software_language(static_cast<navicat_software_language>(read_int(0, 10, "(Input index)> ", "Invalid index.")));
  83. std::cout << std::endl;
  84. std::cout << "[*] Input major version number:" << std::endl;
  85. sn_generator.set_software_version(read_int(11, 16, 16, "(range: 11 ~ 16, default: 16)> ", "Invalid number."));
  86. std::cout << std::endl;
  87. return sn_generator;
  88. }
  89. [[nodiscard]]
  90. navicat_serial_generator CollectInformationAdvanced() {
  91. navicat_serial_generator sn_generator;
  92. std::cout << "[*] Navicat Product Signature:" << std::endl;
  93. sn_generator.set_software_type(static_cast<uint8_t>(read_int(0x00, 0xff, "(range: 0x00 ~ 0xFF)> ", "Invalid number.")));
  94. std::cout << std::endl;
  95. std::cout << "[*] Navicat Language Signature 0:" << std::endl;
  96. auto s1 = static_cast<uint8_t>(read_int(0x00, 0xff, "(range: 0x00 ~ 0xFF)> ", "Invalid number."));
  97. std::cout << std::endl;
  98. std::cout << "[*] Navicat Language Signature 1:" << std::endl;
  99. auto s2 = static_cast<uint8_t>(read_int(0x00, 0xff, "(range: 0x00 ~ 0xFF)> ", "Invalid number."));
  100. sn_generator.set_software_language(s1, s2);
  101. std::cout << std::endl;
  102. std::cout << "[*] Input major version number:" << std::endl;
  103. sn_generator.set_software_version(read_int(0, 15, 12, "(range: 0 ~ 15, default: 12)> ", "Invalid number."));
  104. std::cout << std::endl;
  105. return sn_generator;
  106. }
  107. }
  108. #undef NKG_CURRENT_SOURCE_FILE
  109. #undef NKG_CURRENT_SOURCE_LINE