ROOT  6.06/09
Reference Guide
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 A TSystemFile describes an operating system file.
14 The information is used by the browser (see TBrowser).
15 */
16 
17 #include "TSystemFile.h"
18 #include "TBrowser.h"
19 #include "TSystem.h"
20 #include "TEnv.h"
21 
22 
24 
25 ////////////////////////////////////////////////////////////////////////////////
26 /// TSystemFile default constructor
27 
29 {
30 }
31 
32 ////////////////////////////////////////////////////////////////////////////////
33 /// TSystemFile normal constructor
34 
35 TSystemFile::TSystemFile(const char *filename, const char *dirname)
36  : TNamed(filename, dirname)
37 {
39 }
40 
41 ////////////////////////////////////////////////////////////////////////////////
42 /// Delete TSystemFile object.
43 
45 {
46 }
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// Check if object is a directory.
50 
51 Bool_t TSystemFile::IsDirectory(const char *dir) const
52 {
53  Long64_t size;
54  Long_t id, flags, modtime;
55 
56  flags = id = size = modtime = 0;
57  gSystem->GetPathInfo(!dir ? fName.Data() : dir, &id, &size, &flags, &modtime);
58  Int_t isdir = (Int_t)flags & 2;
59 
60  return isdir ? kTRUE : kFALSE;
61 }
62 
63 ////////////////////////////////////////////////////////////////////////////////
64 /// Execute default action for this system file (action is specified
65 /// in the $HOME/.root.mimes or $ROOTSYS/etc/root.mimes file.
66 
68 {
69  if (b)
70  b->ExecuteDefaultAction(this);
71 }
72 
73 ////////////////////////////////////////////////////////////////////////////////
74 /// Invoke text editor on this file
75 
77 {
78 #ifndef _WIN32
79  const char *ed = gEnv->GetValue("Editor", "vi");
80  Int_t nch = strlen(ed)+strlen(GetName()) + 50;
81  Char_t *cmd = new Char_t[nch];
82  if (!strcmp(ed, "vi"))
83  snprintf(cmd,nch, "xterm -e vi %s &", GetName());
84  else
85  snprintf(cmd,nch, "%s %s &", ed, GetName());
86 #else
87  const char *ed = gEnv->GetValue("Editor", "notepad");
88  Int_t nch = strlen(ed)+strlen(GetName()) + 50;
89  Char_t *cmd = new Char_t[nch];
90  snprintf(cmd,nch, "start %s %s", ed, GetName());
91 #endif
92  gSystem->Exec(cmd);
93 
94  delete [] cmd;
95 }
96 
97 ////////////////////////////////////////////////////////////////////////////////
98 /// copy this file
99 
100 void TSystemFile::Copy(const char *to)
101 {
102  TString name = to;
103 
104  if (IsDirectory(to)) {
105  if (name.EndsWith("/")) name.Chop();
106  char *s = gSystem->ConcatFileName(name, fName);
107  name = s;
108  delete [] s;
109  }
110 
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 
123 void 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  char *s = gSystem->ConcatFileName(name, fName);
135  name = s;
136  delete [] s;
137  }
139 
140  if (!status) {
141  gSystem->Unlink(fName);
142  } else if (status == -2) {
143  Warning("Move", "File %s already exists", name.Data());
144  } else if (status == -1) {
145  Warning("Move", "Failed to move file %s", name.Data());
146  }
147 }
148 
149 ////////////////////////////////////////////////////////////////////////////////
150 /// delete this file
151 
153 {
154  gSystem->Unlink(fName);
155 }
156 
157 ////////////////////////////////////////////////////////////////////////////////
158 /// rename this file
159 
160 void TSystemFile::Rename(const char *name)
161 {
162  gSystem->Rename(fName, name);
163 }
164 
165 ////////////////////////////////////////////////////////////////////////////////
166 /// inspect this file
167 
169 {
170 }
171 
172 ////////////////////////////////////////////////////////////////////////////////
173 /// dump this file
174 
175 void TSystemFile::Dump() const
176 {
177 }
178 
virtual void Inspect() const
inspect this file
long long Long64_t
Definition: RtypesCore.h:69
virtual ~TSystemFile()
Delete TSystemFile object.
Definition: TSystemFile.cxx:44
virtual void Move(const char *to)
move this file
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.
Definition: TSystem.cxx:1363
static const char * filename()
Basic string class.
Definition: TString.h:137
void ExecuteDefaultAction(TObject *obj)
Execute default action for selected object (action is specified in the $HOME/.root.mimes or $ROOTSYS/etc/root.mimes file).
Definition: TBrowser.cxx:355
TAlienJobStatus * status
Definition: TAlienJob.cxx:51
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:732
virtual int Rename(const char *from, const char *to)
Rename a file.
Definition: TSystem.cxx:1319
virtual void Copy(const char *to)
copy this file
const char * Data() const
Definition: TString.h:349
virtual int Unlink(const char *name)
Unlink, i.e. remove, a file.
Definition: TSystem.cxx:1346
virtual void Rename(const char *name)
rename this file
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
XFontStruct * id
Definition: TGX11.cxx:108
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:41
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2220
ClassImp(TSystemFile) TSystemFile
TSystemFile default constructor.
Definition: TSystemFile.cxx:23
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:494
virtual void Delete()
delete this file
virtual void Dump() const
dump this file
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
virtual Int_t Exec(const char *shellcmd)
Execute a command.
Definition: TSystem.cxx:657
TString fName
Definition: TNamed.h:36
long Long_t
Definition: RtypesCore.h:50
virtual Bool_t IsDirectory(const char *dir=0) const
Check if object is a directory.
Definition: TSystemFile.cxx:51
R__EXTERN TEnv * gEnv
Definition: TEnv.h:174
#define name(a, b)
Definition: linkTestLib0.cpp:5
char Char_t
Definition: RtypesCore.h:29
virtual void Browse(TBrowser *b)
Execute default action for this system file (action is specified in the $HOME/.root.mimes or $ROOTSYS/etc/root.mimes file.
Definition: TSystemFile.cxx:67
A TSystemFile describes an operating system file.
Definition: TSystemFile.h:31
virtual void Edit()
Invoke text editor on this file.
Definition: TSystemFile.cxx:76
virtual int CopyFile(const char *from, const char *to, Bool_t overwrite=kFALSE)
Copy a file.
Definition: TSystem.cxx:1310
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual char * ConcatFileName(const char *dir, const char *name)
Concatenate a directory and a file name. User must delete returned string.
Definition: TSystem.cxx:1044
TString & Chop()
Definition: TString.h:622
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:904