macos.c 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  1. /*
  2. Copyright (c) 1990-1999 Info-ZIP. All rights reserved.
  3. See the accompanying file LICENSE, version 1999-Oct-05 or later
  4. (the contents of which are also included in zip.h) for terms of use.
  5. If, for some reason, both of these files are missing, the Info-ZIP license
  6. also may be found at: ftp://ftp.cdrom.com/pub/infozip/license.html
  7. */
  8. /*---------------------------------------------------------------------------
  9. macos.c
  10. Macintosh-specific routines for use with Info-ZIP's Zip 2.3 and later.
  11. ---------------------------------------------------------------------------*/
  12. /*****************************************************************************/
  13. /* Includes */
  14. /*****************************************************************************/
  15. #include "zip.h"
  16. #include "revision.h"
  17. #include "crypt.h"
  18. #include <signal.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <sound.h>
  22. #include <unistd.h>
  23. #include <Strings.h>
  24. #include <setjmp.h>
  25. /* #include "charmap.h" */
  26. #include "helpers.h"
  27. #include "macstuff.h"
  28. #include "pathname.h"
  29. #include "recurse.h"
  30. /*****************************************************************************/
  31. /* Macros, typedefs */
  32. /*****************************************************************************/
  33. #define PATH_END MacPathEnd
  34. /*****************************************************************************/
  35. /* Global Vars */
  36. /*****************************************************************************/
  37. int error_level; /* used only in ziperr() */
  38. /* Note: sizeof() returns the size of this allusion
  39. 13 is current length of "XtraStuf.mac:" */
  40. extern const char ResourceMark[13]; /* var is initialized in file pathname.c */
  41. extern jmp_buf EnvForExit;
  42. MacZipGlobals MacZip;
  43. unsigned long count_of_Zippedfiles = 0;
  44. /*****************************************************************************/
  45. /* Module level Vars */
  46. /*****************************************************************************/
  47. static const char MacPathEnd = ':'; /* the Macintosh dir separator */
  48. /* Inform Progress vars */
  49. long estTicksToFinish;
  50. long createTime;
  51. long updateTicks;
  52. static char *Time_Est_strings[] = {
  53. "Zipping Files; Items done:",
  54. "More than 24 hours",
  55. "More than %s hours",
  56. "About %s hours, %s minutes",
  57. "About an hour",
  58. "Less than an hour",
  59. "About %s minutes, %s seconds",
  60. "About a minute",
  61. "Less than a minute",
  62. "About %s seconds",
  63. "About a second",
  64. "About 1 minute, %s seconds"};
  65. /*****************************************************************************/
  66. /* Prototypes */
  67. /*****************************************************************************/
  68. int DoCurrentDir(void);
  69. void DoAboutBox(void);
  70. void DoQuit(void);
  71. void DoEventLoop(void);
  72. void ZipInitAllVars(void);
  73. void UserStop(void);
  74. Boolean IsZipFile(char *name);
  75. static long EstimateCompletionTime(const long progressMax,
  76. const long progressSoFar, unsigned char percent);
  77. static void UpdateTimeToComplete(void);
  78. #ifdef USE_SIOUX
  79. #include <sioux.h>
  80. void DoWarnUserDupVol( char *FullPath );
  81. /*****************************************************************************/
  82. /* Functions */
  83. /*****************************************************************************/
  84. /*
  85. ** Standalone Unzip with Metrowerks SIOUX starts here
  86. **
  87. */
  88. int main(int argc, char **argv)
  89. {
  90. int return_code;
  91. SIOUXSettings.asktosaveonclose = FALSE;
  92. SIOUXSettings.showstatusline = TRUE;
  93. SIOUXSettings.columns = 100;
  94. SIOUXSettings.rows = 40;
  95. /* 30 = MacZip Johnny Lee's; 40 = new (my) MacZip */
  96. MacZip.MacZipMode = NewZipMode_EF;
  97. argc = ccommand(&argv);
  98. if (verbose) PrintArguments(argc, argv);
  99. ZipInitAllVars();
  100. return_code = zipmain(argc, argv);
  101. if (verbose) printf("\n\n Finish");
  102. return return_code;
  103. }
  104. /*
  105. ** SIOUX needs no extra event handling
  106. **
  107. */
  108. void UserStop(void)
  109. {
  110. };
  111. /*
  112. ** Password enter function '*' printed for each char
  113. **
  114. */
  115. int macgetch(void)
  116. {
  117. WindowPtr whichWindow;
  118. EventRecord theEvent;
  119. char c; /* one-byte buffer for read() to use */
  120. do {
  121. SystemTask();
  122. if (!GetNextEvent(everyEvent, &theEvent))
  123. theEvent.what = nullEvent;
  124. else {
  125. switch (theEvent.what) {
  126. case keyDown:
  127. c = theEvent.message & charCodeMask;
  128. break;
  129. case mouseDown:
  130. if (FindWindow(theEvent.where, &whichWindow) ==
  131. inSysWindow)
  132. SystemClick(&theEvent, whichWindow);
  133. break;
  134. case updateEvt:
  135. break;
  136. }
  137. }
  138. } while (theEvent.what != keyDown);
  139. printf("*");
  140. fflush(stdout);
  141. return (int)c;
  142. }
  143. #endif
  144. /******************************/
  145. /* Function version_local() */
  146. /******************************/
  147. /*
  148. ** Print Compilers version and compile time/date
  149. **
  150. */
  151. void version_local()
  152. {
  153. /* prints e.g:
  154. Compiled with Metrowerks CodeWarrior version 2000 for PowerPC Processor
  155. compile time: Feb 4 1998 17:49:49.
  156. */
  157. static ZCONST char CompiledWith[] =
  158. "\n\nCompiled with %s %x for %s \n %s %s %s.\n\n";
  159. printf(CompiledWith,
  160. #ifdef __MWERKS__
  161. " Metrowerks CodeWarrior version", __MWERKS__,
  162. #endif
  163. #ifdef __MC68K__
  164. " MC68K Processor",
  165. #else
  166. " PowerPC Processor",
  167. #endif
  168. #ifdef __DATE__
  169. "compile time: ", __DATE__, __TIME__
  170. #else
  171. "", "", ""
  172. #endif
  173. );
  174. } /* end function version_local() */
  175. /*
  176. ** Deletes a dir if the switch '-m' is used
  177. **
  178. */
  179. int deletedir(char *path)
  180. {
  181. static char Num = 0;
  182. static FSSpec trashfolder;
  183. static Boolean FirstCall = true;
  184. static Boolean Immediate_File_Deletion = false;
  185. OSErr err;
  186. FSSpec dirToDelete;
  187. char currpath[NAME_MAX], *envptr;
  188. CInfoPBRec fpb;
  189. /* init this function */
  190. if ((path == NULL) ||
  191. (strlen(path) == 0))
  192. {
  193. Num = 0;
  194. FirstCall = true;
  195. return -1;
  196. }
  197. UserStop();
  198. GetCompletePath(currpath,path,&dirToDelete, &err);
  199. if (FirstCall == true)
  200. {
  201. FirstCall = false;
  202. envptr = getenv("Immediate_File_Deletion");
  203. if (!(envptr == (char *)NULL || *envptr == '\0'))
  204. {
  205. if (stricmp(envptr,"yes") == 0)
  206. Immediate_File_Deletion = true;
  207. else
  208. Immediate_File_Deletion = false;
  209. }
  210. err = FSpFindFolder(dirToDelete.vRefNum, kTrashFolderType,
  211. kDontCreateFolder,&trashfolder);
  212. printerr("FSpFindFolder:",err,err,__LINE__,__FILE__,path);
  213. }
  214. fpb.dirInfo.ioNamePtr = dirToDelete.name;
  215. fpb.dirInfo.ioVRefNum = dirToDelete.vRefNum;
  216. fpb.dirInfo.ioDrDirID = dirToDelete.parID;
  217. fpb.dirInfo.ioFDirIndex = 0;
  218. err = PBGetCatInfoSync(&fpb);
  219. printerr("PBGetCatInfo deletedir ", err, err,
  220. __LINE__, __FILE__, "");
  221. if (fpb.dirInfo.ioDrNmFls > 0)
  222. {
  223. return 0; /* do not move / delete folders which are not empty */
  224. }
  225. if (Immediate_File_Deletion)
  226. {
  227. err = FSpDelete(&dirToDelete);
  228. return err;
  229. }
  230. err = CatMove (dirToDelete.vRefNum, dirToDelete.parID,
  231. dirToDelete.name, trashfolder.parID, trashfolder.name);
  232. /* -48 = file is already existing so we have to rename it before
  233. moving the file */
  234. if (err == -48)
  235. {
  236. Num++;
  237. if (dirToDelete.name[0] >= 28) /* cut foldername if to long */
  238. dirToDelete.name[0] = 28;
  239. P2CStr(dirToDelete.name);
  240. sprintf(currpath,"%s~%d",(char *)dirToDelete.name,Num);
  241. C2PStr(currpath);
  242. C2PStr((char *)dirToDelete.name);
  243. err = HRename (dirToDelete.vRefNum, dirToDelete.parID,
  244. dirToDelete.name, (unsigned char *) currpath);
  245. err = CatMove (dirToDelete.vRefNum, dirToDelete.parID,
  246. (unsigned char *) currpath, trashfolder.parID,
  247. trashfolder.name);
  248. }
  249. return err;
  250. }
  251. /*
  252. ** Set the file-type so the archive will get the correct icon, type
  253. ** and creator code.
  254. */
  255. void setfiletype(char *new_f, unsigned long Creator, unsigned long Type)
  256. {
  257. OSErr err;
  258. if (strcmp(zipfile, new_f) == 0)
  259. err = FSpChangeCreatorType(&MacZip.ZipFileSpec, Creator, Type);
  260. printerr("FSpChangeCreatorType:", err, err, __LINE__, __FILE__, new_f);
  261. return;
  262. }
  263. /*
  264. ** Convert the external (native) filename into Zip's internal Unix compatible
  265. ** name space.
  266. */
  267. char *ex2in(char *externalFilen, int isdir, int *pdosflag)
  268. /* char *externalFilen external file name */
  269. /* int isdir input: externalFilen is a directory */
  270. /* int *pdosflag output: force MSDOS file attributes? */
  271. /* Convert the external file name to a zip file name, returning the malloc'ed
  272. string or NULL if not enough memory. */
  273. {
  274. char *internalFilen; /* internal file name (malloc'ed) */
  275. char *t; /* shortened name */
  276. char *Pathname;
  277. char buffer[NAME_MAX];
  278. int dosflag;
  279. AssertStr(externalFilen, externalFilen)
  280. AssertBool(isdir,"")
  281. dosflag = dosify; /* default for non-DOS and non-OS/2 */
  282. /* Find starting point in name before doing malloc */
  283. for (t = externalFilen; *t == PATH_END; t++)
  284. ;
  285. if (!MacZip.StoreFullPath)
  286. {
  287. Pathname = StripPartialDir(buffer, MacZip.SearchDir,t);
  288. }
  289. else
  290. {
  291. Pathname = t;
  292. }
  293. /* Make changes, if any, to the copied name (leave original intact) */
  294. if (!pathput)
  295. {
  296. t = last(Pathname, PATH_END);
  297. }
  298. else t = Pathname;
  299. /* Malloc space for internal name and copy it */
  300. if ((internalFilen = malloc(strlen(t) + 10 + strlen(ResourceMark) )) == NULL)
  301. return NULL;
  302. sstrcpy(internalFilen, t);
  303. /* we have to eliminate illegal chars:
  304. * The name space for Mac filenames and Zip filenames (unix style names)
  305. * do both include all printable extended-ASCII characters. The only
  306. * difference we have to take care of is the single special character
  307. * used as path delimiter:
  308. * ':' on MacOS and '/' on Unix and '\' on Dos.
  309. * So, to convert between Mac filenames and Unix filenames without any
  310. * loss of information, we simply interchange ':' and '/'. Additionally,
  311. * we try to convert the coding of the extended-ASCII characters into
  312. * InfoZip's standard ISO 8859-1 codepage table.
  313. */
  314. MakeCompatibleString(internalFilen, ':', '/', '/', ':',
  315. MacZip.CurrTextEncodingBase);
  316. /* Returned malloc'ed name */
  317. if (pdosflag)
  318. *pdosflag = dosflag;
  319. if (isdir)
  320. {
  321. return internalFilen; /* avoid warning on unused variable */
  322. }
  323. if (dosify)
  324. {
  325. msname(internalFilen);
  326. printf("\n ex2in: %s",internalFilen);
  327. }
  328. return internalFilen;
  329. }
  330. /*
  331. ** Collect all filenames. Go through all directories
  332. **
  333. */
  334. int wild(char *Pathpat)
  335. /* path/pattern to match */
  336. /* If not in exclude mode, expand the pattern based on the contents of the
  337. file system. Return an error code in the ZE_ class. */
  338. {
  339. FSSpec Spec;
  340. char fullpath[NAME_MAX];
  341. OSErr err;
  342. AssertStr(Pathpat, Pathpat);
  343. if (noisy) printf("%s \n\n",GetZipVersionsInfo());
  344. if (extra_fields == 0)
  345. {
  346. MacZip.DataForkOnly = true;
  347. }
  348. /* for switch '-R' -> '.' means current dir */
  349. if (strcmp(Pathpat,".") == 0) sstrcpy(Pathpat,"*");
  350. sstrcpy(MacZip.Pattern,Pathpat);
  351. if (recurse)
  352. {
  353. MacZip.StoreFoldersAlso = true;
  354. MacZip.SearchLevels = 0; /* if 0 we aren't checking levels */
  355. }
  356. else
  357. {
  358. MacZip.StoreFoldersAlso = false;
  359. MacZip.SearchLevels = 1;
  360. }
  361. /* make complete path */
  362. GetCompletePath(fullpath, MacZip.Pattern, &Spec,&err);
  363. err = PrintUserHFSerr((err != -43) && (err != 0), err, MacZip.Pattern);
  364. printerr("GetCompletePath:", err, err, __LINE__, __FILE__, fullpath);
  365. /* extract the filepattern */
  366. GetFilename(MacZip.Pattern, fullpath);
  367. /* extract Path and get FSSpec of search-path */
  368. /* get FSSpec of search-path ; we need a dir to start
  369. searching for filenames */
  370. TruncFilename(MacZip.SearchDir, fullpath);
  371. GetCompletePath(MacZip.SearchDir, MacZip.SearchDir, &Spec,&err);
  372. if (noisy) {
  373. if (MacZip.SearchLevels == 0)
  374. {
  375. printf("\nSearch Pattern: [%s] Levels: all", MacZip.Pattern);
  376. }
  377. else
  378. {
  379. printf("\nSearch Pattern: [%s] Levels: %d", MacZip.Pattern,
  380. MacZip.SearchLevels);
  381. }
  382. printf("\nSearch Path: [%s]", MacZip.SearchDir);
  383. printf("\nZip-File: [%s] \n",MacZip.ZipFullPath);
  384. }
  385. /* we are working only with pathnames;
  386. * this can cause big problems on a mac ...
  387. */
  388. if (CheckMountedVolumes(MacZip.SearchDir) > 1)
  389. DoWarnUserDupVol(MacZip.SearchDir);
  390. /* start getting all filenames */
  391. err = FSpRecurseDirectory(&Spec, MacZip.SearchLevels);
  392. printerr("FSpRecurseDirectory:", err, err, __LINE__, __FILE__, "");
  393. return ZE_OK;
  394. }
  395. /*
  396. ** Convert the internal filename into a external (native).
  397. ** The user will see this modified filename.
  398. ** For more performance:
  399. ** I do not completly switch back to the native macos filename.
  400. ** The user will still see directory separator '/' and the converted
  401. ** charset.
  402. */
  403. char *in2ex(char *n) /* internal file name */
  404. /* Convert the zip file name to an external file name, returning the malloc'ed
  405. string or NULL if not enough memory. */
  406. {
  407. char *x; /* external file name */
  408. AssertStr(n,n)
  409. if ((x = malloc(strlen(n) + 1)) == NULL)
  410. return NULL;
  411. RfDfFilen2Real(x, n, MacZip.MacZipMode, MacZip.DataForkOnly,
  412. &MacZip.CurrentFork);
  413. return x;
  414. }
  415. /*
  416. ** Process on filenames. This function will be called to collect
  417. ** the filenames.
  418. */
  419. int procname(char *filename, /* name to process */
  420. int caseflag) /* true to force case-sensitive match
  421. (always false on a Mac) */
  422. /* Process a name . Return
  423. an error code in the ZE_ class. */
  424. {
  425. int rc; /* matched flag */
  426. AssertBool(caseflag,"caseflag")
  427. AssertStr(filename,filename)
  428. /* add or remove name of file */
  429. rc = newname(filename, MacZip.isDirectory, caseflag);
  430. return rc;
  431. }
  432. ulg filetime(
  433. char *f, /* name of file to get info on */
  434. ulg *a, /* return value: file attributes */
  435. long *n, /* return value: file size */
  436. iztimes *t) /* return value: access, modific. and creation times */
  437. /* If file *f does not exist, return 0. Else, return the file's last
  438. modified date and time as an MSDOS date and time. The date and
  439. time is returned in a long with the date most significant to allow
  440. unsigned integer comparison of absolute times. Also, if a is not
  441. a NULL pointer, store the file attributes there, with the high two
  442. bytes being the Unix attributes, and the low byte being a mapping
  443. of that to DOS attributes. If n is not NULL, store the file size
  444. there. If t is not NULL, the file's access, modification and creation
  445. times are stored there as UNIX time_t values.
  446. If f is "-", use standard input as the file. If f is a device, return
  447. a file size of -1 */
  448. {
  449. struct stat s; /* results of stat() */
  450. AssertStr(f,f)
  451. if (strlen(f) == 0) return 0;
  452. if (SSTAT(f, &s) != 0)
  453. /* Accept about any file kind including directories
  454. * (stored with trailing : with -r option)
  455. */
  456. return 0;
  457. if (a != NULL) {
  458. *a = ((ulg)s.st_mode << 16) | !(s.st_mode & S_IWRITE);
  459. if (MacZip.isDirectory) {
  460. *a |= MSDOS_DIR_ATTR;
  461. }
  462. }
  463. if (n != NULL)
  464. *n = (s.st_mode & UNX_IFMT) == UNX_IFREG ? s.st_size : -1L;
  465. if (t != NULL) {
  466. t->atime = s.st_atime;
  467. t->mtime = s.st_mtime;
  468. t->ctime = s.st_ctime; /* on Mac, st_ctime contains creation time! */
  469. }
  470. return unix2dostime(&s.st_mtime);
  471. }
  472. void stamp(char *f, ulg d)
  473. /* char *f; name of file to change */
  474. /* ulg d; dos-style time to change it to */
  475. /* Set last updated and accessed time of file f to the DOS time d. */
  476. {
  477. time_t u[2]; /* argument for utime() */
  478. f = f;
  479. /* Convert DOS time to time_t format in u */
  480. u[0] = u[1] = dos2unixtime(d);
  481. /* utime(f, u); */
  482. }
  483. /*
  484. ** return only the longest part of the path:
  485. ** second parameter: Volume:test folder:second folder:
  486. ** third parameter: Volume:test folder:second folder:third folder:file
  487. ** result will be: third folder:file
  488. ** first parameter: contains string buffer that will be used to prepend
  489. ** the "resource mark" part in front of the result when
  490. ** a resource fork is processed in "M3" mode.
  491. **
  492. */
  493. char *StripPartialDir(char *CompletePath,
  494. const char *PartialPath, const char *FullPath)
  495. {
  496. const char *tmpPtr1 = PartialPath;
  497. const char *tmpPtr2 = FullPath;
  498. int result;
  499. Assert_it(CompletePath,"StripPartialDir","")
  500. AssertStrNoOverlap(FullPath,PartialPath,PartialPath)
  501. if (MacZip.DataForkOnly)
  502. {
  503. tmpPtr2 += strlen(tmpPtr1);
  504. return (char *)tmpPtr2;
  505. }
  506. switch (MacZip.MacZipMode)
  507. {
  508. case JohnnyLee_EF:
  509. {
  510. tmpPtr2 += strlen(tmpPtr1);
  511. return (char *)tmpPtr2;
  512. break;
  513. }
  514. case NewZipMode_EF:
  515. { /* determine Fork type */
  516. result = strncmp(FullPath, ResourceMark, sizeof(ResourceMark)-2);
  517. if (result != 0)
  518. { /* data fork */
  519. MacZip.CurrentFork = DataFork;
  520. tmpPtr2 += strlen(tmpPtr1);
  521. return (char *)tmpPtr2;
  522. }
  523. else
  524. { /* resource fork */
  525. MacZip.CurrentFork = ResourceFork;
  526. sstrcpy(CompletePath, ResourceMark);
  527. tmpPtr2 += strlen(tmpPtr1);
  528. tmpPtr2 += sizeof(ResourceMark);
  529. sstrcat(CompletePath, tmpPtr2);
  530. return (char *)CompletePath;
  531. }
  532. break;
  533. }
  534. }
  535. return NULL; /* function should never reach this point */
  536. }
  537. /*
  538. ** Init all global variables
  539. ** Must be called for each zip-run
  540. */
  541. void ZipInitAllVars(void)
  542. {
  543. getcwd(MacZip.CurrentPath, sizeof(MacZip.CurrentPath));
  544. /* MacZip.MacZipMode = JohnnyLee_EF; */
  545. MacZip.MacZipMode = NewZipMode_EF;
  546. MacZip.DataForkOnly = false;
  547. MacZip.CurrentFork = NoFork;
  548. MacZip.StoreFoldersAlso = false;
  549. MacZip.FoundFiles = 0;
  550. MacZip.FoundDirectories = 0;
  551. MacZip.RawCountOfItems = 0;
  552. MacZip.BytesOfData = 0;
  553. MacZip.StoreFullPath = false;
  554. MacZip.StatingProgress = false;
  555. MacZip.IncludeInvisible = false;
  556. MacZip.isMacStatValid = false;
  557. MacZip.CurrTextEncodingBase = FontScript();
  558. MacZip.HaveGMToffset = false;
  559. createTime = TickCount();
  560. estTicksToFinish = -1;
  561. updateTicks = 0;
  562. /* init some functions */
  563. IsZipFile(NULL);
  564. destroy(NULL);
  565. deletedir(NULL);
  566. ShowCounter(true);
  567. extra_fields = 1;
  568. error_level = 0;
  569. count_of_Zippedfiles = 0;
  570. }
  571. /*
  572. ** Get the findercomment and store it as file-comment in the Zip-file
  573. **
  574. */
  575. char *GetComment(char *filename)
  576. {
  577. OSErr err;
  578. static char buffer[NAME_MAX];
  579. char buffer2[NAME_MAX];
  580. char *tmpPtr;
  581. if (filename == NULL) return NULL;
  582. /* now we can convert Unix-Path in HFS-Path */
  583. for (tmpPtr = filename; *tmpPtr; tmpPtr++)
  584. if (*tmpPtr == '/')
  585. *tmpPtr = ':';
  586. if (MacZip.StoreFullPath)
  587. { /* filename is already a fullpath */
  588. sstrcpy(buffer,filename);
  589. }
  590. else
  591. { /* make a fullpath */
  592. sstrcpy(buffer,MacZip.SearchDir);
  593. sstrcat(buffer,filename);
  594. }
  595. /* make fullpath and get FSSpec */
  596. /* Unfortunately: I get only the converted filename here */
  597. /* so filenames with extended characters can not be found */
  598. GetCompletePath(buffer2,buffer, &MacZip.fileSpec, &err);
  599. printerr("GetCompletePath:",(err != -43) && (err != -120) && (err != 0) ,
  600. err,__LINE__,__FILE__,buffer);
  601. err = FSpDTGetComment(&MacZip.fileSpec, (unsigned char *) buffer);
  602. printerr("FSpDTGetComment:", (err != -5012) && (err != 0), err,
  603. __LINE__, __FILE__, filename);
  604. P2CStr((unsigned char *) buffer);
  605. if (err == -5012) return NULL; /* no finder-comments found */
  606. if (noisy) printf("\n%32s -> %s",filename, buffer);
  607. /*
  608. Beside the script change we need only to change 0x0d in 0x0a
  609. so the last two arguments are not needed and does nothing.
  610. */
  611. MakeCompatibleString(buffer, 0x0d, 0x0a, ' ', ' ',
  612. MacZip.CurrTextEncodingBase);
  613. return buffer;
  614. }
  615. /*
  616. ** Print a progress indicator for stating the files
  617. **
  618. */
  619. void PrintStatProgress(char *msg)
  620. {
  621. if (!noisy) return; /* do no output if noisy is false */
  622. MacZip.StatingProgress = true;
  623. if (strcmp(msg,"done") == 0)
  624. {
  625. MacZip.StatingProgress = false;
  626. printf("\n ... done \n\n");
  627. }
  628. else printf("\n %s",msg);
  629. }
  630. void InformProgress(const long progressMax, const long progressSoFar )
  631. {
  632. int curr_percent;
  633. char no_time[5] = "...";
  634. curr_percent = percent(progressMax, progressSoFar);
  635. if (curr_percent < 95)
  636. {
  637. estTicksToFinish = EstimateCompletionTime(progressMax,
  638. progressSoFar, curr_percent);
  639. }
  640. else
  641. {
  642. rightStatusString(no_time);
  643. leftStatusString(no_time);
  644. }
  645. updateTicks = TickCount() + 60;
  646. return;
  647. }
  648. void ShowCounter(Boolean reset)
  649. {
  650. static char statusline[100];
  651. static unsigned long filecount = 0;
  652. if (reset)
  653. {
  654. filecount = 0;
  655. return;
  656. }
  657. if (noisy)
  658. {
  659. sprintf(statusline, "%6d", filecount++);
  660. rightStatusString(statusline);
  661. }
  662. }
  663. static long EstimateCompletionTime(const long progressMax,
  664. const long progressSoFar,
  665. unsigned char curr_percent)
  666. {
  667. long max = progressMax, value = progressSoFar;
  668. static char buf[100];
  669. unsigned long ticksTakenSoFar = TickCount() - createTime;
  670. float currentRate = (float) ticksTakenSoFar / (float) value;
  671. long newEst = (long)( currentRate * (float)( max - value ));
  672. sprintf(buf, "%d [%d%%]",progressSoFar, curr_percent);
  673. rightStatusString(buf);
  674. estTicksToFinish = newEst;
  675. UpdateTimeToComplete();
  676. return estTicksToFinish;
  677. }
  678. static void UpdateTimeToComplete(void)
  679. {
  680. short days, hours, minutes, seconds;
  681. char estStr[255];
  682. Str15 xx, yy;
  683. short idx = 0;
  684. if ( estTicksToFinish == -1 )
  685. return;
  686. days = estTicksToFinish / 5184000L;
  687. hours = ( estTicksToFinish - ( days * 5184000L )) / 216000L;
  688. minutes = ( estTicksToFinish - ( days * 5184000L ) -
  689. ( hours * 216000L )) / 3600L;
  690. seconds = ( estTicksToFinish - ( days * 5184000L ) -
  691. ( hours * 216000L ) - ( minutes * 3600L )) / 60L;
  692. xx[0] = 0;
  693. yy[0] = 0;
  694. if ( days )
  695. {
  696. /* "more than 24 hours" */
  697. idx = 1;
  698. goto setEstTimeStr;
  699. }
  700. if ( hours >= 8 )
  701. {
  702. /* "more than x hours" */
  703. NumToString( hours, xx );
  704. idx = 2;
  705. goto setEstTimeStr;
  706. }
  707. if ( estTicksToFinish > 252000L ) /* > 1hr, 10 minutes */
  708. {
  709. /* "about x hours, y minutes" */
  710. NumToString( hours, xx );
  711. NumToString( minutes, yy );
  712. idx = 3;
  713. goto setEstTimeStr;
  714. }
  715. if ( estTicksToFinish > 198000L ) /* > 55 minutes */
  716. {
  717. /* "about an hour" */
  718. idx = 4;
  719. goto setEstTimeStr;
  720. }
  721. if ( estTicksToFinish > 144000L ) /* > 40 minutes */
  722. {
  723. /* "less than an hour" */
  724. idx = 5;
  725. goto setEstTimeStr;
  726. }
  727. if ( estTicksToFinish > 4200L ) /* > 1 minute, 10 sec */
  728. {
  729. /* "about x minutes, y seconds */
  730. NumToString( minutes, xx );
  731. NumToString( seconds, yy );
  732. if ( minutes == 1 )
  733. idx = 11;
  734. else
  735. idx = 6;
  736. goto setEstTimeStr;
  737. }
  738. if ( estTicksToFinish > 3000L ) /* > 50 seconds */
  739. {
  740. /* "about a minute" */
  741. idx = 7;
  742. goto setEstTimeStr;
  743. }
  744. if ( estTicksToFinish > 1500L ) /* > 25 seconds */
  745. {
  746. /* "less than a minute" */
  747. idx = 8;
  748. goto setEstTimeStr;
  749. }
  750. if ( estTicksToFinish > 120L ) /* > 2 seconds */
  751. {
  752. NumToString( seconds, xx );
  753. idx = 9;
  754. goto setEstTimeStr;
  755. }
  756. idx = 10;
  757. setEstTimeStr:
  758. sprintf(estStr,Time_Est_strings[idx],P2CStr(xx),P2CStr(yy));
  759. leftStatusString((char *)estStr);
  760. }
  761. /*
  762. ** Just return the zip version
  763. **
  764. */
  765. char *GetZipVersionsInfo(void)
  766. {
  767. static char ZipVersion[100];
  768. sprintf(ZipVersion, "Zip Module\n%d.%d%d%s of %s", Z_MAJORVER, Z_MINORVER,
  769. Z_PATCHLEVEL, Z_BETALEVEL, REVDATE);
  770. return ZipVersion;
  771. }
  772. #ifndef USE_SIOUX
  773. /*
  774. ** Just return the copyright message
  775. **
  776. */
  777. char *GetZipCopyright(void)
  778. {
  779. static char CopyR[300];
  780. sstrcpy(CopyR, copyright[0]);
  781. sstrcat(CopyR, copyright[1]);
  782. sstrcat(CopyR, "\r\rPlease send bug reports to the authors at\r"\
  783. "Zip-Bugs@lists.wku.edu");
  784. return CopyR;
  785. }
  786. /*
  787. ** Just return the compilers date/time
  788. **
  789. */
  790. char *GetZipVersionLocal(void)
  791. {
  792. static char ZipVersionLocal[50];
  793. sprintf(ZipVersionLocal, "[%s %s]", __DATE__, __TIME__);
  794. return ZipVersionLocal;
  795. }
  796. #endif /* #ifndef USE_SIOUX */