Compare commits

..

No commits in common. "6e3e2400fb717b75bf6936416c2a509201fa7f01" and "e9ce1d99fef243557dcdf3a0f06ea3476f9baa9d" have entirely different histories.

2 changed files with 18 additions and 50 deletions

View File

@ -11,13 +11,7 @@
#include "common/Path.h"
#include "common/StringUtil.h"
// Platform-specific includes
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#include <sys/stat.h>
#endif
#include <unistd.h>
MemoryCardConvertDialog::MemoryCardConvertDialog(QWidget* parent, QString selectedCard)
: QDialog(parent)
@ -44,7 +38,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)
{
@ -79,7 +73,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);
@ -162,7 +156,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;
@ -184,7 +178,7 @@ bool MemoryCardConvertDialog::SetupPicklist()
if (sizeBytes < CardCapacity::_8_MB)
{
m_ui.conversionTypeSelect->addItem(tr("8 MB File"), 8);
if (!typeSet)
{
SetType_8();
@ -195,7 +189,7 @@ bool MemoryCardConvertDialog::SetupPicklist()
if (sizeBytes < CardCapacity::_16_MB)
{
m_ui.conversionTypeSelect->addItem(tr("16 MB File"), 16);
if (!typeSet)
{
SetType_16();
@ -206,7 +200,7 @@ bool MemoryCardConvertDialog::SetupPicklist()
if (sizeBytes < CardCapacity::_32_MB)
{
m_ui.conversionTypeSelect->addItem(tr("32 MB File"), 32);
if (!typeSet)
{
SetType_32();
@ -217,7 +211,7 @@ bool MemoryCardConvertDialog::SetupPicklist()
if (sizeBytes < CardCapacity::_64_MB)
{
m_ui.conversionTypeSelect->addItem(tr("64 MB File"), 64);
if (!typeSet)
{
SetType_64();
@ -250,7 +244,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
@ -266,34 +260,14 @@ void MemoryCardConvertDialog::ConvertCard()
QDir destinationDir(fullPath);
QString absolutePath = destinationDir.absolutePath(); // Get the absolute path
// Check for read/write/execute permissions on the directory
// We only need to check the parent directory where the file will be created
QFileInfo dirInfo(destinationDir.absolutePath());
QString dirPath = dirInfo.absolutePath();
#ifdef _WIN32
// Windows systems
DWORD fileAttributes = GetFileAttributes(dirPath.toStdString().c_str());
// Windows has no direct R/W/X permission model like Linux. We check for basic file existence.
bool canRead = !(fileAttributes & FILE_ATTRIBUTE_READONLY);
bool canWrite = true; // If not read-only, assume write is possible.
if !(canRead && canWrite)
{
PermissionError(absolutePath);
return;
}
#else
// Linux/Unix systems
if (access(dirPath.toStdString().c_str(), R_OK | W_OK | X_OK) != 0)
{
PermissionError(absolutePath);
return;
}
#endif
if (access(absolutePath.toStdString().c_str(), R_OK | W_OK | X_OK) != 0)
{
QMessageBox::critical(this, tr("Cannot Convert Memory Card"),
tr("You have insufficient permissions to convert this Memory Card. Please ensure that your user owns the directory of your Memory Cards. \n \"%1\".")
.arg(absolutePath));
return;
}
// 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()))
@ -301,7 +275,7 @@ void MemoryCardConvertDialog::ConvertCard()
destName = baseName;
destName.append(StringUtil::StdStringFromFormat("_%02zd.ps2", ++num).c_str());
}
m_destCardName = destName;
StartThread();
}
@ -343,8 +317,3 @@ 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::PermissionError(QString absolutePath)
{
QMessageBox::critical(this, tr("Cannot Convert Memory Card"),tr("You have insufficient permissions to convert this Memory Card. Please ensure that your user owns the directory of your Memory Cards. \n \"%1\".").arg(absolutePath));
}

View File

@ -41,7 +41,6 @@ private:
void SetType_32();
void SetType_64();
void SetType_Folder();
void PermissionError(QString absolutePath);
Ui::MemoryCardConvertDialog m_ui;