#include <stdlib.h>
#include "installer.h"
-#include "depack.h"
-
#include "../config.h" //for swftools version
-#include "../lib/os.h" //for registry functions
static int config_forAllUsers = 0;
static int config_createLinks = 0;
static char path_programfiles[MAX_PATH] = "\0";
extern char*crndata;
+extern int crndata_len;
+extern int crn_decompressed_size;
+
extern char*license_text;
static char*install_path = "c:\\swftools\\";
-static char pathBuf[1024];
+static char pathBuf[MAX_PATH];
static int do_abort = 0;
static char* pdf2swf_path;
#define USER_SETMESSAGE 0x7f01
-void tball(HDC hdc, double px, double py, double sx, double sy)
+static void tball(HDC hdc, double px, double py, double sx, double sy)
{
MoveToEx(hdc, 75.25*sx+px, -32.50*sy+py, 0);
LineTo(hdc, 74.75*sx+px, -24.80*sy+py); LineTo(hdc, 74.95*sx+px, -3.45*sy+py); LineTo(hdc, 75.25*sx+px, -32.50*sy+py);
LineTo(hdc, -25.70*sx+px, 128.45*sy+py); LineTo(hdc, -118.85*sx+px, 143.85*sy+py);
}
+static char* concatPaths(const char*base, const char*add)
+{
+ int l1 = strlen(base);
+ int l2 = strlen(add);
+ int pos = 0;
+ char*n = 0;
+ while(l1 && base[l1-1] == '\\')
+ l1--;
+ while(pos < l2 && add[pos] == '\\')
+ pos++;
+
+ n = (char*)malloc(l1 + (l2-pos) + 2);
+ memcpy(n,base,l1);
+ n[l1]='\\';
+ strcpy(&n[l1+1],&add[pos]);
+ return n;
+}
+
+static void handleTemplateFile(const char*filename)
+{
+ FILE*fi = fopen(filename, "rb");
+ fseek(fi, SEEK_END, 0);
+ int len = ftell(fi);
+ fseek(fi, SEEK_SET, 0);
+ char*file = malloc(len);
+ fread(file, len, 1, fi);
+ fclose(fi);
+ int l = strlen(install_path);
+ fi = fopen(filename, "wb");
+ char*pos = file;
+ char*lastpos = file;
+ while(1) {
+ pos = strstr(pos, "%%PATH%%");
+ if(!pos) {
+ pos = &file[len];
+ break;
+ }
+ if(pos!=lastpos)
+ fwrite(lastpos, pos-lastpos, 1, fi);
+ fwrite(install_path, l, 1, fi);
+ pos+=8; // length of "%%PATH%%"
+ lastpos = pos;
+ }
+ fwrite(lastpos, pos-lastpos, 1, fi);
+ fclose(fi);
+ free(file);
+}
+
+static char* getRegistryEntry(char*path)
+{
+ int res = 0;
+ HKEY key;
+ long rc;
+ long size = 0;
+ DWORD type;
+ char*buf;
+ rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, path, 0, KEY_ALL_ACCESS/* KEY_READ*/, &key);
+ if (rc != ERROR_SUCCESS) {
+ fprintf(stderr, "RegOpenKeyEx failed\n");
+ return 0;
+ }
+ rc = RegQueryValueEx(key, NULL, 0, 0, 0, (LPDWORD)&size) ;
+ if(rc != ERROR_SUCCESS) {
+ fprintf(stderr, "RegQueryValueEx(1) failed: %d\n", rc);
+ return 0;
+ }
+ buf = (char*)malloc(size+1);
+ rc = RegQueryValueEx(key, NULL, 0, &type, (BYTE*)buf, (LPDWORD)&size);
+ if(rc != ERROR_SUCCESS) {
+ fprintf(stderr, "RegQueryValueEx(2) failed: %d\n", rc);
+ return 0;
+ }
+ if(type == REG_SZ || type == REG_EXPAND_SZ) {
+ while(size && buf[size-1] == '\0')
+ --size;
+ buf[size] = 0;
+ /* TODO: convert */
+ return buf;
+ } else if(type == REG_BINARY) {
+ return buf;
+ }
+}
+
+static int setRegistryEntry(char*key,char*value)
+{
+ HKEY hkey1;
+ HKEY hkey2;
+ int ret1 = -1, ret2= -1;
+ ret1 = RegCreateKey(HKEY_CURRENT_USER, key, &hkey1);
+ if(config_forAllUsers) {
+ ret2 = RegCreateKey(HKEY_LOCAL_MACHINE, key, &hkey2);
+ }
+
+ if(ret1 && ret2) {
+ fprintf(stderr, "registry: CreateKey %s failed\n", key);
+ return 0;
+ }
+ if(!ret1)
+ ret1 = RegSetValue(hkey1, NULL, REG_SZ, value, strlen(value)+1);
+ if(!ret2)
+ ret2 = RegSetValue(hkey2, NULL, REG_SZ, value, strlen(value)+1);
+ if(ret1 && ret2) {
+ fprintf(stderr, "registry: SetValue %s failed\n", key);
+ return 0;
+ }
+ return 1;
+}
+
static HWND wnd_background = 0;
LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
return 1;
}
+static int CreateURL(const char*url, const char*path)
+{
+ FILE*fi = fopen(path, "wb");
+ if(!fi)
+ return 0;
+ fprintf(fi, "[InternetShortcut]\r\n");
+ fprintf(fi, "URL=http://localhost:8081/\r\n");
+ fclose(fi);
+ return 1;
+}
+
+
BOOL CALLBACK PropertySheetFuncCommon(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, int buttons)
{
LPNMHDR lpnm;
if(message == WM_INITDIALOG) {
SetDlgItemText(hwnd, IDC_INSTALL_PATH, install_path);
- SendDlgItemMessage(hwnd, IDC_ALLUSERS, BM_SETCHECK, 0, 0);
- SendDlgItemMessage(hwnd, IDC_CURRENTUSER, BM_SETCHECK, 1, 0);
+ config_forAllUsers = 0;
+ SendDlgItemMessage(hwnd, IDC_ALLUSERS, BM_SETCHECK, config_forAllUsers, 0);
+ SendDlgItemMessage(hwnd, IDC_CURRENTUSER, BM_SETCHECK, config_forAllUsers^1, 0);
}
if(message == WM_COMMAND) {
if((wParam&0xffff) == IDC_BROWSE) {
if(SHGetPathFromIDList(browse.pidlRoot, browse.pszDisplayName)) {
printf("Path is %s\n", browse.pszDisplayName);
install_path = browse.pszDisplayName;
+ int l = strlen(install_path);
+ while(l && install_path[l-1]=='\\') {
+ install_path[--l]=0;
+ }
}
}
SendDlgItemMessage(hwnd, IDC_INSTALL_PATH, WM_SETTEXT, 0, (LPARAM)install_path);
}
else if((wParam&0xffff) == IDC_ALLUSERS) {
- SendDlgItemMessage(hwnd, IDC_ALLUSERS, BM_SETCHECK, 1, 0);
- SendDlgItemMessage(hwnd, IDC_CURRENTUSER, BM_SETCHECK, 0, 0);
+ config_forAllUsers = 1;
+ SendDlgItemMessage(hwnd, IDC_ALLUSERS, BM_SETCHECK, config_forAllUsers, 0);
+ SendDlgItemMessage(hwnd, IDC_CURRENTUSER, BM_SETCHECK, config_forAllUsers^1, 0);
}
else if((wParam&0xffff) == IDC_CURRENTUSER) {
- SendDlgItemMessage(hwnd, IDC_ALLUSERS, BM_SETCHECK, 0, 0);
- SendDlgItemMessage(hwnd, IDC_CURRENTUSER, BM_SETCHECK, 1, 0);
+ config_forAllUsers = 0;
+ SendDlgItemMessage(hwnd, IDC_ALLUSERS, BM_SETCHECK, config_forAllUsers, 0);
+ SendDlgItemMessage(hwnd, IDC_CURRENTUSER, BM_SETCHECK, config_forAllUsers^1, 0);
}
else if((wParam&0xffff) == IDC_INSTALL_PATH) {
SendDlgItemMessage(hwnd, IDC_INSTALL_PATH, WM_GETTEXT, sizeof(pathBuf), (LPARAM)&(pathBuf[0]));
if(pathBuf[0]) {
install_path = pathBuf;
+ int l = strlen(install_path);
+ while(l && install_path[l-1]=='\\') {
+ install_path[--l]=0;
+ }
}
return 0;
}
if(text && text[0]=='[') return;
SetDlgItemText(statuswnd, IDC_INFO, strdup(text));
int t;
- /* There are usually 6 messages, and a range of 54 to fill, so
+ /* There are usually 4 messages, and a range of 40 to fill, so
step 9 times */
- for(t=0;t<9;t++) {
+ for(t=0;t<10;t++) {
SendDlgItemMessage(statuswnd, IDC_PROGRESS, PBM_SETPOS, ++progress_pos, 0);
processMessages();
Sleep(30);
}
}
}
+
+void print_space(char*dest, char*msg, ULONGLONG size)
+{
+ if(size < 1024)
+ sprintf(dest, "%s%d Bytes", msg, size);
+ else if(size < 1048576l)
+ sprintf(dest, "%s%.2f Kb", msg, size/1024.0);
+ else if(size < 1073741824l)
+ sprintf(dest, "%s%.2f Mb", msg, size/1048576.0);
+ else if(size < 1099511627776ll)
+ sprintf(dest, "%s%.2f Gb", msg, size/1073741824.0);
+ else
+ sprintf(dest, "%s%.2f Tb", msg, size/1125899906842624.0);
+}
+
BOOL CALLBACK PropertySheetFunc3(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
HWND dialog = GetParent(hwnd);
if(message == WM_INITDIALOG) {
SetDlgItemText(hwnd, IDC_INFO, "Ready to install");
+
+ char buf[256];
+ print_space(buf, "Space required: ", crn_decompressed_size);
+ SetDlgItemText(hwnd, IDC_SPACE1, buf);
+ ULARGE_INTEGER available,total,totalfree;
+ available.QuadPart=0;
+ total.QuadPart=0;
+ totalfree.QuadPart=0;
+ GetDiskFreeSpaceEx(install_path, &available, &total, &totalfree);
+ print_space(buf, "Space available: ", available.QuadPart);
+ SetDlgItemText(hwnd, IDC_SPACE2, buf);
}
if(message == WM_NOTIFY && (((LPNMHDR)lParam)->code == PSN_WIZNEXT)) {
+ SetDlgItemText(hwnd, IDC_SPACE1, "");
+ SetDlgItemText(hwnd, IDC_SPACE2, "");
PropSheet_SetWizButtons(dialog, 0);
SendMessage(dialog, PSM_CANCELTOCLOSE, 0, 0); //makes wine display a warning
SetDlgItemText(hwnd, IDC_TITLE, "Installing files...");
statuswnd = hwnd;
- SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETRANGE, 0, (LPARAM)MAKELONG(0,54));
+ SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETRANGE, 0, (LPARAM)MAKELONG(0,40));
progress_pos = 0;
SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETPOS, progress_pos, 0);
- int success = unpack_archive(crndata, install_path, PropertyArchiveStatus);
+ int success = unpack_archive(crndata, crndata_len, install_path, PropertyArchiveStatus);
+ if(!success) {
+ MessageBox(0, "Couldn't extract all installation files", "SWFTools Install", MB_OK|MB_ICONERROR);
+ do_abort=1;
+ exit(1);
+ }
return 0;
}
return PropertySheetFuncCommon(hwnd, message, wParam, lParam, PSWIZB_BACK|PSWIZB_NEXT);
pdf2swf_path = concatPaths(install_path, "pdf2swf_gui.exe");
FILE*fi = fopen(pdf2swf_path, "rb");
if(fi) {
+ printf("a GUI program exists, creating desktop/startmenu links\n");
config_createLinks = 1;
fclose(fi);
}
if(config_createLinks) {
if(config_createDesktop && path_desktop[0]) {
char* linkName = concatPaths(path_desktop, "pdf2swf.lnk");
+ printf("Creating desktop link %s -> %s\n", linkName, pdf2swf_path);
if(!CreateShortcut(pdf2swf_path, "pdf2swf", linkName, 0, 0, 0, install_path)) {
MessageBox(0, "Couldn't create desktop shortcut", "Install.exe", MB_OK);
return 1;
char* group = concatPaths(path_startmenu, "pdf2swf");
CreateDirectory(group, 0);
char* linkName = concatPaths(group, "pdf2swf.lnk");
+ printf("Creating %s -> %s\n", linkName, pdf2swf_path);
if(!CreateShortcut(pdf2swf_path, "pdf2swf", linkName, 0, 0, 0, install_path)) {
MessageBox(0, "Couldn't create start menu entry", "Install.exe", MB_OK);
return 1;
}
}
- }
+ } else {
+ printf("not creating desktop/startmenu links\n");
+ }
}
return PropertySheetFuncCommon(hwnd, message, wParam, lParam, PSWIZB_FINISH);
}
logo = LoadBitmap(me, "SWFTOOLS");
install_path = getRegistryEntry("Software\\quiss.org\\swftools\\InstallPath");
- install_path = 0;
if(!install_path || !install_path[0]) {
if(path_programfiles[0]) {
install_path = concatPaths(path_programfiles, "SWFTools");