From 2ff2923d39d7a87956303001a1986a74ae2a0597 Mon Sep 17 00:00:00 2001 From: ITotalJustice <47043333+ITotalJustice@users.noreply.github.com> Date: Mon, 23 Jun 2025 20:02:04 +0100 Subject: [PATCH] replace almost all uses of shared_ptr with unique_ptr. --- sphaira/CMakeLists.txt | 1 + sphaira/include/app.hpp | 4 +- sphaira/include/dumper.hpp | 6 +- sphaira/include/hasher.hpp | 2 +- sphaira/include/title_info.hpp | 4 +- sphaira/include/ui/menus/appstore.hpp | 6 +- sphaira/include/ui/menus/filebrowser.hpp | 10 +- sphaira/include/ui/menus/game_menu.hpp | 2 - .../ui/menus/install_stream_menu_base.hpp | 2 +- sphaira/include/ui/menus/main_menu.hpp | 12 +- sphaira/include/ui/menus/save_menu.hpp | 2 - sphaira/include/ui/menus/usb_menu.hpp | 2 +- sphaira/include/ui/sidebar.hpp | 15 +- sphaira/include/yati/container/base.hpp | 4 +- sphaira/include/yati/yati.hpp | 6 +- sphaira/source/app.cpp | 130 +++++++-------- sphaira/source/dumper.cpp | 12 +- sphaira/source/hasher.cpp | 12 +- sphaira/source/haze_helper.cpp | 13 +- sphaira/source/owo.cpp | 2 +- sphaira/source/title_info.cpp | 31 ++-- sphaira/source/ui/menus/appstore.cpp | 41 +++-- sphaira/source/ui/menus/filebrowser.cpp | 152 +++++++++--------- sphaira/source/ui/menus/game_menu.cpp | 105 ++++++------ sphaira/source/ui/menus/gc_menu.cpp | 24 +-- sphaira/source/ui/menus/ghdl.cpp | 10 +- sphaira/source/ui/menus/homebrew.cpp | 28 ++-- .../ui/menus/install_stream_menu_base.cpp | 6 +- sphaira/source/ui/menus/irs_menu.cpp | 24 +-- sphaira/source/ui/menus/main_menu.cpp | 71 ++++---- sphaira/source/ui/menus/save_menu.cpp | 72 ++++----- sphaira/source/ui/menus/themezer.cpp | 18 +-- sphaira/source/ui/menus/usb_menu.cpp | 6 +- sphaira/source/ui/progress_box.cpp | 2 +- sphaira/source/ui/sidebar.cpp | 18 +-- sphaira/source/yati/container/xci.cpp | 4 +- sphaira/source/yati/yati.cpp | 29 ++-- 37 files changed, 446 insertions(+), 442 deletions(-) diff --git a/sphaira/CMakeLists.txt b/sphaira/CMakeLists.txt index 6cb1188..9f85f55 100644 --- a/sphaira/CMakeLists.txt +++ b/sphaira/CMakeLists.txt @@ -150,6 +150,7 @@ target_compile_options(sphaira PRIVATE -Wimplicit-fallthrough=5 -Wsuggest-final-types -Wuninitialized + -fdiagnostics-all-candidates ) include(FetchContent) diff --git a/sphaira/include/app.hpp b/sphaira/include/app.hpp index f3b1f7f..e68442f 100644 --- a/sphaira/include/app.hpp +++ b/sphaira/include/app.hpp @@ -58,7 +58,7 @@ public: static void Exit(); static void ExitRestart(); static auto GetVg() -> NVGcontext*; - static void Push(std::shared_ptr); + static void Push(std::unique_ptr&&); // pops all widgets above a menu static void PopToMenu(); @@ -260,7 +260,7 @@ public: Vec2 m_scale{1, 1}; - std::vector> m_widgets; + std::vector> m_widgets; u32 m_pop_count{}; ui::NotifMananger m_notif_manager{}; diff --git a/sphaira/include/dumper.hpp b/sphaira/include/dumper.hpp index a2b3ed2..c5e6646 100644 --- a/sphaira/include/dumper.hpp +++ b/sphaira/include/dumper.hpp @@ -55,10 +55,10 @@ using OnExit = std::function; using OnLocation = std::function; // prompts the user to select dump location, calls on_loc on success with the selected location. -void DumpGetLocation(const std::string& title, u32 location_flags, OnLocation on_loc); +void DumpGetLocation(const std::string& title, u32 location_flags, const OnLocation& on_loc); // dumps to a fetched location using DumpGetLocation(). -void Dump(std::shared_ptr source, const DumpLocation& location, const std::vector& paths, OnExit on_exit); +void Dump(const std::shared_ptr& source, const DumpLocation& location, const std::vector& paths, const OnExit& on_exit); // DumpGetLocation() + Dump() all in one. -void Dump(std::shared_ptr source, const std::vector& paths, OnExit on_exit = [](Result){}, u32 location_flags = DumpLocationFlag_All); +void Dump(const std::shared_ptr& source, const std::vector& paths, const OnExit& on_exit = [](Result){}, u32 location_flags = DumpLocationFlag_All); } // namespace sphaira::dump diff --git a/sphaira/include/hasher.hpp b/sphaira/include/hasher.hpp index d10505f..694379f 100644 --- a/sphaira/include/hasher.hpp +++ b/sphaira/include/hasher.hpp @@ -25,7 +25,7 @@ struct BaseSource { auto GetTypeStr(Type type) -> const char*; // returns the hash string. -Result Hash(ui::ProgressBox* pbox, Type type, std::shared_ptr source, std::string& out); +Result Hash(ui::ProgressBox* pbox, Type type, BaseSource* source, std::string& out); Result Hash(ui::ProgressBox* pbox, Type type, fs::Fs* fs, const fs::FsPath& path, std::string& out); Result Hash(ui::ProgressBox* pbox, Type type, std::span data, std::string& out); diff --git a/sphaira/include/title_info.hpp b/sphaira/include/title_info.hpp index 5c5557f..c14e5ac 100644 --- a/sphaira/include/title_info.hpp +++ b/sphaira/include/title_info.hpp @@ -60,9 +60,9 @@ void Clear(); // adds new entry to queue. void PushAsync(u64 app_id); // gets entry without removing it from the queue. -auto GetAsync(u64 app_id) -> std::shared_ptr; +auto GetAsync(u64 app_id) -> ThreadResultData*; // single threaded title info fetch. -auto Get(u64 app_id, bool* cached = nullptr) -> std::shared_ptr; +auto Get(u64 app_id, bool* cached = nullptr) -> ThreadResultData*; auto GetNcmCs(u8 storage_id) -> NcmContentStorage&; auto GetNcmDb(u8 storage_id) -> NcmContentMetaDatabase&; diff --git a/sphaira/include/ui/menus/appstore.hpp b/sphaira/include/ui/menus/appstore.hpp index 47f761f..2a6c352 100644 --- a/sphaira/include/ui/menus/appstore.hpp +++ b/sphaira/include/ui/menus/appstore.hpp @@ -105,9 +105,9 @@ private: LazyImage m_banner{}; std::unique_ptr m_list{}; - std::shared_ptr m_details{}; - std::shared_ptr m_changelog{}; - std::shared_ptr m_detail_changelog{}; + std::unique_ptr m_details{}; + std::unique_ptr m_changelog{}; + ScrollableText* m_detail_changelog{}; std::unique_ptr m_manifest_list{}; bool m_show_changlog{}; diff --git a/sphaira/include/ui/menus/filebrowser.hpp b/sphaira/include/ui/menus/filebrowser.hpp index 58ba1e0..19ba180 100644 --- a/sphaira/include/ui/menus/filebrowser.hpp +++ b/sphaira/include/ui/menus/filebrowser.hpp @@ -300,7 +300,7 @@ private: // contains all selected files for a command, such as copy, delete, cut etc. struct SelectedStash { - void Add(std::shared_ptr view, SelectedType type, const std::vector& files, const fs::FsPath& path) { + void Add(FsView* view, SelectedType type, const std::vector& files, const fs::FsPath& path) { if (files.empty()) { Reset(); } else { @@ -335,7 +335,7 @@ struct SelectedStash { } // private: - std::shared_ptr m_view{}; + FsView* m_view{}; std::vector m_files{}; fs::FsPath m_path{}; SelectedType m_type{SelectedType::None}; @@ -389,9 +389,9 @@ private: private: static constexpr inline const char* INI_SECTION = "filebrowser"; - std::shared_ptr view{}; - std::shared_ptr view_left{}; - std::shared_ptr view_right{}; + FsView* view{}; + std::unique_ptr view_left{}; + std::unique_ptr view_right{}; std::vector m_assoc_entries{}; SelectedStash m_selected{}; diff --git a/sphaira/include/ui/menus/game_menu.hpp b/sphaira/include/ui/menus/game_menu.hpp index 34c08f2..000bcfe 100644 --- a/sphaira/include/ui/menus/game_menu.hpp +++ b/sphaira/include/ui/menus/game_menu.hpp @@ -16,8 +16,6 @@ struct Entry { NacpLanguageEntry lang{}; int image{}; bool selected{}; - - std::shared_ptr info{}; title::NacpLoadStatus status{title::NacpLoadStatus::None}; auto GetName() const -> const char* { diff --git a/sphaira/include/ui/menus/install_stream_menu_base.hpp b/sphaira/include/ui/menus/install_stream_menu_base.hpp index 705c876..7d7ed77 100644 --- a/sphaira/include/ui/menus/install_stream_menu_base.hpp +++ b/sphaira/include/ui/menus/install_stream_menu_base.hpp @@ -55,7 +55,7 @@ protected: void OnInstallClose(); private: - std::shared_ptr m_source{}; + std::unique_ptr m_source{}; Thread m_thread{}; Mutex m_mutex{}; State m_state{State::None}; diff --git a/sphaira/include/ui/menus/main_menu.hpp b/sphaira/include/ui/menus/main_menu.hpp index d30e69b..0df97e7 100644 --- a/sphaira/include/ui/menus/main_menu.hpp +++ b/sphaira/include/ui/menus/main_menu.hpp @@ -17,7 +17,7 @@ enum class UpdateState { Error, }; -using MiscMenuFunction = std::function(u32 flags)>; +using MiscMenuFunction = std::function(u32 flags)>; enum MiscMenuFlag : u8 { // can be set as the rightside menu. @@ -58,14 +58,14 @@ struct MainMenu final : Widget { } private: - void OnLRPress(std::shared_ptr menu, Button b); + void OnLRPress(MenuBase* menu, Button b); void AddOnLRPress(); private: - std::shared_ptr m_centre_menu{}; - std::shared_ptr m_left_menu{}; - std::shared_ptr m_right_menu{}; - std::shared_ptr m_current_menu{}; + std::unique_ptr m_centre_menu{}; + std::unique_ptr m_left_menu{}; + std::unique_ptr m_right_menu{}; + MenuBase* m_current_menu{}; std::string m_update_url{}; std::string m_update_version{}; diff --git a/sphaira/include/ui/menus/save_menu.hpp b/sphaira/include/ui/menus/save_menu.hpp index bbdb598..7a71747 100644 --- a/sphaira/include/ui/menus/save_menu.hpp +++ b/sphaira/include/ui/menus/save_menu.hpp @@ -16,8 +16,6 @@ struct Entry final : FsSaveDataInfo { NacpLanguageEntry lang{}; int image{}; bool selected{}; - - std::shared_ptr info{}; title::NacpLoadStatus status{title::NacpLoadStatus::None}; auto GetName() const -> const char* { diff --git a/sphaira/include/ui/menus/usb_menu.hpp b/sphaira/include/ui/menus/usb_menu.hpp index 4ba57dc..fd31166 100644 --- a/sphaira/include/ui/menus/usb_menu.hpp +++ b/sphaira/include/ui/menus/usb_menu.hpp @@ -31,7 +31,7 @@ struct Menu final : MenuBase { // this should be private // private: - std::shared_ptr m_usb_source{}; + std::unique_ptr m_usb_source{}; bool m_was_mtp_enabled{}; Thread m_thread{}; diff --git a/sphaira/include/ui/sidebar.hpp b/sphaira/include/ui/sidebar.hpp index ef98928..d02bf9e 100644 --- a/sphaira/include/ui/sidebar.hpp +++ b/sphaira/include/ui/sidebar.hpp @@ -95,7 +95,7 @@ private: class Sidebar final : public Widget { public: enum class Side { LEFT, RIGHT }; - using Items = std::vector>; + using Items = std::vector>; public: Sidebar(std::string title, Side side, Items&& items); @@ -108,7 +108,18 @@ public: auto OnFocusGained() noexcept -> void override; auto OnFocusLost() noexcept -> void override; - void Add(std::shared_ptr entry); + void Add(std::unique_ptr&& entry); + + template + void AddMove(T entry) { + Add(std::move(entry)); + } + + // template + // [[nodiscrad,gnu::always_inline]] + // constexpr typename std::remove_reference<_Tp>::type&& + // move(_Tp&& t) noexcept + // { return static_cast::type&&>(t); } private: void SetIndex(s64 index); diff --git a/sphaira/include/yati/container/base.hpp b/sphaira/include/yati/container/base.hpp index 75c4e5a..d4c0f63 100644 --- a/sphaira/include/yati/container/base.hpp +++ b/sphaira/include/yati/container/base.hpp @@ -29,7 +29,7 @@ using Collections = std::vector; struct Base { using Source = source::Base; - Base(std::shared_ptr source) : m_source{source} { } + Base(Source* source) : m_source{source} { } virtual ~Base() = default; virtual Result GetCollections(Collections& out) = 0; auto GetSource() const { @@ -37,7 +37,7 @@ struct Base { } protected: - std::shared_ptr m_source; + Source* m_source; }; } // namespace sphaira::yati::container diff --git a/sphaira/include/yati/yati.hpp b/sphaira/include/yati/yati.hpp index f2d1d6b..f18d527 100644 --- a/sphaira/include/yati/yati.hpp +++ b/sphaira/include/yati/yati.hpp @@ -79,8 +79,8 @@ struct ConfigOverride { }; Result InstallFromFile(ui::ProgressBox* pbox, fs::Fs* fs, const fs::FsPath& path, const ConfigOverride& override = {}); -Result InstallFromSource(ui::ProgressBox* pbox, std::shared_ptr source, const fs::FsPath& path, const ConfigOverride& override = {}); -Result InstallFromContainer(ui::ProgressBox* pbox, std::shared_ptr container, const ConfigOverride& override = {}); -Result InstallFromCollections(ui::ProgressBox* pbox, std::shared_ptr source, const container::Collections& collections, const ConfigOverride& override = {}); +Result InstallFromSource(ui::ProgressBox* pbox, source::Base* source, const fs::FsPath& path, const ConfigOverride& override = {}); +Result InstallFromContainer(ui::ProgressBox* pbox, container::Base* container, const ConfigOverride& override = {}); +Result InstallFromCollections(ui::ProgressBox* pbox, source::Base* source, const container::Collections& collections, const ConfigOverride& override = {}); } // namespace sphaira::yati diff --git a/sphaira/source/app.cpp b/sphaira/source/app.cpp index f1401cb..a836b47 100644 --- a/sphaira/source/app.cpp +++ b/sphaira/source/app.cpp @@ -51,7 +51,7 @@ constexpr const u8 DEFAULT_IMAGE_DATA[]{ }; void download_default_music() { - App::Push(std::make_shared(0, "Downloading "_i18n, "default_music.bfstm", [](auto pbox) -> Result { + App::Push(std::make_unique(0, "Downloading "_i18n, "default_music.bfstm", [](auto pbox) -> Result { const auto result = curl::Api().ToFile( curl::Url{DEFAULT_MUSIC_URL}, curl::Path{DEFAULT_MUSIC_PATH}, @@ -500,7 +500,7 @@ void App::Loop() { } } -auto App::Push(std::shared_ptr widget) -> void { +auto App::Push(std::unique_ptr&& widget) -> void { log_write("[Mui] pushing widget\n"); if (!g_app->m_widgets.empty()) { @@ -508,7 +508,7 @@ auto App::Push(std::shared_ptr widget) -> void { } log_write("doing focus gained\n"); - g_app->m_widgets.emplace_back(widget)->OnFocusGained(); + g_app->m_widgets.emplace_back(std::forward(widget))->OnFocusGained(); log_write("did it\n"); } @@ -570,7 +570,7 @@ void App::NotifyFlashLed() { Result App::PushErrorBox(Result rc, const std::string& message) { if (R_FAILED(rc)) { - App::Push(std::make_shared(rc, message)); + App::Push(std::make_unique(rc, message)); } return rc; } @@ -733,7 +733,7 @@ void App::SetReplaceHbmenuEnable(bool enable) { } // ask user if they want to restore hbmenu - App::Push(std::make_shared( + App::Push(std::make_unique( "Restore hbmenu?"_i18n, "Back"_i18n, "Restore"_i18n, 1, [hbmenu_nacp](auto op_index){ if (!op_index || *op_index == 0) { @@ -742,7 +742,7 @@ void App::SetReplaceHbmenuEnable(bool enable) { NacpStruct actual_hbmenu_nacp; if (R_FAILED(nro_get_nacp("/switch/hbmenu.nro", actual_hbmenu_nacp))) { - App::Push(std::make_shared( + App::Push(std::make_unique( "Failed to find /switch/hbmenu.nro\n" "Use the Appstore to re-install hbmenu"_i18n, "OK"_i18n @@ -792,7 +792,7 @@ void App::SetReplaceHbmenuEnable(bool enable) { "Failed to restore hbmenu, please re-download hbmenu"_i18n ); } else { - App::Push(std::make_shared( + App::Push(std::make_unique( "Failed to restore hbmenu, using sphaira instead"_i18n, "OK"_i18n )); @@ -805,7 +805,7 @@ void App::SetReplaceHbmenuEnable(bool enable) { // if we were hbmenu, exit now (as romfs is gone). if (IsHbmenu()) { - App::Push(std::make_shared( + App::Push(std::make_unique( "Restored hbmenu, closing sphaira"_i18n, "OK"_i18n, [](auto) { App::Exit(); @@ -872,7 +872,7 @@ void App::SetLanguage(long index) { g_app->m_language.Set(index); on_i18n_change(); - App::Push(std::make_shared( + App::Push(std::make_unique( "Restart Sphaira?"_i18n, "Back"_i18n, "Restart"_i18n, 1, [](auto op_index){ if (op_index && *op_index) { @@ -888,7 +888,7 @@ void App::SetTextScrollSpeed(long index) { } auto App::Install(OwoConfig& config) -> Result { - App::Push(std::make_shared(0, "Installing Forwarder"_i18n, config.name, [config](auto pbox) mutable -> Result { + App::Push(std::make_unique(0, "Installing Forwarder"_i18n, config.name, [config](auto pbox) mutable -> Result { return Install(pbox, config); }, [](Result rc){ App::PushErrorBox(rc, "Failed to install forwarder"_i18n); @@ -1569,7 +1569,7 @@ App::App(const char* argv0) { // load default image m_default_image = nvgCreateImageMem(vg, 0, DEFAULT_IMAGE_DATA, std::size(DEFAULT_IMAGE_DATA)); - App::Push(std::make_shared()); + App::Push(std::make_unique()); log_write("\n\tfinished app constructor, time taken: %.2fs %zums\n\n", ts.GetSecondsD(), ts.GetMs()); } @@ -1593,25 +1593,25 @@ void App::DisplayThemeOptions(bool left_side) { theme_items.emplace_back(p.name); } - auto options = std::make_shared("Theme Options"_i18n, left_side ? ui::Sidebar::Side::LEFT : ui::Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + auto options = std::make_unique("Theme Options"_i18n, left_side ? ui::Sidebar::Side::LEFT : ui::Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); - options->Add(std::make_shared("Select Theme"_i18n, theme_items, [](s64& index_out){ + options->Add(std::make_unique("Select Theme"_i18n, theme_items, [](s64& index_out){ App::SetTheme(index_out); }, App::GetThemeIndex())); - options->Add(std::make_shared("Music"_i18n, App::GetThemeMusicEnable(), [](bool& enable){ + options->Add(std::make_unique("Music"_i18n, App::GetThemeMusicEnable(), [](bool& enable){ App::SetThemeMusicEnable(enable); })); - options->Add(std::make_shared("12 Hour Time"_i18n, App::Get12HourTimeEnable(), [](bool& enable){ + options->Add(std::make_unique("12 Hour Time"_i18n, App::Get12HourTimeEnable(), [](bool& enable){ App::Set12HourTimeEnable(enable); })); - options->Add(std::make_shared("Download Default Music"_i18n, [](){ + options->Add(std::make_unique("Download Default Music"_i18n, [](){ // check if we already have music if (fs::FileExists(DEFAULT_MUSIC_PATH)) { - App::Push(std::make_shared( + App::Push(std::make_unique( "Overwrite current default music?"_i18n, "No"_i18n, "Yes"_i18n, 0, [](auto op_index){ if (op_index && *op_index) { @@ -1631,8 +1631,8 @@ void App::DisplayNetworkOptions(bool left_side) { } void App::DisplayMiscOptions(bool left_side) { - auto options = std::make_shared("Misc Options"_i18n, left_side ? ui::Sidebar::Side::LEFT : ui::Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + auto options = std::make_unique("Misc Options"_i18n, left_side ? ui::Sidebar::Side::LEFT : ui::Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); for (auto& e : ui::menu::main::GetMiscMenuEntries()) { if (e.name == g_app->m_left_menu.Get()) { @@ -1643,13 +1643,13 @@ void App::DisplayMiscOptions(bool left_side) { continue; } - options->Add(std::make_shared(i18n::get(e.title), [e](){ + options->Add(std::make_unique(i18n::get(e.title), [e](){ App::Push(e.func(ui::menu::MenuFlag_None)); })); } if (App::IsApplication()) { - options->Add(std::make_shared("Web"_i18n, [](){ + options->Add(std::make_unique("Web"_i18n, [](){ // add some default entries, will use a config file soon so users can set their own. ui::PopupList::Items items; items.emplace_back("https://lite.duckduckgo.com/lite"); @@ -1658,7 +1658,7 @@ void App::DisplayMiscOptions(bool left_side) { items.emplace_back("https://github.com/ITotalJustice/sphaira/wiki"); items.emplace_back("Enter custom URL"_i18n); - App::Push(std::make_shared( + App::Push(std::make_unique( "Select URL"_i18n, items, [items](auto op_index){ if (op_index) { const auto index = *op_index; @@ -1678,8 +1678,8 @@ void App::DisplayMiscOptions(bool left_side) { } void App::DisplayAdvancedOptions(bool left_side) { - auto options = std::make_shared("Advanced Options"_i18n, left_side ? ui::Sidebar::Side::LEFT : ui::Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + auto options = std::make_unique("Advanced Options"_i18n, left_side ? ui::Sidebar::Side::LEFT : ui::Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); ui::SidebarEntryArray::Items text_scroll_speed_items; text_scroll_speed_items.push_back("Slow"_i18n); @@ -1701,23 +1701,23 @@ void App::DisplayAdvancedOptions(bool left_side) { menu_items.push_back(i18n::get(e.name)); } - options->Add(std::make_shared("Logging"_i18n, App::GetLogEnable(), [](bool& enable){ + options->Add(std::make_unique("Logging"_i18n, App::GetLogEnable(), [](bool& enable){ App::SetLogEnable(enable); })); - options->Add(std::make_shared("Replace hbmenu on exit"_i18n, App::GetReplaceHbmenuEnable(), [](bool& enable){ + options->Add(std::make_unique("Replace hbmenu on exit"_i18n, App::GetReplaceHbmenuEnable(), [](bool& enable){ App::SetReplaceHbmenuEnable(enable); })); - options->Add(std::make_shared("Boost CPU during transfer"_i18n, App::GetApp()->m_progress_boost_mode.Get(), [](bool& enable){ + options->Add(std::make_unique("Boost CPU during transfer"_i18n, App::GetApp()->m_progress_boost_mode.Get(), [](bool& enable){ App::GetApp()->m_progress_boost_mode.Set(enable); })); - options->Add(std::make_shared("Text scroll speed"_i18n, text_scroll_speed_items, [](s64& index_out){ + options->Add(std::make_unique("Text scroll speed"_i18n, text_scroll_speed_items, [](s64& index_out){ App::SetTextScrollSpeed(index_out); }, App::GetTextScrollSpeed())); - options->Add(std::make_shared("Set left-side menu"_i18n, menu_items, [menu_names](s64& index_out){ + options->Add(std::make_unique("Set left-side menu"_i18n, menu_items, [menu_names](s64& index_out){ const auto e = menu_names[index_out]; if (g_app->m_left_menu.Get() != e) { // swap menus around. @@ -1726,7 +1726,7 @@ void App::DisplayAdvancedOptions(bool left_side) { } g_app->m_left_menu.Set(e); - App::Push(std::make_shared( + App::Push(std::make_unique( "Press OK to restart Sphaira"_i18n, "OK"_i18n, [](auto){ App::ExitRestart(); } @@ -1734,7 +1734,7 @@ void App::DisplayAdvancedOptions(bool left_side) { } }, i18n::get(g_app->m_left_menu.Get()))); - options->Add(std::make_shared("Set right-side menu"_i18n, menu_items, [menu_names](s64& index_out){ + options->Add(std::make_unique("Set right-side menu"_i18n, menu_items, [menu_names](s64& index_out){ const auto e = menu_names[index_out]; if (g_app->m_right_menu.Get() != e) { // swap menus around. @@ -1743,7 +1743,7 @@ void App::DisplayAdvancedOptions(bool left_side) { } g_app->m_right_menu.Set(e); - App::Push(std::make_shared( + App::Push(std::make_unique( "Press OK to restart Sphaira"_i18n, "OK"_i18n, [](auto){ App::ExitRestart(); } @@ -1751,129 +1751,129 @@ void App::DisplayAdvancedOptions(bool left_side) { } }, i18n::get(g_app->m_right_menu.Get()))); - options->Add(std::make_shared("Install options"_i18n, [left_side](){ + options->Add(std::make_unique("Install options"_i18n, [left_side](){ App::DisplayInstallOptions(left_side); })); - options->Add(std::make_shared("Dump options"_i18n, [left_side](){ + options->Add(std::make_unique("Dump options"_i18n, [left_side](){ App::DisplayDumpOptions(left_side); })); } void App::DisplayInstallOptions(bool left_side) { - auto options = std::make_shared("Install Options"_i18n, left_side ? ui::Sidebar::Side::LEFT : ui::Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + auto options = std::make_unique("Install Options"_i18n, left_side ? ui::Sidebar::Side::LEFT : ui::Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); ui::SidebarEntryArray::Items install_items; install_items.push_back("System memory"_i18n); install_items.push_back("microSD card"_i18n); - options->Add(std::make_shared("Enable sysmmc"_i18n, App::GetInstallSysmmcEnable(), [](bool& enable){ + options->Add(std::make_unique("Enable sysmmc"_i18n, App::GetInstallSysmmcEnable(), [](bool& enable){ App::SetInstallSysmmcEnable(enable); })); - options->Add(std::make_shared("Enable emummc"_i18n, App::GetInstallEmummcEnable(), [](bool& enable){ + options->Add(std::make_unique("Enable emummc"_i18n, App::GetInstallEmummcEnable(), [](bool& enable){ App::SetInstallEmummcEnable(enable); })); - options->Add(std::make_shared("Show install warning"_i18n, App::GetApp()->m_install_prompt.Get(), [](bool& enable){ + options->Add(std::make_unique("Show install warning"_i18n, App::GetApp()->m_install_prompt.Get(), [](bool& enable){ App::GetApp()->m_install_prompt.Set(enable); })); - options->Add(std::make_shared("Install location"_i18n, install_items, [](s64& index_out){ + options->Add(std::make_unique("Install location"_i18n, install_items, [](s64& index_out){ App::SetInstallSdEnable(index_out); }, (s64)App::GetInstallSdEnable())); - options->Add(std::make_shared("Allow downgrade"_i18n, App::GetApp()->m_allow_downgrade.Get(), [](bool& enable){ + options->Add(std::make_unique("Allow downgrade"_i18n, App::GetApp()->m_allow_downgrade.Get(), [](bool& enable){ App::GetApp()->m_allow_downgrade.Set(enable); })); - options->Add(std::make_shared("Skip if already installed"_i18n, App::GetApp()->m_skip_if_already_installed.Get(), [](bool& enable){ + options->Add(std::make_unique("Skip if already installed"_i18n, App::GetApp()->m_skip_if_already_installed.Get(), [](bool& enable){ App::GetApp()->m_skip_if_already_installed.Set(enable); })); - options->Add(std::make_shared("Ticket only"_i18n, App::GetApp()->m_ticket_only.Get(), [](bool& enable){ + options->Add(std::make_unique("Ticket only"_i18n, App::GetApp()->m_ticket_only.Get(), [](bool& enable){ App::GetApp()->m_ticket_only.Set(enable); })); - options->Add(std::make_shared("Skip base"_i18n, App::GetApp()->m_skip_base.Get(), [](bool& enable){ + options->Add(std::make_unique("Skip base"_i18n, App::GetApp()->m_skip_base.Get(), [](bool& enable){ App::GetApp()->m_skip_base.Set(enable); })); - options->Add(std::make_shared("Skip patch"_i18n, App::GetApp()->m_skip_patch.Get(), [](bool& enable){ + options->Add(std::make_unique("Skip patch"_i18n, App::GetApp()->m_skip_patch.Get(), [](bool& enable){ App::GetApp()->m_skip_patch.Set(enable); })); - options->Add(std::make_shared("Skip dlc"_i18n, App::GetApp()->m_skip_addon.Get(), [](bool& enable){ + options->Add(std::make_unique("Skip dlc"_i18n, App::GetApp()->m_skip_addon.Get(), [](bool& enable){ App::GetApp()->m_skip_addon.Set(enable); })); - options->Add(std::make_shared("Skip data patch"_i18n, App::GetApp()->m_skip_data_patch.Get(), [](bool& enable){ + options->Add(std::make_unique("Skip data patch"_i18n, App::GetApp()->m_skip_data_patch.Get(), [](bool& enable){ App::GetApp()->m_skip_data_patch.Set(enable); })); - options->Add(std::make_shared("Skip ticket"_i18n, App::GetApp()->m_skip_ticket.Get(), [](bool& enable){ + options->Add(std::make_unique("Skip ticket"_i18n, App::GetApp()->m_skip_ticket.Get(), [](bool& enable){ App::GetApp()->m_skip_ticket.Set(enable); })); - options->Add(std::make_shared("Skip NCA hash verify"_i18n, App::GetApp()->m_skip_nca_hash_verify.Get(), [](bool& enable){ + options->Add(std::make_unique("Skip NCA hash verify"_i18n, App::GetApp()->m_skip_nca_hash_verify.Get(), [](bool& enable){ App::GetApp()->m_skip_nca_hash_verify.Set(enable); })); - options->Add(std::make_shared("Skip RSA header verify"_i18n, App::GetApp()->m_skip_rsa_header_fixed_key_verify.Get(), [](bool& enable){ + options->Add(std::make_unique("Skip RSA header verify"_i18n, App::GetApp()->m_skip_rsa_header_fixed_key_verify.Get(), [](bool& enable){ App::GetApp()->m_skip_rsa_header_fixed_key_verify.Set(enable); })); - options->Add(std::make_shared("Skip RSA NPDM verify"_i18n, App::GetApp()->m_skip_rsa_npdm_fixed_key_verify.Get(), [](bool& enable){ + options->Add(std::make_unique("Skip RSA NPDM verify"_i18n, App::GetApp()->m_skip_rsa_npdm_fixed_key_verify.Get(), [](bool& enable){ App::GetApp()->m_skip_rsa_npdm_fixed_key_verify.Set(enable); })); - options->Add(std::make_shared("Ignore distribution bit"_i18n, App::GetApp()->m_ignore_distribution_bit.Get(), [](bool& enable){ + options->Add(std::make_unique("Ignore distribution bit"_i18n, App::GetApp()->m_ignore_distribution_bit.Get(), [](bool& enable){ App::GetApp()->m_ignore_distribution_bit.Set(enable); })); - options->Add(std::make_shared("Convert to common ticket"_i18n, App::GetApp()->m_convert_to_common_ticket.Get(), [](bool& enable){ + options->Add(std::make_unique("Convert to common ticket"_i18n, App::GetApp()->m_convert_to_common_ticket.Get(), [](bool& enable){ App::GetApp()->m_convert_to_common_ticket.Set(enable); })); - options->Add(std::make_shared("Convert to standard crypto"_i18n, App::GetApp()->m_convert_to_standard_crypto.Get(), [](bool& enable){ + options->Add(std::make_unique("Convert to standard crypto"_i18n, App::GetApp()->m_convert_to_standard_crypto.Get(), [](bool& enable){ App::GetApp()->m_convert_to_standard_crypto.Set(enable); })); - options->Add(std::make_shared("Lower master key"_i18n, App::GetApp()->m_lower_master_key.Get(), [](bool& enable){ + options->Add(std::make_unique("Lower master key"_i18n, App::GetApp()->m_lower_master_key.Get(), [](bool& enable){ App::GetApp()->m_lower_master_key.Set(enable); })); - options->Add(std::make_shared("Lower system version"_i18n, App::GetApp()->m_lower_system_version.Get(), [](bool& enable){ + options->Add(std::make_unique("Lower system version"_i18n, App::GetApp()->m_lower_system_version.Get(), [](bool& enable){ App::GetApp()->m_lower_system_version.Set(enable); })); } void App::DisplayDumpOptions(bool left_side) { - auto options = std::make_shared("Dump Options"_i18n, left_side ? ui::Sidebar::Side::LEFT : ui::Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + auto options = std::make_unique("Dump Options"_i18n, left_side ? ui::Sidebar::Side::LEFT : ui::Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); - options->Add(std::make_shared("Created nested folder"_i18n, App::GetApp()->m_dump_app_folder.Get(), [](bool& enable){ + options->Add(std::make_unique("Created nested folder"_i18n, App::GetApp()->m_dump_app_folder.Get(), [](bool& enable){ App::GetApp()->m_dump_app_folder.Set(enable); })); - options->Add(std::make_shared("Append folder with .xci"_i18n, App::GetApp()->m_dump_append_folder_with_xci.Get(), [](bool& enable){ + options->Add(std::make_unique("Append folder with .xci"_i18n, App::GetApp()->m_dump_append_folder_with_xci.Get(), [](bool& enable){ App::GetApp()->m_dump_append_folder_with_xci.Set(enable); })); - options->Add(std::make_shared("Trim XCI"_i18n, App::GetApp()->m_dump_trim_xci.Get(), [](bool& enable){ + options->Add(std::make_unique("Trim XCI"_i18n, App::GetApp()->m_dump_trim_xci.Get(), [](bool& enable){ App::GetApp()->m_dump_trim_xci.Set(enable); })); - options->Add(std::make_shared("Label trimmed XCI"_i18n, App::GetApp()->m_dump_label_trim_xci.Get(), [](bool& enable){ + options->Add(std::make_unique("Label trimmed XCI"_i18n, App::GetApp()->m_dump_label_trim_xci.Get(), [](bool& enable){ App::GetApp()->m_dump_label_trim_xci.Set(enable); })); - options->Add(std::make_shared("Multi-threaded USB transfer"_i18n, App::GetApp()->m_dump_usb_transfer_stream.Get(), [](bool& enable){ + options->Add(std::make_unique("Multi-threaded USB transfer"_i18n, App::GetApp()->m_dump_usb_transfer_stream.Get(), [](bool& enable){ App::GetApp()->m_dump_usb_transfer_stream.Set(enable); })); - options->Add(std::make_shared("Convert to common ticket"_i18n, App::GetApp()->m_dump_convert_to_common_ticket.Get(), [](bool& enable){ + options->Add(std::make_unique("Convert to common ticket"_i18n, App::GetApp()->m_dump_convert_to_common_ticket.Get(), [](bool& enable){ App::GetApp()->m_dump_convert_to_common_ticket.Set(enable); })); } diff --git a/sphaira/source/dumper.cpp b/sphaira/source/dumper.cpp index cc4522b..9429e2f 100644 --- a/sphaira/source/dumper.cpp +++ b/sphaira/source/dumper.cpp @@ -314,7 +314,7 @@ Result DumpToNetwork(ui::ProgressBox* pbox, const location::Entry& loc, BaseSour } // namespace -void DumpGetLocation(const std::string& title, u32 location_flags, OnLocation on_loc) { +void DumpGetLocation(const std::string& title, u32 location_flags, const OnLocation& on_loc) { DumpLocation out; ui::PopupList::Items items; std::vector dump_entries; @@ -342,7 +342,7 @@ void DumpGetLocation(const std::string& title, u32 location_flags, OnLocation on } } - App::Push(std::make_shared( + App::Push(std::make_unique( title, items, [dump_entries, out, on_loc](auto op_index) mutable { out.entry = dump_entries[*op_index]; on_loc(out); @@ -350,8 +350,8 @@ void DumpGetLocation(const std::string& title, u32 location_flags, OnLocation on )); } -void Dump(std::shared_ptr source, const DumpLocation& location, const std::vector& paths, OnExit on_exit) { - App::Push(std::make_shared(0, "Dumping"_i18n, "", [source, paths, location](auto pbox) -> Result { +void Dump(const std::shared_ptr& source, const DumpLocation& location, const std::vector& paths, const OnExit& on_exit) { + App::Push(std::make_unique(0, "Dumping"_i18n, "", [source, paths, location](auto pbox) -> Result { if (location.entry.type == DumpLocationType_Network) { R_TRY(DumpToNetwork(pbox, location.network[location.entry.index], source.get(), paths)); } else if (location.entry.type == DumpLocationType_Stdio) { @@ -377,8 +377,8 @@ void Dump(std::shared_ptr source, const DumpLocation& location, cons })); } -void Dump(std::shared_ptr source, const std::vector& paths, OnExit on_exit, u32 location_flags) { - DumpGetLocation("Select dump location"_i18n, location_flags, [source, paths, on_exit](const DumpLocation& loc){ +void Dump(const std::shared_ptr& source, const std::vector& paths, const OnExit& on_exit, u32 location_flags) { + DumpGetLocation("Select dump location"_i18n, location_flags, [source, paths, on_exit](const DumpLocation& loc) { Dump(source, loc, paths, on_exit); }); } diff --git a/sphaira/source/hasher.cpp b/sphaira/source/hasher.cpp index c009d83..80b8f56 100644 --- a/sphaira/source/hasher.cpp +++ b/sphaira/source/hasher.cpp @@ -156,7 +156,7 @@ private: Sha256Context m_ctx{}; }; -Result Hash(ui::ProgressBox* pbox, std::unique_ptr hash, std::shared_ptr source, std::string& out) { +Result Hash(ui::ProgressBox* pbox, std::unique_ptr hash, BaseSource* source, std::string& out) { s64 file_size; R_TRY(source->Size(&file_size)); @@ -186,7 +186,7 @@ auto GetTypeStr(Type type) -> const char* { return ""; } -Result Hash(ui::ProgressBox* pbox, Type type, std::shared_ptr source, std::string& out) { +Result Hash(ui::ProgressBox* pbox, Type type, BaseSource* source, std::string& out) { switch (type) { case Type::Crc32: return Hash(pbox, std::make_unique(), source, out); case Type::Md5: return Hash(pbox, std::make_unique(), source, out); @@ -197,13 +197,13 @@ Result Hash(ui::ProgressBox* pbox, Type type, std::shared_ptr source } Result Hash(ui::ProgressBox* pbox, Type type, fs::Fs* fs, const fs::FsPath& path, std::string& out) { - auto source = std::make_shared(fs, path); - return Hash(pbox, type, source, out); + auto source = std::make_unique(fs, path); + return Hash(pbox, type, source.get(), out); } Result Hash(ui::ProgressBox* pbox, Type type, std::span data, std::string& out) { - auto source = std::make_shared(data); - return Hash(pbox, type, source, out); + auto source = std::make_unique(data); + return Hash(pbox, type, source.get(), out); } } // namespace sphaira::has diff --git a/sphaira/source/haze_helper.cpp b/sphaira/source/haze_helper.cpp index aa8ea30..3d566ac 100644 --- a/sphaira/source/haze_helper.cpp +++ b/sphaira/source/haze_helper.cpp @@ -87,8 +87,9 @@ protected: }; struct FsProxy final : FsProxyBase { - FsProxy(std::shared_ptr fs, const char* name, const char* display_name) : FsProxyBase{name, display_name} { - m_fs = fs; + FsProxy(std::unique_ptr&& fs, const char* name, const char* display_name) + : FsProxyBase{name, display_name} + , m_fs{std::forward(fs)} { } ~FsProxy() { @@ -229,7 +230,7 @@ struct FsProxy final : FsProxyBase { } private: - std::shared_ptr m_fs{}; + std::unique_ptr m_fs{}; }; // fake fs that allows for files to create r/w on the root. @@ -558,9 +559,9 @@ bool Init() { return false; } - g_fs_entries.emplace_back(std::make_shared(std::make_shared(), "", "microSD card")); - g_fs_entries.emplace_back(std::make_shared(std::make_shared(FsImageDirectoryId_Nand), "image_nand", "Image nand")); - g_fs_entries.emplace_back(std::make_shared(std::make_shared(FsImageDirectoryId_Sd), "image_sd", "Image sd")); + g_fs_entries.emplace_back(std::make_shared(std::make_unique(), "", "microSD card")); + g_fs_entries.emplace_back(std::make_shared(std::make_unique(FsImageDirectoryId_Nand), "image_nand", "Image nand")); + g_fs_entries.emplace_back(std::make_shared(std::make_unique(FsImageDirectoryId_Sd), "image_sd", "Image sd")); g_fs_entries.emplace_back(std::make_shared("DevNull", "DevNull (Speed Test)")); g_fs_entries.emplace_back(std::make_shared("install", "Install (NSP, XCI, NSZ, XCZ)")); diff --git a/sphaira/source/owo.cpp b/sphaira/source/owo.cpp index 5ba3bdc..1157387 100644 --- a/sphaira/source/owo.cpp +++ b/sphaira/source/owo.cpp @@ -1020,7 +1020,7 @@ auto install_forwarder(ui::ProgressBox* pbox, OwoConfig& config, NcmStorageId st } auto install_forwarder(OwoConfig& config, NcmStorageId storage_id) -> Result { - App::Push(std::make_shared(0, "Installing Forwarder"_i18n, config.name, [config, storage_id](auto pbox) mutable -> Result { + App::Push(std::make_unique(0, "Installing Forwarder"_i18n, config.name, [config, storage_id](auto pbox) mutable -> Result { return install_forwarder(pbox, config, storage_id); })); R_SUCCEED(); diff --git a/sphaira/source/title_info.cpp b/sphaira/source/title_info.cpp index 64c5e15..3552e42 100644 --- a/sphaira/source/title_info.cpp +++ b/sphaira/source/title_info.cpp @@ -28,8 +28,8 @@ struct ThreadData { void Clear(); void PushAsync(u64 id); - auto GetAsync(u64 app_id) -> std::shared_ptr; - auto Get(u64 app_id, bool* cached = nullptr) -> std::shared_ptr; + auto GetAsync(u64 app_id) -> ThreadResultData*; + auto Get(u64 app_id, bool* cached = nullptr) -> ThreadResultData*; auto IsRunning() const -> bool { return m_running; @@ -49,7 +49,7 @@ private: // app_ids pushed to the queue, signal uevent when pushed. std::vector m_ids{}; // control data pushed to the queue. - std::vector> m_result{}; + std::vector> m_result{}; std::atomic_bool m_running{}; }; @@ -109,14 +109,14 @@ auto& GetNcmEntry(u8 storage_id) { } // also sets the status to error. -void FakeNacpEntry(std::shared_ptr& e) { +void FakeNacpEntry(ThreadResultData* e) { e->status = NacpLoadStatus::Error; // fake the nacp entry std::strcpy(e->lang.name, "Corrupted"); std::strcpy(e->lang.author, "Corrupted"); } -Result LoadControlManual(u64 id, NacpStruct& nacp, std::shared_ptr& data) { +Result LoadControlManual(u64 id, NacpStruct& nacp, ThreadResultData* data) { TimeStamp ts; MetaEntries entries; @@ -208,19 +208,19 @@ void ThreadData::PushAsync(u64 id) { } } -auto ThreadData::GetAsync(u64 app_id) -> std::shared_ptr { +auto ThreadData::GetAsync(u64 app_id) -> ThreadResultData* { SCOPED_MUTEX(&m_mutex_result); for (s64 i = 0; i < std::size(m_result); i++) { if (app_id == m_result[i]->id) { - return m_result[i]; + return m_result[i].get(); } } return {}; } -auto ThreadData::Get(u64 app_id, bool* cached) -> std::shared_ptr { +auto ThreadData::Get(u64 app_id, bool* cached) -> ThreadResultData* { // try and fetch from results first, before manually loading. if (auto data = GetAsync(app_id)) { if (cached) { @@ -230,7 +230,7 @@ auto ThreadData::Get(u64 app_id, bool* cached) -> std::shared_ptr(app_id); + auto result = std::make_unique(app_id); result->status = NacpLoadStatus::Error; if (auto data = nxtcGetApplicationMetadataEntryById(app_id)) { @@ -264,7 +264,7 @@ auto ThreadData::Get(u64 app_id, bool* cached) -> std::shared_ptrnacp, result)); + manual_load = R_SUCCEEDED(LoadControlManual(app_id, control->nacp, result.get())); } Result rc{}; @@ -276,14 +276,14 @@ auto ThreadData::Get(u64 app_id, bool* cached) -> std::shared_ptrnacp, &lang))) { result->lang = *lang; } else { - FakeNacpEntry(result); + FakeNacpEntry(result.get()); valid = false; } @@ -350,8 +350,7 @@ auto ThreadData::Get(u64 app_id, bool* cached) -> std::shared_ptr std::shared_ptr { +auto GetAsync(u64 app_id) -> ThreadResultData* { SCOPED_MUTEX(&g_mutex); if (g_thread_data) { return g_thread_data->GetAsync(app_id); @@ -437,7 +436,7 @@ auto GetAsync(u64 app_id) -> std::shared_ptr { return {}; } -auto Get(u64 app_id, bool* cached) -> std::shared_ptr { +auto Get(u64 app_id, bool* cached) -> ThreadResultData* { SCOPED_MUTEX(&g_mutex); if (g_thread_data) { return g_thread_data->Get(app_id, cached); diff --git a/sphaira/source/ui/menus/appstore.cpp b/sphaira/source/ui/menus/appstore.cpp index f39b208..d9a705f 100644 --- a/sphaira/source/ui/menus/appstore.cpp +++ b/sphaira/source/ui/menus/appstore.cpp @@ -587,15 +587,15 @@ EntryMenu::EntryMenu(Entry& entry, const LazyImage& default_icon, Menu& menu) } }}), std::make_pair(Button::X, Action{"Options"_i18n, [this](){ - auto options = std::make_shared("Options"_i18n, Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + auto options = std::make_unique("Options"_i18n, Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); - options->Add(std::make_shared("More by Author"_i18n, [this](){ + options->Add(std::make_unique("More by Author"_i18n, [this](){ m_menu.SetAuthor(); SetPop(); }, true)); - options->Add(std::make_shared("Leave Feedback"_i18n, [this](){ + options->Add(std::make_unique("Leave Feedback"_i18n, [this](){ std::string out; if (R_SUCCEEDED(swkbd::ShowText(out)) && !out.empty()) { const auto post = "name=" "switch_user" "&package=" + m_entry.name + "&message=" + out; @@ -618,7 +618,7 @@ EntryMenu::EntryMenu(Entry& entry, const LazyImage& default_icon, Menu& menu) }, true)); if (App::IsApplication() && !m_entry.url.empty()) { - options->Add(std::make_shared("Visit Website"_i18n, [this](){ + options->Add(std::make_unique("Visit Website"_i18n, [this](){ WebShow(m_entry.url); })); } @@ -659,8 +659,8 @@ EntryMenu::EntryMenu(Entry& entry, const LazyImage& default_icon, Menu& menu) SetTitleSubHeading("by " + m_entry.author); - m_details = std::make_shared(m_entry.details, 0, 374, 250, 768, 18); - m_changelog = std::make_shared(m_entry.changelog, 0, 374, 250, 768, 18); + m_details = std::make_unique(m_entry.details, 0, 374, 250, 768, 18); + m_changelog = std::make_unique(m_entry.changelog, 0, 374, 250, 768, 18); m_show_changlog ^= 1; ShowChangelogAction(); @@ -781,13 +781,12 @@ void EntryMenu::ShowChangelogAction() { m_show_changlog ^= 1; m_show_file_list = false; - if (m_show_changlog) { SetAction(Button::L, Action{"Details"_i18n, func}); - m_detail_changelog = m_changelog; + m_detail_changelog = m_changelog.get(); } else { SetAction(Button::L, Action{"Changelog"_i18n, func}); - m_detail_changelog = m_details; + m_detail_changelog = m_details.get(); } } @@ -797,7 +796,7 @@ void EntryMenu::UpdateOptions() { }; const auto install = [this](){ - App::Push(std::make_shared(m_entry.image.image, "Downloading "_i18n, m_entry.title, [this](auto pbox){ + App::Push(std::make_unique(m_entry.image.image, "Downloading "_i18n, m_entry.title, [this](auto pbox){ return InstallApp(pbox, m_entry); }, [this](Result rc){ homebrew::SignalChange(); @@ -813,7 +812,7 @@ void EntryMenu::UpdateOptions() { }; const auto uninstall = [this](){ - App::Push(std::make_shared(m_entry.image.image, "Uninstalling "_i18n, m_entry.title, [this](auto pbox){ + App::Push(std::make_unique(m_entry.image.image, "Uninstalling "_i18n, m_entry.title, [this](auto pbox){ return UninstallApp(pbox, m_entry); }, [this](Result rc){ homebrew::SignalChange(); @@ -866,7 +865,7 @@ void EntryMenu::SetIndex(s64 index) { SetAction(Button::A, Action{option.display_text, option.func}); } else { SetAction(Button::A, Action{option.display_text, [this, option](){ - App::Push(std::make_shared(option.confirm_text, "No"_i18n, "Yes"_i18n, 1, [this, option](auto op_index){ + App::Push(std::make_unique(option.confirm_text, "No"_i18n, "Yes"_i18n, 1, [this, option](auto op_index){ if (op_index && *op_index) { option.func(); } @@ -916,11 +915,11 @@ Menu::Menu(u32 flags) : grid::Menu{"AppStore"_i18n, flags} { // log_write("pushing A when empty: size: %zu count: %zu\n", repo_json.size(), m_entries_current.size()); return; } - App::Push(std::make_shared(m_entries[m_entries_current[m_index]], m_default_image, *this)); + App::Push(std::make_unique(m_entries[m_entries_current[m_index]], m_default_image, *this)); }}), std::make_pair(Button::X, Action{"Options"_i18n, [this](){ - auto options = std::make_shared("AppStore Options"_i18n, Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + auto options = std::make_unique("AppStore Options"_i18n, Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); SidebarEntryArray::Items filter_items; filter_items.push_back("All"_i18n); @@ -947,27 +946,27 @@ Menu::Menu(u32 flags) : grid::Menu{"AppStore"_i18n, flags} { layout_items.push_back("Icon"_i18n); layout_items.push_back("Grid"_i18n); - options->Add(std::make_shared("Filter"_i18n, filter_items, [this](s64& index_out){ + options->Add(std::make_unique("Filter"_i18n, filter_items, [this](s64& index_out){ m_filter.Set(index_out); SetFilter(); }, m_filter.Get())); - options->Add(std::make_shared("Sort"_i18n, sort_items, [this](s64& index_out){ + options->Add(std::make_unique("Sort"_i18n, sort_items, [this](s64& index_out){ m_sort.Set(index_out); SortAndFindLastFile(); }, m_sort.Get())); - options->Add(std::make_shared("Order"_i18n, order_items, [this](s64& index_out){ + options->Add(std::make_unique("Order"_i18n, order_items, [this](s64& index_out){ m_order.Set(index_out); SortAndFindLastFile(); }, m_order.Get())); - options->Add(std::make_shared("Layout"_i18n, layout_items, [this](s64& index_out){ + options->Add(std::make_unique("Layout"_i18n, layout_items, [this](s64& index_out){ m_layout.Set(index_out); OnLayoutChange(); }, m_layout.Get())); - options->Add(std::make_shared("Search"_i18n, [this](){ + options->Add(std::make_unique("Search"_i18n, [this](){ std::string out; if (R_SUCCEEDED(swkbd::ShowText(out)) && !out.empty()) { SetSearch(out); diff --git a/sphaira/source/ui/menus/filebrowser.cpp b/sphaira/source/ui/menus/filebrowser.cpp index 9efc3f8..5125189 100644 --- a/sphaira/source/ui/menus/filebrowser.cpp +++ b/sphaira/source/ui/menus/filebrowser.cpp @@ -332,7 +332,7 @@ FsView::FsView(Menu* menu, const fs::FsPath& path, const FsEntry& entry, ViewSid } if (IsSd() && m_is_update_folder && m_daybreak_path.has_value()) { - App::Push(std::make_shared("Open with DayBreak?"_i18n, "No"_i18n, "Yes"_i18n, 1, [this](auto op_index){ + App::Push(std::make_unique("Open with DayBreak?"_i18n, "No"_i18n, "Yes"_i18n, 1, [this](auto op_index){ if (op_index && *op_index) { // daybreak uses native fs so do not use nro_add_arg_file // otherwise it'll fail to open the folder... @@ -349,7 +349,7 @@ FsView::FsView(Menu* menu, const fs::FsPath& path, const FsEntry& entry, ViewSid } else { // special case for nro if (IsSd() && entry.GetExtension() == "nro") { - App::Push(std::make_shared("Launch "_i18n + entry.GetName() + '?', + App::Push(std::make_unique("Launch "_i18n + entry.GetName() + '?', "No"_i18n, "Launch"_i18n, 1, [this](auto op_index){ if (op_index && *op_index) { nro_launch(GetNewPathCurrent()); @@ -370,7 +370,7 @@ FsView::FsView(Menu* menu, const fs::FsPath& path, const FsEntry& entry, ViewSid } const auto title = "Launch option for: "_i18n + GetEntry().name; - App::Push(std::make_shared( + App::Push(std::make_unique( title, items, [this, assoc_list](auto op_index){ if (op_index) { log_write("selected: %s\n", assoc_list[*op_index].name.c_str()); @@ -642,12 +642,12 @@ void FsView::InstallForwarder() { } const auto title = std::string{"Select launcher for: "_i18n} + GetEntry().name; - App::Push(std::make_shared( + App::Push(std::make_unique( title, items, [this, assoc_list](auto op_index){ if (op_index) { const auto assoc = assoc_list[*op_index]; log_write("pushing it\n"); - App::Push(std::make_shared(0, "Installing Forwarder"_i18n, GetEntry().name, [assoc, this](auto pbox) -> Result { + App::Push(std::make_unique(0, "Installing Forwarder"_i18n, GetEntry().name, [assoc, this](auto pbox) -> Result { log_write("inside callback\n"); NroEntry nro{}; @@ -701,11 +701,11 @@ void FsView::InstallForwarder() { void FsView::InstallFiles() { const auto targets = GetSelectedEntries(); - App::Push(std::make_shared("Install Selected files?"_i18n, "No"_i18n, "Yes"_i18n, 0, [this, targets](auto op_index){ + App::Push(std::make_unique("Install Selected files?"_i18n, "No"_i18n, "Yes"_i18n, 0, [this, targets](auto op_index){ if (op_index && *op_index) { App::PopToMenu(); - App::Push(std::make_shared(0, "Installing "_i18n, "", [this, targets](auto pbox) -> Result { + App::Push(std::make_unique(0, "Installing "_i18n, "", [this, targets](auto pbox) -> Result { for (auto& e : targets) { R_TRY(yati::InstallFromFile(pbox, m_fs.get(), GetNewPath(e))); App::Notify("Installed "_i18n + e.GetName()); @@ -727,7 +727,7 @@ void FsView::UnzipFiles(fs::FsPath dir_path) { dir_path = m_path; } - App::Push(std::make_shared(0, "Extracting "_i18n, "", [this, dir_path, targets](auto pbox) -> Result { + App::Push(std::make_unique(0, "Extracting "_i18n, "", [this, dir_path, targets](auto pbox) -> Result { const auto is_hdd_fs = m_fs->Root().starts_with("ums"); for (auto& e : targets) { @@ -785,7 +785,7 @@ void FsView::ZipFiles(fs::FsPath zip_out) { } } - App::Push(std::make_shared(0, "Compressing "_i18n, "", [this, zip_out, targets](auto pbox) -> Result { + App::Push(std::make_unique(0, "Compressing "_i18n, "", [this, zip_out, targets](auto pbox) -> Result { const auto t = std::time(NULL); const auto tm = std::localtime(&t); const auto is_hdd_fs = m_fs->Root().starts_with("ums"); @@ -876,14 +876,14 @@ void FsView::UploadFiles() { items.emplace_back(p.name); } - App::Push(std::make_shared( + App::Push(std::make_unique( "Select upload location"_i18n, items, [this, network_locations](auto op_index){ if (!op_index) { return; } const auto loc = network_locations[*op_index]; - App::Push(std::make_shared(0, "Uploading"_i18n, "", [this, loc](auto pbox) -> Result { + App::Push(std::make_unique(0, "Uploading"_i18n, "", [this, loc](auto pbox) -> Result { auto targets = GetSelectedEntries(); const auto is_file_based_emummc = App::IsFileBaseEmummc(); @@ -1166,7 +1166,7 @@ void FsView::OnDeleteCallback() { m_menu->RefreshViews(); log_write("did delete\n"); } else { - App::Push(std::make_shared(0, "Deleting"_i18n, "", [this](auto pbox) -> Result { + App::Push(std::make_unique(0, "Deleting"_i18n, "", [this](auto pbox) -> Result { FsDirCollections collections; auto& selected = m_menu->m_selected; auto src_fs = selected.m_view->GetFs(); @@ -1207,7 +1207,7 @@ void FsView::OnPasteCallback() { m_menu->RefreshViews(); } else { - App::Push(std::make_shared(0, "Pasting"_i18n, "", [this](auto pbox) -> Result { + App::Push(std::make_unique(0, "Pasting"_i18n, "", [this](auto pbox) -> Result { auto& selected = m_menu->m_selected; auto src_fs = selected.m_view->GetFs(); const auto is_same_fs = selected.SameFs(this); @@ -1530,7 +1530,7 @@ void FsView::DisplayHash(hash::Type type) { static std::string hash_out; hash_out.clear(); - App::Push(std::make_shared(0, "Hashing"_i18n, GetEntry().name, [this, type](auto pbox) -> Result { + App::Push(std::make_unique(0, "Hashing"_i18n, GetEntry().name, [this, type](auto pbox) -> Result { const auto full_path = GetNewPathCurrent(); pbox->NewTransfer(full_path); R_TRY(hash::Hash(pbox, type, m_fs.get(), full_path, hash_out)); @@ -1543,18 +1543,18 @@ void FsView::DisplayHash(hash::Type type) { char buf[0x100]; // std::snprintf(buf, sizeof(buf), "%s\n%s\n%s", hash::GetTypeStr(type), hash_out.c_str(), GetEntry().GetName()); std::snprintf(buf, sizeof(buf), "%s\n%s", hash::GetTypeStr(type), hash_out.c_str()); - App::Push(std::make_shared(buf, "OK"_i18n)); + App::Push(std::make_unique(buf, "OK"_i18n)); } })); } void FsView::DisplayOptions() { - auto options = std::make_shared("File Options"_i18n, Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + auto options = std::make_unique("File Options"_i18n, Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); - options->Add(std::make_shared("Sort By"_i18n, [this](){ - auto options = std::make_shared("Sort Options"_i18n, Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + options->Add(std::make_unique("Sort By"_i18n, [this](){ + auto options = std::make_unique("Sort Options"_i18n, Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); SidebarEntryArray::Items sort_items; sort_items.push_back("Size"_i18n); @@ -1564,46 +1564,46 @@ void FsView::DisplayOptions() { order_items.push_back("Descending"_i18n); order_items.push_back("Ascending"_i18n); - options->Add(std::make_shared("Sort"_i18n, sort_items, [this](s64& index_out){ + options->Add(std::make_unique("Sort"_i18n, sort_items, [this](s64& index_out){ m_menu->m_sort.Set(index_out); SortAndFindLastFile(); }, m_menu->m_sort.Get())); - options->Add(std::make_shared("Order"_i18n, order_items, [this](s64& index_out){ + options->Add(std::make_unique("Order"_i18n, order_items, [this](s64& index_out){ m_menu->m_order.Set(index_out); SortAndFindLastFile(); }, m_menu->m_order.Get())); - options->Add(std::make_shared("Show Hidden"_i18n, m_menu->m_show_hidden.Get(), [this](bool& v_out){ + options->Add(std::make_unique("Show Hidden"_i18n, m_menu->m_show_hidden.Get(), [this](bool& v_out){ m_menu->m_show_hidden.Set(v_out); SortAndFindLastFile(); })); - options->Add(std::make_shared("Folders First"_i18n, m_menu->m_folders_first.Get(), [this](bool& v_out){ + options->Add(std::make_unique("Folders First"_i18n, m_menu->m_folders_first.Get(), [this](bool& v_out){ m_menu->m_folders_first.Set(v_out); SortAndFindLastFile(); })); - options->Add(std::make_shared("Hidden Last"_i18n, m_menu->m_hidden_last.Get(), [this](bool& v_out){ + options->Add(std::make_unique("Hidden Last"_i18n, m_menu->m_hidden_last.Get(), [this](bool& v_out){ m_menu->m_hidden_last.Set(v_out); SortAndFindLastFile(); })); })); if (m_entries_current.size()) { - options->Add(std::make_shared("Cut"_i18n, [this](){ + options->Add(std::make_unique("Cut"_i18n, [this](){ m_menu->AddSelectedEntries(SelectedType::Cut); }, true)); - options->Add(std::make_shared("Copy"_i18n, [this](){ + options->Add(std::make_unique("Copy"_i18n, [this](){ m_menu->AddSelectedEntries(SelectedType::Copy); }, true)); } if (!m_menu->m_selected.Empty() && (m_menu->m_selected.Type() == SelectedType::Cut || m_menu->m_selected.Type() == SelectedType::Copy)) { - options->Add(std::make_shared("Paste"_i18n, [this](){ + options->Add(std::make_unique("Paste"_i18n, [this](){ const std::string buf = "Paste file(s)?"_i18n; - App::Push(std::make_shared( + App::Push(std::make_unique( buf, "No"_i18n, "Yes"_i18n, 0, [this](auto op_index){ if (op_index && *op_index) { App::PopToMenu(); @@ -1615,7 +1615,7 @@ void FsView::DisplayOptions() { // can't rename more than 1 file if (m_entries_current.size() && !m_selected_count) { - options->Add(std::make_shared("Rename"_i18n, [this](){ + options->Add(std::make_unique("Rename"_i18n, [this](){ std::string out; const auto& entry = GetEntry(); const auto name = entry.GetName(); @@ -1643,11 +1643,11 @@ void FsView::DisplayOptions() { } if (m_entries_current.size()) { - options->Add(std::make_shared("Delete"_i18n, [this](){ + options->Add(std::make_unique("Delete"_i18n, [this](){ m_menu->AddSelectedEntries(SelectedType::Delete); log_write("clicked on delete\n"); - App::Push(std::make_shared( + App::Push(std::make_unique( "Delete Selected files?"_i18n, "No"_i18n, "Yes"_i18n, 0, [this](auto op_index){ if (op_index && *op_index) { App::PopToMenu(); @@ -1673,7 +1673,7 @@ void FsView::DisplayOptions() { // if install is enabled, check if all currently selected files are installable. if (m_entries_current.size() && App::GetInstallEnable()) { if (check_all_ext(INSTALL_EXTENSIONS)) { - options->Add(std::make_shared("Install"_i18n, [this](){ + options->Add(std::make_unique("Install"_i18n, [this](){ InstallFiles(); })); } @@ -1681,9 +1681,9 @@ void FsView::DisplayOptions() { if (IsSd() && m_entries_current.size() && !m_selected_count) { if (App::GetInstallEnable() && GetEntry().IsFile() && (GetEntry().GetExtension() == "nro" || !m_menu->FindFileAssocFor().empty())) { - options->Add(std::make_shared("Install Forwarder"_i18n, [this](){; + options->Add(std::make_unique("Install Forwarder"_i18n, [this](){; if (App::GetInstallPrompt()) { - App::Push(std::make_shared( + App::Push(std::make_unique( "WARNING: Installing forwarders will lead to a ban!"_i18n, "Back"_i18n, "Install"_i18n, 0, [this](auto op_index){ if (op_index && *op_index) { @@ -1700,16 +1700,16 @@ void FsView::DisplayOptions() { if (m_entries_current.size()) { if (check_all_ext(ZIP_EXTENSIONS)) { - options->Add(std::make_shared("Extract zip"_i18n, [this](){ - auto options = std::make_shared("Extract Options"_i18n, Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + options->Add(std::make_unique("Extract zip"_i18n, [this](){ + auto options = std::make_unique("Extract Options"_i18n, Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); - options->Add(std::make_shared("Extract here"_i18n, [this](){ + options->Add(std::make_unique("Extract here"_i18n, [this](){ UnzipFiles(""); })); - options->Add(std::make_shared("Extract to root"_i18n, [this](){ - App::Push(std::make_shared("Are you sure you want to extract to root?"_i18n, + options->Add(std::make_unique("Extract to root"_i18n, [this](){ + App::Push(std::make_unique("Are you sure you want to extract to root?"_i18n, "No"_i18n, "Yes"_i18n, 0, [this](auto op_index){ if (op_index && *op_index) { UnzipFiles(m_fs->Root()); @@ -1717,7 +1717,7 @@ void FsView::DisplayOptions() { })); })); - options->Add(std::make_shared("Extract to..."_i18n, [this](){ + options->Add(std::make_unique("Extract to..."_i18n, [this](){ std::string out; if (R_SUCCEEDED(swkbd::ShowText(out, "Enter the path to the folder to extract into", fs::AppendPath(m_path, ""))) && !out.empty()) { UnzipFiles(out); @@ -1727,15 +1727,15 @@ void FsView::DisplayOptions() { } if (!check_all_ext(ZIP_EXTENSIONS) || m_selected_count) { - options->Add(std::make_shared("Compress to zip"_i18n, [this](){ - auto options = std::make_shared("Compress Options"_i18n, Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + options->Add(std::make_unique("Compress to zip"_i18n, [this](){ + auto options = std::make_unique("Compress Options"_i18n, Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); - options->Add(std::make_shared("Compress"_i18n, [this](){ + options->Add(std::make_unique("Compress"_i18n, [this](){ ZipFiles(""); })); - options->Add(std::make_shared("Compress to..."_i18n, [this](){ + options->Add(std::make_unique("Compress to..."_i18n, [this](){ std::string out; if (R_SUCCEEDED(swkbd::ShowText(out, "Enter the path to the folder to extract into", m_path)) && !out.empty()) { ZipFiles(out); @@ -1745,14 +1745,14 @@ void FsView::DisplayOptions() { } } - options->Add(std::make_shared("Advanced"_i18n, [this](){ + options->Add(std::make_unique("Advanced"_i18n, [this](){ DisplayAdvancedOptions(); })); } void FsView::DisplayAdvancedOptions() { - auto options = std::make_shared("Advanced Options"_i18n, Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + auto options = std::make_unique("Advanced Options"_i18n, Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); SidebarEntryArray::Items mount_items; std::vector fs_entries; @@ -1773,12 +1773,12 @@ void FsView::DisplayAdvancedOptions() { mount_items.push_back(i18n::get(e.name)); } - options->Add(std::make_shared("Mount"_i18n, mount_items, [this, fs_entries](s64& index_out){ + options->Add(std::make_unique("Mount"_i18n, mount_items, [this, fs_entries](s64& index_out){ App::PopToMenu(); SetFs(fs_entries[index_out].root, fs_entries[index_out]); }, i18n::get(m_fs_entry.name))); - options->Add(std::make_shared("Create File"_i18n, [this](){ + options->Add(std::make_unique("Create File"_i18n, [this](){ std::string out; if (R_SUCCEEDED(swkbd::ShowText(out, "Set File Name"_i18n.c_str(), fs::AppendPath(m_path, ""))) && !out.empty()) { App::PopToMenu(); @@ -1800,7 +1800,7 @@ void FsView::DisplayAdvancedOptions() { } })); - options->Add(std::make_shared("Create Folder"_i18n, [this](){ + options->Add(std::make_unique("Create Folder"_i18n, [this](){ std::string out; if (R_SUCCEEDED(swkbd::ShowText(out, "Set Folder Name"_i18n.c_str(), fs::AppendPath(m_path, ""))) && !out.empty()) { App::PopToMenu(); @@ -1822,38 +1822,38 @@ void FsView::DisplayAdvancedOptions() { })); if (IsSd() && m_entries_current.size() && !m_selected_count && GetEntry().IsFile() && GetEntry().file_size < 1024*64) { - options->Add(std::make_shared("View as text (unfinished)"_i18n, [this](){ - App::Push(std::make_shared(GetNewPathCurrent())); + options->Add(std::make_unique("View as text (unfinished)"_i18n, [this](){ + App::Push(std::make_unique(GetNewPathCurrent())); })); } if (m_entries_current.size()) { - options->Add(std::make_shared("Upload"_i18n, [this](){ + options->Add(std::make_unique("Upload"_i18n, [this](){ UploadFiles(); })); } if (m_entries_current.size() && !m_selected_count && GetEntry().IsFile()) { - options->Add(std::make_shared("Hash"_i18n, [this](){ - auto options = std::make_shared("Hash Options"_i18n, Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + options->Add(std::make_unique("Hash"_i18n, [this](){ + auto options = std::make_unique("Hash Options"_i18n, Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); - options->Add(std::make_shared("CRC32"_i18n, [this](){ + options->Add(std::make_unique("CRC32"_i18n, [this](){ DisplayHash(hash::Type::Crc32); })); - options->Add(std::make_shared("MD5"_i18n, [this](){ + options->Add(std::make_unique("MD5"_i18n, [this](){ DisplayHash(hash::Type::Md5); })); - options->Add(std::make_shared("SHA1"_i18n, [this](){ + options->Add(std::make_unique("SHA1"_i18n, [this](){ DisplayHash(hash::Type::Sha1); })); - options->Add(std::make_shared("SHA256"_i18n, [this](){ + options->Add(std::make_unique("SHA256"_i18n, [this](){ DisplayHash(hash::Type::Sha256); })); })); } - options->Add(std::make_shared("Ignore read only"_i18n, m_menu->m_ignore_read_only.Get(), [this](bool& v_out){ + options->Add(std::make_unique("Ignore read only"_i18n, m_menu->m_ignore_read_only.Get(), [this](bool& v_out){ m_menu->m_ignore_read_only.Set(v_out); m_fs->SetIgnoreReadOnly(v_out); })); @@ -1870,7 +1870,8 @@ Menu::Menu(u32 flags) : MenuBase{"FileBrowser"_i18n, flags} { }}); } - view = view_left = std::make_shared(this, ViewSide::Left); + view_left = std::make_unique(this, ViewSide::Left); + view = view_left.get(); ueventCreate(&g_change_uevent, true); } @@ -1910,7 +1911,7 @@ void Menu::Draw(NVGcontext* vg, Theme* theme) { view_left->Draw(vg, theme); view_right->Draw(vg, theme); - if (view == view_left) { + if (view == view_left.get()) { gfx::drawRect(vg, view_right->GetPos(), theme->GetColour(ThemeEntryID_FOCUS), 5); } else { gfx::drawRect(vg, view_left->GetPos(), theme->GetColour(ThemeEntryID_FOCUS), 5); @@ -2102,7 +2103,7 @@ void Menu::SetSplitScreen(bool enable) { m_split_screen = enable; if (m_split_screen) { - const auto change_view = [this](auto new_view){ + const auto change_view = [this](FsView* new_view){ if (view != new_view) { view->OnFocusLost(); view = new_view; @@ -2114,19 +2115,22 @@ void Menu::SetSplitScreen(bool enable) { // load second screen as a copy of the left side. view->SetSide(ViewSide::Left); - view_right = std::make_shared(this, view->m_path, view->GetFsEntry(), ViewSide::Right); - change_view(view_right); + view_right = std::make_unique(this, view->m_path, view->GetFsEntry(), ViewSide::Right); + change_view(view_right.get()); SetAction(Button::LEFT, Action{[this, change_view](){ - change_view(view_left); + change_view(view_left.get()); }}); SetAction(Button::RIGHT, Action{[this, change_view](){ - change_view(view_right); + change_view(view_right.get()); }}); } else { - view_left = {}; + if (view == view_right.get()) { + view_left = std::move(view_right); + } + view_right = {}; - view_left = view; + view = view_left.get(); view->SetSide(ViewSide::Left); RemoveAction(Button::LEFT); @@ -2152,7 +2156,7 @@ void Menu::PromptIfShouldExit() { return; } - App::Push(std::make_shared( + App::Push(std::make_unique( "Close FileBrowser?"_i18n, "No"_i18n, "Yes"_i18n, 1, [this](auto op_index){ if (op_index && *op_index) { diff --git a/sphaira/source/ui/menus/game_menu.cpp b/sphaira/source/ui/menus/game_menu.cpp index b39eef6..20f3f30 100644 --- a/sphaira/source/ui/menus/game_menu.cpp +++ b/sphaira/source/ui/menus/game_menu.cpp @@ -172,7 +172,7 @@ private: Result Notify(Result rc, const std::string& error_message) { if (R_FAILED(rc)) { - App::Push(std::make_shared(rc, + App::Push(std::make_unique(rc, i18n::get(error_message) )); } else { @@ -185,12 +185,10 @@ Result GetMetaEntries(const Entry& e, title::MetaEntries& out, u32 flags = title return title::GetMetaEntries(e.app_id, out, flags); } -bool LoadControlImage(Entry& e) { - if (!e.image && e.info && !e.info->icon.empty()) { - ON_SCOPE_EXIT(e.info.reset()); - +bool LoadControlImage(Entry& e, title::ThreadResultData* result) { + if (!e.image && result && !result->icon.empty()) { TimeStamp ts; - const auto image = ImageLoadFromMemory(e.info->icon, ImageFlag_JPEG); + const auto image = ImageLoadFromMemory(result->icon, ImageFlag_JPEG); if (!image.data.empty()) { e.image = nvgCreateImageRGBA(App::GetVg(), image.w, image.h, 0, image.data.data()); log_write("\t[image load] time taken: %.2fs %zums\n", ts.GetSecondsD(), ts.GetMs()); @@ -201,11 +199,12 @@ bool LoadControlImage(Entry& e) { return false; } -void LoadResultIntoEntry(Entry& e, const std::shared_ptr& result) { - e.info = result; - e.status = result->status; - e.lang = result->lang; - e.status = result->status; +void LoadResultIntoEntry(Entry& e, title::ThreadResultData* result) { + if (result) { + e.status = result->status; + e.lang = result->lang; + e.status = result->status; + } } void LoadControlEntry(Entry& e, bool force_image_load = false) { @@ -214,7 +213,7 @@ void LoadControlEntry(Entry& e, bool force_image_load = false) { } if (force_image_load && e.status == title::NacpLoadStatus::Loaded) { - LoadControlImage(e); + LoadControlImage(e, title::Get(e.app_id)); } } @@ -474,13 +473,13 @@ Menu::Menu(u32 flags) : grid::Menu{"Games"_i18n, flags} { LaunchEntry(m_entries[m_index]); }}), std::make_pair(Button::X, Action{"Options"_i18n, [this](){ - auto options = std::make_shared("Game Options"_i18n, Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + auto options = std::make_unique("Game Options"_i18n, Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); if (m_entries.size()) { - options->Add(std::make_shared("Sort By"_i18n, [this](){ - auto options = std::make_shared("Sort Options"_i18n, Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + options->Add(std::make_unique("Sort By"_i18n, [this](){ + auto options = std::make_unique("Sort Options"_i18n, Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); SidebarEntryArray::Items sort_items; sort_items.push_back("Updated"_i18n); @@ -494,39 +493,39 @@ Menu::Menu(u32 flags) : grid::Menu{"Games"_i18n, flags} { layout_items.push_back("Icon"_i18n); layout_items.push_back("Grid"_i18n); - options->Add(std::make_shared("Sort"_i18n, sort_items, [this](s64& index_out){ + options->Add(std::make_unique("Sort"_i18n, sort_items, [this](s64& index_out){ m_sort.Set(index_out); SortAndFindLastFile(false); }, m_sort.Get())); - options->Add(std::make_shared("Order"_i18n, order_items, [this](s64& index_out){ + options->Add(std::make_unique("Order"_i18n, order_items, [this](s64& index_out){ m_order.Set(index_out); SortAndFindLastFile(false); }, m_order.Get())); - options->Add(std::make_shared("Layout"_i18n, layout_items, [this](s64& index_out){ + options->Add(std::make_unique("Layout"_i18n, layout_items, [this](s64& index_out){ m_layout.Set(index_out); OnLayoutChange(); }, m_layout.Get())); - options->Add(std::make_shared("Hide forwarders"_i18n, m_hide_forwarders.Get(), [this](bool& v_out){ + options->Add(std::make_unique("Hide forwarders"_i18n, m_hide_forwarders.Get(), [this](bool& v_out){ m_hide_forwarders.Set(v_out); m_dirty = true; })); })); #if 0 - options->Add(std::make_shared("Info"_i18n, [this](){ + options->Add(std::make_unique("Info"_i18n, [this](){ })); #endif - options->Add(std::make_shared("Launch random game"_i18n, [this](){ + options->Add(std::make_unique("Launch random game"_i18n, [this](){ const auto random_index = randomGet64() % std::size(m_entries); auto& e = m_entries[random_index]; LoadControlEntry(e, true); - App::Push(std::make_shared( + App::Push(std::make_unique( "Launch "_i18n + e.GetName(), "Back"_i18n, "Launch"_i18n, 1, [this, &e](auto op_index){ if (op_index && *op_index) { @@ -536,11 +535,11 @@ Menu::Menu(u32 flags) : grid::Menu{"Games"_i18n, flags} { )); })); - options->Add(std::make_shared("List meta records"_i18n, [this](){ + options->Add(std::make_unique("List meta records"_i18n, [this](){ title::MetaEntries meta_entries; const auto rc = GetMetaEntries(m_entries[m_index], meta_entries); if (R_FAILED(rc)) { - App::Push(std::make_shared(rc, + App::Push(std::make_unique(rc, i18n::get("Failed to list application meta entries") )); return; @@ -558,7 +557,7 @@ Menu::Menu(u32 flags) : grid::Menu{"Games"_i18n, flags} { items.emplace_back(buf); } - App::Push(std::make_shared( + App::Push(std::make_unique( "Entries"_i18n, items, [this, meta_entries](auto op_index){ #if 0 if (op_index) { @@ -569,35 +568,35 @@ Menu::Menu(u32 flags) : grid::Menu{"Games"_i18n, flags} { )); })); - options->Add(std::make_shared("Dump"_i18n, [this](){ - auto options = std::make_shared("Select content to dump"_i18n, Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + options->Add(std::make_unique("Dump"_i18n, [this](){ + auto options = std::make_unique("Select content to dump"_i18n, Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); - options->Add(std::make_shared("Dump All"_i18n, [this](){ + options->Add(std::make_unique("Dump All"_i18n, [this](){ DumpGames(title::ContentFlag_All); }, true)); - options->Add(std::make_shared("Dump Application"_i18n, [this](){ + options->Add(std::make_unique("Dump Application"_i18n, [this](){ DumpGames(title::ContentFlag_Application); }, true)); - options->Add(std::make_shared("Dump Patch"_i18n, [this](){ + options->Add(std::make_unique("Dump Patch"_i18n, [this](){ DumpGames(title::ContentFlag_Patch); }, true)); - options->Add(std::make_shared("Dump AddOnContent"_i18n, [this](){ + options->Add(std::make_unique("Dump AddOnContent"_i18n, [this](){ DumpGames(title::ContentFlag_AddOnContent); }, true)); - options->Add(std::make_shared("Dump DataPatch"_i18n, [this](){ + options->Add(std::make_unique("Dump DataPatch"_i18n, [this](){ DumpGames(title::ContentFlag_DataPatch); }, true)); }, true)); - options->Add(std::make_shared("Dump options"_i18n, [this](){ + options->Add(std::make_unique("Dump options"_i18n, [this](){ App::DisplayDumpOptions(false); })); // completely deletes the application record and all data. - options->Add(std::make_shared("Delete"_i18n, [this](){ + options->Add(std::make_unique("Delete"_i18n, [this](){ const auto buf = "Are you sure you want to delete "_i18n + m_entries[m_index].GetName() + "?"; - App::Push(std::make_shared( + App::Push(std::make_unique( buf, "Back"_i18n, "Delete"_i18n, 0, [this](auto op_index){ if (op_index && *op_index) { @@ -608,16 +607,16 @@ Menu::Menu(u32 flags) : grid::Menu{"Games"_i18n, flags} { }, true)); } - options->Add(std::make_shared("Advanced options"_i18n, [this](){ - auto options = std::make_shared("Advanced Options"_i18n, Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + options->Add(std::make_unique("Advanced options"_i18n, [this](){ + auto options = std::make_unique("Advanced Options"_i18n, Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); - options->Add(std::make_shared("Refresh"_i18n, [this](){ + options->Add(std::make_unique("Refresh"_i18n, [this](){ m_dirty = true; App::PopToMenu(); })); - options->Add(std::make_shared("Create contents folder"_i18n, [this](){ + options->Add(std::make_unique("Create contents folder"_i18n, [this](){ const auto rc = fs::FsNativeSd().CreateDirectory(title::GetContentsPath(m_entries[m_index].app_id)); App::PushErrorBox(rc, "Folder create failed!"_i18n); @@ -626,14 +625,14 @@ Menu::Menu(u32 flags) : grid::Menu{"Games"_i18n, flags} { } })); - options->Add(std::make_shared("Create save"_i18n, [this](){ + options->Add(std::make_unique("Create save"_i18n, [this](){ ui::PopupList::Items items{}; const auto accounts = App::GetAccountList(); for (auto& p : accounts) { items.emplace_back(p.nickname); } - App::Push(std::make_shared( + App::Push(std::make_unique( "Select user to create save for"_i18n, items, [this, accounts](auto op_index){ if (op_index) { CreateSaves(accounts[*op_index].uid); @@ -642,12 +641,12 @@ Menu::Menu(u32 flags) : grid::Menu{"Games"_i18n, flags} { )); })); - options->Add(std::make_shared("Title cache"_i18n, m_title_cache.Get(), [this](bool& v_out){ + options->Add(std::make_unique("Title cache"_i18n, m_title_cache.Get(), [this](bool& v_out){ m_title_cache.Set(v_out); })); - options->Add(std::make_shared("Delete title cache"_i18n, [this](){ - App::Push(std::make_shared( + options->Add(std::make_unique("Delete title cache"_i18n, [this](){ + App::Push(std::make_unique( "Are you sure you want to delete the title cache?"_i18n, "Back"_i18n, "Delete"_i18n, 0, [this](auto op_index){ if (op_index && *op_index) { @@ -714,14 +713,12 @@ void Menu::Draw(NVGcontext* vg, Theme* theme) { title::PushAsync(e.app_id); e.status = title::NacpLoadStatus::Progress; } else if (e.status == title::NacpLoadStatus::Progress) { - if (const auto data = title::GetAsync(e.app_id)) { - LoadResultIntoEntry(e, data); - } + LoadResultIntoEntry(e, title::GetAsync(e.app_id)); } // lazy load image if (image_load_count < image_load_max) { - if (LoadControlImage(e)) { + if (LoadControlImage(e, title::GetAsync(e.app_id))) { image_load_count++; } } @@ -879,7 +876,7 @@ void Menu::OnLayoutChange() { } void Menu::DeleteGames() { - App::Push(std::make_shared(0, "Deleting"_i18n, "", [this](auto pbox) -> Result { + App::Push(std::make_unique(0, "Deleting"_i18n, "", [this](auto pbox) -> Result { auto targets = GetSelectedEntries(); for (s64 i = 0; i < std::size(targets); i++) { @@ -924,7 +921,7 @@ void Menu::DumpGames(u32 flags) { } void Menu::CreateSaves(AccountUid uid) { - App::Push(std::make_shared(0, "Creating"_i18n, "", [this, uid](auto pbox) -> Result { + App::Push(std::make_unique(0, "Creating"_i18n, "", [this, uid](auto pbox) -> Result { auto targets = GetSelectedEntries(); for (s64 i = 0; i < std::size(targets); i++) { diff --git a/sphaira/source/ui/menus/gc_menu.cpp b/sphaira/source/ui/menus/gc_menu.cpp index 1bfadb1..c49d426 100644 --- a/sphaira/source/ui/menus/gc_menu.cpp +++ b/sphaira/source/ui/menus/gc_menu.cpp @@ -376,16 +376,16 @@ Menu::Menu(u32 flags) : MenuBase{"GameCard"_i18n, flags} { if (m_option_index == 0) { if (!App::GetInstallEnable()) { - App::Push(std::make_shared( + App::Push(std::make_unique( "Install disabled...\n" "Please enable installing via the install options."_i18n, "OK"_i18n )); } else { log_write("[GC] doing install A\n"); - App::Push(std::make_shared(m_icon, "Installing "_i18n, m_entries[m_entry_index].lang_entry.name, [this](auto pbox) -> Result { - auto source = std::make_shared(m_entries[m_entry_index], m_fs.get()); - return yati::InstallFromCollections(pbox, source, source->m_collections, source->m_config); + App::Push(std::make_unique(m_icon, "Installing "_i18n, m_entries[m_entry_index].lang_entry.name, [this](auto pbox) -> Result { + auto source = std::make_unique(m_entries[m_entry_index], m_fs.get()); + return yati::InstallFromCollections(pbox, source.get(), source->m_collections, source->m_config); }, [this](Result rc){ App::PushErrorBox(rc, "Gc install failed!"_i18n); @@ -395,11 +395,11 @@ Menu::Menu(u32 flags) : MenuBase{"GameCard"_i18n, flags} { })); } } else { - auto options = std::make_shared("Select content to dump"_i18n, Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + auto options = std::make_unique("Select content to dump"_i18n, Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); const auto add = [&](const std::string& name, u32 flags){ - options->Add(std::make_shared(name, [this, flags](){ + options->Add(std::make_unique(name, [this, flags](){ DumpGames(flags); m_dirty = true; }, true)); @@ -419,14 +419,14 @@ Menu::Menu(u32 flags) : MenuBase{"GameCard"_i18n, flags} { SetPop(); }}), std::make_pair(Button::X, Action{"Options"_i18n, [this](){ - auto options = std::make_shared("Game Options"_i18n, Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + auto options = std::make_unique("Game Options"_i18n, Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); - options->Add(std::make_shared("Install options"_i18n, [this](){ + options->Add(std::make_unique("Install options"_i18n, [this](){ App::DisplayInstallOptions(false); })); - options->Add(std::make_shared("Dump options"_i18n, [this](){ + options->Add(std::make_unique("Dump options"_i18n, [this](){ App::DisplayDumpOptions(false); })); }}) @@ -982,7 +982,7 @@ Result Menu::DumpGames(u32 flags) { // if trimmed and the user wants to dump the full xci, error. if ((flags & DumpFileFlag_XCI) && is_trimmed && App::GetApp()->m_dump_trim_xci.Get()) { - App::Push(std::make_shared( + App::Push(std::make_unique( "WARNING: GameCard is already trimmed!"_i18n, "Back"_i18n, "Continue"_i18n, 0, [&](auto op_index){ if (op_index && *op_index) { diff --git a/sphaira/source/ui/menus/ghdl.cpp b/sphaira/source/ui/menus/ghdl.cpp index c6572ad..785d667 100644 --- a/sphaira/source/ui/menus/ghdl.cpp +++ b/sphaira/source/ui/menus/ghdl.cpp @@ -166,7 +166,7 @@ Menu::Menu(u32 flags) : MenuBase{"GitHub"_i18n, flags} { static GhApiEntry gh_entry; gh_entry = {}; - App::Push(std::make_shared(0, "Downloading "_i18n, GetEntry().repo, [this](auto pbox) -> Result { + App::Push(std::make_unique(0, "Downloading "_i18n, GetEntry().repo, [this](auto pbox) -> Result { return DownloadAssetJson(pbox, GenerateApiUrl(GetEntry()), gh_entry); }, [this](Result rc){ App::PushErrorBox(rc, "Failed to download json"_i18n); @@ -199,7 +199,7 @@ Menu::Menu(u32 flags) : MenuBase{"GitHub"_i18n, flags} { } } - App::Push(std::make_shared("Select asset to download for "_i18n + GetEntry().repo, asset_items, [this, api_assets, asset_ptr](auto op_index){ + App::Push(std::make_unique("Select asset to download for "_i18n + GetEntry().repo, asset_items, [this, api_assets, asset_ptr](auto op_index){ if (!op_index) { return; } @@ -216,7 +216,7 @@ Menu::Menu(u32 flags) : MenuBase{"GitHub"_i18n, flags} { } const auto func = [this, &asset_entry, ptr](){ - App::Push(std::make_shared(0, "Downloading "_i18n, GetEntry().repo, [this, &asset_entry, ptr](auto pbox) -> Result { + App::Push(std::make_unique(0, "Downloading "_i18n, GetEntry().repo, [this, &asset_entry, ptr](auto pbox) -> Result { return DownloadApp(pbox, asset_entry, ptr); }, [this, ptr](Result rc){ homebrew::SignalChange(); @@ -230,14 +230,14 @@ Menu::Menu(u32 flags) : MenuBase{"GitHub"_i18n, flags} { } if (!post_install_message.empty()) { - App::Push(std::make_shared(post_install_message, "OK"_i18n)); + App::Push(std::make_unique(post_install_message, "OK"_i18n)); } } })); }; if (!pre_install_message.empty()) { - App::Push(std::make_shared( + App::Push(std::make_unique( pre_install_message, "Back"_i18n, "Download"_i18n, 1, [this, func](auto op_index){ if (op_index && *op_index) { diff --git a/sphaira/source/ui/menus/homebrew.cpp b/sphaira/source/ui/menus/homebrew.cpp index f2e85dc..6b894ce 100644 --- a/sphaira/source/ui/menus/homebrew.cpp +++ b/sphaira/source/ui/menus/homebrew.cpp @@ -56,13 +56,13 @@ Menu::Menu() : grid::Menu{"Homebrew"_i18n, MenuFlag_Tab} { nro_launch(m_entries[m_index].path); }}), std::make_pair(Button::X, Action{"Options"_i18n, [this](){ - auto options = std::make_shared("Homebrew Options"_i18n, Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + auto options = std::make_unique("Homebrew Options"_i18n, Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); if (m_entries.size()) { - options->Add(std::make_shared("Sort By"_i18n, [this](){ - auto options = std::make_shared("Sort Options"_i18n, Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + options->Add(std::make_unique("Sort By"_i18n, [this](){ + auto options = std::make_unique("Sort Options"_i18n, Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); SidebarEntryArray::Items sort_items; sort_items.push_back("Updated"_i18n); @@ -81,35 +81,35 @@ Menu::Menu() : grid::Menu{"Homebrew"_i18n, MenuFlag_Tab} { layout_items.push_back("Icon"_i18n); layout_items.push_back("Grid"_i18n); - options->Add(std::make_shared("Sort"_i18n, sort_items, [this, sort_items](s64& index_out){ + options->Add(std::make_unique("Sort"_i18n, sort_items, [this, sort_items](s64& index_out){ m_sort.Set(index_out); SortAndFindLastFile(); }, m_sort.Get())); - options->Add(std::make_shared("Order"_i18n, order_items, [this, order_items](s64& index_out){ + options->Add(std::make_unique("Order"_i18n, order_items, [this, order_items](s64& index_out){ m_order.Set(index_out); SortAndFindLastFile(); }, m_order.Get())); - options->Add(std::make_shared("Layout"_i18n, layout_items, [this](s64& index_out){ + options->Add(std::make_unique("Layout"_i18n, layout_items, [this](s64& index_out){ m_layout.Set(index_out); OnLayoutChange(); }, m_layout.Get())); - options->Add(std::make_shared("Hide Sphaira"_i18n, m_hide_sphaira.Get(), [this](bool& enable){ + options->Add(std::make_unique("Hide Sphaira"_i18n, m_hide_sphaira.Get(), [this](bool& enable){ m_hide_sphaira.Set(enable); })); })); #if 0 - options->Add(std::make_shared("Info"_i18n, [this](){ + options->Add(std::make_unique("Info"_i18n, [this](){ })); #endif - options->Add(std::make_shared("Delete"_i18n, [this](){ + options->Add(std::make_unique("Delete"_i18n, [this](){ const auto buf = "Are you sure you want to delete "_i18n + m_entries[m_index].path.toString() + "?"; - App::Push(std::make_shared( + App::Push(std::make_unique( buf, "Back"_i18n, "Delete"_i18n, 1, [this](auto op_index){ if (op_index && *op_index) { @@ -124,9 +124,9 @@ Menu::Menu() : grid::Menu{"Homebrew"_i18n, MenuFlag_Tab} { }, true)); if (App::GetInstallEnable()) { - options->Add(std::make_shared("Install Forwarder"_i18n, [this](){ + options->Add(std::make_unique("Install Forwarder"_i18n, [this](){ if (App::GetInstallPrompt()) { - App::Push(std::make_shared( + App::Push(std::make_unique( "WARNING: Installing forwarders will lead to a ban!"_i18n, "Back"_i18n, "Install"_i18n, 0, [this](auto op_index){ if (op_index && *op_index) { diff --git a/sphaira/source/ui/menus/install_stream_menu_base.cpp b/sphaira/source/ui/menus/install_stream_menu_base.cpp index 7197952..62d3e16 100644 --- a/sphaira/source/ui/menus/install_stream_menu_base.cpp +++ b/sphaira/source/ui/menus/install_stream_menu_base.cpp @@ -142,9 +142,9 @@ void Menu::Update(Controller* controller, TouchInfo* touch) { if (m_state == State::Connected) { m_state = State::Progress; - App::Push(std::make_shared(0, "Installing "_i18n, m_source->GetPath(), [this](auto pbox) -> Result { + App::Push(std::make_unique(0, "Installing "_i18n, m_source->GetPath(), [this](auto pbox) -> Result { INSTALL_STATE = InstallState::Progress; - const auto rc = yati::InstallFromSource(pbox, m_source, m_source->GetPath()); + const auto rc = yati::InstallFromSource(pbox, m_source.get(), m_source->GetPath()); INSTALL_STATE = InstallState::Finished; if (R_FAILED(rc)) { @@ -234,7 +234,7 @@ bool Menu::OnInstallStart(const char* path) { SCOPED_MUTEX(&m_mutex); - m_source = std::make_shared(path, GetToken()); + m_source = std::make_unique(path, GetToken()); INSTALL_STATE = InstallState::None; m_state = State::Connected; log_write("[Menu::OnInstallStart] exiting\n"); diff --git a/sphaira/source/ui/menus/irs_menu.cpp b/sphaira/source/ui/menus/irs_menu.cpp index 72963b6..d407f1d 100644 --- a/sphaira/source/ui/menus/irs_menu.cpp +++ b/sphaira/source/ui/menus/irs_menu.cpp @@ -81,8 +81,8 @@ Menu::Menu(u32 flags) : MenuBase{"Irs"_i18n, flags} { }}); SetAction(Button::X, Action{"Options"_i18n, [this](){ - auto options = std::make_shared("Options"_i18n, Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + auto options = std::make_unique("Options"_i18n, Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); SidebarEntryArray::Items controller_str; for (u32 i = 0; i < IRS_MAX_CAMERAS; i++) { @@ -126,44 +126,44 @@ Menu::Menu(u32 flags) : MenuBase{"Irs"_i18n, flags} { format_str.emplace_back("20\u00D715"); } - options->Add(std::make_shared("Controller"_i18n, controller_str, [this](s64& index){ + options->Add(std::make_unique("Controller"_i18n, controller_str, [this](s64& index){ irsStopImageProcessor(m_entries[m_index].m_handle); m_index = index; UpdateConfig(&m_config); }, m_index)); - options->Add(std::make_shared("Rotation"_i18n, rotation_str, [this](s64& index){ + options->Add(std::make_unique("Rotation"_i18n, rotation_str, [this](s64& index){ m_rotation = (Rotation)index; }, m_rotation)); - options->Add(std::make_shared("Colour"_i18n, colour_str, [this](s64& index){ + options->Add(std::make_unique("Colour"_i18n, colour_str, [this](s64& index){ m_colour = (Colour)index; updateColourArray(); }, m_colour)); - options->Add(std::make_shared("Light Target"_i18n, light_target_str, [this](s64& index){ + options->Add(std::make_unique("Light Target"_i18n, light_target_str, [this](s64& index){ m_config.light_target = index; UpdateConfig(&m_config); }, m_config.light_target)); - options->Add(std::make_shared("Gain"_i18n, gain_str, [this](s64& index){ + options->Add(std::make_unique("Gain"_i18n, gain_str, [this](s64& index){ m_config.gain = GAIN_MIN + index; UpdateConfig(&m_config); }, m_config.gain - GAIN_MIN)); - options->Add(std::make_shared("Negative Image"_i18n, is_negative_image_used_str, [this](s64& index){ + options->Add(std::make_unique("Negative Image"_i18n, is_negative_image_used_str, [this](s64& index){ m_config.is_negative_image_used = index; UpdateConfig(&m_config); }, m_config.is_negative_image_used)); - options->Add(std::make_shared("Format"_i18n, format_str, [this](s64& index){ + options->Add(std::make_unique("Format"_i18n, format_str, [this](s64& index){ m_config.orig_format = index; m_config.trimming_format = index; UpdateConfig(&m_config); }, m_config.orig_format)); if (hosversionAtLeast(4,0,0)) { - options->Add(std::make_shared("Trimming Format"_i18n, format_str, [this](s64& index){ + options->Add(std::make_unique("Trimming Format"_i18n, format_str, [this](s64& index){ // you cannot set trim a larger region than the source if (index < m_config.orig_format) { index = m_config.orig_format; @@ -173,13 +173,13 @@ Menu::Menu(u32 flags) : MenuBase{"Irs"_i18n, flags} { } }, m_config.orig_format)); - options->Add(std::make_shared("External Light Filter"_i18n, m_config.is_external_light_filter_enabled, [this](bool& enable){ + options->Add(std::make_unique("External Light Filter"_i18n, m_config.is_external_light_filter_enabled, [this](bool& enable){ m_config.is_external_light_filter_enabled = enable; UpdateConfig(&m_config); })); } - options->Add(std::make_shared("Load Default"_i18n, [this](){ + options->Add(std::make_unique("Load Default"_i18n, [this](){ LoadDefaultConfig(); }, true)); }}); diff --git a/sphaira/source/ui/menus/main_menu.cpp b/sphaira/source/ui/menus/main_menu.cpp index b443c6c..0fcfec2 100644 --- a/sphaira/source/ui/menus/main_menu.cpp +++ b/sphaira/source/ui/menus/main_menu.cpp @@ -44,7 +44,7 @@ constexpr const fs::FsPath SPHAIRA_PATHS[]{ template auto MiscMenuFuncGenerator(u32 flags) { - return std::make_shared(flags); + return std::make_unique(flags); } const MiscMenuEntry MISC_MENU_ENTRIES[] = { @@ -122,7 +122,7 @@ auto InstallUpdate(ProgressBox* pbox, const std::string url, const std::string v R_SUCCEED(); } -auto CreateLeftSideMenu(std::string& name_out) -> std::shared_ptr { +auto CreateLeftSideMenu(std::string& name_out) -> std::unique_ptr { const auto name = App::GetApp()->m_left_menu.Get(); for (auto& e : GetMiscMenuEntries()) { @@ -133,20 +133,20 @@ auto CreateLeftSideMenu(std::string& name_out) -> std::shared_ptr { } name_out = "FileBrowser"; - return std::make_shared(MenuFlag_Tab); + return std::make_unique(MenuFlag_Tab); } -auto CreateRightSideMenu(std::string_view left_name) -> std::shared_ptr { +auto CreateRightSideMenu(std::string_view left_name) -> std::unique_ptr { const auto name = App::GetApp()->m_right_menu.Get(); // handle if the user tries to mount the same menu twice. if (name == left_name) { // check if we can mount the default. if (left_name != "AppStore") { - return std::make_shared(MenuFlag_Tab); + return std::make_unique(MenuFlag_Tab); } else { // otherwise, fallback to left side default. - return std::make_shared(MenuFlag_Tab); + return std::make_unique(MenuFlag_Tab); } } @@ -156,7 +156,7 @@ auto CreateRightSideMenu(std::string_view left_name) -> std::shared_ptr(MenuFlag_Tab); + return std::make_unique(MenuFlag_Tab); } } // namespace @@ -235,8 +235,8 @@ MainMenu::MainMenu() { std::make_pair(Button::START, Action{App::Exit}), std::make_pair(Button::SELECT, Action{App::DisplayMiscOptions}), std::make_pair(Button::Y, Action{"Menu"_i18n, [this](){ - auto options = std::make_shared("Menu Options"_i18n, "v" APP_VERSION_HASH, Sidebar::Side::LEFT); - ON_SCOPE_EXIT(App::Push(options)); + auto options = std::make_unique("Menu Options"_i18n, "v" APP_VERSION_HASH, Sidebar::Side::LEFT); + ON_SCOPE_EXIT(App::Push(std::move(options))); SidebarEntryArray::Items language_items; language_items.push_back("Auto"_i18n); @@ -255,17 +255,17 @@ MainMenu::MainMenu() { language_items.push_back("Vietnamese"_i18n); language_items.push_back("Ukrainian"_i18n); - options->Add(std::make_shared("Theme"_i18n, [](){ + options->Add(std::make_unique("Theme"_i18n, [](){ App::DisplayThemeOptions(); })); - options->Add(std::make_shared("Network"_i18n, [this](){ - auto options = std::make_shared("Network Options"_i18n, Sidebar::Side::LEFT); - ON_SCOPE_EXIT(App::Push(options)); + options->Add(std::make_unique("Network"_i18n, [this](){ + auto options = std::make_unique("Network Options"_i18n, Sidebar::Side::LEFT); + ON_SCOPE_EXIT(App::Push(std::move(options))); if (m_update_state == UpdateState::Update) { - options->Add(std::make_shared("Download update: "_i18n + m_update_version, [this](){ - App::Push(std::make_shared(0, "Downloading "_i18n, "Sphaira v" + m_update_version, [this](auto pbox) -> Result { + options->Add(std::make_unique("Download update: "_i18n + m_update_version, [this](){ + App::Push(std::make_unique(0, "Downloading "_i18n, "Sphaira v" + m_update_version, [this](auto pbox) -> Result { return InstallUpdate(pbox, m_update_url, m_update_version); }, [this](Result rc){ App::PushErrorBox(rc, "Failed to download update"_i18n); @@ -273,7 +273,7 @@ MainMenu::MainMenu() { if (R_SUCCEEDED(rc)) { m_update_state = UpdateState::None; App::Notify("Updated to "_i18n + m_update_version); - App::Push(std::make_shared( + App::Push(std::make_unique( "Press OK to restart Sphaira"_i18n, "OK"_i18n, [](auto){ App::ExitRestart(); } @@ -283,44 +283,43 @@ MainMenu::MainMenu() { })); } - options->Add(std::make_shared("Ftp"_i18n, App::GetFtpEnable(), [](bool& enable){ + options->Add(std::make_unique("Ftp"_i18n, App::GetFtpEnable(), [](bool& enable){ App::SetFtpEnable(enable); })); - options->Add(std::make_shared("Mtp"_i18n, App::GetMtpEnable(), [](bool& enable){ + options->Add(std::make_unique("Mtp"_i18n, App::GetMtpEnable(), [](bool& enable){ App::SetMtpEnable(enable); })); - options->Add(std::make_shared("Nxlink"_i18n, App::GetNxlinkEnable(), [](bool& enable){ + options->Add(std::make_unique("Nxlink"_i18n, App::GetNxlinkEnable(), [](bool& enable){ App::SetNxlinkEnable(enable); })); - options->Add(std::make_shared("Hdd"_i18n, App::GetHddEnable(), [](bool& enable){ + options->Add(std::make_unique("Hdd"_i18n, App::GetHddEnable(), [](bool& enable){ App::SetHddEnable(enable); })); - options->Add(std::make_shared("Hdd write protect"_i18n, App::GetWriteProtect(), [](bool& enable){ + options->Add(std::make_unique("Hdd write protect"_i18n, App::GetWriteProtect(), [](bool& enable){ App::SetWriteProtect(enable); })); })); - options->Add(std::make_shared("Language"_i18n, language_items, [](s64& index_out){ + options->Add(std::make_unique("Language"_i18n, language_items, [](s64& index_out){ App::SetLanguage(index_out); }, (s64)App::GetLanguage())); - options->Add(std::make_shared("Misc"_i18n, [](){ + options->Add(std::make_unique("Misc"_i18n, [](){ App::DisplayMiscOptions(); })); - options->Add(std::make_shared("Advanced"_i18n, [](){ + options->Add(std::make_unique("Advanced"_i18n, [](){ App::DisplayAdvancedOptions(); })); }}) ); - m_centre_menu = std::make_shared(); - m_current_menu = m_centre_menu; - + m_centre_menu = std::make_unique(); + m_current_menu = m_centre_menu.get(); std::string left_side_name; m_left_menu = CreateLeftSideMenu(left_side_name); @@ -355,13 +354,13 @@ void MainMenu::OnFocusLost() { m_current_menu->OnFocusLost(); } -void MainMenu::OnLRPress(std::shared_ptr menu, Button b) { +void MainMenu::OnLRPress(MenuBase* menu, Button b) { m_current_menu->OnFocusLost(); - if (m_current_menu == m_centre_menu) { + if (m_current_menu == m_centre_menu.get()) { m_current_menu = menu; RemoveAction(b); } else { - m_current_menu = m_centre_menu; + m_current_menu = m_centre_menu.get(); } AddOnLRPress(); @@ -373,17 +372,17 @@ void MainMenu::OnLRPress(std::shared_ptr menu, Button b) { } void MainMenu::AddOnLRPress() { - if (m_current_menu != m_left_menu) { - const auto label = m_current_menu == m_centre_menu ? m_left_menu->GetShortTitle() : m_centre_menu->GetShortTitle(); + if (m_current_menu != m_left_menu.get()) { + const auto label = m_current_menu == m_centre_menu.get() ? m_left_menu->GetShortTitle() : m_centre_menu->GetShortTitle(); SetAction(Button::L, Action{i18n::get(label), [this]{ - OnLRPress(m_left_menu, Button::L); + OnLRPress(m_left_menu.get(), Button::L); }}); } - if (m_current_menu != m_right_menu) { - const auto label = m_current_menu == m_centre_menu ? m_right_menu->GetShortTitle() : m_centre_menu->GetShortTitle(); + if (m_current_menu != m_right_menu.get()) { + const auto label = m_current_menu == m_centre_menu.get() ? m_right_menu->GetShortTitle() : m_centre_menu->GetShortTitle(); SetAction(Button::R, Action{i18n::get(label), [this]{ - OnLRPress(m_right_menu, Button::R); + OnLRPress(m_right_menu.get(), Button::R); }}); } } diff --git a/sphaira/source/ui/menus/save_menu.cpp b/sphaira/source/ui/menus/save_menu.cpp index cccc4f0..9a5f5ca 100644 --- a/sphaira/source/ui/menus/save_menu.cpp +++ b/sphaira/source/ui/menus/save_menu.cpp @@ -215,15 +215,12 @@ void FakeNacpEntryForSystem(Entry& e) { // fake the nacp entry std::snprintf(e.lang.name, sizeof(e.lang.name), "%s | %016lX", GetSystemSaveName(e.system_save_data_id), e.system_save_data_id); std::strcpy(e.lang.author, "Nintendo"); - e.info.reset(); } -bool LoadControlImage(Entry& e) { - if (!e.image && e.info && !e.info->icon.empty()) { - ON_SCOPE_EXIT(e.info.reset()); - +bool LoadControlImage(Entry& e, title::ThreadResultData* result) { + if (!e.image && result && !result->icon.empty()) { TimeStamp ts; - const auto image = ImageLoadFromMemory(e.info->icon, ImageFlag_JPEG); + const auto image = ImageLoadFromMemory(result->icon, ImageFlag_JPEG); if (!image.data.empty()) { e.image = nvgCreateImageRGBA(App::GetVg(), image.w, image.h, 0, image.data.data()); log_write("\t[image load] time taken: %.2fs %zums\n", ts.GetSecondsD(), ts.GetMs()); @@ -234,8 +231,7 @@ bool LoadControlImage(Entry& e) { return false; } -void LoadResultIntoEntry(Entry& e, const std::shared_ptr& result) { - e.info = result; +void LoadResultIntoEntry(Entry& e, title::ThreadResultData* result) { e.status = result->status; e.lang = result->lang; e.status = result->status; @@ -251,7 +247,7 @@ void LoadControlEntry(Entry& e, bool force_image_load = false) { } if (force_image_load && e.status == title::NacpLoadStatus::Loaded) { - LoadControlImage(e); + LoadControlImage(e, title::Get(e.application_id)); } } @@ -330,8 +326,8 @@ Menu::Menu(u32 flags) : grid::Menu{"Saves"_i18n, flags} { SetPop(); }}), std::make_pair(Button::X, Action{"Options"_i18n, [this](){ - auto options = std::make_shared("Save Options"_i18n, Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + auto options = std::make_unique("Save Options"_i18n, Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); SidebarEntryArray::Items account_items; for (const auto& e : m_accounts) { @@ -347,9 +343,9 @@ Menu::Menu(u32 flags) : grid::Menu{"Saves"_i18n, flags} { data_type_items.emplace_back("Cache"_i18n); data_type_items.emplace_back("System BCAT"_i18n); - options->Add(std::make_shared("Sort By"_i18n, [this](){ - auto options = std::make_shared("Sort Options"_i18n, Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + options->Add(std::make_unique("Sort By"_i18n, [this](){ + auto options = std::make_unique("Sort Options"_i18n, Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); SidebarEntryArray::Items sort_items; sort_items.push_back("Updated"_i18n); @@ -363,36 +359,36 @@ Menu::Menu(u32 flags) : grid::Menu{"Saves"_i18n, flags} { layout_items.push_back("Icon"_i18n); layout_items.push_back("Grid"_i18n); - options->Add(std::make_shared("Sort"_i18n, sort_items, [this](s64& index_out){ + options->Add(std::make_unique("Sort"_i18n, sort_items, [this](s64& index_out){ m_sort.Set(index_out); SortAndFindLastFile(false); }, m_sort.Get())); - options->Add(std::make_shared("Order"_i18n, order_items, [this](s64& index_out){ + options->Add(std::make_unique("Order"_i18n, order_items, [this](s64& index_out){ m_order.Set(index_out); SortAndFindLastFile(false); }, m_order.Get())); - options->Add(std::make_shared("Layout"_i18n, layout_items, [this](s64& index_out){ + options->Add(std::make_unique("Layout"_i18n, layout_items, [this](s64& index_out){ m_layout.Set(index_out); OnLayoutChange(); }, m_layout.Get())); })); - options->Add(std::make_shared("Account"_i18n, account_items, [this](s64& index_out){ + options->Add(std::make_unique("Account"_i18n, account_items, [this](s64& index_out){ m_account_index = index_out; m_dirty = true; App::PopToMenu(); }, m_account_index)); - options->Add(std::make_shared("Data Type"_i18n, data_type_items, [this](s64& index_out){ + options->Add(std::make_unique("Data Type"_i18n, data_type_items, [this](s64& index_out){ m_data_type = index_out; m_dirty = true; App::PopToMenu(); }, m_data_type)); if (m_entries.size()) { - options->Add(std::make_shared("Backup"_i18n, [this](){ + options->Add(std::make_unique("Backup"_i18n, [this](){ std::vector> entries; if (m_selected_count) { for (auto& e : m_entries) { @@ -408,21 +404,21 @@ Menu::Menu(u32 flags) : grid::Menu{"Saves"_i18n, flags} { }, true)); if (m_entries[m_index].save_data_type == FsSaveDataType_Account || m_entries[m_index].save_data_type == FsSaveDataType_Bcat) { - options->Add(std::make_shared("Restore"_i18n, [this](){ + options->Add(std::make_unique("Restore"_i18n, [this](){ RestoreSave(); }, true)); } } - options->Add(std::make_shared("Advanced"_i18n, [this](){ - auto options = std::make_shared("Advanced Options"_i18n, Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + options->Add(std::make_unique("Advanced"_i18n, [this](){ + auto options = std::make_unique("Advanced Options"_i18n, Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); - options->Add(std::make_shared("Auto backup on restore"_i18n, m_auto_backup_on_restore.Get(), [this](bool& v_out){ + options->Add(std::make_unique("Auto backup on restore"_i18n, m_auto_backup_on_restore.Get(), [this](bool& v_out){ m_auto_backup_on_restore.Set(v_out); })); - options->Add(std::make_shared("Compress backup"_i18n, m_compress_save_backup.Get(), [this](bool& v_out){ + options->Add(std::make_unique("Compress backup"_i18n, m_compress_save_backup.Get(), [this](bool& v_out){ m_compress_save_backup.Set(v_out); })); })); @@ -507,14 +503,12 @@ void Menu::Draw(NVGcontext* vg, Theme* theme) { FakeNacpEntryForSystem(e); } } else if (e.status == title::NacpLoadStatus::Progress) { - if (const auto data = title::GetAsync(e.application_id)) { - LoadResultIntoEntry(e, data); - } + LoadResultIntoEntry(e, title::GetAsync(e.application_id)); } // lazy load image if (image_load_count < image_load_max) { - if (LoadControlImage(e)) { + if (LoadControlImage(e, title::GetAsync(e.application_id))) { image_load_count++; } } @@ -683,7 +677,7 @@ void Menu::OnLayoutChange() { void Menu::BackupSaves(std::vector>& entries) { dump::DumpGetLocation("Select backup location"_i18n, dump::DumpLocationFlag_SdCard|dump::DumpLocationFlag_Stdio, [this, entries](const dump::DumpLocation& location){ - App::Push(std::make_shared(0, "Backup"_i18n, "", [this, entries, location](auto pbox) -> Result { + App::Push(std::make_unique(0, "Backup"_i18n, "", [this, entries, location](auto pbox) -> Result { for (auto& e : entries) { // the entry may not have loaded yet. LoadControlEntry(e); @@ -734,7 +728,7 @@ void Menu::RestoreSave() { } if (paths.empty()) { - App::Push(std::make_shared( + App::Push(std::make_unique( "No saves found in "_i18n + fs::AppendPath(fs->Root(), BuildSaveBasePath(m_entries[m_index])).toString(), "OK"_i18n )); @@ -742,7 +736,7 @@ void Menu::RestoreSave() { } const auto title = "Restore save for: "_i18n + m_entries[m_index].GetName(); - App::Push(std::make_shared( + App::Push(std::make_unique( title, items, [this, paths, items, location](auto op_index){ if (!op_index) { return; @@ -751,11 +745,11 @@ void Menu::RestoreSave() { const auto file_name = items[*op_index]; const auto file_path = paths[*op_index]; - App::Push(std::make_shared( + App::Push(std::make_unique( "Are you sure you want to restore "_i18n + file_name + "?", "Back"_i18n, "Restore"_i18n, 0, [this, file_path, location](auto op_index){ if (op_index && *op_index) { - App::Push(std::make_shared(0, "Restore"_i18n, "", [this, file_path, location](auto pbox) -> Result { + App::Push(std::make_unique(0, "Restore"_i18n, "", [this, file_path, location](auto pbox) -> Result { // the entry may not have loaded yet. LoadControlEntry(m_entries[m_index]); @@ -813,8 +807,8 @@ Result Menu::RestoreSaveInternal(ProgressBox* pbox, const Entry& e, const fs::Fs pbox->SetTitle(e.GetName()); if (e.image) { pbox->SetImage(e.image); - } else if (e.info && !e.info->icon.empty()) { - pbox->SetImageDataConst(e.info->icon); + } else if (auto data = title::Get(e.application_id); data && !data->icon.empty()) { + pbox->SetImageDataConst(data->icon); } else { pbox->SetImage(0); } @@ -940,8 +934,8 @@ Result Menu::BackupSaveInternal(ProgressBox* pbox, const dump::DumpLocation& loc pbox->SetTitle(e.GetName()); if (e.image) { pbox->SetImage(e.image); - } else if (e.info && !e.info->icon.empty()) { - pbox->SetImageDataConst(e.info->icon); + } else if (auto data = title::Get(e.application_id); data && !data->icon.empty()) { + pbox->SetImageDataConst(data->icon); } else { pbox->SetImage(0); } diff --git a/sphaira/source/ui/menus/themezer.cpp b/sphaira/source/ui/menus/themezer.cpp index bfb49ef..2ee8669 100644 --- a/sphaira/source/ui/menus/themezer.cpp +++ b/sphaira/source/ui/menus/themezer.cpp @@ -306,7 +306,7 @@ Menu::Menu(u32 flags) : MenuBase{"Themezer"_i18n, flags} { this->SetActions( std::make_pair(Button::A, Action{"Download"_i18n, [this](){ - App::Push(std::make_shared( + App::Push(std::make_unique( "Download theme?"_i18n, "Back"_i18n, "Download"_i18n, 1, [this](auto op_index){ if (op_index && *op_index) { @@ -315,7 +315,7 @@ Menu::Menu(u32 flags) : MenuBase{"Themezer"_i18n, flags} { const auto& entry = page.m_packList[m_index]; const auto url = apiBuildUrlDownloadPack(entry); - App::Push(std::make_shared(entry.themes[0].preview.lazy_image.image, "Downloading "_i18n, entry.details.name, [this, &entry](auto pbox) -> Result { + App::Push(std::make_unique(entry.themes[0].preview.lazy_image.image, "Downloading "_i18n, entry.details.name, [this, &entry](auto pbox) -> Result { return InstallTheme(pbox, entry); }, [this, &entry](Result rc){ App::PushErrorBox(rc, "Failed to download theme"_i18n); @@ -330,8 +330,8 @@ Menu::Menu(u32 flags) : MenuBase{"Themezer"_i18n, flags} { )); }}), std::make_pair(Button::X, Action{"Options"_i18n, [this](){ - auto options = std::make_shared("Themezer Options"_i18n, Sidebar::Side::RIGHT); - ON_SCOPE_EXIT(App::Push(options)); + auto options = std::make_unique("Themezer Options"_i18n, Sidebar::Side::RIGHT); + ON_SCOPE_EXIT(App::Push(std::move(options))); SidebarEntryArray::Items sort_items; sort_items.push_back("Downloads"_i18n); @@ -343,26 +343,26 @@ Menu::Menu(u32 flags) : MenuBase{"Themezer"_i18n, flags} { order_items.push_back("Descending (down)"_i18n); order_items.push_back("Ascending (Up)"_i18n); - options->Add(std::make_shared("Nsfw"_i18n, m_nsfw.Get(), [this](bool& v_out){ + options->Add(std::make_unique("Nsfw"_i18n, m_nsfw.Get(), [this](bool& v_out){ m_nsfw.Set(v_out); InvalidateAllPages(); })); - options->Add(std::make_shared("Sort"_i18n, sort_items, [this, sort_items](s64& index_out){ + options->Add(std::make_unique("Sort"_i18n, sort_items, [this, sort_items](s64& index_out){ if (m_sort.Get() != index_out) { m_sort.Set(index_out); InvalidateAllPages(); } }, m_sort.Get())); - options->Add(std::make_shared("Order"_i18n, order_items, [this, order_items](s64& index_out){ + options->Add(std::make_unique("Order"_i18n, order_items, [this, order_items](s64& index_out){ if (m_order.Get() != index_out) { m_order.Set(index_out); InvalidateAllPages(); } }, m_order.Get())); - options->Add(std::make_shared("Page"_i18n, [this](){ + options->Add(std::make_unique("Page"_i18n, [this](){ s64 out; if (R_SUCCEEDED(swkbd::ShowNumPad(out, "Enter Page Number"_i18n.c_str(), nullptr, -1, 3))) { if (out < m_page_index_max) { @@ -375,7 +375,7 @@ Menu::Menu(u32 flags) : MenuBase{"Themezer"_i18n, flags} { } })); - options->Add(std::make_shared("Search"_i18n, [this](){ + options->Add(std::make_unique("Search"_i18n, [this](){ std::string out; if (R_SUCCEEDED(swkbd::ShowText(out)) && !out.empty()) { m_search = out; diff --git a/sphaira/source/ui/menus/usb_menu.cpp b/sphaira/source/ui/menus/usb_menu.cpp index b4da890..e3fe5f5 100644 --- a/sphaira/source/ui/menus/usb_menu.cpp +++ b/sphaira/source/ui/menus/usb_menu.cpp @@ -68,7 +68,7 @@ Menu::Menu(u32 flags) : MenuBase{"USB"_i18n, flags} { } // 3 second timeout for transfers. - m_usb_source = std::make_shared(TRANSFER_TIMEOUT); + m_usb_source = std::make_unique(TRANSFER_TIMEOUT); if (R_FAILED(m_usb_source->GetOpenResult())) { log_write("usb init open\n"); m_state = State::Failed; @@ -109,13 +109,13 @@ void Menu::Update(Controller* controller, TouchInfo* touch) { log_write("set to progress\n"); m_state = State::Progress; log_write("got connection\n"); - App::Push(std::make_shared(0, "Installing "_i18n, "", [this](auto pbox) -> Result { + App::Push(std::make_unique(0, "Installing "_i18n, "", [this](auto pbox) -> Result { ON_SCOPE_EXIT(m_usb_source->Finished(FINISHED_TIMEOUT)); log_write("inside progress box\n"); for (const auto& file_name : m_names) { m_usb_source->SetFileNameForTranfser(file_name); - const auto rc = yati::InstallFromSource(pbox, m_usb_source, file_name); + const auto rc = yati::InstallFromSource(pbox, m_usb_source.get(), file_name); if (R_FAILED(rc)) { m_usb_source->SignalCancel(); log_write("exiting usb install\n"); diff --git a/sphaira/source/ui/progress_box.cpp b/sphaira/source/ui/progress_box.cpp index 7ef96d9..1751a45 100644 --- a/sphaira/source/ui/progress_box.cpp +++ b/sphaira/source/ui/progress_box.cpp @@ -25,7 +25,7 @@ ProgressBox::ProgressBox(int image, const std::string& action, const std::string } SetAction(Button::B, Action{"Back"_i18n, [this](){ - App::Push(std::make_shared("Are you sure you wish to cancel?"_i18n, "No"_i18n, "Yes"_i18n, 1, [this](auto op_index){ + App::Push(std::make_unique("Are you sure you wish to cancel?"_i18n, "No"_i18n, "Yes"_i18n, 1, [this](auto op_index){ if (op_index && *op_index) { RequestExit(); SetPop(); diff --git a/sphaira/source/ui/sidebar.cpp b/sphaira/source/ui/sidebar.cpp index 8ff05ad..17a1d64 100644 --- a/sphaira/source/ui/sidebar.cpp +++ b/sphaira/source/ui/sidebar.cpp @@ -26,7 +26,7 @@ auto DistanceBetweenY(Vec4 va, Vec4 vb) -> Vec4 { } // namespace SidebarEntryBase::SidebarEntryBase(std::string&& title) -: m_title{std::forward(title)} { +: m_title{std::forward(title)} { } @@ -114,13 +114,13 @@ SidebarEntryArray::SidebarEntryArray(std::string title, Items items, std::string } m_list_callback = [&index, this]() { - App::Push(std::make_shared( + App::Push(std::make_unique( m_title, m_items, index, m_index )); }; // m_callback = [&index, this](auto& idx) { - // App::Push(std::make_shared( + // App::Push(std::make_unique( // m_title, m_items, index, idx // )); // }; @@ -136,13 +136,13 @@ SidebarEntryArray::SidebarEntryArray(std::string title, Items items, Callback cb } SidebarEntryArray::SidebarEntryArray(std::string title, Items items, Callback cb, s64 index) -: SidebarEntryBase{std::forward(title)} +: SidebarEntryBase{std::forward(title)} , m_items{std::move(items)} , m_callback{cb} , m_index{index} { m_list_callback = [this]() { - App::Push(std::make_shared( + App::Push(std::make_unique( m_title, m_items, [this](auto op_idx){ if (op_idx) { m_index = *op_idx; @@ -219,7 +219,7 @@ auto SidebarEntryArray::OnFocusLost() noexcept -> void { } Sidebar::Sidebar(std::string title, Side side, Items&& items) -: Sidebar{std::move(title), "", side, std::forward(items)} { +: Sidebar{std::move(title), "", side, std::forward(items)} { } Sidebar::Sidebar(std::string title, Side side) @@ -230,7 +230,7 @@ Sidebar::Sidebar(std::string title, std::string sub, Side side, Items&& items) : m_title{std::move(title)} , m_sub{std::move(sub)} , m_side{side} -, m_items{std::forward(items)} { +, m_items{std::forward(items)} { switch (m_side) { case Side::LEFT: SetPos(Vec4{0.f, 0.f, 450.f, 720.f}); @@ -313,8 +313,8 @@ auto Sidebar::OnFocusLost() noexcept -> void { SetHidden(true); } -void Sidebar::Add(std::shared_ptr entry) { - m_items.emplace_back(entry); +void Sidebar::Add(std::unique_ptr&& entry) { + m_items.emplace_back(std::forward(entry)); m_items.back()->SetPos(m_base_pos); // give focus to first entry. diff --git a/sphaira/source/yati/container/xci.cpp b/sphaira/source/yati/container/xci.cpp index 271b08d..469b962 100644 --- a/sphaira/source/yati/container/xci.cpp +++ b/sphaira/source/yati/container/xci.cpp @@ -62,12 +62,12 @@ Result Hfs0GetPartition(source::Base* source, s64 off, Hfs0& out) { Result Xci::GetCollections(Collections& out) { Hfs0 root{}; - R_TRY(Hfs0GetPartition(m_source.get(), HFS0_HEADER_OFFSET, root)); + R_TRY(Hfs0GetPartition(m_source, HFS0_HEADER_OFFSET, root)); for (u32 i = 0; i < root.header.total_files; i++) { if (root.string_table[i] == "secure") { Hfs0 secure{}; - R_TRY(Hfs0GetPartition(m_source.get(), root.data_offset + root.file_table[i].data_offset, secure)); + R_TRY(Hfs0GetPartition(m_source, root.data_offset + root.file_table[i].data_offset, secure)); for (u32 i = 0; i < secure.header.total_files; i++) { CollectionEntry entry; diff --git a/sphaira/source/yati/yati.cpp b/sphaira/source/yati/yati.cpp index bea5ca0..013e57f 100644 --- a/sphaira/source/yati/yati.cpp +++ b/sphaira/source/yati/yati.cpp @@ -252,7 +252,7 @@ struct ThreadData { }; struct Yati { - Yati(ui::ProgressBox*, std::shared_ptr); + Yati(ui::ProgressBox*, source::Base*); ~Yati(); Result Setup(const ConfigOverride& override); @@ -274,7 +274,7 @@ struct Yati { // private: ui::ProgressBox* pbox{}; - std::shared_ptr source{}; + source::Base* source{}; // for all content storages NcmContentStorage ncm_cs[2]{}; @@ -793,7 +793,7 @@ struct BufHelper { u64 offset{}; }; -Yati::Yati(ui::ProgressBox* _pbox, std::shared_ptr _source) : pbox{_pbox}, source{_source} { +Yati::Yati(ui::ProgressBox* _pbox, source::Base* _source) : pbox{_pbox}, source{_source} { App::SetAutoSleepDisabled(true); } @@ -1293,7 +1293,7 @@ Result Yati::RegisterNcasAndPushRecord(const CnmtCollection& cnmt, u32 latest_ve R_SUCCEED(); } -Result InstallInternal(ui::ProgressBox* pbox, std::shared_ptr source, const container::Collections& collections, const ConfigOverride& override) { +Result InstallInternal(ui::ProgressBox* pbox, source::Base* source, const container::Collections& collections, const ConfigOverride& override) { auto yati = std::make_unique(pbox, source); R_TRY(yati->Setup(override)); @@ -1343,7 +1343,7 @@ Result InstallInternal(ui::ProgressBox* pbox, std::shared_ptr sour R_SUCCEED(); } -Result InstallInternalStream(ui::ProgressBox* pbox, std::shared_ptr source, container::Collections collections, const ConfigOverride& override) { +Result InstallInternalStream(ui::ProgressBox* pbox, source::Base* source, container::Collections collections, const ConfigOverride& override) { auto yati = std::make_unique(pbox, source); R_TRY(yati->Setup(override)); @@ -1442,30 +1442,33 @@ Result InstallInternalStream(ui::ProgressBox* pbox, std::shared_ptr(fs, path), path, override); - // return InstallFromSource(pbox, std::make_shared(fs, path), path, override); + auto source = std::make_unique(fs, path); + // auto source = std::make_unique(fs, path); // enable for testing. + return InstallFromSource(pbox, source.get(), path, override); } -Result InstallFromSource(ui::ProgressBox* pbox, std::shared_ptr source, const fs::FsPath& path, const ConfigOverride& override) { +Result InstallFromSource(ui::ProgressBox* pbox, source::Base* source, const fs::FsPath& path, const ConfigOverride& override) { const auto ext = std::strrchr(path.s, '.'); R_UNLESS(ext, Result_YatiContainerNotFound); + std::unique_ptr container; if (!strcasecmp(ext, ".nsp") || !strcasecmp(ext, ".nsz")) { - return InstallFromContainer(pbox, std::make_unique(source), override); + container = std::make_unique(source); } else if (!strcasecmp(ext, ".xci") || !strcasecmp(ext, ".xcz")) { - return InstallFromContainer(pbox, std::make_unique(source), override); + container = std::make_unique(source); } - R_THROW(Result_YatiContainerNotFound); + R_UNLESS(container, Result_YatiContainerNotFound); + return InstallFromContainer(pbox, container.get(), override); } -Result InstallFromContainer(ui::ProgressBox* pbox, std::shared_ptr container, const ConfigOverride& override) { +Result InstallFromContainer(ui::ProgressBox* pbox, container::Base* container, const ConfigOverride& override) { container::Collections collections; R_TRY(container->GetCollections(collections)); return InstallFromCollections(pbox, container->GetSource(), collections); } -Result InstallFromCollections(ui::ProgressBox* pbox, std::shared_ptr source, const container::Collections& collections, const ConfigOverride& override) { +Result InstallFromCollections(ui::ProgressBox* pbox, source::Base* source, const container::Collections& collections, const ConfigOverride& override) { if (source->IsStream()) { return InstallInternalStream(pbox, source, collections, override); } else {