mirror of
https://github.com/J-D-K/JKSV.git
synced 2026-04-25 07:57:04 -05:00
Fix potential crash and typo in remote::Storage.
This commit is contained in:
parent
85dfaa73b9
commit
781df01d1c
|
|
@ -9,6 +9,7 @@
|
|||
#include "ui/ui.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
/// @brief This is the state where the user can backup and restore saves.
|
||||
class BackupMenuState final : public BaseState
|
||||
|
|
@ -113,6 +114,9 @@ class BackupMenuState final : public BaseState
|
|||
/// @brief The menu used by all instances of BackupMenuState.
|
||||
static inline std::shared_ptr<ui::Menu> sm_backupMenu{};
|
||||
|
||||
/// @brief Prevents this and threads calling refresh() from causing races.
|
||||
static inline std::mutex sm_menuMutex{};
|
||||
|
||||
/// @brief The slide out panel used by all instances of BackupMenuState.
|
||||
static inline std::shared_ptr<ui::SlideOutPanel> sm_slidePanel{};
|
||||
|
||||
|
|
|
|||
|
|
@ -52,6 +52,8 @@ void BackupMenuState::update()
|
|||
sm_slidePanel->update(hasFocus);
|
||||
if (!isOpen) { return; }
|
||||
|
||||
std::lock_guard menuGuard{sm_menuMutex};
|
||||
|
||||
const int selected = sm_backupMenu->get_selected();
|
||||
const bool aPressed = input::button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input::button_pressed(HidNpadButton_B);
|
||||
|
|
@ -75,7 +77,6 @@ void BackupMenuState::update()
|
|||
else if (popEmpty) { BackupMenuState::pop_save_empty(); }
|
||||
else if (bPressed) { sm_slidePanel->close(); }
|
||||
else if (sm_slidePanel->is_closed()) { BackupMenuState::deactivate_state(); }
|
||||
|
||||
sm_backupMenu->update(hasFocus);
|
||||
}
|
||||
|
||||
|
|
@ -104,6 +105,9 @@ void BackupMenuState::refresh()
|
|||
|
||||
m_directoryListing.open(m_directoryPath);
|
||||
if (!autoUpload && !m_directoryListing.is_open()) { return; }
|
||||
|
||||
std::lock_guard menuGuard{sm_menuMutex};
|
||||
|
||||
sm_backupMenu->reset();
|
||||
m_menuEntries.clear();
|
||||
|
||||
|
|
|
|||
|
|
@ -157,13 +157,17 @@ void FileModeState::enter_selected(fslib::Path &path, fslib::Directory &director
|
|||
{
|
||||
const int selected = menu.get_selected();
|
||||
|
||||
if (selected == 0) { return; }
|
||||
else if (selected == 1) { FileModeState::up_one_directory(path, directory, menu); }
|
||||
else
|
||||
switch (selected)
|
||||
{
|
||||
const int dirIndex = selected - 2;
|
||||
const fslib::DirectoryEntry &entry = directory[dirIndex];
|
||||
if (entry.is_directory()) { FileModeState::enter_directory(path, directory, menu, entry); }
|
||||
case 0: return;
|
||||
case 1: FileModeState::up_one_directory(path, directory, menu); break;
|
||||
default:
|
||||
{
|
||||
const int dirIndex = selected - 2;
|
||||
const fslib::DirectoryEntry &entry = directory[dirIndex];
|
||||
if (entry.is_directory()) { FileModeState::enter_directory(path, directory, menu, entry); }
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include "fs/fs.hpp"
|
||||
#include "graphics/colors.hpp"
|
||||
#include "graphics/gfxutil.hpp"
|
||||
#include "logging/logger.hpp"
|
||||
#include "sdl.hpp"
|
||||
#include "stringutil.hpp"
|
||||
|
||||
|
|
@ -202,6 +203,8 @@ void data::User::load_user_data()
|
|||
|
||||
void data::User::load_icon()
|
||||
{
|
||||
const std::string iconName =
|
||||
stringutil::get_formatted_string("%016llX%016llX", m_nickname, m_accountID.uid[0], m_accountID.uid[1]);
|
||||
if (m_saveType == FsSaveDataType_Account)
|
||||
{
|
||||
uint32_t iconSize{};
|
||||
|
|
@ -219,9 +222,9 @@ void data::User::load_icon()
|
|||
if (loadError) { return; }
|
||||
|
||||
accountProfileClose(&profile);
|
||||
m_icon = sdl::TextureManager::load(m_nickname, iconBuffer.get(), iconSize);
|
||||
m_icon = sdl::TextureManager::load(iconName, iconBuffer.get(), iconSize);
|
||||
}
|
||||
else { m_icon = gfxutil::create_generic_icon(m_nickname, SIZE_ICON_FONT, colors::DIALOG_DARK, colors::WHITE); }
|
||||
else { m_icon = gfxutil::create_generic_icon(iconName, SIZE_ICON_FONT, colors::DIALOG_DARK, colors::WHITE); }
|
||||
}
|
||||
|
||||
void data::User::load_account(AccountProfile &profile, AccountProfileBase &profileBase)
|
||||
|
|
|
|||
|
|
@ -105,7 +105,8 @@ remote::Storage::List::iterator remote::Storage::find_directory_by_id(std::strin
|
|||
auto is_match = [&](const Item &item) noexcept
|
||||
{
|
||||
const bool isDir = item.is_directory();
|
||||
const bool idMatch = item.get_id() == id;
|
||||
const bool idMatch = isDir && item.get_id() == id;
|
||||
|
||||
return isDir && idMatch;
|
||||
};
|
||||
|
||||
|
|
@ -117,7 +118,7 @@ remote::Storage::List::const_iterator remote::Storage::find_directory_by_id(std:
|
|||
auto is_match = [&](const Item &item) noexcept
|
||||
{
|
||||
const bool isDir = item.is_directory();
|
||||
const bool idMatch = item.get_id() == id;
|
||||
const bool idMatch = isDir && item.get_id() == id;
|
||||
|
||||
return isDir && idMatch;
|
||||
};
|
||||
|
|
@ -144,7 +145,7 @@ remote::Storage::List::const_iterator remote::Storage::find_file_by_name(std::st
|
|||
auto is_match = [&](const Item &item) noexcept
|
||||
{
|
||||
const bool isFile = !item.is_directory();
|
||||
const bool parentMatch = !isFile && item.get_parent_id() == m_parent;
|
||||
const bool parentMatch = isFile && item.get_parent_id() == m_parent;
|
||||
const bool nameMatch = parentMatch && item.get_name() == name;
|
||||
|
||||
return isFile && parentMatch && nameMatch;
|
||||
|
|
@ -158,7 +159,7 @@ remote::Storage::List::iterator remote::Storage::find_file_by_id(std::string_vie
|
|||
auto is_match = [&](const Item &item) noexcept
|
||||
{
|
||||
const bool isFile = !item.is_directory();
|
||||
const bool isMatch = item.get_id() == id;
|
||||
const bool isMatch = isFile && item.get_id() == id;
|
||||
|
||||
return isFile && isMatch;
|
||||
};
|
||||
|
|
@ -171,7 +172,7 @@ remote::Storage::List::const_iterator remote::Storage::find_file_by_id(std::stri
|
|||
auto is_match = [&](const remote::Item &item) noexcept
|
||||
{
|
||||
const bool isFile = !item.is_directory();
|
||||
const bool isMatch = item.get_id() == id;
|
||||
const bool isMatch = isFile && item.get_id() == id;
|
||||
|
||||
return isFile && isMatch;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user