cmd.exe: Add ASSOC command.

This commit is contained in:
Jason Edmeades 2007-03-04 22:34:45 +00:00 committed by Alexandre Julliard
parent 8049ae1af8
commit 79aa1a009f
18 changed files with 183 additions and 3 deletions

View File

@ -234,4 +234,5 @@ Zadejte HELP <p
WCMD_CONFIRM, "Are you sure"
WCMD_YES, "Y"
WCMD_NO, "N"
WCMD_NOASSOC, "File association missing for extension %s\n"
}

View File

@ -251,4 +251,5 @@ obigen Befehle erhalten.\n"
WCMD_CONFIRM, "Are you sure"
WCMD_YES, "Y"
WCMD_NO, "N"
WCMD_NOASSOC, "File association missing for extension %s\n"
}

View File

@ -238,4 +238,5 @@ Enter HELP <command> for further information on any of the above commands\n"
WCMD_CONFIRM, "Are you sure"
WCMD_YES, "Y"
WCMD_NO, "N"
WCMD_NOASSOC, "File association missing for extension %s\n"
}

View File

@ -246,4 +246,5 @@ Introduzca HELP <comando> para m
WCMD_CONFIRM, "Are you sure"
WCMD_YES, "Y"
WCMD_NO, "N"
WCMD_NOASSOC, "File association missing for extension %s\n"
}

View File

@ -228,4 +228,5 @@ Entrez HELP <commande> pour plus d'informations sur les commandes ci-dessus\n"
WCMD_CONFIRM, "Are you sure"
WCMD_YES, "Y"
WCMD_NO, "N"
WCMD_NOASSOC, "File association missing for extension %s\n"
}

View File

@ -232,4 +232,5 @@ EXIT\t\tCMD
WCMD_CONFIRM, "Are you sure"
WCMD_YES, "Y"
WCMD_NO, "N"
WCMD_NOASSOC, "File association missing for extension %s\n"
}

View File

@ -223,4 +223,5 @@ HELP <
WCMD_CONFIRM, "Are you sure"
WCMD_YES, "Y"
WCMD_NO, "N"
WCMD_NOASSOC, "File association missing for extension %s\n"
}

View File

@ -4,7 +4,7 @@ SRCDIR = @srcdir@
VPATH = @srcdir@
MODULE = cmd.exe
APPMODE = -mconsole
IMPORTS = shell32 user32 kernel32
IMPORTS = shell32 user32 advapi32 kernel32
C_SRCS = \
batch.c \

View File

@ -231,4 +231,5 @@ type HELP <opdracht> voor meer informatie over bovengenoemde opdrachten\n"
WCMD_CONFIRM, "Are you sure"
WCMD_YES, "Y"
WCMD_NO, "N"
WCMD_NOASSOC, "File association missing for extension %s\n"
}

View File

@ -229,4 +229,5 @@ Skriv
WCMD_CONFIRM, "Are you sure"
WCMD_YES, "Y"
WCMD_NO, "N"
WCMD_NOASSOC, "File association missing for extension %s\n"
}

View File

@ -225,4 +225,5 @@ Wpisz HELP <komenda> dla dok
WCMD_CONFIRM, "Are you sure"
WCMD_YES, "Y"
WCMD_NO, "N"
WCMD_NOASSOC, "File association missing for extension %s\n"
}

View File

@ -438,4 +438,5 @@ Digite HELP <comando> para mais informa
WCMD_CONFIRM, "Are you sure"
WCMD_YES, "Y"
WCMD_NO, "N"
WCMD_NOASSOC, "File association missing for extension %s\n"
}

View File

@ -229,4 +229,5 @@ EXIT\t\t
WCMD_CONFIRM, "Are you sure"
WCMD_YES, "Y"
WCMD_NO, "N"
WCMD_NOASSOC, "File association missing for extension %s\n"
}

View File

@ -230,4 +230,5 @@ Enter HELP <command> for further information on any of the above commands\n"
WCMD_CONFIRM, "Are you sure"
WCMD_YES, "Y"
WCMD_NO, "N"
WCMD_NOASSOC, "File association missing for extension %s\n"
}

View File

@ -232,4 +232,5 @@ Yukar
WCMD_CONFIRM, "Are you sure"
WCMD_YES, "Y"
WCMD_NO, "N"
WCMD_NOASSOC, "File association missing for extension %s\n"
}

View File

@ -1457,3 +1457,159 @@ BOOL WCMD_ask_confirm (char *message, BOOL showSureText) {
/* Return the answer */
return (answer[0] == Ybuffer[0]);
}
/*****************************************************************************
* WCMD_assoc
*
* Lists or sets file associations
*/
void WCMD_assoc (char *command) {
HKEY key;
DWORD accessOptions = KEY_READ;
char *newValue;
LONG rc = ERROR_SUCCESS;
char keyValue[MAXSTRING];
DWORD valueLen = MAXSTRING;
HKEY readKey;
/* See if parameter includes '=' */
errorlevel = 0;
newValue = strchr(command, '=');
if (newValue) accessOptions |= KEY_WRITE;
/* Open a key to HKEY_CLASSES_ROOT for enumerating */
if (RegOpenKeyEx(HKEY_CLASSES_ROOT, "", 0,
accessOptions, &key) != ERROR_SUCCESS) {
WINE_FIXME("Unexpected failure opening HKCR key: %d\n", GetLastError());
return;
}
/* If no paramaters then list all associations */
if (*command == 0x00) {
int index = 0;
/* Enumerate all the keys */
while (rc != ERROR_NO_MORE_ITEMS) {
char keyName[MAXSTRING];
DWORD nameLen;
/* Find the next value */
nameLen = MAXSTRING;
rc = RegEnumKeyEx(key, index++,
keyName, &nameLen,
NULL, NULL, NULL, NULL);
if (rc == ERROR_SUCCESS) {
/* Only interested in extension ones */
if (keyName[0] == '.') {
if (RegOpenKeyEx(key, keyName, 0,
accessOptions, &readKey) == ERROR_SUCCESS) {
rc = RegQueryValueEx(readKey, NULL, NULL, NULL,
(LPBYTE)keyValue, &valueLen);
WCMD_output_asis(keyName);
WCMD_output_asis("=");
/* If no default value found, leave line empty after '=' */
if (rc == ERROR_SUCCESS) {
WCMD_output_asis(keyValue);
}
WCMD_output_asis("\n");
}
}
}
}
RegCloseKey(readKey);
} else {
/* Parameter supplied - if no '=' on command line, its a query */
if (newValue == NULL) {
char *space;
/* Query terminates the parameter at the first space */
strcpy(keyValue, command);
space = strchr(keyValue, ' ');
if (space) *space=0x00;
if (RegOpenKeyEx(key, keyValue, 0,
accessOptions, &readKey) == ERROR_SUCCESS) {
rc = RegQueryValueEx(readKey, NULL, NULL, NULL,
(LPBYTE)keyValue, &valueLen);
WCMD_output_asis(command);
WCMD_output_asis("=");
/* If no default value found, leave line empty after '=' */
if (rc == ERROR_SUCCESS) WCMD_output_asis(keyValue);
WCMD_output_asis("\n");
RegCloseKey(readKey);
} else {
char msgbuffer[MAXSTRING];
char outbuffer[MAXSTRING];
/* Load the translated 'File association not found' */
LoadString (hinst, WCMD_NOASSOC, msgbuffer, sizeof(msgbuffer));
sprintf(outbuffer, msgbuffer, keyValue);
WCMD_output_asis(outbuffer);
errorlevel = 2;
}
/* Not a query - its a set or clear of a value */
} else {
/* Get pointer to new value */
*newValue = 0x00;
newValue++;
/* If nothing after '=' then clear value */
if (*newValue == 0x00) {
rc = RegDeleteKey(key, command);
if (rc == ERROR_SUCCESS) {
WINE_TRACE("HKCR Key '%s' deleted\n", command);
} else if (rc != ERROR_FILE_NOT_FOUND) {
WCMD_print_error();
errorlevel = 2;
} else {
char msgbuffer[MAXSTRING];
char outbuffer[MAXSTRING];
/* Load the translated 'File association not found' */
LoadString (hinst, WCMD_NOASSOC, msgbuffer, sizeof(msgbuffer));
sprintf(outbuffer, msgbuffer, keyValue);
WCMD_output_asis(outbuffer);
errorlevel = 2;
}
/* It really is a set value = contents */
} else {
rc = RegCreateKeyEx(key, command, 0, NULL, REG_OPTION_NON_VOLATILE,
accessOptions, NULL, &readKey, NULL);
if (rc == ERROR_SUCCESS) {
rc = RegSetValueEx(readKey, NULL, 0, REG_SZ,
(LPBYTE)newValue, strlen(newValue));
RegCloseKey(readKey);
}
if (rc != ERROR_SUCCESS) {
WCMD_print_error();
errorlevel = 2;
} else {
WCMD_output_asis(command);
WCMD_output_asis("=");
WCMD_output_asis(newValue);
WCMD_output_asis("\n");
}
}
}
}
/* Clean up */
RegCloseKey(key);
}

View File

@ -27,6 +27,7 @@
#include <stdio.h>
#include <ctype.h>
void WCMD_assoc (char *);
void WCMD_batch (char *, char *, int, char *, HANDLE);
void WCMD_call (char *command);
void WCMD_change_tty (void);
@ -155,9 +156,10 @@ struct env_stack
#define WCMD_SETLOCAL 37
#define WCMD_PUSHD 38
#define WCMD_POPD 39
#define WCMD_ASSOC 40
/* Must be last in list */
#define WCMD_EXIT 40
#define WCMD_EXIT 41
/* Some standard messages */
extern const char nyi[];
@ -169,6 +171,7 @@ extern const char anykey[];
#define WCMD_CONFIRM 1001
#define WCMD_YES 1002
#define WCMD_NO 1003
#define WCMD_NOASSOC 1004
/* msdn specified max for Win XP */
#define MAXSTRING 8192

View File

@ -26,13 +26,16 @@
#include "config.h"
#include "wcmd.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(cmd);
const char * const inbuilt[] = {"ATTRIB", "CALL", "CD", "CHDIR", "CLS", "COPY", "CTTY",
"DATE", "DEL", "DIR", "ECHO", "ERASE", "FOR", "GOTO",
"HELP", "IF", "LABEL", "MD", "MKDIR", "MOVE", "PATH", "PAUSE",
"PROMPT", "REM", "REN", "RENAME", "RD", "RMDIR", "SET", "SHIFT",
"TIME", "TITLE", "TYPE", "VERIFY", "VER", "VOL",
"ENDLOCAL", "SETLOCAL", "PUSHD", "POPD", "EXIT" };
"ENDLOCAL", "SETLOCAL", "PUSHD", "POPD", "ASSOC", "EXIT" };
HINSTANCE hinst;
DWORD errorlevel;
@ -441,6 +444,7 @@ void WCMD_process_command (char *command)
* Strip leading whitespaces, and a '@' if supplied
*/
whichcmd = WCMD_strtrim_leading_spaces(cmd);
WINE_TRACE("Command: '%s'\n", cmd);
if (whichcmd[0] == '@') whichcmd++;
/*
@ -570,6 +574,9 @@ void WCMD_process_command (char *command)
case WCMD_POPD:
WCMD_popd();
break;
case WCMD_ASSOC:
WCMD_assoc(p);
break;
case WCMD_EXIT:
WCMD_exit ();
break;