home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
online
/
source
/
c
/
compilers
/
Tickle-4.0.sit.hqx
/
Tickle-4.0
/
src
/
hfs_action.c
< prev
next >
Wrap
Text File
|
1993-11-18
|
17KB
|
636 lines
/*
** This source code was written by Tim Endres
** Email: time@ice.com.
** USMail: 8840 Main Street, Whitmore Lake, MI 48189
**
** Some portions of this application utilize sources
** that are copyrighted by ICE Engineering, Inc., and
** ICE Engineering retains all rights to those sources.
**
** Neither ICE Engineering, Inc., nor Tim Endres,
** warrants this source code for any reason, and neither
** party assumes any responsbility for the use of these
** sources, libraries, or applications. The user of these
** sources and binaries assumes all responsbilities for
** any resulting consequences.
*/
#pragma segment HFSAction
#include "tickle.h"
#include <DiskInit.h>
#include <OSEvents.h>
extern int errno;
#define HFS_SKIP_DIR (-64)
#define HFS_RECURSIVE 0x0100
#define HFS_FILES 0x0001
#define HFS_FOLDERS 0x0002
#define HFS_FILES_AND_FOLDERS ( HFS_FILES | HFS_FOLDERS )
#define HFS_FILES_RECURSIVELY ( HFS_FILES | HFS_RECURSIVE)
#define HFS_FOLDERS_RECURSIVELY ( HFS_FOLDERS | HFS_RECURSIVE)
#define HFS_FILES_AND_FOLDERS_RECURSIVELY ( HFS_FILES | HFS_FOLDERS | HFS_RECURSIVE)
#define HFS_DO_FILES(FLAGS) ( ( (FLAGS) & HFS_FILES ) != 0 )
#define HFS_DO_FOLDERS(FLAGS) ( ( (FLAGS) & HFS_FOLDERS ) != 0 )
#define HFS_DO_RECURSIVELY(FLAGS) ( ( (FLAGS) & HFS_RECURSIVE ) != 0 )
extern void SProgressCounting();
static int count_progress_count = 0;
static int total_count = 0;
static int current_count = 0;
static short hfs_process_first_folder = 0;
extern long progress_pos, progress_start;
void
SProgressActionProc(message, start, end, pos)
char *message;
int start;
int end;
int pos;
{
#pragma unused (pos)
sprintf(message, "Finished %d of %d files...",
(progress_pos - progress_start), (end - start));
}
HFSSetFileInfo(cpb, parent, vRefNum, dirID, filename, action_data, action_ptr)
CInfoPBPtr cpb;
CInfoPBPtr parent;
int vRefNum;
long dirID;
char *filename; /* C string */
long action_data;
char *action_ptr;
{
int result;
char pname[32];
HParamBlockRec hpb;
#pragma unused (parent, action_ptr)
strcpy(pname, filename); c2pstr(pname);
hpb.fileParam.ioCompletion = 0;
hpb.fileParam.ioFVersNum = 0;
hpb.fileParam.ioFDirIndex = 0;
hpb.fileParam.ioNamePtr = pname;
hpb.fileParam.ioVRefNum = vRefNum;
hpb.fileParam.ioDirID = dirID;
hpb.fileParam.ioFlAttrib = cpb->hFileInfo.ioFlAttrib;
hpb.fileParam.ioFlFndrInfo = cpb->hFileInfo.ioFlFndrInfo;
hpb.fileParam.ioFlCrDat = cpb->hFileInfo.ioFlCrDat;
hpb.fileParam.ioFlMdDat = cpb->hFileInfo.ioFlMdDat;
if (action_ptr == NULL)
hpb.fileParam.ioFlFndrInfo.fdType = (OSType)action_data;
else
hpb.fileParam.ioFlFndrInfo.fdCreator = (OSType)action_data;
result = PBHSetFInfo(&hpb, FALSE);
return result;
}
HFSSetFolderView(cpb, parent, vRefNum, dirID, filename, action_data, action_ptr)
CInfoPBPtr cpb;
CInfoPBPtr parent;
int vRefNum;
long dirID;
char *filename; /* C string */
long action_data;
char *action_ptr;
{
int result;
int saveindex;
char *savename;
#pragma unused (parent, vRefNum, dirID, filename, action_ptr)
savename = cpb->dirInfo.ioNamePtr;
saveindex = cpb->dirInfo.ioFDirIndex;
cpb->dirInfo.ioDrUsrWds.frView = (short)(action_data & 0x0000FFFF);
cpb->dirInfo.ioNamePtr = NULL;
cpb->dirInfo.ioFDirIndex = -1;
result = PBSetCatInfo(cpb, FALSE);
cpb->dirInfo.ioNamePtr = savename;
cpb->dirInfo.ioFDirIndex = saveindex;
return result;
}
HFSPrintInfo(cpb, parent, vRefNum, dirID, filename, action_data, action_ptr)
CInfoPBPtr cpb;
CInfoPBPtr parent;
int vRefNum;
long dirID;
char *filename; /* C string */
long action_data;
char *action_ptr;
{
#pragma unused (parent, vRefNum, dirID, action_data, action_ptr)
if ((cpb->hFileInfo.ioFlAttrib & ioDirMask) != 0) {
/* DIR */
Feedback("");
SetPort(theFeedbackWindow);
TextFace(bold);
Feedback("DIR %s", filename);
SetPort(theFeedbackWindow);
TextFace(normal);
Feedback(" ID=%ld ParID=%ld vRef=%d flAttrib x%04X numFls %ld ",
cpb->dirInfo.ioDrDirID, cpb->dirInfo.ioDrParID, cpb->dirInfo.ioVRefNum,
cpb->dirInfo.ioFlAttrib, cpb->dirInfo.ioDrNmFls);
Feedback(" DInfo: RECT T%d L%d B%d R%d ",
cpb->dirInfo.ioDrUsrWds.frRect.top, cpb->dirInfo.ioDrUsrWds.frRect.left,
cpb->dirInfo.ioDrUsrWds.frRect.bottom, cpb->dirInfo.ioDrUsrWds.frRect.right);
Feedback(" DInfo: Flags x%04X View x%04X Loc H%d V%d ",
cpb->dirInfo.ioDrUsrWds.frFlags, cpb->dirInfo.ioDrUsrWds.frView,
cpb->dirInfo.ioDrUsrWds.frLocation.h, cpb->dirInfo.ioDrUsrWds.frLocation.v);
Feedback(" DXInfo: OpenChain %ld PutAway %ld Comment %d Scroll H%d V%d ",
cpb->dirInfo.ioDrFndrInfo.frOpenChain, cpb->dirInfo.ioDrFndrInfo.frPutAway,
cpb->dirInfo.ioDrFndrInfo.frComment,
cpb->dirInfo.ioDrFndrInfo.frScroll.h, cpb->dirInfo.ioDrFndrInfo.frScroll.v);
}
else {
/* FILE */
SetPort(theFeedbackWindow);
TextFace(bold);
Feedback("FILE %s", filename);
SetPort(theFeedbackWindow);
TextFace(normal);
Feedback(" DirID=%ld ParID=%ld vRef=%d flAttrib x%04X refNum %ld ",
cpb->hFileInfo.ioDirID, cpb->hFileInfo.ioFlParID,
cpb->hFileInfo.ioVRefNum, cpb->hFileInfo.ioFlAttrib, cpb->hFileInfo.ioFRefNum);
Feedback(" Type '%4.4s' Creator '%4.4s' IconID %ld Cmt %ld PutAway %ld ",
&cpb->hFileInfo.ioFlFndrInfo.fdType, &cpb->hFileInfo.ioFlFndrInfo.fdCreator,
cpb->hFileInfo.ioFlXFndrInfo.fdIconID, cpb->hFileInfo.ioFlXFndrInfo.fdComment,
cpb->hFileInfo.ioFlXFndrInfo.fdPutAway);
Feedback(" fdFlags x%04X fdFldr %d Location H%d V%d ",
cpb->hFileInfo.ioFlFndrInfo.fdFlags, cpb->hFileInfo.ioFlFndrInfo.fdFldr,
cpb->hFileInfo.ioFlFndrInfo.fdLocation.h,
cpb->hFileInfo.ioFlFndrInfo.fdLocation.v);
}
return noErr;
}
show_file_info()
{
ShowFeedback();
SetPort(theFeedbackWindow);
TextFace(underline);
Feedback("Show File Information");
SetPort(theFeedbackWindow);
TextFace(normal);
hfs_process_first_folder = 0;
HFSApplyTo(HFSPrintInfo, 0, NULL, "Show Info", HFS_FILES_RECURSIVELY, 0);
}
show_folder_info()
{
ShowFeedback();
SetPort(theFeedbackWindow);
TextFace(underline);
Feedback("Show Folder Information");
SetPort(theFeedbackWindow);
TextFace(normal);
hfs_process_first_folder = 1;
HFSApplyTo(HFSPrintInfo, 0, NULL, "Show Info", HFS_FOLDERS_RECURSIVELY, 0);
}
show_file_and_folder_info()
{
ShowFeedback();
SetPort(theFeedbackWindow);
TextFace(underline);
Feedback("Show File and Folder Information");
SetPort(theFeedbackWindow);
TextFace(normal);
hfs_process_first_folder = 1;
HFSApplyTo(HFSPrintInfo, 0, NULL, "Show Info", HFS_FILES_AND_FOLDERS_RECURSIVELY, 0);
}
set_folder_views()
{
long view;
view = GetFolderView(0x0100);
if (view != 0) {
ShowFeedback();
SetPort(theFeedbackWindow);
TextFace(underline);
Feedback("Show File and Folder Information");
SetPort(theFeedbackWindow);
TextFace(normal);
hfs_process_first_folder = 1;
HFSApplyTo(HFSSetFolderView, view, NULL, "Folder View", HFS_FOLDERS_RECURSIVELY, 1);
}
}
HFSApplyTo(action_proc, action_data, action_ptr, action_name, apply_to, verbose)
PFI action_proc;
long action_data;
char *action_ptr;
char *action_name;
int apply_to;
int verbose;
{
int result;
short vRefNum;
long dirID;
char this_folder[32];
char from_path[256];
CInfoPBRec cpb;
void SProgressActionProc();
yield_menus(YIELD_ON);
if (! GetFolderPathName(action_name, from_path, &vRefNum, &dirID))
{
yield_menus(YIELD_OFF);
return;
}
Feedback("Path '%s' vRef %d DirID %ld\n", from_path, vRefNum, dirID);
cpb.hFileInfo.ioCompletion = 0; /* Synchronous */
cpb.hFileInfo.ioNamePtr = this_folder; this_folder[0] = 0;
cpb.hFileInfo.ioVRefNum = vRefNum; /* Returned here */
cpb.hFileInfo.ioFDirIndex = -1; /* Get the directory in ioDirID */
cpb.hFileInfo.ioDirID = dirID; /* same offset as ioFlNum */
result = PBGetCatInfo(&cpb, (Boolean)0);/* Synchronous */
total_count = hfs_object_count(vRefNum, dirID, apply_to);
if (total_count == CANCEL) {
Feedback("%s canceled by user.", action_name);
yield_menus(YIELD_OFF);
return;
}
if (total_count == FAILURE) {
Feedback("Error counting files to %s.", action_name);
yield_menus(YIELD_OFF);
return;
}
current_count = 0;
Feedback("Total files to %s = %d.", action_name, total_count);
c2pstr(action_name);
StartProgressWindow( action_name, 0, total_count, 0, SProgressActionProc);
p2cstr(action_name);
result = do_hfs_action( vRefNum, dirID, apply_to,
action_proc, action_name, action_data, action_ptr, verbose );
StopProgressWindow();
if (result == SUCCESS)
Feedback("%s of '%sƒ' completed.", action_name, from_path);
else if (result == CANCEL)
Feedback("%s of '%sƒ' canceled by user.", action_name, from_path);
else
message_alert("%s of '%sƒ' failed [%d].", action_name, from_path, result);
yield_menus(YIELD_OFF);
InitCursor();
}
hfs_set_file_info(creator)
int creator;
{
int result;
short vRefNum;
long dirID;
OSType fdCreator;
char creator_str[32];
char this_folder[32];
char from_path[256];
CInfoPBRec cpb;
void SProgressActionProc();
yield_menus(YIELD_ON);
if (! GetFolderPathName("Set File Info...", from_path, &vRefNum, &dirID))
{
yield_menus(YIELD_OFF);
return;
}
Feedback("Path '%s' vRef %d DirID %ld\n", from_path, vRefNum, dirID);
cpb.hFileInfo.ioCompletion = 0; /* Synchronous */
cpb.hFileInfo.ioNamePtr = this_folder; this_folder[0] = 0;
cpb.hFileInfo.ioVRefNum = vRefNum; /* Returned here */
cpb.hFileInfo.ioFDirIndex = -1; /* Get the directory in ioDirID */
cpb.hFileInfo.ioDirID = dirID; /* same offset as ioFlNum */
result = PBGetCatInfo(&cpb, (Boolean)0); /* Synchronous */
strcpy(creator_str, ( creator ? "MPS " : "TEXT" ));
if (! GetInputLine( ( creator ? "New Creator:" : "New Type:" ), creator_str))
{
yield_menus(YIELD_OFF);
return;
}
sprintf((char *)&fdCreator, "%4.4s", creator_str);
total_count = hfs_object_count(vRefNum, dirID, HFS_FILES_RECURSIVELY);
if (total_count == CANCEL) {
Feedback("Change canceled by user.");
yield_menus(YIELD_OFF);
return;
}
if (total_count == FAILURE) {
Feedback("Error counting the files to be changed.");
yield_menus(YIELD_OFF);
return;
}
current_count = 0;
Feedback("Total files to change = %d.", total_count);
StartProgressWindow( ( creator ? "\pChange Creator" : "\pChange Type" ),
0, total_count, 0, SProgressActionProc);
result = do_hfs_action( vRefNum, dirID, HFS_FILES_RECURSIVELY, HFSSetFileInfo,
( creator ? "Set Creator" : "Set Type" ),
fdCreator, ( creator ? (char *)-1 : NULL ), 1 );
StopProgressWindow();
if (result == SUCCESS)
Feedback("%s change to '%sƒ' completed.",
( creator ? "Creator" : "Type" ), from_path);
else if (result == CANCEL)
Feedback("%s change to '%sƒ' canceled by user.",
( creator ? "Creator" : "Type" ), from_path);
else
message_alert("%s change to '%sƒ' failed [%d].",
( creator ? "Creator" : "Type" ), from_path, result);
yield_menus(YIELD_OFF);
InitCursor();
}
do_hfs_action(vRefNum, dirID, apply_to, action_proc, action_name, action_data, action_ptr, verbose)
int vRefNum;
long dirID;
int apply_to;
PFI action_proc;
char *action_name;
long action_data;
char *action_ptr;
int verbose;
{
short index, myresult;
CInfoPBRec cpb, parent;
char myname[48],
cname[48],
thisfolder[48];
DoYield();
thisfolder[0] = 0;
parent.hFileInfo.ioCompletion = 0; /* Synchronous */
parent.hFileInfo.ioNamePtr = thisfolder; /* Space for *returned* name */
parent.hFileInfo.ioVRefNum = vRefNum; /* Returned here */
parent.hFileInfo.ioFDirIndex = -1; /* Get the directory in ioDirID */
parent.hFileInfo.ioDirID = dirID; /* same offset as ioFlNum */
myresult = PBGetCatInfo(&parent, (Boolean)0); /* Synchronous */
if (myresult != noErr) {
Feedback("do_hfs_action: PBGetCatInfo(%d, %d) = %d\n", vRefNum, dirID, myresult);
return myresult;
}
if (hfs_process_first_folder) {
if (HFS_DO_FOLDERS(apply_to)) {
sprintf(cname, "%.*s", thisfolder[0], &thisfolder[1]);
if (verbose)
Feedback("%s '%s'...", action_name, cname);
myresult = (*action_proc) (&parent, NULL, vRefNum, dirID,
cname, action_data, action_ptr);
UpdateProgress(++current_count);
if (myresult != noErr && myresult != HFS_SKIP_DIR) {
Feedback("Error #%d %s folder '%s'.", myresult, action_name, cname);
return myresult;
}
}
}
hfs_process_first_folder = 0;
cancel_current_op = 0;
for (index=1 ; ! cancel_current_op ; index++) {
DoYield();
if (pause_op)
while (pause_op)
pausing();
if (cancel_current_op)
break;
/*
**
** GET INFO OF NEXT OBJECT...
**
*/
cpb.hFileInfo.ioCompletion = 0; /* Synchronous */
cpb.hFileInfo.ioNamePtr = myname; myname[0] = 0;
cpb.hFileInfo.ioVRefNum = vRefNum; /* Returned here */
cpb.hFileInfo.ioFDirIndex = index; /* Get the ith file/directory */
cpb.hFileInfo.ioDirID = dirID; /* same offset as ioFlNum */
myresult = PBGetCatInfo(&cpb, (Boolean)false); /* Synchronous */
if (cpb.hFileInfo.ioResult == fnfErr)
{
return SUCCESS;
}
if (cpb.hFileInfo.ioResult != noErr)
{
Feedback("do_hfs_action: PBGetCatInfo(%d, %d, #%d) = %d\n",
vRefNum, dirID, index, myresult);
return myresult;
}
/*
**
** PROCESS OBJECT
**
*/
if ((cpb.hFileInfo.ioFlAttrib & ioDirMask) != 0)
{
/* This is a DIRECTORY. */
sprintf(cname, "%.*s", myname[0], &myname[1]);
myresult = SUCCESS;
if (HFS_DO_FOLDERS(apply_to)) {
if (verbose)
Feedback("%s '%s'...", action_name, cname);
myresult = (*action_proc) (&cpb, &parent, vRefNum, dirID,
cname, action_data, action_ptr);
UpdateProgress(++current_count);
if (myresult != noErr && myresult != HFS_SKIP_DIR) {
Feedback("Error #%d %s folder '%s'.", myresult, action_name, cname);
return myresult;
}
}
if (HFS_DO_RECURSIVELY(apply_to) && myresult != HFS_SKIP_DIR) {
myresult = do_hfs_action(vRefNum, cpb.hFileInfo.ioDirID, apply_to,
action_proc, action_name, action_data, action_ptr, verbose);
switch (myresult) {
case FAILURE:
case CANCEL:
Feedback("Error #%d from do_hfs_action(%d, %d).",
myresult, vRefNum, cpb.hFileInfo.ioDirID);
return myresult;
break;
}
}
}
else
{
/* This is a FILE. */
sprintf(cname, "%.*s", myname[0], &myname[1]);
if (HFS_DO_FILES(apply_to)) {
if (verbose)
Feedback("%s '%s'...", action_name, cname);
myresult = (*action_proc) (&cpb, &parent, vRefNum, dirID,
cname, action_data, action_ptr);
UpdateProgress(++current_count);
if (myresult != noErr) {
Feedback("Error #%d %s file '%s'.", myresult, action_name, cname);
return myresult;
}
}
} /* got a file... */
} /* for objects in directory... */
return SUCCESS;
}
#define my_disk_item 69
hfs_object_count(vRefNum, dirID, count_what)
{
long mycount;
count_progress_count = 0;
StartProgressWindow("\pCount Files", 0, -1, 0, SProgressCounting);
mycount = do_hfs_object_count(vRefNum, dirID, count_what);
StopProgressWindow();
return mycount;
}
do_hfs_object_count(vRefNum, dirID, count_what)
int vRefNum;
long dirID;
int count_what;
{
short index, myresult;
int count = 0;
CInfoPBRec cpb;
char myname[48];
char thisfolder[48];
void SProgressCounting();
DoYield();
cpb.hFileInfo.ioCompletion = 0; /* Synchronous */
cpb.hFileInfo.ioNamePtr = thisfolder; thisfolder[0] = 0;
cpb.hFileInfo.ioVRefNum = vRefNum; /* Returned here */
cpb.hFileInfo.ioFDirIndex = -1; /* Get the directory in ioDirID */
cpb.hFileInfo.ioDirID = dirID; /* same offset as ioFlNum */
myresult = PBGetCatInfo(&cpb, (Boolean)0); /* Synchronous */
if (hfs_process_first_folder)
count++;
for (index=1 ; ! cancel_current_op ; index++) {
DoYield();
if (pause_op)
while (pause_op)
pausing();
if (cancel_current_op)
break;
cpb.hFileInfo.ioCompletion = 0; /* Synchronous */
cpb.hFileInfo.ioNamePtr = myname; myname[0] = 0;
cpb.hFileInfo.ioVRefNum = vRefNum; /* Returned here */
cpb.hFileInfo.ioFDirIndex = index; /* Get the ith file/directory */
cpb.hFileInfo.ioDirID = dirID; /* same offset as ioFlNum */
myresult = PBGetCatInfo(&cpb, (Boolean)false); /* Synchronous */
if (cpb.hFileInfo.ioResult == fnfErr)
{
return count;
}
if (cpb.hFileInfo.ioResult != noErr)
{
/* This is an ERROR. */
Feedback("Error #%d PBGetCatInfo(%d)!", cpb.hFileInfo.ioResult, index);
return FAILURE;
}
else if ((cpb.hFileInfo.ioFlAttrib & ioDirMask) > 0)
{
/* This is a DIRECTORY. */
UpdateProgress(++count_progress_count);
if (HFS_DO_FOLDERS(count_what))
count++;
count += do_hfs_object_count(vRefNum, cpb.hFileInfo.ioDirID, count_what);
}
else
{
/* This is a FILE. */
if (HFS_DO_FILES(count_what))
count++;
if ((++count_progress_count & 8) != 0)
UpdateProgress(count_progress_count);
} /* got a file... */
} /* for file in directory... */
return count;
}