ROOT logo
// @(#)root/base:$Id: TSystemFile.cxx 20877 2007-11-19 11:17:07Z rdm $
// Author: Rene Brun   26/06/96

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TSystemFile                                                          //
//                                                                      //
// A TSystemFile describes an operating system file.                    //
// The information is used by the browser (see TBrowser).               //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TSystemFile.h"
#include "TBrowser.h"
#include "TSystem.h"
#include "TEnv.h"


ClassImp(TSystemFile)

//______________________________________________________________________________
TSystemFile::TSystemFile() : TNamed()
{
   // TSystemFile default constructor

}

//______________________________________________________________________________
TSystemFile::TSystemFile(const char *filename, const char *dirname)
   : TNamed(filename, dirname)
{
   // TSystemFile normal constructor

   SetBit(kCanDelete);
}

//______________________________________________________________________________
TSystemFile::~TSystemFile()
{
   // Delete TSystemFile object.
}

//______________________________________________________________________________
Bool_t TSystemFile::IsDirectory(const char *dir) const
{
   // Check if object is a directory.

   Long64_t size;
   Long_t id, flags, modtime;

   flags = id = size = modtime = 0;
   gSystem->GetPathInfo(!dir ? fName.Data() : dir, &id, &size, &flags, &modtime);
   Int_t isdir = (Int_t)flags & 2;

   return isdir ? kTRUE : kFALSE;
}

//______________________________________________________________________________
void TSystemFile::Browse(TBrowser *b)
{
   // Execute default action for this system file (action is specified
   // in the $HOME/.root.mimes or $ROOTSYS/etc/root.mimes file.

   if (b)
      b->ExecuteDefaultAction(this);
}

//______________________________________________________________________________
void TSystemFile::Edit()
{
   // Invoke text editor on this file

#ifndef _WIN32
   const char *ed = gEnv->GetValue("Editor", "vi");
   Char_t *cmd = new Char_t[strlen(ed)+strlen(GetName()) + 50];
   if (!strcmp(ed, "vi"))
      sprintf(cmd, "xterm -e vi %s &", GetName());
   else
      sprintf(cmd, "%s %s &", ed, GetName());
#else
   const char *ed = gEnv->GetValue("Editor", "notepad");
   Char_t *cmd = new Char_t[strlen(ed)+strlen(GetName()) + 50];
   sprintf(cmd, "start %s %s", ed, GetName());
#endif
   gSystem->Exec(cmd);

   delete [] cmd;
}

//______________________________________________________________________________
void TSystemFile::Copy(const char *to)
{
   // copy this file

   TString name = to;

   if (IsDirectory(to)) {
      if (name.EndsWith("/")) name.Chop();
      name = gSystem->ConcatFileName(name, fName);
   }

   Int_t status = gSystem->CopyFile(fName, name, kFALSE);

   if (status == -2) {
      Warning("Copy", "File %s already exists", name.Data());
   } else if (status == -1) {
      Warning("Copy", "Failed to move file %s", name.Data());
   }
}

//______________________________________________________________________________
void TSystemFile::Move(const char *to)
{
   // move this file

   if (!to) {
      Warning("Move", "No file/dir name specified");
      return;
   }

   TString name = to;

   if (IsDirectory(to)) {
      if (name.EndsWith("/")) name.Chop();
      name = gSystem->ConcatFileName(name, fName);
   }
   Int_t status = gSystem->CopyFile(fName, name, kFALSE);

   if (!status) {
      gSystem->Unlink(fName);
   } else if (status == -2) {
      Warning("Move", "File %s already exists", name.Data());
   } else if (status == -1) {
      Warning("Move", "Failed to move file %s", name.Data());
   }
}

//______________________________________________________________________________
void TSystemFile::Delete()
{
   // delete this file

   gSystem->Unlink(fName);
}

//______________________________________________________________________________
void TSystemFile::Rename(const char *name)
{
   // rename this file

   gSystem->Rename(fName, name);
}

//______________________________________________________________________________
void TSystemFile::Inspect() const
{
   // inspect this file
}

//______________________________________________________________________________
void TSystemFile::Dump() const
{
   // dump this file
}



 TSystemFile.cxx:1
 TSystemFile.cxx:2
 TSystemFile.cxx:3
 TSystemFile.cxx:4
 TSystemFile.cxx:5
 TSystemFile.cxx:6
 TSystemFile.cxx:7
 TSystemFile.cxx:8
 TSystemFile.cxx:9
 TSystemFile.cxx:10
 TSystemFile.cxx:11
 TSystemFile.cxx:12
 TSystemFile.cxx:13
 TSystemFile.cxx:14
 TSystemFile.cxx:15
 TSystemFile.cxx:16
 TSystemFile.cxx:17
 TSystemFile.cxx:18
 TSystemFile.cxx:19
 TSystemFile.cxx:20
 TSystemFile.cxx:21
 TSystemFile.cxx:22
 TSystemFile.cxx:23
 TSystemFile.cxx:24
 TSystemFile.cxx:25
 TSystemFile.cxx:26
 TSystemFile.cxx:27
 TSystemFile.cxx:28
 TSystemFile.cxx:29
 TSystemFile.cxx:30
 TSystemFile.cxx:31
 TSystemFile.cxx:32
 TSystemFile.cxx:33
 TSystemFile.cxx:34
 TSystemFile.cxx:35
 TSystemFile.cxx:36
 TSystemFile.cxx:37
 TSystemFile.cxx:38
 TSystemFile.cxx:39
 TSystemFile.cxx:40
 TSystemFile.cxx:41
 TSystemFile.cxx:42
 TSystemFile.cxx:43
 TSystemFile.cxx:44
 TSystemFile.cxx:45
 TSystemFile.cxx:46
 TSystemFile.cxx:47
 TSystemFile.cxx:48
 TSystemFile.cxx:49
 TSystemFile.cxx:50
 TSystemFile.cxx:51
 TSystemFile.cxx:52
 TSystemFile.cxx:53
 TSystemFile.cxx:54
 TSystemFile.cxx:55
 TSystemFile.cxx:56
 TSystemFile.cxx:57
 TSystemFile.cxx:58
 TSystemFile.cxx:59
 TSystemFile.cxx:60
 TSystemFile.cxx:61
 TSystemFile.cxx:62
 TSystemFile.cxx:63
 TSystemFile.cxx:64
 TSystemFile.cxx:65
 TSystemFile.cxx:66
 TSystemFile.cxx:67
 TSystemFile.cxx:68
 TSystemFile.cxx:69
 TSystemFile.cxx:70
 TSystemFile.cxx:71
 TSystemFile.cxx:72
 TSystemFile.cxx:73
 TSystemFile.cxx:74
 TSystemFile.cxx:75
 TSystemFile.cxx:76
 TSystemFile.cxx:77
 TSystemFile.cxx:78
 TSystemFile.cxx:79
 TSystemFile.cxx:80
 TSystemFile.cxx:81
 TSystemFile.cxx:82
 TSystemFile.cxx:83
 TSystemFile.cxx:84
 TSystemFile.cxx:85
 TSystemFile.cxx:86
 TSystemFile.cxx:87
 TSystemFile.cxx:88
 TSystemFile.cxx:89
 TSystemFile.cxx:90
 TSystemFile.cxx:91
 TSystemFile.cxx:92
 TSystemFile.cxx:93
 TSystemFile.cxx:94
 TSystemFile.cxx:95
 TSystemFile.cxx:96
 TSystemFile.cxx:97
 TSystemFile.cxx:98
 TSystemFile.cxx:99
 TSystemFile.cxx:100
 TSystemFile.cxx:101
 TSystemFile.cxx:102
 TSystemFile.cxx:103
 TSystemFile.cxx:104
 TSystemFile.cxx:105
 TSystemFile.cxx:106
 TSystemFile.cxx:107
 TSystemFile.cxx:108
 TSystemFile.cxx:109
 TSystemFile.cxx:110
 TSystemFile.cxx:111
 TSystemFile.cxx:112
 TSystemFile.cxx:113
 TSystemFile.cxx:114
 TSystemFile.cxx:115
 TSystemFile.cxx:116
 TSystemFile.cxx:117
 TSystemFile.cxx:118
 TSystemFile.cxx:119
 TSystemFile.cxx:120
 TSystemFile.cxx:121
 TSystemFile.cxx:122
 TSystemFile.cxx:123
 TSystemFile.cxx:124
 TSystemFile.cxx:125
 TSystemFile.cxx:126
 TSystemFile.cxx:127
 TSystemFile.cxx:128
 TSystemFile.cxx:129
 TSystemFile.cxx:130
 TSystemFile.cxx:131
 TSystemFile.cxx:132
 TSystemFile.cxx:133
 TSystemFile.cxx:134
 TSystemFile.cxx:135
 TSystemFile.cxx:136
 TSystemFile.cxx:137
 TSystemFile.cxx:138
 TSystemFile.cxx:139
 TSystemFile.cxx:140
 TSystemFile.cxx:141
 TSystemFile.cxx:142
 TSystemFile.cxx:143
 TSystemFile.cxx:144
 TSystemFile.cxx:145
 TSystemFile.cxx:146
 TSystemFile.cxx:147
 TSystemFile.cxx:148
 TSystemFile.cxx:149
 TSystemFile.cxx:150
 TSystemFile.cxx:151
 TSystemFile.cxx:152
 TSystemFile.cxx:153
 TSystemFile.cxx:154
 TSystemFile.cxx:155
 TSystemFile.cxx:156
 TSystemFile.cxx:157
 TSystemFile.cxx:158
 TSystemFile.cxx:159
 TSystemFile.cxx:160
 TSystemFile.cxx:161
 TSystemFile.cxx:162
 TSystemFile.cxx:163
 TSystemFile.cxx:164
 TSystemFile.cxx:165
 TSystemFile.cxx:166
 TSystemFile.cxx:167
 TSystemFile.cxx:168
 TSystemFile.cxx:169
 TSystemFile.cxx:170
 TSystemFile.cxx:171
 TSystemFile.cxx:172
 TSystemFile.cxx:173
 TSystemFile.cxx:174
 TSystemFile.cxx:175