inline JBoolean jTranslateLocalToRemote1 ( const JString& localPath, const JCharacter* mountDev, const JCharacter* mountDir, JBoolean* found, JString* host, JString* remotePath ) { if (!JIsSamePartition(localPath, mountDir)) { return kJFalse; } const JString dev = mountDev; JIndex hostEndIndex; if (dev.LocateSubstring(":/", &hostEndIndex) && hostEndIndex > 1) { *host = dev.GetSubstring(1, hostEndIndex-1); #ifdef _J_CYGWIN if (host->GetLength() == 1 && 'A' <= host->GetFirstCharacter() && host->GetFirstCharacter() <= 'Z') { *host = JGetHostName(); *remotePath = localPath; JCleanPath(remotePath); *found = kJTrue; return kJTrue; } #endif jGetFullHostName(host); *remotePath = dev.GetSubstring(hostEndIndex+1, dev.GetLength()); JAppendDirSeparator(remotePath); // use JIndexRange to allow empty JIndexRange r(strlen(mountDir)+1, localPath.GetLength()); *remotePath += localPath.GetSubstring(r); JCleanPath(remotePath); *found = kJTrue; } return kJTrue; }
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(); }
void JXCurrentPathMenu::SetPath ( const JCharacter* path ) { RemoveAllItems(); JString p = path; JCleanPath(&p); JString p1, n; while (!JIsRootDirectory(p)) { JStripTrailingDirSeparator(&p); JSplitPathAndName(p, &p1, &n); PrependItem(n); SetItemImage(1, GetIcon(p), kJFalse); p = p1; } PrependItem(p); SetItemImage(1, GetIcon(p), kJFalse); const JXImage* image = NULL; GetItemImage(GetItemCount(), &image); SetTitle(GetItemText(GetItemCount()), const_cast<JXImage*>(image), kJFalse); SetUpdateAction(kDisableNone); }
inline JBoolean jTranslateRemoteToLocal1 ( const JCharacter* host, const JString& remotePath, const JCharacter* mountDev, const JCharacter* mountDir, JString* localPath ) { const JString dev = mountDev; JIndex hostEndIndex; if (dev.LocateSubstring(":/", &hostEndIndex) && hostEndIndex > 1) { JString h = dev.GetSubstring(1, hostEndIndex-1); jGetFullHostName(&h); JString p = dev.GetSubstring(hostEndIndex+1, dev.GetLength()); JAppendDirSeparator(&p); // force complete name when check BeginsWith() if (host == h && remotePath.BeginsWith(p)) { *localPath = remotePath; localPath->ReplaceSubstring(1, p.GetLength()-1, mountDir); JCleanPath(localPath); return kJTrue; } } return kJFalse; }
JBoolean JSplitPathAndName ( const JCharacter* fullName, JString* path, JString* name ) { assert( !JStringEmpty(fullName) ); JString pathAndName = fullName; assert( pathAndName.GetLastCharacter() != ACE_DIRECTORY_SEPARATOR_CHAR ); JIndex i; if (pathAndName.LocateLastSubstring(ACE_DIRECTORY_SEPARATOR_STR, &i)) { *path = pathAndName.GetSubstring(1,i); *name = pathAndName.GetSubstring(i+1, pathAndName.GetLength()); JCleanPath(path); return kJTrue; } else { *path = JGetCurrentDirectory(); *name = pathAndName; return kJFalse; } }
JString SyGApplication::GetMountPointPrefsPath ( const JCharacter* path ) const { JString s = path; JCleanPath(&s); JStripTrailingDirSeparator(&s); return s; }
JString JCombinePathAndName ( const JCharacter* path, const JCharacter* name ) { assert( !JStringEmpty(path) ); assert( !JStringEmpty(name) ); JString file = path; if (file.GetLastCharacter() != ACE_DIRECTORY_SEPARATOR_CHAR && name[0] != ACE_DIRECTORY_SEPARATOR_CHAR) { file.AppendCharacter(ACE_DIRECTORY_SEPARATOR_CHAR); } file += name; JCleanPath(&file); return file; }
JString JConvertToRelativePath ( const JCharacter* origPath, const JCharacter* origBase ) { // Check that they are both absolute paths. assert( origPath != NULL && origPath[0] == '/' && origBase != NULL && origBase[0] == '/' ); // Remove extra directory separators // and make sure that base ends with one. JString path = origPath; JCleanPath(&path); JString base = origBase; JCleanPath(&base); JAppendDirSeparator(&base); // Find and remove the matching directories at the beginning. // The while loop backs us up so we only consider complete directory names. JBoolean hadTDS = kJTrue; if (path.GetLastCharacter() != '/') { path.AppendCharacter('/'); hadTDS = kJFalse; } JSize matchLength = JCalcMatchLength(path, base); if (!hadTDS) { path.RemoveSubstring(path.GetLength(), path.GetLength()); } while (base.GetCharacter(matchLength) != '/') { matchLength--; } assert( matchLength >= 1 ); if (matchLength == 1) { return path; } if (matchLength > path.GetLength()) { base.RemoveSubstring(matchLength, matchLength); matchLength--; } path.RemoveSubstring(1, matchLength); base.RemoveSubstring(1, matchLength); if (base.IsEmpty()) { path.Prepend("./"); return path; } // The number of remaining directory separators in base // is the number of levels to go up. JSize upCount = 0; const JSize baseLength = base.GetLength(); for (JIndex i=1; i<=baseLength; i++) { if (base.GetCharacter(i) == '/') { upCount++; path.Prepend("../"); } } assert( upCount > 0 ); return path; }