]>
git.saurik.com Git - wxWidgets.git/blob - utils/Install/sfxace/uac_crt.c
1 /* ------------------------------------------------------------------------ */
3 /* Creates/Replaces files or directories. */
5 /* ------------------------------------------------------------------------ */
10 #include <sys/types.h>
11 #include <sys/dirent.h>
15 #include <stdio.h> // printf() remove()
16 #include <string.h> // strncpy()
17 #include <sys/types.h>
18 #include <sys/stat.h> // struct stat
22 #if defined(DOS) || defined(WINNT) || defined(WIN16)
23 #include <io.h> // access()
25 #if defined(__CYGWIN__)
26 #include <Windows32/Base.h>
37 extern char installdir
[400];
39 /* Undocumented functions */
40 #if defined(__OS2__) || defined(__EMX__)
41 APIRET APIENTRY
DosReplaceModule(PSZ pszOldModule
,PSZ pszNewModule
,PSZ pszBackupModule
);
45 /* gets file name from header
47 CHAR
*ace_fname(CHAR
* s
, thead
* head
, INT nopath
)
52 strncpy(s
, (CHAR
*)(*(tfhead
*) head
).FNAME
, i
= (*(tfhead
*) head
).FNAME_SIZE
);
59 memmove(s
, cp
+1, strlen(cp
));
63 { // by current OS seperator
65 while ((cp
=strchr(cp
, '\\'))!=NULL
)
73 void check_ext_dir(CHAR
* f
) // checks/creates path of file
77 int z
, flag
= 0, len
= strlen(f
);
91 for(z
=0;z
<strlen(buffer
);z
++)
95 if(!(z
== 2 && buffer
[1] == ':'))
101 #if (defined(__OS2__) && !defined(__EMX__)) || (defined(WINNT) && !defined(__CYGWIN__))
110 error("Error while creating directory \"%s\".", d
);
117 #ifdef ENABLE_LOGGING
120 if(strlen(d
) > 1 && d
[1] == ':')
121 fprintf(logfile
, "<NewDir>,%s\r\n", d
);
124 if(installdir
[strlen(installdir
)-1] == '\\')
125 fprintf(logfile
, "<NewDir>,%s%s\r\n", installdir
, d
);
127 fprintf(logfile
, "<NewDir>,%s\\%s\r\n", installdir
, d
);
139 INT
ovr_delete(CHAR
* n
) // deletes directory or file
141 if (remove(n
) && rmdir(n
))
143 #if defined(__OS2__) || defined(__EMX__)
144 DosReplaceModule(n
, NULL
, NULL
);
146 if (remove(n
) && rmdir(n
))
148 error("Could not delete file or directory: \"%s\" Access denied.", n
);
155 INT
create_dest_file(CHAR
* file
, INT a
) // creates file or directory
159 ex
= fileexists(file
);
161 extern int no_update
;
167 { // create dir or file?
173 #if (defined(__OS2__) && !defined(__EMX__)) || (!defined(__CYGWIN__) && defined(WINNT))
174 if ((!ex
&& mkdir(file
)) || (ex
&& (st
.st_mode
& S_IFDIR
)))
176 if ((!ex
&& mkdir(file
, 0)) || (ex
&& (st
.st_mode
& S_IFDIR
)))
179 error("Could not create directory %s.");
183 { /* I wonder why it never gets here... :/ BS */
186 fprintf(logfile
, "<NewDir>,%s\\%s\r\n", installdir
, file
);
191 _dos_setfileattr(file
, a
); // set directory attributes
198 { // does the file already exist
199 #if defined(__OS2_) || defined(__EMX__)
200 static int sddall
= 0;
201 FILESTATUS3 fileinfo
;
205 DosQueryPathInfo(file
, FIL_STANDARD
, &fileinfo
, sizeof(FILESTATUS3
));
213 *((USHORT
*)&fdate
) = (USHORT
)(fhead
.FTIME
>> 16);
214 *((USHORT
*)&ftime
) = (USHORT
)fhead
.FTIME
;
216 tc
.tm_year
= fileinfo
.fdateLastWrite
.year
+ 80;
217 tc
.tm_mon
= fileinfo
.fdateLastWrite
.month
- 1;
218 tc
.tm_mday
= fileinfo
.fdateLastWrite
.day
;
219 tc
.tm_hour
= fileinfo
.ftimeLastWrite
.hours
;
220 tc
.tm_min
= fileinfo
.ftimeLastWrite
.minutes
;
221 tc
.tm_sec
= fileinfo
.ftimeLastWrite
.twosecs
* 2;
223 tc2
.tm_year
= fdate
.year
+ 80;
224 tc2
.tm_mon
= fdate
.month
- 1;
225 tc2
.tm_mday
= fdate
.day
;
226 tc2
.tm_hour
= ftime
.hours
;
227 tc2
.tm_min
= ftime
.minutes
;
228 tc2
.tm_sec
= ftime
.twosecs
* 2;
230 if((tt
= mktime(&tc
)) == -1 || (tt2
= mktime(&tc2
)) == -1 || tt
> tt2
)
234 i
= confirm("File \"%s\" has a newer modification time. Overwrite?", file
); // prompt for overwrite
237 if(installdir
[strlen(installdir
)-1] == '\\')
238 i
= confirm("File \"%s%s\" has a newer modification time. Overwrite?", installdir
, file
); // prompt for overwrite
240 i
= confirm("File \"%s\\%s\" has a newer modification time. Overwrite?", installdir
, file
); // prompt for overwrite
253 fileinfo
.attrFile
= FILE_NORMAL
;
254 DosSetPathInfo(file
, FIL_STANDARD
, (PVOID
)&fileinfo
, sizeof(FILESTATUS3
), 0);
258 if(installdir
[strlen(installdir
)-1] == '\\')
259 i
= confirm("Overwrite file \"%s%s\"?", installdir
, file
); // prompt for overwrite
261 i
= confirm("Overwrite file \"%s\\%s\"?", installdir
, file
); // prompt for overwrite
266 if ((i
&& !f_ovrall
) || ovr_delete(file
))
267 return (-1); // delete?
269 #if defined(__OS2_) || defined(__EMX__) || defined(WIN32)
270 if ((han
= open(file
, O_WRONLY
| O_TRUNC
| O_CREAT
| O_BINARY
,
271 S_IREAD
| S_IWRITE
| S_IEXEC
| S_IDELETE
|
272 S_IRGRP
| S_IWGRP
| S_IROTH
| S_IWOTH
)) < 0)
274 if ((han
= open(file
, O_WRONLY
| O_TRUNC
| O_CREAT
,
275 S_IREAD
| S_IWRITE
| S_IEXEC
| S_IDELETE
|
276 S_IRGRP
| S_IWGRP
| S_IROTH
| S_IWOTH
)) < 0)
278 error("Could not create destination file \"%s\".", file
);
281 #ifdef ENABLE_LOGGING
286 if(strlen(file
) > 1 && file
[1] == ':')
287 fprintf(logfile
, "<FileInst>,%s\r\n", file
);
290 if(installdir
[strlen(installdir
)-1] == '\\')
291 fprintf(logfile
, "<FileInst>,%s%s\r\n", installdir
, file
);
293 fprintf(logfile
, "<FileInst>,%s\\%s\r\n", installdir
, file
);