2010-12-06 19:25:01 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2006-2010 Jacek Caban for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2012-10-09 15:48:47 +02:00
|
|
|
#include "wine/port.h"
|
2010-12-06 19:25:01 +01:00
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <fcntl.h>
|
2010-12-29 00:53:38 +01:00
|
|
|
#include <stdio.h>
|
2012-10-09 15:48:47 +02:00
|
|
|
#include <errno.h>
|
2010-12-06 19:25:01 +01:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "cpl.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "ole2.h"
|
|
|
|
#include "commctrl.h"
|
|
|
|
#include "advpub.h"
|
|
|
|
#include "wininet.h"
|
|
|
|
#include "shellapi.h"
|
|
|
|
#include "urlmon.h"
|
2011-02-10 16:42:49 +01:00
|
|
|
#include "msi.h"
|
2010-12-06 19:25:01 +01:00
|
|
|
|
|
|
|
#include "appwiz.h"
|
|
|
|
#include "res.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "wine/library.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(appwizcpl);
|
|
|
|
|
2013-05-17 12:34:34 +02:00
|
|
|
#define GECKO_VERSION "2.21"
|
2010-12-06 19:25:01 +01:00
|
|
|
|
|
|
|
#ifdef __i386__
|
|
|
|
#define ARCH_STRING "x86"
|
2013-05-17 12:34:34 +02:00
|
|
|
#define GECKO_SHA "a514fc4d53783a586c7880a676c415695fe934a3"
|
2010-12-06 19:25:01 +01:00
|
|
|
#elif defined(__x86_64__)
|
|
|
|
#define ARCH_STRING "x86_64"
|
2013-05-17 12:34:34 +02:00
|
|
|
#define GECKO_SHA "c6f249ff2c6eb7dfe423ef246aba54e1a3b26934"
|
2010-12-06 19:25:01 +01:00
|
|
|
#else
|
|
|
|
#define ARCH_STRING ""
|
2010-12-29 00:53:38 +01:00
|
|
|
#define GECKO_SHA "???"
|
2010-12-06 19:25:01 +01:00
|
|
|
#endif
|
|
|
|
|
2012-10-15 22:17:11 +02:00
|
|
|
#define MONO_VERSION "0.0.8"
|
|
|
|
#define MONO_SHA "dd349e72249ce5ff981be0e9dae33ac4a46a9f60"
|
2012-05-21 14:46:03 +02:00
|
|
|
|
2012-05-15 11:47:27 +02:00
|
|
|
typedef struct {
|
2012-05-15 11:47:40 +02:00
|
|
|
const char *version;
|
2012-05-15 11:47:27 +02:00
|
|
|
const char *file_name;
|
2012-05-15 11:47:58 +02:00
|
|
|
const char *subdir_name;
|
2012-05-15 11:47:40 +02:00
|
|
|
const char *sha;
|
2012-05-30 13:22:46 +02:00
|
|
|
const char *url_default;
|
2012-05-15 11:48:12 +02:00
|
|
|
const char *config_key;
|
|
|
|
const char *url_config_key;
|
|
|
|
const char *dir_config_key;
|
2012-05-17 16:19:10 +02:00
|
|
|
LPCWSTR dialog_template;
|
2012-05-15 11:47:27 +02:00
|
|
|
} addon_info_t;
|
|
|
|
|
|
|
|
static const addon_info_t addons_info[] = {
|
|
|
|
{
|
2012-05-15 11:47:40 +02:00
|
|
|
GECKO_VERSION,
|
|
|
|
"wine_gecko-" GECKO_VERSION "-" ARCH_STRING ".msi",
|
2012-05-15 11:47:58 +02:00
|
|
|
"gecko",
|
2012-05-15 11:48:12 +02:00
|
|
|
GECKO_SHA,
|
2012-05-30 13:22:46 +02:00
|
|
|
"http://source.winehq.org/winegecko.php",
|
2012-05-17 16:19:10 +02:00
|
|
|
"MSHTML", "GeckoUrl", "GeckoCabDir",
|
|
|
|
MAKEINTRESOURCEW(ID_DWL_GECKO_DIALOG)
|
2012-05-21 14:46:03 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
MONO_VERSION,
|
|
|
|
"wine-mono-" MONO_VERSION ".msi",
|
|
|
|
"mono",
|
|
|
|
MONO_SHA,
|
2012-05-30 13:22:46 +02:00
|
|
|
"http://source.winehq.org/winemono.php",
|
2012-05-21 14:46:03 +02:00
|
|
|
"Dotnet", "MonoUrl", "MonoCabDir",
|
|
|
|
MAKEINTRESOURCEW(ID_DWL_MONO_DIALOG)
|
2012-05-15 11:47:27 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-15 11:48:31 +02:00
|
|
|
static const addon_info_t *addon;
|
2010-12-06 19:25:01 +01:00
|
|
|
|
|
|
|
static HWND install_dialog = NULL;
|
|
|
|
static LPWSTR url = NULL;
|
|
|
|
|
2012-10-09 15:48:47 +02:00
|
|
|
static WCHAR * (CDECL *p_wine_get_dos_file_name)(const char*);
|
|
|
|
static const WCHAR kernel32_dllW[] = {'k','e','r','n','e','l','3','2','.','d','l','l',0};
|
|
|
|
|
|
|
|
|
2010-12-29 00:53:38 +01:00
|
|
|
/* SHA definitions are copied from advapi32. They aren't available in headers. */
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
ULONG Unknown[6];
|
|
|
|
ULONG State[5];
|
|
|
|
ULONG Count[2];
|
|
|
|
UCHAR Buffer[64];
|
|
|
|
} SHA_CTX, *PSHA_CTX;
|
|
|
|
|
|
|
|
void WINAPI A_SHAInit(PSHA_CTX);
|
|
|
|
void WINAPI A_SHAUpdate(PSHA_CTX,const unsigned char*,UINT);
|
|
|
|
void WINAPI A_SHAFinal(PSHA_CTX,PULONG);
|
|
|
|
|
|
|
|
static BOOL sha_check(const WCHAR *file_name)
|
|
|
|
{
|
|
|
|
const unsigned char *file_map;
|
|
|
|
HANDLE file, map;
|
|
|
|
ULONG sha[5];
|
|
|
|
char buf[2*sizeof(sha)+1];
|
|
|
|
SHA_CTX ctx;
|
|
|
|
DWORD size, i;
|
|
|
|
|
|
|
|
file = CreateFileW(file_name, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
|
|
|
|
if(file == INVALID_HANDLE_VALUE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
size = GetFileSize(file, NULL);
|
|
|
|
|
|
|
|
map = CreateFileMappingW(file, NULL, PAGE_READONLY, 0, 0, NULL);
|
|
|
|
CloseHandle(file);
|
|
|
|
if(!map)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
file_map = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
|
|
|
|
CloseHandle(map);
|
|
|
|
if(!file_map)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
A_SHAInit(&ctx);
|
|
|
|
A_SHAUpdate(&ctx, file_map, size);
|
|
|
|
A_SHAFinal(&ctx, sha);
|
|
|
|
|
|
|
|
UnmapViewOfFile(file_map);
|
|
|
|
|
|
|
|
for(i=0; i < sizeof(sha); i++)
|
|
|
|
sprintf(buf + i*2, "%02x", *((unsigned char*)sha+i));
|
|
|
|
|
2012-05-15 11:47:40 +02:00
|
|
|
if(strcmp(buf, addon->sha)) {
|
|
|
|
WARN("Got %s, expected %s\n", buf, addon->sha);
|
2010-12-29 00:53:38 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-12-06 19:25:01 +01:00
|
|
|
static void set_status(DWORD id)
|
|
|
|
{
|
|
|
|
HWND status = GetDlgItem(install_dialog, ID_DWL_STATUS);
|
|
|
|
WCHAR buf[64];
|
|
|
|
|
|
|
|
LoadStringW(hInst, id, buf, sizeof(buf)/sizeof(WCHAR));
|
|
|
|
SendMessageW(status, WM_SETTEXT, 0, (LPARAM)buf);
|
|
|
|
}
|
|
|
|
|
2012-07-16 10:09:32 +02:00
|
|
|
enum install_res {
|
|
|
|
INSTALL_OK = 0,
|
|
|
|
INSTALL_FAILED,
|
|
|
|
INSTALL_NEXT,
|
|
|
|
};
|
|
|
|
|
|
|
|
static enum install_res install_file(const WCHAR *file_name)
|
2011-02-10 16:42:49 +01:00
|
|
|
{
|
|
|
|
ULONG res;
|
|
|
|
|
|
|
|
res = MsiInstallProductW(file_name, NULL);
|
|
|
|
if(res != ERROR_SUCCESS) {
|
|
|
|
ERR("MsiInstallProduct failed: %u\n", res);
|
2012-07-16 10:09:32 +02:00
|
|
|
return INSTALL_FAILED;
|
2011-02-10 16:42:49 +01:00
|
|
|
}
|
|
|
|
|
2012-07-16 10:09:32 +02:00
|
|
|
return INSTALL_OK;
|
2011-02-10 16:42:49 +01:00
|
|
|
}
|
|
|
|
|
2012-07-16 10:09:32 +02:00
|
|
|
static enum install_res install_from_unix_file(const char *dir, const char *subdir, const char *file_name)
|
2010-12-06 19:25:01 +01:00
|
|
|
{
|
|
|
|
LPWSTR dos_file_name;
|
2012-05-15 11:47:27 +02:00
|
|
|
char *file_path;
|
|
|
|
int fd, len;
|
2012-07-16 10:09:32 +02:00
|
|
|
enum install_res ret;
|
2010-12-06 19:25:01 +01:00
|
|
|
|
2012-05-15 11:47:27 +02:00
|
|
|
len = strlen(dir);
|
2012-05-15 11:47:58 +02:00
|
|
|
file_path = heap_alloc(len+strlen(subdir)+strlen(file_name)+3);
|
2012-05-15 11:47:27 +02:00
|
|
|
if(!file_path)
|
2012-07-16 10:09:32 +02:00
|
|
|
return INSTALL_FAILED;
|
2012-05-15 11:47:27 +02:00
|
|
|
|
|
|
|
memcpy(file_path, dir, len);
|
|
|
|
if(len && file_path[len-1] != '/' && file_path[len-1] != '\\')
|
|
|
|
file_path[len++] = '/';
|
2012-05-15 11:47:58 +02:00
|
|
|
if(*subdir) {
|
|
|
|
strcpy(file_path+len, subdir);
|
|
|
|
len += strlen(subdir);
|
|
|
|
file_path[len++] = '/';
|
|
|
|
}
|
2012-05-15 11:47:27 +02:00
|
|
|
strcpy(file_path+len, file_name);
|
|
|
|
|
|
|
|
fd = open(file_path, O_RDONLY);
|
2010-12-06 19:25:01 +01:00
|
|
|
if(fd == -1) {
|
2012-05-15 11:47:27 +02:00
|
|
|
TRACE("%s not found\n", debugstr_a(file_path));
|
|
|
|
heap_free(file_path);
|
2012-07-16 10:09:32 +02:00
|
|
|
return INSTALL_NEXT;
|
2010-12-06 19:25:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
2012-10-09 15:48:47 +02:00
|
|
|
if(p_wine_get_dos_file_name) { /* Wine UNIX mode */
|
|
|
|
dos_file_name = p_wine_get_dos_file_name(file_path);
|
2010-12-06 19:25:01 +01:00
|
|
|
if(!dos_file_name) {
|
2012-05-15 11:47:27 +02:00
|
|
|
ERR("Could not get dos file name of %s\n", debugstr_a(file_path));
|
|
|
|
heap_free(file_path);
|
2012-07-16 10:09:32 +02:00
|
|
|
return INSTALL_FAILED;
|
2010-12-06 19:25:01 +01:00
|
|
|
}
|
|
|
|
} else { /* Windows mode */
|
|
|
|
UINT res;
|
|
|
|
WARN("Could not get wine_get_dos_file_name function, calling install_cab directly.\n");
|
2012-05-15 11:47:27 +02:00
|
|
|
res = MultiByteToWideChar( CP_ACP, 0, file_path, -1, 0, 0);
|
2010-12-06 19:25:01 +01:00
|
|
|
dos_file_name = heap_alloc (res*sizeof(WCHAR));
|
2012-05-15 11:47:27 +02:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, file_path, -1, dos_file_name, res);
|
2010-12-06 19:25:01 +01:00
|
|
|
}
|
|
|
|
|
2012-05-15 11:47:27 +02:00
|
|
|
heap_free(file_path);
|
|
|
|
|
2011-02-10 16:42:49 +01:00
|
|
|
ret = install_file(dos_file_name);
|
2010-12-06 19:25:01 +01:00
|
|
|
|
|
|
|
heap_free(dos_file_name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-05-15 11:48:12 +02:00
|
|
|
static HKEY open_config_key(void)
|
|
|
|
{
|
|
|
|
HKEY hkey, ret;
|
|
|
|
DWORD res;
|
|
|
|
|
|
|
|
static const WCHAR wine_keyW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e',0};
|
|
|
|
|
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\$config_key */
|
|
|
|
res = RegOpenKeyW(HKEY_CURRENT_USER, wine_keyW, &hkey);
|
|
|
|
if(res != ERROR_SUCCESS)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
res = RegOpenKeyA(hkey, addon->config_key, &ret);
|
|
|
|
RegCloseKey(hkey);
|
|
|
|
return res == ERROR_SUCCESS ? ret : NULL;
|
|
|
|
}
|
|
|
|
|
2012-07-16 10:09:32 +02:00
|
|
|
static enum install_res install_from_registered_dir(void)
|
2010-12-06 19:25:01 +01:00
|
|
|
{
|
2012-05-15 11:47:27 +02:00
|
|
|
char *package_dir;
|
2010-12-06 19:25:01 +01:00
|
|
|
HKEY hkey;
|
|
|
|
DWORD res, type, size = MAX_PATH;
|
2012-07-16 10:09:32 +02:00
|
|
|
enum install_res ret;
|
2010-12-06 19:25:01 +01:00
|
|
|
|
2012-05-15 11:48:12 +02:00
|
|
|
hkey = open_config_key();
|
|
|
|
if(!hkey)
|
2012-07-16 10:09:32 +02:00
|
|
|
return INSTALL_NEXT;
|
2010-12-06 19:25:01 +01:00
|
|
|
|
2012-05-15 11:47:27 +02:00
|
|
|
package_dir = heap_alloc(size);
|
2012-05-15 11:48:12 +02:00
|
|
|
res = RegGetValueA(hkey, NULL, addon->dir_config_key, RRF_RT_ANY, &type, (PBYTE)package_dir, &size);
|
2010-12-06 19:25:01 +01:00
|
|
|
if(res == ERROR_MORE_DATA) {
|
2012-05-15 11:47:27 +02:00
|
|
|
package_dir = heap_realloc(package_dir, size);
|
2012-05-15 11:48:12 +02:00
|
|
|
res = RegGetValueA(hkey, NULL, addon->dir_config_key, RRF_RT_ANY, &type, (PBYTE)package_dir, &size);
|
2010-12-06 19:25:01 +01:00
|
|
|
}
|
|
|
|
RegCloseKey(hkey);
|
2012-07-16 10:09:32 +02:00
|
|
|
if(res == ERROR_FILE_NOT_FOUND) {
|
2012-05-15 11:47:27 +02:00
|
|
|
heap_free(package_dir);
|
2012-07-16 10:09:32 +02:00
|
|
|
return INSTALL_NEXT;
|
|
|
|
} else if(res != ERROR_SUCCESS || (type != REG_SZ && type != REG_EXPAND_SZ)) {
|
|
|
|
heap_free(package_dir);
|
|
|
|
return INSTALL_FAILED;
|
2010-12-06 19:25:01 +01:00
|
|
|
}
|
|
|
|
|
2012-05-15 11:47:27 +02:00
|
|
|
TRACE("Trying %s/%s\n", debugstr_a(package_dir), debugstr_a(addon->file_name));
|
2010-12-06 19:25:01 +01:00
|
|
|
|
2012-05-15 11:47:58 +02:00
|
|
|
ret = install_from_unix_file(package_dir, "", addon->file_name);
|
2010-12-06 19:25:01 +01:00
|
|
|
|
2012-05-15 11:47:27 +02:00
|
|
|
heap_free(package_dir);
|
2010-12-06 19:25:01 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-16 10:09:32 +02:00
|
|
|
static enum install_res install_from_default_dir(void)
|
2010-12-06 19:25:01 +01:00
|
|
|
{
|
2012-05-15 11:47:58 +02:00
|
|
|
const char *data_dir, *package_dir;
|
|
|
|
char *dir_buf = NULL;
|
|
|
|
int len;
|
2010-12-06 19:25:01 +01:00
|
|
|
BOOL ret;
|
|
|
|
|
2012-05-15 11:47:58 +02:00
|
|
|
if((data_dir = wine_get_data_dir())) {
|
|
|
|
package_dir = data_dir;
|
|
|
|
}else if((data_dir = wine_get_build_dir())) {
|
|
|
|
len = strlen(data_dir);
|
|
|
|
dir_buf = heap_alloc(len + sizeof("/../"));
|
|
|
|
memcpy(dir_buf, data_dir, len);
|
|
|
|
strcpy(dir_buf+len, "/../");
|
|
|
|
package_dir = dir_buf;
|
|
|
|
}else {
|
2012-07-16 10:09:32 +02:00
|
|
|
return INSTALL_NEXT;
|
2012-05-15 11:47:58 +02:00
|
|
|
}
|
2010-12-06 19:25:01 +01:00
|
|
|
|
2012-05-15 11:47:58 +02:00
|
|
|
ret = install_from_unix_file(package_dir, addon->subdir_name, addon->file_name);
|
|
|
|
heap_free(dir_buf);
|
2010-12-06 19:25:01 +01:00
|
|
|
|
2012-07-16 10:09:32 +02:00
|
|
|
if (ret == INSTALL_NEXT)
|
2012-05-15 11:47:58 +02:00
|
|
|
ret = install_from_unix_file(INSTALL_DATADIR "/wine/", addon->subdir_name, addon->file_name);
|
2012-07-16 10:09:32 +02:00
|
|
|
if (ret == INSTALL_NEXT && strcmp(INSTALL_DATADIR, "/usr/share"))
|
2012-05-15 11:47:58 +02:00
|
|
|
ret = install_from_unix_file("/usr/share/wine/", addon->subdir_name, addon->file_name);
|
2010-12-06 19:25:01 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-10-09 15:48:47 +02:00
|
|
|
static WCHAR *get_cache_file_name(BOOL ensure_exists)
|
|
|
|
{
|
|
|
|
const char *home_dir = NULL, *xdg_cache_dir;
|
|
|
|
size_t len, size = strlen(addon->file_name) + 7; /* strlen("/wine/"), '\0' */
|
|
|
|
char *cache_file_name;
|
|
|
|
WCHAR *ret;
|
|
|
|
|
|
|
|
/* non-Wine (eg. Windows) cache is currently not supported */
|
|
|
|
if(!p_wine_get_dos_file_name)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
xdg_cache_dir = getenv("XDG_CACHE_HOME");
|
|
|
|
if(xdg_cache_dir && *xdg_cache_dir) {
|
|
|
|
size += strlen(xdg_cache_dir);
|
|
|
|
}else {
|
|
|
|
home_dir = getenv("HOME");
|
|
|
|
if(!home_dir)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
size += strlen(home_dir) + 8; /* strlen("/.cache/") */
|
|
|
|
}
|
|
|
|
|
|
|
|
cache_file_name = heap_alloc(size);
|
|
|
|
if(!cache_file_name)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if(xdg_cache_dir && *xdg_cache_dir) {
|
|
|
|
len = strlen(xdg_cache_dir);
|
|
|
|
if(len > 1 && xdg_cache_dir[len-1] == '/')
|
|
|
|
len--;
|
|
|
|
memcpy(cache_file_name, xdg_cache_dir, len);
|
|
|
|
cache_file_name[len] = 0;
|
|
|
|
}else {
|
|
|
|
len = strlen(home_dir);
|
|
|
|
memcpy(cache_file_name, home_dir, len);
|
|
|
|
strcpy(cache_file_name+len, "/.cache");
|
|
|
|
len += 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ensure_exists && mkdir(cache_file_name, 0777) && errno != EEXIST) {
|
|
|
|
WARN("%s does not exist and could not be created: %s\n", cache_file_name, strerror(errno));
|
|
|
|
heap_free(cache_file_name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(cache_file_name+len, "/wine");
|
|
|
|
len += 5;
|
|
|
|
|
|
|
|
if(ensure_exists && mkdir(cache_file_name, 0777) && errno != EEXIST) {
|
|
|
|
WARN("%s does not exist and could not be created: %s\n", cache_file_name, strerror(errno));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cache_file_name[len++] = '/';
|
|
|
|
strcpy(cache_file_name+len, addon->file_name);
|
|
|
|
ret = p_wine_get_dos_file_name(cache_file_name);
|
|
|
|
|
|
|
|
TRACE("%s -> %s\n", cache_file_name, debugstr_w(ret));
|
|
|
|
|
|
|
|
heap_free(cache_file_name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum install_res install_from_cache(void)
|
|
|
|
{
|
|
|
|
WCHAR *cache_file_name;
|
|
|
|
enum install_res res;
|
|
|
|
|
|
|
|
cache_file_name = get_cache_file_name(FALSE);
|
|
|
|
if(!cache_file_name)
|
|
|
|
return INSTALL_NEXT;
|
|
|
|
|
|
|
|
if(!sha_check(cache_file_name)) {
|
|
|
|
WARN("could not validate check sum\n");
|
|
|
|
DeleteFileW(cache_file_name);
|
|
|
|
heap_free(cache_file_name);
|
|
|
|
return INSTALL_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = install_file(cache_file_name);
|
|
|
|
heap_free(cache_file_name);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-12-06 19:25:01 +01:00
|
|
|
static HRESULT WINAPI InstallCallback_QueryInterface(IBindStatusCallback *iface,
|
|
|
|
REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IBindStatusCallback, riid)) {
|
|
|
|
*ppv = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI InstallCallback_AddRef(IBindStatusCallback *iface)
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI InstallCallback_Release(IBindStatusCallback *iface)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InstallCallback_OnStartBinding(IBindStatusCallback *iface,
|
|
|
|
DWORD dwReserved, IBinding *pib)
|
|
|
|
{
|
|
|
|
set_status(IDS_DOWNLOADING);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InstallCallback_GetPriority(IBindStatusCallback *iface,
|
|
|
|
LONG *pnPriority)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InstallCallback_OnLowResource(IBindStatusCallback *iface,
|
|
|
|
DWORD dwReserved)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InstallCallback_OnProgress(IBindStatusCallback *iface, ULONG ulProgress,
|
|
|
|
ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
|
|
|
|
{
|
|
|
|
HWND progress = GetDlgItem(install_dialog, ID_DWL_PROGRESS);
|
|
|
|
|
|
|
|
if(ulProgressMax)
|
|
|
|
SendMessageW(progress, PBM_SETRANGE32, 0, ulProgressMax);
|
|
|
|
if(ulProgress)
|
|
|
|
SendMessageW(progress, PBM_SETPOS, ulProgress, 0);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InstallCallback_OnStopBinding(IBindStatusCallback *iface,
|
|
|
|
HRESULT hresult, LPCWSTR szError)
|
|
|
|
{
|
|
|
|
if(FAILED(hresult)) {
|
|
|
|
ERR("Binding failed %08x\n", hresult);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_status(IDS_INSTALLING);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InstallCallback_GetBindInfo(IBindStatusCallback *iface,
|
|
|
|
DWORD* grfBINDF, BINDINFO* pbindinfo)
|
|
|
|
{
|
|
|
|
/* FIXME */
|
|
|
|
*grfBINDF = 0;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InstallCallback_OnDataAvailable(IBindStatusCallback *iface, DWORD grfBSCF,
|
|
|
|
DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
|
|
|
|
{
|
|
|
|
ERR("\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InstallCallback_OnObjectAvailable(IBindStatusCallback *iface,
|
|
|
|
REFIID riid, IUnknown* punk)
|
|
|
|
{
|
|
|
|
ERR("\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IBindStatusCallbackVtbl InstallCallbackVtbl = {
|
|
|
|
InstallCallback_QueryInterface,
|
|
|
|
InstallCallback_AddRef,
|
|
|
|
InstallCallback_Release,
|
|
|
|
InstallCallback_OnStartBinding,
|
|
|
|
InstallCallback_GetPriority,
|
|
|
|
InstallCallback_OnLowResource,
|
|
|
|
InstallCallback_OnProgress,
|
|
|
|
InstallCallback_OnStopBinding,
|
|
|
|
InstallCallback_GetBindInfo,
|
|
|
|
InstallCallback_OnDataAvailable,
|
|
|
|
InstallCallback_OnObjectAvailable
|
|
|
|
};
|
|
|
|
|
|
|
|
static IBindStatusCallback InstallCallback = { &InstallCallbackVtbl };
|
|
|
|
|
2012-05-30 13:22:46 +02:00
|
|
|
static void append_url_params( WCHAR *url )
|
|
|
|
{
|
|
|
|
static const WCHAR arch_formatW[] = {'?','a','r','c','h','='};
|
|
|
|
static const WCHAR v_formatW[] = {'&','v','='};
|
|
|
|
DWORD size = INTERNET_MAX_URL_LENGTH * sizeof(WCHAR);
|
|
|
|
DWORD len = strlenW(url);
|
|
|
|
|
|
|
|
memcpy(url+len, arch_formatW, sizeof(arch_formatW));
|
|
|
|
len += sizeof(arch_formatW)/sizeof(WCHAR);
|
|
|
|
len += MultiByteToWideChar(CP_ACP, 0, ARCH_STRING, sizeof(ARCH_STRING),
|
|
|
|
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, addon->version, -1, url+len, size/sizeof(WCHAR)-len);
|
|
|
|
}
|
|
|
|
|
2010-12-06 19:25:01 +01:00
|
|
|
static LPWSTR get_url(void)
|
|
|
|
{
|
2012-05-15 11:48:12 +02:00
|
|
|
DWORD size = INTERNET_MAX_URL_LENGTH*sizeof(WCHAR);
|
|
|
|
WCHAR *url, *config_key;
|
2010-12-06 19:25:01 +01:00
|
|
|
HKEY hkey;
|
|
|
|
DWORD res, type;
|
|
|
|
DWORD returned_size;
|
|
|
|
|
|
|
|
static const WCHAR httpW[] = {'h','t','t','p'};
|
|
|
|
|
|
|
|
url = heap_alloc(size);
|
|
|
|
returned_size = size;
|
|
|
|
|
2012-05-30 13:22:46 +02:00
|
|
|
hkey = open_config_key();
|
|
|
|
if (hkey)
|
|
|
|
{
|
|
|
|
config_key = heap_strdupAtoW(addon->url_config_key);
|
|
|
|
res = RegQueryValueExW(hkey, config_key, NULL, &type, (LPBYTE)url, &returned_size);
|
|
|
|
heap_free(config_key);
|
|
|
|
RegCloseKey(hkey);
|
|
|
|
if(res == ERROR_SUCCESS && type == REG_SZ) goto found;
|
2010-12-06 19:25:01 +01:00
|
|
|
}
|
|
|
|
|
2012-05-30 13:22:46 +02:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, addon->url_default, -1, url, size / sizeof(WCHAR) );
|
2010-12-06 19:25:01 +01:00
|
|
|
|
2012-05-30 13:22:46 +02:00
|
|
|
found:
|
|
|
|
if (returned_size > sizeof(httpW) && !memcmp(url, httpW, sizeof(httpW))) append_url_params( url );
|
2010-12-06 19:25:01 +01:00
|
|
|
|
|
|
|
TRACE("Got URL %s\n", debugstr_w(url));
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD WINAPI download_proc(PVOID arg)
|
|
|
|
{
|
|
|
|
WCHAR tmp_dir[MAX_PATH], tmp_file[MAX_PATH];
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
GetTempPathW(sizeof(tmp_dir)/sizeof(WCHAR), tmp_dir);
|
|
|
|
GetTempFileNameW(tmp_dir, NULL, 0, tmp_file);
|
|
|
|
|
|
|
|
TRACE("using temp file %s\n", debugstr_w(tmp_file));
|
|
|
|
|
|
|
|
hres = URLDownloadToFileW(NULL, url, tmp_file, 0, &InstallCallback);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
ERR("URLDownloadToFile failed: %08x\n", hres);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-09 15:48:47 +02:00
|
|
|
if(sha_check(tmp_file)) {
|
|
|
|
WCHAR *cache_file_name;
|
|
|
|
|
2011-02-10 16:42:49 +01:00
|
|
|
install_file(tmp_file);
|
2012-10-09 15:48:47 +02:00
|
|
|
|
|
|
|
cache_file_name = get_cache_file_name(TRUE);
|
|
|
|
if(cache_file_name) {
|
|
|
|
MoveFileW(tmp_file, cache_file_name);
|
|
|
|
heap_free(cache_file_name);
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
WCHAR message[256];
|
|
|
|
|
|
|
|
if(LoadStringW(hInst, IDS_INVALID_SHA, message, sizeof(message)/sizeof(WCHAR)))
|
|
|
|
MessageBoxW(NULL, message, NULL, MB_ICONERROR);
|
|
|
|
}
|
|
|
|
|
2010-12-06 19:25:01 +01:00
|
|
|
DeleteFileW(tmp_file);
|
|
|
|
EndDialog(install_dialog, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-07 18:28:04 +01:00
|
|
|
static void run_winebrowser(const WCHAR *url)
|
2010-12-06 19:25:01 +01:00
|
|
|
{
|
2011-12-07 18:28:04 +01:00
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
STARTUPINFOW si;
|
|
|
|
WCHAR app[MAX_PATH];
|
|
|
|
LONG len, url_len;
|
|
|
|
WCHAR *args;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
static const WCHAR winebrowserW[] = {'\\','w','i','n','e','b','r','o','w','s','e','r','.','e','x','e',0};
|
|
|
|
|
|
|
|
url_len = strlenW(url);
|
|
|
|
|
|
|
|
len = GetSystemDirectoryW(app, MAX_PATH-sizeof(winebrowserW)/sizeof(WCHAR));
|
|
|
|
memcpy(app+len, winebrowserW, sizeof(winebrowserW));
|
|
|
|
len += sizeof(winebrowserW)/sizeof(WCHAR) -1;
|
|
|
|
|
|
|
|
args = heap_alloc((len+1+url_len)*sizeof(WCHAR));
|
|
|
|
if(!args)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memcpy(args, app, len*sizeof(WCHAR));
|
|
|
|
args[len++] = ' ';
|
|
|
|
memcpy(args+len, url, (url_len+1) * sizeof(WCHAR));
|
2011-12-01 20:37:18 +01:00
|
|
|
|
2011-12-07 18:28:04 +01:00
|
|
|
TRACE("starting %s\n", debugstr_w(args));
|
|
|
|
|
|
|
|
memset(&si, 0, sizeof(si));
|
|
|
|
si.cb = sizeof(si);
|
2013-01-14 21:20:06 +01:00
|
|
|
ret = CreateProcessW(app, args, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &si, &pi);
|
2011-12-07 18:28:04 +01:00
|
|
|
heap_free(args);
|
|
|
|
if (ret) {
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static INT_PTR CALLBACK installer_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2010-12-06 19:25:01 +01:00
|
|
|
switch(msg) {
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
ShowWindow(GetDlgItem(hwnd, ID_DWL_PROGRESS), SW_HIDE);
|
|
|
|
install_dialog = hwnd;
|
|
|
|
return TRUE;
|
|
|
|
|
2011-12-01 20:37:18 +01:00
|
|
|
case WM_NOTIFY:
|
|
|
|
switch (((NMHDR *)lParam)->code)
|
|
|
|
{
|
|
|
|
case NM_CLICK:
|
|
|
|
case NM_RETURN:
|
|
|
|
if (wParam == ID_DWL_STATUS)
|
2011-12-07 18:28:04 +01:00
|
|
|
run_winebrowser(((NMLINK*)lParam)->item.szUrl);
|
2011-12-01 20:37:18 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-12-06 19:25:01 +01:00
|
|
|
case WM_COMMAND:
|
|
|
|
switch(wParam) {
|
|
|
|
case IDCANCEL:
|
|
|
|
EndDialog(hwnd, 0);
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
case ID_DWL_INSTALL:
|
|
|
|
ShowWindow(GetDlgItem(hwnd, ID_DWL_PROGRESS), SW_SHOW);
|
|
|
|
EnableWindow(GetDlgItem(hwnd, ID_DWL_INSTALL), 0);
|
|
|
|
EnableWindow(GetDlgItem(hwnd, IDCANCEL), 0); /* FIXME */
|
2011-12-30 21:53:54 +01:00
|
|
|
CloseHandle( CreateThread(NULL, 0, download_proc, NULL, 0, NULL));
|
2010-12-06 19:25:01 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-05-15 11:48:31 +02:00
|
|
|
BOOL install_addon(addon_t addon_type)
|
2010-12-06 19:25:01 +01:00
|
|
|
{
|
|
|
|
if(!*ARCH_STRING)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-05-15 11:48:31 +02:00
|
|
|
addon = addons_info+addon_type;
|
|
|
|
|
2012-10-09 15:48:47 +02:00
|
|
|
p_wine_get_dos_file_name = (void*)GetProcAddress(GetModuleHandleW(kernel32_dllW), "wine_get_dos_file_name");
|
|
|
|
|
2010-12-06 19:25:01 +01:00
|
|
|
/*
|
2012-05-15 11:48:31 +02:00
|
|
|
* Try to find addon .msi file in following order:
|
|
|
|
* - directory stored in $dir_config_key value of HKCU/Wine/Software/$config_key key
|
|
|
|
* - $datadir/$addon_subdir/
|
|
|
|
* - $INSTALL_DATADIR/wine/$addon_subdir/
|
|
|
|
* - /usr/share/wine/$addon_subdir/
|
|
|
|
* - download from URL stored in $url_config_key value of HKCU/Wine/Software/$config_key key
|
2010-12-06 19:25:01 +01:00
|
|
|
*/
|
2012-07-16 10:09:32 +02:00
|
|
|
if (install_from_registered_dir() == INSTALL_NEXT
|
|
|
|
&& install_from_default_dir() == INSTALL_NEXT
|
2012-10-09 15:48:47 +02:00
|
|
|
&& install_from_cache() == INSTALL_NEXT
|
2012-07-16 10:09:32 +02:00
|
|
|
&& (url = get_url()))
|
2012-05-17 16:19:10 +02:00
|
|
|
DialogBoxW(hInst, addon->dialog_template, 0, installer_proc);
|
2010-12-06 19:25:01 +01:00
|
|
|
|
|
|
|
heap_free(url);
|
|
|
|
url = NULL;
|
|
|
|
return TRUE;
|
|
|
|
}
|