diff --git a/CMakeLists.txt b/CMakeLists.txt index 769a75f..a9abfbc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ project(palera1n VERSION 3.0) include(FetchContent) include(ExternalProject) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED True) if(NOT IOS) set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11") diff --git a/src/events/event.cpp b/src/events/event.cpp index e739197..755b9b7 100644 --- a/src/events/event.cpp +++ b/src/events/event.cpp @@ -113,14 +113,15 @@ void retain_handle(const hotplug_handle_t& h) { #endif } -template +template struct Releaser { - template - void operator()(T* ptr) const { if (ptr) FreeFn(ptr); } + void operator()(T* ptr) const { + if (ptr) FreeFn(ptr); + } }; -template -using unique_c_ptr = std::unique_ptr>; +template +using unique_c_ptr = std::unique_ptr>; std::mutex g_mutex; std::vector g_callbacks; @@ -168,7 +169,7 @@ void publish_state() { std::vector callbacks; DeviceState state; { - std::lock_guard lock(g_mutex); + std::lock_guard lock(g_mutex); callbacks = g_callbacks; state = build_public_state_locked(); } @@ -255,7 +256,7 @@ static void handle_other_add(hotplug_handle_t handle, DeviceMode mode, bool supp if (ecid == 0) return; { - std::lock_guard lock(g_mutex); + std::lock_guard lock(g_mutex); ManagedDevice& m = g_devices[ecid]; release_handle(m.handle); @@ -279,9 +280,9 @@ static void handle_other_add(hotplug_handle_t handle, DeviceMode mode, bool supp static void remove_device(platform_service_t service, DeviceMode mode, uint32_t target_device_id = 0, const std::string& target_udid = "") { bool changed = false; { - std::lock_guard lock(g_mutex); + std::lock_guard lock(g_mutex); - auto it = std::find_if(g_devices.begin(), g_devices.end(), [&](const auto& pair) { + auto it = std::find_if(g_devices.begin(), g_devices.end(), [&](const std::pair& pair) { if (service != IO_OBJECT_NULL) { #if !defined(__APPLE__) && defined(WITH_CIDERRAIN) return pair.second.handle.handle == service; @@ -302,7 +303,8 @@ static void remove_device(platform_service_t service, DeviceMode mode, uint32_t }); if (it != g_devices.end()) { - auto& [ecid, m] = *it; + auto& ecid = it->first; + auto& m = it->second; if (mode == DeviceMode::Normal) { m.normalPresent = false; @@ -377,7 +379,7 @@ void usbmuxd_listener_worker() { known_normal_devices[id] = dev.get_udid().unwrap(); { - std::lock_guard lock(g_mutex); + std::lock_guard lock(g_mutex); ManagedDevice& m = g_devices[discovered.ecid]; release_handle(m.handle); @@ -388,7 +390,9 @@ void usbmuxd_listener_worker() { m.dfuPresent = false; m.device_id = id; - m.usbmuxd_device = std::make_unique(std::move(dev)); + m.usbmuxd_device = std::unique_ptr( + new IdeviceFFI::UsbmuxdDevice(std::move(dev)) + ); } publish_state(); } @@ -429,7 +433,7 @@ void register_device_state_callback(DeviceStateCallback cb) { if (!cb) return; DeviceState snapshot; { - std::lock_guard lock(g_mutex); + std::lock_guard lock(g_mutex); g_callbacks.push_back(cb); snapshot = build_public_state_locked(); } @@ -448,7 +452,7 @@ bool enter_recovery() { std::string udid_str = ""; { - std::lock_guard lock(g_mutex); + std::lock_guard lock(g_mutex); if (g_activeEcid == 0) return false; auto it = g_devices.find(g_activeEcid); @@ -479,7 +483,7 @@ void exit_recovery() { hotplug_handle_t handle; std::memset(&handle, 0, sizeof(handle)); { - std::lock_guard lock(g_mutex); + std::lock_guard lock(g_mutex); if (g_activeEcid == 0) return; auto it = g_devices.find(g_activeEcid); diff --git a/src/events/ra1ncovery/hotplug.cpp b/src/events/ra1ncovery/hotplug.cpp index 0769ecc..5dfa8c9 100644 --- a/src/events/ra1ncovery/hotplug.cpp +++ b/src/events/ra1ncovery/hotplug.cpp @@ -325,7 +325,7 @@ static void hotplug_polling_worker() { active_paths.insert(path); if (gConnectedDevices.find(path) == gConnectedDevices.end()) { - auto ctx = std::make_unique(); + auto ctx = std::unique_ptr(new PersistentDeviceContext()); ctx->device = dev; if (liteusb_open_handle(&ctx->device, &ctx->session) == LITEUSB_ERR_SUCCESS) { diff --git a/src/tui/Tui.cpp b/src/tui/Tui.cpp index 8d9b5d3..2b71216 100644 --- a/src/tui/Tui.cpp +++ b/src/tui/Tui.cpp @@ -144,11 +144,11 @@ TuiFrame::~TuiFrame() { void TuiFrame::InitPanels() { m_panels.resize(PANEL_COUNT); - m_panels[PANEL_MAIN] = std::make_unique(this); - m_panels[PANEL_OPTIONS] = std::make_unique(this); - m_panels[PANEL_START_1] = std::make_unique(this); - m_panels[PANEL_START_2] = std::make_unique(this); - m_panels[PANEL_FINAL] = std::make_unique(this); + m_panels[PANEL_MAIN] = std::unique_ptr(new TuiMainPanel(this)); + m_panels[PANEL_OPTIONS] = std::unique_ptr(new TuiSettingsPanel(this)); + m_panels[PANEL_START_1] = std::unique_ptr(new TuiRecoveryPanel(this)); + m_panels[PANEL_START_2] = std::unique_ptr(new TuiDfuPanel(this)); + m_panels[PANEL_FINAL] = std::unique_ptr(new TuiExploitPanel(this)); } void TuiFrame::InitDeviceEventListeners() { @@ -213,7 +213,7 @@ void TuiFrame::DrawUi() { std::vector labels; labels.reserve(static_cast(btn_cnt)); - const int button_width = std::clamp(SIDEBAR_BUTTON_WIDTH, 8, content_width); + const int button_width = std::min(std::max(SIDEBAR_BUTTON_WIDTH, 8), content_width); for (int i = 0; i < btn_cnt; ++i) { labels.push_back(format_sidebar_button_label(panel_buttons[i], button_width)); diff --git a/src/tui/TuiDfuPanel.cpp b/src/tui/TuiDfuPanel.cpp index d690cc9..d0f953b 100644 --- a/src/tui/TuiDfuPanel.cpp +++ b/src/tui/TuiDfuPanel.cpp @@ -185,7 +185,10 @@ void TuiDfuPanel::draw_sequence_buttons(int button_x, int button_y, int button_w const int mapped_x = button_x + scale_coord(btn.x, kDfuPanelCoordinateWidth, button_width); const int mapped_y = button_y + scale_coord(btn.y, kDfuButtonCoordinateMaxY, button_height); - const int label_x = std::clamp(mapped_x, button_x, button_x + std::max(0, button_width - 1)); + const int label_x = std::min( + std::max(mapped_x, button_x), + button_x + std::max(0, button_width - 1) + ); const bool is_active = active_buttons.find(btn.id) != active_buttons.end(); if (is_active) { diff --git a/src/tui/TuiExploitPanel.cpp b/src/tui/TuiExploitPanel.cpp index ec3b148..1523484 100644 --- a/src/tui/TuiExploitPanel.cpp +++ b/src/tui/TuiExploitPanel.cpp @@ -74,13 +74,13 @@ void TuiExploitPanel::draw(int sy, int sx, int selected) { mvprintw(sy + 8, content_x, "%.*s", kExploitContentWidth, status_text.empty() ? stage_to_string(STAGE_RESET) : status_text.c_str()); const int bar_width = 50; - const int filled = (std::clamp(progress, 0, 100) * bar_width) / 100; + const int filled = (std::min(std::max(progress, 0), 100) * bar_width) / 100; std::string bar(static_cast(bar_width), '-'); for (int i = 0; i < filled; ++i) { bar[static_cast(i)] = '#'; } - mvprintw(sy + 10, sx + 2, "[%s] %3d%%", bar.c_str(), std::clamp(progress, 0, 100)); + mvprintw(sy + 10, sx + 2, "[%s] %3d%%", bar.c_str(), std::min(std::max(progress, 0), 100)); } void TuiExploitPanel::handle_enter(int selected, int sy, int sx) { @@ -105,7 +105,7 @@ bool TuiExploitPanel::is_button_enabled(int btn_idx) const { void TuiExploitPanel::set_status(const std::string& status, int progress) { std::lock_guard lock(m_status_mutex); m_status_text = status; - m_progress = std::clamp(progress, 0, 100); + m_progress = std::min(std::max(progress, 0), 100); } void TuiExploitPanel::exploit() diff --git a/src/tui/TuiExploitPanel.hpp b/src/tui/TuiExploitPanel.hpp index d224740..966f784 100644 --- a/src/tui/TuiExploitPanel.hpp +++ b/src/tui/TuiExploitPanel.hpp @@ -57,7 +57,7 @@ private: std::mutex m_status_mutex; std::string m_status_text; int m_progress = 0; - std::atomic m_is_exploiting = false; + std::atomic m_is_exploiting{false}; }; #endif // TUI_EXPLOIT_PANEL_HPP