From 44aaa7ee7deab6cb2916c37ed195df648aa859f8 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 17 Sep 2024 02:18:51 +0200 Subject: [PATCH] Qt: Add a permission error dialog when converting memorycards in a R/O directory --- .../scripts/linux/build-dependencies-qt.sh | 2 +- pcsx2-qt/Settings/MemoryCardConvertDialog.cpp | 41 ++++++++++++++----- pcsx2-qt/Settings/MemoryCardConvertDialog.h | 1 + 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/.github/workflows/scripts/linux/build-dependencies-qt.sh b/.github/workflows/scripts/linux/build-dependencies-qt.sh index f9054b4e5d55d..245ed95eebd88 100755 --- a/.github/workflows/scripts/linux/build-dependencies-qt.sh +++ b/.github/workflows/scripts/linux/build-dependencies-qt.sh @@ -51,7 +51,7 @@ aa27e4454ce631c5a17924ce0624eac736da19fc6f5a2ab15a6c58da7b36950f shaderc-glslan 03ee1a2c06f3b61008478f4abe9423454e53e580b9488b47c8071547c6a9db47 shaderc-spirv-tools-$SHADERC_SPIRVTOOLS.tar.gz EOF -curl -C - -L \ +curl -L \ -O "https://github.com/ianlancetaylor/libbacktrace/archive/$LIBBACKTRACE.zip" \ -O "https://ijg.org/files/jpegsrc.v$LIBJPEG.tar.gz" \ -O "https://downloads.sourceforge.net/project/libpng/libpng16/$LIBPNG/libpng-$LIBPNG.tar.xz" \ diff --git a/pcsx2-qt/Settings/MemoryCardConvertDialog.cpp b/pcsx2-qt/Settings/MemoryCardConvertDialog.cpp index ab37b9d360736..7bd6c20449d2b 100644 --- a/pcsx2-qt/Settings/MemoryCardConvertDialog.cpp +++ b/pcsx2-qt/Settings/MemoryCardConvertDialog.cpp @@ -8,6 +8,7 @@ #include #include "common/Console.h" +#include "common/Error.h" #include "common/Path.h" #include "common/StringUtil.h" @@ -36,7 +37,7 @@ MemoryCardConvertDialog::MemoryCardConvertDialog(QWidget* parent, QString select m_ui.progressBar->setRange(0, 100); m_ui.progressBar->setValue(0); - connect(m_ui.conversionTypeSelect, &QComboBox::currentIndexChanged, this, [this]() + connect(m_ui.conversionTypeSelect, &QComboBox::currentIndexChanged, this, [this]() { switch (m_srcCardInfo.type) { @@ -71,7 +72,7 @@ MemoryCardConvertDialog::MemoryCardConvertDialog(QWidget* parent, QString select } } ); - + disconnect(m_ui.buttonBox, &QDialogButtonBox::accepted, this, nullptr); connect(m_ui.buttonBox->button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &MemoryCardConvertDialog::ConvertCard); @@ -154,7 +155,7 @@ bool MemoryCardConvertDialog::SetupPicklist() for (auto dirEntry : rootDir) { const std::string_view fileName = Path::GetFileName(dirEntry.FileName); - + if (fileName.size() >= 7 && fileName.substr(0, 7).compare("_pcsx2_") == 0) { continue; @@ -176,7 +177,7 @@ bool MemoryCardConvertDialog::SetupPicklist() if (sizeBytes < CardCapacity::_8_MB) { m_ui.conversionTypeSelect->addItem(tr("8 MB File"), 8); - + if (!typeSet) { SetType_8(); @@ -187,7 +188,7 @@ bool MemoryCardConvertDialog::SetupPicklist() if (sizeBytes < CardCapacity::_16_MB) { m_ui.conversionTypeSelect->addItem(tr("16 MB File"), 16); - + if (!typeSet) { SetType_16(); @@ -198,7 +199,7 @@ bool MemoryCardConvertDialog::SetupPicklist() if (sizeBytes < CardCapacity::_32_MB) { m_ui.conversionTypeSelect->addItem(tr("32 MB File"), 32); - + if (!typeSet) { SetType_32(); @@ -209,7 +210,7 @@ bool MemoryCardConvertDialog::SetupPicklist() if (sizeBytes < CardCapacity::_64_MB) { m_ui.conversionTypeSelect->addItem(tr("64 MB File"), 64); - + if (!typeSet) { SetType_64(); @@ -242,7 +243,7 @@ void MemoryCardConvertDialog::ConvertCard() else { QString baseName = m_selectedCard; - + // Get our destination file name size_t extensionPos = baseName.lastIndexOf(".ps2", -1); // Strip the extension off of it @@ -253,7 +254,7 @@ void MemoryCardConvertDialog::ConvertCard() size_t num = 0; QString destName = baseName; destName.append(".ps2"); - + // If a match is found, revert back to the base name, add a number and the extension, and try again. // Keep incrementing the number until we get a unique result. while (m_srcCardInfo.type == MemoryCardType::File ? FileSystem::DirectoryExists(Path::Combine(EmuFolders::MemoryCards, destName.toStdString()).c_str()) : FileSystem::FileExists(Path::Combine(EmuFolders::MemoryCards, destName.toStdString()).c_str())) @@ -261,7 +262,22 @@ void MemoryCardConvertDialog::ConvertCard() destName = baseName; destName.append(StringUtil::StdStringFromFormat("_%02zd.ps2", ++num).c_str()); } - + + // Check if we have write permission in the memory card directory + const std::string destPath = Path::Combine(EmuFolders::MemoryCards, destName.toStdString()); + Error error; + FILE* tmpFile = FileSystem::OpenCFile(destPath.c_str(), "w", &error); + if (tmpFile == nullptr) + { + FileOpenError(error.GetDescription().c_str()); + return; + } + else + { + fclose(tmpFile); + FileSystem::DeleteFilePath(destPath.c_str()); + } + m_destCardName = destName; StartThread(); } @@ -303,3 +319,8 @@ void MemoryCardConvertDialog::SetType_Folder() { SetType(MemoryCardType::Folder, MemoryCardFileType::Unknown, tr("Uses a folder on your PC filesystem, instead of a file. Infinite capacity, while keeping the same compatibility as an 8 MB Memory Card.")); } + +void MemoryCardConvertDialog::FileOpenError(const QString errmsg) +{ + QMessageBox::critical(this, tr("Cannot Convert Memory Card"),tr("There was an error when accessing the memory card directory. Error message: %0").arg(errmsg)); +} diff --git a/pcsx2-qt/Settings/MemoryCardConvertDialog.h b/pcsx2-qt/Settings/MemoryCardConvertDialog.h index 5e876b6fdee04..625adbbf3dbae 100644 --- a/pcsx2-qt/Settings/MemoryCardConvertDialog.h +++ b/pcsx2-qt/Settings/MemoryCardConvertDialog.h @@ -41,6 +41,7 @@ private Q_SLOTS: void SetType_32(); void SetType_64(); void SetType_Folder(); + void FileOpenError(const QString errmsg); Ui::MemoryCardConvertDialog m_ui;