int dir_Delete(char *pathString, int pathStringLength) {
	/* Delete the existing directory with the given path. */
    char cFileName[1000];

    if (pathStringLength >= 1000) {
        return false;
    }

	if (equalsLastPath(pathString, pathStringLength))
		lastPathValid = false;

#if defined(__MWERKS__)
	{
    	/* Delete the existing directory with the given path. */
        FSSpec spec;
        OSErr  err;

        if ((err = makeFSSpec(pathString, pathStringLength,&spec))  != noErr)
            return false;
            
       	return FSpDelete(&spec) == noErr;
    }
#else
    /* copy the file name into a null-terminated C string */
    sqFilenameFromString(cFileName, (int) pathString, pathStringLength);
    return rmdir(cFileName) == 0;
#endif
}
int dir_Delete(char *pathString, int pathStringLength) {
	/* Delete the existing directory with the given path. */
    FSSpec spec;
    OSErr  err;

    if ((err = makeFSSpec(pathString, pathStringLength,&spec)) == -1)
        return false;
        
   	return FSpDelete(&spec) == noErr;
}
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;
}
OSErr getSpecAndFInfo(char *filename, int filenameSize,FSSpec *spec,FInfo *finderInfo) {
    OSErr err;
    
    if ((err = makeFSSpec(filename, filenameSize,spec)) != noErr)
        return err;
        
    if ((err= FSpGetFInfo(spec,finderInfo)) != noErr) 
        return err;
        
    return noErr;
}
Beispiel #5
0
CFragConnectionID LoadLibViaPath(char *libName, char *pluginDirPath) {
	FSSpec				fileSpec;
	Str255				problemLibName;
        char				tempDirPath[DOCUMENT_NAME_SIZE+1];
        Ptr				junk;
	CFragConnectionID		libHandle = 0;
	OSErr				err = noErr;

	strncpy(tempDirPath,pluginDirPath,DOCUMENT_NAME_SIZE);
        if (tempDirPath[strlen(tempDirPath)-1] != DELIMITER)
            strcat(tempDirPath,DELIMITER);
            
        strcat(tempDirPath,libName);
	err =makeFSSpec(tempDirPath,&fileSpec);
	if (err) return nil; /* bad plugin directory path */

        err = GetDiskFragment(
		&fileSpec, 0, kCFragGoesToEOF, nil, kLoadCFrag, &libHandle, &junk, problemLibName);
                
        if (err) 
	    return nil;

	return libHandle;
}
Beispiel #6
0
int asyncFileOpen(AsyncFile *f, char *fileNamePtr, int fileNameSize, int writeFlag, int semaIndex) {
  /* Opens the given file using the supplied AsyncFile structure to record
	 its state. Fails with no side effects if f is already open. Files are
	 always opened in binary mode. */

	short int fileRefNum;
	AsyncFileState *state;
	OSErr err;
	void * ithisSessionfn;
	int thisSession;
        FSSpec	theSpec; 

	/* don't open an already open file */
	if (asyncFileValid(f)) return success(false);

	/* build complete routine descriptor, if necessary */
	if (asyncFileCompletionProc == nil) {
#if TARGET_API_MAC_CARBON
		asyncFileCompletionProc = NewIOCompletionUPP((pascal void (*) (union ParamBlockRec *) )asyncFileCompletionRoutine);
#else
		asyncFileCompletionProc = NewIOCompletionProc((pascal void (*) (union ParamBlockRec *) )asyncFileCompletionRoutine);
#endif
	}

	/* copy the file name into a null-terminated C string */
	if (fileNameSize > 1000) return success(false);
	
	makeFSSpec((char*) fileNamePtr, fileNameSize,&theSpec);
        
	f->sessionID = 0;
	if (writeFlag) {
		/* first try to open an existing file read/write: */
		err = FSpOpenDF(&theSpec,fsRdWrPerm, &fileRefNum); 
		if (err != noErr) {
			/* file does not exist; must create it. */
			err = FSpCreate(&theSpec,'R*ch','TEXT',smSystemScript); 
			if (err != noErr) return success(false);
			err = FSpOpenDF(&theSpec,fsRdWrPerm, &fileRefNum); 
			if (err != noErr) return success(false);
		}
	} else {
		/* open the file read-only  */
		err = FSpOpenDF(&theSpec,fsRdPerm, &fileRefNum); 
		if (err != noErr) return success(false);
	}
	f->state = (AsyncFileState *) NewPtr(sizeof(AsyncFileState));	/* allocate state record */
	if (f->state == nil) {
		FSClose(fileRefNum);
		return success(false);
	}
	ithisSessionfn = interpreterProxy->ioLoadFunctionFrom("getThisSession", "FilePlugin");
	if (ithisSessionfn != 0)
		thisSession =  ((int (*) (void)) ithisSessionfn)();
	else 
		thisSession = 0;
	f->sessionID = thisSession;
	state = (AsyncFileState *) f->state;
	state->refNum = fileRefNum;
	state->writable = writeFlag;
	state->semaIndex = semaIndex;
	state->status = IDLE;
	state->bytesTransferred = 0;
	state->bufferSize = 0;
	state->bufferPtr = nil;
	return 0;
}