Implemented safer and faster way to get current mirror URL

This commit is contained in:
spectranator 2024-05-08 17:47:00 +02:00
commit 377c9bc831

View file

@ -3520,38 +3520,18 @@ void GMainWindow::OpenURL(const QUrl& url) {
} }
void GMainWindow::OnOpenMirrorRepo() { void GMainWindow::OnOpenMirrorRepo() {
struct Mirror { httplib::Client cli("https://codeberg.org");
const char *host, *path; auto res = cli.Get("/litucks/tz-mu/raw/branch/main/mu.txt");
}; if (!res) {
const std::initializer_list<Mirror> mirrors = { QMessageBox::warning(this, tr("Error locating mirror"), tr("There has been an error finding the current mirror repository.<br/>"
{"https://github.com", "/litucks/torzu"}, "Your version may be too old or your network connectivity may be"
{"https://gitlab.com", "/litucks/torzu"}, "limited.<br/>"
{"https://bitbucket.org", "/litucks/torzu"}, "Please either try again later, through a VPN or access the main<br/>"
{"https://codeberg.org", "/litucks/torzu"}, "repository via the Tor Browser:<br/>"
{"https://notabug.org", "/litucks/torzu"}, "<a href='http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/torzu-emu/torzu'>http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/torzu-emu/torzu</a>"));
{"https://gitea.com", "/litucks/torzu"},
{"https://try.gitea.io", "/litucks/torzu"},
{"https://git.math.hamburg", "/litucks/torzu"},
{"https://gitea.sprint-pay.com", "/litucks/torzu"},
{"https://gitea.djoe.ovh", "/litucks/torzu"},
{"https://git.sheetjs.com", "/litucks/torzu"},
{"https://gitea.cisetech.com", "/litucks/torzu"}
};
for (const auto& mirror : mirrors) {
httplib::Client cli(mirror.host);
if (cli.Get(mirror.path)) {
OpenURL(QUrl(QString::fromStdString(fmt::format("{}{}", mirror.host, mirror.path))));
return;
}
} }
QMessageBox::warning(this, tr("Error locating mirror"), tr("There has been an error finding the current mirror repository.\n" OpenURL(QUrl(QString::fromStdString(res->body)));
"Your version may be so old the list has already been depleted\n"
"or your network connectivity may be limited.\n"
"Please either try again later, through a VPN or access the main\n"
"repository via the Tor Browser:\n"
"http://y2nlvhmmk5jnsvechppxnbyzmmv3vbl7dvzn6ltwcdbpgxixp3clkgqd.onion/torzu-emu/torzu"));
} }
void GMainWindow::ToggleFullscreen() { void GMainWindow::ToggleFullscreen() {