JError JCreateDirectory ( const JCharacter* dirName, const mode_t mode ) { if (JDirectoryExists(dirName)) { return JSetPermissions(dirName, mode); } JString path = dirName; JCleanPath(&path); JAppendDirSeparator(&path); JString dir; JIndex slashIndex = 2; while (path.LocateNextSubstring("/", &slashIndex)) { dir = path.GetSubstring(1, slashIndex); if (!JDirectoryExists(dir)) { const JError err = JMkDir(dir, mode); if (!err.OK()) { return err; } } slashIndex++; // move past the slash we found } return JNoError(); }
JBoolean SyGGetTrashDirectory ( JString* path, const JBoolean reportErrors ) { if (!theTrashDir.IsEmpty()) { *path = theTrashDir; return kJTrue; } if (!JGetPrefsDirectory(path)) { if (reportErrors) { (JGetUserNotification())->ReportError(JGetString(kNoPrefsDirID)); } return kJFalse; } *path = JCombinePathAndName(*path, kTrashDirName); JError err = JNoError(); if (!JDirectoryExists(*path)) { err = JCreateDirectory(*path, kTrashCanPerms); } else { err = JSetPermissions(*path, kTrashCanPerms); } if (err.OK()) { theTrashDir = *path; const JBoolean ok = JDirInfo::Create(theTrashDir, &theTrashDirInfo); assert( ok ); return kJTrue; } else { path->Clear(); if (reportErrors) { (JGetStringManager())->ReportError(kCreateTrashErrorID, err); } return kJFalse; } }
JBoolean SyGGetRecentFileDirectory ( JString* path, const JBoolean reportErrors ) { if (!theRecentFileDir.IsEmpty()) { *path = theRecentFileDir; return kJTrue; } if (!JGetPrefsDirectory(path)) { if (reportErrors) { (JGetUserNotification())->ReportError(JGetString(kNoPrefsDirID)); } return kJFalse; } *path = JCombinePathAndName(*path, kRecentFileDirName); JError err = JNoError(); if (!JDirectoryExists(*path)) { err = JCreateDirectory(*path, kRecentFileDirPerms); } else { err = JSetPermissions(*path, kRecentFileDirPerms); } if (err.OK()) { theRecentFileDir = *path; return kJTrue; } else { path->Clear(); if (reportErrors) { (JGetStringManager())->ReportError(kCreateRecentFileDirErrorID, err); } return kJFalse; } }