From cc368479df8d392077747e77cdf5bea3b69fe4d9 Mon Sep 17 00:00:00 2001 From: HookedBehemoth Date: Sat, 30 Nov 2019 13:58:39 +0100 Subject: [PATCH] cleanup xci installation --- include/install/http_xci.hpp | 23 --------------- include/install/local_xci.hpp | 3 +- include/install/xci.hpp | 1 - source/install/http_xci.cpp | 10 ++----- source/install/install_xci.cpp | 43 +--------------------------- source/install/local_xci.cpp | 52 ++++++++++++++++++++++++++++++---- 6 files changed, 51 insertions(+), 81 deletions(-) diff --git a/include/install/http_xci.hpp b/include/install/http_xci.hpp index c167c43..73718b8 100755 --- a/include/install/http_xci.hpp +++ b/include/install/http_xci.hpp @@ -24,28 +24,6 @@ SOFTWARE. #include "install/xci.hpp" #include "util/network_util.hpp" -/* -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. -*/ - #include namespace tin::install::xci @@ -57,7 +35,6 @@ namespace tin::install::xci HTTPXCI(std::string url); - virtual bool CanStream() override; virtual void StreamToPlaceholder(std::shared_ptr& contentStorage, NcmContentId placeholderId) override; virtual void BufferData(void* buf, off_t offset, size_t size) override; }; diff --git a/include/install/local_xci.hpp b/include/install/local_xci.hpp index 6f80047..28e9281 100755 --- a/include/install/local_xci.hpp +++ b/include/install/local_xci.hpp @@ -32,8 +32,7 @@ namespace tin::install::xci LocalXCI(std::string path); ~LocalXCI(); - virtual bool CanStream() override; - virtual void StreamToPlaceholder(std::shared_ptr& contentStorage, NcmContentId placeholderId) override; + virtual void StreamToPlaceholder(std::shared_ptr& contentStorage, NcmContentId ncaId) override; virtual void BufferData(void* buf, off_t offset, size_t size) override; private: FILE* m_xciFile; diff --git a/include/install/xci.hpp b/include/install/xci.hpp index af506f3..a5f72aa 100755 --- a/include/install/xci.hpp +++ b/include/install/xci.hpp @@ -41,7 +41,6 @@ namespace tin::install::xci XCI(); public: - virtual bool CanStream() = 0; virtual void StreamToPlaceholder(std::shared_ptr& contentStorage, NcmContentId placeholderId) = 0; virtual void BufferData(void* buf, off_t offset, size_t size) = 0; diff --git a/source/install/http_xci.cpp b/source/install/http_xci.cpp index cd0dbbf..8006d0b 100755 --- a/source/install/http_xci.cpp +++ b/source/install/http_xci.cpp @@ -77,19 +77,15 @@ namespace tin::install::xci return 0; } - bool HTTPXCI::CanStream() { - return true; - } - - void HTTPXCI::StreamToPlaceholder(std::shared_ptr& contentStorage, NcmContentId placeholderId) + void HTTPXCI::StreamToPlaceholder(std::shared_ptr& contentStorage, NcmContentId ncaId) { - const HFS0FileEntry* fileEntry = this->GetFileEntryByNcaId(placeholderId); + const HFS0FileEntry* fileEntry = this->GetFileEntryByNcaId(ncaId); std::string ncaFileName = this->GetFileEntryName(fileEntry); printf("Retrieving %s\n", ncaFileName.c_str()); size_t ncaSize = fileEntry->fileSize; - tin::data::BufferedPlaceholderWriter bufferedPlaceholderWriter(contentStorage, placeholderId, ncaSize); + tin::data::BufferedPlaceholderWriter bufferedPlaceholderWriter(contentStorage, ncaId, ncaSize); StreamFuncArgs args; args.download = &m_download; args.bufferedPlaceholderWriter = &bufferedPlaceholderWriter; diff --git a/source/install/install_xci.cpp b/source/install/install_xci.cpp index 0c52c2c..da84197 100755 --- a/source/install/install_xci.cpp +++ b/source/install/install_xci.cpp @@ -23,7 +23,6 @@ SOFTWARE. #include "install/install_xci.hpp" #include "util/file_util.hpp" #include "util/title_util.hpp" -#include "nx/nca_writer.h" #include "util/debug.h" #include "util/error.hpp" #include "util/config.hpp" @@ -115,47 +114,7 @@ namespace tin::install::xci } } - if (m_xci->CanStream()) { - m_xci->StreamToPlaceholder(contentStorage, ncaId); - } else { - NcaWriter writer(ncaId, contentStorage); - - float progress; - - u64 fileStart = m_xci->GetDataOffset() + fileEntry->dataOffset; - u64 fileOff = 0; - size_t readSize = 0x400000; // 4MB buff - auto readBuffer = std::make_unique(readSize); - - try - { - inst::ui::setInstInfoText("Installing " + ncaFileName + "..."); - inst::ui::setInstBarPerc(0); - while (fileOff < ncaSize) - { - progress = (float) fileOff / (float) ncaSize; - - if (fileOff % (0x400000 * 3) == 0) { - printf("> Progress: %lu/%lu MB (%d%s)\r", (fileOff / 1000000), (ncaSize / 1000000), (int)(progress * 100.0), "%"); - inst::ui::setInstBarPerc((double)(progress * 100.0)); - } - - if (fileOff + readSize >= ncaSize) readSize = ncaSize - fileOff; - - m_xci->BufferData(readBuffer.get(), fileOff + fileStart, readSize); - writer.write(readBuffer.get(), readSize); - - fileOff += readSize; - } - inst::ui::setInstBarPerc(100); - } - catch (std::exception& e) - { - printf("something went wrong: %s\n", e.what()); - } - - writer.close(); - } + m_xci->StreamToPlaceholder(contentStorage, ncaId); // Clean up the line for whatever comes next printf(" \r"); diff --git a/source/install/local_xci.cpp b/source/install/local_xci.cpp index 8b65bb2..a7cbb7a 100755 --- a/source/install/local_xci.cpp +++ b/source/install/local_xci.cpp @@ -1,6 +1,8 @@ #include "install/local_xci.hpp" #include "error.hpp" #include "debug.h" +#include "nx/nca_writer.h" +#include "nspInstall.hpp" namespace tin::install::xci { @@ -16,13 +18,51 @@ namespace tin::install::xci fclose(m_xciFile); } - bool LocalXCI::CanStream() { - return false; - } - - void LocalXCI::StreamToPlaceholder(std::shared_ptr& contentStorage, NcmContentId placeholderId) + void LocalXCI::StreamToPlaceholder(std::shared_ptr& contentStorage, NcmContentId ncaId) { - THROW_FORMAT("not streamable\n"); + const HFS0FileEntry* fileEntry = this->GetFileEntryByNcaId(ncaId); + std::string ncaFileName = this->GetFileEntryName(fileEntry); + + printf("Retrieving %s\n", ncaFileName.c_str()); + size_t ncaSize = fileEntry->fileSize; + + NcaWriter writer(ncaId, contentStorage); + + float progress; + + u64 fileStart = GetDataOffset() + fileEntry->dataOffset; + u64 fileOff = 0; + size_t readSize = 0x400000; // 4MB buff + auto readBuffer = std::make_unique(readSize); + + try + { + inst::ui::setInstInfoText("Installing " + ncaFileName + "..."); + inst::ui::setInstBarPerc(0); + while (fileOff < ncaSize) + { + progress = (float) fileOff / (float) ncaSize; + + if (fileOff % (0x400000 * 3) == 0) { + printf("> Progress: %lu/%lu MB (%d%s)\r", (fileOff / 1000000), (ncaSize / 1000000), (int)(progress * 100.0), "%"); + inst::ui::setInstBarPerc((double)(progress * 100.0)); + } + + if (fileOff + readSize >= ncaSize) readSize = ncaSize - fileOff; + + this->BufferData(readBuffer.get(), fileOff + fileStart, readSize); + writer.write(readBuffer.get(), readSize); + + fileOff += readSize; + } + inst::ui::setInstBarPerc(100); + } + catch (std::exception& e) + { + printf("something went wrong: %s\n", e.what()); + } + + writer.close(); } void LocalXCI::BufferData(void* buf, off_t offset, size_t size)