util.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "util.h"
  2. namespace util {
  3. std::string getUAHash(std::string execPath) {
  4. auto path = std::filesystem::path(execPath).parent_path() / "pkg_version";
  5. std::ifstream infile(path);
  6. std::string line;
  7. std::regex str_expr = std::regex("UserAssembly.dll.*\"([0-9a-f]{32})\"");
  8. auto match = std::smatch();
  9. while (std::getline(infile, line)) {
  10. std::regex_search(line, match, str_expr);
  11. if (match.size() == 2) {
  12. return match[1].str();
  13. break;
  14. }
  15. }
  16. }
  17. std::vector<std::string> split(const std::string& content, const std::string& delimiter) {
  18. std::vector<std::string> tokens;
  19. size_t pos = 0;
  20. size_t prevPos = 0;
  21. std::string token;
  22. while ((pos = content.find(delimiter, prevPos)) != std::string::npos) {
  23. token = content.substr(prevPos, pos - prevPos);
  24. tokens.push_back(token);
  25. prevPos = pos + delimiter.length();
  26. }
  27. tokens.push_back(content.substr(prevPos));
  28. return tokens;
  29. }
  30. int64_t GetCurrentTimeMillisec() {
  31. return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
  32. }
  33. std::string FirstCharToLowercase(std::string string) {
  34. std::string output = string;
  35. output[0] = std::tolower(output[0]);
  36. return output;
  37. }
  38. std::string ConvertToWords(const std::string& input) { // convert strings with format "SomeString" to "Some string"
  39. std::string result;
  40. for (size_t i = 0; i < input.length(); ++i) {
  41. if (i > 0 && isupper(input[i]))
  42. result += ' ';
  43. result += tolower(input[i]);
  44. }
  45. result[0] = toupper(result[0]);
  46. return result;
  47. }
  48. }