removed os.h include
[swftools.git] / installer / installer.c
index 2b1fff5..ee1b3d0 100644 (file)
@@ -30,7 +30,6 @@
 #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;
@@ -56,7 +55,7 @@ static HINSTANCE me;
 
 #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);
@@ -100,6 +99,49 @@ void tball(HDC hdc, double px, double py, double sx, double sy)
     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 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)
 {
@@ -233,8 +275,9 @@ BOOL CALLBACK PropertySheetFunc2(HWND hwnd, UINT message, WPARAM wParam, LPARAM
     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) {
@@ -258,12 +301,14 @@ BOOL CALLBACK PropertySheetFunc2(HWND hwnd, UINT message, WPARAM wParam, LPARAM
 
        }
        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]));
@@ -374,6 +419,7 @@ BOOL CALLBACK PropertySheetFunc4(HWND hwnd, UINT message, WPARAM wParam, LPARAM
        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;
@@ -383,12 +429,15 @@ BOOL CALLBACK PropertySheetFunc4(HWND hwnd, UINT message, WPARAM wParam, LPARAM
                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);
 }
@@ -497,7 +546,6 @@ int WINAPI WinMain(HINSTANCE _me,HINSTANCE hPrevInst,LPSTR lpszArgs, int nWinMod
     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");