[MSHTML]
[reactos.git] / reactos / dll / win32 / mshtml / install.c
index 605fa05..e47c284 100644 (file)
 
 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
 
-#define GECKO_FILE_NAME "wine_gecko-" GECKO_VERSION ".cab"
+#ifdef __i386__
+#define GECKO_ARCH "x86"
+#else
+#define GECKO_ARCH ""
+#endif
+
+#define GECKO_FILE_NAME "wine_gecko-" GECKO_VERSION "-" GECKO_ARCH ".cab"
 
 static const WCHAR mshtml_keyW[] =
     {'S','o','f','t','w','a','r','e',
      '\\','W','i','n','e',
      '\\','M','S','H','T','M','L',0};
 
+static const CHAR mshtml_keyA[] =
+    {'S','o','f','t','w','a','r','e',
+    '\\','W','i','n','e',
+    '\\','M','S','H','T','M','L',0};
+
 static HWND install_dialog = NULL;
 static LPWSTR tmp_file_name = NULL;
 static HANDLE tmp_file = INVALID_HANDLE_VALUE;
@@ -141,7 +152,7 @@ static BOOL install_cab(LPCWSTR file_name)
 
     TRACE("(%s)\n", debugstr_w(file_name));
 
-    GetWindowsDirectoryA(install_dir, sizeof(install_dir));
+    GetSystemDirectoryA(install_dir, sizeof(install_dir));
     strcat(install_dir, "\\gecko\\");
     res = CreateDirectoryA(install_dir, NULL);
     if(!res && GetLastError() != ERROR_ALREADY_EXISTS) {
@@ -182,7 +193,7 @@ static BOOL install_from_unix_file(const char *file_name)
     int fd;
     BOOL ret;
 
-    static WCHAR *(*wine_get_dos_file_name)(const char*);
+    static WCHAR * (CDECL *wine_get_dos_file_name)(const char*);
     static const WCHAR kernel32W[] = {'k','e','r','n','e','l','3','2','.','d','l','l',0};
 
     fd = open(file_name, O_RDONLY);
@@ -193,18 +204,21 @@ static BOOL install_from_unix_file(const char *file_name)
 
     close(fd);
 
-    if(!wine_get_dos_file_name) {
+    if(!wine_get_dos_file_name)
         wine_get_dos_file_name = (void*)GetProcAddress(GetModuleHandleW(kernel32W), "wine_get_dos_file_name");
-        if(!wine_get_dos_file_name) {
-            ERR("Could not get wine_get_dos_file_name function.\n");
-            return FALSE;
-        }
-    }
 
-    dos_file_name = wine_get_dos_file_name(file_name);
-    if(!dos_file_name) {
-        ERR("Could not get dos file name of %s\n", debugstr_a(file_name));
-        return FALSE;
+    if(wine_get_dos_file_name) { /* Wine UNIX mode */
+       dos_file_name = wine_get_dos_file_name(file_name);
+       if(!dos_file_name) {
+           ERR("Could not get dos file name of %s\n", debugstr_a(file_name));
+           return FALSE;
+       }
+    } else { /* Windows mode */
+       UINT res;
+       WARN("Could not get wine_get_dos_file_name function, calling install_cab directly.\n");
+       res = MultiByteToWideChar( CP_ACP, 0, file_name, -1, 0, 0);
+       dos_file_name = heap_alloc (res*sizeof(WCHAR));
+       MultiByteToWideChar( CP_ACP, 0, file_name, -1, dos_file_name, res);
     }
 
     ret = install_cab(dos_file_name);
@@ -216,23 +230,18 @@ static BOOL install_from_unix_file(const char *file_name)
 static BOOL install_from_registered_dir(void)
 {
     char *file_name;
-    HKEY hkey;
     DWORD res, type, size = MAX_PATH;
     BOOL ret;
 
-    /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
-    res = RegOpenKeyW(HKEY_CURRENT_USER, mshtml_keyW, &hkey);
-    if(res != ERROR_SUCCESS)
-        return FALSE;
-
     file_name = heap_alloc(size+sizeof(GECKO_FILE_NAME));
-    res = RegQueryValueExA(hkey, "GeckoCabDir", NULL, &type, (PBYTE)file_name, &size);
+    /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
+    res = RegGetValueA(HKEY_CURRENT_USER, mshtml_keyA, "GeckoCabDir", RRF_RT_ANY, &type, (PBYTE)file_name, &size);
     if(res == ERROR_MORE_DATA) {
         file_name = heap_realloc(file_name, size+sizeof(GECKO_FILE_NAME));
-        res = RegQueryValueExA(hkey, "GeckoCabDir", NULL, &type, (PBYTE)file_name, &size);
+        res = RegGetValueA(HKEY_CURRENT_USER, mshtml_keyA, "GeckoCabDir", RRF_RT_ANY, &type, (PBYTE)file_name, &size);
     }
-    RegCloseKey(hkey);
-    if(res != ERROR_SUCCESS || type != REG_SZ) {
+    
+    if(res != ERROR_SUCCESS || (type != REG_SZ && type != REG_EXPAND_SZ)) {
         heap_free(file_name);
         return FALSE;
     }
@@ -383,10 +392,12 @@ static HRESULT WINAPI InstallCallback_OnDataAvailable(IBindStatusCallback *iface
     HRESULT hres;
 
     do {
+        DWORD written;
+
         size = 0;
         hres = IStream_Read(str, buf, sizeof(buf), &size);
         if(size)
-            WriteFile(tmp_file, buf, size, NULL, NULL);
+            WriteFile(tmp_file, buf, size, &written, NULL);
     }while(hres == S_OK);
 
     return S_OK;
@@ -420,11 +431,13 @@ static LPWSTR get_url(void)
     HKEY hkey;
     DWORD res, type;
     DWORD size = INTERNET_MAX_URL_LENGTH*sizeof(WCHAR);
+    DWORD returned_size;
     LPWSTR url;
 
     static const WCHAR wszGeckoUrl[] = {'G','e','c','k','o','U','r','l',0};
     static const WCHAR httpW[] = {'h','t','t','p'};
-    static const WCHAR v_formatW[] = {'?','v','=',0};
+    static const WCHAR arch_formatW[] = {'?','a','r','c','h','='};
+    static const WCHAR v_formatW[] = {'&','v','='};
 
     /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
     res = RegOpenKeyW(HKEY_CURRENT_USER, mshtml_keyW, &hkey);
@@ -432,17 +445,25 @@ static LPWSTR get_url(void)
         return NULL;
 
     url = heap_alloc(size);
+    returned_size = size;
 
-    res = RegQueryValueExW(hkey, wszGeckoUrl, NULL, &type, (LPBYTE)url, &size);
+    res = RegQueryValueExW(hkey, wszGeckoUrl, NULL, &type, (LPBYTE)url, &returned_size);
     RegCloseKey(hkey);
     if(res != ERROR_SUCCESS || type != REG_SZ) {
         heap_free(url);
         return NULL;
     }
 
-    if(size > sizeof(httpW) && !memcmp(url, httpW, sizeof(httpW))) {
-        strcatW(url, v_formatW);
-        MultiByteToWideChar(CP_ACP, 0, GECKO_VERSION, -1, url+strlenW(url), -1);
+    if(returned_size > sizeof(httpW) && !memcmp(url, httpW, sizeof(httpW))) {
+        DWORD len;
+
+        len = strlenW(url);
+        memcpy(url+len, arch_formatW, sizeof(arch_formatW));
+        len += sizeof(arch_formatW)/sizeof(WCHAR);
+        len += MultiByteToWideChar(CP_ACP, 0, GECKO_ARCH, sizeof(GECKO_ARCH), url+len, size/sizeof(WCHAR)-len)-1;
+        memcpy(url+len, v_formatW, sizeof(v_formatW));
+        len += sizeof(v_formatW)/sizeof(WCHAR);
+        MultiByteToWideChar(CP_ACP, 0, GECKO_VERSION, -1, url+len, size/sizeof(WCHAR)-len);
     }
 
     TRACE("Got URL %s\n", debugstr_w(url));
@@ -505,6 +526,9 @@ BOOL install_wine_gecko(BOOL silent)
 {
     HANDLE hsem;
 
+    if(!*GECKO_ARCH)
+        return FALSE;
+
     SetLastError(ERROR_SUCCESS);
     hsem = CreateSemaphoreA( NULL, 0, 1, "mshtml_install_semaphore");