summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2019-10-11 23:16:05 +0200
committerGravatar Nikias Bassen2019-10-11 23:16:05 +0200
commitbd85a1bd5a8dd8cce74a9235011f866402a23c59 (patch)
tree7b46fcd11448c4b118cc6fcf7ddc0379e9c34b60
parent767fcceaeb456f5e281a6bd1b3f51713e4989293 (diff)
downloadidevicerestore-bd85a1bd5a8dd8cce74a9235011f866402a23c59.tar.gz
idevicerestore-bd85a1bd5a8dd8cce74a9235011f866402a23c59.tar.bz2
win32: Use signal on win32 but make sure user input can be cancelled with ctrl+c
also added ESC key as a fallback cancel method.
-rw-r--r--src/common.c10
-rw-r--r--src/idevicerestore.c6
2 files changed, 14 insertions, 2 deletions
diff --git a/src/common.c b/src/common.c
index f9377ba..a54ae6f 100644
--- a/src/common.c
+++ b/src/common.c
@@ -506,7 +506,9 @@ char* realpath(const char *filename, char *resolved_name)
#ifdef WIN32
#define BS_CC '\b'
-#define my_getch getch
+#define CTRL_C_CC 0x03
+#define ESC_CC 0x1B
+#define my_getch _getch
#else
#define BS_CC 0x7f
static int my_getch(void)
@@ -541,6 +543,12 @@ void get_user_input(char *buf, int maxlen, int secure)
len--;
}
}
+#ifdef WIN32
+ else if (c == CTRL_C_CC || c == ESC_CC) {
+ c = -1;
+ break;
+ }
+#endif
}
if (c < 0) {
len = 0;
diff --git a/src/idevicerestore.c b/src/idevicerestore.c
index f96fc61..7c02eda 100644
--- a/src/idevicerestore.c
+++ b/src/idevicerestore.c
@@ -1499,12 +1499,16 @@ int main(int argc, char* argv[]) {
idevicerestore_client = client;
+#ifdef WIN32
+ signal(SIGINT, handle_signal);
+ signal(SIGTERM, handle_signal);
+ signal(SIGABRT, handle_signal);
+#else
struct sigaction sa;
memset(&sa, 0, sizeof(struct sigaction));
sa.sa_handler = handle_signal;
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
-#ifndef WIN32
sigaction(SIGQUIT, &sa, NULL);
sa.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &sa, NULL);