| 51 | } |
| 52 | |
| 53 | void UpdateLayout::StartUpdateSearch() { |
| 54 | g_MainApplication->LoadCommonIconMenuData(true, cfg::Strings.GetString(284), CommonIconKind::Update, cfg::Strings.GetString(302)); |
| 55 | |
| 56 | ScopeGuard on_exit([&]() { |
| 57 | g_MainApplication->ReturnToParentLayout(); |
| 58 | }); |
| 59 | |
| 60 | this->download_p_bar->SetVisible(false); |
| 61 | this->info_text->SetText(cfg::Strings.GetString(305)); |
| 62 | g_MainApplication->CallForRender(); |
| 63 | |
| 64 | const auto json_data = net::RetrieveContent("https://api.github.com/repos/XorTroll/Goldleaf/releases", "application/json"); |
| 65 | if(json_data.empty()) { |
| 66 | g_MainApplication->DisplayDialog(cfg::Strings.GetString(284), cfg::Strings.GetString(316), { cfg::Strings.GetString(234) }, true); |
| 67 | return; |
| 68 | } |
| 69 | json::GitHubReleases releases; |
| 70 | const auto err = glz::read<PartialJsonOptions{}>(releases, json_data); |
| 71 | if(err || releases.empty()) { |
| 72 | g_MainApplication->DisplayDialog(cfg::Strings.GetString(284), cfg::Strings.GetString(316), { cfg::Strings.GetString(234) }, true); |
| 73 | return; |
| 74 | } |
| 75 | const auto last_id = releases.front().tag_name; |
| 76 | if(last_id.empty()) { |
| 77 | g_MainApplication->DisplayDialog(cfg::Strings.GetString(284), cfg::Strings.GetString(316), { cfg::Strings.GetString(234) }, true); |
| 78 | return; |
| 79 | } |
| 80 | this->info_text->SetText(cfg::Strings.GetString(306)); |
| 81 | g_MainApplication->CallForRender(); |
| 82 | |
| 83 | const auto last_ver = Version::FromString(last_id); |
| 84 | const auto cur_ver = Version::MakeVersion(GLEAF_MAJOR, GLEAF_MINOR, GLEAF_MICRO); |
| 85 | if(last_ver.IsEqual(cur_ver)) { |
| 86 | g_MainApplication->DisplayDialog(cfg::Strings.GetString(284), cfg::Strings.GetString(307), { cfg::Strings.GetString(234) }, true); |
| 87 | } |
| 88 | else if(last_ver.IsLower(cur_ver)) { |
| 89 | const auto option = g_MainApplication->DisplayDialog(cfg::Strings.GetString(284), cfg::Strings.GetString(308), { cfg::Strings.GetString(111), cfg::Strings.GetString(18) }, true); |
| 90 | if(option == 0) { |
| 91 | EnsureDirectories(); |
| 92 | auto sd_exp = fs::GetSdCardExplorer(); |
| 93 | sd_exp->DeleteFile(GLEAF_PATH_TEMP_UPDATE_NRO); |
| 94 | |
| 95 | this->info_text->SetText(cfg::Strings.GetString(309)); |
| 96 | g_MainApplication->CallForRender(); |
| 97 | |
| 98 | hos::LockExit(); |
| 99 | this->download_p_bar->SetVisible(true); |
| 100 | const auto download_url = "https://github.com/XorTroll/Goldleaf/releases/download/" + last_id + "/Goldleaf.nro"; |
| 101 | sd_exp->DeleteFile(GLEAF_PATH_TEMP_UPDATE_NRO); |
| 102 | net::RetrieveToFile(download_url, sd_exp->AbsolutePathFor(GLEAF_PATH_TEMP_UPDATE_NRO), [&](const double done, const double total) { |
| 103 | this->download_p_bar->SetMaxProgress(total); |
| 104 | this->download_p_bar->SetProgress(done); |
| 105 | g_MainApplication->CallForRender(); |
| 106 | }); |
| 107 | this->download_p_bar->SetVisible(false); |
| 108 | hos::UnlockExit(); |
| 109 | |
| 110 | if(sd_exp->IsFile(GLEAF_PATH_TEMP_UPDATE_NRO)) { |
no test coverage detected