IFileSystem *MetaFileSystem::GetSystem(const std::string &prefix) { for (auto it = fileSystems.begin(); it != fileSystems.end(); ++it) { if (it->prefix == NormalizePrefix(prefix)) return it->system; } return NULL; }
static void MyReg_DeleteVal_Path_if_Equal(HKEY hKey, LPCWSTR name) { WCHAR s[MAX_PATH + 10]; if (MyRegistry_QueryString(hKey, name, s)) { NormalizePrefix(s); if (AreStringsEqual_NoCase(s, path)) RegDeleteValueW(hKey, name); } }
bool MetaFileSystem::MapFilePath(const std::string &_inpath, std::string &outpath, MountPoint **system) { lock_guard guard(lock); std::string realpath; std::string inpath = _inpath; // "ms0:/file.txt" is equivalent to " ms0:/file.txt". Yes, really. if (inpath.find(':') != inpath.npos) { size_t offset = 0; while (inpath[offset] == ' ') { offset++; } if (offset > 0) { inpath = inpath.substr(offset); } } // Special handling: host0:command.txt (as seen in Super Monkey Ball Adventures, for example) // appears to mean the current directory on the UMD. Let's just assume the current directory. if (strncasecmp(inpath.c_str(), "host0:", strlen("host0:")) == 0) { INFO_LOG(FILESYS, "Host0 path detected, stripping: %s", inpath.c_str()); inpath = inpath.substr(strlen("host0:")); } const std::string *currentDirectory = &startingDirectory; int currentThread = __KernelGetCurThread(); currentDir_t::iterator it = currentDir.find(currentThread); if (it == currentDir.end()) { //Attempt to emulate SCE_KERNEL_ERROR_NOCWD / 8002032C: may break things requiring fixes elsewhere if (inpath.find(':') == std::string::npos /* means path is relative */) { lastOpenError = SCE_KERNEL_ERROR_NOCWD; WARN_LOG(FILESYS, "Path is relative, but current directory not set for thread %i. returning 8002032C(SCE_KERNEL_ERROR_NOCWD) instead.", currentThread); } } else { currentDirectory = &(it->second); } if ( RealPath(*currentDirectory, inpath, realpath) ) { std::string prefix = realpath; size_t prefixPos = realpath.find(':'); if (prefixPos != realpath.npos) prefix = NormalizePrefix(realpath.substr(0, prefixPos + 1)); for (size_t i = 0; i < fileSystems.size(); i++) { size_t prefLen = fileSystems[i].prefix.size(); if (strncasecmp(fileSystems[i].prefix.c_str(), prefix.c_str(), prefLen) == 0) { outpath = realpath.substr(prefixPos + 1); *system = &(fileSystems[i]); VERBOSE_LOG(FILESYS, "MapFilePath: mapped \"%s\" to prefix: \"%s\", path: \"%s\"", inpath.c_str(), fileSystems[i].prefix.c_str(), outpath.c_str()); return true; } } } DEBUG_LOG(FILESYS, "MapFilePath: failed mapping \"%s\", returning false", inpath.c_str()); return false; }