changed statusfunc to a struct
[swftools.git] / installer / installer.c
index 9d2fed7..dc6f36a 100644 (file)
@@ -27,8 +27,6 @@
 #include <stdlib.h>
 #include "installer.h"
 
-#include "depack.h"
-
 #include "../config.h" //for swftools version
 
 static int config_forAllUsers = 0;
@@ -41,6 +39,9 @@ static char path_desktop[MAX_PATH] = "\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\\";
@@ -412,9 +413,9 @@ void PropertyArchiveStatus(int type, char*text)
     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);
@@ -427,20 +428,53 @@ void PropertyArchiveStatus(int type, char*text)
        }
     }
 }
+
+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);
@@ -453,6 +487,7 @@ BOOL CALLBACK PropertySheetFunc4(HWND hwnd, UINT message, WPARAM wParam, LPARAM
        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);
        }