Logo ROOT   6.10/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 \ingroup Base
14 
15 A TSystemFile describes an operating system file.
16 The 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 
26 
27 ////////////////////////////////////////////////////////////////////////////////
28 /// TSystemFile default constructor
29 
31 {
32 }
33 
34 ////////////////////////////////////////////////////////////////////////////////
35 /// TSystemFile normal constructor
36 
37 TSystemFile::TSystemFile(const char *filename, const char *dirname)
38  : TNamed(filename, dirname)
39 {
41 }
42 
43 ////////////////////////////////////////////////////////////////////////////////
44 /// Delete TSystemFile object.
45 
47 {
48 }
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 /// Check if object is a directory.
52 
53 Bool_t TSystemFile::IsDirectory(const char *dir) const
54 {
55  Long64_t size;
56  Long_t id, flags, modtime;
57 
58  flags = id = size = modtime = 0;
59  gSystem->GetPathInfo(!dir ? fName.Data() : dir, &id, &size, &flags, &modtime);
60  Int_t isdir = (Int_t)flags & 2;
61 
62  return isdir ? kTRUE : kFALSE;
63 }
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 /// Execute default action for this system file (action is specified
67 /// in the $HOME/.root.mimes or $ROOTSYS/etc/root.mimes file.
68 
70 {
71  if (b)
72  b->ExecuteDefaultAction(this);
73 }
74 
75 ////////////////////////////////////////////////////////////////////////////////
76 /// Invoke text editor on this file
77 
79 {
80 #ifndef _WIN32
81  const char *ed = gEnv->GetValue("Editor", "vi");
82  Int_t nch = strlen(ed)+strlen(GetName()) + 50;
83  Char_t *cmd = new Char_t[nch];
84  if (!strcmp(ed, "vi"))
85  snprintf(cmd,nch, "xterm -e vi %s &", GetName());
86  else
87  snprintf(cmd,nch, "%s %s &", ed, GetName());
88 #else
89  const char *ed = gEnv->GetValue("Editor", "notepad");
90  Int_t nch = strlen(ed)+strlen(GetName()) + 50;
91  Char_t *cmd = new Char_t[nch];
92  snprintf(cmd,nch, "start %s %s", ed, GetName());
93 #endif
94  gSystem->Exec(cmd);
95 
96  delete [] cmd;
97 }
98 
99 ////////////////////////////////////////////////////////////////////////////////
100 /// copy this file
101 
102 void TSystemFile::Copy(const char *to)
103 {
104  TString name = to;
105 
106  if (IsDirectory(to)) {
107  if (name.EndsWith("/")) name.Chop();
108  char *s = gSystem->ConcatFileName(name, fName);
109  name = s;
110  delete [] s;
111  }
112 
113  Int_t status = gSystem->CopyFile(fName, name, kFALSE);
114 
115  if (status == -2) {
116  Warning("Copy", "File %s already exists", name.Data());
117  } else if (status == -1) {
118  Warning("Copy", "Failed to move file %s", name.Data());
119  }
120 }
121 
122 ////////////////////////////////////////////////////////////////////////////////
123 /// move this file
124 
125 void TSystemFile::Move(const char *to)
126 {
127  if (!to) {
128  Warning("Move", "No file/dir name specified");
129  return;
130  }
131 
132  TString name = to;
133 
134  if (IsDirectory(to)) {
135  if (name.EndsWith("/")) name.Chop();
136  char *s = gSystem->ConcatFileName(name, fName);
137  name = s;
138  delete [] s;
139  }
140  Int_t status = gSystem->CopyFile(fName, name, kFALSE);
141 
142  if (!status) {
143  gSystem->Unlink(fName);
144  } else if (status == -2) {
145  Warning("Move", "File %s already exists", name.Data());
146  } else if (status == -1) {
147  Warning("Move", "Failed to move file %s", name.Data());
148  }
149 }
150 
151 ////////////////////////////////////////////////////////////////////////////////
152 /// delete this file
153 
155 {
156  gSystem->Unlink(fName);
157 }
158 
159 ////////////////////////////////////////////////////////////////////////////////
160 /// rename this file
161 
162 void TSystemFile::Rename(const char *name)
163 {
164  gSystem->Rename(fName, name);
165 }
166 
167 ////////////////////////////////////////////////////////////////////////////////
168 /// inspect this file
169 
171 {
172 }
173 
174 ////////////////////////////////////////////////////////////////////////////////
175 /// dump this file
176 
177 void TSystemFile::Dump() const
178 {
179 }
180 
TSystemFile()
TSystemFile default constructor.
Definition: TSystemFile.cxx:30
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
long long Long64_t
Definition: RtypesCore.h:69
virtual ~TSystemFile()
Delete TSystemFile object.
Definition: TSystemFile.cxx:46
virtual void Move(const char *to)
move this file
virtual void Dump() const
dump 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:1370
Basic string class.
Definition: TString.h:129
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:357
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual Bool_t IsDirectory(const char *dir=0) const
Check if object is a directory.
Definition: TSystemFile.cxx:53
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:687
if object in a list can be deleted
Definition: TObject.h:58
virtual int Rename(const char *from, const char *to)
Rename a file.
Definition: TSystem.cxx:1326
virtual void Copy(const char *to)
copy this file
virtual int Unlink(const char *name)
Unlink, i.e. remove, a file.
Definition: TSystem.cxx:1353
virtual void Rename(const char *name)
rename this file
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2231
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
R__EXTERN TSystem * gSystem
Definition: TSystem.h:539
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:482
virtual void Delete()
delete this file
virtual Int_t Exec(const char *shellcmd)
Execute a command.
Definition: TSystem.cxx:660
TString fName
Definition: TNamed.h:32
const Bool_t kFALSE
Definition: RtypesCore.h:92
long Long_t
Definition: RtypesCore.h:50
#define ClassImp(name)
Definition: Rtypes.h:336
R__EXTERN TEnv * gEnv
Definition: TEnv.h:170
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:69
A TSystemFile describes an operating system file.
Definition: TSystemFile.h:29
virtual void Edit()
Invoke text editor on this file.
Definition: TSystemFile.cxx:78
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
#define snprintf
Definition: civetweb.c:822
virtual int CopyFile(const char *from, const char *to, Bool_t overwrite=kFALSE)
Copy a file.
Definition: TSystem.cxx:1317
virtual void Inspect() const
inspect this file
const Bool_t kTRUE
Definition: RtypesCore.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:1051
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:859
TString & Chop()
Definition: TString.h:627
const char * Data() const
Definition: TString.h:347