summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Zach Hilman2018-08-09 23:10:32 -0400
committerGravatar Zach Hilman2018-08-11 22:50:48 -0400
commit167bfddafadb843236c0fa683cf97eaffaa5ea1a (patch)
treebd67e895222feb751c4d4625143b9d352eb62847 /src
parentqt: Add 'Install to NAND' option to menu (diff)
downloadyuzu-167bfddafadb843236c0fa683cf97eaffaa5ea1a.tar.gz
yuzu-167bfddafadb843236c0fa683cf97eaffaa5ea1a.tar.xz
yuzu-167bfddafadb843236c0fa683cf97eaffaa5ea1a.zip
file_sys: Comply to style guidelines
Diffstat (limited to 'src')
-rw-r--r--src/common/hex_util.h2
-rw-r--r--src/core/file_sys/nca_metadata.cpp10
-rw-r--r--src/core/file_sys/nca_metadata.h4
-rw-r--r--src/core/file_sys/registered_cache.cpp24
-rw-r--r--src/core/file_sys/registered_cache.h13
-rw-r--r--src/core/file_sys/vfs_concat.cpp8
-rw-r--r--src/core/file_sys/vfs_concat.h6
-rw-r--r--src/yuzu/main.cpp40
8 files changed, 60 insertions, 47 deletions
diff --git a/src/common/hex_util.h b/src/common/hex_util.h
index f16c58aab..13d586015 100644
--- a/src/common/hex_util.h
+++ b/src/common/hex_util.h
@@ -5,6 +5,8 @@
5#pragma once 5#pragma once
6 6
7#include <array> 7#include <array>
8#include <cstddef>
9#include <string>
8#include <fmt/format.h> 10#include <fmt/format.h>
9#include "common/common_types.h" 11#include "common/common_types.h"
10 12
diff --git a/src/core/file_sys/nca_metadata.cpp b/src/core/file_sys/nca_metadata.cpp
index fa06897b7..118a0c287 100644
--- a/src/core/file_sys/nca_metadata.cpp
+++ b/src/core/file_sys/nca_metadata.cpp
@@ -2,6 +2,7 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <cstring>
5#include "common/common_funcs.h" 6#include "common/common_funcs.h"
6#include "common/swap.h" 7#include "common/swap.h"
7#include "content_archive.h" 8#include "content_archive.h"
@@ -67,9 +68,10 @@ const std::vector<MetaRecord>& CNMT::GetMetaRecords() const {
67bool CNMT::UnionRecords(const CNMT& other) { 68bool CNMT::UnionRecords(const CNMT& other) {
68 bool change = false; 69 bool change = false;
69 for (const auto& rec : other.content_records) { 70 for (const auto& rec : other.content_records) {
70 const auto iter = std::find_if( 71 const auto iter = std::find_if(content_records.begin(), content_records.end(),
71 content_records.begin(), content_records.end(), 72 [&rec](const ContentRecord& r) {
72 [rec](const ContentRecord& r) { return r.nca_id == rec.nca_id && r.type == rec.type; }); 73 return r.nca_id == rec.nca_id && r.type == rec.type;
74 });
73 if (iter == content_records.end()) { 75 if (iter == content_records.end()) {
74 content_records.emplace_back(rec); 76 content_records.emplace_back(rec);
75 ++header->number_content_entries; 77 ++header->number_content_entries;
@@ -78,7 +80,7 @@ bool CNMT::UnionRecords(const CNMT& other) {
78 } 80 }
79 for (const auto& rec : other.meta_records) { 81 for (const auto& rec : other.meta_records) {
80 const auto iter = 82 const auto iter =
81 std::find_if(meta_records.begin(), meta_records.end(), [rec](const MetaRecord& r) { 83 std::find_if(meta_records.begin(), meta_records.end(), [&rec](const MetaRecord& r) {
82 return r.title_id == rec.title_id && r.title_version == rec.title_version && 84 return r.title_id == rec.title_id && r.title_version == rec.title_version &&
83 r.type == rec.type; 85 r.type == rec.type;
84 }); 86 });
diff --git a/src/core/file_sys/nca_metadata.h b/src/core/file_sys/nca_metadata.h
index 7b0725f36..6cd919e54 100644
--- a/src/core/file_sys/nca_metadata.h
+++ b/src/core/file_sys/nca_metadata.h
@@ -4,7 +4,11 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <cstring>
7#include <memory> 8#include <memory>
9#include <vector>
10#include "common/common_types.h"
11#include "common/swap.h"
8#include "core/file_sys/vfs.h" 12#include "core/file_sys/vfs.h"
9 13
10namespace FileSys { 14namespace FileSys {
diff --git a/src/core/file_sys/registered_cache.cpp b/src/core/file_sys/registered_cache.cpp
index 766fef254..3e7706171 100644
--- a/src/core/file_sys/registered_cache.cpp
+++ b/src/core/file_sys/registered_cache.cpp
@@ -23,13 +23,13 @@ bool operator<(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs)
23} 23}
24 24
25static bool FollowsTwoDigitDirFormat(std::string_view name) { 25static bool FollowsTwoDigitDirFormat(std::string_view name) {
26 const static std::regex two_digit_regex( 26 static const std::regex two_digit_regex(
27 "000000[0123456789abcdefABCDEF][0123456789abcdefABCDEF]"); 27 "000000[0123456789abcdefABCDEF][0123456789abcdefABCDEF]");
28 return std::regex_match(name.begin(), name.end(), two_digit_regex); 28 return std::regex_match(name.begin(), name.end(), two_digit_regex);
29} 29}
30 30
31static bool FollowsNcaIdFormat(std::string_view name) { 31static bool FollowsNcaIdFormat(std::string_view name) {
32 const static std::regex nca_id_regex("[0123456789abcdefABCDEF]+.nca"); 32 static const std::regex nca_id_regex("[0123456789abcdefABCDEF]+.nca");
33 return name.size() == 36 && std::regex_match(name.begin(), name.end(), nca_id_regex); 33 return name.size() == 36 && std::regex_match(name.begin(), name.end(), nca_id_regex);
34} 34}
35 35
@@ -56,7 +56,7 @@ static std::string GetCNMTName(TitleType type, u64 title_id) {
56 "" ///< Currently unknown 'DeltaTitle' 56 "" ///< Currently unknown 'DeltaTitle'
57 }; 57 };
58 58
59 size_t index = static_cast<size_t>(type); 59 auto index = static_cast<size_t>(type);
60 if (index >= 0x80) 60 if (index >= 0x80)
61 index -= 0x80; 61 index -= 0x80;
62 return fmt::format("{}_{:016x}.cnmt", TITLE_TYPE_NAMES[index], title_id); 62 return fmt::format("{}_{:016x}.cnmt", TITLE_TYPE_NAMES[index], title_id);
@@ -90,15 +90,15 @@ VirtualFile RegisteredCache::OpenFileOrDirectoryConcat(const VirtualDir& dir,
90 VirtualFile file = nullptr; 90 VirtualFile file = nullptr;
91 91
92 const auto files = nca_dir->GetFiles(); 92 const auto files = nca_dir->GetFiles();
93 if (files.size() == 1 && files[0]->GetName() == "00") 93 if (files.size() == 1 && files[0]->GetName() == "00") {
94 file = files[0]; 94 file = files[0];
95 else { 95 } else {
96 std::vector<VirtualFile> concat; 96 std::vector<VirtualFile> concat;
97 for (u8 i = 0; i < 0x10; ++i) { 97 for (u8 i = 0; i < 0x10; ++i) {
98 auto next = nca_dir->GetFile(fmt::format("{:02X}", i)); 98 auto next = nca_dir->GetFile(fmt::format("{:02X}", i));
99 if (next != nullptr) 99 if (next != nullptr) {
100 concat.push_back(std::move(next)); 100 concat.push_back(std::move(next));
101 else { 101 } else {
102 next = nca_dir->GetFile(fmt::format("{:02x}", i)); 102 next = nca_dir->GetFile(fmt::format("{:02x}", i));
103 if (next != nullptr) 103 if (next != nullptr)
104 concat.push_back(std::move(next)); 104 concat.push_back(std::move(next));
@@ -146,7 +146,8 @@ boost::optional<NcaID> RegisteredCache::GetNcaIDFromMetadata(u64 title_id,
146 return boost::make_optional(iter->nca_id); 146 return boost::make_optional(iter->nca_id);
147} 147}
148 148
149void RegisteredCache::AccumulateFiles(std::vector<NcaID>& ids) const { 149std::vector<NcaID> RegisteredCache::AccumulateFiles() const {
150 std::vector<NcaID> ids;
150 for (const auto& d2_dir : dir->GetSubdirectories()) { 151 for (const auto& d2_dir : dir->GetSubdirectories()) {
151 if (FollowsNcaIdFormat(d2_dir->GetName())) { 152 if (FollowsNcaIdFormat(d2_dir->GetName())) {
152 ids.push_back(HexStringToArray<0x10, true>(d2_dir->GetName().substr(0, 0x20))); 153 ids.push_back(HexStringToArray<0x10, true>(d2_dir->GetName().substr(0, 0x20)));
@@ -175,6 +176,7 @@ void RegisteredCache::AccumulateFiles(std::vector<NcaID>& ids) const {
175 if (FollowsNcaIdFormat(d2_file->GetName())) 176 if (FollowsNcaIdFormat(d2_file->GetName()))
176 ids.push_back(HexStringToArray<0x10, true>(d2_file->GetName().substr(0, 0x20))); 177 ids.push_back(HexStringToArray<0x10, true>(d2_file->GetName().substr(0, 0x20)));
177 } 178 }
179 return ids;
178} 180}
179 181
180void RegisteredCache::ProcessFiles(const std::vector<NcaID>& ids) { 182void RegisteredCache::ProcessFiles(const std::vector<NcaID>& ids) {
@@ -185,8 +187,9 @@ void RegisteredCache::ProcessFiles(const std::vector<NcaID>& ids) {
185 continue; 187 continue;
186 const auto nca = std::make_shared<NCA>(parser(file, id)); 188 const auto nca = std::make_shared<NCA>(parser(file, id));
187 if (nca->GetStatus() != Loader::ResultStatus::Success || 189 if (nca->GetStatus() != Loader::ResultStatus::Success ||
188 nca->GetType() != NCAContentType::Meta) 190 nca->GetType() != NCAContentType::Meta) {
189 continue; 191 continue;
192 }
190 193
191 const auto section0 = nca->GetSubdirectories()[0]; 194 const auto section0 = nca->GetSubdirectories()[0];
192 195
@@ -218,8 +221,7 @@ void RegisteredCache::AccumulateYuzuMeta() {
218void RegisteredCache::Refresh() { 221void RegisteredCache::Refresh() {
219 if (dir == nullptr) 222 if (dir == nullptr)
220 return; 223 return;
221 std::vector<NcaID> ids; 224 const auto ids = AccumulateFiles();
222 AccumulateFiles(ids);
223 ProcessFiles(ids); 225 ProcessFiles(ids);
224 AccumulateYuzuMeta(); 226 AccumulateYuzuMeta();
225} 227}
diff --git a/src/core/file_sys/registered_cache.h b/src/core/file_sys/registered_cache.h
index ba2e3403f..baaed02dd 100644
--- a/src/core/file_sys/registered_cache.h
+++ b/src/core/file_sys/registered_cache.h
@@ -5,14 +5,17 @@
5#pragma once 5#pragma once
6 6
7#include <array> 7#include <array>
8#include <functional>
8#include <map> 9#include <map>
9#include <memory> 10#include <memory>
10#include <string> 11#include <string>
12#include <vector>
11#include <boost/container/flat_map.hpp> 13#include <boost/container/flat_map.hpp>
12#include "common/common_funcs.h" 14#include "common/common_funcs.h"
15#include "common/common_types.h"
13#include "content_archive.h" 16#include "content_archive.h"
17#include "core/file_sys/nca_metadata.h"
14#include "core/file_sys/vfs.h" 18#include "core/file_sys/vfs.h"
15#include "nca_metadata.h"
16 19
17namespace FileSys { 20namespace FileSys {
18class XCI; 21class XCI;
@@ -49,9 +52,9 @@ public:
49 // Parsing function defines the conversion from raw file to NCA. If there are other steps 52 // Parsing function defines the conversion from raw file to NCA. If there are other steps
50 // besides creating the NCA from the file (e.g. NAX0 on SD Card), that should go in a custom 53 // besides creating the NCA from the file (e.g. NAX0 on SD Card), that should go in a custom
51 // parsing function. 54 // parsing function.
52 RegisteredCache(VirtualDir dir, 55 explicit RegisteredCache(VirtualDir dir,
53 RegisteredCacheParsingFunction parsing_function = 56 RegisteredCacheParsingFunction parsing_function =
54 [](const VirtualFile& file, const NcaID& id) { return file; }); 57 [](const VirtualFile& file, const NcaID& id) { return file; });
55 58
56 void Refresh(); 59 void Refresh();
57 60
@@ -86,7 +89,7 @@ private:
86 void IterateAllMetadata(std::vector<T>& out, 89 void IterateAllMetadata(std::vector<T>& out,
87 std::function<T(const CNMT&, const ContentRecord&)> proc, 90 std::function<T(const CNMT&, const ContentRecord&)> proc,
88 std::function<bool(const CNMT&, const ContentRecord&)> filter) const; 91 std::function<bool(const CNMT&, const ContentRecord&)> filter) const;
89 void AccumulateFiles(std::vector<NcaID>& ids) const; 92 std::vector<NcaID> AccumulateFiles() const;
90 void ProcessFiles(const std::vector<NcaID>& ids); 93 void ProcessFiles(const std::vector<NcaID>& ids);
91 void AccumulateYuzuMeta(); 94 void AccumulateYuzuMeta();
92 boost::optional<NcaID> GetNcaIDFromMetadata(u64 title_id, ContentRecordType type) const; 95 boost::optional<NcaID> GetNcaIDFromMetadata(u64 title_id, ContentRecordType type) const;
diff --git a/src/core/file_sys/vfs_concat.cpp b/src/core/file_sys/vfs_concat.cpp
index 1d439e0a4..88a9a5259 100644
--- a/src/core/file_sys/vfs_concat.cpp
+++ b/src/core/file_sys/vfs_concat.cpp
@@ -9,17 +9,17 @@
9 9
10namespace FileSys { 10namespace FileSys {
11 11
12VirtualFile ConcatenateFiles(std::vector<VirtualFile> files, std::string_view name) { 12VirtualFile ConcatenateFiles(std::vector<VirtualFile> files, std::string name) {
13 if (files.empty()) 13 if (files.empty())
14 return nullptr; 14 return nullptr;
15 if (files.size() == 1) 15 if (files.size() == 1)
16 return files[0]; 16 return files[0];
17 17
18 return std::shared_ptr<VfsFile>(new ConcatenatedVfsFile(std::move(files), name)); 18 return std::shared_ptr<VfsFile>(new ConcatenatedVfsFile(std::move(files), std::move(name)));
19} 19}
20 20
21ConcatenatedVfsFile::ConcatenatedVfsFile(std::vector<VirtualFile> files_, std::string_view name) 21ConcatenatedVfsFile::ConcatenatedVfsFile(std::vector<VirtualFile> files_, std::string name)
22 : name(name) { 22 : name(std::move(name)) {
23 size_t next_offset = 0; 23 size_t next_offset = 0;
24 for (const auto& file : files_) { 24 for (const auto& file : files_) {
25 files[next_offset] = file; 25 files[next_offset] = file;
diff --git a/src/core/file_sys/vfs_concat.h b/src/core/file_sys/vfs_concat.h
index d319c5786..686d32515 100644
--- a/src/core/file_sys/vfs_concat.h
+++ b/src/core/file_sys/vfs_concat.h
@@ -12,14 +12,14 @@
12namespace FileSys { 12namespace FileSys {
13 13
14// Wrapper function to allow for more efficient handling of files.size() == 0, 1 cases. 14// Wrapper function to allow for more efficient handling of files.size() == 0, 1 cases.
15VirtualFile ConcatenateFiles(std::vector<VirtualFile> files, std::string_view name = ""); 15VirtualFile ConcatenateFiles(std::vector<VirtualFile> files, std::string name = "");
16 16
17// Class that wraps multiple vfs files and concatenates them, making reads seamless. Currently 17// Class that wraps multiple vfs files and concatenates them, making reads seamless. Currently
18// read-only. 18// read-only.
19class ConcatenatedVfsFile : public VfsFile { 19class ConcatenatedVfsFile : public VfsFile {
20 friend VirtualFile ConcatenateFiles(std::vector<VirtualFile> files, std::string_view name); 20 friend VirtualFile ConcatenateFiles(std::vector<VirtualFile> files, std::string name);
21 21
22 ConcatenatedVfsFile(std::vector<VirtualFile> files, std::string_view name); 22 ConcatenatedVfsFile(std::vector<VirtualFile> files, std::string name);
23 23
24public: 24public:
25 std::string GetName() const override; 25 std::string GetName() const override;
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index c48191486..fd237df43 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -619,7 +619,7 @@ void GMainWindow::OnMenuLoadFolder() {
619} 619}
620 620
621void GMainWindow::OnMenuInstallToNAND() { 621void GMainWindow::OnMenuInstallToNAND() {
622 const static QString file_filter = 622 const QString file_filter =
623 tr("Installable Switch File (*.nca *.xci);;Nintendo Content Archive (*.nca);;NX Cartridge " 623 tr("Installable Switch File (*.nca *.xci);;Nintendo Content Archive (*.nca);;NX Cartridge "
624 "Image (*.xci)"); 624 "Image (*.xci)");
625 QString filename = QFileDialog::getOpenFileName(this, tr("Install File"), 625 QString filename = QFileDialog::getOpenFileName(this, tr("Install File"),
@@ -629,36 +629,36 @@ void GMainWindow::OnMenuInstallToNAND() {
629 const auto xci = std::make_shared<FileSys::XCI>( 629 const auto xci = std::make_shared<FileSys::XCI>(
630 vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); 630 vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read));
631 if (xci->GetStatus() != Loader::ResultStatus::Success) { 631 if (xci->GetStatus() != Loader::ResultStatus::Success) {
632 QMessageBox::critical( 632 QMessageBox::warning(
633 this, tr("Failed to Install XCI"), 633 this, tr("Failed to Install XCI"),
634 tr("The XCI file you provided is invalid. Please double-check your encryption " 634 tr("The XCI file you provided is invalid. Please double-check your encryption "
635 "keys and the file and try again.")); 635 "keys and the file and try again."));
636 return; 636 return;
637 } 637 }
638 if (!Service::FileSystem::GetUserNANDContents()->InstallEntry(xci)) { 638 if (Service::FileSystem::GetUserNANDContents()->InstallEntry(xci)) {
639 QMessageBox::critical(
640 this, tr("Failed to Install XCI"),
641 tr("There was an error while attempting to install the provided XCI file. It "
642 "could have an incorrect format or be missing a metadata entry. Please "
643 "double-check your file and try again."));
644 } else {
645 QMessageBox::information(this, tr("Successfully Installed XCI"), 639 QMessageBox::information(this, tr("Successfully Installed XCI"),
646 tr("The file was successfully installed.")); 640 tr("The file was successfully installed."));
647 game_list->PopulateAsync(UISettings::values.gamedir, 641 game_list->PopulateAsync(UISettings::values.gamedir,
648 UISettings::values.gamedir_deepscan); 642 UISettings::values.gamedir_deepscan);
643 } else {
644 QMessageBox::warning(
645 this, tr("Failed to Install XCI"),
646 tr("There was an error while attempting to install the provided XCI file. It "
647 "could have an incorrect format or be missing a metadata entry. Please "
648 "double-check your file and try again."));
649 } 649 }
650 } else { 650 } else {
651 const auto nca = std::make_shared<FileSys::NCA>( 651 const auto nca = std::make_shared<FileSys::NCA>(
652 vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); 652 vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read));
653 if (nca->GetStatus() != Loader::ResultStatus::Success) { 653 if (nca->GetStatus() != Loader::ResultStatus::Success) {
654 QMessageBox::critical( 654 QMessageBox::warning(
655 this, tr("Failed to Install NCA"), 655 this, tr("Failed to Install NCA"),
656 tr("The NCA file you provided is invalid. Please double-check your encryption " 656 tr("The NCA file you provided is invalid. Please double-check your encryption "
657 "keys and the file and try again.")); 657 "keys and the file and try again."));
658 return; 658 return;
659 } 659 }
660 660
661 const static QStringList tt_options{"System Application", 661 static const QStringList tt_options{"System Application",
662 "System Archive", 662 "System Archive",
663 "System Application Update", 663 "System Application Update",
664 "Firmware Package (Type A)", 664 "Firmware Package (Type A)",
@@ -676,26 +676,26 @@ void GMainWindow::OnMenuInstallToNAND() {
676 676
677 auto index = tt_options.indexOf(item); 677 auto index = tt_options.indexOf(item);
678 if (!ok || index == -1) { 678 if (!ok || index == -1) {
679 QMessageBox::critical(this, tr("Failed to Install NCA"), 679 QMessageBox::warning(this, tr("Failed to Install NCA"),
680 tr("The title type you selected for the NCA is invalid.")); 680 tr("The title type you selected for the NCA is invalid."));
681 return; 681 return;
682 } 682 }
683 683
684 if (index >= 5) 684 if (index >= 5)
685 index += 0x80; 685 index += 0x80;
686 686
687 if (!Service::FileSystem::GetUserNANDContents()->InstallEntry( 687 if (Service::FileSystem::GetUserNANDContents()->InstallEntry(
688 nca, static_cast<FileSys::TitleType>(index))) { 688 nca, static_cast<FileSys::TitleType>(index))) {
689 QMessageBox::critical(this, tr("Failed to Install NCA"),
690 tr("There was an error while attempting to install the "
691 "provided NCA file. An error might have occured creating "
692 "the metadata file or parsing the NCA. Please "
693 "double-check your file and try again."));
694 } else {
695 QMessageBox::information(this, tr("Successfully Installed NCA"), 689 QMessageBox::information(this, tr("Successfully Installed NCA"),
696 tr("The file was successfully installed.")); 690 tr("The file was successfully installed."));
697 game_list->PopulateAsync(UISettings::values.gamedir, 691 game_list->PopulateAsync(UISettings::values.gamedir,
698 UISettings::values.gamedir_deepscan); 692 UISettings::values.gamedir_deepscan);
693 } else {
694 QMessageBox::warning(this, tr("Failed to Install NCA"),
695 tr("There was an error while attempting to install the "
696 "provided NCA file. An error might have occured creating "
697 "the metadata file or parsing the NCA. Please "
698 "double-check your file and try again."));
699 } 699 }
700 } 700 }
701 } 701 }