ff::String ff::Module::GetPath() const { #if METRO_APP // Assume that the name is a DLL in the application directory Windows::ApplicationModel::Package ^package = Windows::ApplicationModel::Package::Current; String path = String::from_pstring(package->InstalledLocation->Path); AppendPathTail(path, _name); ChangePathExtension(path, ff::String(L"dll")); assert(FileExists(path)); return path; #else assert(_instance != nullptr); return GetModulePath(_instance); #endif }
ff::String ff::CleanFileName(StringRef name) { String szNewName(name); for (size_t i = PreviousSize(szNewName.length()); i != INVALID_SIZE; i = PreviousSize(i)) { wchar_t ch = szNewName[i]; if (ch == '.' && (i == szNewName.length() - 1 || (i > 0 && szNewName[i - 1] == '.'))) { // Don't allow more than one period in a row, // and don't allow a period at the end szNewName.erase(i, 1); } else if (ch < 32 || ch > 125) { szNewName[i] = '-'; } else switch (ch) { case '<': szNewName[i] = '('; break; case '>': szNewName[i] = ')'; break; case ':': szNewName[i] = '-'; break; case '\"': szNewName[i] = '\''; break; case '/': szNewName[i] = '-'; break; case '\\': szNewName[i] = '-'; break; case '|': szNewName[i] = '-'; break; case '?': szNewName[i] = '-'; break; case '*': szNewName[i] = '-'; break; } } String szExt = GetPathExtension(szNewName); ChangePathExtension(szNewName, GetEmptyString()); if (!_wcsicmp(szNewName.c_str(), L"CON") || !_wcsicmp(szNewName.c_str(), L"PRN") || !_wcsicmp(szNewName.c_str(), L"AUX") || !_wcsicmp(szNewName.c_str(), L"NUL") || !_wcsicmp(szNewName.c_str(), L"COM1") || !_wcsicmp(szNewName.c_str(), L"COM2") || !_wcsicmp(szNewName.c_str(), L"COM3") || !_wcsicmp(szNewName.c_str(), L"COM4") || !_wcsicmp(szNewName.c_str(), L"COM5") || !_wcsicmp(szNewName.c_str(), L"COM6") || !_wcsicmp(szNewName.c_str(), L"COM7") || !_wcsicmp(szNewName.c_str(), L"COM8") || !_wcsicmp(szNewName.c_str(), L"COM9") || !_wcsicmp(szNewName.c_str(), L"LPT1") || !_wcsicmp(szNewName.c_str(), L"LPT2") || !_wcsicmp(szNewName.c_str(), L"LPT3") || !_wcsicmp(szNewName.c_str(), L"LPT4") || !_wcsicmp(szNewName.c_str(), L"LPT5") || !_wcsicmp(szNewName.c_str(), L"LPT6") || !_wcsicmp(szNewName.c_str(), L"LPT7") || !_wcsicmp(szNewName.c_str(), L"LPT8") || !_wcsicmp(szNewName.c_str(), L"LPT9")) { szNewName += L"-File"; } ChangePathExtension(szNewName, szExt); return szNewName; }