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 TString path;
58 if (dir) {
59 path = dir;
60 } else if (!fTitle.IsNull() && !gSystem->IsAbsoluteFileName(fName.Data())) {
61 path = fName;
63 } else {
64 path = fName;
65 }
66
67 flags = id = size = modtime = 0;
68 gSystem->GetPathInfo(path.Data(), &id, &size, &flags, &modtime);
69 Int_t isdir = (Int_t)flags & 2;
70
71 return isdir ? kTRUE : kFALSE;
72}
73
74////////////////////////////////////////////////////////////////////////////////
75/// Execute default action for this system file (action is specified
76/// in the $HOME/.root.mimes or $ROOTSYS/etc/root.mimes file.
77
79{
80 if (b)
81 b->ExecuteDefaultAction(this);
82}
83
84////////////////////////////////////////////////////////////////////////////////
85/// Invoke text editor on this file
86
88{
89#ifndef _WIN32
90 const char *ed = gEnv->GetValue("Editor", "vi");
91 Int_t nch = strlen(ed)+strlen(GetName()) + 50;
92 Char_t *cmd = new Char_t[nch];
93 if (!strcmp(ed, "vi"))
94 snprintf(cmd,nch, "xterm -e vi %s &", GetName());
95 else
96 snprintf(cmd,nch, "%s %s &", ed, GetName());
97#else
98 const char *ed = gEnv->GetValue("Editor", "notepad");
99 Int_t nch = strlen(ed)+strlen(GetName()) + 50;
100 Char_t *cmd = new Char_t[nch];
101 snprintf(cmd,nch, "start %s %s", ed, GetName());
102#endif
103 gSystem->Exec(cmd);
104
105 delete [] cmd;
106}
107
108////////////////////////////////////////////////////////////////////////////////
109/// copy this file
110
111void TSystemFile::Copy(const char *to)
112{
113 TString name = to;
114
115 if (IsDirectory(to)) {
116 if (name.EndsWith("/")) name.Chop();
117 TString temp = fName;
119 }
120
121 Int_t status = gSystem->CopyFile(fName, name, kFALSE);
122
123 if (status == -2) {
124 Warning("Copy", "File %s already exists", name.Data());
125 } else if (status == -1) {
126 Warning("Copy", "Failed to move file %s", name.Data());
127 }
128}
129
130////////////////////////////////////////////////////////////////////////////////
131/// move this file
132
133void TSystemFile::Move(const char *to)
134{
135 if (!to) {
136 Warning("Move", "No file/dir name specified");
137 return;
138 }
139
140 TString name = to;
141
142 if (IsDirectory(to)) {
143 if (name.EndsWith("/")) name.Chop();
144 TString temp = fName;
146 }
147 Int_t status = gSystem->CopyFile(fName, name, kFALSE);
148
149 if (!status) {
151 } else if (status == -2) {
152 Warning("Move", "File %s already exists", name.Data());
153 } else if (status == -1) {
154 Warning("Move", "Failed to move file %s", name.Data());
155 }
156}
157
158////////////////////////////////////////////////////////////////////////////////
159/// delete this file
160
162{
164}
165
166////////////////////////////////////////////////////////////////////////////////
167/// rename this file
168
169void TSystemFile::Rename(const char *name)
170{
172}
173
174////////////////////////////////////////////////////////////////////////////////
175/// inspect this file
176
178{
179}
180
181////////////////////////////////////////////////////////////////////////////////
182/// dump this file
183
185{
186}
187
#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:60
char Char_t
Character 1 byte (char)
Definition RtypesCore.h:52
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:69
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:84
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
R__EXTERN TEnv * gEnv
Definition TEnv.h:126
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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
char name[80]
Definition TGX11.cxx:142
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
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:511
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
TString fTitle
Definition TNamed.h:33
TString fName
Definition TNamed.h:32
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1082
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:886
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:71
Basic string class.
Definition TString.h:137
const char * Data() const
Definition TString.h:385
Bool_t IsNull() const
Definition TString.h:423
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.
virtual int CopyFile(const char *from, const char *to, Bool_t overwrite=kFALSE)
Copy a file.
Definition TSystem.cxx:1364
virtual Int_t Exec(const char *shellcmd)
Execute a command.
Definition TSystem.cxx:657
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:1421
virtual const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
Definition TSystem.cxx:1098
virtual int Rename(const char *from, const char *to)
Rename a file.
Definition TSystem.cxx:1373
virtual Bool_t IsAbsoluteFileName(const char *dir)
Return true if dir is an absolute pathname.
Definition TSystem.cxx:967
virtual int Unlink(const char *name)
Unlink, i.e.
Definition TSystem.cxx:1404