TSystemFile.cxx

Go to the documentation of this file.
00001 // @(#)root/base:$Id: TSystemFile.cxx 35922 2010-09-30 14:43:08Z brun $
00002 // Author: Rene Brun   26/06/96
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 // TSystemFile                                                          //
00015 //                                                                      //
00016 // A TSystemFile describes an operating system file.                    //
00017 // The information is used by the browser (see TBrowser).               //
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    // TSystemFile default constructor
00033 
00034 }
00035 
00036 //______________________________________________________________________________
00037 TSystemFile::TSystemFile(const char *filename, const char *dirname)
00038    : TNamed(filename, dirname)
00039 {
00040    // TSystemFile normal constructor
00041 
00042    SetBit(kCanDelete);
00043 }
00044 
00045 //______________________________________________________________________________
00046 TSystemFile::~TSystemFile()
00047 {
00048    // Delete TSystemFile object.
00049 }
00050 
00051 //______________________________________________________________________________
00052 Bool_t TSystemFile::IsDirectory(const char *dir) const
00053 {
00054    // Check if object is a directory.
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    // Execute default action for this system file (action is specified
00070    // in the $HOME/.root.mimes or $ROOTSYS/etc/root.mimes file.
00071 
00072    if (b)
00073       b->ExecuteDefaultAction(this);
00074 }
00075 
00076 //______________________________________________________________________________
00077 void TSystemFile::Edit()
00078 {
00079    // Invoke text editor on this file
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    // copy this file
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    // move this file
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    // delete this file
00156 
00157    gSystem->Unlink(fName);
00158 }
00159 
00160 //______________________________________________________________________________
00161 void TSystemFile::Rename(const char *name)
00162 {
00163    // rename this file
00164 
00165    gSystem->Rename(fName, name);
00166 }
00167 
00168 //______________________________________________________________________________
00169 void TSystemFile::Inspect() const
00170 {
00171    // inspect this file
00172 }
00173 
00174 //______________________________________________________________________________
00175 void TSystemFile::Dump() const
00176 {
00177    // dump this file
00178 }
00179 

Generated on Tue Jul 5 14:11:24 2011 for ROOT_528-00b_version by  doxygen 1.5.1