2019-11-01 20:00:28 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2017-2018 Adubbz
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2019-10-22 22:14:37 +00:00
|
|
|
#include <cstring>
|
|
|
|
#include <sstream>
|
2019-10-26 01:00:13 +00:00
|
|
|
#include <filesystem>
|
2019-11-03 20:02:15 +00:00
|
|
|
#include <ctime>
|
2019-12-10 03:23:21 +00:00
|
|
|
#include <thread>
|
2019-12-16 23:15:40 +00:00
|
|
|
#include <memory>
|
2019-12-19 02:36:38 +00:00
|
|
|
#include "sdInstall.hpp"
|
2019-10-22 22:14:37 +00:00
|
|
|
#include "install/install_nsp.hpp"
|
2019-11-29 08:23:11 +00:00
|
|
|
#include "install/install_xci.hpp"
|
2019-12-16 23:15:40 +00:00
|
|
|
#include "install/sdmc_xci.hpp"
|
|
|
|
#include "install/sdmc_nsp.hpp"
|
2019-10-22 22:14:37 +00:00
|
|
|
#include "nx/fs.hpp"
|
|
|
|
#include "util/file_util.hpp"
|
|
|
|
#include "util/title_util.hpp"
|
|
|
|
#include "util/error.hpp"
|
2019-10-28 23:47:49 +00:00
|
|
|
#include "util/config.hpp"
|
|
|
|
#include "util/util.hpp"
|
2019-12-20 00:09:36 +00:00
|
|
|
#include "util/lang.hpp"
|
2019-12-19 02:36:38 +00:00
|
|
|
#include "ui/MainApplication.hpp"
|
|
|
|
#include "ui/instPage.hpp"
|
2019-10-22 22:14:37 +00:00
|
|
|
|
|
|
|
namespace inst::ui {
|
|
|
|
extern MainApplication *mainApp;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace nspInstStuff {
|
|
|
|
|
2019-11-30 16:12:45 +00:00
|
|
|
void installNspFromFile(std::vector<std::filesystem::path> ourTitleList, int whereToInstall)
|
2019-10-22 22:14:37 +00:00
|
|
|
{
|
2019-11-03 21:16:52 +00:00
|
|
|
inst::util::initInstallServices();
|
2019-12-19 02:36:38 +00:00
|
|
|
inst::ui::instPage::loadInstallScreen();
|
2019-11-02 00:12:00 +00:00
|
|
|
bool nspInstalled = true;
|
2019-11-14 19:04:40 +00:00
|
|
|
NcmStorageId m_destStorageId = NcmStorageId_SdCard;
|
2019-10-22 22:14:37 +00:00
|
|
|
|
2019-11-14 19:04:40 +00:00
|
|
|
if (whereToInstall) m_destStorageId = NcmStorageId_BuiltInUser;
|
2019-11-30 16:12:45 +00:00
|
|
|
unsigned int titleItr;
|
2019-10-23 01:33:13 +00:00
|
|
|
|
2019-11-17 20:38:01 +00:00
|
|
|
std::vector<int> previousClockValues;
|
|
|
|
if (inst::config::overClock) {
|
|
|
|
previousClockValues.push_back(inst::util::setClockSpeed(0, 1785000000)[0]);
|
|
|
|
previousClockValues.push_back(inst::util::setClockSpeed(1, 76800000)[0]);
|
|
|
|
previousClockValues.push_back(inst::util::setClockSpeed(2, 1600000000)[0]);
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:12:00 +00:00
|
|
|
try
|
2019-10-22 22:14:37 +00:00
|
|
|
{
|
2019-11-30 16:12:45 +00:00
|
|
|
for (titleItr = 0; titleItr < ourTitleList.size(); titleItr++) {
|
2019-12-20 00:09:36 +00:00
|
|
|
inst::ui::instPage::setTopInstInfoText("inst.info_page.top_info0"_lang + inst::util::shortenString(ourTitleList[titleItr].filename().string(), 40, true) + "inst.sd.source_string"_lang);
|
2019-12-16 23:15:40 +00:00
|
|
|
std::unique_ptr<tin::install::Install> installTask;
|
2019-11-29 08:23:11 +00:00
|
|
|
|
2019-11-30 16:12:45 +00:00
|
|
|
if (ourTitleList[titleItr].extension() == ".xci" || ourTitleList[titleItr].extension() == ".xcz") {
|
2019-12-16 23:15:40 +00:00
|
|
|
auto sdmcXCI = std::make_shared<tin::install::xci::SDMCXCI>(ourTitleList[titleItr]);
|
|
|
|
installTask = std::make_unique<tin::install::xci::XCIInstallTask>(m_destStorageId, inst::config::ignoreReqVers, sdmcXCI);
|
2019-11-29 08:23:11 +00:00
|
|
|
} else {
|
2019-12-16 23:15:40 +00:00
|
|
|
auto sdmcNSP = std::make_shared<tin::install::nsp::SDMCNSP>(ourTitleList[titleItr]);
|
|
|
|
installTask = std::make_unique<tin::install::nsp::NSPInstall>(m_destStorageId, inst::config::ignoreReqVers, sdmcNSP);
|
2019-12-06 20:03:12 +00:00
|
|
|
}
|
2019-12-16 23:15:40 +00:00
|
|
|
|
|
|
|
LOG_DEBUG("%s\n", "Preparing installation");
|
2019-12-20 00:09:36 +00:00
|
|
|
inst::ui::instPage::setInstInfoText("inst.info_page.preparing"_lang);
|
2019-12-19 02:36:38 +00:00
|
|
|
inst::ui::instPage::setInstBarPerc(0);
|
2019-12-16 23:15:40 +00:00
|
|
|
installTask->Prepare();
|
|
|
|
installTask->Begin();
|
2019-10-22 22:14:37 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-02 00:12:00 +00:00
|
|
|
catch (std::exception& e)
|
|
|
|
{
|
2019-11-30 17:12:59 +00:00
|
|
|
LOG_DEBUG("Failed to install");
|
|
|
|
LOG_DEBUG("%s", e.what());
|
2019-11-02 00:12:00 +00:00
|
|
|
fprintf(stdout, "%s", e.what());
|
2019-12-20 00:09:36 +00:00
|
|
|
inst::ui::instPage::setInstInfoText("inst.info_page.failed"_lang + inst::util::shortenString(ourTitleList[titleItr].filename().string(), 42, true));
|
2019-12-19 02:36:38 +00:00
|
|
|
inst::ui::instPage::setInstBarPerc(0);
|
2019-12-10 03:23:21 +00:00
|
|
|
std::thread audioThread(inst::util::playAudio,"romfs:/audio/bark.wav");
|
2019-12-20 00:09:36 +00:00
|
|
|
inst::ui::mainApp->CreateShowDialog("inst.info_page.failed"_lang + inst::util::shortenString(ourTitleList[titleItr].filename().string(), 42, true) + "!", "inst.info_page.failed_desc"_lang + "\n\n" + (std::string)e.what(), {"common.ok"_lang}, true);
|
2019-12-10 03:23:21 +00:00
|
|
|
audioThread.join();
|
2019-11-02 00:12:00 +00:00
|
|
|
nspInstalled = false;
|
|
|
|
}
|
2019-10-22 22:14:37 +00:00
|
|
|
|
2019-11-17 20:38:01 +00:00
|
|
|
if (previousClockValues.size() > 0) {
|
|
|
|
inst::util::setClockSpeed(0, previousClockValues[0]);
|
|
|
|
inst::util::setClockSpeed(1, previousClockValues[1]);
|
|
|
|
inst::util::setClockSpeed(2, previousClockValues[2]);
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:12:00 +00:00
|
|
|
if(nspInstalled) {
|
2019-12-20 00:09:36 +00:00
|
|
|
inst::ui::instPage::setInstInfoText("inst.info_page.complete"_lang);
|
2019-12-19 02:36:38 +00:00
|
|
|
inst::ui::instPage::setInstBarPerc(100);
|
2019-12-10 03:23:21 +00:00
|
|
|
std::thread audioThread(inst::util::playAudio,"romfs:/audio/awoo.wav");
|
2019-11-30 16:12:45 +00:00
|
|
|
if (ourTitleList.size() > 1) {
|
2019-11-06 02:45:26 +00:00
|
|
|
if (inst::config::deletePrompt) {
|
2019-12-20 00:09:36 +00:00
|
|
|
if(inst::ui::mainApp->CreateShowDialog(std::to_string(ourTitleList.size()) + "inst.sd.delete_info_multi"_lang, "inst.sd.delete_desc"_lang, {"common.no"_lang,"common.yes"_lang}, false) == 1) {
|
2019-11-30 16:12:45 +00:00
|
|
|
for (long unsigned int i = 0; i < ourTitleList.size(); i++) {
|
|
|
|
if (std::filesystem::exists(ourTitleList[i])) std::filesystem::remove(ourTitleList[i]);
|
2019-11-06 02:45:26 +00:00
|
|
|
}
|
2019-11-02 00:12:00 +00:00
|
|
|
}
|
2019-12-20 00:09:36 +00:00
|
|
|
} else inst::ui::mainApp->CreateShowDialog(std::to_string(ourTitleList.size()) + "inst.info_page.desc0"_lang, Language::GetRandomMsg(), {"common.ok"_lang}, true);
|
2019-11-02 00:12:00 +00:00
|
|
|
} else {
|
2019-11-06 02:45:26 +00:00
|
|
|
if (inst::config::deletePrompt) {
|
2019-12-20 00:09:36 +00:00
|
|
|
if(inst::ui::mainApp->CreateShowDialog(inst::util::shortenString(ourTitleList[0].filename().string(), 32, true) + "inst.sd.delete_info"_lang, "inst.sd.delete_desc"_lang, {"common.no"_lang,"common.yes"_lang}, false) == 1) if (std::filesystem::exists(ourTitleList[0])) std::filesystem::remove(ourTitleList[0]);
|
|
|
|
} else inst::ui::mainApp->CreateShowDialog(inst::util::shortenString(ourTitleList[0].filename().string(), 42, true) + "inst.info_page.desc1"_lang, Language::GetRandomMsg(), {"common.ok"_lang}, true);
|
2019-11-02 00:12:00 +00:00
|
|
|
}
|
2019-12-10 03:23:21 +00:00
|
|
|
audioThread.join();
|
2019-11-02 00:12:00 +00:00
|
|
|
}
|
2019-10-26 01:00:13 +00:00
|
|
|
|
2019-11-30 17:12:59 +00:00
|
|
|
LOG_DEBUG("Done");
|
2019-12-19 02:36:38 +00:00
|
|
|
inst::ui::instPage::loadMainMenu();
|
2019-11-03 21:16:52 +00:00
|
|
|
inst::util::deinitInstallServices();
|
2019-10-24 19:53:54 +00:00
|
|
|
return;
|
2019-10-22 22:14:37 +00:00
|
|
|
}
|
|
|
|
}
|