40using namespace std::string_literals;
49bool IsWindowsLink(
const std::string &path)
51 return (path.length() > 4) && (path.rfind(
".lnk") == path.length() - 4);
79 if (IsWindowsLink(
fPath)) {
81 if (realWinPath)
fPath = realWinPath;
82 delete [] realWinPath;
92 auto hFile = CreateFile(
fPath.c_str(),
97 FILE_FLAG_BACKUP_SEMANTICS,
103 auto dwRet = GetFinalPathNameByHandle( hFile, path,
BUFSIZE, VOLUME_NAME_DOS );
105 if ((dwRet > 0) && (dwRet <
BUFSIZE))
106 if ((path[0] ==
'\\') && (path[1] ==
'\\') && (path[2] ==
'?') && (path[3] ==
'\\')) {
139 std::string path =
fPath;
141 const char *
slash =
"\\";
143 const char *
slash =
"/";
145 if (path.rfind(
slash) != path.length() - 1)
153 auto testname =
name;
160 if (pathinfores && !IsWindowsLink(path)) {
161 std::string lpath = path +
".lnk";
163 if (!pathinfores) testname.append(
".lnk");
204 std::string sname =
name;
206 if ((sname ==
".") || (sname ==
".."))
218 auto pos = fname.rfind(
".");
219 if ((pos != std::string::npos) && (pos < fname.length() - 1) && (pos > 0))
220 return fname.substr(pos+1);
232 bool Find(
const std::string &
name,
int = -1)
override
272 item->SetIcon(
"sap-icon://folder-blank"s);
277 item->SetSize(item->size);
280 time_t loctime = (time_t) item->modtime;
281 struct tm *newtime = localtime(&loctime);
283 snprintf(tmp,
sizeof(tmp),
"%d-%02d-%02d %02d:%02d", newtime->tm_year + 1900,
284 newtime->tm_mon+1, newtime->tm_mday, newtime->tm_hour,
288 item->SetMTime(
"1901-01-01 00:00");
292 snprintf(tmp,
sizeof(tmp),
"%c%c%c%c%c%c%c%c%c%c",
307 ((item->type &
kS_IRUSR) ?
'r' :
'-'),
308 ((item->type &
kS_IWUSR) ?
'w' :
'-'),
310 ((item->type &
kS_IRGRP) ?
'r' :
'-'),
311 ((item->type &
kS_IWGRP) ?
'w' :
'-'),
313 ((item->type &
kS_IROTH) ?
'r' :
'-'),
314 ((item->type &
kS_IWOTH) ?
'w' :
'-'),
324 item->SetUid(std::to_string(item->uid));
325 item->SetGid(std::to_string(item->gid));
339 if (elem)
return elem;
358 std::string
name = fname;
359 std::transform(
name.begin(),
name.end(),
name.begin(), ::tolower);
361 auto EndsWith = [
name](
const std::string &suffix) {
362 return (
name.length() > suffix.length()) ? (0 ==
name.compare (
name.length() - suffix.length(), suffix.length(), suffix)) :
false;
365 if ((EndsWith(
".c")) ||
366 (EndsWith(
".cpp")) ||
367 (EndsWith(
".cxx")) ||
368 (EndsWith(
".c++")) ||
369 (EndsWith(
".cxx")) ||
373 (EndsWith(
".hpp")) ||
374 (EndsWith(
".hxx")) ||
375 (EndsWith(
".h++")) ||
377 (EndsWith(
".txt")) ||
378 (EndsWith(
".cmake")) ||
379 (EndsWith(
".dat")) ||
380 (EndsWith(
".log")) ||
381 (EndsWith(
".xml")) ||
382 (EndsWith(
".htm")) ||
383 (EndsWith(
".html")) ||
384 (EndsWith(
".json")) ||
387 (EndsWith(
".css")) ||
389 return "sap-icon://document-text"s;
390 if ((EndsWith(
".bmp")) ||
391 (EndsWith(
".gif")) ||
392 (EndsWith(
".jpeg")) ||
393 (EndsWith(
".jpg")) ||
394 (EndsWith(
".png")) ||
396 return "sap-icon://picture"s;
397 if (EndsWith(
".root"))
398 return "sap-icon://org-chart"s;
400 return "sap-icon://document"s;
418 auto pos =
fFileName.find_last_of(
"\\/");
419 if ((pos != std::string::npos) && (pos <
fFileName.length() - 1)) {
429 : fStat(stat), fDirName(dirname), fFileName(
filename)
450 return std::equal(
name.begin(),
name.end(),
451 ownname.begin(), ownname.end(),
453 return tolower(a) == tolower(b);
457 return ownname ==
name;
471 if (icon ==
"sap-icon://document-text"s)
return kActEdit;
472 if (icon ==
"sap-icon://picture"s)
return kActImage;
473 if (icon ==
"sap-icon://org-chart"s)
return kActBrowse;
493 return std::make_unique<RSysDirLevelIter>(
GetFullName());
503 return std::string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
508 std::string content = std::string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
512 auto pos =
GetName().rfind(
".");
514 std::string image_kind =
GetName().substr(pos+1);
515 std::transform(image_kind.begin(), image_kind.end(), image_kind.begin(), ::tolower);
516 if (image_kind ==
"svg") image_kind =
"svg+xml";
518 return "data:image/"s + image_kind +
";base64,"s +
encode.Data();
535 std::string seldir = workdir;
547 while ((obj = iter()) !=
nullptr) {
549 std::string dir =
name +
"\\"s;
550 comp->Add(std::make_shared<Browsable::RWrapper>(
name, std::make_unique<RSysFile>(dir)));
555 comp->Add(std::make_shared<Browsable::RWrapper>(
"Files system", std::make_unique<RSysFile>(
"/")));
557 seldir =
"/Files system"s + seldir;
561 if (!homedir.empty())
562 comp->Add(std::make_shared<Browsable::RWrapper>(
"Home", std::make_unique<RSysFile>(homedir)));
573 std::string seldir = workdir;
584 seldir =
"/Files system"s + seldir;
#define R__LOG_ERROR(...)
#define R__LOG_DEBUG(DEBUGLEVEL,...)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
#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)
R__EXTERN TSystem * gSystem
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)
Iterator over files in in sub-directory.
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
virtual ~RSysDirLevelIter()
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 "Files ...
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
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
virtual void FreeDirectory(void *dirp)
Free a directory.
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
int GetPathInfo(const char *path, Long_t *id, Long_t *size, Long_t *flags, Long_t *modtime)
Get info about a file: id, size, flags, modification time.
virtual TList * GetVolumes(Option_t *) const
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
virtual const char * UnixPathName(const char *unixpathname)
Convert from a local pathname to a Unix pathname.
virtual const char * WorkingDirectory()
Return working directory.
virtual const char * HomeDirectory(const char *userName=nullptr)
Return the user's home directory.
virtual const char * GetError()
Return system error string.
virtual UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
std::vector< std::string > RElementPath_t
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
ROOT::Experimental::RLogChannel & BrowsableLog()
Log channel for Browsable diagnostics.