[PATCH 1/2] uninstaller: Add WriteConsoleW support (bug 28186)
Hugh McMaster
hugh.mcmaster at outlook.com
Mon Aug 3 02:55:02 CDT 2015
---
programs/uninstaller/main.c | 46 ++++++++++++++++++++++++++++---------
programs/uninstaller/resource.h | 5 ++++
programs/uninstaller/uninstaller.rc | 3 +++
3 files changed, 43 insertions(+), 11 deletions(-)
diff --git a/programs/uninstaller/main.c b/programs/uninstaller/main.c
index 6b16e5d..270f44b 100644
--- a/programs/uninstaller/main.c
+++ b/programs/uninstaller/main.c
@@ -60,6 +60,38 @@ static const WCHAR UninstallCommandlineW[] = {'U','n','i','n','s','t','a','l','l
static const WCHAR WindowsInstallerW[] = {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
static const WCHAR SystemComponentW[] = {'S','y','s','t','e','m','C','o','m','p','o','n','e','n','t',0};
+static void output_formatstring(const WCHAR *fmt, __ms_va_list va_args)
+{
+ WCHAR *str;
+ DWORD len, count;
+
+ SetLastError(NO_ERROR);
+ len = FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ALLOCATE_BUFFER,
+ fmt, 0, 0, (LPWSTR)&str, 0, &va_args);
+ if (len == 0 && GetLastError() != NO_ERROR)
+ {
+ WINE_FIXME("Could not format string: le=%u, fmt=%s\n", GetLastError(), wine_dbgstr_w(fmt));
+ return;
+ }
+ WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), str, len, &count, NULL);
+ LocalFree(str);
+}
+
+static void output_message(unsigned int id, ...)
+{
+ WCHAR fmt[1024];
+ __ms_va_list va_args;
+
+ if (!LoadStringW(GetModuleHandleW(NULL), id, fmt, sizeof(fmt)/sizeof(fmt[0])))
+ {
+ WINE_FIXME("LoadString failed with %d\n", GetLastError());
+ return;
+ }
+ __ms_va_start(va_args, id);
+ output_formatstring(fmt, va_args);
+ __ms_va_end(va_args);
+}
+
/**
* Used to output program list when used with --list
*/
@@ -90,8 +122,6 @@ static void ListUninstallPrograms(void)
static void RemoveSpecificProgram(WCHAR *nameW)
{
unsigned int i;
- int lenName;
- char *name;
FetchUninstallInformation();
@@ -107,13 +137,7 @@ static void RemoveSpecificProgram(WCHAR *nameW)
if (i < numentries)
UninstallProgram();
else
- {
- lenName = WideCharToMultiByte(CP_UNIXCP, 0, nameW, -1, NULL, 0, NULL, NULL);
- name = HeapAlloc(GetProcessHeap(), 0, lenName);
- WideCharToMultiByte(CP_UNIXCP, 0, nameW, -1, name, lenName, NULL, NULL);
- fprintf(stderr, "Error: could not match application [%s]\n", name);
- HeapFree(GetProcessHeap(), 0, name);
- }
+ output_message(STRING_NO_APP_MATCH, nameW);
}
@@ -138,7 +162,7 @@ int wmain(int argc, WCHAR *argv[])
{
if( i >= argc )
{
- WINE_ERR( "The remove option requires a parameter.\n");
+ output_message(STRING_PARAMETER_REQUIRED);
return 1;
}
@@ -147,7 +171,7 @@ int wmain(int argc, WCHAR *argv[])
}
else
{
- WINE_ERR( "unknown option %s\n",wine_dbgstr_w(token));
+ output_message(STRING_INVALID_OPTION, token);
return 1;
}
}
diff --git a/programs/uninstaller/resource.h b/programs/uninstaller/resource.h
index 67e1f4b..f617b2a 100644
--- a/programs/uninstaller/resource.h
+++ b/programs/uninstaller/resource.h
@@ -22,4 +22,9 @@
#define IDS_APPNAME 1000
#define IDS_UNINSTALLFAILED 1001
+
+#define STRING_NO_APP_MATCH 2000
+#define STRING_PARAMETER_REQUIRED 2001
+#define STRING_INVALID_OPTION 2002
+
#define MAX_STRING_LEN 255
diff --git a/programs/uninstaller/uninstaller.rc b/programs/uninstaller/uninstaller.rc
index 0018992..e1750c8 100644
--- a/programs/uninstaller/uninstaller.rc
+++ b/programs/uninstaller/uninstaller.rc
@@ -27,4 +27,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT
STRINGTABLE {
IDS_APPNAME, "Wine Application Uninstaller"
IDS_UNINSTALLFAILED, "Execution of uninstall command '%s' failed, perhaps due to missing executable.\nDo you want to remove the uninstall entry from the registry?"
+ STRING_NO_APP_MATCH, "uninstaller: The application with GUID '%1' was not found\n"
+ STRING_PARAMETER_REQUIRED, "uninstaller: The option [--remove] must be followed by an application GUID\n"
+ STRING_INVALID_OPTION, "uninstaller: Invalid option [%1]\n"
}
--
1.9.1
More information about the wine-patches
mailing list