home *** CD-ROM | disk | FTP | other *** search
- #include <MacTypes.h>
- #include <ResourceMgr.h>
- #include <QuickDraw.h>
- #include <WindowMgr.h>
- #include <ControlMgr.h>
- #include <DialogMgr.h>
- #include <FileMgr.h>
-
- #include "setjmp.h"
- #include "fix.h"
-
- enum {
- ITEM_PROCESS_STEP = 2,
-
- ITEM_STATS_OK = 1,
- ITEM_STATS_INFO = 3
- };
-
- static Handle process_item;
- static jmp_buf abort; /* Environment for setjmp(). */
- static int desktop_refnum;
-
- void show_statistics(void);
- void general_init(void);
- void general_finish(void);
- void general_cleanup(void);
-
- /* Processing control routines. */
-
- /* Handle processing of one volume. */
-
- void one_pass()
- {
- register DialogPtr process_dialog;
- register int reason;
-
- CouldDialog(DIALOG_PROCESS);
- CouldDialog(DIALOG_STATS);
- CouldAlert(ALERT_GENERAL);
- if (select_volume_dialog(&volume_refnum, &is_hfs)) {
- set_watch_cursor();
- process_dialog = NIL;
- reason = setjmp(abort);
- if (!reason) { /* Abort to here... */
- general_init();
-
- process_dialog = GetNewDialog(DIALOG_PROCESS, NIL, MINUS_ONE);
- process_item = get_item(process_dialog, ITEM_PROCESS_STEP);
- DrawDialog(process_dialog);
-
- /* Pre-process the volume. */
-
- GetIndString(string, STR_ID, STR_READDESKTOP);
- SetIText(process_item, string);
-
- if (process_comments)
- pre_comment_processing();
- if (process_bundles)
- pre_bundle_processing();
- if (process_appls)
- pre_appl_processing();
-
- /* Process the files on the volume. */
-
- GetIndString(string, STR_ID, STR_READDISK);
- SetIText(process_item, string);
- if (is_hfs)
- hfs_scan_disk();
- else
- mfs_scan_disk();
-
- /* Post-process the volume. */
-
- GetIndString(string, STR_ID, STR_UPDATEDESKTOP);
- SetIText(process_item, string);
-
- if (process_comments)
- post_comment_processing();
- if (process_bundles)
- post_bundle_processing();
- if (process_appls)
- post_appl_processing();
-
- general_finish();
- SystemTask();
- DisposDialog(process_dialog);
- set_normal_cursor();
- show_statistics();
- }
- else { /* Aborted somewhere... */
- if (process_dialog)
- DisposDialog(process_dialog);
- if (reason > 0)
- general_cleanup(); /* Try to clean up... */
- set_normal_cursor();
- }
- }
- FreeDialog(DIALOG_PROCESS);
- FreeDialog(DIALOG_STATS);
- FreeAlert(ALERT_GENERAL);
- }
-
- /* Do general initialization (open DeskTop file). */
-
- static void general_init()
- {
- register Handle thing;
-
- GetIndString(string, STR_ID, STR_DESKTOP);
- desktop_refnum = OpenRFPerm(string, volume_refnum, fsRdWrPerm);
- if (desktop_refnum <= 0) {
- GetIndString(string, STR_ID, STR_NODESK);
- ParamText(string, NIL, NIL, NIL);
- set_normal_cursor();
- Alert(ALERT_GENERAL, NIL);
- longjmp(abort, -1); /* Desktop is not open... */
- }
- else {
- thing = GetResource('STR ', 0);
- HLock(thing);
- GetIndString(string, STR_ID, STR_FINDERID);
- if (!equalstr((StringPtr) *thing, string)) {
- HUnlock(thing);
- ReleaseResource(thing);
- GetIndString(string, STR_ID, STR_BADFINDERID);
- ParamText(string, NIL, NIL, NIL);
- set_normal_cursor();
- Alert(ALERT_GENERAL, NIL);
- longjmp(abort, 1);
- }
- else {
- HUnlock(thing);
- ReleaseResource(thing);
- }
- }
- }
-
- /* Finish volume processing. */
-
- static void general_finish()
- {
- CloseResFile(desktop_refnum);
- }
-
- /* Clean up after an abort (if desktop was open). */
-
- static void general_cleanup()
- {
- SetResFileAttrs(desktop_refnum, mapReadOnly);
- CloseResFile(desktop_refnum);
- }
-
- /* Display volume processing statistics. */
-
- static void show_statistics()
- {
- static unsigned char cr[2] = "\p\r";
-
- register DialogPtr stats_dialog;
- register unsigned char *t;
- int blob;
- unsigned char temp[256], buf[16];
-
- stats_dialog = GetNewDialog(DIALOG_STATS, NIL, MINUS_ONE);
- t = temp;
-
- t[0] = '\0';
- if (process_comments) {
- NumToString(comment_count, buf);
- concatstr(t, buf, t);
- GetIndString(string, STR_ID, (comment_count == 1) ?
- STR_COMMENT : STR_COMMENTS);
- concatstr(t, string, t);
- concatstr(t, cr, t);
- }
- if (process_bundles) {
- NumToString(bndl_count,buf);
- concatstr(t, buf, t);
- GetIndString(string, STR_ID, (bndl_count == 1) ?
- STR_BUNDLE : STR_BUNDLES);
- concatstr(t, string, t);
- concatstr(t, cr, t);
- }
- if (process_appls && is_hfs) {
- NumToString(appl_count,buf);
- concatstr(t, buf, t);
- GetIndString(string, STR_ID, (appl_count == 1) ?
- STR_APPL : STR_APPLS);
- concatstr(t, string, t);
- }
- SetIText(get_item(stats_dialog, ITEM_STATS_INFO), t);
- ShowWindow(stats_dialog);
- ModalDialog(NIL, &blob);
- DisposDialog(stats_dialog);
- }
-
- /* Display directory being processed. */
-
- void set_processing(name)
- unsigned char *name;
- {
- register unsigned char *s;
-
- s = string;
-
- if (name == NIL)
- GetIndString(s, STR_ID, STR_READDISK);
- else {
- GetIndString(s, STR_ID, STR_READFOLDER);
- concatstr(s, name, s);
- }
- SetIText(process_item, s);
- }
-