home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Samples / GTakPM / Source / Backup.cpp next >
C/C++ Source or Header  |  1996-08-12  |  3KB  |  111 lines

  1. // GTakPM
  2. // (c) Benjamin Stein 1994
  3. // All Rights Reserved
  4. // Backup.cpp
  5.  
  6. // $Header: W:/Projects/OCL/Samples/GTakPM/Source/rcs/Backup.cpp 1.50 1996/08/11 23:48:05 B.STEIN Release $
  7.  
  8. #include "..\Source\GTakPM.hpp"
  9.  
  10.  
  11. void GTPMWin::backup()
  12. {
  13. #ifdef __TK21__
  14.  PSZ   tempEnv;
  15. #else
  16.  PCSZ  tempEnv;
  17. #endif 
  18.  PSZ      pstr;
  19.  ULONG    item, items;
  20.  OString  path;
  21.  OString  includes;
  22.  OString  excludes;
  23.  OString  batch;
  24.  OString  dirfile;
  25.  OString  str;
  26.  ofstream incfile;
  27.  ofstream excfile;
  28.  ofstream batchfile;
  29.  
  30.  if ((DosScanEnv("TEMP", &tempEnv)) &&
  31.      (DosScanEnv("TMP", &tempEnv)))
  32.   {
  33.    path << GTPMApp::GTakPM->callName;
  34.    path.rightCut('\\');
  35.   }
  36.  else
  37.    path << (PSZ)tempEnv;
  38.  
  39.  if (path.getText()[strlen(path) - 1] != '\\')
  40.    path + "\\";
  41.  
  42.  includes << path;
  43.  includes + "gtmp.inc";
  44.  excludes << path;
  45.  excludes + "gtmp.exc";
  46.  batch << path;
  47.  batch + "gtmp.cmd";
  48.  dirfile << path;
  49.  dirfile + "gtmp.dir";
  50.  
  51.  path << "Cannot open: ";
  52.  
  53.  incfile.open(includes);
  54.  if (!incfile) {
  55.    path + includes;
  56.    throw OPMException(path, 0); }
  57.  
  58.  excfile.open(excludes);
  59.  if (!excfile) {
  60.    path + excludes;
  61.    throw OPMException(path, 0); }
  62.  
  63.  batchfile.open(batch);
  64.  if (!batchfile) {
  65.    path + batch;
  66.    throw OPMException(path, 0); }
  67.  
  68. // write includes-file 
  69.  items = Includes->queryItemCount();
  70.  for(item = 0; item < items; item++)
  71.    if (Includes->queryItemText(str, item)) {
  72.      pstr = str.getText();
  73.      while((pstr = strchr(pstr, '\\'))!=NULL)
  74.        pstr[0] = '/';
  75.      incfile << ((PSZ)(strchr(str, ' ')+1)) << endl; }
  76.  incfile.close();
  77.  
  78. // write excludes-file 
  79.  items = Excludes->queryItemCount();
  80.  for(item = 0; item < items; item++)
  81.    if (Excludes->queryItemText(str, item)) {
  82.      pstr = str.getText();
  83.      while((pstr = strchr(pstr, '\\'))!=NULL)
  84.        pstr[0] = '/';
  85.      excfile << ((PSZ)(strchr(str, ' ')+1)) << endl; }
  86.  excfile.close();
  87.  
  88. // write batchfile
  89.  batchfile << "@ECHO OFF\n"
  90.            << "echo Initializing Tape\n"
  91.            << "tape stat >NUL 2>NUL\n"
  92.            << "tape blocksize 0 stat sel 0 eraseq tell\n"
  93.            << "echo Backup in progress\ntar -cEppP @"
  94.            << (PSZ) includes
  95.            << " --totals --exclude-from "
  96.            << (PSZ) excludes
  97.            << " -D "
  98.            << (PSZ) dirfile
  99.            << "\ntape stat\n"
  100.            << "echo Compare in progress\n"
  101.            << "tape rew >NUL 2>NUL\n"
  102.            << "tar -dEppP\n"
  103.            << "tape stat\n"
  104.            << "echo Operation completed.\n";
  105.  batchfile.close();
  106.  tape->batch(batch);
  107. }
  108.  
  109.  
  110. // end of source
  111.