Logo ROOT  
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
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
26
27////////////////////////////////////////////////////////////////////////////////
28/// TSystemFile default constructor
29
31{
32}
33
34////////////////////////////////////////////////////////////////////////////////
35/// TSystemFile normal constructor
36
37TSystemFile::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
53Bool_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
102void 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
125void 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) {
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{
157}
158
159////////////////////////////////////////////////////////////////////////////////
160/// rename this file
161
162void TSystemFile::Rename(const char *name)
163{
165}
166
167////////////////////////////////////////////////////////////////////////////////
168/// inspect this file
169
171{
172}
173
174////////////////////////////////////////////////////////////////////////////////
175/// dump this file
176
178{
179}
180
#define b(i)
Definition: RSha256.hxx:100
int Int_t
Definition: RtypesCore.h:41
char Char_t
Definition: RtypesCore.h:29
const Bool_t kFALSE
Definition: RtypesCore.h:88
long Long_t
Definition: RtypesCore.h:50
bool Bool_t
Definition: RtypesCore.h:59
long long Long64_t
Definition: RtypesCore.h:69
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:365
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
XFontStruct * id
Definition: TGX11.cxx:108
char name[80]
Definition: TGX11.cxx:109
R__EXTERN TSystem * gSystem
Definition: TSystem.h:560
#define snprintf
Definition: civetweb.c:1540
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
TString fName
Definition: TNamed.h:32
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:866
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:694
@ kCanDelete
if object in a list can be deleted
Definition: TObject.h:58
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364
A TSystemFile describes an operating system file.
Definition: TSystemFile.h:29
TSystemFile()
TSystemFile default constructor.
Definition: TSystemFile.cxx:30
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.
Definition: TSystemFile.cxx:78
virtual void Browse(TBrowser *b)
Execute default action for this system file (action is specified in the $HOME/.root....
Definition: TSystemFile.cxx:69
virtual void Copy(const char *to)
copy this file
virtual void Inspect() const
inspect this file
virtual void Dump() const
dump this file
virtual Bool_t IsDirectory(const char *dir=0) const
Check if object is a directory.
Definition: TSystemFile.cxx:53
virtual ~TSystemFile()
Delete TSystemFile object.
Definition: TSystemFile.cxx:46
virtual int CopyFile(const char *from, const char *to, Bool_t overwrite=kFALSE)
Copy a file.
Definition: TSystem.cxx:1332
virtual char * ConcatFileName(const char *dir, const char *name)
Concatenate a directory and a file name. User must delete returned string.
Definition: TSystem.cxx:1062
virtual Int_t Exec(const char *shellcmd)
Execute a command.
Definition: TSystem.cxx:663
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:1389
virtual int Rename(const char *from, const char *to)
Rename a file.
Definition: TSystem.cxx:1341
virtual int Unlink(const char *name)
Unlink, i.e.
Definition: TSystem.cxx:1372
static constexpr double s