diff options
| author | 2018-10-26 19:28:47 -0400 | |
|---|---|---|
| committer | 2018-10-27 01:05:50 -0400 | |
| commit | 8eaf857d0605117350dfef13cbd68d53d7f76234 (patch) | |
| tree | 6cacd6287193d4cda1fb7789f7ac2d26a96cb75d /src | |
| parent | Merge pull request #1533 from FernandoS27/lmem (diff) | |
| download | yuzu-8eaf857d0605117350dfef13cbd68d53d7f76234.tar.gz yuzu-8eaf857d0605117350dfef13cbd68d53d7f76234.tar.xz yuzu-8eaf857d0605117350dfef13cbd68d53d7f76234.zip | |
configure_system: Display errors to the user if file operations fail when setting user images
We should display an error to the user if setting a user image for an
account fails, rather than continuing onwards.
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/configuration/configure_system.cpp | 70 |
1 files changed, 46 insertions, 24 deletions
diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index 20ffb0a9a..adb16de8a 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp | |||
| @@ -48,9 +48,10 @@ constexpr std::array<u8, 107> backup_jpeg{ | |||
| 48 | 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, | 48 | 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, |
| 49 | }; | 49 | }; |
| 50 | 50 | ||
| 51 | std::string GetImagePath(Service::Account::UUID uuid) { | 51 | QString GetImagePath(Service::Account::UUID uuid) { |
| 52 | return FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + | 52 | const auto path = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + |
| 53 | "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg"; | 53 | "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg"; |
| 54 | return QString::fromStdString(path); | ||
| 54 | } | 55 | } |
| 55 | 56 | ||
| 56 | std::string GetAccountUsername(const Service::Account::ProfileManager& manager, | 57 | std::string GetAccountUsername(const Service::Account::ProfileManager& manager, |
| @@ -63,6 +64,17 @@ std::string GetAccountUsername(const Service::Account::ProfileManager& manager, | |||
| 63 | return Common::StringFromFixedZeroTerminatedBuffer( | 64 | return Common::StringFromFixedZeroTerminatedBuffer( |
| 64 | reinterpret_cast<const char*>(profile.username.data()), profile.username.size()); | 65 | reinterpret_cast<const char*>(profile.username.data()), profile.username.size()); |
| 65 | } | 66 | } |
| 67 | |||
| 68 | QPixmap GetIcon(Service::Account::UUID uuid) { | ||
| 69 | QPixmap icon{GetImagePath(uuid)}; | ||
| 70 | |||
| 71 | if (!icon) { | ||
| 72 | icon.fill(Qt::black); | ||
| 73 | icon.loadFromData(backup_jpeg.data(), backup_jpeg.size()); | ||
| 74 | } | ||
| 75 | |||
| 76 | return icon; | ||
| 77 | } | ||
| 66 | } // Anonymous namespace | 78 | } // Anonymous namespace |
| 67 | 79 | ||
| 68 | ConfigureSystem::ConfigureSystem(QWidget* parent) | 80 | ConfigureSystem::ConfigureSystem(QWidget* parent) |
| @@ -131,18 +143,6 @@ void ConfigureSystem::setConfiguration() { | |||
| 131 | UpdateCurrentUser(); | 143 | UpdateCurrentUser(); |
| 132 | } | 144 | } |
| 133 | 145 | ||
| 134 | static QPixmap GetIcon(Service::Account::UUID uuid) { | ||
| 135 | const auto icon_url = QString::fromStdString(GetImagePath(uuid)); | ||
| 136 | QPixmap icon{icon_url}; | ||
| 137 | |||
| 138 | if (!icon) { | ||
| 139 | icon.fill(Qt::black); | ||
| 140 | icon.loadFromData(backup_jpeg.data(), backup_jpeg.size()); | ||
| 141 | } | ||
| 142 | |||
| 143 | return icon; | ||
| 144 | } | ||
| 145 | |||
| 146 | void ConfigureSystem::PopulateUserList() { | 146 | void ConfigureSystem::PopulateUserList() { |
| 147 | const auto& profiles = profile_manager->GetAllUsers(); | 147 | const auto& profiles = profile_manager->GetAllUsers(); |
| 148 | for (const auto& user : profiles) { | 148 | for (const auto& user : profiles) { |
| @@ -325,24 +325,46 @@ void ConfigureSystem::SetUserImage() { | |||
| 325 | const auto index = tree_view->currentIndex().row(); | 325 | const auto index = tree_view->currentIndex().row(); |
| 326 | const auto uuid = profile_manager->GetUser(index); | 326 | const auto uuid = profile_manager->GetUser(index); |
| 327 | ASSERT(uuid != std::nullopt); | 327 | ASSERT(uuid != std::nullopt); |
| 328 | const auto username = GetAccountUsername(*profile_manager, *uuid); | ||
| 329 | 328 | ||
| 330 | const auto file = QFileDialog::getOpenFileName(this, tr("Select User Image"), QString(), | 329 | const auto file = QFileDialog::getOpenFileName(this, tr("Select User Image"), QString(), |
| 331 | tr("JPEG Images (*.jpg *.jpeg)")); | 330 | tr("JPEG Images (*.jpg *.jpeg)")); |
| 332 | 331 | ||
| 333 | if (file.isEmpty()) | 332 | if (file.isEmpty()) { |
| 334 | return; | 333 | return; |
| 334 | } | ||
| 335 | 335 | ||
| 336 | FileUtil::Delete(GetImagePath(*uuid)); | 336 | const auto image_path = GetImagePath(*uuid); |
| 337 | if (QFile::exists(image_path) && !QFile::remove(image_path)) { | ||
| 338 | QMessageBox::warning( | ||
| 339 | this, tr("Error deleting image"), | ||
| 340 | tr("Error occurred attempting to overwrite previous image at: %1.").arg(image_path)); | ||
| 341 | return; | ||
| 342 | } | ||
| 337 | 343 | ||
| 338 | const auto raw_path = | 344 | const auto raw_path = QString::fromStdString( |
| 339 | FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + "/system/save/8000000000000010"; | 345 | FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + "/system/save/8000000000000010"); |
| 340 | if (FileUtil::Exists(raw_path) && !FileUtil::IsDirectory(raw_path)) | 346 | const QFileInfo raw_info{raw_path}; |
| 341 | FileUtil::Delete(raw_path); | 347 | if (raw_info.exists() && !raw_info.isDir() && !QFile::remove(raw_path)) { |
| 348 | QMessageBox::warning(this, tr("Error deleting file"), | ||
| 349 | tr("Unable to delete existing file: %1.").arg(raw_path)); | ||
| 350 | return; | ||
| 351 | } | ||
| 342 | 352 | ||
| 343 | FileUtil::CreateFullPath(GetImagePath(*uuid)); | 353 | const QString absolute_dst_path = QFileInfo{image_path}.absolutePath(); |
| 344 | FileUtil::Copy(file.toStdString(), GetImagePath(*uuid)); | 354 | if (!QDir{raw_path}.mkpath(absolute_dst_path)) { |
| 355 | QMessageBox::warning( | ||
| 356 | this, tr("Error creating user image directory"), | ||
| 357 | tr("Unable to create directory %1 for storing user images.").arg(absolute_dst_path)); | ||
| 358 | return; | ||
| 359 | } | ||
| 345 | 360 | ||
| 361 | if (!QFile::copy(file, image_path)) { | ||
| 362 | QMessageBox::warning(this, tr("Error copying user image"), | ||
| 363 | tr("Unable to copy image from %1 to %2").arg(file, image_path)); | ||
| 364 | return; | ||
| 365 | } | ||
| 366 | |||
| 367 | const auto username = GetAccountUsername(*profile_manager, *uuid); | ||
| 346 | item_model->setItem( | 368 | item_model->setItem( |
| 347 | index, 0, | 369 | index, 0, |
| 348 | new QStandardItem{ | 370 | new QStandardItem{ |