]>
git.saurik.com Git - wxWidgets.git/blob - utils/Install/instsup.cpp
2 * instsup.c (c) 1999,2000 Brian Smith
17 #if defined(__OS2__) || defined(__EMX__) || defined(WIN32) || defined(WINNT)
20 #include <sys/types.h>
27 extern char *INSTALLER_TITLE
;
28 extern char *INSTALLER_PROGRAM
;
29 extern char *INSTALLER_FOLDER
;
30 extern char *INSTALLER_SHADOW
;
31 extern char *INSTALLER_OBJECT
;
32 extern char tempPath
[], installdir
[], csfile
[], bufile
[], bootdrive
[], instlog
[], installdir2
[];
33 extern int installstate
, success
;
41 char *replaceem(char *orig
);
43 int sendmessage(int destination
, int messid
)
46 /* Update percentage bar */
57 extern wxCondition
*InstCond
;
59 InstCond
->Broadcast();
71 /* This should return the current color depth */
72 unsigned long color_depth(void)
75 HDC hdc
= WinOpenWindowDC(HWND_DESKTOP
);
78 DevQueryCaps(hdc
, CAPS_COLORS
, 1, &colors
);
86 * Call the reboot vector.
93 #define REBOOTDEV "\\DEV\\DOS$"
99 rc
= DosOpen(REBOOTDEV
,
105 OPEN_SHARE_DENYNONE
| OPEN_ACCESS_READWRITE
,
124 * Display an informational dialog box to the user with the given text.
126 int mesg(char *format
, ...) {
130 va_start(args
, format
);
131 vsprintf(outbuf
, format
, args
);
134 wxMessageBox(outbuf
, INSTALLER_TITLE
,
135 wxOK
| wxICON_EXCLAMATION
, NULL
);
137 return strlen(outbuf
);
140 int checktext(char *text
, char *buffer
, int buflen
)
142 int z
, len
= strlen(text
);
144 for(z
=0;z
<(buflen
-len
);z
++)
146 if(memcmp(text
, &buffer
[z
], len
) == 0)
154 * Returns the offset withing the executable to the specified text.
156 long findtext(char *text
)
160 unsigned long curpos
= 0;
162 fseek(self
, 0, SEEK_SET
);
163 fread(buffer
, 1, 512, self
);
164 if((offset
= checktext(text
, buffer
, 512)) > -1)
168 memcpy(buffer
, &buffer
[256], 256);
169 fread(&buffer
[256], 1, 256, self
);
171 if((offset
= checktext(text
, buffer
, 512)) > -1)
172 return offset
+curpos
;
178 /* We encode archive search text so we don't get confused
179 * by the string table - I was using LXLite to take care
180 * of this problem on OS/2 but in portable code this may
181 * not be an option. */
182 char *decode(char *input
)
187 result
= (char *)malloc(strlen(input
) / 2 + 1);
189 while (input
[0] && input
[1])
191 result
[i
] = ((input
[0] - 0x41) << 4) | (input
[1] - 0x41);
201 * Removes any carriage returns or line feeds from the buffer.
203 void stripcrlf(char *buffer
)
205 int z
, len
= strlen(buffer
);
209 if(buffer
[z
] == '\r' || buffer
[z
] == '\n')
218 * Returns the space free on a given drive... where 0 is A: in MB
220 unsigned long drivefree(int drive
)
223 ULONG aulFSInfoBuf
[40] = {0};
224 APIRET rc
= NO_ERROR
;
227 DosError(FERR_DISABLEHARDERR
);
228 rc
= DosQueryFSInfo(drive
,
231 sizeof(aulFSInfoBuf
));
233 DosError(FERR_ENABLEHARDERR
);
237 bytesFree
= (double)aulFSInfoBuf
[3] * (double)aulFSInfoBuf
[1] * (USHORT
)aulFSInfoBuf
[4];
238 return (unsigned long)(bytesFree
/ (1024.0 * 1024.0));
245 * Display a fatal error message and set the abort flag in case we are in a secondary thread.
247 void error(char *format
, ...) {
249 char errstring
[1024];
251 va_start(args
, format
);
252 vsprintf(errstring
, format
, args
);
255 if(installstate
!= ABORTED
)
258 installstate
=ABORTED
;
260 wxMessageBox(errstring
, INSTALLER_TITLE
,
261 wxOK
| wxICON_EXCLAMATION
, NULL
);
264 void setdrivedir(char *drivedir
)
266 wxSetWorkingDirectory(drivedir
);
270 * Make the TEMP directory the current directory, or the root directory of the boot drive.
272 void settempdir(void)
274 #if defined(__EMX__) || defined(__OS2__) || defined(WIN32) || defined(WINNT)
275 /* Windows or OS/2 */
276 char *envdir
= getenv("TMP");
280 envdir
= getenv("TEMP");
282 envdir
= replaceem("%BOOTDRIVE%:\\");
283 strcpy(tempPath
,envdir
);
284 len
= strlen(tempPath
);
285 if (len
> 3 && tempPath
[len
-1] == '\\')
288 setdrivedir(tempPath
);
295 void getbootdrive(void)
297 /* On windows I don't think you can boot from anything
298 except C: drive. So I am not going to do anything here. */
301 void PM_backslash(char *s
)
303 unsigned int pos
= strlen(s
);
304 if (s
[pos
-1] != '\\') {
311 * Makes a folder on the desktop.
313 void MakeFolder(char Title
[], char Icon
[], char dest
[], char id
[], char setup
[])
318 memset(szArg
,0,sizeof(szArg
));
320 if ((Icon
!= NULL
) && (strlen(Icon
) != 0))
322 strcat(szArg
,"ICONFILE=");
326 if ((id
!= NULL
) && (strlen(id
) != 0))
328 strcat(szArg
,";OBJECTID=");
332 if ((setup
!= NULL
) && (strlen(setup
) != 0))
338 WinCreateObject("WPFolder",Title
,szArg
,dest
,CO_REPLACEIFEXISTS
);
340 char startpath
[MAX_PATH
];
343 if(!SHGetSpecialFolderLocation(NULL
, CSIDL_PROGRAMS
, &pidl
))
345 SHGetPathFromIDList(pidl
, startpath
);
347 if(startpath
[strlen(startpath
)-1] != '\\')
348 strcat(startpath
, "\\");
349 strcat(startpath
, Title
);
350 CreateDirectory(startpath
, NULL
);
358 HRESULT
CreateLink(LPCSTR lpszPathObj
,
359 LPSTR lpszPathLink
, LPSTR lpszDesc
)
364 // Get a pointer to the IShellLink interface.
365 hres
= CoCreateInstance(CLSID_ShellLink
, NULL
,
366 CLSCTX_INPROC_SERVER
, IID_IShellLink
, (void **)&psl
);
367 if (SUCCEEDED(hres
)) {
370 // Set the path to the shortcut target, and add the
372 psl
->SetPath(lpszPathObj
);
374 psl
->SetDescription(lpszDesc
);
376 // Query IShellLink for the IPersistFile interface for saving the
377 // shortcut in persistent storage.
378 hres
= psl
->QueryInterface(IID_IPersistFile
,
381 if (SUCCEEDED(hres
)) {
384 // Ensure that the string is ANSI.
385 MultiByteToWideChar(CP_ACP
, 0, lpszPathLink
, -1,
389 // Save the link by calling IPersistFile::Save.
390 hres
= ppf
->Save(wsz
, TRUE
);
400 * Makes a Program object on the desktop.
402 void MakeProgram(char Title
[], char Program
[], char Icon
[], char dest
[], char id
[], char setup
[])
407 memset(szArg
,0,sizeof(szArg
));
409 strcat(szArg
,"EXENAME=");
410 strcat(szArg
,Program
);
412 if ((Icon
!= NULL
) && (strlen(Icon
) != 0))
414 strcat(szArg
,";ICONFILE=");
418 if ((id
!= NULL
) && (strlen(id
) != 0))
420 strcat(szArg
,";OBJECTID=");
424 if ((setup
!= NULL
) && (strlen(setup
) != 0))
430 WinCreateObject("WPProgram",Title
,szArg
,dest
,CO_REPLACEIFEXISTS
);
432 char startpath
[MAX_PATH
];
435 if(!SHGetSpecialFolderLocation(NULL
, CSIDL_PROGRAMS
, &pidl
))
437 SHGetPathFromIDList(pidl
, startpath
);
439 if(startpath
[strlen(startpath
)-1] != '\\')
440 strcat(startpath
, "\\");
441 strcat(startpath
, dest
);
442 strcat(startpath
, "\\");
443 strcat(startpath
, Title
);
444 strcat(startpath
, ".lnk");
447 CreateLink(Program
, startpath
, Title
);
457 * Makes a user defined object on the desktop.
459 void MakeObject(char Title
[], char oclass
[], char dest
[], char id
[], char setup
[])
464 memset(szArg
,0,sizeof(szArg
));
466 if ((oclass
== NULL
) || (strlen(oclass
) == 0))
469 if ((id
!= NULL
) && (strlen(id
) != 0))
471 strcat(szArg
,"OBJECTID=");
475 if ((setup
!= NULL
) && (strlen(setup
) != 0))
477 if ((id
!= NULL
) && (strlen(id
) != 0))
482 WinCreateObject(oclass
,Title
,szArg
,dest
,CO_REPLACEIFEXISTS
);
484 /* Not sure if there is an equivilent on Windows */
490 * Makes a shadow on the desktop.
492 void MakeShadow(char Title
[], char reference
[], char dest
[], char id
[])
497 memset(szArg
,0,sizeof(szArg
));
499 strcpy(szArg
,"SHADOWID=");
500 strcat(szArg
,reference
);
501 if ((id
!= NULL
) && (strlen(id
) != 0))
503 strcat(szArg
,";OBJECTID=");
507 WinCreateObject("WPShadow",Title
,szArg
,dest
,CO_REPLACEIFEXISTS
);
509 /* Nothing like this on Windows9x anyway */
515 /* This creates program objects on the desktop, it was originally designed
516 * for the OS/2 Workplace Shell so it may be somewhat different in use on
519 void create_wps_objects(void)
521 char *arg1
, *arg2
, *arg3
, *arg4
, *arg5
, *arg6
;
523 char zerotext
[2] = "";
526 /* No distinction for the moment... this may change.. */
527 strcpy(installdir2
, installdir
);
529 /* Create Folder Objects */
530 if(strlen(INSTALLER_FOLDER
)>0)
532 strcpy(temp
, replaceem(INSTALLER_FOLDER
));
535 arg2
=arg3
=arg4
=arg5
=&zerotext
[0];
559 MakeFolder(arg1
, arg2
, arg3
, arg4
, arg5
);
560 #ifdef ENABLE_LOGGING
561 fprintf(logfile
, "<WPSFolderAdd>,%s,%s,%s,%s,%s\r\n", arg1
, arg2
,arg3
,arg4
,arg5
);
564 arg2
=arg3
=arg4
=arg5
=&zerotext
[0];
569 MakeFolder(arg1
, arg2
, arg3
, arg4
, arg5
);
570 #ifdef ENABLE_LOGGING
571 fprintf(logfile
, "<WPSFolderAdd>,%s,%s,%s,%s,%s\r\n", arg1
, arg2
,arg3
,arg4
,arg5
);
575 /* Create Program Objects */
576 if(strlen(INSTALLER_PROGRAM
)>0)
578 strcpy(temp
, replaceem(INSTALLER_PROGRAM
));
581 arg2
=arg3
=arg4
=arg5
=arg6
=&zerotext
[0];
608 MakeProgram(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
609 #ifdef ENABLE_LOGGING
610 fprintf(logfile
, "<WPSProgramAdd>,%s,%s,%s,%s,%s,%s\r\n", arg1
,arg2
,arg3
,arg4
,arg5
,arg6
);
613 arg2
=arg3
=arg4
=arg5
=arg6
=&zerotext
[0];
618 MakeProgram(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
619 #ifdef ENABLE_LOGGING
620 fprintf(logfile
, "<WPSProgramAdd>,%s,%s,%s,%s,%s,%s\r\n", arg1
, arg2
,arg3
,arg4
,arg5
,arg6
);
624 /* Create Shadow Objects */
625 if(strlen(INSTALLER_SHADOW
)>0)
627 strcpy(temp
, replaceem(INSTALLER_SHADOW
));
630 arg2
=arg3
=arg4
=&zerotext
[0];
651 MakeShadow(arg1
, arg2
, arg3
, arg4
);
652 #ifdef ENABLE_LOGGING
653 fprintf(logfile
, "<WPSShadowAdd>,%s,%s,%s,%s\r\n", arg1
,arg2
,arg3
,arg4
);
656 arg2
=arg3
=arg4
=&zerotext
[0];
661 MakeShadow(arg1
, arg2
, arg3
, arg4
);
662 #ifdef ENABLE_LOGGING
663 fprintf(logfile
, "<WPSShadowAdd>,%s,%s,%s,%s\r\n", arg1
,arg2
,arg3
,arg4
);
667 /* Create Generic Objects */
668 if(strlen(INSTALLER_OBJECT
)>0)
670 strcpy(temp
, replaceem(INSTALLER_OBJECT
));
673 arg2
=arg3
=arg4
=arg5
=&zerotext
[0];
697 MakeObject(arg1
, arg2
, arg3
, arg4
, arg5
);
698 #ifdef ENABLE_LOGGING
699 fprintf(logfile
, "<WPSObjectAdd>,%s,%s,%s,%s,%s\r\n", arg1
,arg2
,arg3
,arg4
,arg5
);
702 arg2
=arg3
=arg4
=arg5
=&zerotext
[0];
707 MakeObject(arg1
, arg2
, arg3
, arg4
, arg5
);
708 #ifdef ENABLE_LOGGING
709 fprintf(logfile
, "<WPSObjectAdd>,%s,%s,%s,%s,%s\r\n", arg1
, arg2
,arg3
,arg4
,arg5
);