40using namespace std::string_literals;
45namespace Experimental {
50bool IsWindowsLink(
const std::string &path)
52 return (path.length() > 4) && (path.rfind(
".lnk") == path.length() - 4);
80 if (IsWindowsLink(
fPath)) {
82 if (realWinPath)
fPath = realWinPath;
83 delete [] realWinPath;
93 auto hFile = CreateFile(
fPath.c_str(),
98 FILE_FLAG_BACKUP_SEMANTICS,
104 auto dwRet = GetFinalPathNameByHandle( hFile, path,
BUFSIZE, VOLUME_NAME_DOS );
106 if ((dwRet > 0) && (dwRet <
BUFSIZE))
107 if ((path[0] ==
'\\') && (path[1] ==
'\\') && (path[2] ==
'?') && (path[3] ==
'\\')) {
140 std::string path =
fPath;
142 const char *
slash =
"\\";
144 const char *
slash =
"/";
146 if (path.rfind(
slash) != path.length() - 1)
154 auto testname =
name;
161 if (pathinfores && !IsWindowsLink(path)) {
162 std::string lpath = path +
".lnk";
164 if (!pathinfores) testname.append(
".lnk");
205 std::string sname =
name;
207 if ((sname ==
".") || (sname ==
".."))
219 auto pos = fname.rfind(
".");
220 if ((pos != std::string::npos) && (pos < fname.length() - 1) && (pos > 0))
221 return fname.substr(pos+1);
233 bool Find(
const std::string &
name,
int = -1)
override
273 item->SetIcon(
"sap-icon://folder-blank"s);
278 item->SetSize(item->size);
281 time_t loctime = (time_t) item->modtime;
282 struct tm *newtime = localtime(&loctime);
284 snprintf(tmp,
sizeof(tmp),
"%d-%02d-%02d %02d:%02d", newtime->tm_year + 1900,
285 newtime->tm_mon+1, newtime->tm_mday, newtime->tm_hour,
289 item->SetMTime(
"1901-01-01 00:00");
293 snprintf(tmp,
sizeof(tmp),
"%c%c%c%c%c%c%c%c%c%c",
308 ((item->type &
kS_IRUSR) ?
'r' :
'-'),
309 ((item->type &
kS_IWUSR) ?
'w' :
'-'),
311 ((item->type &
kS_IRGRP) ?
'r' :
'-'),
312 ((item->type &
kS_IWGRP) ?
'w' :
'-'),
314 ((item->type &
kS_IROTH) ?
'r' :
'-'),
315 ((item->type &
kS_IWOTH) ?
'w' :
'-'),
325 item->SetUid(std::to_string(item->uid));
326 item->SetGid(std::to_string(item->gid));
340 if (elem)
return elem;
360 std::string
name = fname;
361 std::transform(
name.begin(),
name.end(),
name.begin(), ::tolower);
363 auto EndsWith = [
name](
const std::string &suffix) {
364 return (
name.length() > suffix.length()) ? (0 ==
name.compare (
name.length() - suffix.length(), suffix.length(), suffix)) :
false;
367 if ((EndsWith(
".c")) ||
368 (EndsWith(
".cpp")) ||
369 (EndsWith(
".cxx")) ||
370 (EndsWith(
".c++")) ||
371 (EndsWith(
".cxx")) ||
375 (EndsWith(
".hpp")) ||
376 (EndsWith(
".hxx")) ||
377 (EndsWith(
".h++")) ||
379 (EndsWith(
".txt")) ||
380 (EndsWith(
".cmake")) ||
381 (EndsWith(
".dat")) ||
382 (EndsWith(
".log")) ||
383 (EndsWith(
".xml")) ||
384 (EndsWith(
".htm")) ||
385 (EndsWith(
".html")) ||
386 (EndsWith(
".json")) ||
389 (EndsWith(
".css")) ||
391 return "sap-icon://document-text"s;
392 if ((EndsWith(
".bmp")) ||
393 (EndsWith(
".gif")) ||
394 (EndsWith(
".jpeg")) ||
395 (EndsWith(
".jpg")) ||
396 (EndsWith(
".png")) ||
398 return "sap-icon://picture"s;
399 if (EndsWith(
".root"))
400 return "sap-icon://org-chart"s;
402 return "sap-icon://document"s;
420 auto pos =
fFileName.find_last_of(
"\\/");
421 if ((pos != std::string::npos) && (pos <
fFileName.length() - 1)) {
431 : fStat(stat), fDirName(dirname), fFileName(
filename)
452 return std::equal(
name.begin(),
name.end(),
453 ownname.begin(), ownname.end(),
455 return tolower(a) == tolower(b);
459 return ownname ==
name;
473 if (icon ==
"sap-icon://document-text"s)
return kActEdit;
474 if (icon ==
"sap-icon://picture"s)
return kActImage;
475 if (icon ==
"sap-icon://org-chart"s)
return kActBrowse;
495 return std::make_unique<RSysDirLevelIter>(
GetFullName());
505 return std::string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
510 std::string content = std::string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
514 auto pos =
GetName().rfind(
".");
516 std::string image_kind =
GetName().substr(pos+1);
517 std::transform(image_kind.begin(), image_kind.end(), image_kind.begin(), ::tolower);
518 if (image_kind ==
"svg") image_kind =
"svg+xml";
520 return "data:image/"s + image_kind +
";base64,"s +
encode.Data();
537 std::string seldir = workdir;
549 while ((obj = iter()) !=
nullptr) {
551 std::string dir =
name +
"\\"s;
552 comp->Add(std::make_shared<Browsable::RWrapper>(
name, std::make_unique<RSysFile>(dir)));
557 comp->Add(std::make_shared<Browsable::RWrapper>(
"Files system", std::make_unique<RSysFile>(
"/")));
559 seldir =
"/Files system"s + seldir;
563 if (!homedir.empty())
564 comp->Add(std::make_shared<Browsable::RWrapper>(
"Home", std::make_unique<RSysFile>(homedir)));
575 std::string seldir = workdir;
586 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)
@ kFileName
"filename" - file name if applicable
@ kImage
"image64" - base64 for supported image formats (png/gif/gpeg)
@ kText
"text" - plain text for code editor
static EContentKind GetContentKind(const std::string &kind)
Find item with specified name Default implementation, should work for all.
EActionKind
Possible actions on double-click.
@ kActEdit
can provide data for text editor
@ kActBrowse
just browse (expand) item
@ kActImage
can be shown in image viewer, can provide image
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 CloseDir()
Close directory for listing.
std::string fItemName
! current item name
bool OpenDir()
Open directory for listing.
bool TestDirEntry(const std::string &name)
Check if entry of that name exists.
bool Next() override
Shift to next entry.
std::string FullDirName() const
Return full dir name with appropriate slash at the end.
bool CanItemHaveChilds() const override
Returns true if directory or is file format supported.
std::string GetFileExtension(const std::string &fname) const
std::string fCurrentName
! current file name
std::unique_ptr< RItem > CreateItem() override
Create generic description item for RBrowser.
bool NextDirEntry()
Trying to produce next entry.
virtual ~RSysDirLevelIter()
RSysDirLevelIter(const std::string &path="")
FileStat_t fCurrentStat
! stat for current file name
std::string GetItemName() const override
Returns current entry name
void * fDir
! current directory handle
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 fPath
! fully qualified path without final slash
std::shared_ptr< RElement > GetElement() override
Returns full information for current element.
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 fFileName
! file name in current dir
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 fDirName
! fully-qualified directory name
FileStat_t fStat
! file stat object
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
RLogChannel & BrowsableLog()
Log channel for Browsable diagnostics.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.