[PATCH 3/6] [UnInstall]: No longer use unix stdio functions, but the kernel32 equivalent
Eric Pouech
eric.pouech at orange.fr
Fri Nov 4 15:14:11 CDT 2011
#28185
A+
---
programs/uninstaller/main.c | 65 ++++++++++++++++++++++++++++++-------------
1 files changed, 46 insertions(+), 19 deletions(-)
diff --git a/programs/uninstaller/main.c b/programs/uninstaller/main.c
index e3178db..06dbc2d 100644
--- a/programs/uninstaller/main.c
+++ b/programs/uninstaller/main.c
@@ -27,6 +27,7 @@
#include <shlwapi.h>
#include "resource.h"
#include "regstr.h"
+#include "wine/unicode.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(uninstaller);
@@ -62,29 +63,58 @@ 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 int myprintf(BOOL out, const WCHAR *format, ...)
+{
+ static char output_bufA[65536];
+ static WCHAR output_bufW[sizeof(output_bufA) / sizeof(WCHAR)];
+ va_list parms;
+ DWORD nOut;
+ int len;
+ BOOL res = FALSE;
+ HANDLE hout = GetStdHandle(out ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE);
+
+ va_start(parms, format);
+ len = vsnprintfW(output_bufW, sizeof(output_bufW), format, parms);
+ va_end(parms);
+ if (len < 0)
+ {
+ /* String too long */
+ return 0;
+ }
+
+ /* Try to write as unicode whenever we think it's a console */
+ if (((DWORD_PTR)hout & 3) == 3)
+ {
+ res = WriteConsoleW(hout, output_bufW, len, &nOut, NULL);
+ }
+ else
+ {
+ BOOL usedDefaultChar = FALSE;
+ DWORD convertedChars;
+
+ /* Convert to OEM, then output */
+ convertedChars = WideCharToMultiByte(GetConsoleOutputCP(), 0, output_bufW, len,
+ output_bufA, sizeof(output_bufA),
+ "?", &usedDefaultChar);
+ res = WriteFile(hout, output_bufA, convertedChars, &nOut, FALSE);
+ }
+
+ return res ? nOut : 0;
+}
+
/**
* Used to output program list when used with --list
*/
static void ListUninstallPrograms(void)
{
unsigned int i;
- int lenDescr, lenKey;
- char *descr;
- char *key;
+ static const WCHAR fmt[] = {'%','s','|','|','|','%','s','\n',0};
FetchUninstallInformation();
for (i=0; i < numentries; i++)
{
- lenDescr = WideCharToMultiByte(CP_UNIXCP, 0, entries[i].descr, -1, NULL, 0, NULL, NULL);
- lenKey = WideCharToMultiByte(CP_UNIXCP, 0, entries[i].key, -1, NULL, 0, NULL, NULL);
- descr = HeapAlloc(GetProcessHeap(), 0, lenDescr);
- key = HeapAlloc(GetProcessHeap(), 0, lenKey);
- WideCharToMultiByte(CP_UNIXCP, 0, entries[i].descr, -1, descr, lenDescr, NULL, NULL);
- WideCharToMultiByte(CP_UNIXCP, 0, entries[i].key, -1, key, lenKey, NULL, NULL);
- printf("%s|||%s\n", key, descr);
- HeapFree(GetProcessHeap(), 0, descr);
- HeapFree(GetProcessHeap(), 0, key);
+ myprintf(TRUE, fmt, entries[i].key, entries[i].descr);
}
}
@@ -92,8 +122,6 @@ static void ListUninstallPrograms(void)
static void RemoveSpecificProgram(WCHAR *nameW)
{
unsigned int i;
- int lenName;
- char *name;
FetchUninstallInformation();
@@ -110,11 +138,10 @@ static void RemoveSpecificProgram(WCHAR *nameW)
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);
+ static const WCHAR fmt[] = {'E','r','r','o','r',':',' ','c','o','u','l','d',' ','n','o','t',' ',
+ 'm','a','t','c','h',' ','a','p','p','l','i','c','a','t','i','o','n',' ',
+ '[','%','s',']','\n',0};
+ myprintf(FALSE, fmt, nameW);
}
}
More information about the wine-patches
mailing list