Commit 79aa1a00 authored by Jason Edmeades's avatar Jason Edmeades Committed by Alexandre Julliard

cmd.exe: Add ASSOC command.

parent 8049ae1a
......@@ -234,4 +234,5 @@ Zadejte HELP <pkaz> pro podrobnj informace o nkterm z ve uvedench pk
WCMD_CONFIRM, "Are you sure"
WCMD_YES, "Y"
WCMD_NO, "N"
WCMD_NOASSOC, "File association missing for extension %s\n"
}
......@@ -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"
}
......@@ -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"
}
......@@ -246,4 +246,5 @@ Introduzca HELP <comando> para ms informacin sobre cualquiera de los comandos\
WCMD_CONFIRM, "Are you sure"
WCMD_YES, "Y"
WCMD_NO, "N"
WCMD_NOASSOC, "File association missing for extension %s\n"
}
......@@ -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"
}
......@@ -232,4 +232,5 @@ EXIT\t\tCMDI\n\n\
WCMD_CONFIRM, "Are you sure"
WCMD_YES, "Y"
WCMD_NO, "N"
WCMD_NOASSOC, "File association missing for extension %s\n"
}
......@@ -223,4 +223,5 @@ HELP <명령>을 치면 그 명령의 상세한 정보를 보여줌\n"
WCMD_CONFIRM, "Are you sure"
WCMD_YES, "Y"
WCMD_NO, "N"
WCMD_NOASSOC, "File association missing for extension %s\n"
}
......@@ -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 \
......
......@@ -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"
}
......@@ -229,4 +229,5 @@ Skriv HELP <kommando> for mer informasjon om kommandoene ovenfor\n"
WCMD_CONFIRM, "Are you sure"
WCMD_YES, "Y"
WCMD_NO, "N"
WCMD_NOASSOC, "File association missing for extension %s\n"
}
......@@ -225,4 +225,5 @@ Wpisz HELP <komenda> dla dokadniejszych informacji o komendzie\n"
WCMD_CONFIRM, "Are you sure"
WCMD_YES, "Y"
WCMD_NO, "N"
WCMD_NOASSOC, "File association missing for extension %s\n"
}
......@@ -438,4 +438,5 @@ Digite HELP <comando> para mais informaes sobre alguns dos comandos acima\n"
WCMD_CONFIRM, "Are you sure"
WCMD_YES, "Y"
WCMD_NO, "N"
WCMD_NOASSOC, "File association missing for extension %s\n"
}
......@@ -229,4 +229,5 @@ EXIT\t\t WCMD\n\n\
WCMD_CONFIRM, "Are you sure"
WCMD_YES, "Y"
WCMD_NO, "N"
WCMD_NOASSOC, "File association missing for extension %s\n"
}
......@@ -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"
}
......@@ -232,4 +232,5 @@ Yukardaki komutlar hakknda daha fazla bilgi iin HELP <komut> girin\n"
WCMD_CONFIRM, "Are you sure"
WCMD_YES, "Y"
WCMD_NO, "N"
WCMD_NOASSOC, "File association missing for extension %s\n"
}
......@@ -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);
}
......@@ -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
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment