Skip to content

Commit

Permalink
holy fuck it works
Browse files Browse the repository at this point in the history
  • Loading branch information
LimeGradient committed Jun 15, 2024
1 parent bb7f9d9 commit fd2f0f6
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions src/ModProfilesPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ void ModProfilesPopup::setup() {
setTouchEnabled(true);
}

void ModProfilesPopup::importMods(CCObject* obj) {
std::vector<std::string> modDownloadLinks;
FileTask importFromFile() {
return file::pick(file::PickMode::OpenFile, ModProfilesPopup::m_options);
}

void downloadMods(FileTask::Event* e) {
std::vector<std::string> downloadLinks;

m_webTaskListener.bind([=] (web::WebTask::Event* e) {
if (web::WebResponse* res = e->getValue()) {
Expand All @@ -71,8 +75,10 @@ void ModProfilesPopup::importMods(CCObject* obj) {
m_downloadFileListener.bind([=] (web::WebTask::Event* ev) {
if (web::WebResponse* response = e->getValue()) {
if (response->ok()) {
response->into(fmt::format("{}/{}", geode::dirs::getModsDir(), modID + ".geode"));
Notification::create(fmt::format("Successfully installed: {}", modID), NotificationIcon::Success);
if (!fs::exists(fmt::format("{}/{}", geode::dirs::getModsDir(), modID + ".geode"))) {
response->into(fmt::format("{}/{}", geode::dirs::getModsDir(), modID + ".geode"));
Notification::create(fmt::format("Successfully installed: {}", modID), NotificationIcon::Success);
}
}
} else if (e->isCancelled()) {
Notification::create(fmt::format("Error while downloading mod: {}", modID), NotificationIcon::Error);
Expand All @@ -86,10 +92,28 @@ void ModProfilesPopup::importMods(CCObject* obj) {
}
});


if (auto result = e->getValue()) {
if (result->isOk()) {
auto path = result->unwrap();
std::ifstream modProfileFile(path);
std::string line;
while (std::getline(modProfileFile, line)) {
downloadLinks.push_back(line);
}

auto req = web::WebRequest();
m_webTaskListener.setFilter(req.get("https://api.geode-sdk.org/v1/mods/geode.devtools"));
for (std::string downloadLink : downloadLinks) {
auto req = web::WebRequest();
m_webTaskListener.setFilter(req.get(downloadLink));
}
}
}
}

void ModProfilesPopup::importMods(CCObject* obj) {
m_fileTaskListener.bind([=](auto* e) {
downloadMods(e);
});
m_fileTaskListener.setFilter(importFromFile());
}

FileTask exportToFile() {
Expand Down

0 comments on commit fd2f0f6

Please sign in to comment.