diff --git a/include/JKSV.hpp b/include/JKSV.hpp index f8fbbb5..cc2fe2f 100644 --- a/include/JKSV.hpp +++ b/include/JKSV.hpp @@ -17,7 +17,7 @@ class JKSV /// @brief Returns if initializing was successful and JKSV is running. /// @return True or false. - bool is_running() const; + bool is_running() const noexcept; /// @brief Runs JKSV's update routine. void update(); diff --git a/include/appstates/BaseState.hpp b/include/appstates/BaseState.hpp index 679fe70..264f013 100644 --- a/include/appstates/BaseState.hpp +++ b/include/appstates/BaseState.hpp @@ -48,7 +48,7 @@ class BaseState private: /// @brief Stores whether or not the state is currently active. - bool m_isActive = true; + bool m_isActive{true}; /// @brief Stores whether or not the state has focus. bool m_hasFocus{}; diff --git a/include/appstates/FileModeState.hpp b/include/appstates/FileModeState.hpp index 934910b..a801291 100644 --- a/include/appstates/FileModeState.hpp +++ b/include/appstates/FileModeState.hpp @@ -38,23 +38,8 @@ class FileModeState final : public BaseState /// @brief Render override. void render() override; - /// @brief Returns the target/active bool. - bool get_target() const noexcept; - - /// @brief Returns the source path. This is used with the FileOptionState. - fslib::Path get_source(); - - /// @brief Returns the destination path. This is used with the FileOptionState. - fslib::Path get_destination(); - - /// @brief Returns whether or not committing the transfer is required to FileOptionState. - bool commit_required() const noexcept; - - /// @brief Returns the journaling size passed to this for FileOptionState. - int64_t get_journal_size() const noexcept; - - /// @brief Renders the control guide in the bottom right. - void render_control_guide() noexcept; + /// @brief This thing is a headache without this. + friend class FileOptionState; private: /// @brief These store the mount points to close the filesystems upon construction. @@ -146,6 +131,9 @@ class FileModeState final : public BaseState ui::Menu &menu, const fslib::DirectoryEntry &entry); + /// @brief Renders the control guide string on the bottom of the screen. + void render_control_guide(); + /// @brief Returns a reference to the currently active menu. ui::Menu &get_source_menu() noexcept; diff --git a/include/appstates/FileOptionState.hpp b/include/appstates/FileOptionState.hpp index 1bd558b..46ebea1 100644 --- a/include/appstates/FileOptionState.hpp +++ b/include/appstates/FileOptionState.hpp @@ -5,6 +5,8 @@ #include "fslib.hpp" #include "ui/ui.hpp" +#include + class FileOptionState final : public BaseState { public: @@ -34,12 +36,19 @@ class FileOptionState final : public BaseState /// @brief Render routine. void render() override; + /// @brief Signals to this state to update the source/target menu on the next update() call. + void update_source(); + + /// @brief Signals to this state to update the destination. Very rarely used. + void update_destination(); + // clang-format off struct DataStruct { fslib::Path sourcePath{}; fslib::Path destPath{}; int64_t journalSize{}; + FileOptionState *spawningState{}; }; // clang-format on @@ -50,12 +59,6 @@ class FileOptionState final : public BaseState /// @brief Pointer to spawning FileMode state. FileModeState *m_spawningState{}; - /// @brief Stores whether or not tasks require committing data and changes to the target. - bool m_commitData{}; - - /// @brief Journal size for when committing is required. - int64_t m_journalSize{}; - /// @brief X coordinate. This is set at construction according to the target from the spawning state. int m_x{}; @@ -68,8 +71,9 @@ class FileOptionState final : public BaseState /// @brief Whether or not the state should be closed. bool m_close{}; - /// @brief This holds the scaling in config. - double m_scaling{}; + /// @brief Stores whether or not an update is needed on the next update(). + std::atomic m_updateSource{}; + std::atomic m_updateDest{}; /// @brief This is the data struct passed to tasks. std::shared_ptr m_dataStruct{}; @@ -86,17 +90,31 @@ class FileOptionState final : public BaseState /// @brief Sets whether the dialog/menu are positioned left or right depending on the menu active in the spawning state. void set_menu_side(); + /// @brief Assigns the pointer to this. + void initialize_data_struct(); + + /// @brief Updates the FileModeState's source data. + void update_filemode_source(); + + /// @brief Updates the FileModeState's destination data. + void update_filemode_dest(); + /// @brief Updates the Y coordinate void update_x_coord(); + /// @brief Sets up and begins the copy task. void copy_target(); + /// @brief Sets up and begins the delete task. void delete_target(); + /// @brief Attempts to rename the target. void rename_target(); + /// @brief Attempts to create a new directory. void create_directory(); + /// @brief Gets the properties of a file/folder. void get_show_target_properties(); /// @brief Closes and hides the state. diff --git a/include/config/ConfigContext.hpp b/include/config/ConfigContext.hpp index dc615e0..b066d2f 100644 --- a/include/config/ConfigContext.hpp +++ b/include/config/ConfigContext.hpp @@ -27,52 +27,52 @@ namespace config void save(); /// @brief Attempts to find and return the value of the key passed. - uint8_t get_by_key(std::string_view key) const; + uint8_t get_by_key(std::string_view key) const noexcept; /// @brief Attempts to toggle the value for the key passed. For simple 1 and 0. - void toggle_by_key(std::string_view key); + void toggle_by_key(std::string_view key) noexcept; /// @brief Attempts to set the key passed to the value passd. - void set_by_key(std::string_view key, uint8_t value); + void set_by_key(std::string_view key, uint8_t value) noexcept; /// @brief Returns the current working directory. fslib::Path get_working_directory() const; /// @brief Sets the current work directory if the path passed is valid. - bool set_working_directory(const fslib::Path &workDir); + bool set_working_directory(const fslib::Path &workDir) noexcept; /// @brief Returns the transition scaling speed. - double get_animation_scaling() const; + double get_animation_scaling() const noexcept; /// @brief Sets the current animation scaling speed. - void set_animation_scaling(double scaling); + void set_animation_scaling(double scaling) noexcept; /// @brief Adds a favorite to the favorite titles. void add_favorite(uint64_t applicationID); /// @brief Removes a title from the favorites. - void remove_favorite(uint64_t applicationID); + void remove_favorite(uint64_t applicationID) noexcept; /// @brief Returns if the application ID passed is a favorite. - bool is_favorite(uint64_t applicationID) const; + bool is_favorite(uint64_t applicationID) const noexcept; /// @brief Adds the application ID passed to the blacklist. void add_to_blacklist(uint64_t applicationID); /// @brief Removes the application ID passed from the blacklist. - void remove_from_blacklist(uint64_t applicationID); + void remove_from_blacklist(uint64_t applicationID) noexcept; /// @brief Writes all of the currently blacklisted titles to the vector passed. void get_blacklist(std::vector &listOut); /// @brief Returns if the application ID passed is found in the blacklist. - bool is_blacklisted(uint64_t applicationID) const; + bool is_blacklisted(uint64_t applicationID) const noexcept; /// @brief Returns if the blacklist is empty. - bool blacklist_empty() const; + bool blacklist_empty() const noexcept; /// @brief Returns if the application ID passed has a custom output path. - bool has_custom_path(uint64_t applicationID) const; + bool has_custom_path(uint64_t applicationID) const noexcept; /// @brief Adds a new output path. void add_custom_path(uint64_t applicationID, std::string_view newPath); diff --git a/include/config/config.hpp b/include/config/config.hpp index 0d5ac8c..d7525db 100644 --- a/include/config/config.hpp +++ b/include/config/config.hpp @@ -19,16 +19,16 @@ namespace config /// @brief Retrieves the config value according to the key passed. /// @param key Key to retrieve. See config::keys /// @return Key's value if found. 0 if it is not. - uint8_t get_by_key(std::string_view key); + uint8_t get_by_key(std::string_view key) noexcept; /// @brief Toggles the key. This is only for basic true or false settings. /// @param key Key to toggle. - void toggle_by_key(std::string_view key); + void toggle_by_key(std::string_view key) noexcept; /// @brief Sets the key according /// @param key Key to set. /// @param value Value to set the key to. - void set_by_key(std::string_view key, uint8_t value); + void set_by_key(std::string_view key, uint8_t value) noexcept; /// @brief Returns the working directory. /// @return Working directory. @@ -36,15 +36,15 @@ namespace config /// @brief Attempts to set the working directory to the one passed. /// @param path Path for JKSV to use. - bool set_working_directory(const fslib::Path &path); + bool set_working_directory(const fslib::Path &path) noexcept; /// @brief Returns the scaling speed of UI transitions and animations. /// @return Scaling variable. - double get_animation_scaling(); + double get_animation_scaling() noexcept; /// @brief Sets the UI animation scaling. /// @param newScale New value to set the scaling to. - void set_animation_scaling(double newScale); + void set_animation_scaling(double newScale) noexcept; /// @brief Adds or removes a title from the favorites list. /// @param applicationID Application ID of title to add or remove. @@ -53,11 +53,11 @@ namespace config /// @brief Returns if the title is found in the favorites list. /// @param applicationID Application ID to search for. /// @return True if found. False if not. - bool is_favorite(uint64_t applicationID); + bool is_favorite(uint64_t applicationID) noexcept; /// @brief Adds or removes title from blacklist. /// @param applicationID Application ID to add or remove. - void add_remove_blacklist(uint64_t applicationID); + void add_remove_blacklist(uint64_t applicationID) noexcept; /// @brief Gets the currently blacklisted application IDs. /// @param listOut Vector to store application IDs to. @@ -66,10 +66,10 @@ namespace config /// @brief Returns if the title is found in the blacklist. /// @param applicationID Application ID to search for. /// @return True if found. False if not. - bool is_blacklisted(uint64_t applicationID); + bool is_blacklisted(uint64_t applicationID) noexcept; /// @brief Returns whether or not the blacklist is empty. - bool blacklist_is_empty(); + bool blacklist_is_empty() noexcept; /// @brief Adds a custom output path for the title. /// @param applicationID Application ID of title to add a path for. @@ -79,7 +79,7 @@ namespace config /// @brief Searches to see if the application ID passed has a custom output path. /// @param applicationID Application ID to check. /// @return True if it does. False if it doesn't. - bool has_custom_path(uint64_t applicationID); + bool has_custom_path(uint64_t applicationID) noexcept; /// @brief Gets the custom, defined path for the title. /// @param applicationID Application ID of title to get. diff --git a/include/config/keys.hpp b/include/config/keys.hpp index b619659..2f2cb26 100644 --- a/include/config/keys.hpp +++ b/include/config/keys.hpp @@ -28,4 +28,4 @@ namespace config::keys inline constexpr std::string_view UI_ANIMATION_SCALE = "UIAnimationScaling"; inline constexpr std::string_view FAVORITES = "Favorites"; inline constexpr std::string_view BLACKLIST = "BlackList"; -} +} \ No newline at end of file diff --git a/include/curl/DownloadStruct.hpp b/include/curl/DownloadStruct.hpp index 419dc2c..e83292c 100644 --- a/include/curl/DownloadStruct.hpp +++ b/include/curl/DownloadStruct.hpp @@ -13,18 +13,25 @@ namespace curl { /// @brief Buffer mutex. std::mutex lock{}; + /// @brief Conditional for when the buffer is full. std::condition_variable condition{}; + /// @brief Shared buffer that is read into. std::vector sharedBuffer{}; + /// @brief Bool to signal when the buffer is ready/empty. bool bufferReady{}; + /// @brief Destination file to write to. fslib::File *dest{}; + /// @brief Optional. Task to update with progress. sys::ProgressTask *task{}; + /// @brief Current offset in the file. size_t offset{}; + /// @brief Size of the file being downloaded. int64_t fileSize{}; }; diff --git a/include/curl/UploadStruct.hpp b/include/curl/UploadStruct.hpp index e3dd921..0cadc8a 100644 --- a/include/curl/UploadStruct.hpp +++ b/include/curl/UploadStruct.hpp @@ -9,6 +9,7 @@ namespace curl { /// @brief Source file to upload from. fslib::File *source{}; + /// @brief Optional. Task to update with progress. sys::ProgressTask *task{}; }; diff --git a/include/data/DataContext.hpp b/include/data/DataContext.hpp index 93bb3aa..16ce0d7 100644 --- a/include/data/DataContext.hpp +++ b/include/data/DataContext.hpp @@ -35,7 +35,7 @@ namespace data void load_title(uint64_t applicationID); /// @brief Returns the title info mapped to applicationID. nullptr on not found. - data::TitleInfo *get_title_by_id(uint64_t applicationID); + data::TitleInfo *get_title_by_id(uint64_t applicationID) noexcept; /// @brief Gets a vector of pointers to all of the current title info instances. void get_title_info_list(data::TitleInfoList &listOut); diff --git a/include/data/TitleInfo.hpp b/include/data/TitleInfo.hpp index cd7831b..135b004 100644 --- a/include/data/TitleInfo.hpp +++ b/include/data/TitleInfo.hpp @@ -20,12 +20,12 @@ namespace data public: /// @brief Constructs a TitleInfo instance. Loads control data, icon. /// @param applicationID Application ID of title to load. - TitleInfo(uint64_t applicationID); + TitleInfo(uint64_t applicationID) noexcept; /// @brief Initializes a TitleInfo instance using external (cached) NsApplicationControlData /// @param applicationID Application ID of the title loaded from cache. /// @param controlData Reference to the control data to init from. - TitleInfo(uint64_t applicationID, NsApplicationControlData &controlData); + TitleInfo(uint64_t applicationID, NsApplicationControlData &controlData) noexcept; // None of this nonesense around these parts. TitleInfo(const TitleInfo &) = delete; @@ -33,63 +33,63 @@ namespace data /// @brief Returns the application ID of the title. /// @return Title's application ID. - uint64_t get_application_id() const; + uint64_t get_application_id() const noexcept; /// @brief Returns a pointer to the control data for the title. /// @return Pointer to control data. - NsApplicationControlData *get_control_data(); + const NsApplicationControlData *get_control_data() const noexcept; /// @brief Returns whether or not the title has control data. /// @return Whether or not the title has control data. - bool has_control_data() const; + bool has_control_data() const noexcept; /// @brief Returns the title of the title? /// @return Title directly from the NACP. - const char *get_title(); + const char *get_title() const noexcept; /// @brief Returns the path safe version of the title for file system usage. /// @return Path safe version of the title. - const char *get_path_safe_title() const; + const char *get_path_safe_title() const noexcept; /// @brief Returns the publisher of the title. /// @return Publisher string from NACP. - const char *get_publisher(); + const char *get_publisher() const noexcept; /// @brief Returns the owner ID of the save data. - uint64_t get_save_data_owner_id() const; + uint64_t get_save_data_owner_id() const noexcept; /// @brief Returns the save data container's base size. /// @param saveType Type of save data to return. /// @return Size of baseline save data if applicable. If not, 0. - int64_t get_save_data_size(uint8_t saveType) const; + int64_t get_save_data_size(uint8_t saveType) const noexcept; /// @brief Returns the maximum size of the save data container. /// @param saveType Type of save data to return. /// @return Maximum size of the save container if applicable. If not, 0. - int64_t get_save_data_size_max(uint8_t saveType) const; + int64_t get_save_data_size_max(uint8_t saveType) const noexcept; /// @brief Returns the journaling size for the save type passed. /// @param saveType Save type to return. /// @return Journal size if applicable. If not, 0. - int64_t get_journal_size(uint8_t saveType) const; + int64_t get_journal_size(uint8_t saveType) const noexcept; /// @brief Returns the maximum journal size for the save type passed. /// @param saveType Save type to return. /// @return Maximum journal size if applicable. If not, 0. - int64_t get_journal_size_max(uint8_t saveType) const; + int64_t get_journal_size_max(uint8_t saveType) const noexcept; /// @brief Returns if a title uses the save type passed. /// @param saveType Save type to check for. /// @return True on success. False on failure. - bool has_save_data_type(uint8_t saveType) const; + bool has_save_data_type(uint8_t saveType) const noexcept; /// @brief Returns a pointer to the icon texture. /// @return Icon - sdl::SharedTexture get_icon() const; + sdl::SharedTexture get_icon() const noexcept; /// @brief Allows the path safe title to be set to a new path. /// @param newPathSafe Buffer containing the new safe path to use. - void set_path_safe_title(const char *newPathSafe); + void set_path_safe_title(const char *newPathSafe) noexcept; /// @brief Loads the icon from the nacp. void load_icon() override; @@ -104,6 +104,9 @@ namespace data /// @brief Where all the good stuff is. NsApplicationControlData m_data{}; + /// @brief Stores the pointer to the language entry of the title. + NacpLanguageEntry *m_entry{}; + /// @brief Saves whether or not the title has control data. bool m_hasData{}; @@ -114,6 +117,6 @@ namespace data sdl::SharedTexture m_icon{}; /// @brief Private function to get/create the path safe title. - void get_create_path_safe_title(); + void get_create_path_safe_title() noexcept; }; } // namespace data diff --git a/include/data/User.hpp b/include/data/User.hpp index c5eb486..143036f 100644 --- a/include/data/User.hpp +++ b/include/data/User.hpp @@ -29,18 +29,21 @@ namespace data /// @brief Constructs a new user with accountID /// @param accountID AccountID of user. /// @param saveType Save data type account uses. - User(AccountUid accountID, FsSaveDataType saveType); + User(AccountUid accountID, FsSaveDataType saveType) noexcept; /// @brief This is the constructor used to create the fake system users. /// @param accountID AccountID to associate with saveType. /// @param pathSafeNickname The path safe version of the save data since JKSV is in everything the Switch supports. /// @param iconPath Path to the icon to load for account. /// @param saveType Save data type of user. - User(AccountUid accountID, std::string_view nickname, std::string_view pathSafeNickname, FsSaveDataType saveType); + User(AccountUid accountID, + std::string_view nickname, + std::string_view pathSafeNickname, + FsSaveDataType saveType) noexcept; /// @brief Move constructor and operator. - User(User &&user); - User &operator=(User &&user); + User(User &&user) noexcept; + User &operator=(User &&user) noexcept; // Non of this around these parts. User(const User &) = delete; @@ -52,47 +55,47 @@ namespace data void add_data(const FsSaveDataInfo *saveInfo, const PdmPlayStatistics *playStats); /// @brief Clears the user save info vector. - void clear_data_entries(); + void clear_data_entries() noexcept; /// @brief Erases data at index. /// @param index Index of save data info to erase. void erase_data(int index); /// @brief Runs the sort algo on the vector. - void sort_data(); + void sort_data() noexcept; /// @brief Returns the account ID of the user - AccountUid get_account_id() const; + AccountUid get_account_id() const noexcept; /// @brief Returns the primary save data type o - FsSaveDataType get_account_save_type() const; + FsSaveDataType get_account_save_type() const noexcept; /// @brief Returns the user's full UTF-8 nickname. - const char *get_nickname() const; + const char *get_nickname() const noexcept; /// @brief Returns the path safe version of the user's nickname. - const char *get_path_safe_nickname() const; + const char *get_path_safe_nickname() const noexcept; /// @brief Returns the total data entries. - size_t get_total_data_entries() const; + size_t get_total_data_entries() const noexcept; /// @brief Returns the application ID of the title at index. - uint64_t get_application_id_at(int index) const; + uint64_t get_application_id_at(int index) const noexcept; /// @brief Returns a pointer to the save data info at index. - FsSaveDataInfo *get_save_info_at(int index); + FsSaveDataInfo *get_save_info_at(int index) noexcept; /// @brief Returns a pointer to the play statistics at index. - PdmPlayStatistics *get_play_stats_at(int index); + PdmPlayStatistics *get_play_stats_at(int index) noexcept; /// @brief Returns a pointer to the save info of applicationID. - FsSaveDataInfo *get_save_info_by_id(uint64_t applicationID); + FsSaveDataInfo *get_save_info_by_id(uint64_t applicationID) noexcept; /// @brief Returns a reference to the internal map for range based loops. - data::UserSaveInfoList &get_user_save_info_list(); + data::UserSaveInfoList &get_user_save_info_list() noexcept; /// @brief Returns a pointer to the play statistics of applicationID - PdmPlayStatistics *get_play_stats_by_id(uint64_t applicationID); + PdmPlayStatistics *get_play_stats_by_id(uint64_t applicationID) noexcept; /// @brief Erases a UserDataEntry according to the application ID passed. /// @param applicationID ID of the save to erase. diff --git a/include/data/accountUID.hpp b/include/data/accountUID.hpp index 03e051e..5273a77 100644 --- a/include/data/accountUID.hpp +++ b/include/data/accountUID.hpp @@ -11,7 +11,7 @@ namespace data /// @param accountIDA First account to compare. /// @param accountIDB Second account to compare. /// @return True if both account IDs match. -static inline bool operator==(AccountUid accountIDA, AccountUid accountIDB) +static inline bool operator==(AccountUid accountIDA, AccountUid accountIDB) noexcept { return (accountIDA.uid[0] == accountIDB.uid[0]) && (accountIDA.uid[1] == accountIDB.uid[1]); } @@ -22,7 +22,7 @@ static inline bool operator==(AccountUid accountIDA, AccountUid accountIDB) /// @return True if they match. False if they don't. /// @note I'm not 100% sure which uint64_t in the AccountUid struct comes first. I don't know if it's [0][1] or [1][0]. To do: /// Figure that out. -static inline bool operator==(AccountUid accountIDA, u128 accountIDB) +static inline bool operator==(AccountUid accountIDA, u128 accountIDB) noexcept { return accountIDA.uid[0] == (accountIDB >> 64 & 0xFFFFFFFFFFFFFFFF) && accountIDA.uid[1] == (accountIDB & 0xFFFFFFFFFFFFFFFF); diff --git a/include/data/data.hpp b/include/data/data.hpp index c252bcb..d573559 100644 --- a/include/data/data.hpp +++ b/include/data/data.hpp @@ -21,7 +21,7 @@ namespace data /// @brief Returns a pointer to the title mapped to applicationID. /// @param applicationID ApplicationID of title to retrieve. /// @return Pointer to data. nullptr if it's not found. - data::TitleInfo *get_title_info_by_id(uint64_t applicationID); + data::TitleInfo *get_title_info_by_id(uint64_t applicationID) noexcept; /// @brief Gets a vector of pointers to the title info. /// @param listOut List to store pointers in. @@ -34,7 +34,7 @@ namespace data /// @brief Returns if the title with applicationID is already loaded to the map. /// @param applicationID Application ID of the title to search for. /// @return True if it has been. False if it hasn't. - bool title_exists_in_map(uint64_t applicationID); + bool title_exists_in_map(uint64_t applicationID) noexcept; /// @brief Gets a vector of pointers with all titles with saveType. /// @param saveType Save data type to check for. diff --git a/include/error.hpp b/include/error.hpp index aabbfc9..f83a55b 100644 --- a/include/error.hpp +++ b/include/error.hpp @@ -5,11 +5,11 @@ namespace error { /// @brief Logs and returns if a call from libnx fails. - bool libnx(Result code, const std::source_location &location = std::source_location::current()); + bool libnx(Result code, const std::source_location &location = std::source_location::current()) noexcept; /// @brief Logs and returns if an fslib function fails. - bool fslib(bool result, const std::source_location &location = std::source_location::current()); + bool fslib(bool result, const std::source_location &location = std::source_location::current()) noexcept; /// @brief Returns whether or not the pointer passed is null. Records the location in which this occurred. - bool is_null(const void *pointer, const std::source_location &location = std::source_location::current()); + bool is_null(const void *pointer, const std::source_location &location = std::source_location::current()) noexcept; } diff --git a/include/fs/PathFilter.hpp b/include/fs/PathFilter.hpp index 051c10f..2a9b8a0 100644 --- a/include/fs/PathFilter.hpp +++ b/include/fs/PathFilter.hpp @@ -13,10 +13,10 @@ namespace fs PathFilter(const fslib::Path &filterPath); /// @brief Returns whether or not the filter has valid paths. - bool has_paths() const; + bool has_paths() const noexcept; /// @brief Returns whether or not the path passed is filtered. - bool is_filtered(const fslib::Path &path); + bool is_filtered(const fslib::Path &path) const noexcept; private: /// @brief Vector of paths to filter from deletion and backup. diff --git a/include/fs/SaveMetaData.hpp b/include/fs/SaveMetaData.hpp index 89ff579..359a0fd 100644 --- a/include/fs/SaveMetaData.hpp +++ b/include/fs/SaveMetaData.hpp @@ -33,11 +33,10 @@ namespace fs // clang-format on /// @brief Didn't feel like a whole new file just for this. Fills an fs::SaveMetaData struct. - bool fill_save_meta_data(const FsSaveDataInfo *saveInfo, SaveMetaData &meta); + bool fill_save_meta_data(const FsSaveDataInfo *saveInfo, SaveMetaData &meta) noexcept; /// @brief Processes the save meta data and applies it to the passed saveInfo pointer. /// @param saveInfo FsSaveDataInfo to apply the meta to. /// @param meta Save meta data to apply. - bool process_save_meta_data(const FsSaveDataInfo *saveInfo, const SaveMetaData &meta); - + bool process_save_meta_data(const FsSaveDataInfo *saveInfo, const SaveMetaData &meta) noexcept; } // namespace fs diff --git a/include/fs/ScopedSaveMount.hpp b/include/fs/ScopedSaveMount.hpp index 46163ac..91c18ee 100644 --- a/include/fs/ScopedSaveMount.hpp +++ b/include/fs/ScopedSaveMount.hpp @@ -13,8 +13,8 @@ namespace fs /// @param log Optional. Whether or not logging errors is wanted. True by default. ScopedSaveMount(std::string_view mount, const FsSaveDataInfo *saveInfo, bool log = true); - ScopedSaveMount(ScopedSaveMount &&scopedSaveMount); - ScopedSaveMount &operator=(ScopedSaveMount &&scopedSaveMount); + ScopedSaveMount(ScopedSaveMount &&scopedSaveMount) noexcept; + ScopedSaveMount &operator=(ScopedSaveMount &&scopedSaveMount) noexcept; ScopedSaveMount(const ScopedSaveMount &) = delete; ScopedSaveMount &operator=(const ScopedSaveMount &) = delete; @@ -23,7 +23,7 @@ namespace fs ~ScopedSaveMount(); /// @brief Returns whether or not mounting the data was successful. - bool is_open() const; + bool is_open() const noexcept; private: /// @brief Saves a copy of the mount point for destruction. diff --git a/include/fs/save_data_functions.hpp b/include/fs/save_data_functions.hpp index 8686532..d452b7f 100644 --- a/include/fs/save_data_functions.hpp +++ b/include/fs/save_data_functions.hpp @@ -9,29 +9,29 @@ namespace fs /// @param targetUser User to create save data for. /// @param titleInfo Title to create save data for. /// @return True on success. False on failure. - bool create_save_data_for(data::User *targetUser, data::TitleInfo *titleInfo); + bool create_save_data_for(data::User *targetUser, data::TitleInfo *titleInfo) noexcept; /// @brief Deletes the save data of the FsSaveDataInfo passed. /// @param saveInfo Save data to delete. /// @return True on success. False on failure. - bool delete_save_data(const FsSaveDataInfo *saveInfo); + bool delete_save_data(const FsSaveDataInfo *saveInfo) noexcept; /// @brief Extends the save data of the FsSaveDataInfo struct passed. /// @param saveInfo Pointer to the FsSaveDataInfo struct of the save to extend. /// @param size Size (in MB) to extend the save data to. /// @param journalSize Size of the journaling space. /// @return True on success. False on failure. - bool extend_save_data(const FsSaveDataInfo *saveInfo, int64_t size, int64_t journalSize); + bool extend_save_data(const FsSaveDataInfo *saveInfo, int64_t size, int64_t journalSize) noexcept; /// @brief Returns whether or not the saveInfo passed is system type. /// @param saveInfo FsSaveDataInfo to check. /// @return True if it is. False if it isn't. /// @note The config setting overrides this. - bool is_system_save_data(const FsSaveDataInfo *saveInfo); + bool is_system_save_data(const FsSaveDataInfo *saveInfo) noexcept; /// @brief Reads the extra info of the save container according to the FsSaveDataInfo passed. /// @param saveInfo Pointer to the save info to read. /// @param extraOut Reference to the FsSaveDataExtraData to read to. /// @return True on success. False on failure. - bool read_save_extra_data(const FsSaveDataInfo *saveInfo, FsSaveDataExtraData &extraOut); + bool read_save_extra_data(const FsSaveDataInfo *saveInfo, FsSaveDataExtraData &extraOut) noexcept; } // namespace fs diff --git a/include/fs/save_mount.hpp b/include/fs/save_mount.hpp index d44a322..b2f8377 100644 --- a/include/fs/save_mount.hpp +++ b/include/fs/save_mount.hpp @@ -5,8 +5,8 @@ namespace fs { /// @brief Default mount point used for JKSV for saves. - static constexpr std::string_view DEFAULT_SAVE_MOUNT = "save"; + inline constexpr std::string_view DEFAULT_SAVE_MOUNT = "save"; /// @brief Same as above, but as a root directory. - static constexpr std::string_view DEFAULT_SAVE_ROOT = "save:/"; + inline constexpr std::string_view DEFAULT_SAVE_ROOT = "save:/"; } // namespace fs diff --git a/include/input.hpp b/include/input.hpp index 1d08bb6..00fef10 100644 --- a/include/input.hpp +++ b/include/input.hpp @@ -7,17 +7,17 @@ namespace input void initialize(); /// @brief Updates the PadState. - void update(); + void update() noexcept; /// @brief Returns if a button was pressed the current frame, but not the previous. /// @param button Button to check. - bool button_pressed(HidNpadButton button); + bool button_pressed(HidNpadButton button) noexcept; /// @brief Returns if the button was pressed or held the previous and current frame. /// @param button Button to check. - bool button_held(HidNpadButton button); + bool button_held(HidNpadButton button) noexcept; /// @brief Returns if the button was pressed or held the previous frame, but not the current. /// @param button Button to check. - bool button_released(HidNpadButton button); + bool button_released(HidNpadButton button) noexcept; } // namespace input diff --git a/include/logging/logger.hpp b/include/logging/logger.hpp index b50a4a5..635bd37 100644 --- a/include/logging/logger.hpp +++ b/include/logging/logger.hpp @@ -9,5 +9,5 @@ namespace logger /// @brief Logs a formatted string. /// @param format Format of string. /// @param arguments Va arguments. - void log(const char *format, ...); + void log(const char *format, ...) noexcept; } // namespace logger diff --git a/include/mathutil.hpp b/include/mathutil.hpp index cfc78b9..bfcb06f 100644 --- a/include/mathutil.hpp +++ b/include/mathutil.hpp @@ -6,6 +6,6 @@ namespace math class Util { public: - static inline Type absolute_distance(Type a, Type b) { return a > b ? a - b : b - a; } + static inline Type absolute_distance(Type a, Type b) noexcept { return a > b ? a - b : b - a; } }; } diff --git a/include/remote/Form.hpp b/include/remote/Form.hpp index c38d72d..9a9a345 100644 --- a/include/remote/Form.hpp +++ b/include/remote/Form.hpp @@ -15,11 +15,11 @@ namespace remote /// @brief Move constructor. /// @param form Form to copy from. - Form(Form &&form); + Form(Form &&form) noexcept; /// @brief = Operator. /// @param form Form to copy. - Form &operator=(const Form &form); + Form &operator=(const Form &form) noexcept; /// @brief = Move operator. /// @param form Form to rob of its life. @@ -31,10 +31,10 @@ namespace remote Form &append_parameter(std::string_view param, std::string_view value); /// @brief Returns the C string of the form string. - const char *get() const; + const char *get() const noexcept; /// @brief Returns m_form.length() - size_t length() const; + size_t length() const noexcept; private: /// @brief String containing the actual data posted. diff --git a/include/remote/GoogleDrive.hpp b/include/remote/GoogleDrive.hpp index 279b2be..838ef65 100644 --- a/include/remote/GoogleDrive.hpp +++ b/include/remote/GoogleDrive.hpp @@ -79,7 +79,7 @@ namespace remote bool get_root_id(); /// @brief Returns whether or not the auth token is still valid for use or needs to be refreshed. - bool token_is_valid() const; + bool token_is_valid() const noexcept; /// @brief Attempts to refresh the auth token if needed. bool refresh_token(); @@ -95,6 +95,6 @@ namespace remote /// @param json Json object to check. /// @param log Whether or not to log the error. /// @note This doesn't catch every error. Google's errors aren't consistent. - bool error_occurred(json::Object &json, bool log = true); + bool error_occurred(json::Object &json, bool log = true) noexcept; }; } // namespace remote diff --git a/include/remote/Item.hpp b/include/remote/Item.hpp index 820ac29..673d145 100644 --- a/include/remote/Item.hpp +++ b/include/remote/Item.hpp @@ -16,23 +16,23 @@ namespace remote /// @brief Returns the name of the item. /// @return Name of the item. - std::string_view get_name() const; + std::string_view get_name() const noexcept; /// @brief Returns the id of the item. /// @return ID of the item. - std::string_view get_id() const; + std::string_view get_id() const noexcept; /// @brief Returns the parent id of the item. /// @return Parent ID of the item. - std::string_view get_parent_id() const; + std::string_view get_parent_id() const noexcept; /// @brief Gets the size of the item. /// @return Size of the item in bytes. - size_t get_size() const; + size_t get_size() const noexcept; /// @brief Returns whether or not the item is a directory. /// @return Whether or not the item is a directory. - bool is_directory() const; + bool is_directory() const noexcept; /// @brief Sets the name of the item. /// @param name New name of the item. @@ -48,26 +48,26 @@ namespace remote /// @brief Sets the size of the item. /// @param size Size of the item. - void set_size(size_t size); + void set_size(size_t size) noexcept; /// @brief Sets whether or not the item is a directory. /// @param directory Whether or not the item is a directory. - void set_is_directory(bool directory); + void set_is_directory(bool directory) noexcept; private: /// @brief The name of the item. - std::string m_name; + std::string m_name{}; /// @brief The ID of the item. - std::string m_id; + std::string m_id{}; /// @brief Parent ID of the item. - std::string m_parent; + std::string m_parent{}; /// @brief Size of the item. - size_t m_size; + size_t m_size{}; /// @brief Whether or not the item is a directory. - bool m_isDirectory; + bool m_isDirectory{}; }; } // namespace remote diff --git a/include/remote/Storage.hpp b/include/remote/Storage.hpp index ce8fb91..0923058 100644 --- a/include/remote/Storage.hpp +++ b/include/remote/Storage.hpp @@ -23,12 +23,12 @@ namespace remote Storage(std::string_view prefix, bool supportsUtf8 = false); /// @brief Returns whether or not the Storage type was successfully. initialized. - bool is_initialized() const; + bool is_initialized() const noexcept; // Directory functions. /// @brief Returns whether or not a directory with name exists within the current parent. /// @param name Name of the directory to search for. - bool directory_exists(std::string_view name); + bool directory_exists(std::string_view name) const noexcept; /// @brief Returns the parent to the root directory. void return_to_root(); @@ -48,7 +48,7 @@ namespace remote /// @brief Searches the list for a directory matching name and the current parent. /// @param name Name of the directory to search for. /// @return Pointer to the item representing the directory on success. nullptr on failure/not found. - remote::Item *get_directory_by_name(std::string_view name); + remote::Item *get_directory_by_name(std::string_view name) noexcept; /// @brief Retrieves a listing of the items in the current parent directory. /// @param listOut List to fill. @@ -62,7 +62,7 @@ namespace remote // File functions. /// @brief Returns whether a file with name exists within the current directory. /// @param name Name of the file. - bool file_exists(std::string_view name); + bool file_exists(std::string_view name) const noexcept; /// @brief Uploads a file from the SD card to the remote. /// @param source Path to the file to upload. @@ -83,7 +83,7 @@ namespace remote /// @brief Searches the list for a file matching name and the current parent. /// @param name Name of the file to search for. /// @return Pointer to the item if located. nullptr if not. - remote::Item *get_file_by_name(std::string_view name); + remote::Item *get_file_by_name(std::string_view name) noexcept; // General functions that apply to both. /// @brief Deletes a file or folder from the remote. @@ -96,10 +96,10 @@ namespace remote virtual bool rename_item(remote::Item *item, std::string_view newName) = 0; /// @brief Returns whether or not the remote storage type supports UTF-8 for names or requires path safe titles. - bool supports_utf8() const; + bool supports_utf8() const noexcept; /// @brief Returns the prefix for menus. - std::string_view get_prefix() const; + std::string_view get_prefix() const noexcept; protected: /// @brief This is the size of the buffers used for snprintf'ing URLs together. @@ -131,27 +131,34 @@ namespace remote /// @brief Searches the list for a directory matching name and the current parent. /// @param name Name to search for. - Storage::List::iterator find_directory_by_name(std::string_view name); + Storage::List::iterator find_directory_by_name(std::string_view name) noexcept; + Storage::List::const_iterator find_directory_by_name(std::string_view name) const noexcept; /// @brief Searches the list for a directory matching ID. /// @param id ID of the directory to search for. - Storage::List::iterator find_directory_by_id(std::string_view id); + Storage::List::iterator find_directory_by_id(std::string_view id) noexcept; + Storage::List::const_iterator find_directory_by_id(std::string_view id) const noexcept; /// @brief Searches to find if a file with name exists within the current parent. /// @param name Name of the file to search for. - Storage::List::iterator find_file_by_name(std::string_view name); + Storage::List::iterator find_file_by_name(std::string_view name) noexcept; + Storage::List::const_iterator find_file_by_name(std::string_view name) const noexcept; /// @brief Searches the list for a file matching ID. /// @param id ID to search for.s - Storage::List::iterator find_file_by_id(std::string_view id); + Storage::List::iterator find_file_by_id(std::string_view id) noexcept; + Storage::List::const_iterator find_file_by_id(std::string_view id) const noexcept; /// @brief Locates any item (directory/file) by the id passed. /// @param id ID to search for. - Storage::List::iterator find_item_by_id(std::string_view id); + Storage::List::iterator find_item_by_id(std::string_view id) noexcept; + Storage::List::const_iterator find_item_by_id(std::string_view id) const noexcept; /// @brief Searches starting with the iterator start for items that belong to parentID /// @param start Beginning iterator for search. /// @param parentID ParentID to match. - Storage::List::iterator find_by_parent_id(Storage::List::iterator start, std::string_view parentID); + Storage::List::iterator find_by_parent_id(Storage::List::iterator start, std::string_view parentID) noexcept; + Storage::List::const_iterator find_by_parent_id(Storage::List::const_iterator start, + std::string_view parentID) const noexcept; }; } // namespace remote diff --git a/include/remote/URL.hpp b/include/remote/URL.hpp index 87d74ff..bc661c2 100644 --- a/include/remote/URL.hpp +++ b/include/remote/URL.hpp @@ -21,7 +21,7 @@ namespace remote /// @brief Move constructor. /// @param url URL to move. - URL(URL &&url); + URL(URL &&url) noexcept; /// @brief Makes a copy of the URL passed. /// @param url remote::URL instance to make a copy of. @@ -29,7 +29,7 @@ namespace remote /// @brief Move operator. /// @param url URL to move. - URL &operator=(URL &&url); + URL &operator=(URL &&url) noexcept; /// @brief Sets the base URL. Basically resets the string back to square 0. /// @param base Base URL to start with. @@ -48,7 +48,7 @@ namespace remote URL &append_slash(); /// @brief Returns the C string of the url string. - const char *get() const; + const char *get() const noexcept; private: /// @brief This is where the actual URL is held. diff --git a/include/remote/remote.hpp b/include/remote/remote.hpp index 18c4911..df7c224 100644 --- a/include/remote/remote.hpp +++ b/include/remote/remote.hpp @@ -10,7 +10,7 @@ namespace remote static constexpr std::string_view PATH_WEBDAV_CONFIG = "sdmc:/config/JKSV/webdav.json"; /// @brief Returns whether or not the console has an active internet connection. - bool has_internet_connection(); + bool has_internet_connection() noexcept; /// @brief Initializes the Storage instance to Google Drive. void initialize_google_drive(); @@ -19,5 +19,5 @@ namespace remote void initialize_webdav(); /// @brief Returns the pointer to the Storage instance. - remote::Storage *get_remote_storage(); + remote::Storage *get_remote_storage() noexcept; } // namespace remote diff --git a/include/strings/strings.hpp b/include/strings/strings.hpp index 3d9ae9e..2eb2231 100644 --- a/include/strings/strings.hpp +++ b/include/strings/strings.hpp @@ -9,5 +9,5 @@ namespace strings bool initialize(); // Returns string with name and index. Returns nullptr if string doesn't exist. - const char *get_by_name(std::string_view name, int index); + const char *get_by_name(std::string_view name, int index) noexcept; } // namespace strings diff --git a/include/sys/DataTask.hpp b/include/sys/DataTask.hpp deleted file mode 100644 index c3c12da..0000000 --- a/include/sys/DataTask.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once -#include "sys/Task.hpp" - -#include - -namespace sys -{ - class DataTask final : public sys::Task - { - public: - DataTask(ThreadFunc function, bool clearCache); - - ~DataTask(); - - private - Thread m_thread{}; - } -} \ No newline at end of file diff --git a/include/sys/ProgressTask.hpp b/include/sys/ProgressTask.hpp index b5cfc30..27c5bed 100644 --- a/include/sys/ProgressTask.hpp +++ b/include/sys/ProgressTask.hpp @@ -24,22 +24,22 @@ namespace sys /// @brief Resets the progress and sets a new goal. /// @param goal The goal we all strive for. - void reset(double goal); + void reset(double goal) noexcept; /// @brief Updates the current progress. /// @param current The current progress value. - void update_current(double current); + void update_current(double current) noexcept; /// @brief Increases the current progress by a set amount. - void increase_current(double amount); + void increase_current(double amount) noexcept; /// @brief Returns the goal value. /// @return Goal - double get_goal() const; + double get_goal() const noexcept; /// @brief Returns the current progress. /// @return Current progress. - double get_progress() const; + double get_progress() const noexcept; private: // Current value and goal diff --git a/include/sys/Task.hpp b/include/sys/Task.hpp index 6fb43a5..fd3c855 100644 --- a/include/sys/Task.hpp +++ b/include/sys/Task.hpp @@ -31,18 +31,18 @@ namespace sys /// @brief Returns if the thread has signaled it's finished running. /// @return True if the thread is still running. False if it isn't. - bool is_running() const; + bool is_running() const noexcept; /// @brief Allows thread to signal it's finished. /// @note Spawned task threads must call this when their work is finished. - void complete(); + void complete() noexcept; /// @brief Sets the task/threads current status string. Thread safe. void set_status(std::string_view status); /// @brief Returns the status string. Thread safe. /// @return Copy of the status string. - std::string get_status(); + std::string get_status() noexcept; protected: // Whether task is still running. diff --git a/include/sys/Timer.hpp b/include/sys/Timer.hpp index d156b25..299c347 100644 --- a/include/sys/Timer.hpp +++ b/include/sys/Timer.hpp @@ -13,18 +13,18 @@ namespace sys /// @brief Constructs a new timer. /// @param triggerTicks Number of ticks the timer is triggered at. - Timer(uint64_t triggerTicks); + Timer(uint64_t triggerTicks) noexcept; /// @brief Starts the timer. /// @param triggerTicks Number of ticks to trigger at. - void start(uint64_t triggerTicks); + void start(uint64_t triggerTicks) noexcept; /// @brief Updates and returns if the timer was triggered. /// @return True if timer is triggered. False if it isn't. - bool is_triggered(); + bool is_triggered() noexcept; /// @brief Forces the timer to restart. - void restart(); + void restart() noexcept; private: /// @brief Tick count when the timer starts. diff --git a/include/ui/BoundingBox.hpp b/include/ui/BoundingBox.hpp index bf7db12..ec45566 100644 --- a/include/ui/BoundingBox.hpp +++ b/include/ui/BoundingBox.hpp @@ -17,9 +17,6 @@ namespace ui /// @param height Height of the box in pixels. BoundingBox(int x, int y, int width, int height); - /// @brief Required destructor. - ~BoundingBox() {}; - /// @brief Creates a returns a new BoundingBox. See constructor. static inline std::shared_ptr create(int x, int y, int width, int height) { @@ -32,18 +29,17 @@ namespace ui /// @brief Render override. void render(sdl::SharedTexture &target, bool hasFocus) override; - /// @brief Sets the X and Y coord. - /// @param x New X coord. - /// @param y New Y coord. - void set_xy(int x, int y); + /// @brief Sets the X coord. + void set_x(int x) noexcept; - /// @brief Sets the width and height of the bounding box. - /// @param width New width. - /// @param height New height. - void set_width_height(int width, int height); + /// @brief Sets the Y coord. + void set_y(int y) noexcept; - /// @brief Passing this to the set functions will keep the same coord. - static inline constexpr int NO_SET = -1; + /// @brief Sets the width. + void set_width(int width) noexcept; + + /// @brief Sets the height. + void set_height(int height) noexcept; private: /// @brief X coord to render to. diff --git a/include/ui/ColorMod.hpp b/include/ui/ColorMod.hpp index 2a6915e..5883a99 100644 --- a/include/ui/ColorMod.hpp +++ b/include/ui/ColorMod.hpp @@ -1,5 +1,6 @@ #pragma once #include "sdl.hpp" + #include namespace ui @@ -12,11 +13,11 @@ namespace ui ColorMod() = default; /// @brief Updates the color modification variable. - void update(); + void update() noexcept; /// @brief Operator that allows using this as an sdl::Color directly. /// @note Since all of these pulse the same color, no sense in not doing this. - operator sdl::Color() const; + operator sdl::Color() const noexcept; private: /// @brief Whether we're adding or subtracting from the color value. diff --git a/include/ui/DialogBox.hpp b/include/ui/DialogBox.hpp index d82a2a9..e7cfc50 100644 --- a/include/ui/DialogBox.hpp +++ b/include/ui/DialogBox.hpp @@ -22,9 +22,6 @@ namespace ui /// @param type Optional. The type of box. Default is dark since JKSV rewrite doesn't do theme detection. DialogBox(int x, int y, int width, int height, DialogBox::Type type = DialogBox::Type::Dark); - /// @brief Required destructor. - ~DialogBox() {}; - /// @brief Creates and returns a new DialogBox instance. See constructor. static inline std::shared_ptr create(int x, int y, @@ -44,16 +41,16 @@ namespace ui void render(sdl::SharedTexture &target, bool hasFocus) override; /// @brief Sets the X render coord. - void set_x(int x); + void set_x(int x) noexcept; /// @brief Sets the X render coord. - void set_y(int y); + void set_y(int y) noexcept; /// @brief Sets the width. - void set_width(int width); + void set_width(int width) noexcept; /// @brief Sets the height. - void set_height(int height); + void set_height(int height) noexcept; private: /// @brief X render coord. diff --git a/include/ui/Element.hpp b/include/ui/Element.hpp index cb8b76d..4535f31 100644 --- a/include/ui/Element.hpp +++ b/include/ui/Element.hpp @@ -11,7 +11,7 @@ namespace ui Element() = default; /// @brief Virtual destructor. - virtual ~Element() {}; + virtual ~Element() noexcept {}; /// @brief Virtual update method. All derived classes must have this. /// @param HasFocus Whether or not the state containing the element currently has focus. diff --git a/include/ui/Frame.hpp b/include/ui/Frame.hpp index cc39f80..b90d8d2 100644 --- a/include/ui/Frame.hpp +++ b/include/ui/Frame.hpp @@ -12,9 +12,6 @@ namespace ui /// @brief Constructs a new frame. Frame(int x, int y, int width, int height); - /// @brief Doesn't need to do anything because modern C++. - ~Frame() {}; - /// @brief Inline function to make constructing nicer. static inline std::shared_ptr create(int x, int y, int width, int height) { @@ -28,16 +25,16 @@ namespace ui void render(sdl::SharedTexture &target, bool hasFocus) override; /// @brief Sets the X coord. - void set_x(int x); + void set_x(int x) noexcept; /// @brief Sets the Y coord. - void set_y(int y); + void set_y(int y) noexcept; /// @brief Sets the width of the frame. - void set_width(int width); + void set_width(int width) noexcept; /// @brief Sets the height of the frame. - void set_height(int height); + void set_height(int height) noexcept; private: /// @brief X rendering coord. diff --git a/include/ui/IconMenu.hpp b/include/ui/IconMenu.hpp index 0d8565f..7821b4b 100644 --- a/include/ui/IconMenu.hpp +++ b/include/ui/IconMenu.hpp @@ -18,9 +18,6 @@ namespace ui /// @param renderTargetHeight Height of the render target to calculate how many options can be displayed at once. IconMenu(int x, int y, int renderTargetHeight); - /// @brief Required destructor. - ~IconMenu() {}; - /// @brief Creates and returns a new IconMenu instance. static inline std::shared_ptr create(int x, int y, int renderTargetHeight) { diff --git a/include/ui/Menu.hpp b/include/ui/Menu.hpp index 8a2c77e..e2bf6f9 100644 --- a/include/ui/Menu.hpp +++ b/include/ui/Menu.hpp @@ -51,24 +51,24 @@ namespace ui /// @brief Returns the index of the currently selected menu option. /// @return Index of currently selected option. - int get_selected() const; + int get_selected() const noexcept; /// @brief Sets the selected item. /// @param selected Value to set selected to. void set_selected(int selected); - /// @brief This is a workaround function until I find something better. - /// @param width New width of the menu in pixels. - void set_width(int width); - /// @brief Updates the X render coordinate. - void set_x(int x); + void set_x(int x) noexcept; /// @brief Updates the Y render coordinate. - void set_y(int y); + void set_y(int y) noexcept; + + /// @brief This is a workaround function until I find something better. + /// @param width New width of the menu in pixels. + void set_width(int width) noexcept; /// @brief Returns if the menu has no options. - bool is_empty() const; + bool is_empty() const noexcept; /// @brief Resets the menu and returns it to an empty, default state. void reset(); diff --git a/include/ui/PopMessage.hpp b/include/ui/PopMessage.hpp index 34c7bf8..f75d3fd 100644 --- a/include/ui/PopMessage.hpp +++ b/include/ui/PopMessage.hpp @@ -19,10 +19,10 @@ namespace ui void render(); /// @brief Returns whether or not the message can be purged. - bool finished() const; + bool finished() const noexcept; /// @brief Returns the text of the message. - std::string_view get_message() const; + std::string_view get_message() const noexcept; private: // Every message begins off screen. @@ -65,9 +65,9 @@ namespace ui std::shared_ptr m_dialog{}; /// @brief Updates the Y Coord to match the target passed. - void update_y(double targetY); + void update_y(double targetY) noexcept; /// @brief Updates the current end offset of the text. - void update_text_offset(); + void update_text_offset() noexcept; }; } diff --git a/include/ui/SlideOutPanel.hpp b/include/ui/SlideOutPanel.hpp index 960f7cd..37e8e60 100644 --- a/include/ui/SlideOutPanel.hpp +++ b/include/ui/SlideOutPanel.hpp @@ -47,27 +47,27 @@ namespace ui void clear_target(); /// @brief Resets the panel back to its default state. - void reset(); + void reset() noexcept; /// @brief Closes the panel. - void close(); + void close() noexcept; /// @brief Hides the panel temporarily. - void hide(); + void hide() noexcept; /// @brief Unhides the panel. - void unhide(); + void unhide() noexcept; /// @brief Returns if the panel is fully open. /// @return If the panel is fully open. - bool is_open() const; + bool is_open() const noexcept; /// @brief Returns if the panel is fully closed. /// @return If the panel is fully closed. - bool is_closed(); + bool is_closed() noexcept; /// @brief Returns whether or not the panel is hidden. - bool is_hidden() const; + bool is_hidden() const noexcept; /// @brief Pushes a new element to the element vector. /// @param newElement New element to push. @@ -78,7 +78,7 @@ namespace ui /// @brief Returns a pointer to the render target of the panel. /// @return Raw SDL_Texture pointer to target. - sdl::SharedTexture &get_target(); + sdl::SharedTexture &get_target() noexcept; private: /// @brief Bool for whether panel is fully open or not. @@ -109,15 +109,15 @@ namespace ui std::vector> m_elements{}; /// @brief Handles sliding out logic. - void slide_out(); + void slide_out() noexcept; /// @brief Slides the panel out from the left side. - void slide_out_left(); + void slide_out_left() noexcept; /// @brief Slides the panel out from the right side. - void slide_out_right(); + void slide_out_right() noexcept; /// @brief Contains the logic for hiding/closing the panel. - void close_hide_panel(); + void close_hide_panel() noexcept; }; } // namespace ui diff --git a/include/ui/TextScroll.hpp b/include/ui/TextScroll.hpp index 2bc64a2..9512f9a 100644 --- a/include/ui/TextScroll.hpp +++ b/include/ui/TextScroll.hpp @@ -32,9 +32,6 @@ namespace ui sdl::Color clearColor, bool center = true); - /// @brief Required destructor. - ~TextScroll() {}; - /// @brief Creates and returns a new TextScroll. See constructor. static inline std::shared_ptr create(std::string_view text, int x, @@ -76,14 +73,11 @@ namespace ui void render(sdl::SharedTexture &target, bool hasFocus) override; /// @brief Returns the current text being used for scrolling. - std::string_view get_text() const; + std::string_view get_text() const noexcept; /// @brief Sets and allows changing the text scrolled. void set_text(std::string_view text, bool center); - /// @brief Allows setting of the X and Y render coordinates. - void set_xy(int x, int y); - private: /// @brief Text to display. std::string m_text{}; diff --git a/include/ui/TitleTile.hpp b/include/ui/TitleTile.hpp index 133ac7c..8db9f29 100644 --- a/include/ui/TitleTile.hpp +++ b/include/ui/TitleTile.hpp @@ -23,22 +23,22 @@ namespace ui void render(sdl::SharedTexture &target, int x, int y); /// @brief Resets the width and height of the tile. - void reset(); + void reset() noexcept; /// @brief Returns the render width in pixels. /// @return Render width. - int get_width() const; + int get_width() const noexcept; /// @brief Returns the render height in pixels. /// @return Render height. - int get_height() const; + int get_height() const noexcept; private: /// @brief Width in pixels to render icon at. - int m_renderWidth = 128; + int m_renderWidth{128}; /// @brief Height in pixels to render icon at. - int m_renderHeight = 128; + int m_renderHeight{128}; /// @brief Whether or not the title is a favorite. bool m_isFavorite{}; diff --git a/include/ui/TitleView.hpp b/include/ui/TitleView.hpp index dc5aa4e..0c33d88 100644 --- a/include/ui/TitleView.hpp +++ b/include/ui/TitleView.hpp @@ -18,9 +18,6 @@ namespace ui /// @param user User to use. TitleView(data::User *user); - /// @brief Required destructor. - ~TitleView() {}; - static inline std::shared_ptr create(data::User *user) { return std::make_shared(user); @@ -37,10 +34,10 @@ namespace ui /// @brief Returns index of the currently selected tile. /// @return Index of currently selected tile. - int get_selected() const; + int get_selected() const noexcept; /// @brief Sets the currently selected item. - void set_selected(int selected); + void set_selected(int selected) noexcept; /// @brief Forces a refresh of the view. void refresh(); diff --git a/romfs/Text/ENUS.json b/romfs/Text/ENUS.json index 2697857..e34ccfd 100644 --- a/romfs/Text/ENUS.json +++ b/romfs/Text/ENUS.json @@ -69,7 +69,7 @@ ], "FileOptionConfs": [ "0: Are you sure you want to copy #%s# to #%s#?", - "1: Are you sure you want to delete #%s#?", + "1: Are you sure you want to delete #%s#?" ], "FileModePops": [ "0: Copied #%s#!", diff --git a/source/JKSV.cpp b/source/JKSV.cpp index a8068f8..176c459 100644 --- a/source/JKSV.cpp +++ b/source/JKSV.cpp @@ -60,30 +60,12 @@ static bool initialize_service(Result (*function)(Args...), const char *serviceN return true; } -class BootTimer final -{ - public: - BootTimer() - : m_start(std::chrono::high_resolution_clock::now()) {}; - - ~BootTimer() - { - auto end = std::chrono::high_resolution_clock::now(); - auto microSeconds = std::chrono::duration_cast(end - m_start); - logger::log("Boot time: %llu microseconds", microSeconds); - } - - private: - std::chrono::system_clock::time_point m_start{}; -}; - // Definition at bottom. static void finish_initialization(); // This can't really have an initializer list since it sets everything up. JKSV::JKSV() { - BootTimer timer{}; appletSetCpuBoostMode(ApmCpuBoostMode_FastLoad); ABORT_ON_FAILURE(JKSV::initialize_services()); ABORT_ON_FAILURE(JKSV::initialize_filesystem()); @@ -121,7 +103,7 @@ JKSV::~JKSV() appletSetCpuBoostMode(ApmCpuBoostMode_Normal); } -bool JKSV::is_running() const { return m_isRunning; } +bool JKSV::is_running() const noexcept { return m_isRunning; } void JKSV::update() { diff --git a/source/appstates/FileModeState.cpp b/source/appstates/FileModeState.cpp index 8d6017d..5545b22 100644 --- a/source/appstates/FileModeState.cpp +++ b/source/appstates/FileModeState.cpp @@ -70,50 +70,6 @@ void FileModeState::render() sm_renderTarget->render(sdl::Texture::Null, 23, m_y + 12); } -bool FileModeState::get_target() const noexcept { return m_target; } - -fslib::Path FileModeState::get_source() -{ - const fslib::Path &sourcePath = FileModeState::get_source_path(); - const fslib::Directory &sourceDir = FileModeState::get_source_directory(); - const ui::Menu &sourceMenu = FileModeState::get_source_menu(); - - const int selected = sourceMenu.get_selected(); - - // If 0, the current path is our target. - if (selected == 0) { return sourcePath; } - - const int dirIndex = selected - 2; - const fslib::DirectoryEntry &entry = sourceDir[dirIndex]; - - return sourcePath / entry; -} - -fslib::Path FileModeState::get_destination() -{ - const fslib::Path &destPath = FileModeState::get_destination_path(); - const fslib::Directory &destDir = FileModeState::get_destination_directory(); - const ui::Menu &destMenu = FileModeState::get_destination_menu(); - - const int selected = destMenu.get_selected(); - - if (selected == 0) { return destPath; } - - const int dirIndex = selected - 1; - const fslib::DirectoryEntry &entry = destDir[dirIndex]; - - return destPath / entry; -} - -bool FileModeState::commit_required() const noexcept { return m_target == false && m_journalSize > 0; } - -int64_t FileModeState::get_journal_size() const noexcept { return m_journalSize; } - -void FileModeState::render_control_guide() noexcept -{ - sdl::text::render(sdl::Texture::Null, sm_controlGuideX, 673, 22, sdl::text::NO_WRAP, colors::WHITE, sm_controlGuide); -} - void FileModeState::initialize_static_members() { static constexpr std::string_view RENDER_TARGET_NAME = "FMRenderTarget"; @@ -177,7 +133,8 @@ void FileModeState::update_y_coord() noexcept const double distance = math::Util::absolute_distance(m_targetY, m_y); m_y += std::round(add); - if (distance <= 4) + // The second condition is a fix for when scaling is 1. + if (distance <= 4 || m_y == m_targetY) { m_y = m_targetY; m_inPlace = true; @@ -240,6 +197,11 @@ void FileModeState::enter_directory(fslib::Path &path, FileModeState::initialize_directory_menu(path, directory, menu); } +void FileModeState::render_control_guide() +{ + sdl::text::render(sdl::Texture::Null, sm_controlGuideX, 673, 22, sdl::text::NO_WRAP, colors::WHITE, sm_controlGuide); +} + ui::Menu &FileModeState::get_source_menu() noexcept { return m_target ? *m_dirMenuB.get() : *m_dirMenuA.get(); } ui::Menu &FileModeState::get_destination_menu() noexcept { return m_target ? *m_dirMenuA.get() : *m_dirMenuB.get(); } diff --git a/source/appstates/FileOptionState.cpp b/source/appstates/FileOptionState.cpp index 1b35ecd..0c8fd3f 100644 --- a/source/appstates/FileOptionState.cpp +++ b/source/appstates/FileOptionState.cpp @@ -33,12 +33,11 @@ namespace FileOptionState::FileOptionState(FileModeState *spawningState) : m_spawningState(spawningState) - , m_commitData(m_spawningState->commit_required()) - , m_scaling(config::get_animation_scaling()) , m_dataStruct(std::make_shared()) { FileOptionState::initialize_static_members(); FileOptionState::set_menu_side(); + FileOptionState::initialize_data_struct(); } void FileOptionState::update() @@ -48,6 +47,17 @@ void FileOptionState::update() FileOptionState::update_x_coord(); if (!m_inPlace) { return; } + if (m_updateSource) + { + FileOptionState::update_filemode_source(); + m_updateSource = false; + } + else if (m_updateDest) + { + FileOptionState::update_filemode_dest(); + m_updateDest = false; + } + sm_copyMenu->update(hasFocus); const int selected = sm_copyMenu->get_selected(); const bool aPressed = input::button_pressed(HidNpadButton_A); @@ -77,6 +87,10 @@ void FileOptionState::render() m_spawningState->render_control_guide(); } +void FileOptionState::update_source() { m_updateSource = true; } + +void FileOptionState::update_destination() { m_updateDest = true; } + void FileOptionState::initialize_static_members() { if (sm_copyMenu && sm_dialog) { return; } @@ -93,7 +107,7 @@ void FileOptionState::initialize_static_members() void FileOptionState::set_menu_side() { - const bool target = m_spawningState->get_target(); + const bool target = m_spawningState->m_target; m_x = target ? 1280 : -240; m_targetX = target ? 840 : 200; @@ -101,11 +115,32 @@ void FileOptionState::set_menu_side() sm_copyMenu->set_x(m_x + 9); } +void FileOptionState::initialize_data_struct() { m_dataStruct->spawningState = this; } + +void FileOptionState::update_filemode_source() +{ + const fslib::Path &sourcePath = m_spawningState->get_source_path(); + fslib::Directory &sourceDir = m_spawningState->get_source_directory(); + ui::Menu &sourceMenu = m_spawningState->get_source_menu(); + + m_spawningState->initialize_directory_menu(sourcePath, sourceDir, sourceMenu); +} + +void FileOptionState::update_filemode_dest() +{ + const fslib::Path &destPath = m_spawningState->get_destination_path(); + fslib::Directory &destDir = m_spawningState->get_destination_directory(); + ui::Menu &destMenu = m_spawningState->get_destination_menu(); + + m_spawningState->initialize_directory_menu(destPath, destDir, destMenu); +} + void FileOptionState::update_x_coord() { if (m_x == m_targetX) { return; } - const int add = (m_targetX - m_x) / m_scaling; + // We're going to borrow the scaling from the FileMode + const int add = (m_targetX - m_x) / m_spawningState->m_scaling; m_x += add; const int distance = math::Util::absolute_distance(m_x, m_targetX); @@ -120,54 +155,96 @@ void FileOptionState::update_x_coord() void FileOptionState::copy_target() { - fslib::Path source = m_spawningState->get_source(); - fslib::Path dest = m_spawningState->get_destination(); + const int64_t journalSize = m_spawningState->m_journalSize; + + const fslib::Path &sourcePath = m_spawningState->get_source_path(); + const fslib::Directory &sourceDir = m_spawningState->get_source_directory(); + const ui::Menu &sourceMenu = m_spawningState->get_source_menu(); + + const fslib::Path &destPath = m_spawningState->get_destination_path(); + const fslib::Directory &destDir = m_spawningState->get_destination_directory(); + const ui::Menu &destMenu = m_spawningState->get_destination_menu(); + + const int sourceSelected = sourceMenu.get_selected(); + const int destSelected = destMenu.get_selected(); + + const int sourceIndex = sourceSelected - 2; + const int destIndex = destSelected - 2; + + fslib::Path fullSource{sourcePath}; + if (sourceSelected > 1) + { + const int dirIndex = sourceSelected - 2; + fullSource /= sourceDir[sourceIndex]; + } + + fslib::Path fullDest{destPath}; + if (destSelected == 0) { fullDest /= sourceDir[sourceIndex]; } + if (destSelected > 1) + { + fullDest /= destDir[destIndex]; + if (sourceSelected > 1) { fullDest /= sourceDir[sourceIndex]; } + } + + // Reminder: JK, you move these. That's why the string is blank if they're declared past this point. + const std::string sourceString = fullSource.string(); + const std::string destString = fullDest.string(); + m_dataStruct->sourcePath = std::move(fullSource); + m_dataStruct->destPath = std::move(fullDest); + m_dataStruct->journalSize = journalSize; const char *copyFormat = strings::get_by_name(strings::names::FILEOPTION_CONFS, 0); - const std::string query = stringutil::get_formatted_string(copyFormat, source.string().c_str(), dest.string().c_str()); - - m_dataStruct->sourcePath = std::move(source); - m_dataStruct->destPath = std::move(dest); - m_dataStruct->journalSize = m_journalSize; + const std::string query = stringutil::get_formatted_string(copyFormat, sourceString.c_str(), destString.c_str()); ProgressConfirm::create_push_fade(query, false, tasks::fileoptions::copy_source_to_destination, m_dataStruct); } void FileOptionState::delete_target() { - fslib::Path source = m_spawningState->get_source(); + const fslib::Path &targetPath = m_spawningState->get_source_path(); + const fslib::Directory &targetDir = m_spawningState->get_source_directory(); + const ui::Menu &targetMenu = m_spawningState->get_source_menu(); + + fslib::Path fullTarget{targetPath}; + const int selected = targetMenu.get_selected(); + if (selected > 1) + { + const int dirIndex = selected - 2; + fullTarget /= targetDir[dirIndex]; + } const char *deleteFormat = strings::get_by_name(strings::names::FILEOPTION_CONFS, 1); - const std::string query = stringutil::get_formatted_string(deleteFormat, source.string().c_str()); + const std::string query = stringutil::get_formatted_string(deleteFormat, fullTarget.string().c_str()); - m_dataStruct->sourcePath = std::move(source); - m_dataStruct->journalSize = m_journalSize; + m_dataStruct->sourcePath = std::move(fullTarget); + m_dataStruct->journalSize = m_spawningState->m_journalSize; TaskConfirm::create_push_fade(query, true, tasks::fileoptions::delete_target, m_dataStruct); } void FileOptionState::rename_target() { - const int popTicks = ui::PopMessageManager::DEFAULT_TICKS; - const bool target = m_spawningState->get_target(); - const fslib::Path targetPath = target ? m_spawningState->get_destination() : m_spawningState->get_source(); + const int popTicks = ui::PopMessageManager::DEFAULT_TICKS; + const fslib::Path &targetPath = m_spawningState->get_source_path(); + fslib::Directory &targetDir = m_spawningState->get_source_directory(); + ui::Menu &targetMenu = m_spawningState->get_source_menu(); + const int selected = targetMenu.get_selected(); + if (selected < 2) { return; } char nameBuffer[FS_MAX_PATH] = {0}; - const char *filename = targetPath.get_filename(); + const int dirIndex = selected - 2; + const char *filename = targetDir[dirIndex].get_filename(); const char *keyboardFormat = strings::get_by_name(strings::names::KEYBOARD, 9); const std::string keyboardHeader = stringutil::get_formatted_string(keyboardFormat, filename); const bool validInput = keyboard::get_input(SwkbdType_QWERTY, filename, keyboardHeader, nameBuffer, FS_MAX_PATH); if (validInput) { return; } - size_t folderBegin = targetPath.find_last_of('/'); - if (folderBegin == targetPath.NOT_FOUND) { return; } - else if (folderBegin < 1) { folderBegin = 1; } + const fslib::Path oldPath{targetPath / filename}; + const fslib::Path newPath{targetPath / nameBuffer}; - fslib::Path newPath{targetPath.sub_path(folderBegin) / nameBuffer}; - - const bool isDir = fslib::directory_exists(targetPath); - const bool renameDir = isDir && error::fslib(fslib::rename_directory(targetPath, newPath)); - const bool renameFile = !isDir && error::fslib(fslib::rename_file(targetPath, newPath)); + const bool isDir = fslib::directory_exists(oldPath); + const bool renameDir = isDir && error::fslib(fslib::rename_directory(oldPath, newPath)); + const bool renameFile = !isDir && error::fslib(fslib::rename_file(oldPath, newPath)); if (!renameDir && !renameFile) { const char *popFormat = strings::get_by_name(strings::names::FILEMODE_POPS, 5); @@ -180,11 +257,50 @@ void FileOptionState::rename_target() const std::string pop = stringutil::get_formatted_string(popFormat, filename, nameBuffer); ui::PopMessageManager::push_message(popTicks, pop); } + + m_spawningState->initialize_directory_menu(targetPath, targetDir, targetMenu); +} + +void FileOptionState::create_directory() +{ + const int popTicks = ui::PopMessageManager::DEFAULT_TICKS; + const fslib::Path &targetPath = m_spawningState->get_source_path(); + fslib::Directory &targetDir = m_spawningState->get_source_directory(); + ui::Menu &targetMenu = m_spawningState->get_source_menu(); + + char nameBuffer[FS_MAX_PATH] = {0}; + const char *keyboardHeader = strings::get_by_name(strings::names::KEYBOARD, 6); + const bool validInput = keyboard::get_input(SwkbdType_QWERTY, {}, keyboardHeader, nameBuffer, FS_MAX_PATH); + if (!validInput) { return; } + + const fslib::Path fullTarget{targetPath / nameBuffer}; + const bool createError = error::fslib(fslib::create_directory(fullTarget)); + if (createError) + { + const char *popFormat = strings::get_by_name(strings::names::FILEMODE_POPS, 7); + const std::string pop = stringutil::get_formatted_string(popFormat, nameBuffer); + ui::PopMessageManager::push_message(popTicks, pop); + } + else + { + const char *popFormat = strings::get_by_name(strings::names::FILEMODE_POPS, 6); + const std::string pop = stringutil::get_formatted_string(popFormat, nameBuffer); + ui::PopMessageManager::push_message(popTicks, pop); + } + + m_spawningState->initialize_directory_menu(targetPath, targetDir, targetMenu); +} + +void FileOptionState::get_show_target_properties() +{ + const fslib::Path &targetPath = m_spawningState->get_source_path(); + const fslib::Directory &targetDir = m_spawningState->get_source_directory(); + const ui::Menu &targeMenu = m_spawningState->get_source_menu(); } void FileOptionState::close() { - const bool target = m_spawningState->get_target(); + const bool target = m_spawningState->m_target; m_close = true; m_targetX = target ? 1280 : -240; diff --git a/source/config/ConfigContext.cpp b/source/config/ConfigContext.cpp index 58f5152..2ba541b 100644 --- a/source/config/ConfigContext.cpp +++ b/source/config/ConfigContext.cpp @@ -67,14 +67,14 @@ bool config::ConfigContext::load() void config::ConfigContext::save() { ConfigContext::save_config_file(); } -uint8_t config::ConfigContext::get_by_key(std::string_view key) const +uint8_t config::ConfigContext::get_by_key(std::string_view key) const noexcept { const auto findKey = m_configMap.find(key); if (findKey == m_configMap.end()) { return 0; } return findKey->second; } -void config::ConfigContext::toggle_by_key(std::string_view key) +void config::ConfigContext::toggle_by_key(std::string_view key) noexcept { auto findKey = m_configMap.find(key); if (findKey == m_configMap.end()) { return; } @@ -83,7 +83,7 @@ void config::ConfigContext::toggle_by_key(std::string_view key) findKey->second = value ? 0 : 1; } -void config::ConfigContext::set_by_key(std::string_view key, uint8_t value) +void config::ConfigContext::set_by_key(std::string_view key, uint8_t value) noexcept { auto findKey = m_configMap.find(key); if (findKey == m_configMap.end()) { return; } @@ -91,9 +91,9 @@ void config::ConfigContext::set_by_key(std::string_view key, uint8_t value) findKey->second = value; } -fslib::Path config::ConfigContext::get_working_directory() const { return m_workingDirectory; } +fslib::Path config::ConfigContext::get_working_directory() const noexcept { return m_workingDirectory; } -bool config::ConfigContext::set_working_directory(const fslib::Path &workDir) +bool config::ConfigContext::set_working_directory(const fslib::Path &workDir) noexcept { if (!workDir.is_valid()) { return false; } @@ -101,9 +101,9 @@ bool config::ConfigContext::set_working_directory(const fslib::Path &workDir) return true; } -double config::ConfigContext::get_animation_scaling() const { return m_animationScaling; } +double config::ConfigContext::get_animation_scaling() const noexcept { return m_animationScaling; } -void config::ConfigContext::set_animation_scaling(double scaling) { m_animationScaling = scaling; } +void config::ConfigContext::set_animation_scaling(double scaling) noexcept { m_animationScaling = scaling; } void config::ConfigContext::add_favorite(uint64_t applicationID) { @@ -113,7 +113,7 @@ void config::ConfigContext::add_favorite(uint64_t applicationID) ConfigContext::save_config_file(); } -void config::ConfigContext::remove_favorite(uint64_t applicationID) +void config::ConfigContext::remove_favorite(uint64_t applicationID) noexcept { const auto findFav = ConfigContext::find_application_id(m_favorites, applicationID); if (findFav == m_favorites.end()) { return; } @@ -121,7 +121,7 @@ void config::ConfigContext::remove_favorite(uint64_t applicationID) ConfigContext::save_config_file(); } -bool config::ConfigContext::is_favorite(uint64_t applicationID) const +bool config::ConfigContext::is_favorite(uint64_t applicationID) const noexcept { return ConfigContext::find_application_id(m_favorites, applicationID) != m_favorites.end(); } @@ -133,7 +133,7 @@ void config::ConfigContext::add_to_blacklist(uint64_t applicationID) m_blacklist.push_back(applicationID); } -void config::ConfigContext::remove_from_blacklist(uint64_t applicationID) +void config::ConfigContext::remove_from_blacklist(uint64_t applicationID) noexcept { const auto findTitle = ConfigContext::find_application_id(m_blacklist, applicationID); if (findTitle == m_blacklist.end()) { return; } @@ -145,14 +145,14 @@ void config::ConfigContext::get_blacklist(std::vector &listOut) listOut.assign(m_blacklist.begin(), m_blacklist.end()); } -bool config::ConfigContext::is_blacklisted(uint64_t applicationID) const +bool config::ConfigContext::is_blacklisted(uint64_t applicationID) const noexcept { return ConfigContext::find_application_id(m_blacklist, applicationID) != m_blacklist.end(); } -bool config::ConfigContext::blacklist_empty() const { return m_blacklist.empty(); } +bool config::ConfigContext::blacklist_empty() const noexcept { return m_blacklist.empty(); } -bool config::ConfigContext::has_custom_path(uint64_t applicationID) const +bool config::ConfigContext::has_custom_path(uint64_t applicationID) const noexcept { return m_paths.find(applicationID) != m_paths.end(); } diff --git a/source/config/config.cpp b/source/config/config.cpp index 1711019..3118586 100644 --- a/source/config/config.cpp +++ b/source/config/config.cpp @@ -20,15 +20,15 @@ void config::reset_to_default() { s_context.reset(); } void config::save() { s_context.save(); } -uint8_t config::get_by_key(std::string_view key) { return s_context.get_by_key(key); } +uint8_t config::get_by_key(std::string_view key) noexcept { return s_context.get_by_key(key); } -void config::toggle_by_key(std::string_view key) { s_context.toggle_by_key(key); } +void config::toggle_by_key(std::string_view key) noexcept { s_context.toggle_by_key(key); } -void config::set_by_key(std::string_view key, uint8_t value) { s_context.set_by_key(key, value); } +void config::set_by_key(std::string_view key, uint8_t value) noexcept { s_context.set_by_key(key, value); } fslib::Path config::get_working_directory() { return s_context.get_working_directory(); } -bool config::set_working_directory(const fslib::Path &path) +bool config::set_working_directory(const fslib::Path &path) noexcept { const bool pathSet = s_context.set_working_directory(path); if (!pathSet) { return false; } @@ -37,9 +37,9 @@ bool config::set_working_directory(const fslib::Path &path) return true; } -double config::get_animation_scaling() { return s_context.get_animation_scaling(); } +double config::get_animation_scaling() noexcept { return s_context.get_animation_scaling(); } -void config::set_animation_scaling(double newScale) { s_context.set_animation_scaling(newScale); } +void config::set_animation_scaling(double newScale) noexcept { s_context.set_animation_scaling(newScale); } void config::add_remove_favorite(uint64_t applicationID) { @@ -49,7 +49,7 @@ void config::add_remove_favorite(uint64_t applicationID) s_context.save(); } -bool config::is_favorite(uint64_t applicationID) { return s_context.is_favorite(applicationID); } +bool config::is_favorite(uint64_t applicationID) noexcept { return s_context.is_favorite(applicationID); } void config::add_remove_blacklist(uint64_t applicationID) { @@ -61,16 +61,16 @@ void config::add_remove_blacklist(uint64_t applicationID) void config::get_blacklisted_titles(std::vector &listOut) { s_context.get_blacklist(listOut); } -bool config::is_blacklisted(uint64_t applicationID) { return s_context.is_blacklisted(applicationID); } +bool config::is_blacklisted(uint64_t applicationID) noexcept { return s_context.is_blacklisted(applicationID); } -bool config::blacklist_is_empty() { return s_context.blacklist_empty(); } +bool config::blacklist_is_empty() noexcept { return s_context.blacklist_empty(); } void config::add_custom_path(uint64_t applicationID, std::string_view customPath) { s_context.add_custom_path(applicationID, customPath); } -bool config::has_custom_path(uint64_t applicationID) { return s_context.has_custom_path(applicationID); } +bool config::has_custom_path(uint64_t applicationID) noexcept { return s_context.has_custom_path(applicationID); } void config::get_custom_path(uint64_t applicationID, char *pathOut, size_t pathOutSize) { diff --git a/source/data/DataContext.cpp b/source/data/DataContext.cpp index 7861003..9662376 100644 --- a/source/data/DataContext.cpp +++ b/source/data/DataContext.cpp @@ -132,7 +132,7 @@ void data::DataContext::load_title(uint64_t applicationID) m_iconQueue.push_back(&m_titleInfo.at(applicationID)); } -data::TitleInfo *data::DataContext::get_title_by_id(uint64_t applicationID) +data::TitleInfo *data::DataContext::get_title_by_id(uint64_t applicationID) noexcept { std::lock_guard titleGuard{m_titleMutex}; auto findTitle = m_titleInfo.find(applicationID); diff --git a/source/data/TitleInfo.cpp b/source/data/TitleInfo.cpp index d73c3f7..27ec299 100644 --- a/source/data/TitleInfo.cpp +++ b/source/data/TitleInfo.cpp @@ -9,13 +9,12 @@ #include -data::TitleInfo::TitleInfo(uint64_t applicationID) +data::TitleInfo::TitleInfo(uint64_t applicationID) noexcept : m_applicationID(applicationID) { static constexpr size_t SIZE_CTRL_DATA = sizeof(NsApplicationControlData); uint64_t controlSize{}; - NacpLanguageEntry *entry{}; // This will filter from even trying to fetch control data for system titles. const bool isSystem = applicationID & 0x8000000000000000; @@ -24,7 +23,7 @@ data::TitleInfo::TitleInfo(uint64_t applicationID) &m_data, SIZE_CTRL_DATA, &controlSize)); - const bool entryError = !getError && error::libnx(nacpGetLanguageEntry(&m_data.nacp, &entry)); + const bool entryError = !getError && error::libnx(nacpGetLanguageEntry(&m_data.nacp, &m_entry)); if (isSystem || getError) { const std::string appIDHex = stringutil::get_formatted_string("%04X", m_applicationID & 0xFFFF); @@ -41,46 +40,33 @@ data::TitleInfo::TitleInfo(uint64_t applicationID) } // To do: Make this safer... -data::TitleInfo::TitleInfo(uint64_t applicationID, NsApplicationControlData &controlData) +data::TitleInfo::TitleInfo(uint64_t applicationID, NsApplicationControlData &controlData) noexcept : m_applicationID(applicationID) { m_hasData = true; m_data = controlData; - NacpLanguageEntry *entry{}; - const bool entryError = error::libnx(nacpGetLanguageEntry(&m_data.nacp, &entry)); - if (entryError) { std::snprintf(entry->name, TitleInfo::SIZE_PATH_SAFE, "%016lX", m_applicationID); } + const bool entryError = error::libnx(nacpGetLanguageEntry(&m_data.nacp, &m_entry)); + if (entryError) { std::snprintf(m_entry->name, TitleInfo::SIZE_PATH_SAFE, "%016lX", m_applicationID); } TitleInfo::get_create_path_safe_title(); } -uint64_t data::TitleInfo::get_application_id() const { return m_applicationID; } +uint64_t data::TitleInfo::get_application_id() const noexcept { return m_applicationID; } -NsApplicationControlData *data::TitleInfo::get_control_data() { return &m_data; } +const NsApplicationControlData *data::TitleInfo::get_control_data() const noexcept { return &m_data; } -bool data::TitleInfo::has_control_data() const { return m_hasData; } +bool data::TitleInfo::has_control_data() const noexcept { return m_hasData; } -const char *data::TitleInfo::get_title() -{ - NacpLanguageEntry *entry{}; - const bool entryError = error::libnx(nacpGetLanguageEntry(&m_data.nacp, &entry)); - if (entryError) { return nullptr; } - return entry->name; -} +const char *data::TitleInfo::get_title() const noexcept { return m_entry->name; } -const char *data::TitleInfo::get_path_safe_title() const { return m_pathSafeTitle; } +const char *data::TitleInfo::get_path_safe_title() const noexcept { return m_pathSafeTitle; } -const char *data::TitleInfo::get_publisher() -{ - NacpLanguageEntry *entry{}; - const bool entryError = error::libnx(nacpGetLanguageEntry(&m_data.nacp, &entry)); - if (entryError) { return nullptr; } - return entry->author; -} +const char *data::TitleInfo::get_publisher() const noexcept { return m_entry->author; } -uint64_t data::TitleInfo::get_save_data_owner_id() const { return m_data.nacp.save_data_owner_id; } +uint64_t data::TitleInfo::get_save_data_owner_id() const noexcept { return m_data.nacp.save_data_owner_id; } -int64_t data::TitleInfo::get_save_data_size(uint8_t saveType) const +int64_t data::TitleInfo::get_save_data_size(uint8_t saveType) const noexcept { const NacpStruct &nacp = m_data.nacp; switch (saveType) @@ -94,7 +80,7 @@ int64_t data::TitleInfo::get_save_data_size(uint8_t saveType) const return 0; } -int64_t data::TitleInfo::get_save_data_size_max(uint8_t saveType) const +int64_t data::TitleInfo::get_save_data_size_max(uint8_t saveType) const noexcept { const NacpStruct &nacp = m_data.nacp; switch (saveType) @@ -108,7 +94,7 @@ int64_t data::TitleInfo::get_save_data_size_max(uint8_t saveType) const return 0; } -int64_t data::TitleInfo::get_journal_size(uint8_t saveType) const +int64_t data::TitleInfo::get_journal_size(uint8_t saveType) const noexcept { const NacpStruct &nacp = m_data.nacp; switch (saveType) @@ -122,7 +108,7 @@ int64_t data::TitleInfo::get_journal_size(uint8_t saveType) const return 0; } -int64_t data::TitleInfo::get_journal_size_max(uint8_t saveType) const +int64_t data::TitleInfo::get_journal_size_max(uint8_t saveType) const noexcept { const NacpStruct &nacp = m_data.nacp; switch (saveType) @@ -138,7 +124,7 @@ int64_t data::TitleInfo::get_journal_size_max(uint8_t saveType) const return 0; } -bool data::TitleInfo::has_save_data_type(uint8_t saveType) const +bool data::TitleInfo::has_save_data_type(uint8_t saveType) const noexcept { const NacpStruct &nacp = m_data.nacp; switch (saveType) @@ -151,9 +137,9 @@ bool data::TitleInfo::has_save_data_type(uint8_t saveType) const return false; } -sdl::SharedTexture data::TitleInfo::get_icon() const { return m_icon; } +sdl::SharedTexture data::TitleInfo::get_icon() const noexcept { return m_icon; } -void data::TitleInfo::set_path_safe_title(const char *newPathSafe) +void data::TitleInfo::set_path_safe_title(const char *newPathSafe) noexcept { const size_t length = std::char_traits::length(newPathSafe); if (length >= TitleInfo::SIZE_PATH_SAFE) { return; } @@ -162,10 +148,9 @@ void data::TitleInfo::set_path_safe_title(const char *newPathSafe) std::memcpy(m_pathSafeTitle, newPathSafe, length); } -void data::TitleInfo::get_create_path_safe_title() +void data::TitleInfo::get_create_path_safe_title() noexcept { const uint64_t applicationID = TitleInfo::get_application_id(); - NacpLanguageEntry *entry{}; const bool hasCustom = config::has_custom_path(applicationID); if (hasCustom) @@ -175,13 +160,8 @@ void data::TitleInfo::get_create_path_safe_title() } const bool useTitleId = config::get_by_key(config::keys::USE_TITLE_IDS); - const bool entryError = !useTitleId && error::libnx(nacpGetLanguageEntry(&m_data.nacp, &entry)); - const bool sanitized = - !useTitleId && !entryError && stringutil::sanitize_string_for_path(entry->name, m_pathSafeTitle, SIZE_PATH_SAFE); - if (useTitleId || entryError || !sanitized) - { - std::snprintf(m_pathSafeTitle, TitleInfo::SIZE_PATH_SAFE, "%016lX", m_applicationID); - } + const bool sanitized = !useTitleId && stringutil::sanitize_string_for_path(m_entry->name, m_pathSafeTitle, SIZE_PATH_SAFE); + if (useTitleId || !sanitized) { std::snprintf(m_pathSafeTitle, TitleInfo::SIZE_PATH_SAFE, "%016lX", m_applicationID); } } void data::TitleInfo::load_icon() diff --git a/source/data/User.cpp b/source/data/User.cpp index affaba0..7b96745 100644 --- a/source/data/User.cpp +++ b/source/data/User.cpp @@ -33,7 +33,7 @@ namespace // Function used to sort user data. Definition at the bottom. static bool sort_user_data(const data::UserDataEntry &entryA, const data::UserDataEntry &entryB); -data::User::User(AccountUid accountID, FsSaveDataType saveType) +data::User::User(AccountUid accountID, FsSaveDataType saveType) noexcept : m_accountID{accountID} , m_saveType{saveType} { @@ -47,7 +47,10 @@ data::User::User(AccountUid accountID, FsSaveDataType saveType) accountProfileClose(&profile); } -data::User::User(AccountUid accountID, std::string_view nickname, std::string_view pathSafeNickname, FsSaveDataType saveType) +data::User::User(AccountUid accountID, + std::string_view nickname, + std::string_view pathSafeNickname, + FsSaveDataType saveType) noexcept : m_accountID{accountID} , m_saveType{saveType} { @@ -55,9 +58,9 @@ data::User::User(AccountUid accountID, std::string_view nickname, std::string_vi std::memcpy(m_pathSafeNickname, pathSafeNickname.data(), pathSafeNickname.length()); } -data::User::User(data::User &&user) { *this = std::move(user); } +data::User::User(data::User &&user) noexcept { *this = std::move(user); } -data::User &data::User::operator=(data::User &&user) +data::User &data::User::operator=(data::User &&user) noexcept { static constexpr size_t SIZE_NICKNAME = 0x20; @@ -88,50 +91,50 @@ void data::User::add_data(const FsSaveDataInfo *saveInfo, const PdmPlayStatistic m_userData.push_back(std::move(vectorPair)); } -void data::User::clear_data_entries() { m_userData.clear(); } +void data::User::clear_data_entries() noexcept { m_userData.clear(); } void data::User::erase_data(int index) { m_userData.erase(m_userData.begin() + index); } -void data::User::sort_data() { std::sort(m_userData.begin(), m_userData.end(), sort_user_data); } +void data::User::sort_data() noexcept { std::sort(m_userData.begin(), m_userData.end(), sort_user_data); } -AccountUid data::User::get_account_id() const { return m_accountID; } +AccountUid data::User::get_account_id() const noexcept { return m_accountID; } -FsSaveDataType data::User::get_account_save_type() const { return m_saveType; } +FsSaveDataType data::User::get_account_save_type() const noexcept { return m_saveType; } -const char *data::User::get_nickname() const { return m_nickname; } +const char *data::User::get_nickname() const noexcept { return m_nickname; } -const char *data::User::get_path_safe_nickname() const { return m_pathSafeNickname; } +const char *data::User::get_path_safe_nickname() const noexcept { return m_pathSafeNickname; } -size_t data::User::get_total_data_entries() const { return m_userData.size(); } +size_t data::User::get_total_data_entries() const noexcept { return m_userData.size(); } -uint64_t data::User::get_application_id_at(int index) const +uint64_t data::User::get_application_id_at(int index) const noexcept { if (!User::index_check(index)) { return 0; } return m_userData.at(index).first; } -FsSaveDataInfo *data::User::get_save_info_at(int index) +FsSaveDataInfo *data::User::get_save_info_at(int index) noexcept { if (!User::index_check(index)) { return nullptr; } return &m_userData.at(index).second.first; } -PdmPlayStatistics *data::User::get_play_stats_at(int index) +PdmPlayStatistics *data::User::get_play_stats_at(int index) noexcept { if (!User::index_check(index)) { return nullptr; } return &m_userData.at(index).second.second; } -FsSaveDataInfo *data::User::get_save_info_by_id(uint64_t applicationID) +FsSaveDataInfo *data::User::get_save_info_by_id(uint64_t applicationID) noexcept { auto target = User::find_title_by_id(applicationID); if (target == m_userData.end()) { return nullptr; } return &target->second.first; } -data::UserSaveInfoList &data::User::get_user_save_info_list() { return m_userData; } +data::UserSaveInfoList &data::User::get_user_save_info_list() noexcept { return m_userData; } -PdmPlayStatistics *data::User::get_play_stats_by_id(uint64_t applicationID) +PdmPlayStatistics *data::User::get_play_stats_by_id(uint64_t applicationID) noexcept { auto target = User::find_title_by_id(applicationID); if (target == m_userData.end()) { return nullptr; } diff --git a/source/data/data.cpp b/source/data/data.cpp index d9e6e86..06966f2 100644 --- a/source/data/data.cpp +++ b/source/data/data.cpp @@ -24,11 +24,14 @@ void data::launch_initialization(bool clearCache, std::function onDestru void data::get_users(data::UserList &userList) { s_context.get_users(userList); } -data::TitleInfo *data::get_title_info_by_id(uint64_t applicationID) { return s_context.get_title_by_id(applicationID); } +data::TitleInfo *data::get_title_info_by_id(uint64_t applicationID) noexcept +{ + return s_context.get_title_by_id(applicationID); +} void data::load_title_to_map(uint64_t applicationID) { s_context.load_title(applicationID); } -bool data::title_exists_in_map(uint64_t applicationID) { return s_context.title_is_loaded(applicationID); } +bool data::title_exists_in_map(uint64_t applicationID) noexcept { return s_context.title_is_loaded(applicationID); } void data::get_title_info_list(data::TitleInfoList &listOut) { s_context.get_title_info_list(listOut); } diff --git a/source/error.cpp b/source/error.cpp index d00c48c..290d860 100644 --- a/source/error.cpp +++ b/source/error.cpp @@ -7,9 +7,9 @@ #include /// @brief Prepares and makes sure the strings match the format I actually want! -static void prep_locations(std::string_view &file, std::string_view &function, const std::source_location &location); +static void prep_locations(std::string_view &file, std::string_view &function, const std::source_location &location) noexcept; -bool error::libnx(Result code, const std::source_location &location) +bool error::libnx(Result code, const std::source_location &location) noexcept { if (code == 0) { return false; } @@ -20,7 +20,7 @@ bool error::libnx(Result code, const std::source_location &location) return true; } -bool error::fslib(bool result, const std::source_location &location) +bool error::fslib(bool result, const std::source_location &location) noexcept { if (result) { return false; } @@ -37,7 +37,7 @@ bool error::fslib(bool result, const std::source_location &location) return true; } -bool error::is_null(const void *pointer, const std::source_location &location) +bool error::is_null(const void *pointer, const std::source_location &location) noexcept { if (pointer) { return false; } @@ -49,7 +49,7 @@ bool error::is_null(const void *pointer, const std::source_location &location) return true; } -static void prep_locations(std::string_view &file, std::string_view &function, const std::source_location &location) +static void prep_locations(std::string_view &file, std::string_view &function, const std::source_location &location) noexcept { file = location.file_name(); function = location.function_name(); diff --git a/source/fs/PathFilter.cpp b/source/fs/PathFilter.cpp index fdc85d0..5d3042a 100644 --- a/source/fs/PathFilter.cpp +++ b/source/fs/PathFilter.cpp @@ -22,9 +22,9 @@ fs::PathFilter::PathFilter(const fslib::Path &filePath) } } -bool fs::PathFilter::has_paths() const { return !m_paths.empty(); } +bool fs::PathFilter::has_paths() const noexcept { return !m_paths.empty(); } -bool fs::PathFilter::is_filtered(const fslib::Path &path) +bool fs::PathFilter::is_filtered(const fslib::Path &path) const noexcept { return std::find(m_paths.begin(), m_paths.end(), path) != m_paths.end(); } diff --git a/source/fs/SaveMetaData.cpp b/source/fs/SaveMetaData.cpp index 3f4e5fe..fdd99aa 100644 --- a/source/fs/SaveMetaData.cpp +++ b/source/fs/SaveMetaData.cpp @@ -11,7 +11,7 @@ namespace constexpr size_t SIZE_EXTRA_DATA = sizeof(FsSaveDataExtraData); } -bool fs::fill_save_meta_data(const FsSaveDataInfo *saveInfo, fs::SaveMetaData &meta) +bool fs::fill_save_meta_data(const FsSaveDataInfo *saveInfo, fs::SaveMetaData &meta) noexcept { FsSaveDataExtraData extraData{}; const bool extraRead = fs::read_save_extra_data(saveInfo, extraData); @@ -35,7 +35,7 @@ bool fs::fill_save_meta_data(const FsSaveDataInfo *saveInfo, fs::SaveMetaData &m return true; } -bool fs::process_save_meta_data(const FsSaveDataInfo *saveInfo, const SaveMetaData &meta) +bool fs::process_save_meta_data(const FsSaveDataInfo *saveInfo, const SaveMetaData &meta) noexcept { FsSaveDataExtraData extraData{}; const bool extraRead = fs::read_save_extra_data(saveInfo, extraData); diff --git a/source/fs/ScopedSaveMount.cpp b/source/fs/ScopedSaveMount.cpp index 7bb6cd5..cc11b46 100644 --- a/source/fs/ScopedSaveMount.cpp +++ b/source/fs/ScopedSaveMount.cpp @@ -11,9 +11,9 @@ fs::ScopedSaveMount::ScopedSaveMount(std::string_view mount, const FsSaveDataInf else { m_isOpen = fslib::open_save_data_with_save_info(m_mountPoint, *saveInfo); } } -fs::ScopedSaveMount::ScopedSaveMount(ScopedSaveMount &&scopedSaveMount) { *this = std::move(scopedSaveMount); } +fs::ScopedSaveMount::ScopedSaveMount(ScopedSaveMount &&scopedSaveMount) noexcept { *this = std::move(scopedSaveMount); } -fs::ScopedSaveMount &fs::ScopedSaveMount::operator=(ScopedSaveMount &&scopedSaveMount) +fs::ScopedSaveMount &fs::ScopedSaveMount::operator=(ScopedSaveMount &&scopedSaveMount) noexcept { m_mountPoint = std::move(scopedSaveMount.m_mountPoint); m_isOpen = scopedSaveMount.m_isOpen; @@ -27,4 +27,4 @@ fs::ScopedSaveMount::~ScopedSaveMount() else { fslib::close_file_system(m_mountPoint); } } -bool fs::ScopedSaveMount::is_open() const { return m_isOpen; } +bool fs::ScopedSaveMount::is_open() const noexcept { return m_isOpen; } diff --git a/source/fs/save_data_functions.cpp b/source/fs/save_data_functions.cpp index 3f6f395..3953e55 100644 --- a/source/fs/save_data_functions.cpp +++ b/source/fs/save_data_functions.cpp @@ -3,7 +3,7 @@ #include "error.hpp" #include "logging/logger.hpp" -bool fs::create_save_data_for(data::User *targetUser, data::TitleInfo *titleInfo) +bool fs::create_save_data_for(data::User *targetUser, data::TitleInfo *titleInfo) noexcept { static constexpr FsSaveDataMetaInfo saveMeta = {.size = 0x40060, .type = FsSaveDataMetaType_Thumbnail}; @@ -32,7 +32,7 @@ bool fs::create_save_data_for(data::User *targetUser, data::TitleInfo *titleInfo return error::libnx(fsCreateSaveDataFileSystem(&saveAttributes, &saveCreation, &saveMeta)) == false; } -bool fs::delete_save_data(const FsSaveDataInfo *saveInfo) +bool fs::delete_save_data(const FsSaveDataInfo *saveInfo) noexcept { const FsSaveDataSpaceId spaceID = static_cast(saveInfo->save_data_space_id); const bool isSystem = fs::is_system_save_data(saveInfo); @@ -57,12 +57,12 @@ bool fs::extend_save_data(const FsSaveDataInfo *saveInfo, int64_t size, int64_t return error::libnx(fsExtendSaveDataFileSystem(spaceID, saveID, size, journalSize)) == false; } -bool fs::is_system_save_data(const FsSaveDataInfo *saveInfo) +bool fs::is_system_save_data(const FsSaveDataInfo *saveInfo) noexcept { return saveInfo->save_data_type == FsSaveDataType_System || saveInfo->save_data_type == FsSaveDataType_SystemBcat; } -bool fs::read_save_extra_data(const FsSaveDataInfo *saveInfo, FsSaveDataExtraData &extraOut) +bool fs::read_save_extra_data(const FsSaveDataInfo *saveInfo, FsSaveDataExtraData &extraOut) noexcept { static constexpr size_t EXTRA_SIZE = sizeof(FsSaveDataExtraData); diff --git a/source/fs/zip.cpp b/source/fs/zip.cpp index 6c2a041..980778a 100644 --- a/source/fs/zip.cpp +++ b/source/fs/zip.cpp @@ -19,7 +19,7 @@ namespace { /// @brief Buffer size used for writing files to ZIP. - constexpr size_t SIZE_ZIP_BUFFER = 0x100000; + constexpr size_t SIZE_ZIP_BUFFER = 0x10000; /// @brief Buffer size used for decompressing files from ZIP. constexpr size_t SIZE_UNZIP_BUFFER = 0x600000; diff --git a/source/input.cpp b/source/input.cpp index 1f005f7..8b6e6df 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -11,16 +11,19 @@ void input::initialize() padInitializeDefault(&s_gamepad); } -void input::update() { padUpdate(&s_gamepad); } +void input::update() noexcept { padUpdate(&s_gamepad); } -bool input::button_pressed(HidNpadButton button) +bool input::button_pressed(HidNpadButton button) noexcept { return (s_gamepad.buttons_cur & button) && !(s_gamepad.buttons_old & button); } -bool input::button_held(HidNpadButton button) { return (s_gamepad.buttons_cur & button) && (s_gamepad.buttons_old & button); } +bool input::button_held(HidNpadButton button) noexcept +{ + return (s_gamepad.buttons_cur & button) && (s_gamepad.buttons_old & button); +} -bool input::button_released(HidNpadButton button) +bool input::button_released(HidNpadButton button) noexcept { return (s_gamepad.buttons_old & button) && !(s_gamepad.buttons_cur & button); } diff --git a/source/logging/logger.cpp b/source/logging/logger.cpp index 0b4c1af..b1adda1 100644 --- a/source/logging/logger.cpp +++ b/source/logging/logger.cpp @@ -27,7 +27,7 @@ void logger::initialize() if (!exists) { fslib::create_file(logPath); } } -void logger::log(const char *format, ...) +void logger::log(const char *format, ...) noexcept { static std::mutex logLock{}; diff --git a/source/remote/Form.cpp b/source/remote/Form.cpp index f4aa8ea..e05875f 100644 --- a/source/remote/Form.cpp +++ b/source/remote/Form.cpp @@ -2,7 +2,7 @@ remote::Form::Form(const remote::Form &form) { m_form = form.m_form; } -remote::Form::Form(remote::Form &&form) { m_form = std::move(form.m_form); } +remote::Form::Form(remote::Form &&form) noexcept { m_form = std::move(form.m_form); } remote::Form &remote::Form::operator=(const remote::Form &form) { @@ -10,7 +10,7 @@ remote::Form &remote::Form::operator=(const remote::Form &form) return *this; } -remote::Form &remote::Form::operator=(remote::Form &&form) +remote::Form &remote::Form::operator=(remote::Form &&form) noexcept { m_form = std::move(form.m_form); return *this; @@ -23,6 +23,6 @@ remote::Form &remote::Form::append_parameter(std::string_view param, std::string return *this; } -const char *remote::Form::get() const { return m_form.c_str(); } +const char *remote::Form::get() const noexcept { return m_form.c_str(); } -size_t remote::Form::length() const { return m_form.length(); } +size_t remote::Form::length() const noexcept { return m_form.length(); } diff --git a/source/remote/GoogleDrive.cpp b/source/remote/GoogleDrive.cpp index b46a80d..55bf06f 100644 --- a/source/remote/GoogleDrive.cpp +++ b/source/remote/GoogleDrive.cpp @@ -550,7 +550,7 @@ bool remote::GoogleDrive::get_root_id() return true; } -bool remote::GoogleDrive::token_is_valid() const +bool remote::GoogleDrive::token_is_valid() const noexcept { // I'm giving this a grace period just to be safe. return std::time(NULL) < m_tokenExpires - 10; @@ -681,7 +681,7 @@ bool remote::GoogleDrive::process_listing(json::Object &json) return true; } -bool remote::GoogleDrive::error_occurred(json::Object &json, bool log) +bool remote::GoogleDrive::error_occurred(json::Object &json, bool log) noexcept { json_object *error = json::get_object(json, "error"); if (!error) { return false; } diff --git a/source/remote/Item.cpp b/source/remote/Item.cpp index 045c412..b657299 100644 --- a/source/remote/Item.cpp +++ b/source/remote/Item.cpp @@ -9,15 +9,15 @@ remote::Item::Item(std::string_view name, std::string_view id, std::string_view , m_size{size} , m_isDirectory{directory} {}; -std::string_view remote::Item::get_name() const { return m_name; } +std::string_view remote::Item::get_name() const noexcept { return m_name; } -std::string_view remote::Item::get_id() const { return m_id; } +std::string_view remote::Item::get_id() const noexcept { return m_id; } -std::string_view remote::Item::get_parent_id() const { return m_parent; } +std::string_view remote::Item::get_parent_id() const noexcept { return m_parent; } -size_t remote::Item::get_size() const { return m_size; } +size_t remote::Item::get_size() const noexcept { return m_size; } -bool remote::Item::is_directory() const { return m_isDirectory; } +bool remote::Item::is_directory() const noexcept { return m_isDirectory; } void remote::Item::set_name(std::string_view name) { m_name = name; } @@ -25,6 +25,6 @@ void remote::Item::set_id(std::string_view id) { m_id = id; } void remote::Item::set_parent_id(std::string_view parent) { m_parent = parent; } -void remote::Item::set_size(size_t size) { m_size = size; } +void remote::Item::set_size(size_t size) noexcept { m_size = size; } -void remote::Item::set_is_directory(bool directory) { m_isDirectory = directory; } +void remote::Item::set_is_directory(bool directory) noexcept { m_isDirectory = directory; } diff --git a/source/remote/Storage.cpp b/source/remote/Storage.cpp index 89516d8..d9819e6 100644 --- a/source/remote/Storage.cpp +++ b/source/remote/Storage.cpp @@ -11,9 +11,12 @@ remote::Storage::Storage(std::string_view prefix, bool supportsUtf8) , m_utf8Paths(supportsUtf8) , m_prefix(prefix) {}; -bool remote::Storage::is_initialized() const { return m_isInitialized; } +bool remote::Storage::is_initialized() const noexcept { return m_isInitialized; } -bool remote::Storage::directory_exists(std::string_view name) { return Storage::find_directory_by_name(name) != m_list.end(); } +bool remote::Storage::directory_exists(std::string_view name) const noexcept +{ + return Storage::find_directory_by_name(name) != m_list.end(); +} void remote::Storage::return_to_root() { m_parent = m_root; } @@ -21,7 +24,7 @@ void remote::Storage::set_root_directory(const remote::Item *root) { m_root = ro void remote::Storage::change_directory(const remote::Item *item) { m_parent = item->get_id(); } -remote::Item *remote::Storage::get_directory_by_name(std::string_view name) +remote::Item *remote::Storage::get_directory_by_name(std::string_view name) noexcept { auto findDirectory = Storage::find_directory_by_name(name); if (findDirectory == m_list.end()) { return nullptr; } @@ -53,22 +56,25 @@ void remote::Storage::get_directory_listing_with_parent(const remote::Item *item } } -bool remote::Storage::file_exists(std::string_view name) { return Storage::find_file_by_name(name) != m_list.end(); } +bool remote::Storage::file_exists(std::string_view name) const noexcept +{ + return Storage::find_file_by_name(name) != m_list.end(); +} -remote::Item *remote::Storage::get_file_by_name(std::string_view name) +remote::Item *remote::Storage::get_file_by_name(std::string_view name) noexcept { auto findFile = Storage::find_file_by_name(name); if (findFile == m_list.end()) { return nullptr; } return &(*findFile); } -bool remote::Storage::supports_utf8() const { return m_utf8Paths; } +bool remote::Storage::supports_utf8() const noexcept { return m_utf8Paths; } -std::string_view remote::Storage::get_prefix() const { return m_prefix; } +std::string_view remote::Storage::get_prefix() const noexcept { return m_prefix; } -remote::Storage::List::iterator remote::Storage::find_directory_by_name(std::string_view name) +remote::Storage::List::iterator remote::Storage::find_directory_by_name(std::string_view name) noexcept { - auto is_match = [&](const Item &item) + auto is_match = [&](const Item &item) noexcept { const bool isDir = item.is_directory(); const bool parentMatch = isDir && item.get_parent_id() == m_parent; @@ -80,9 +86,23 @@ remote::Storage::List::iterator remote::Storage::find_directory_by_name(std::str return std::find_if(m_list.begin(), m_list.end(), is_match); } -remote::Storage::List::iterator remote::Storage::find_directory_by_id(std::string_view id) +remote::Storage::List::const_iterator remote::Storage::find_directory_by_name(std::string_view name) const noexcept { - auto is_match = [&](const Item &item) + auto is_match = [&](const Item &item) noexcept + { + const bool isDir = item.is_directory(); + const bool parentMatch = isDir && item.get_parent_id() == m_parent; + const bool nameMatch = parentMatch && item.get_name() == name; + + return isDir && parentMatch && nameMatch; + }; + + return std::find_if(m_list.begin(), m_list.end(), is_match); +} + +remote::Storage::List::iterator remote::Storage::find_directory_by_id(std::string_view id) noexcept +{ + auto is_match = [&](const Item &item) noexcept { const bool isDir = item.is_directory(); const bool idMatch = item.get_id() == id; @@ -92,23 +112,50 @@ remote::Storage::List::iterator remote::Storage::find_directory_by_id(std::strin return std::find_if(m_list.begin(), m_list.end(), is_match); } -remote::Storage::List::iterator remote::Storage::find_file_by_name(std::string_view name) +remote::Storage::List::const_iterator remote::Storage::find_directory_by_id(std::string_view id) const noexcept { - auto is_match = [&](const Item &item) + auto is_match = [&](const Item &item) noexcept { - const bool notDir = !item.is_directory(); - const bool parentMatch = notDir && item.get_parent_id() == m_parent; - const bool nameMatch = parentMatch && item.get_name() == name; + const bool isDir = item.is_directory(); + const bool idMatch = item.get_id() == id; - return notDir && parentMatch && nameMatch; + return isDir && idMatch; }; return std::find_if(m_list.begin(), m_list.end(), is_match); } -remote::Storage::List::iterator remote::Storage::find_file_by_id(std::string_view id) +remote::Storage::List::iterator remote::Storage::find_file_by_name(std::string_view name) noexcept { - auto is_match = [&](const Item &item) + 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 nameMatch = parentMatch && item.get_name() == name; + + return isFile && parentMatch && nameMatch; + }; + + return std::find_if(m_list.begin(), m_list.end(), is_match); +} + +remote::Storage::List::const_iterator remote::Storage::find_file_by_name(std::string_view name) const noexcept +{ + 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 nameMatch = parentMatch && item.get_name() == name; + + return isFile && parentMatch && nameMatch; + }; + + return std::find_if(m_list.begin(), m_list.end(), is_match); +} + +remote::Storage::List::iterator remote::Storage::find_file_by_id(std::string_view id) noexcept +{ + auto is_match = [&](const Item &item) noexcept { const bool isFile = !item.is_directory(); const bool isMatch = item.get_id() == id; @@ -119,22 +166,45 @@ remote::Storage::List::iterator remote::Storage::find_file_by_id(std::string_vie return std::find_if(m_list.begin(), m_list.end(), is_match); } -remote::Storage::List::iterator remote::Storage::find_item_by_id(std::string_view id) +remote::Storage::List::const_iterator remote::Storage::find_file_by_id(std::string_view id) const noexcept { - auto is_match = [&](const Item &item) + auto is_match = [&](const remote::Item &item) noexcept { + const bool isFile = !item.is_directory(); const bool isMatch = item.get_id() == id; - return isMatch; + return isFile && isMatch; }; return std::find_if(m_list.begin(), m_list.end(), is_match); } +remote::Storage::List::iterator remote::Storage::find_item_by_id(std::string_view id) noexcept +{ + auto is_match = [&](const Item &item) { return item.get_id() == id; }; + + return std::find_if(m_list.begin(), m_list.end(), is_match); +} + +remote::Storage::List::const_iterator remote::Storage::find_item_by_id(std::string_view id) const noexcept +{ + auto is_match = [&](const remote::Item &item) { return item.get_id() == id; }; + + return std::find_if(m_list.begin(), m_list.end(), is_match); +} + remote::Storage::List::iterator remote::Storage::find_by_parent_id(remote::Storage::List::iterator start, - std::string_view parentID) + std::string_view parentID) noexcept { auto is_match = [&](const Item &item) { return item.get_parent_id() == parentID; }; return std::find_if(start, m_list.end(), is_match); } + +remote::Storage::List::const_iterator remote::Storage::find_by_parent_id(Storage::List::const_iterator start, + std::string_view parentID) const noexcept +{ + auto is_match = [&](const remote::Item &item) { return item.get_parent_id() == parentID; }; + + return std::find_if(start, m_list.end(), is_match); +} diff --git a/source/remote/URL.cpp b/source/remote/URL.cpp index e2322bd..1b7d9cd 100644 --- a/source/remote/URL.cpp +++ b/source/remote/URL.cpp @@ -13,7 +13,7 @@ remote::URL &remote::URL::operator=(const remote::URL &url) return *this; } -remote::URL &remote::URL::operator=(remote::URL &&url) +remote::URL &remote::URL::operator=(remote::URL &&url) noexcept { m_url = std::move(url.m_url); return *this; @@ -47,7 +47,7 @@ remote::URL &remote::URL::append_slash() return *this; } -const char *remote::URL::get() const { return m_url.c_str(); } +const char *remote::URL::get() const noexcept { return m_url.c_str(); } void remote::URL::append_separator() { diff --git a/source/remote/remote.cpp b/source/remote/remote.cpp index 5270232..58d7a0e 100644 --- a/source/remote/remote.cpp +++ b/source/remote/remote.cpp @@ -31,7 +31,7 @@ static void drive_sign_in(sys::Task *task, remote::GoogleDrive *drive); /// @param drive Pointer to the drive instance.. static void drive_set_jksv_root(remote::GoogleDrive *drive); -bool remote::has_internet_connection() +bool remote::has_internet_connection() noexcept { NifmInternetConnectionType type{}; uint32_t strength{}; @@ -86,7 +86,7 @@ void remote::initialize_webdav() } } -remote::Storage *remote::get_remote_storage() +remote::Storage *remote::get_remote_storage() noexcept { if (!s_storage || !s_storage->is_initialized()) { return nullptr; } return s_storage.get(); diff --git a/source/strings/strings.cpp b/source/strings/strings.cpp index 48300bb..80aa112 100644 --- a/source/strings/strings.cpp +++ b/source/strings/strings.cpp @@ -78,7 +78,7 @@ bool strings::initialize() return true; } -const char *strings::get_by_name(std::string_view name, int index) +const char *strings::get_by_name(std::string_view name, int index) noexcept { const auto mapPair = std::make_pair(name.data(), index); const auto findPair = s_stringMap.find(mapPair); diff --git a/source/sys/ProgressTask.cpp b/source/sys/ProgressTask.cpp index 13d50aa..f03c25e 100644 --- a/source/sys/ProgressTask.cpp +++ b/source/sys/ProgressTask.cpp @@ -1,18 +1,18 @@ #include "sys/ProgressTask.hpp" -void sys::ProgressTask::reset(double goal) +void sys::ProgressTask::reset(double goal) noexcept { m_current = 0; m_goal = goal; } -void sys::ProgressTask::update_current(double current) { m_current = current; } +void sys::ProgressTask::update_current(double current) noexcept { m_current = current; } -void sys::ProgressTask::increase_current(double amount) { m_current += amount; } +void sys::ProgressTask::increase_current(double amount) noexcept { m_current += amount; } -double sys::ProgressTask::get_goal() const { return m_goal; } +double sys::ProgressTask::get_goal() const noexcept { return m_goal; } -double sys::ProgressTask::get_progress() const +double sys::ProgressTask::get_progress() const noexcept { // Reminder: Never divide by zero. It ends badly every time! return m_goal > 0 ? m_current / m_goal : 0; diff --git a/source/sys/Task.cpp b/source/sys/Task.cpp index 572e567..46180e5 100644 --- a/source/sys/Task.cpp +++ b/source/sys/Task.cpp @@ -4,9 +4,9 @@ sys::Task::~Task() { m_thread.join(); } -bool sys::Task::is_running() const { return m_isRunning; } +bool sys::Task::is_running() const noexcept { return m_isRunning; } -void sys::Task::complete() { m_isRunning = false; } +void sys::Task::complete() noexcept { m_isRunning = false; } void sys::Task::set_status(std::string_view status) { @@ -14,7 +14,7 @@ void sys::Task::set_status(std::string_view status) m_status = status; } -std::string sys::Task::get_status() +std::string sys::Task::get_status() noexcept { std::lock_guard statusGuard{m_statusLock}; return m_status; diff --git a/source/sys/Timer.cpp b/source/sys/Timer.cpp index 65b3148..a7078c6 100644 --- a/source/sys/Timer.cpp +++ b/source/sys/Timer.cpp @@ -4,15 +4,15 @@ #include -sys::Timer::Timer(uint64_t triggerTicks) { Timer::start(triggerTicks); } +sys::Timer::Timer(uint64_t triggerTicks) noexcept { Timer::start(triggerTicks); } -void sys::Timer::start(uint64_t triggerTicks) +void sys::Timer::start(uint64_t triggerTicks) noexcept { m_triggerTicks = triggerTicks; m_startingTicks = SDL_GetTicks64(); } -bool sys::Timer::is_triggered() +bool sys::Timer::is_triggered() noexcept { const uint64_t currentTicks = SDL_GetTicks64(); const bool started = m_startingTicks != 0 && m_triggerTicks != 0; @@ -23,4 +23,4 @@ bool sys::Timer::is_triggered() return true; } -void sys::Timer::restart() { m_startingTicks = SDL_GetTicks64(); } +void sys::Timer::restart() noexcept { m_startingTicks = SDL_GetTicks64(); } diff --git a/source/tasks/fileoptions.cpp b/source/tasks/fileoptions.cpp index 999bb69..0750c63 100644 --- a/source/tasks/fileoptions.cpp +++ b/source/tasks/fileoptions.cpp @@ -3,23 +3,40 @@ #include "error.hpp" #include "fs/fs.hpp" #include "fslib.hpp" +#include "logging/logger.hpp" void tasks::fileoptions::copy_source_to_destination(sys::ProgressTask *task, FileOptionState::TaskData taskData) { if (error::is_null(task)) { return; } - fslib::Path &source = taskData->sourcePath; - fslib::Path &dest = taskData->destPath; - int64_t journalSpace = taskData->journalSize; + const fslib::Path &source = taskData->sourcePath; + const fslib::Path &dest = taskData->destPath; + const int64_t journalSpace = taskData->journalSize; + FileOptionState *spawningState = taskData->spawningState; + + const bool sourceIsDir = fslib::directory_exists(source); + bool destError = false; + if (sourceIsDir) { destError = error::fslib(fslib::create_directories_recursively(dest)); } + else + { + const size_t subDest = dest.find_last_of('/'); + if (subDest != dest.NOT_FOUND && subDest > 1) + { + fslib::Path subDestPath{dest.sub_path(subDest)}; + destError = error::fslib(fslib::create_directories_recursively(subDestPath)); + } + } + + if (destError) { TASK_FINISH_RETURN(task); } - const bool isDir = fslib::directory_exists(source); const bool needsCommit = journalSpace > 0; - if (isDir && needsCommit) { fs::copy_directory_commit(source, dest, journalSpace, task); } - else if (!isDir && needsCommit) { fs::copy_file_commit(source, dest, journalSpace, task); } - else if (isDir && !needsCommit) { fs::copy_directory(source, dest, task); } - else if (!isDir && !needsCommit) { fs::copy_file(source, dest, task); } + if (sourceIsDir && needsCommit) { fs::copy_directory_commit(source, dest, journalSpace, task); } + else if (!sourceIsDir && needsCommit) { fs::copy_file_commit(source, dest, journalSpace, task); } + else if (sourceIsDir && !needsCommit) { fs::copy_directory(source, dest, task); } + else if (!sourceIsDir && !needsCommit) { fs::copy_file(source, dest, task); } + spawningState->update_destination(); task->complete(); } @@ -27,8 +44,9 @@ void tasks::fileoptions::delete_target(sys::Task *task, FileOptionState::TaskDat { if (error::is_null(task)) { return; } - fslib::Path target = taskData->sourcePath; - int64_t journalSpace = taskData->journalSize; + fslib::Path target = taskData->sourcePath; + int64_t journalSpace = taskData->journalSize; + FileOptionState *spawningState = taskData->spawningState; const bool isDir = fslib::directory_exists(target); bool needsCommit = journalSpace > 0; @@ -38,5 +56,6 @@ void tasks::fileoptions::delete_target(sys::Task *task, FileOptionState::TaskDat if (needsCommit) { fslib::commit_data_to_file_system(target.get_device_name()); } + spawningState->update_source(); task->complete(); } \ No newline at end of file diff --git a/source/ui/BoundingBox.cpp b/source/ui/BoundingBox.cpp index 71c4ebd..2fb6273 100644 --- a/source/ui/BoundingBox.cpp +++ b/source/ui/BoundingBox.cpp @@ -46,17 +46,13 @@ void ui::BoundingBox::render(sdl::SharedTexture &target, bool hasFocus) sm_corners->render_part(target, rightX, bottomY, CORNER_WIDTH, CORNER_HEIGHT, CORNER_WIDTH, CORNER_HEIGHT); } -void ui::BoundingBox::set_xy(int x, int y) -{ - if (x != BoundingBox::NO_SET) { m_x = x; } - if (y != BoundingBox::NO_SET) { m_y = y; } -} +void ui::BoundingBox::set_x(int x) noexcept { m_x = x; } -void ui::BoundingBox::set_width_height(int width, int height) -{ - if (width != BoundingBox::NO_SET) { m_width = width; } - if (height != BoundingBox::NO_SET) { m_height = height; } -} +void ui::BoundingBox::set_y(int y) noexcept { m_y = y; } + +void ui::BoundingBox::set_width(int width) noexcept { m_width = width; } + +void ui::BoundingBox::set_height(int height) noexcept { m_height = height; } void ui::BoundingBox::initialize_static_members() { diff --git a/source/ui/ColorMod.cpp b/source/ui/ColorMod.cpp index 5b71993..5c4e5d5 100644 --- a/source/ui/ColorMod.cpp +++ b/source/ui/ColorMod.cpp @@ -1,6 +1,6 @@ #include "ui/ColorMod.hpp" -void ui::ColorMod::update() +void ui::ColorMod::update() noexcept { const bool changeDown = m_direction && ((m_colorMod += 6) >= 0x72); const bool changeUp = !m_direction && ((m_colorMod -= 3) <= 0x00); @@ -8,7 +8,7 @@ void ui::ColorMod::update() else if (changeUp) { m_direction = true; } } -ui::ColorMod::operator sdl::Color() const +ui::ColorMod::operator sdl::Color() const noexcept { uint32_t color{}; color |= static_cast((0x88 + m_colorMod) << 16); diff --git a/source/ui/DialogBox.cpp b/source/ui/DialogBox.cpp index a8417f4..9614ab6 100644 --- a/source/ui/DialogBox.cpp +++ b/source/ui/DialogBox.cpp @@ -49,13 +49,13 @@ void ui::DialogBox::render(sdl::SharedTexture &target, bool hasFocus) CORNER_HEIGHT); } -void ui::DialogBox::set_x(int x) { m_x = x; } +void ui::DialogBox::set_x(int x) noexcept { m_x = x; } -void ui::DialogBox::set_y(int y) { m_y = y; } +void ui::DialogBox::set_y(int y) noexcept { m_y = y; } -void ui::DialogBox::set_width(int width) { m_width = width; } +void ui::DialogBox::set_width(int width) noexcept { m_width = width; } -void ui::DialogBox::set_height(int height) { m_height = height; } +void ui::DialogBox::set_height(int height) noexcept { m_height = height; } void ui::DialogBox::initialize_static_members() { diff --git a/source/ui/IconMenu.cpp b/source/ui/IconMenu.cpp index 0f155b6..ed72f70 100644 --- a/source/ui/IconMenu.cpp +++ b/source/ui/IconMenu.cpp @@ -15,7 +15,8 @@ ui::IconMenu::IconMenu(int x, int y, int renderTargetHeight) : Menu(x, y, 152, 84, renderTargetHeight) { // This needs to be overriden from the base state. - m_boundingBox->set_width_height(152, 146); + m_boundingBox->set_width(152); + m_boundingBox->set_height(146); } void ui::IconMenu::update(bool hasFocus) { Menu::update(hasFocus); } @@ -31,7 +32,8 @@ void ui::IconMenu::render(sdl::SharedTexture &target, bool hasFocus) { if (hasFocus) { - m_boundingBox->set_xy(m_x - 8, tempY - 8); + m_boundingBox->set_x(m_x - 8); + m_boundingBox->set_y(tempY - 8); m_boundingBox->render(target, hasFocus); } // This is always rendered. diff --git a/source/ui/Menu.cpp b/source/ui/Menu.cpp index d71bdd4..213ce9b 100644 --- a/source/ui/Menu.cpp +++ b/source/ui/Menu.cpp @@ -63,7 +63,8 @@ void ui::Menu::render(sdl::SharedTexture &target, bool hasFocus) { if (hasFocus) { - m_boundingBox->set_xy(m_x - 4, tempY - 4); + m_boundingBox->set_x(m_x - 4); + m_boundingBox->set_y(tempY - 4); m_boundingBox->render(target, hasFocus); } sdl::render_rect_fill(m_optionTarget, 8, 8, 4, m_optionHeight - 14, colors::BLUE_GREEN); @@ -89,19 +90,18 @@ void ui::Menu::edit_option(int index, std::string_view newOption) m_options[index] = newOption.data(); } -int ui::Menu::get_selected() const { return m_selected; } +int ui::Menu::get_selected() const noexcept { return m_selected; } void ui::Menu::set_selected(int selected) { m_selected = selected; Menu::update_scroll_text(); } +void ui::Menu::set_x(int x) noexcept { m_x = x; } -void ui::Menu::set_width(int width) { m_width = width; } +void ui::Menu::set_y(int y) noexcept { m_y = y; } -void ui::Menu::set_x(int x) { m_x = x; } - -void ui::Menu::set_y(int y) { m_y = y; } +void ui::Menu::set_width(int width) noexcept { m_width = width; } void ui::Menu::reset() { @@ -110,7 +110,7 @@ void ui::Menu::reset() m_options.clear(); } -bool ui::Menu::is_empty() const { return m_options.empty(); } +bool ui::Menu::is_empty() const noexcept { return m_options.empty(); } void ui::Menu::update_scroll_text() { diff --git a/source/ui/PopMessage.cpp b/source/ui/PopMessage.cpp index 7912579..816a59b 100644 --- a/source/ui/PopMessage.cpp +++ b/source/ui/PopMessage.cpp @@ -32,11 +32,11 @@ void ui::PopMessage::render() sdl::text::render(sdl::Texture::Null, m_textX, m_y + 5, 22, sdl::text::NO_WRAP, colors::BLACK, message); } -std::string_view ui::PopMessage::get_message() const { return m_message; } +bool ui::PopMessage::finished() const noexcept { return m_finished; } -bool ui::PopMessage::finished() const { return m_finished; } +std::string_view ui::PopMessage::get_message() const noexcept { return m_message; } -void ui::PopMessage::update_y(double targetY) +void ui::PopMessage::update_y(double targetY) noexcept { if (m_y == targetY) { return; } @@ -54,7 +54,7 @@ void ui::PopMessage::update_y(double targetY) m_dialog->set_y(m_y - 6); } -void ui::PopMessage::update_text_offset() +void ui::PopMessage::update_text_offset() noexcept { static constexpr int HALF_WIDTH = 640; diff --git a/source/ui/SlideOutPanel.cpp b/source/ui/SlideOutPanel.cpp index 1cd122f..b6bf9aa 100644 --- a/source/ui/SlideOutPanel.cpp +++ b/source/ui/SlideOutPanel.cpp @@ -46,37 +46,37 @@ void ui::SlideOutPanel::render(sdl::SharedTexture &target, bool hasFocus) void ui::SlideOutPanel::clear_target() { m_renderTarget->clear(colors::SLIDE_PANEL_CLEAR); } -void ui::SlideOutPanel::reset() +void ui::SlideOutPanel::reset() noexcept { m_x = m_side == Side::Left ? -(m_width) : SCREEN_WIDTH; m_isOpen = false; m_closePanel = false; } -void ui::SlideOutPanel::close() { m_closePanel = true; } +void ui::SlideOutPanel::close() noexcept { m_closePanel = true; } -void ui::SlideOutPanel::hide() { m_hidePanel = true; } +void ui::SlideOutPanel::hide() noexcept { m_hidePanel = true; } -void ui::SlideOutPanel::unhide() { m_hidePanel = false; } +void ui::SlideOutPanel::unhide() noexcept { m_hidePanel = false; } -bool ui::SlideOutPanel::is_open() const { return m_isOpen; } +bool ui::SlideOutPanel::is_open() const noexcept { return m_isOpen; } -bool ui::SlideOutPanel::is_closed() +bool ui::SlideOutPanel::is_closed() noexcept { close_hide_panel(); const bool closed = m_side == Side::Left ? m_x <= -m_width : m_x >= SCREEN_WIDTH; return m_closePanel && closed; } -bool ui::SlideOutPanel::is_hidden() const { return m_hidePanel; } +bool ui::SlideOutPanel::is_hidden() const noexcept { return m_hidePanel; } void ui::SlideOutPanel::push_new_element(std::shared_ptr newElement) { m_elements.push_back(newElement); } void ui::SlideOutPanel::clear_elements() { m_elements.clear(); } -sdl::SharedTexture &ui::SlideOutPanel::get_target() { return m_renderTarget; } +sdl::SharedTexture &ui::SlideOutPanel::get_target() noexcept { return m_renderTarget; } -void ui::SlideOutPanel::slide_out() +void ui::SlideOutPanel::slide_out() noexcept { const bool needsSlideOut = !m_isOpen && !m_closePanel && !m_hidePanel; if (!needsSlideOut) { return; } @@ -88,7 +88,7 @@ void ui::SlideOutPanel::slide_out() else if (slideLeft) { SlideOutPanel::slide_out_right(); } } -void ui::SlideOutPanel::slide_out_left() +void ui::SlideOutPanel::slide_out_left() noexcept { const double scaling = config::get_animation_scaling(); @@ -103,7 +103,7 @@ void ui::SlideOutPanel::slide_out_left() } } -void ui::SlideOutPanel::slide_out_right() +void ui::SlideOutPanel::slide_out_right() noexcept { const double scaling = config::get_animation_scaling(); const double screenWidth = static_cast(SCREEN_WIDTH); @@ -119,7 +119,7 @@ void ui::SlideOutPanel::slide_out_right() } } -void ui::SlideOutPanel::close_hide_panel() +void ui::SlideOutPanel::close_hide_panel() noexcept { const double scaling = config::get_animation_scaling(); const bool closeHide = m_closePanel || m_hidePanel; diff --git a/source/ui/TextScroll.cpp b/source/ui/TextScroll.cpp index f0271db..6b42b79 100644 --- a/source/ui/TextScroll.cpp +++ b/source/ui/TextScroll.cpp @@ -54,7 +54,7 @@ void ui::TextScroll::initialize(std::string_view text, TextScroll::set_text(text, center); } -std::string_view ui::TextScroll::get_text() const { return m_text; } +std::string_view ui::TextScroll::get_text() const noexcept { return m_text; } void ui::TextScroll::set_text(std::string_view text, bool center) { @@ -103,12 +103,6 @@ void ui::TextScroll::update(bool hasFocus) } } -void ui::TextScroll::set_xy(int x, int y) -{ - m_renderX = x; - m_renderY = y; -} - void ui::TextScroll::render(sdl::SharedTexture &target, bool hasFocus) { m_renderTarget->clear(m_clearColor); diff --git a/source/ui/TitleTile.cpp b/source/ui/TitleTile.cpp index d1c082b..a0822ba 100644 --- a/source/ui/TitleTile.cpp +++ b/source/ui/TitleTile.cpp @@ -40,12 +40,12 @@ void ui::TitleTile::render(sdl::SharedTexture &target, int x, int y) if (m_isFavorite) { sdl::text::render(target, renderX + 2, renderY + 2, 28, sdl::text::NO_WRAP, colors::PINK, HEART_CHAR); } } -void ui::TitleTile::reset() +void ui::TitleTile::reset() noexcept { m_renderWidth = 128; m_renderHeight = 128; } -int ui::TitleTile::get_width() const { return m_renderWidth; } +int ui::TitleTile::get_width() const noexcept { return m_renderWidth; } -int ui::TitleTile::get_height() const { return m_renderHeight; } +int ui::TitleTile::get_height() const noexcept { return m_renderHeight; } diff --git a/source/ui/TitleView.cpp b/source/ui/TitleView.cpp index 9f68ab2..7cec71e 100644 --- a/source/ui/TitleView.cpp +++ b/source/ui/TitleView.cpp @@ -57,7 +57,8 @@ void ui::TitleView::render(sdl::SharedTexture &target, bool hasFocus) if (hasFocus) { - m_bounding->set_xy(m_selectedX - 30, m_selectedY - 30); + m_bounding->set_x(m_selectedX - 30); + m_bounding->set_y(m_selectedY - 30); sdl::render_rect_fill(target, m_selectedX - 28, m_selectedY - 28, 184, 184, colors::CLEAR_COLOR); m_bounding->render(target, hasFocus); } @@ -66,9 +67,9 @@ void ui::TitleView::render(sdl::SharedTexture &target, bool hasFocus) selectedTile.render(target, m_selectedX, m_selectedY); } -int ui::TitleView::get_selected() const { return m_selected; } +int ui::TitleView::get_selected() const noexcept { return m_selected; } -void ui::TitleView::set_selected(int selected) +void ui::TitleView::set_selected(int selected) noexcept { const int tilesCount = m_titleTiles.size(); if (selected < 0 || selected >= tilesCount) { return; }