00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "TSystemFile.h"
00022 #include "TBrowser.h"
00023 #include "TSystem.h"
00024 #include "TEnv.h"
00025
00026
00027 ClassImp(TSystemFile)
00028
00029
00030 TSystemFile::TSystemFile() : TNamed()
00031 {
00032
00033
00034 }
00035
00036
00037 TSystemFile::TSystemFile(const char *filename, const char *dirname)
00038 : TNamed(filename, dirname)
00039 {
00040
00041
00042 SetBit(kCanDelete);
00043 }
00044
00045
00046 TSystemFile::~TSystemFile()
00047 {
00048
00049 }
00050
00051
00052 Bool_t TSystemFile::IsDirectory(const char *dir) const
00053 {
00054
00055
00056 Long64_t size;
00057 Long_t id, flags, modtime;
00058
00059 flags = id = size = modtime = 0;
00060 gSystem->GetPathInfo(!dir ? fName.Data() : dir, &id, &size, &flags, &modtime);
00061 Int_t isdir = (Int_t)flags & 2;
00062
00063 return isdir ? kTRUE : kFALSE;
00064 }
00065
00066
00067 void TSystemFile::Browse(TBrowser *b)
00068 {
00069
00070
00071
00072 if (b)
00073 b->ExecuteDefaultAction(this);
00074 }
00075
00076
00077 void TSystemFile::Edit()
00078 {
00079
00080
00081 #ifndef _WIN32
00082 const char *ed = gEnv->GetValue("Editor", "vi");
00083 Int_t nch = strlen(ed)+strlen(GetName()) + 50;
00084 Char_t *cmd = new Char_t[nch];
00085 if (!strcmp(ed, "vi"))
00086 snprintf(cmd,nch, "xterm -e vi %s &", GetName());
00087 else
00088 snprintf(cmd,nch, "%s %s &", ed, GetName());
00089 #else
00090 const char *ed = gEnv->GetValue("Editor", "notepad");
00091 Int_t nch = strlen(ed)+strlen(GetName()) + 50;
00092 Char_t *cmd = new Char_t[nch];
00093 snprintf(cmd,nch, "start %s %s", ed, GetName());
00094 #endif
00095 gSystem->Exec(cmd);
00096
00097 delete [] cmd;
00098 }
00099
00100
00101 void TSystemFile::Copy(const char *to)
00102 {
00103
00104
00105 TString name = to;
00106
00107 if (IsDirectory(to)) {
00108 if (name.EndsWith("/")) name.Chop();
00109 char *s = gSystem->ConcatFileName(name, fName);
00110 name = s;
00111 delete [] s;
00112 }
00113
00114 Int_t status = gSystem->CopyFile(fName, name, kFALSE);
00115
00116 if (status == -2) {
00117 Warning("Copy", "File %s already exists", name.Data());
00118 } else if (status == -1) {
00119 Warning("Copy", "Failed to move file %s", name.Data());
00120 }
00121 }
00122
00123
00124 void TSystemFile::Move(const char *to)
00125 {
00126
00127
00128 if (!to) {
00129 Warning("Move", "No file/dir name specified");
00130 return;
00131 }
00132
00133 TString name = to;
00134
00135 if (IsDirectory(to)) {
00136 if (name.EndsWith("/")) name.Chop();
00137 char *s = gSystem->ConcatFileName(name, fName);
00138 name = s;
00139 delete [] s;
00140 }
00141 Int_t status = gSystem->CopyFile(fName, name, kFALSE);
00142
00143 if (!status) {
00144 gSystem->Unlink(fName);
00145 } else if (status == -2) {
00146 Warning("Move", "File %s already exists", name.Data());
00147 } else if (status == -1) {
00148 Warning("Move", "Failed to move file %s", name.Data());
00149 }
00150 }
00151
00152
00153 void TSystemFile::Delete()
00154 {
00155
00156
00157 gSystem->Unlink(fName);
00158 }
00159
00160
00161 void TSystemFile::Rename(const char *name)
00162 {
00163
00164
00165 gSystem->Rename(fName, name);
00166 }
00167
00168
00169 void TSystemFile::Inspect() const
00170 {
00171
00172 }
00173
00174
00175 void TSystemFile::Dump() const
00176 {
00177
00178 }
00179