pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] rev 2296 - in trunk/contrib/windows_installer/src: . BlueZi


From: address@hidden
Subject: [Pingus-CVS] rev 2296 - in trunk/contrib/windows_installer/src: . BlueZip
Date: Sun, 18 Apr 2004 22:54:42 +0200

Author: torangan
Date: 2004-04-18 22:54:42 +0200 (Sun, 18 Apr 2004)
New Revision: 2296

Modified:
   trunk/contrib/windows_installer/src/BlueZip/BlueZip.cpp
   trunk/contrib/windows_installer/src/BlueZip/BlueZip.h
   trunk/contrib/windows_installer/src/FileCode.cpp
   trunk/contrib/windows_installer/src/FileCode.h
   trunk/contrib/windows_installer/src/Installer.rc
   trunk/contrib/windows_installer/src/ShellCode.cpp
   trunk/contrib/windows_installer/src/StartCode.cpp
   trunk/contrib/windows_installer/src/resource.h
Log:
display space on drive, better error handling


Modified: trunk/contrib/windows_installer/src/BlueZip/BlueZip.cpp
===================================================================
--- trunk/contrib/windows_installer/src/BlueZip/BlueZip.cpp     2004-04-18 
18:05:19 UTC (rev 2295)
+++ trunk/contrib/windows_installer/src/BlueZip/BlueZip.cpp     2004-04-18 
20:54:42 UTC (rev 2296)
@@ -1,6 +1,6 @@
 #include "BlueHead.h"
 
-BlueZip::BlueZip(LPCTSTR FileName)
+void BlueZip::Setup(LPCTSTR FileName)
 {
        this->FileName = CopyString(FileName);
 

Modified: trunk/contrib/windows_installer/src/BlueZip/BlueZip.h
===================================================================
--- trunk/contrib/windows_installer/src/BlueZip/BlueZip.h       2004-04-18 
18:05:19 UTC (rev 2295)
+++ trunk/contrib/windows_installer/src/BlueZip/BlueZip.h       2004-04-18 
20:54:42 UTC (rev 2296)
@@ -13,6 +13,8 @@
        bool ScanZip(File f);
        void ReadEnd(File f);
 
+       void Setup(LPCTSTR FileName);
+
 #ifndef NO_COMPRESSION
        fList* Pending; // List of names to add
        void WriteEnd(File f);
@@ -24,7 +26,10 @@
        zList* Files;                   // A point to the first file in the ZIP
 
 
-       BlueZip(LPCTSTR FileName);
+       BlueZip(){};
+       BlueZip(LPCTSTR FileName){Setup(FileName);}
+       void SetZipFile(LPCTSTR FileName){Setup(FileName);}
+
        ~BlueZip();
 
        bool Read(); //Load the file into memory

Modified: trunk/contrib/windows_installer/src/FileCode.cpp
===================================================================
--- trunk/contrib/windows_installer/src/FileCode.cpp    2004-04-18 18:05:19 UTC 
(rev 2295)
+++ trunk/contrib/windows_installer/src/FileCode.cpp    2004-04-18 20:54:42 UTC 
(rev 2296)
@@ -28,26 +28,74 @@
                if (File[i] == '/')
                        File[i] = '\\';
        }
+       if (File[i-1] == '\\')
+               File[i-1] = 0;
 }
 
-// The first file passed must end in a \\ character
-bool CreateFolder(char* File)
+bool ParentFolder(char* File)
 {
        char* s = strrchr(File, '\\');
        if (s == NULL)
                return false;
 
-       int BufChar = s[0];
        s[0] = 0;
-       bool Success = false;
-       if (!CreateDirectory(File, NULL))
+       return true;
+}
+
+void UnparentFolder(char* File)
+{
+       File[strlen(File)] = '\\';
+}
+
+
+bool EnsureFolder(char* File)
+{
+       if (ExistsDir(File))
+               return true;
+
+       if (ParentFolder(File))
        {
-               if (CreateFolder(File) && CreateDirectory(File, NULL))
-                       Success = true;
+               bool Res = EnsureFolder(File);
+               UnparentFolder(File);
+               if (!Res) return false;
        }
+
+       return (CreateDirectory(File, NULL) != 0);
+}
+
+void FileSize(__int64 Size, char* Buffer)
+{
+       //set the number of bytes as a Windows standard file count
+       const TCHAR PreFix[] = "KMGTP";
+       //make sure to 3 sf
+
+       if (Size < 1000)
+       {
+               itoa((int) Size, Buffer, 10);
+               strcat(Buffer, " bytes");
+       }
        else
-               Success = true;
+       {
+               int i, j = 1024;
+               for (i = 0; Size > j * 999; i++)
+                       j *= 1024;
 
-       s[0] = BufChar;
-       return Success;
+               itoa((int) (Size / (__int64) j), Buffer, 10);
+               int k = strlen(Buffer);
+               if (k != 3)
+               {
+                       Buffer[k] = '.';
+                       j = ((int) (Size % j) * 1000) / j;
+                       int l = 100;
+                       for (k++; k != 4; k++)
+                       {
+                               Buffer[k] = (j / l) + '0';
+                               j %= l;
+                               l /= 10;
+                       }
+               }
+               Buffer[k + 0] = PreFix[i];
+               Buffer[k + 1] = 'B';
+               Buffer[k + 2] = 0;
+       }
 }

Modified: trunk/contrib/windows_installer/src/FileCode.h
===================================================================
--- trunk/contrib/windows_installer/src/FileCode.h      2004-04-18 18:05:19 UTC 
(rev 2295)
+++ trunk/contrib/windows_installer/src/FileCode.h      2004-04-18 20:54:42 UTC 
(rev 2296)
@@ -4,4 +4,7 @@
 bool ExistsDir(char* File);
 bool CanReadWrite(char* File);
 void NormalPath(char* File);
-bool CreateFolder(char* File);
+bool EnsureFolder(char* File);
+void FileSize(__int64 Size, char* Buffer);
+
+const int MaxFileSizeBuf = 10;

Modified: trunk/contrib/windows_installer/src/Installer.rc
===================================================================
--- trunk/contrib/windows_installer/src/Installer.rc    2004-04-18 18:05:19 UTC 
(rev 2295)
+++ trunk/contrib/windows_installer/src/Installer.rc    2004-04-18 20:54:42 UTC 
(rev 2296)
@@ -27,18 +27,18 @@
 // TEXTINCLUDE
 //
 
-1 TEXTINCLUDE DISCARDABLE 
+1 TEXTINCLUDE DISCARDABLE
 BEGIN
     "resource.h\0"
 END
 
-2 TEXTINCLUDE DISCARDABLE 
+2 TEXTINCLUDE DISCARDABLE
 BEGIN
     "#include ""afxres.h""\r\n"
     "\0"
 END
 
-3 TEXTINCLUDE DISCARDABLE 
+3 TEXTINCLUDE DISCARDABLE
 BEGIN
     "\r\n"
     "\0"
@@ -69,14 +69,15 @@
     CONTROL         "Run program after installation",chkExecute,"Button",
                     BS_AUTOCHECKBOX | WS_TABSTOP,7,140,294,11
     CONTROL         "Create shortcut on Desktop",chkShortcutDesktop,"Button",
-                    BS_AUTOCHECKBOX | WS_TABSTOP,7,100,294,10
+                    BS_AUTOCHECKBOX | WS_TABSTOP,7,114,294,10
     CONTROL         "",IDC_STATIC,"Static",SS_ETCHEDHORZ,-1,164,311,1
     LTEXT           "Windows Installer � Neil Mitchell 1999-2004",IDC_STATIC,
                     7,176,155,10,WS_DISABLED
     CONTROL         "Progress2",prgBar,"msctls_progress32",NOT WS_VISIBLE,7,
                     74,294,12
     CONTROL         "Create shortcut in the Start Menu",chkShortcutStart,
-                    "Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,111,294,10
+                    "Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,124,294,10
+    LTEXT           "#",lblSpace,7,89,294,9
 END
 
 
@@ -86,7 +87,7 @@
 //
 
 #ifdef APSTUDIO_INVOKED
-GUIDELINES DESIGNINFO DISCARDABLE 
+GUIDELINES DESIGNINFO DISCARDABLE
 BEGIN
     dlgInstall, DIALOG
     BEGIN

Modified: trunk/contrib/windows_installer/src/ShellCode.cpp
===================================================================
--- trunk/contrib/windows_installer/src/ShellCode.cpp   2004-04-18 18:05:19 UTC 
(rev 2295)
+++ trunk/contrib/windows_installer/src/ShellCode.cpp   2004-04-18 20:54:42 UTC 
(rev 2296)
@@ -1,6 +1,7 @@
 #include "Header.h"
 #include "Parameters.h"
 #include <shlobj.h>
+#include "FileCode.h"
 
 
 bool OleReady;
@@ -94,12 +95,11 @@
                return false;
 
        strcat(Destination, "\\" ProgramName);
-       if (!CreateDirectory(Destination, NULL))
+       if (!EnsureFolder(Destination))
                return false;
 
+       strcat(Destination, "\\");
        char* i = &Destination[strlen(Destination)];
-       i[0] = '\\';
-       i++;
 
        char Target[MyMaxPath];
        strcpy(Target, Folder);
@@ -124,7 +124,21 @@
 
 
 
+int CALLBACK BrowseCallbackProc(HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM 
lpData)
+{
+       switch(uMsg)
+       {
+       case BFFM_INITIALIZED:
+               char Buffer[MyMaxPath];
+               GetWindowText((HWND) lpData, Buffer, MyMaxPath);
+               SendMessage(hWnd, BFFM_SETSELECTION, TRUE, (LPARAM) Buffer);
+               break;
+       }
 
+       return 0;
+}
+
+
 void Browse(HWND hDlg, HWND hText)
 {
        const int bif_NEWDIALOGSTYLE = 0x40;
@@ -133,10 +147,10 @@
        bi.hwndOwner = hDlg;
        bi.pidlRoot = NULL;
        bi.pszDisplayName = NULL;
-       bi.lpszTitle = "Please select the installation folder";
+       bi.lpszTitle = "Select the installation folder for " ProgramName;
        bi.ulFlags = BIF_RETURNONLYFSDIRS | bif_NEWDIALOGSTYLE;
-       bi.lpfn = NULL;
-       bi.lParam = 0;
+       bi.lpfn = &BrowseCallbackProc;
+       bi.lParam = (LPARAM) hText;
        bi.iImage = 0;
 
        LPITEMIDLIST idl = SHBrowseForFolder(&bi);

Modified: trunk/contrib/windows_installer/src/StartCode.cpp
===================================================================
--- trunk/contrib/windows_installer/src/StartCode.cpp   2004-04-18 18:05:19 UTC 
(rev 2295)
+++ trunk/contrib/windows_installer/src/StartCode.cpp   2004-04-18 20:54:42 UTC 
(rev 2296)
@@ -2,6 +2,7 @@
 #include "FileCode.h"
 #include "ShellCode.h"
 #include <commctrl.h>
+#include <stdio.h>
 
 
 #define PLAY_NICELY
@@ -10,10 +11,8 @@
 #include "resource.h"
 #include "Parameters.h"
 
-//Really no clue whats up with handles, needs more investigating (culprit - 
BlueZip!!)
 
 
-
 #define ErrBox(Msg)                            MessageBox(hDlg, Msg, 
ProgramName " Installer", MB_ICONERROR)
 #define QuestBox(Msg, Flag)            MessageBox(hDlg, Msg, ProgramName " 
Installer", MB_ICONQUESTION | Flag)
 #define InfoBox(Msg)                   MessageBox(hDlg, Msg, ProgramName " 
Installer", MB_ICONINFORMATION)
@@ -21,9 +20,19 @@
 // GLOBAL STATE
 HINSTANCE hInst;
 bool InDoEvents = false;
+BlueZip zip;
+
+int TotalCompSize;
+int TotalRealSize;
 // END GLOBAL STATE
 
 
+//Predefines
+void PathChanged(HWND hDlg);
+//end
+
+
+
 void InitDialog(HWND hDlg)
 {
        InitCommonControls();
@@ -37,8 +46,69 @@
        CheckDlgButton(hDlg, chkExecute, BST_CHECKED);
        CheckDlgButton(hDlg, chkShortcutDesktop, BST_CHECKED);
        CheckDlgButton(hDlg, chkShortcutStart, BST_CHECKED);
+
+       char ZipFile[MyMaxPath];
+       GetModuleFileName(hInst, ZipFile, MyMaxPath);
+
+#ifdef _DEBUG
+       //make practical debugging a reality
+       strcat(ZipFile, ".zip");
+#endif
+
+       zip.SetZipFile(ZipFile);
+       if (!zip.Read())
+       {
+               ErrBox("Corrupt installer data, please try redownloading");
+               DestroyWindow(hDlg);
+               return;
+       }
+
+       TotalCompSize = 0;
+       TotalRealSize = 0;
+       for (zList* i = zip.Files; i != NULL; i = i->next)
+       {
+               TotalCompSize += i->CompressedSize();
+               TotalRealSize += i->OriginalSize();
+       }
+       PathChanged(hDlg);
 }
 
+void PathChanged(HWND hDlg)
+{
+       static char LastPath = -1;
+       char Buffer[MyMaxPath];
+
+       GetDlgItemText(hDlg, txtEdit, Buffer, MyMaxPath);
+       char NewLastPath;
+       if (Buffer[1] == ':')
+               NewLastPath = toupper(Buffer[0]);
+       else
+               NewLastPath = 0;
+       if ((NewLastPath > 'Z') || (NewLastPath < 'A'))
+               NewLastPath = 0;
+
+       if (LastPath == NewLastPath)
+               return;
+       LastPath = NewLastPath;
+
+       char Buf[MaxFileSizeBuf];
+       FileSize(TotalRealSize, Buf);
+       int Len = sprintf(Buffer, "Space required is %s", Buf);
+
+       if (LastPath != 0)
+       {
+               ULARGE_INTEGER DriveSpace;
+               char Buf[4] = {LastPath, ':', '\\', 0};
+               if (!GetDiskFreeSpaceEx(Buf, &DriveSpace, NULL, NULL))
+                       DriveSpace.QuadPart = 0;
+
+               FileSize(DriveSpace.QuadPart, Buf);
+               sprintf(&Buffer[Len], ", installing on drive %c: which has %s 
free", LastPath, Buf);
+       }
+
+       SetDlgItemText(hDlg, lblSpace, Buffer);
+}
+
 void PaintDialog(HWND hDlg)
 {
        const char* Msg = ProgramName " - " Description "\n� " Copyright;
@@ -82,34 +152,10 @@
 
 bool DoInstall(char* InstallTo, bool RunOnEnd, HWND hDlg)
 {
-       char ZipFile[MyMaxPath];
-       GetModuleFileName(hInst, ZipFile, MyMaxPath);
-
-#ifdef _DEBUG
-       //make practical debugging a reality
-       strcat(ZipFile, ".zip");
-#endif
-
-       BlueZip b(ZipFile);
-       if (!b.Read())
-       {
-               ErrBox("Corrupt installer data, please try redownloading");
-               return true;
-       }
-
        //Now replace / with \ to make it less confusing
+       //And guarantee it has no trailing slash
        NormalPath(InstallTo);
 
-       //And guarantee it has a trailing slash
-       int BufLen = strlen(InstallTo);
-       char* BufPos = &InstallTo[BufLen];
-       if ((BufLen > 0) && (BufPos[-1] != '\\'))
-       {
-               BufPos[0] = '\\';
-               BufPos++;
-               BufPos[0] = 0;
-       }
-       
 
        //Now see if you can create the directory
        if (ExistsDir(InstallTo))
@@ -121,15 +167,16 @@
        }
        else
        {
-               if (!CreateFolder(InstallTo))
+               if (!EnsureFolder(InstallTo))
                {
                        ErrBox("Could not create the specified directory");
                        return false;
                }
        }
 
-
-
+       strcat(InstallTo, "\\");
+       int BufLen = strlen(InstallTo);
+       char* BufPos = &InstallTo[BufLen];
        //Buffer is C:\\Program Files\\ProgramDir\\<space>
        //BufPos is <space>
 
@@ -156,29 +203,27 @@
        }
 
        const int PrgFactor = 4096;
-       int Sum = 0;
-       for (zList* i = b.Files; i != NULL; i = i->next)
-               Sum += i->CompressedSize();
-       SendDlgItemMessage(hDlg, prgBar, PBM_SETRANGE, 0, MAKELPARAM(0, Sum / 
PrgFactor));
-       Sum = 0;
+       SendDlgItemMessage(hDlg, prgBar, PBM_SETRANGE, 0, MAKELPARAM(0, 
TotalCompSize / PrgFactor));
+       int Done = 0;
 
 
        //now you have access to at least the file Str
        //extract all the files
-       for (i = b.Files; i != NULL; i = i->next)
+       for (zList* i = zip.Files; i != NULL; i = i->next)
        {
-               SendDlgItemMessage(hDlg, prgBar, PBM_SETPOS, Sum / PrgFactor, 
0);
-               Sum += i->CompressedSize();
+               Done += i->CompressedSize();
 
                strcpy(BufPos, i->FileName);
+               char LastChar = BufPos[strlen(BufPos)-1];
+               bool IsFolder = ((LastChar == '\\') || (LastChar == '/'));
                NormalPath(BufPos);
-               SetDlgItemText(hDlg, lblInstallFile, InstallTo);
+               SetDlgItemText(hDlg, lblInstallFile, BufPos);
                DoEvents();
-               
+
                //if the last char is a '\' then directory
-               if (BufPos[strlen(BufPos)-1] == '\\')
+               if (IsFolder)
                {
-                       if (!ExistsDir(InstallTo) && !CreateFolder(InstallTo))
+                       if (!EnsureFolder(InstallTo))
                        {
                                ErrDialog(hDlg, "Could not create the 
directory\n\n", InstallTo);
                                return false;
@@ -187,14 +232,14 @@
                else
                {
                        if ( (Exists(InstallTo) && !DeleteFile(InstallTo)) ||
-                                (!b.GetFile(i, InstallTo)))
+                                (!zip.GetFile(i, InstallTo)))
                        {
                                ErrDialog(hDlg, "Could not extract the 
file\n\n", InstallTo);
                                return false;
                        }
                }
+               SendDlgItemMessage(hDlg, prgBar, PBM_SETPOS, Done / PrgFactor, 
0);
        }
-       SendDlgItemMessage(hDlg, prgBar, PBM_SETPOS, Sum / PrgFactor, 0);
        SetDlgItemText(hDlg, lblInstallFile, "Finalising...");
 
        //now InstallTo is the install directory, plus a \\ character
@@ -293,6 +338,11 @@
                case cmdBrowse:
                        Browse(hDlg, GetDlgItem(hDlg, txtEdit));
                        break;
+
+               case txtEdit:
+                       if ((HIWORD(wParam) == EN_CHANGE) && (TotalRealSize != 
0))
+                               PathChanged(hDlg);
+                       break;
                }
                break;
        }

Modified: trunk/contrib/windows_installer/src/resource.h
===================================================================
--- trunk/contrib/windows_installer/src/resource.h      2004-04-18 18:05:19 UTC 
(rev 2295)
+++ trunk/contrib/windows_installer/src/resource.h      2004-04-18 20:54:42 UTC 
(rev 2296)
@@ -15,14 +15,15 @@
 #define lblWelcome                      1013
 #define lblInstallTo                    1014
 #define lblInstallFile                  1015
+#define lblSpace                        1016
 
 // Next default values for new objects
-// 
+//
 #ifdef APSTUDIO_INVOKED
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NEXT_RESOURCE_VALUE        107
 #define _APS_NEXT_COMMAND_VALUE         40001
-#define _APS_NEXT_CONTROL_VALUE         1016
+#define _APS_NEXT_CONTROL_VALUE         1017
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif





reply via email to

[Prev in Thread] Current Thread [Next in Thread]