Skip to content

Commit

Permalink
fs: added /download0 mount
Browse files Browse the repository at this point in the history
fs: get rid of double slashes
  • Loading branch information
raziel1000 committed Jul 26, 2024
1 parent 2841eba commit 600a13c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/common/path_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ static auto UserPaths = [] {
create_path(PathType::GameDataDir, user_dir / GAMEDATA_DIR);
create_path(PathType::TempDataDir, user_dir / TEMPDATA_DIR);
create_path(PathType::SysModuleDir, user_dir / SYSMODULES_DIR);
create_path(PathType::DownloadDir, user_dir / DOWNLOAD_DIR);

return paths;
}();
Expand Down
2 changes: 2 additions & 0 deletions src/common/path_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum class PathType {
TempDataDir, // Where game temp data is stored.
GameDataDir, // Where game data is stored.
SysModuleDir, // Where system modules are stored.
DownloadDir, // Where downloads/temp files are stored.
};

constexpr auto PORTABLE_DIR = "user";
Expand All @@ -31,6 +32,7 @@ constexpr auto SAVEDATA_DIR = "savedata";
constexpr auto GAMEDATA_DIR = "data";
constexpr auto TEMPDATA_DIR = "temp";
constexpr auto SYSMODULES_DIR = "sys_modules";
constexpr auto DOWNLOAD_DIR = "download";

// Filenames
constexpr auto LOG_FILE = "shad_log.txt";
Expand Down
22 changes: 13 additions & 9 deletions src/core/file_sys/fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,27 @@ void MntPoints::UnmountAll() {
}

std::filesystem::path MntPoints::GetHostPath(const std::string& guest_directory) {
const MntPair* mount = GetMount(guest_directory);
// Evil games like Turok2 pass double slashes e.g /app0//game.kpf
auto corrected_path = guest_directory;
size_t pos = corrected_path.find("//");
while (pos != std::string::npos) {
corrected_path.replace(pos, 2, "/");
pos = corrected_path.find("//", pos + 1);
}

const MntPair* mount = GetMount(corrected_path);
if (!mount) {
return guest_directory;
return "";
}

// Nothing to do if getting the mount itself.
if (guest_directory == mount->mount) {
if (corrected_path == mount->mount) {
return mount->host_path;
}

// Remove device (e.g /app0) from path to retrieve relative path.
u32 pos = mount->mount.size() + 1;
// Evil games like Turok2 pass double slashes e.g /app0//game.kpf
if (guest_directory[pos] == '/') {
pos++;
}
const auto rel_path = std::string_view(guest_directory).substr(pos);
pos = mount->mount.size() + 1;
const auto rel_path = std::string_view(corrected_path).substr(pos);
const auto host_path = mount->host_path / rel_path;
if (!NeedsCaseInsensiveSearch) {
return host_path;
Expand Down
7 changes: 7 additions & 0 deletions src/emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ void Emulator::Run(const std::filesystem::path& file) {
}
mnt->Mount(mount_temp_dir, "/temp0"); // called in app_content ==> stat/mkdir

const auto& mount_download_dir =
Common::FS::GetUserPath(Common::FS::PathType::DownloadDir) / id;
if (!std::filesystem::exists(mount_download_dir)) {
std::filesystem::create_directory(mount_download_dir);
}
mnt->Mount(mount_download_dir, "/download0");

// Initialize kernel and library facilities.
Libraries::Kernel::init_pthreads();
Libraries::InitHLELibs(&linker->GetHLESymbols());
Expand Down

0 comments on commit 600a13c

Please sign in to comment.