|
29 | 29 | #define AUTOSUBMIT_TOAST_TAG "autosubmit" |
30 | 30 | #define COOP_NAME_MESSAGE_TYPE "coop-name" |
31 | 31 | #define API_KEY_FILE "autosubmit.key" |
| 32 | +#define OLD_API_KEY_FILE "autosubmit_key.txt" |
32 | 33 |
|
33 | 34 | bool AutoSubmit::g_cheated = false; |
34 | 35 | std::string AutoSubmit::g_partner_name = ""; |
@@ -410,7 +411,50 @@ static void submitTime(int score, std::string demopath, bool coop, std::string m |
410 | 411 | } |
411 | 412 | } |
412 | 413 |
|
| 414 | +static void convertOldApiKeys() { |
| 415 | + auto old_filepath = fileSystem->FindFileSomewhere(OLD_API_KEY_FILE); |
| 416 | + if (!old_filepath.has_value()) |
| 417 | + return; |
| 418 | + |
| 419 | + /* read key from old file */ |
| 420 | + std::string key; |
| 421 | + { |
| 422 | + std::ifstream f(old_filepath.value()); |
| 423 | + std::stringstream buf; |
| 424 | + buf << f.rdbuf(); |
| 425 | + key = buf.str(); |
| 426 | + } |
| 427 | + |
| 428 | + key.erase(std::remove_if(key.begin(), key.end(), isspace), key.end()); |
| 429 | + |
| 430 | + std::ofstream f; |
| 431 | + |
| 432 | + /* check if user has a key with new format already, if yes, append to end, if not, create new file */ |
| 433 | + auto new_filepath = fileSystem->FindFileSomewhere(API_KEY_FILE); |
| 434 | + if (!new_filepath.has_value()) { |
| 435 | + /* create new file path */ |
| 436 | + auto path = old_filepath.value(); |
| 437 | + path = path.substr(0, path.length() - strlen(OLD_API_KEY_FILE)); |
| 438 | + |
| 439 | + f.open(path + API_KEY_FILE); |
| 440 | + } else |
| 441 | + f.open(new_filepath.value(), std::ios::app); // open in append mode |
| 442 | + |
| 443 | + /* file should have newline at end! */ |
| 444 | + f << "board.portal2.sr" << std::endl; |
| 445 | + f << key << std::endl; |
| 446 | + |
| 447 | + f.close(); |
| 448 | + |
| 449 | + /* remove old api key file */ |
| 450 | + std::filesystem::remove(old_filepath.value()); |
| 451 | + |
| 452 | + console->Print("Successfully converted API key file!\n"); |
| 453 | +} |
| 454 | + |
413 | 455 | void AutoSubmit::LoadApiKey(bool output_nonexist) { |
| 456 | + convertOldApiKeys(); |
| 457 | + |
414 | 458 | auto filepath = fileSystem->FindFileSomewhere(API_KEY_FILE); |
415 | 459 | if (!filepath.has_value()) { |
416 | 460 | if (output_nonexist) { |
|
0 commit comments