2019-12-19 02:36:38 +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-11-28 00:49:58 +00:00
|
|
|
#include <string>
|
2019-12-10 03:23:21 +00:00
|
|
|
#include <thread>
|
2020-01-08 22:51:27 +00:00
|
|
|
#include <malloc.h>
|
2019-11-17 15:01:06 +00:00
|
|
|
#include "usbInstall.hpp"
|
|
|
|
#include "install/usb_nsp.hpp"
|
2019-12-16 23:15:40 +00:00
|
|
|
#include "install/install_nsp.hpp"
|
2019-12-19 02:36:38 +00:00
|
|
|
#include "install/usb_xci.hpp"
|
|
|
|
#include "install/install_xci.hpp"
|
|
|
|
#include "util/error.hpp"
|
2019-11-17 15:01:06 +00:00
|
|
|
#include "util/usb_util.hpp"
|
|
|
|
#include "util/util.hpp"
|
|
|
|
#include "util/config.hpp"
|
2019-12-20 00:09:36 +00:00
|
|
|
#include "util/lang.hpp"
|
2019-11-17 15:01:06 +00:00
|
|
|
#include "ui/MainApplication.hpp"
|
2019-12-19 02:36:38 +00:00
|
|
|
#include "ui/usbInstPage.hpp"
|
|
|
|
#include "ui/instPage.hpp"
|
2019-11-17 15:01:06 +00:00
|
|
|
|
|
|
|
namespace inst::ui {
|
|
|
|
extern MainApplication *mainApp;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace usbInstStuff {
|
|
|
|
struct TUSHeader
|
|
|
|
{
|
|
|
|
u32 magic; // TUL0 (Tinfoil Usb List 0)
|
2019-11-30 16:12:45 +00:00
|
|
|
u32 titleListSize;
|
2019-11-17 15:01:06 +00:00
|
|
|
u64 padding;
|
|
|
|
} PACKED;
|
|
|
|
|
2020-01-08 22:51:27 +00:00
|
|
|
int bufferData(void* buf, size_t size, u64 timeout = 5000000000)
|
|
|
|
{
|
|
|
|
u8* tempBuffer = (u8*)memalign(0x1000, size);
|
|
|
|
if (tin::util::USBRead(tempBuffer, size, timeout) == 0) return 0;
|
|
|
|
memcpy(buf, tempBuffer, size);
|
|
|
|
free(tempBuffer);
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2019-12-08 23:59:37 +00:00
|
|
|
std::vector<std::string> OnSelected() {
|
2019-11-17 15:01:06 +00:00
|
|
|
TUSHeader header;
|
2019-12-06 22:25:11 +00:00
|
|
|
while(true) {
|
2020-01-08 22:51:27 +00:00
|
|
|
if (bufferData(&header, sizeof(TUSHeader), 500000000) != 0) break;
|
2019-12-08 23:59:37 +00:00
|
|
|
hidScanInput();
|
|
|
|
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
|
|
|
|
if (kDown & KEY_B) return {};
|
2019-12-20 00:09:36 +00:00
|
|
|
if (kDown & KEY_X) inst::ui::mainApp->CreateShowDialog("inst.usb.help.title"_lang, "inst.usb.help.desc"_lang, {"common.ok"_lang}, true);
|
C++ is a general-purpose programming language created by Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significantly over time, and modern C++ now has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation. It is almost always implemented as a compiled language, and many vendors provide C++ compilers, including the Free Software Foundation, LLVM, Microsoft, Intel, Oracle, and IBM, so it is available on many platforms.
* fix XCI installation if card was inserted prior
* fix double expression call on ASSERT_OK failure
* fix compatibility with latest libnx master to build with usb:ds changes for 11.0.0+
* remove unused functions
2020-12-12 01:46:33 +00:00
|
|
|
if (!inst::util::usbIsConnected()) return {};
|
2019-12-06 22:25:11 +00:00
|
|
|
}
|
2019-11-17 15:01:06 +00:00
|
|
|
|
2019-12-08 23:59:37 +00:00
|
|
|
if (header.magic != 0x304C5554) return {};
|
2019-11-17 15:01:06 +00:00
|
|
|
|
2019-11-30 16:12:45 +00:00
|
|
|
std::vector<std::string> titleNames;
|
2020-01-08 22:51:27 +00:00
|
|
|
char* titleNameBuffer = (char*)memalign(0x1000, header.titleListSize + 1);
|
|
|
|
memset(titleNameBuffer, 0, header.titleListSize + 1);
|
2019-11-17 15:01:06 +00:00
|
|
|
|
2020-01-10 19:46:51 +00:00
|
|
|
tin::util::USBRead(titleNameBuffer, header.titleListSize, 10000000000);
|
2019-11-17 15:01:06 +00:00
|
|
|
|
2019-11-30 16:12:45 +00:00
|
|
|
// Split the string up into individual title names
|
2020-01-08 22:51:27 +00:00
|
|
|
std::stringstream titleNamesStream(titleNameBuffer);
|
2019-11-17 15:01:06 +00:00
|
|
|
std::string segment;
|
2020-01-03 16:35:08 +00:00
|
|
|
while (std::getline(titleNamesStream, segment, '\n')) titleNames.push_back(segment);
|
2020-01-08 22:51:27 +00:00
|
|
|
free(titleNameBuffer);
|
2020-01-03 16:35:08 +00:00
|
|
|
std::sort(titleNames.begin(), titleNames.end(), inst::util::ignoreCaseCompare);
|
2019-11-17 15:01:06 +00:00
|
|
|
|
2019-12-08 23:59:37 +00:00
|
|
|
return titleNames;
|
2019-11-17 15:01:06 +00:00
|
|
|
}
|
|
|
|
|
2019-11-30 16:12:45 +00:00
|
|
|
void installTitleUsb(std::vector<std::string> ourTitleList, int ourStorage)
|
2019-11-28 00:49:58 +00:00
|
|
|
{
|
2019-11-17 15:01:06 +00:00
|
|
|
inst::util::initInstallServices();
|
2019-12-19 02:36:38 +00:00
|
|
|
inst::ui::instPage::loadInstallScreen();
|
2019-11-28 00:49:58 +00:00
|
|
|
bool nspInstalled = true;
|
2019-11-17 15:01:06 +00:00
|
|
|
NcmStorageId m_destStorageId = NcmStorageId_SdCard;
|
|
|
|
|
|
|
|
if (ourStorage) m_destStorageId = NcmStorageId_BuiltInUser;
|
2019-11-28 00:49:58 +00:00
|
|
|
unsigned int fileItr;
|
2019-11-17 15:01:06 +00:00
|
|
|
|
2019-11-28 00:49:58 +00:00
|
|
|
std::vector<std::string> fileNames;
|
2019-11-30 16:12:45 +00:00
|
|
|
for (long unsigned int i = 0; i < ourTitleList.size(); i++) {
|
2019-11-30 17:21:01 +00:00
|
|
|
fileNames.push_back(inst::util::shortenString(inst::util::formatUrlString(ourTitleList[i]), 40, true));
|
2019-11-28 00:49:58 +00:00
|
|
|
}
|
2019-11-30 17:21:01 +00:00
|
|
|
|
2019-11-28 00:49:58 +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-30 17:21:01 +00:00
|
|
|
|
2019-11-28 00:49:58 +00:00
|
|
|
try {
|
2019-11-30 16:12:45 +00:00
|
|
|
for (fileItr = 0; fileItr < ourTitleList.size(); fileItr++) {
|
2019-12-20 00:09:36 +00:00
|
|
|
inst::ui::instPage::setTopInstInfoText("inst.info_page.top_info0"_lang + fileNames[fileItr] + "inst.usb.source_string"_lang);
|
2019-12-16 23:15:40 +00:00
|
|
|
std::unique_ptr<tin::install::Install> installTask;
|
2019-11-30 16:12:45 +00:00
|
|
|
|
|
|
|
if (ourTitleList[fileItr].compare(ourTitleList[fileItr].size() - 3, 2, "xc") == 0) {
|
2019-12-16 23:15:40 +00:00
|
|
|
auto usbXCI = std::make_shared<tin::install::xci::USBXCI>(ourTitleList[fileItr]);
|
|
|
|
installTask = std::make_unique<tin::install::xci::XCIInstallTask>(m_destStorageId, inst::config::ignoreReqVers, usbXCI);
|
2019-11-30 16:12:45 +00:00
|
|
|
} else {
|
2019-12-16 23:15:40 +00:00
|
|
|
auto usbNSP = std::make_shared<tin::install::nsp::USBNSP>(ourTitleList[fileItr]);
|
|
|
|
installTask = std::make_unique<tin::install::nsp::NSPInstall>(m_destStorageId, inst::config::ignoreReqVers, usbNSP);
|
2019-11-30 16:12:45 +00:00
|
|
|
}
|
2019-11-17 15:01:06 +00:00
|
|
|
|
2019-11-30 17:12:59 +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-11-30 16:12:45 +00:00
|
|
|
installTask->Prepare();
|
2019-11-28 00:49:58 +00:00
|
|
|
|
2019-11-30 16:12:45 +00:00
|
|
|
installTask->Begin();
|
2019-11-17 15:01:06 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-28 00:49:58 +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-28 00:49:58 +00:00
|
|
|
fprintf(stdout, "%s", e.what());
|
2019-12-20 00:09:36 +00:00
|
|
|
inst::ui::instPage::setInstInfoText("inst.info_page.failed"_lang + fileNames[fileItr]);
|
2019-12-19 02:36:38 +00:00
|
|
|
inst::ui::instPage::setInstBarPerc(0);
|
2020-09-22 18:29:09 +00:00
|
|
|
std::string audioPath = "romfs:/audio/bark.wav";
|
|
|
|
if (inst::config::gayMode) audioPath = "";
|
|
|
|
if (std::filesystem::exists(inst::config::appDir + "/bark.wav")) audioPath = inst::config::appDir + "/bark.wav";
|
|
|
|
std::thread audioThread(inst::util::playAudio,audioPath);
|
2019-12-20 00:09:36 +00:00
|
|
|
inst::ui::mainApp->CreateShowDialog("inst.info_page.failed"_lang + fileNames[fileItr] + "!", "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-28 00:49:58 +00:00
|
|
|
nspInstalled = false;
|
|
|
|
}
|
2019-11-17 15:01:06 +00:00
|
|
|
|
2019-11-28 00:49:58 +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-30 17:21:01 +00:00
|
|
|
|
2019-11-28 00:49:58 +00:00
|
|
|
if(nspInstalled) {
|
2019-12-01 04:06:00 +00:00
|
|
|
tin::util::USBCmdManager::SendExitCmd();
|
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);
|
2020-09-22 18:29:09 +00:00
|
|
|
std::string audioPath = "romfs:/audio/awoo.wav";
|
|
|
|
if (inst::config::gayMode) audioPath = "";
|
|
|
|
if (std::filesystem::exists(inst::config::appDir + "/awoo.wav")) audioPath = inst::config::appDir + "/awoo.wav";
|
|
|
|
std::thread audioThread(inst::util::playAudio,audioPath);
|
2019-12-20 00:09:36 +00:00
|
|
|
if (ourTitleList.size() > 1) inst::ui::mainApp->CreateShowDialog(std::to_string(ourTitleList.size()) + "inst.info_page.desc0"_lang, Language::GetRandomMsg(), {"common.ok"_lang}, true);
|
|
|
|
else inst::ui::mainApp->CreateShowDialog(fileNames[0] + "inst.info_page.desc1"_lang, Language::GetRandomMsg(), {"common.ok"_lang}, true);
|
2019-12-10 03:23:21 +00:00
|
|
|
audioThread.join();
|
2019-11-28 00:49:58 +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-28 00:49:58 +00:00
|
|
|
inst::util::deinitInstallServices();
|
|
|
|
return;
|
2019-11-17 15:01:06 +00:00
|
|
|
}
|
|
|
|
}
|