Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
TSystemFile.cxx
Go to the documentation of this file.
1// @(#)root/base:$Id$
2// Author: Rene Brun 26/06/96
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/** \class TSystemFile
13\ingroup Base
14
15A TSystemFile describes an operating system file.
16The information is used by the browser (see TBrowser).
17*/
18
19#include "TSystemFile.h"
20#include "TBrowser.h"
21#include "TSystem.h"
22#include "TEnv.h"
23
24
25
26////////////////////////////////////////////////////////////////////////////////
27/// TSystemFile default constructor
28
32
33////////////////////////////////////////////////////////////////////////////////
34/// TSystemFile normal constructor
35
36TSystemFile::TSystemFile(const char *filename, const char *dirname)
37 : TNamed(filename, dirname)
38{
40}
41
42////////////////////////////////////////////////////////////////////////////////
43/// Delete TSystemFile object.
44
48
49////////////////////////////////////////////////////////////////////////////////
50/// Check if object is a directory.
51
52Bool_t TSystemFile::IsDirectory(const char *dir) const
53{
55 Long_t id, flags, modtime;
56
57 flags = id = size = modtime = 0;
58 gSystem->GetPathInfo(!dir ? fName.Data() : dir, &id, &size, &flags, &modtime);
59 Int_t isdir = (Int_t)flags & 2;
60
61 return isdir ? kTRUE : kFALSE;
62}
63
64////////////////////////////////////////////////////////////////////////////////
65/// Execute default action for this system file (action is specified
66/// in the $HOME/.root.mimes or $ROOTSYS/etc/root.mimes file.
67
69{
70 if (b)
71 b->ExecuteDefaultAction(this);
72}
73
74////////////////////////////////////////////////////////////////////////////////
75/// Invoke text editor on this file
76
78{
79#ifndef _WIN32
80 const char *ed = gEnv->GetValue("Editor", "vi");
81 Int_t nch = strlen(ed)+strlen(GetName()) + 50;
82 Char_t *cmd = new Char_t[nch];
83 if (!strcmp(ed, "vi"))
84 snprintf(cmd,nch, "xterm -e vi %s &", GetName());
85 else
86 snprintf(cmd,nch, "%s %s &", ed, GetName());
87#else
88 const char *ed = gEnv->GetValue("Editor", "notepad");
89 Int_t nch = strlen(ed)+strlen(GetName()) + 50;
90 Char_t *cmd = new Char_t[nch];
91 snprintf(cmd,nch, "start %s %s", ed, GetName());
92#endif
93 gSystem->Exec(cmd);
94
95 delete [] cmd;
96}
97
98////////////////////////////////////////////////////////////////////////////////
99/// copy this file
100
101void TSystemFile::Copy(const char *to)
102{
103 TString name = to;
104
105 if (IsDirectory(to)) {
106 if (name.EndsWith("/")) name.Chop();
107 TString temp = fName;
108 name = gSystem->PrependPathName(name, temp);
109 }
110
111 Int_t status = gSystem->CopyFile(fName, name, kFALSE);
112
113 if (status == -2) {
114 Warning("Copy", "File %s already exists", name.Data());
115 } else if (status == -1) {
116 Warning("Copy", "Failed to move file %s", name.Data());
117 }
118}
119
120////////////////////////////////////////////////////////////////////////////////
121/// move this file
122
123void TSystemFile::Move(const char *to)
124{
125 if (!to) {
126 Warning("Move", "No file/dir name specified");
127 return;
128 }
129
130 TString name = to;
131
132 if (IsDirectory(to)) {
133 if (name.EndsWith("/")) name.Chop();
134 TString temp = fName;
135 name = gSystem->PrependPathName(name, temp);
136 }
137 Int_t status = gSystem->CopyFile(fName, name, kFALSE);
138
139 if (!status) {
140 gSystem->Unlink(fName);
141 } else if (status == -2) {
142 Warning("Move", "File %s already exists", name.Data());
143 } else if (status == -1) {
144 Warning("Move", "Failed to move file %s", name.Data());
145 }
146}
147
148////////////////////////////////////////////////////////////////////////////////
149/// delete this file
150
152{
153 gSystem->Unlink(fName);
154}
155
156////////////////////////////////////////////////////////////////////////////////
157/// rename this file
158
159void TSystemFile::Rename(const char *name)
160{
161 gSystem->Rename(fName, name);
162}
163
164////////////////////////////////////////////////////////////////////////////////
165/// inspect this file
166
168{
169}
170
171////////////////////////////////////////////////////////////////////////////////
172/// dump this file
173
175{
176}
177
#define b(i)
Definition RSha256.hxx:100
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
char Char_t
Character 1 byte (char).
Definition RtypesCore.h:51
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:68
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
externTEnv * gEnv
Definition TEnv.h:170
XFontStruct * id
Definition TGX11.cxx:147
char name[80]
Definition TGX11.cxx:148
externTSystem * gSystem
Definition TSystem.h:582
#define snprintf
Definition civetweb.c:1579
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
TNamed()
Definition TNamed.h:38
TString fName
Definition TNamed.h:32
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1084
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:888
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:71
Basic string class.
Definition TString.h:138
TSystemFile()
TSystemFile default constructor.
void Dump() const override
dump this file
virtual void Move(const char *to)
move this file
virtual void Delete()
delete this file
virtual void Rename(const char *name)
rename this file
virtual void Edit()
Invoke text editor on this file.
void Browse(TBrowser *b) override
Execute default action for this system file (action is specified in the $HOME/.root....
void Inspect() const override
inspect this file
virtual void Copy(const char *to)
copy this file
virtual Bool_t IsDirectory(const char *dir=nullptr) const
Check if object is a directory.
virtual ~TSystemFile()
Delete TSystemFile object.