mirror of
https://github.com/palera1n/palera1n.git
synced 2026-10-21 01:37:02 +02:00
refactor: migrate to C++11
This commit is contained in:
7 files changed
+35
-28
No files matched your search
+1
-1
@@ -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")
|
||||
|
||||
+19
-15
@@ -113,14 +113,15 @@ void retain_handle(const hotplug_handle_t& h) {
|
||||
#endif
|
||||
}
|
||||
|
||||
template<auto FreeFn>
|
||||
template<typename T, void (*FreeFn)(T*)>
|
||||
struct Releaser {
|
||||
template<typename T>
|
||||
void operator()(T* ptr) const { if (ptr) FreeFn(ptr); }
|
||||
void operator()(T* ptr) const {
|
||||
if (ptr) FreeFn(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, auto FreeFn>
|
||||
using unique_c_ptr = std::unique_ptr<T, Releaser<FreeFn>>;
|
||||
template<typename T, void (*FreeFn)(T*)>
|
||||
using unique_c_ptr = std::unique_ptr<T, Releaser<T, FreeFn>>;
|
||||
|
||||
std::mutex g_mutex;
|
||||
std::vector<DeviceStateCallback> g_callbacks;
|
||||
@@ -168,7 +169,7 @@ void publish_state() {
|
||||
std::vector<DeviceStateCallback> callbacks;
|
||||
DeviceState state;
|
||||
{
|
||||
std::lock_guard lock(g_mutex);
|
||||
std::lock_guard<std::mutex> 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<std::mutex> 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<std::mutex> 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<const uint64_t, ManagedDevice>& 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<std::mutex> 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<IdeviceFFI::UsbmuxdDevice>(std::move(dev));
|
||||
m.usbmuxd_device = std::unique_ptr<IdeviceFFI::UsbmuxdDevice>(
|
||||
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<std::mutex> 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<std::mutex> 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<std::mutex> lock(g_mutex);
|
||||
if (g_activeEcid == 0) return;
|
||||
|
||||
auto it = g_devices.find(g_activeEcid);
|
||||
|
||||
@@ -325,7 +325,7 @@ static void hotplug_polling_worker() {
|
||||
active_paths.insert(path);
|
||||
|
||||
if (gConnectedDevices.find(path) == gConnectedDevices.end()) {
|
||||
auto ctx = std::make_unique<PersistentDeviceContext>();
|
||||
auto ctx = std::unique_ptr<PersistentDeviceContext>(new PersistentDeviceContext());
|
||||
ctx->device = dev;
|
||||
|
||||
if (liteusb_open_handle(&ctx->device, &ctx->session) == LITEUSB_ERR_SUCCESS) {
|
||||
|
||||
+6
-6
@@ -144,11 +144,11 @@ TuiFrame::~TuiFrame() {
|
||||
|
||||
void TuiFrame::InitPanels() {
|
||||
m_panels.resize(PANEL_COUNT);
|
||||
m_panels[PANEL_MAIN] = std::make_unique<TuiMainPanel>(this);
|
||||
m_panels[PANEL_OPTIONS] = std::make_unique<TuiSettingsPanel>(this);
|
||||
m_panels[PANEL_START_1] = std::make_unique<TuiRecoveryPanel>(this);
|
||||
m_panels[PANEL_START_2] = std::make_unique<TuiDfuPanel>(this);
|
||||
m_panels[PANEL_FINAL] = std::make_unique<TuiExploitPanel>(this);
|
||||
m_panels[PANEL_MAIN] = std::unique_ptr<TuiMainPanel>(new TuiMainPanel(this));
|
||||
m_panels[PANEL_OPTIONS] = std::unique_ptr<TuiSettingsPanel>(new TuiSettingsPanel(this));
|
||||
m_panels[PANEL_START_1] = std::unique_ptr<TuiRecoveryPanel>(new TuiRecoveryPanel(this));
|
||||
m_panels[PANEL_START_2] = std::unique_ptr<TuiDfuPanel>(new TuiDfuPanel(this));
|
||||
m_panels[PANEL_FINAL] = std::unique_ptr<TuiExploitPanel>(new TuiExploitPanel(this));
|
||||
}
|
||||
|
||||
void TuiFrame::InitDeviceEventListeners() {
|
||||
@@ -213,7 +213,7 @@ void TuiFrame::DrawUi() {
|
||||
|
||||
std::vector<std::string> labels;
|
||||
labels.reserve(static_cast<size_t>(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));
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<size_t>(bar_width), '-');
|
||||
for (int i = 0; i < filled; ++i) {
|
||||
bar[static_cast<size_t>(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<std::mutex> 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()
|
||||
|
||||
@@ -57,7 +57,7 @@ private:
|
||||
std::mutex m_status_mutex;
|
||||
std::string m_status_text;
|
||||
int m_progress = 0;
|
||||
std::atomic<bool> m_is_exploiting = false;
|
||||
std::atomic<bool> m_is_exploiting{false};
|
||||
};
|
||||
|
||||
#endif // TUI_EXPLOIT_PANEL_HPP
|
||||
|
||||
Reference in new issue
Block a user