| 39 | }; |
| 40 | |
| 41 | streamfx::ui::about::about() : QDialog(reinterpret_cast<QWidget*>(obs_frontend_get_main_window())) |
| 42 | { |
| 43 | std::deque<ui::about::entry> entries; |
| 44 | |
| 45 | // Set-up UI. |
| 46 | setupUi(this); |
| 47 | setWindowFlag(Qt::WindowContextHelpButtonHint, false); // Remove Help button. |
| 48 | content->setSizePolicy(QSizePolicy::Policy::Minimum, QSizePolicy::Policy::Maximum); |
| 49 | |
| 50 | // Create a uniform |
| 51 | std::random_device rd; |
| 52 | std::mt19937_64 generator(rd()); |
| 53 | std::uniform_int_distribution<uint64_t> rnd; |
| 54 | |
| 55 | // Load entries from 'thanks.json' |
| 56 | try { |
| 57 | auto file = streamfx::data_file_path("thanks.json"); |
| 58 | D_LOG_DEBUG("Attempting to load '%s'...", file.generic_string().c_str()); |
| 59 | if (!std::filesystem::exists(file)) { |
| 60 | // Crash if this file is missing. |
| 61 | throw std::runtime_error("File 'thanks.json' is missing."); |
| 62 | } |
| 63 | |
| 64 | std::ifstream fils{file}; |
| 65 | if (fils.bad() || fils.eof()) { |
| 66 | // Crash if this file is corrupt. |
| 67 | throw std::runtime_error("File 'thanks.json' is corrupted."); |
| 68 | } |
| 69 | |
| 70 | auto data = nlohmann::json::parse(fils); |
| 71 | if (auto iter = data.find("contributor"); iter != data.end()) { |
| 72 | D_LOG_DEBUG(" Found %" PRIu64 " contributor entries.", iter->size()); |
| 73 | auto kvs = iter->items(); |
| 74 | for (auto kv : kvs) { |
| 75 | D_LOG_DEBUG(" '%s' => '%s'", kv.key().c_str(), kv.value().get<std::string>().c_str()); |
| 76 | entries.push_back(ui::about::entry{kv.key(), role_type::CONTRIBUTOR, "", kv.value().get<std::string>()}); |
| 77 | } |
| 78 | } |
| 79 | if (auto iter = data.find("translator"); iter != data.end()) { |
| 80 | D_LOG_DEBUG(" Found %" PRIu64 " translator entries.", iter->size()); |
| 81 | auto kvs = iter->items(); |
| 82 | for (auto kv : kvs) { |
| 83 | D_LOG_DEBUG(" '%s' => '%s'", kv.key().c_str(), kv.value().get<std::string>().c_str()); |
| 84 | entries.push_back(ui::about::entry{kv.key(), role_type::TRANSLATOR, "", kv.value().get<std::string>()}); |
| 85 | } |
| 86 | } |
| 87 | if (auto iter = data.find("supporter"); iter != data.end()) { |
| 88 | auto data2 = *iter; |
| 89 | if (auto iter2 = data2.find("github"); iter2 != data2.end()) { |
| 90 | D_LOG_DEBUG(" Found %" PRIu64 " GitHub supporter entries.", iter2->size()); |
| 91 | auto kvs = iter2->items(); |
| 92 | for (auto kv : kvs) { |
| 93 | D_LOG_DEBUG(" '%s' => '%s'", kv.key().c_str(), kv.value().get<std::string>().c_str()); |
| 94 | entries.push_back(ui::about::entry{kv.key(), role_type::SUPPORTER, "GitHub", kv.value().get<std::string>()}); |
| 95 | } |
| 96 | } |
| 97 | if (auto iter2 = data2.find("patreon"); iter2 != data2.end()) { |
| 98 | D_LOG_DEBUG(" Found %" PRIu64 " Patreon supporter entries.", iter2->size()); |