示例#1
0
void SetBasePath(void)
{
	OSErr			error;
	FSSpec		where;
	//Handle		theString;
	Str255		name;
	short			vRef;
	long			dirID;
	long			nDirID;
	error = FindFolder(kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, &vRef, &dirID);
	GetIndString(name, kTransportPath, 1);
	if (name[0] != '0') {
		error = FSMakeFSSpec(vRef, dirID, name, &where);	// First, check to see if the directory exists
		if (error != noErr) {
			// Create it
			error = FSpDirCreate(&where, smSystemScript, &nDirID);
		}
		p2cstr(name);
		strncat((char *)name, "Serial", 63);	// It won't matter if this exists or not; we'll get the parent directory ID this way
		c2pstr((char *)name);
		error = FSMakeFSSpec(vRef, dirID, name, &where);
		gvRef = where.vRefNum;
		gparID = where.parID;
	}
}
示例#2
0
static boolean filecreatefolder (const tybrowserspec * fsfolder) {
	
	OSErr ec;
	long folderid;
	
	ec = FSpDirCreate (fsfolder, smSystemScript, &folderid);
	
	return (true);
	} /*filecreatefolder*/
int dir_Create(char *pathString, int pathStringLength) {
    FSSpec spec;
    OSErr  err;
    long  createdDirID;
    
    if ((err = makeFSSpec(pathString, pathStringLength,&spec)) == -1)
        return false;
        
   	return FSpDirCreate(&spec,smSystemScript,&createdDirID) == noErr;
}
示例#4
0
static OSErr MacCreateDirectory(const char *inPathname)
{
	OSErr err;
	FSSpec fss;
	ScriptCode scriptTag = 0;
	long createdDirID;
	
	err = MacPathname2FSSpec(inPathname, &fss);
	if (err != noErr) return err;
	
	err = FSpDirCreate(&fss, scriptTag, &createdDirID);
	return err;
}
示例#5
0
short file_dircreate(const char *path) {

	FSSpec	fss;
	Str255	fname;
	long	ret;

	mkstr255(fname, path);
	FSMakeFSSpec(0, 0, fname, &fss);
	if (FSpDirCreate(&fss, smSystemScript, &ret) == noErr) {
		return(0);
	}
	return(-1);
}
示例#6
0
OSErr
DirCreateRecursive(char* path)
{
	long 		count, len=strlen(path), dummyDirID;
	char 		*delim = '\0', *pathpos = path, *currDir;
	OSErr 		err = noErr;
	StringPtr	pCurrDir;
	FSSpec		currDirFSp;
	
	currDir = (char*) malloc(len+1);
	
	if ((delim=strchr(pathpos, ':'))!=0)		/* skip first since it's volName */
	{
		for (count=0; ((count<len)&&( (delim=strchr(pathpos, ':'))!=0) ); count++)
		{
			currDir[0] = '\0';
			strncpy(currDir, path, delim-path+1);
			currDir[delim-path+1] = '\0';
		
			pCurrDir = CToPascal(currDir);
			if (pCurrDir && *pCurrDir > 0)
			{
				err = FSMakeFSSpec(0, 0, pCurrDir, &currDirFSp);
				if (err == fnfErr)
				{	
					err = FSpDirCreate(&currDirFSp, smSystemScript, &dummyDirID);
					if (err!=noErr) 
					{
						if (currDir)
							free(currDir);
						if (pCurrDir)
							DisposePtr((Ptr)pCurrDir);
						return err;
					}
				}
				
				DisposePtr((Ptr)pCurrDir);
				pathpos = delim+1;
			}	
		}
	}
	
	if (currDir)
		free(currDir);
		
	return err;
}
示例#7
0
文件: FSpCompat.c 项目: zv/metamage_1
pascal	OSErr	FSpDirCreateCompat(const FSSpec *spec,
                                   ScriptCode scriptTag,
                                   long *createdDirID)
{
#if !__MACOSSEVENORLATER
    if ( !FSHasFSSpecCalls() && !QTHasFSSpecCalls() )
    {
        OSErr			result;
        UniversalFMPB	pb;

        pb.hPB.fileParam.ioVRefNum = spec->vRefNum;
        pb.hPB.fileParam.ioDirID = spec->parID;
        pb.hPB.fileParam.ioNamePtr = (StringPtr) &(spec->name);
        result = PBDirCreateSync(&(pb.hPB));
        *createdDirID = pb.hPB.fileParam.ioDirID;
        if ( result == noErr )
        {
            /* get info on created item */
            pb.ciPB.dirInfo.ioFDirIndex = 0;
            pb.ciPB.dirInfo.ioDrDirID = spec->parID;
            result = PBGetCatInfoSync(&(pb.ciPB));
            if ( result == noErr )
            {
                /* Set frScript in DXInfo */
                /* The negative script constants (smSystemScript, smCurrentScript, and smAllScripts) */
                /* don't make sense on disk, so only use scriptTag if scriptTag >= smRoman */
                /* (smRoman is 0). frScript is valid if high bit is set (see IM-6, page 9-38) */
                pb.ciPB.dirInfo.ioDrFndrInfo.frScript = (scriptTag >= smRoman) ?
                                                        ((char)scriptTag | (char)0x80) :
                                                        (smRoman);
                /* Restore ioDirID field in pb which was changed by PBGetCatInfo */
                pb.ciPB.dirInfo.ioDrDirID = spec->parID;
                result = PBSetCatInfoSync(&(pb.ciPB));
            }
        }
        return ( result );
    }
    else
#endif	/* !__MACOSSEVENORLATER */
    {
        return ( FSpDirCreate(spec, scriptTag, createdDirID) );
    }
}
示例#8
0
OSErr FSpGetDirID(FSSpec *f, long *idp, Boolean makeit) {
    CInfoPBRec pb;
    OSErr error = noErr;

    pb.dirInfo.ioNamePtr = f->name;
    pb.dirInfo.ioVRefNum = f->vRefNum;
    pb.dirInfo.ioDrDirID = f->parID;
    pb.dirInfo.ioFDirIndex = 0;
    error = PBGetCatInfoSync(&pb);
    if (error == fnfErr && makeit)
	return FSpDirCreate(f, smSystemScript, idp);
    if (error != noErr) goto out;
    if ((pb.dirInfo.ioFlAttrib & ioDirMask) == 0) {
	error = dirNFErr;
	goto out;
    }
    *idp = pb.dirInfo.ioDrDirID;

  out:
    return error;
}
示例#9
0
/*__________________________________________________________________________*/
OSErr FindMidiShareFolder (Boolean create, short * vRefNum, long * dirID)
{
	CInfoPBRec paramBlock; FSSpec spec; OSErr err;
	unsigned char * name = MidiShareDrvFolder;

	err = FindFolder(kOnSystemDisk, kSystemFolderType, false, vRefNum, dirID);
	if (err != noErr) return err;
	
	err= FSMakeFSSpec (*vRefNum, *dirID, name, &spec);
	if (err == noErr) {
		err= GetCatInfos (&paramBlock, &spec, 0);
		if (err != noErr) return err;
		if (Directory(paramBlock.hFileInfo.ioFlAttrib)) {
			*dirID = paramBlock.dirInfo.ioDrDirID;
		}
		else return fnfErr;
	}
	else if (err == fnfErr) {
		if (create)
			err = FSpDirCreate (&spec, smSystemScript, dirID);
	}
	return err;
}
static OSStatus RunOneServer(InetHost ipAddr)
	// This routine is the main line of the thread that runs
	// an HTTP server.  ipAddr is the address on which the
	// server is listening.
	//
	// The routine uses a directory whose name is the
	// dotted decimal string representation of ipAddr as the
	// root directory of the HTTP server.
{
	OSStatus 	err;
	OSStatus 	junk;
	Str255 		ipAddrString;
	FSSpec 		dirSpec;
	CInfoPBRec 	cpb;
	ServerContext *context;
	MPTaskID    junkServerThread;
	
	// Allocate a context for the preemptive thread.
	
	err = noErr;
	context = (ServerContext *) MPAllocateAligned(sizeof(*context), kMPAllocateDefaultAligned, kNilOptions);
	if (context == NULL) {
		err = memFullErr;
	}
	
	// Fill out the context.  We do this here because it needs 
	// to use services that aren't MP-safe.
	
	if (err == noErr) {
		context->ipAddr = ipAddr;
		
		// Get ipAddr as a dotted decimal Pascal string.
		OTInetHostToString(ipAddr, ((char *) ipAddrString) + 1);
		ipAddrString[0] = OTStrLength(((char *) ipAddrString) + 1);
		
		// Find the associated dirID, creating the directory
		// if necessary.

		junk = MoreProcGetCurrentProcessFSSpec(&dirSpec);
		assert(junk == noErr);
			
		(void) FSMakeFSSpec(dirSpec.vRefNum, dirSpec.parID, ipAddrString, &dirSpec);
		context->rootVRefNum = dirSpec.vRefNum;
		err = FSpGetCatInfo(&dirSpec, 0, &cpb);
		if (err == noErr && ( (cpb.hFileInfo.ioFlAttrib & (1 << 4)) != 0) ) {
			context->rootDirID = cpb.hFileInfo.ioDirID;
		} else {
			err = FSpDirCreate(&dirSpec, 0, (SInt32 *) &context->rootDirID);
		}
	}
	
	// Start a preemptive thread to run an HTTP server on the IP address.
	
	if (err == noErr) {
		err = MPCreateTask(HTTPServerProc, context, 65536, kInvalidID, NULL, NULL, kNilOptions, &junkServerThread);
		if (err == noErr) {
			context = NULL;				// it's now the task's responsibility
		}
	}
	if (context != NULL) {
		MPFree(context);
	}
	
	return err;
}
示例#11
0
OSErr
RunAllXPIs(short xpiVRefNum, long xpiDirID, short vRefNum, long dirID)
{
	OSErr 				err = noErr;
	FSSpec				tgtDirSpec, xpiStubDirSpec, xpiSpec;
	XPI_InitProc		xpi_initProc;
	XPI_InstallProc		xpi_installProc;
	XPI_ExitProc		xpi_exitProc;
	CFragConnectionID	connID;
	nsresult 			rv = NS_OK;
	StringPtr			pcurrArchive;
	int					i, len, compsDone = 0, numXPIs, currXPICount = 0, instChoice = gControls->opt->instChoice-1;
	Boolean				isCurrXPI = false, indeterminateFlag = false;
	Str255				installingStr, msg;
	StringPtr           pTargetSubfolder = "\p"; /* subfolder is optional so init empty */
	long                dummyDirID = 0;
	
    err = FSMakeFSSpec(vRefNum, dirID, kViewerFolder, &xpiStubDirSpec); /* xpistub dir */
    if (gControls->cfg->targetSubfolder)
    {
        HLock(gControls->cfg->targetSubfolder);
        if (*gControls->cfg->targetSubfolder)
            pTargetSubfolder = CToPascal(*gControls->cfg->targetSubfolder);
        HUnlock(gControls->cfg->targetSubfolder);
    }
    err = FSMakeFSSpec(gControls->opt->vRefNum, gControls->opt->dirID, /* program dir */
	                   pTargetSubfolder, &tgtDirSpec);
	if (err == fnfErr)
	    err = FSpDirCreate(&tgtDirSpec, smSystemScript, &dummyDirID);
	    
	if (err != noErr)
    {
        ErrorHandler(err, nil);
        return err;
    }

	ERR_CHECK_MSG(LoadXPIStub(&xpi_initProc, &xpi_installProc, &xpi_exitProc, &connID, xpiStubDirSpec, msg), err, msg);
	XPI_ERR_CHECK(xpi_initProc( xpiStubDirSpec, tgtDirSpec, NULL, xpicbProgress ));
	    
	// init overall xpi indicator
	numXPIs = CountSelectedXPIs();
	if (gControls->tw->allProgressBar)
	{
		SetControlMaximum(gControls->tw->allProgressBar, numXPIs*2); // numXPIs * 2 so that prog bar moves more
		SetControlData(gControls->tw->allProgressBar, kControlNoPart, kControlProgressBarIndeterminateTag,
						sizeof(indeterminateFlag), (Ptr) &indeterminateFlag);
		SetControlValue(gControls->tw->allProgressBar, 0);
		Draw1Control(gControls->tw->allProgressBar);
	}
	
	if (gControls->tw->xpiProgressBar)
		ShowControl(gControls->tw->xpiProgressBar);
		
	// enumerate through all .xpi's
	// loop through 0 to kMaxComponents
	for(i=0; i<kMaxComponents; i++)
	{
	    BreathFunc();
		// general test: if component in setup type
		if ( (gControls->cfg->st[instChoice].comp[i] == kInSetupType) &&
			 (compsDone < gControls->cfg->st[instChoice].numComps) )
		{ 
			// if custom and selected, or not custom setup type
			// add file to buffer
			if ( ((instChoice == gControls->cfg->numSetupTypes-1) && 
				  (gControls->cfg->comp[i].selected == true)) ||
				 (instChoice < gControls->cfg->numSetupTypes-1) )
			{
				// if LAUNCHAPP and DOWNLOAD_ONLY attr wasn't set
			 	if (!gControls->cfg->comp[i].launchapp && !gControls->cfg->comp[i].download_only)
				{
					HLock(gControls->cfg->comp[i].archive);
					pcurrArchive = CToPascal(*gControls->cfg->comp[i].archive);
					HUnlock(gControls->cfg->comp[i].archive);
		
					isCurrXPI = IsArchiveXPI(pcurrArchive);
								
					err = FSMakeFSSpec(xpiVRefNum, xpiDirID, pcurrArchive, &xpiSpec);
					if (err==noErr && isCurrXPI)
					{
						// update package display name
						if (gControls->tw->allProgressMsg)
						{
							ProgressMsgInit();
							GetResourcedString(installingStr, rInstList, sInstalling);
							TEInsert(&installingStr[1], installingStr[0], gControls->tw->allProgressMsg);
							HLock(gControls->cfg->comp[i].shortDesc);
							len = strlen(*gControls->cfg->comp[i].shortDesc);
							TEInsert(*gControls->cfg->comp[i].shortDesc, (len>64?64:len), gControls->tw->allProgressMsg);
							HUnlock(gControls->cfg->comp[i].shortDesc);
						}
						
						err = RunXPI(xpiSpec, &xpi_installProc);
						BreathFunc();
						if (err != NS_OK)
						    break;
						
						// update progess bar
						if (gControls->tw->allProgressBar)
							SetControlValue(gControls->tw->allProgressBar,
											GetControlValue(gControls->tw->allProgressBar)+1);
					}
					if (pcurrArchive)
						DisposePtr((Ptr) pcurrArchive);
				}
				compsDone++;
			}
		}
		else if (compsDone >= gControls->cfg->st[instChoice].numComps)
			break;  
	}
	
	xpi_exitProc();	
	UnloadXPIStub(&connID);
	
    if (pTargetSubfolder)
	    DisposePtr((Ptr)pTargetSubfolder);
	return err;
}
示例#12
0
/* create folder with IPIcon */
OSErr MakeFolderWithIPIcon(const FSSpec *theFolder,const IPIconRec *ipIcon)
{
	OSErr		err;
	long		dirID;
	FSSpec		theIconFile;
	Str15		iconFileName;
	#ifdef __MOREFILESX__
	FSRef		fsRef;
	
	#endif
	
	/* create a folder */
	err=FSpDirCreate(theFolder,smSystemScript,&dirID);
	if (err==dupFNErr || err==dirNFErr)
	{
		Boolean	isDirectory;
		
		#ifdef __MOREFILESX__
		err = FSpMakeFSRef(theFolder,&fsRef);
		err = FSGetNodeID(&fsRef,&dirID,&isDirectory);
		#else
		err=FSpGetDirectoryID(theFolder,&dirID,&isDirectory);
		#endif
		if (!isDirectory) return -1;
	}
	if (err!=noErr) return err;
	
	#ifdef __MOREFILESX__
	err = FSpMakeFSRef(theFolder,&fsRef);
	#endif
	
	/* create icon file */
	GetIndString(iconFileName,140,3);
	err=FSMakeFSSpec(theFolder->vRefNum,dirID,iconFileName,&theIconFile);
	if (err==fnfErr)
	{
		FInfo	fndrInfo;
		
		FSpCreateResFile(&theIconFile,kFinderCreator,'icon',smSystemScript);
		err=FSpGetFInfo(&theIconFile,&fndrInfo);
		fndrInfo.fdFlags |= kIsInvisible;
		err=FSpSetFInfo(&theIconFile,&fndrInfo);
	}
	
	/* save icon data */
	if (err==noErr)
	{
		short	refNum;
		IconActionUPP	addIconUPP;
		MyIconResRec	newIcon;
		#ifndef __MOREFILESX__
		DInfo			dInfo;
		#endif
		
		newIcon.resID=kCustomIconResource;
		GetIndString(newIcon.resName,141,2);
		newIcon.attrs=0;
		
		refNum=FSpOpenResFile(&theIconFile,fsWrPerm);
		UseResFile(refNum);
		
		/* save icon family(separated icons) */
		if (ipIcon->iconSuite != NULL)
		{
			addIconUPP = NewIconActionUPP(AddIconToFile);
			err=ForEachIconDo(ipIcon->iconSuite,kSelectorMyData,addIconUPP,&newIcon);
			DisposeIconActionUPP(addIconUPP);
		}
		
		/* save icns(single icon) */
		if (isIconServicesAvailable)
		{
			IconFamilyHandle	iconFamily;
			
			err=IPIconToIconFamily(ipIcon,&iconFamily);
			if (err==noErr)
			{
				SaveDataToResource(*iconFamily,GetHandleSize((Handle)iconFamily),
					kIconFamilyType,newIcon.resID,newIcon.resName,newIcon.attrs);
				DisposeHandle((Handle)iconFamily);
			}
		}
		else
			/* delete icns resource */
			DeleteIconFamilyResource();
		
		CloseResFile(refNum);
		UseResFile(gApplRefNum);
		
		/* set flag for custom icons */
		#ifdef __MOREFILESX__
		err = FSSetHasCustomIcon(&fsRef);
		err = FSClearHasBeenInited(&fsRef);
		#else
		err=FSpGetDInfo(theFolder,&dInfo);
		dInfo.frFlags |= kHasCustomIcon;
		dInfo.frFlags &= ~kHasBeenInited;
		err=FSpSetDInfo(theFolder,&dInfo);
		#endif
		
		gUsedCount.exportNum++;
	}
	
	FlushVol(0L,theFolder->vRefNum);
	
	/* update folder icon */
	UpdateFinderIcon(theFolder);
	
	return err;
}