Skip to content

Commit

Permalink
Merge branch 'feature/XboxDisc-extracted-disc-file-system'
Browse files Browse the repository at this point in the history
  • Loading branch information
GerbilSoft committed Jan 25, 2025
2 parents 30388aa + 8d37cec commit 3dc6b90
Show file tree
Hide file tree
Showing 8 changed files with 758 additions and 269 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
* WiiUPackage: Add support for extracted Wii U packages.
* Fixes #430: Add support for extracted WiiU games
* Requested by @Masamune3210.
* XboxDisc: Extracted disc file systems are now supported.
* Handled similarly to WiiUPackage.
* Fixes #436: Add folder icon support for OG Xbox games
* Requested by @Masamune3210.

* Bug fixes:
* Amiibo: Fix an error that can cause the wrong Character Variant to be
Expand Down
67 changes: 18 additions & 49 deletions src/libromdata/Console/WiiUPackage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,27 +215,31 @@ IRpFilePtr WiiUPackagePrivate::open(const char *filename)
if (packageType == PackageType::Extracted) {
// Extracted package format. Open the file directly.
// TODO: Change slashes to backslashes on Windows?
tstring s_full_filename(path);
s_full_filename += DIR_SEP_CHR;
tstring ts_full_filename(path);
ts_full_filename += DIR_SEP_CHR;

// Remove leading slashes, if present.
while (*filename == _T('/')) {
filename++;
}
if (*filename == '\0') {
// Oops, no filename...
return {};
}

#ifdef _WIN32
const size_t old_sz = s_full_filename.size();
const size_t old_sz = ts_full_filename.size();
#endif /* _WIN32 */
s_full_filename += U82T_c(filename);
ts_full_filename += U82T_c(filename);
#ifdef _WIN32
// Replace all slashes with backslashes.
const auto start_iter = s_full_filename.begin() + old_sz;
std::transform(start_iter, s_full_filename.end(), start_iter, [](TCHAR c) {
const auto start_iter = ts_full_filename.begin() + old_sz;
std::transform(start_iter, ts_full_filename.end(), start_iter, [](TCHAR c) {
return (c == '/') ? DIR_SEP_CHR : c;
});
#endif /* _WIN32 */

return std::make_shared<RpFile>(s_full_filename.c_str(), RpFile::FM_OPEN_READ);
return std::make_shared<RpFile>(ts_full_filename.c_str(), RpFile::FM_OPEN_READ);
}

assert(fst != nullptr);
Expand Down Expand Up @@ -373,6 +377,7 @@ WiiUPackage::WiiUPackage(const wchar_t *path)
void WiiUPackage::init(void)
{
RP_D(WiiUPackage);
d->mimeType = "inode/directory";
d->fileType = FileType::ApplicationPackage;

if (!d->path) {
Expand Down Expand Up @@ -549,42 +554,6 @@ int WiiUPackage::isRomSupported_static(const DetectInfo *info)
return -1;
}

/**
* Is a directory supported by this class?
* @tparam T Character type (char for UTF-8; wchar_t for Windows UTF-16)
* @param path Directory to check
* @param filenames_to_check Array of filenames to check
* @return True if all files are found; false if at least one file is missing.
*/
template<typename T>
bool WiiUPackagePrivate::T_isDirSupported_static(const T *path, const array<const T*, 3> &filenames_to_check)
{
assert(path != nullptr);
assert(path[0] != '\0');
if (!path || path[0] == '\0') {
// No path specified.
return false;
}

std::basic_string<T> s_path(path);
s_path += DIR_SEP_CHR;
const size_t path_orig_size = s_path.size();

// Check for the required files.
for (const auto *const filename : filenames_to_check) {
s_path.resize(path_orig_size);
s_path += filename;

if (FileSystem::access(s_path.c_str(), R_OK) != 0) {
// File is missing.
return false;
}
}

// This appears to be a Wii U NUS package.
return true;
}

/**
* Is a directory supported by this class?
* @param path Directory to check
Expand All @@ -599,7 +568,7 @@ int WiiUPackage::isDirSupported_static(const char *path)
"title.cert", // Certificate chain
}};

if (WiiUPackagePrivate::T_isDirSupported_static(path, NUS_package_filenames)) {
if (RomDataPrivate::T_isDirSupported_allFiles_static(path, NUS_package_filenames)) {
return static_cast<int>(WiiUPackagePrivate::PackageType::NUS);
}

Expand All @@ -611,15 +580,15 @@ int WiiUPackage::isDirSupported_static(const char *path)
"meta/meta.xml",
}};

if (WiiUPackagePrivate::T_isDirSupported_static(path, extracted_package_filenames)) {
if (RomDataPrivate::T_isDirSupported_allFiles_static(path, extracted_package_filenames)) {
return static_cast<int>(WiiUPackagePrivate::PackageType::Extracted);
}

// Not supported.
return static_cast<int>(WiiUPackagePrivate::PackageType::Unknown);
}

#ifdef _WIN32
#if defined(_WIN32) && defined(_UNICODE)
/**
* Is a directory supported by this class?
* @param path Directory to check
Expand All @@ -634,7 +603,7 @@ int WiiUPackage::isDirSupported_static(const wchar_t *path)
L"title.cert", // Certificate chain
}};

if (WiiUPackagePrivate::T_isDirSupported_static(path, NUS_package_filenames)) {
if (RomDataPrivate::T_isDirSupported_allFiles_static(path, NUS_package_filenames)) {
return static_cast<int>(WiiUPackagePrivate::PackageType::NUS);
}

Expand All @@ -646,14 +615,14 @@ int WiiUPackage::isDirSupported_static(const wchar_t *path)
L"meta/meta.xml",
}};

if (WiiUPackagePrivate::T_isDirSupported_static(path, extracted_package_filenames)) {
if (RomDataPrivate::T_isDirSupported_allFiles_static(path, extracted_package_filenames)) {
return static_cast<int>(WiiUPackagePrivate::PackageType::Extracted);
}

// Not supported.
return static_cast<int>(WiiUPackagePrivate::PackageType::Unknown);
}
#endif /* _WIN32 */
#endif /* defined(_WIN32) && defined(_UNICODE) */

/**
* Get the name of the system the loaded ROM is designed for.
Expand Down
13 changes: 1 addition & 12 deletions src/libromdata/Console/WiiUPackage_p.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* ROM Properties Page shell extension. (libromdata) *
* WiiUPackage_p.hpp: Wii U NUS Package reader. (PRIVATE CLASS) *
* *
* Copyright (c) 2016-2024 by David Korth. *
* Copyright (c) 2016-2025 by David Korth. *
* SPDX-License-Identifier: GPL-2.0-or-later *
***************************************************************************/

Expand Down Expand Up @@ -123,17 +123,6 @@ class WiiUPackagePrivate final : public LibRpBase::RomDataPrivate
*/
LibRpTexture::rp_image_const_ptr loadIcon(void);

public:
/**
* Is a directory supported by this class?
* @tparam T Character type (char for UTF-8; wchar_t for Windows UTF-16)
* @param path Directory to check
* @param filenames_to_check Array of filenames to check
* @return True if all files are found; false if at least one file is missing.
*/
template<typename T>
static bool T_isDirSupported_static(const T *path, const std::array<const T*, 3> &filenames_to_check);

#ifdef ENABLE_XML
private:
/**
Expand Down
Loading

0 comments on commit 3dc6b90

Please sign in to comment.