SHARE
TWEET

Untitled

Baoulettes Jun 30th, 2020 1,037 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void CheckNewSQL() {
  2.     using namespace std::string_view_literals;
  3.     using json = nlohmann::json;
  4.     bool Need_to_update =   true;
  5.     int Local_version = 0;
  6.     std::string Local_file = "no_name";
  7.     int Network_version = 0;
  8.     int BufferIO = 1000000; //Max std::tring lenght before saving in now slot
  9.     std::string Network_file = "0.0.0";
  10.     UD_LOGI("CheckNewSQL : INIT . . .");
  11.     if (!kHookLib->patchData->exists("Translation_fr_version")) {
  12.         UD_LOGI("CheckNewSQL : Translation_fr_version not found so creating");
  13.         kHookLib->patchData->putInt32("Translation_fr_version", 0);
  14.         Need_to_update = true;
  15.     } else {
  16.         UD_LOGI("CheckNewSQL : Translation_fr_version found so loading");
  17.         Local_version = kHookLib->patchData->getInt32("Translation_fr_version", 0);
  18.     }
  19.     auto Check_new_sql = RestClient::get("https://baoulettes.fr/download/Updater.json");
  20.     if (Check_new_sql.code == 200) {
  21.         UD_LOGI("CheckNewSQL : Json Found . . .");
  22.         auto Updater_Json = json::parse(Check_new_sql.body);
  23.         std::string DumpJson    =   Updater_Json.dump();
  24.         UD_LOGI("Updater_Json : %s", DumpJson.c_str());
  25.         Network_version     =   Updater_Json["Updater"]["Version"].get<int>();
  26.         Network_file        =   Updater_Json["Updater"]["File"].get<std::string>();
  27.         kHookLib->patchData->putString("Translation_fr_local_file", Network_file);
  28.         UD_LOGI("CheckNewSQL : Local version %d | Network verison %d ",Local_version,Network_version);
  29.         if (Network_version > Local_version) {
  30.             Need_to_update = true;
  31.             UD_LOGI("CheckNewSQL : Update is required");
  32.         } else {
  33.             Need_to_update = false;
  34.             UD_LOGI("CheckNewSQL : Update is not required");
  35.         }
  36.     } else {
  37.         UD_LOGI("CheckNewSQL : Json Not found . . .");
  38.         Need_to_update = false;
  39.     }
  40.     // Need_to_update = true; //Debug!
  41.     if (Need_to_update == true) {
  42.         std::string file_fetch = "https://baoulettes.fr/download/"+Network_file+".sql";
  43.         auto update_sql = RestClient::get(file_fetch);
  44.         if (update_sql.code == 200) {
  45.             auto link_url_not_found = "https://baoulettes.fr/download/"+Network_file+".sql is found";
  46.             UD_LOGI(link_url_not_found.c_str());
  47.             std::string s = update_sql.body;
  48.             int count = 0;
  49.             UD_LOGI("size     : [%d]", s.size());
  50.             UD_LOGI("length   : [%d]", s.length());
  51.             UD_LOGI("capacity : [%d]", s.capacity());
  52.             UD_LOGI("max_size : [%d]", s.max_size());
  53.             int substrIO = BufferIO;
  54.             for (unsigned i = 0; i < s.length();) {
  55.                 std::string To_Save;
  56.                 if (i > s.length()) {
  57.                     substrIO = s.length();
  58.                 } else {
  59.                     substrIO = BufferIO;
  60.                 }
  61.                 To_Save = s.substr(i, substrIO);   
  62.                 UD_LOGI("Step(s)  : [%d]", count);
  63.                 UD_LOGI("BufferIO : [%d]", BufferIO);
  64.                 UD_LOGI("substrIO : [%d]", substrIO);
  65.                 kHookLib->patchData->putString("Translation_fr_sql_v"+std::to_string(Network_version)+"_"+std::to_string(count), To_Save);
  66.                 count++;
  67.                 i = i + BufferIO;
  68.             }
  69.             UD_LOGI("Trying : kHookLib->patchData->putInt32(\"Translation_fr_version\", Network_version");
  70.             kHookLib->patchData->putInt32("Translation_fr_version", Network_version);
  71.         } else {
  72.             UD_LOGI("file_fetch not found : %s",file_fetch.c_str());
  73.         }
  74.     }
  75.     std::string Translation_fr_sql;
  76.     Local_file  =   kHookLib->patchData->getString("Translation_fr_local_file", "");
  77.     Local_version = kHookLib->patchData->getInt32("Translation_fr_version", 0);
  78.     int count_load = 0;
  79.     int substrIO_load = BufferIO;
  80.     for (unsigned i = 0; i < 10;) {
  81.         UD_LOGI("Load step: [%d]", count_load);
  82.         if (!kHookLib->patchData->exists("Translation_fr_sql_v"+std::to_string(Local_version)+"_"+std::to_string(count_load))) {
  83.             UD_LOGI("Save not found : Translation_fr_sql_v%d_%d",Local_version,count_load);
  84.             break;
  85.         } else {
  86.             UD_LOGI("Save found : Translation_fr_sql_v%d_%d",Local_version,count_load);
  87.             Translation_fr_sql.append(kHookLib->patchData->getString("Translation_fr_sql_v"+Local_file+"_"+std::to_string(count_load), ""));
  88.         }
  89.         count_load++;
  90.         i++;
  91.     }
  92.     // UD_LOGI("Inserting Translation_fr_sql : %s",Translation_fr_sql.c_str());
  93.     UD_LOGI("Inserting Translation_fr_sql_v%d",Local_version);
  94.     UniDokkan::Database::exec(Translation_fr_sql.c_str());
  95.     UD_LOGI("inserted Translation_fr_sql_v%d",Local_version);
  96. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top