39using namespace std::string_literals;
48bool IsWindowsLink(
const std::string &path)
50 return (path.length() > 4) && (path.rfind(
".lnk") == path.length() - 4);
78 if (IsWindowsLink(
fPath)) {
79 char *realWinPath =
gSystem->ExpandPathName(
fPath.c_str());
80 if (realWinPath)
fPath = realWinPath;
81 delete [] realWinPath;
91 auto hFile = CreateFile(
fPath.c_str(),
96 FILE_FLAG_BACKUP_SEMANTICS,
102 auto dwRet = GetFinalPathNameByHandle( hFile, path,
BUFSIZE, VOLUME_NAME_DOS );
104 if ((dwRet > 0) && (dwRet <
BUFSIZE))
105 if ((path[0] ==
'\\') && (path[1] ==
'\\') && (path[2] ==
'?') && (path[3] ==
'\\')) {
138 std::string path =
fPath;
140 const char *
slash =
"\\";
142 const char *
slash =
"/";
144 if (path.rfind(
slash) != path.length() - 1)
152 auto testname =
name;
159 if (pathinfores && !IsWindowsLink(path)) {
160 std::string lpath = path +
".lnk";
162 if (!pathinfores) testname.append(
".lnk");
203 std::string sname =
name;
205 if ((sname ==
".") || (sname ==
".."))
217 auto pos = fname.rfind(
".");
218 if ((
pos != std::string::npos) && (
pos < fname.length() - 1) && (
pos > 0))
219 return fname.substr(
pos+1);
231 bool Find(
const std::string &
name,
int = -1)
override
271 item->SetIcon(
"sap-icon://folder-blank"s);
276 item->SetSize(item->size);
279 time_t loctime = (time_t) item->modtime;
280 struct tm *newtime = localtime(&loctime);
282 snprintf(tmp,
sizeof(tmp),
"%d-%02d-%02d %02d:%02d", newtime->tm_year + 1900,
283 newtime->tm_mon+1, newtime->tm_mday, newtime->tm_hour,
287 item->SetMTime(
"1901-01-01 00:00");
291 snprintf(tmp,
sizeof(tmp),
"%c%c%c%c%c%c%c%c%c%c",
306 ((item->type &
kS_IRUSR) ?
'r' :
'-'),
307 ((item->type &
kS_IWUSR) ?
'w' :
'-'),
309 ((item->type &
kS_IRGRP) ?
'r' :
'-'),
310 ((item->type &
kS_IWGRP) ?
'w' :
'-'),
312 ((item->type &
kS_IROTH) ?
'r' :
'-'),
313 ((item->type &
kS_IWOTH) ?
'w' :
'-'),
323 item->SetUid(std::to_string(item->uid));
324 item->SetGid(std::to_string(item->gid));
338 if (elem)
return elem;
357 std::string
name = fname;
358 std::transform(
name.begin(),
name.end(),
name.begin(), ::tolower);
361 return (
name.length() > suffix.length()) ? (0 ==
name.compare (
name.length() - suffix.length(), suffix.length(), suffix)) :
false;
369 return "sap-icon://document-text"s;
372 return "sap-icon://picture"s;
374 return "sap-icon://org-chart"s;
376 return "sap-icon://document"s;
387 R__LOG_DEBUG(0, BrowsableLog()) <<
"Broken symlink of " << fFileName;
389 R__LOG_DEBUG(0, BrowsableLog()) <<
"Can't read file attributes of \"" << fFileName
390 <<
"\" err:" << gSystem->GetError();
394 auto pos = fFileName.find_last_of(
"\\/");
395 if ((
pos != std::string::npos) && (
pos < fFileName.length() - 1)) {
396 fDirName = fFileName.substr(0, pos+1);
397 fFileName.erase(0, pos+1);
426 return std::equal(
name.begin(),
name.end(),
427 ownname.begin(), ownname.end(),
429 return tolower(a) == tolower(b);
433 return ownname ==
name;
447 if (icon ==
"sap-icon://document-text"s)
return kActEdit;
448 if (icon ==
"sap-icon://picture"s)
return kActImage;
449 if (icon ==
"sap-icon://org-chart"s)
return kActBrowse;
469 return std::make_unique<RSysDirLevelIter>(
GetFullName());
479 return std::string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
484 std::string content = std::string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
490 std::string image_kind =
GetName().substr(
pos+1);
491 std::transform(image_kind.begin(), image_kind.end(), image_kind.begin(), ::tolower);
492 if (image_kind ==
"svg") image_kind =
"svg+xml";
494 return "data:image/"s + image_kind +
";base64,"s + encode.Data();
511 std::string seldir = workdir;
514 seldir =
gSystem->WorkingDirectory();
516 seldir =
gSystem->UnixPathName(seldir.c_str());
518 auto volumes =
gSystem->GetVolumes(
"all");
523 while ((obj = iter()) !=
nullptr) {
525 std::string dir =
name +
"\\"s;
526 comp->Add(std::make_shared<Browsable::RWrapper>(
name, std::make_unique<RSysFile>(dir)));
531 comp->Add(std::make_shared<Browsable::RWrapper>(
"File system", std::make_unique<RSysFile>(
"/")));
533 seldir =
"/File system"s + seldir;
535 std::string homedir =
gSystem->UnixPathName(
gSystem->HomeDirectory());
537 if (!homedir.empty())
538 comp->Add(std::make_shared<Browsable::RWrapper>(
"Home", std::make_unique<RSysFile>(homedir)));
549 std::string seldir = workdir;
552 seldir =
gSystem->WorkingDirectory();
554 seldir =
gSystem->UnixPathName(seldir.c_str());
556 auto volumes =
gSystem->GetVolumes(
"all");
560 seldir =
"/File system"s + seldir;
#define R__LOG_ERROR(...)
#define R__LOG_DEBUG(DEBUGLEVEL,...)
#define INVALID_HANDLE_VALUE
Bool_t R_ISFIFO(Int_t mode)
Bool_t R_ISSOCK(Int_t mode)
Bool_t R_ISBLK(Int_t mode)
Bool_t R_ISREG(Int_t mode)
Bool_t R_ISDIR(Int_t mode)
Bool_t R_ISCHR(Int_t mode)
static EContentKind GetContentKind(const std::string &kind)
Find item with specified name Default implementation, should work for all.
@ kFileName
"filename" - file name if applicable
@ kText
"text" - plain text for code editor
@ kImage
"image64" - base64 for supported image formats (png/gif/gpeg)
EActionKind
Possible actions on double-click.
@ kActImage
can be shown in image viewer, can provide image
@ kActBrowse
just browse (expand) item
@ kActEdit
can provide data for text editor
static RElementPath_t ParsePath(const std::string &str)
Parse string path to produce RElementPath_t One should avoid to use string pathes as much as possible...
Iterator over single level hierarchy like any array, keys list, ...
static bool IsFileFormatSupported(const std::string &extension)
static std::shared_ptr< RElement > OpenFile(const std::string &extension, const std::string &fullname)
~RSysDirLevelIter() override
void * fDir
! current directory handle
FileStat_t fCurrentStat
! stat for current file name
bool Find(const std::string &name, int=-1) override
Find item with specified name Default implementation, should work for all If index specified,...
std::string fItemName
! current item name
void CloseDir()
Close directory for listing.
std::string GetFileExtension(const std::string &fname) const
std::string FullDirName() const
Return full dir name with appropriate slash at the end.
std::shared_ptr< RElement > GetElement() override
Returns full information for current element.
bool TestDirEntry(const std::string &name)
Check if entry of that name exists.
std::string fCurrentName
! current file name
RSysDirLevelIter(const std::string &path="")
std::string fPath
! fully qualified path without final slash
std::unique_ptr< RItem > CreateItem() override
Create generic description item for RBrowser.
bool OpenDir()
Open directory for listing.
bool NextDirEntry()
Trying to produce next entry.
bool Next() override
Shift to next entry.
bool CanItemHaveChilds() const override
Returns true if directory or is file format supported.
std::string GetItemName() const override
Returns current entry name.
std::string GetFullName() const
Returns full file name - including fully qualified path.
std::unique_ptr< RLevelIter > GetChildsIter() override
Returns iterator for files in directory.
std::string fDirName
! fully-qualified directory name
FileStat_t fStat
! file stat object
RSysFile(const std::string &filename)
Create file element.
std::string GetName() const override
Name of RElement - file name in this case.
static std::string GetFileIcon(const std::string &fname)
Get icon for the type of given file name.
EActionKind GetDefaultAction() const override
Get default action for the file Either start text editor or image viewer or just do file browsing.
std::string GetContent(const std::string &kind) override
Returns file content of requested kind.
static RElementPath_t ProvideTopEntries(std::shared_ptr< RGroup > &comp, const std::string &workdir="")
Provide top entries for file system On windows it is list of existing drivers, on Linux it is "File s...
bool MatchName(const std::string &name) const override
Checks if element name match to provided value.
std::string fFileName
! file name in current dir
static RElementPath_t GetWorkingPath(const std::string &workdir="")
Return working path in browser hierarchy.
static TString Encode(const char *data)
Transform data into a null terminated base64 string.
Mother of all ROOT objects.
virtual const char * GetName() const
Returns name of object.
const char * Data() const
std::vector< std::string > RElementPath_t
bool EndsWith(std::string_view string, std::string_view suffix)
ROOT::RLogChannel & BrowsableLog()
Log channel for Browsable diagnostics.