Compare commits

..

1 Commits

Author SHA1 Message Date
Lioncash
15e0c4c4ec filesystem: Use a std::string_view in OpenFile()
Rather than make a full copy of the path, we can just use a string view
and truncate the viewed portion of the string instead of creating a totally
new truncated string.
2019-04-04 20:59:00 -04:00
2 changed files with 17 additions and 11 deletions

View File

@@ -197,13 +197,16 @@ ResultCode VfsDirectoryServiceWrapper::RenameDirectory(const std::string& src_pa
ResultVal<FileSys::VirtualFile> VfsDirectoryServiceWrapper::OpenFile(const std::string& path_,
FileSys::Mode mode) const {
std::string path(FileUtil::SanitizePath(path_));
auto npath = path;
while (npath.size() > 0 && (npath[0] == '/' || npath[0] == '\\'))
npath = npath.substr(1);
const std::string path(FileUtil::SanitizePath(path_));
std::string_view npath = path;
while (!npath.empty() && (npath[0] == '/' || npath[0] == '\\')) {
npath.remove_prefix(1);
}
auto file = backing->GetFileRelative(npath);
if (file == nullptr)
if (file == nullptr) {
return FileSys::ERROR_PATH_NOT_FOUND;
}
if (mode == FileSys::Mode::Append) {
return MakeResult<FileSys::VirtualFile>(

View File

@@ -1087,28 +1087,31 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target
void GMainWindow::OnTransferableShaderCacheOpenFile(u64 program_id) {
ASSERT(program_id != 0);
constexpr char open_target[] = "Transferable Shader Cache";
const QString tranferable_shader_cache_folder_path =
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir)) + "opengl" +
DIR_SEP + "transferable";
const QString transferable_shader_cache_file_path =
tranferable_shader_cache_folder_path + DIR_SEP +
QString::fromStdString(fmt::format("{:016X}.bin", program_id));
QString::fromStdString(fmt::format("{:016X}", program_id)) + ".bin";
if (!QFile::exists(transferable_shader_cache_file_path)) {
QMessageBox::warning(this, tr("Error Opening Transferable Shader Cache"),
tr("A shader cache for this title does not exist."));
if (!QFile(transferable_shader_cache_file_path).exists()) {
QMessageBox::warning(this,
tr("Error Opening %1 File").arg(QString::fromStdString(open_target)),
tr("File does not exist!"));
return;
}
LOG_INFO(Frontend, "Opening {} path for program_id={:016x}", open_target, program_id);
// Windows supports opening a folder with selecting a specified file in explorer. On every other
// OS we just open the transferable shader cache folder without preselecting the transferable
// shader cache file for the selected game.
#if defined(Q_OS_WIN)
const QString explorer = QStringLiteral("explorer");
const QString explorer = "explorer";
QStringList param;
if (!QFileInfo(transferable_shader_cache_file_path).isDir()) {
param << QStringLiteral("/select,");
param << QLatin1String("/select,");
}
param << QDir::toNativeSeparators(transferable_shader_cache_file_path);
QProcess::startDetached(explorer, param);