diff --git a/programs/cmd/Cs.rc b/programs/cmd/Cs.rc index d452bd874a0..390d875803f 100644 --- a/programs/cmd/Cs.rc +++ b/programs/cmd/Cs.rc @@ -230,4 +230,8 @@ VER\t\tZobraz VOL\t\tUke jmenovku disku\n\ EXIT\t\tUkon CMD\n\n\ Zadejte HELP pro podrobnj informace o nkterm z ve uvedench pkaz\n" + + WCMD_CONFIRM, "Are you sure" + WCMD_YES, "Y" + WCMD_NO, "N" } diff --git a/programs/cmd/De.rc b/programs/cmd/De.rc index 4fd40c8807d..50a69bcdb82 100644 --- a/programs/cmd/De.rc +++ b/programs/cmd/De.rc @@ -247,4 +247,8 @@ VOL\t\tZeigt die Bezeichnung eines Laufwerkes an\n\ EXIT\t\tBeendet den CMD\n\n\ Geben Sie HELP ein, damit Sie weitere Informationen fr einen der\n\ obigen Befehle erhalten.\n" + + WCMD_CONFIRM, "Are you sure" + WCMD_YES, "Y" + WCMD_NO, "N" } diff --git a/programs/cmd/En.rc b/programs/cmd/En.rc index 1a8877d2a58..10891a5e5be 100644 --- a/programs/cmd/En.rc +++ b/programs/cmd/En.rc @@ -234,4 +234,8 @@ VER\t\tShow the current version of CMD\n\ VOL\t\tShow the volume label of a disk device\n\ EXIT\t\tClose down CMD\n\n\ Enter HELP for further information on any of the above commands\n" + + WCMD_CONFIRM, "Are you sure" + WCMD_YES, "Y" + WCMD_NO, "N" } diff --git a/programs/cmd/Es.rc b/programs/cmd/Es.rc index 279ab716a62..482200789e8 100644 --- a/programs/cmd/Es.rc +++ b/programs/cmd/Es.rc @@ -242,4 +242,8 @@ VER\t\tMostrar la versi VOL\t\tMostrar la etiqueta de volumen de un dispositivo de disco\n\ EXIT\t\tConcluir CMD\n\n\ Introduzca HELP para ms informacin sobre cualquiera de los comandos\nde arriba\n" + + WCMD_CONFIRM, "Are you sure" + WCMD_YES, "Y" + WCMD_NO, "N" } diff --git a/programs/cmd/Fr.rc b/programs/cmd/Fr.rc index cc65abd7e3f..78f206d0a29 100644 --- a/programs/cmd/Fr.rc +++ b/programs/cmd/Fr.rc @@ -224,4 +224,8 @@ VER\t\tAffiche la version de cmd actuellement en m VOL\t\tAffiche le nom de volume d'un lecteur de disque\n\ EXIT\t\tQuitte CMD\n\n\ Entrez HELP pour plus d'informations sur les commandes ci-dessus\n" + + WCMD_CONFIRM, "Are you sure" + WCMD_YES, "Y" + WCMD_NO, "N" } diff --git a/programs/cmd/Ja.rc b/programs/cmd/Ja.rc index 3e4f629e2f3..1937480137a 100644 --- a/programs/cmd/Ja.rc +++ b/programs/cmd/Ja.rc @@ -228,4 +228,8 @@ VER\t\tCMD VOL\t\tfBXNfoCX̃{[x\\n\ EXIT\t\tCMDI\n\n\ L̃R}hɊւڍׂ\ɂ HELP Ɠ͂ĉB\n" + + WCMD_CONFIRM, "Are you sure" + WCMD_YES, "Y" + WCMD_NO, "N" } diff --git a/programs/cmd/Ko.rc b/programs/cmd/Ko.rc index 32c6b51752a..fa6b83fe816 100644 --- a/programs/cmd/Ko.rc +++ b/programs/cmd/Ko.rc @@ -219,4 +219,8 @@ VER\t\tCMD VOL\t\tũ ġ ҷ ֱ\n\ EXIT\t\tCMD ݱ\n\n\ HELP <> ġ \n" + + WCMD_CONFIRM, "Are you sure" + WCMD_YES, "Y" + WCMD_NO, "N" } diff --git a/programs/cmd/Nl.rc b/programs/cmd/Nl.rc index da09b09abab..8e8d1c450f0 100644 --- a/programs/cmd/Nl.rc +++ b/programs/cmd/Nl.rc @@ -227,4 +227,8 @@ VER\t\tToon de versie van CMD\n\ VOL\t\tToon het label van een schijf\n\ EXIT\t\tSluit CMD af\n\n\ type HELP voor meer informatie over bovengenoemde opdrachten\n" + + WCMD_CONFIRM, "Are you sure" + WCMD_YES, "Y" + WCMD_NO, "N" } diff --git a/programs/cmd/No.rc b/programs/cmd/No.rc index 2b01c4788f5..c98dd15269c 100644 --- a/programs/cmd/No.rc +++ b/programs/cmd/No.rc @@ -225,4 +225,8 @@ VER\t\tViser CMDs versjonnummer\n\ VOL\t\tViser volumnavnet til en stasjon\n\ EXIT\t\tAvslutter CMD\n\n\ Skriv HELP for mer informasjon om kommandoene ovenfor\n" + + WCMD_CONFIRM, "Are you sure" + WCMD_YES, "Y" + WCMD_NO, "N" } diff --git a/programs/cmd/Pl.rc b/programs/cmd/Pl.rc index b5a60eb8e99..5b49433d9d3 100644 --- a/programs/cmd/Pl.rc +++ b/programs/cmd/Pl.rc @@ -221,4 +221,8 @@ VER\t\tWy VOL\t\tWywietla etykiet dysku\n\ EXIT\t\tWycza CMD\n\n\ Wpisz HELP dla dokadniejszych informacji o komendzie\n" + + WCMD_CONFIRM, "Are you sure" + WCMD_YES, "Y" + WCMD_NO, "N" } diff --git a/programs/cmd/Pt.rc b/programs/cmd/Pt.rc index 480e3d99d55..13a9b4ccbf0 100644 --- a/programs/cmd/Pt.rc +++ b/programs/cmd/Pt.rc @@ -434,4 +434,8 @@ VER\t\tMostra a vers VOL\t\tMostra o rtulo do volume de uma unidade de disco\n\ EXIT\t\tFecha o CMD\n\n\ Digite HELP para mais informaes sobre alguns dos comandos acima\n" + + WCMD_CONFIRM, "Are you sure" + WCMD_YES, "Y" + WCMD_NO, "N" } diff --git a/programs/cmd/Ru.rc b/programs/cmd/Ru.rc index 61ab8ef9be8..411810226aa 100644 --- a/programs/cmd/Ru.rc +++ b/programs/cmd/Ru.rc @@ -225,4 +225,8 @@ VER\t\t VOL\t\t \n\ EXIT\t\t WCMD\n\n\ HELP <> .\n" + + WCMD_CONFIRM, "Are you sure" + WCMD_YES, "Y" + WCMD_NO, "N" } diff --git a/programs/cmd/Si.rc b/programs/cmd/Si.rc index a8fbb57c4c2..7623bebf83a 100644 --- a/programs/cmd/Si.rc +++ b/programs/cmd/Si.rc @@ -226,4 +226,8 @@ VER\t\tShow the current version of CMD\n\ VOL\t\tShow the volume label of a disk device\n\ EXIT\t\tClose down CMD\n\n\ Enter HELP for further information on any of the above commands\n" + + WCMD_CONFIRM, "Are you sure" + WCMD_YES, "Y" + WCMD_NO, "N" } diff --git a/programs/cmd/Tr.rc b/programs/cmd/Tr.rc index 40c9fc2801e..bdecde38ef8 100644 --- a/programs/cmd/Tr.rc +++ b/programs/cmd/Tr.rc @@ -228,4 +228,8 @@ VER\t\tGe VOL\t\tDisk aygtnn blm etiketini gster\n\ EXIT\t\tCMD'yi kapat\n\n\ Yukardaki komutlar hakknda daha fazla bilgi iin HELP girin\n" + + WCMD_CONFIRM, "Are you sure" + WCMD_YES, "Y" + WCMD_NO, "N" } diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index a1d11542919..500c27e4149 100644 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -643,8 +643,22 @@ void WCMD_remove_dir (void) { /* Otherwise use ShFileOp to recursively remove a directory */ } else { - /* Do the delete */ SHFILEOPSTRUCT lpDir; + + /* Ask first */ + if (strstr (quals, "/Q") == NULL) { + BOOL ok; + char question[MAXSTRING]; + + /* Ask for confirmation */ + sprintf(question, "%s, ", param1); + ok = WCMD_ask_confirm(question); + + /* Abort if answer is 'N' */ + if (!ok) return; + } + + /* Do the delete */ lpDir.hwnd = NULL; lpDir.pTo = NULL; lpDir.pFrom = param1; @@ -786,7 +800,7 @@ void WCMD_endlocal (void) { } LocalFree (old); FreeEnvironmentStringsW (env); - + /* restore old environment */ env = temp->strings; len = 0; @@ -1260,3 +1274,43 @@ void WCMD_exit (void) { ExitProcess(rc); } } + +/************************************************************************** + * WCMD_ask_confirm + * + * Issue a message and ask 'Are you sure (Y/N)', waiting on a valid + * answer. + * + * Returns True if Y answer is selected + * + */ +BOOL WCMD_ask_confirm (char *message) { + + char msgbuffer[MAXSTRING]; + char Ybuffer[MAXSTRING]; + char Nbuffer[MAXSTRING]; + char answer[MAX_PATH] = ""; + DWORD count = 0; + + /* Load the translated 'Are you sure', plus valid answers */ + LoadString (hinst, WCMD_CONFIRM, msgbuffer, sizeof(msgbuffer)); + LoadString (hinst, WCMD_YES, Ybuffer, sizeof(Ybuffer)); + LoadString (hinst, WCMD_NO, Nbuffer, sizeof(Nbuffer)); + + /* Loop waiting on a Y or N */ + while (answer[0] != Ybuffer[0] && answer[0] != Nbuffer[0]) { + WCMD_output_asis (message); + WCMD_output_asis (msgbuffer); + WCMD_output_asis (" ("); + WCMD_output_asis (Ybuffer); + WCMD_output_asis ("/"); + WCMD_output_asis (Nbuffer); + WCMD_output_asis (")?"); + ReadFile (GetStdHandle(STD_INPUT_HANDLE), answer, sizeof(answer), + &count, NULL); + answer[0] = toupper(answer[0]); + } + + /* Return the answer */ + return (answer[0] == Ybuffer[0]); +} diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h index d9127bf3179..f27824ae493 100644 --- a/programs/cmd/wcmd.h +++ b/programs/cmd/wcmd.h @@ -80,6 +80,7 @@ char *WCMD_strtrim_leading_spaces (char *string); void WCMD_strtrim_trailing_spaces (char *string); void WCMD_opt_s_strip_quotes(char *cmd); void WCMD_HandleTildaModifiers(char **start, char *forVariable); +BOOL WCMD_ask_confirm (char *message); /* Data structure to hold context when executing batch files */ @@ -154,5 +155,10 @@ extern const char newline[]; extern const char version_string[]; extern const char anykey[]; +/* Translated messages */ +#define WCMD_CONFIRM 1001 +#define WCMD_YES 1002 +#define WCMD_NO 1003 + /* msdn specified max for Win XP */ #define MAXSTRING 8192