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)
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
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;
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;
136 }
137 Int_t status = gSystem->CopyFile(fName, name, kFALSE);
138
139 if (!status) {
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{
154}
155
156////////////////////////////////////////////////////////////////////////////////
157/// rename this file
158
159void TSystemFile::Rename(const char *name)
160{
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
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TEnv * gEnv
Definition TEnv.h:170
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:110
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
#define snprintf
Definition civetweb.c:1579
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:503
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 fName
Definition TNamed.h:32
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1074
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:881
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:68
Basic string class.
Definition TString.h:138
const char * Data() const
Definition TString.h:384
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:1352
virtual Int_t Exec(const char *shellcmd)
Execute a command.
Definition TSystem.cxx:651
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:1409
virtual const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
Definition TSystem.cxx:1092
virtual int Rename(const char *from, const char *to)
Rename a file.
Definition TSystem.cxx:1361
virtual int Unlink(const char *name)
Unlink, i.e.
Definition TSystem.cxx:1392