Ejemplo n.º 1
0
/* Creates directory. */
HXBOOL 
CHXDirectory::Create()
{
	OSErr err = fnfErr;
	
	CHXDirSpecifier dirSpec(m_strPath);
	
	if (dirSpec.IsSet())
	{
		// create the file if it doesn't already exist
		FSRef parentRef;
		HFSUniStr255 hfsName;
		FSRef newRef;
		UInt32 newDirID;
		
		parentRef = (FSRef) dirSpec.GetParentDirectory();
		hfsName = dirSpec.GetNameHFSUniStr255();
		
		FSCatalogInfo * kDontSetCatInfo = NULL;
		FSSpec *kDontWantSpec = NULL;
		
		err = FSCreateDirectoryUnicode(&parentRef, hfsName.length,
			hfsName.unicode, kFSCatInfoNone, kDontSetCatInfo,
			&newRef, kDontWantSpec, &newDirID);
		
	}
	
	
	return (err == noErr);
}
Ejemplo n.º 2
0
static OSStatus FindSNESFolder (FSRef *folderRef, char *folderPath, const char *folderName)
{
	OSStatus	err;
	CFURLRef	burl, purl;
	CFStringRef	fstr;
	FSRef		pref;
	UniChar		buffer[PATH_MAX + 1];
	Boolean		r;

	fstr = CFStringCreateWithCString(kCFAllocatorDefault, folderName, CFStringGetSystemEncoding());
	CFStringGetCharacters(fstr, CFRangeMake(0, CFStringGetLength(fstr)), buffer);

	burl = CFBundleCopyBundleURL(CFBundleGetMainBundle());
	purl = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, burl);
	r    = CFURLGetFSRef(purl, &pref);

	err = FSMakeFSRefUnicode(&pref, CFStringGetLength(fstr), buffer, kTextEncodingUnicodeDefault, folderRef);
	if (err == dirNFErr || err == fnfErr)
	{
		err = FSCreateDirectoryUnicode(&pref, CFStringGetLength(fstr), buffer, kFSCatInfoNone, NULL, folderRef, NULL, NULL);
		if (err == noErr)
			AddFolderIcon(folderRef, folderName);
	}

	if (err == noErr)
		err = FSRefMakePath(folderRef, (unsigned char *) folderPath, PATH_MAX);

	CFRelease(purl);
	CFRelease(burl);
	CFRelease(fstr);

	return (err);
}
Ejemplo n.º 3
0
static OSErr FindApplicationSupportFolder(FSRef *folderRef, char *folderPath, const char *folderName)
{
	OSErr		err;
	FSRef		p2ref, p1ref;
	CFStringRef	fstr;
	UniChar		buffer[PATH_MAX + 1];
	UniChar		s9xfolder[6] = { 'S', 'n', 'e', 's', '9', 'x' },
				oldfolder[6] = { 'S', 'N', 'E', 'S', '9', 'X' };

	err = FSFindFolder(kUserDomain, kApplicationSupportFolderType, kCreateFolder, &p2ref);
	if (err)
		return (err);

	err = FSMakeFSRefUnicode(&p2ref, 6, s9xfolder, kTextEncodingUnicodeDefault, &p1ref);
	if (err == dirNFErr || err == fnfErr)
	{
		err = FSMakeFSRefUnicode(&p2ref, 6, oldfolder, kTextEncodingUnicodeDefault, &p1ref);
		if (err == dirNFErr || err == fnfErr)
			err = FSCreateDirectoryUnicode(&p2ref, 6, s9xfolder, kFSCatInfoNone, nil, &p1ref, nil, nil);
	}
	if (err)
		return (err);

	fstr = CFStringCreateWithCString(kCFAllocatorDefault, folderName, CFStringGetSystemEncoding());
	CFStringGetCharacters(fstr, CFRangeMake(0, CFStringGetLength(fstr)), buffer);

	err = FSMakeFSRefUnicode(&p1ref, CFStringGetLength(fstr), buffer, kTextEncodingUnicodeDefault, folderRef);
 	if (err == dirNFErr || err == fnfErr)
	{
		err = FSCreateDirectoryUnicode(&p1ref, CFStringGetLength(fstr), buffer, kFSCatInfoNone, nil, folderRef, nil, nil);
		if (err == noErr)
			AddFolderIcon(folderRef, folderName);
	}

	if (err != noErr && !folderWarning)
	{
		AppearanceAlert(kAlertCautionAlert, kFolderFail, kFolderHint);
		folderWarning = true;
	}
	else
		err = FSRefMakePath(folderRef, (unsigned char *) folderPath, PATH_MAX);

	CFRelease(fstr);

	return err;
}
int dir_Create(char *pathString, int pathStringLength) {
	/* Create a new directory with the given path. By default, this
	   directory is created in the current directory. Use
	   a full path name such as "MyDisk:Working:New Folder" to
	   create folders elsewhere. */

    char cFileName[1001];

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

    /* copy the file name into a null-terminated C string */
    sqFilenameFromString((char *) cFileName, (int) pathString, pathStringLength);
    
#if defined(__MWERKS__)
	{
        CFStringRef 	filePath,lastFilePath;
        CFURLRef 	    sillyThing,sillyThing2;
        FSRef	        parentFSRef;
        UniChar         buffer[1024];
        long            tokenLength;
		int err;
        
        filePath   = CFStringCreateWithBytes(kCFAllocatorDefault,(UInt8 *)cFileName,strlen(cFileName),gCurrentVMEncoding,false);
        if (filePath == nil) 
            return false;
        sillyThing = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,filePath,kCFURLHFSPathStyle,true);
        CFRelease(filePath);

        lastFilePath = CFURLCopyLastPathComponent(sillyThing);
        tokenLength = CFStringGetLength(lastFilePath);
        if (tokenLength > 1024)
            return false;
        CFStringGetCharacters(lastFilePath,CFRangeMake(0,tokenLength),buffer);
        CFRelease(lastFilePath);

        sillyThing2 = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault,sillyThing);

        err = CFURLGetFSRef(sillyThing2,&parentFSRef);
        CFRelease(sillyThing);
        CFRelease(sillyThing2);
        if (err == 0) {
            return false;  
        }
		err = FSCreateDirectoryUnicode(&parentFSRef,tokenLength,buffer,kFSCatInfoNone,NULL,NULL,NULL,NULL);
		
    	return (err == noErr ? 1 : 0);
    }
#else
    return mkdir(cFileName, 0777) == 0;
#endif
}
Ejemplo n.º 5
0
HLFileSystemObject*	HLDirectoryFactory::Create(const FSRef& inParentFSRef, CFStringRef inName, const void* inData, UInt32 inDataSize)
{
	CACFString theDirectoryName(inName, false);
	UInt32 theDirectoryNameLength = 255;
	UniChar	theDirectoryNameString[255];
	theDirectoryName.GetUnicodeString(theDirectoryNameString, theDirectoryNameLength);
	
	//	create the directory
	FSRef theFSRef;
	OSStatus theError = FSCreateDirectoryUnicode(&inParentFSRef, theDirectoryNameLength, theDirectoryNameString, kFSCatInfoNone, NULL, &theFSRef, NULL, NULL);
	ThrowIfError(theError, CAException(theError), "HLDirectoryFactory::Create: couldn't create the directory");
	
	return Allocate(theFSRef);
}
Ejemplo n.º 6
0
static OSStatus CFCreateDirectory(FSRef	*parentRef, CFStringRef name, FSRef *newRef)
{
	OSStatus		result = noErr;
	HFSUniStr255	uniStr;
	
	uniStr.length = CFStringGetLength(name);
	CFStringGetCharacters(name, CFRangeMake(0, uniStr.length), uniStr.unicode);
	result = FSMakeFSRefUnicode(parentRef, uniStr.length, uniStr.unicode, kTextEncodingMacRoman, newRef);
	if (result != noErr)
	{
		result = FSCreateDirectoryUnicode(parentRef, uniStr.length, uniStr.unicode, 0, NULL, newRef, NULL, NULL);
	}

	return result;
}
Ejemplo n.º 7
0
void myCreateFolder(t_mkdir, t_symbol *newfoldername) 
// short CreateFolder(const FSRef parentFolder, const CFStringRef folderName) 
{
	OSErr myerr;
	long len;
	short path;
	char name[256];
	char inname[2048];
	char name[2048];
	char parentname[2048];
	FSSpec fs;
	CFStringRef str;
	CFURLRef url;
	HFSUniStr255 folderNameU;


	path_nameconform(inname, newfoldername->s_name, PATH_STYLE_NATIVE, PATH_TYPE_ABSOLUTE);	
	len = strlen(inname);
	strrchr();
	filename = strrchr(name, '/') + 1;

	if (!path_topathname(path, "", inname)) { // check if path alreay exists
	
		path_nameconform(outname, natname, PATH_STYLE_NATIVE, PATH_TYPE_ABSOLUTE);
		
		path_tospec(0, natname, &fs);
	
		str = CFStringCreateWithCString(kCFAllocatorDefault, name, kCFStringEncodingASCII);
		
		folderNameU.length = (UInt16) CFStringGetLength(str);
		
		CFStringGetCharacters(folderName, CFRangeMake(0, folderNameU.length), folderNameU.unicode);

		// see if it already exists?
		myerr = FSMakeFSRefUnicode(&parentname, folderNameU.length,folderNameU.unicode,
							kTextEncodingUnicodeDefault, NULL);
		// should now verify that is, in fact, a folder.
	
		if (myerr != noErr) { // no, so try to create it.		
			myerr = FSCreateDirectoryUnicode(&parentFolder, folderNameU.length, folderNameU.unicode,
				kFSCatInfoNone, NULL, NULL, NULL, NULL);
		}
		return myerr;	
	}
}
Ejemplo n.º 8
0
extern char* vr_findVerRegName()
{
    OSErr   err;
    FSRef   foundRef;
    
    err = FSFindFolder(kLocalDomain, kDomainLibraryFolderType, kDontCreateFolder, &foundRef);
    if (err == noErr)
    {
        FSRef parentRef;
        err = FSMakeFSRefUnicode(&foundRef, UNICHAR_ARRAY_LEN(kOSXRegParentName), kOSXRegParentName,
                                 kTextEncodingUnknown, &parentRef);
        if (err == fnfErr)
        {
            err = FSCreateDirectoryUnicode(&foundRef, UNICHAR_ARRAY_LEN(kOSXRegParentName), kOSXRegParentName,
                                           kFSCatInfoNone, NULL, &parentRef, NULL, NULL);
        }
        if (err == noErr)
        {
            FSRef regRef;
            err = FSMakeFSRefUnicode(&parentRef, UNICHAR_ARRAY_LEN(kOSXVersRegName), kOSXVersRegName,
                                     kTextEncodingUnknown, &regRef);
            if (err == fnfErr)
            {
                FSCatalogInfo catalogInfo;
                FileInfo fileInfo = { 'REGS', 'MOSS', 0, { 0, 0 }, 0 };
                memmove(&(catalogInfo.finderInfo), &fileInfo, sizeof(FileInfo));
                err = FSCreateFileUnicode(&parentRef, UNICHAR_ARRAY_LEN(kOSXVersRegName), kOSXVersRegName,
                                               kFSCatInfoFinderInfo, &catalogInfo, &regRef, NULL);
            }
            if (err == noErr)
            {
                UInt8 pathBuf[PATH_MAX];
                err = FSRefMakePath(&regRef, pathBuf, sizeof(pathBuf));
                if (err == noErr)
                    verRegName = XP_STRDUP((const char*)pathBuf);
            }
        }
    }
    return verRegName;
}
Ejemplo n.º 9
0
// -------------------------------------------------------------------------- //
//  * CreateFolder( const KUInt16* )
// -------------------------------------------------------------------------- //
TDCLFSItemRef
TDCLMacCarbonFolder::CreateFolder( const KUInt16 *inName )
{
	FSRef newRef;
	OSErr theErr = FSCreateDirectoryUnicode(
							&mRef,
							UUTF16CStr::StrLen(inName),
							inName,
							0L,
							NULL,
							&newRef,
							NULL,
							NULL); 

	if (theErr)
	{
		throw DCLPlatformUnknownError( theErr );
	}
	
	return TDCLFSItemRef(
				new TDCLMacCarbonFolder(
					(TDCLMacFiles*) GetFilesIntf(), &newRef ) );
}
Ejemplo n.º 10
0
void filecontainer_gettemppath(t_filecontainer *x)
{
    char			temppath[512];
    char			outpath[512];
    t_symbol		*unique = symbol_unique();
    OSErr			err = 0;
#ifdef MAC_VERSION
    FSRef			folderref, newref;
    UniChar			uni[512];
    unsigned short	i;

    err = FSFindFolder(kUserDomain, kTemporaryFolderType, kCreateFolder, &folderref);
    err = FSRefMakePath(&folderref, (UInt8 *)temppath, 511);
    strcat(temppath, "/");
#else // WIN_VERSION
    GetTempPath(512, (LPSTR)temppath);
#endif
    strcat(temppath, unique->s_name);

#ifdef MAC_VERSION
    for(i=0; i<strlen(unique->s_name); i++)					// Convert from 8-bit ASCII to 16-bit Unicode
        uni[i] = unique->s_name[i];

    err = FSCreateDirectoryUnicode(&folderref, strlen(unique->s_name), uni,
                                   kFSCatInfoNone, NULL, &newref, NULL, NULL);
#else // WIN_VERSION
    CreateDirectory((LPCSTR)temppath, NULL);
#endif

    path_nameconform(temppath, outpath, PATH_STYLE_MAX, PATH_TYPE_ABSOLUTE);
    x->temp_fullpath = gensym(outpath);
    path_frompathname(outpath, &x->temp_path, temppath);	// re-using temppath since we don't need it anymore

    // Add to the searchpath
    path_addnamed(SEARCH_PATH, outpath, 1, 0);
}
Ejemplo n.º 11
0
static OSStatus FindCustomFolder (FSRef *folderRef, char *folderPath, const char *folderName)
{
	OSStatus	err;
	CFStringRef	fstr;
	FSRef		pref;
	UniChar		buffer[PATH_MAX + 1];
	char		s[PATH_MAX + 1];

	if (saveFolderPath == NULL)
		return (-1);

	err = CFStringGetCString(saveFolderPath, s, PATH_MAX, kCFStringEncodingUTF8) ? noErr : -1;
	if (err == noErr)
		err = FSPathMakeRef((unsigned char *) s, &pref, NULL);

	if (err)
		return (err);

	fstr = CFStringCreateWithCString(kCFAllocatorDefault, folderName, CFStringGetSystemEncoding());
	CFStringGetCharacters(fstr, CFRangeMake(0, CFStringGetLength(fstr)), buffer);

	err = FSMakeFSRefUnicode(&pref, CFStringGetLength(fstr), buffer, kTextEncodingUnicodeDefault, folderRef);
	if (err == dirNFErr || err == fnfErr)
	{
		err = FSCreateDirectoryUnicode(&pref, CFStringGetLength(fstr), buffer, kFSCatInfoNone, NULL, folderRef, NULL, NULL);
		if (err == noErr)
			AddFolderIcon(folderRef, folderName);
	}

	if (err == noErr)
		err = FSRefMakePath(folderRef, (unsigned char *) folderPath, PATH_MAX);

	CFRelease(fstr);

	return (err);
}