Changeset 387ce2b in tol


Ignore:
Timestamp:
Mar 17, 2011, 5:59:55 PM (16 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
724c736
Parents:
b9ea255
Message:

Fixes #922

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@3322 be4846ae-f051-483a-831f-b64e7d08527f

Location:
tol
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • tol/PackArchive/PackArchive.cpp

    rb9ea255 r387ce2b  
    140140bool Store::Open(BText path, char openMode) { return(false); };
    141141bool Store::Close() { return(false); };
    142 bool Store::FileAdd(BText originalFilePath) { return(false); };
     142bool Store::FileAdd(BText originalFilePath, BText pathInZip) { return(false); };
    143143bool Store::FileExtract(BText originalFilePath, BText destinationDirPath) { return(false); };
    144144bool Store::FileExist(BText originalFilePath) { return(false); };
    … …  
    185185//--------------------------------------------------------------------
    186186  DeclareContensClass(BDat, BDatTemporary, BDatPackArchiveClose);
    187   DefExtOpr(1, BDatPackArchiveClose, "PackArchive.Close", 1, 1, "Real",
     187  DefExtOpr(1, BDatPackArchiveClose, "PackArchive.Close",
     188  1, 1, "Real",
    188189  "(Real packArchiveId)",
    189190  I2("Closes a packed archive that was open with ",
    … …  
    212213  DeclareContensClass(BDat, BDatTemporary, BDatPackArchiveFileAdd);
    213214  DefExtOpr(1, BDatPackArchiveFileAdd, "PackArchive.FileAdd",
    214   1, 2, "Real Text",
    215   "(Real packArchiveId, Text originalFilePath)",
     215  3, 3, "Real Text Text",
     216  "(Real packArchiveId, Text originalFilePath, Text pathInZip)",
    216217  I2("Adds a file to a packed archive that was open with ",
    217218     "Añade un fichero a un archivo empaquetado que fue abierto con ")+
    … …  
    226227  if(store)
    227228  {
    228     contens_ = store->FileAdd(Text(Arg(2)));
     229    contens_ = store->FileAdd(Text(Arg(2)),Text(Arg(3)));
    229230  }
    230231  else
    … …  
    237238  DeclareContensClass(BDat, BDatTemporary, BDatPackArchiveFileExtract);
    238239  DefExtOpr(1, BDatPackArchiveFileExtract, "PackArchive.FileExtract",
    239   1, 3, "Real Text Text",
     240  3, 3, "Real Text Text",
    240241  "(Real packArchiveId, Text originalFilePath, Text destinationDirPath)",
    241242  I2("Extracts a file from a packed archive that was open with ",
    … …  
    262263  DeclareContensClass(BDat, BDatTemporary, BDatPackArchiveFileExist);
    263264  DefExtOpr(1, BDatPackArchiveFileExist, "PackArchive.FileExist",
    264   1, 2, "Real Text",
     265  2, 2, "Real Text",
    265266  "(Real packArchiveId, Text originalFilePath)",
    266267  I2("Checks if there is a file into a packed archive that was open with ",
    … …  
    287288  DeclareContensClass(BDat, BDatTemporary, BDatPackArchiveDirAdd);
    288289  DefExtOpr(1, BDatPackArchiveDirAdd, "PackArchive.DirAdd",
    289   1, 2, "Real Text",
     290  2, 2, "Real Text",
    290291  "(Real packArchiveId, Text originalDirPath)",
    291292  I2("Adds recursively a directory to a packed archive that was open "
    … …  
    314315  DeclareContensClass(BDat, BDatTemporary, BDatPackArchiveDirExtract);
    315316  DefExtOpr(1, BDatPackArchiveDirExtract, "PackArchive.DirExtract",
    316   1, 3, "Real Text Text",
     317  3, 3, "Real Text Text",
    317318  "(Real packArchiveId, Text originalFilePath, Text destinationDirPath)",
    318319  I2("Extracts recursively a directory from a packed archive that was open with ",
    … …  
    339340  DeclareContensClass(BDat, BDatTemporary, BDatPackArchiveDirExist);
    340341  DefExtOpr(1, BDatPackArchiveDirExist, "PackArchive.DirExist",
    341   1, 2, "Real Text",
     342  2, 2, "Real Text",
    342343  "(Real packArchiveId, Text originalFilePath)",
    343344  I2("Checks if there is a directory into a packed archive that was open with ",
  • tol/PackArchive/StoreZipArchive.cpp

    rb9ea255 r387ce2b  
    2828#include "tol_PackArchive.h"
    2929#include "tol_StoreZipArchive.h"
     30#include "tol_bdir.h"
    3031
    3132//--------------------------------------------------------------------
    3233StoreZipArchive::StoreZipArchive()
    3334//--------------------------------------------------------------------
    34 : Store()
     35: Store(), _exceptions(0)
    3536{
    3637}
    … …  
    4748//--------------------------------------------------------------------
    4849{
     50  if(_exceptions) { return(false); }
    4951  _errMsg[0]='\0';
    5052  _path = path;
    … …  
    5658    {
    5759      remove(_path);
    58       _zip.Open(_path.String(), CZipArchive::zipCreate);
     60      ok = _zip.Open(_path.String(), CZipArchive::zipCreate);
    5961    }
    6062    else if(openMode=='r')
    6163    {
    62       _zip.Open(_path.String(), CZipArchive::zipOpenReadOnly, false);
     64     ok =  _zip.Open(_path.String(), CZipArchive::zipOpenReadOnly, false);
     65    }
     66    if(!ok)
     67    {
     68      sprintf(_errMsg,"[ZipArchive] The archive %s was already opened "
     69      "before or an invalid open mode was specified.",_path.String());
    6370    }
    6471  }
    … …  
    7279      (LPCTSTR)ex.GetErrorDescription());
    7380    _zip.Close(CZipArchive::afAfterException);
     81    _exceptions ++;
    7482  }
    7583  if(!ok) { Error(_errMsg); }
    … …  
    8290//--------------------------------------------------------------------
    8391{
     92  if(_exceptions) { return(false); }
    8493  _errMsg[0]='\0';
    8594  if(_openMode == ' ') { return(true); }
    … …  
    97106      (LPCTSTR)ex.GetErrorDescription());
    98107    _zip.Close(CZipArchive::afAfterException);
     108    _exceptions ++;
    99109  }
    100110  if(!ok) { Error(_errMsg); }
    … …  
    106116//--------------------------------------------------------------------
    107117//Añade un fichero al archivo
    108 bool StoreZipArchive::FileAdd(BText originalFilePath)
    109 //--------------------------------------------------------------------
    110 {
    111   _errMsg[0]='\0';
    112   bool ok = true;
    113   try
    114   {
    115     _zip.AddNewFile(originalFilePath.String());
     118bool StoreZipArchive::FileAdd(BText originalFilePath, BText pathInZip)
     119//--------------------------------------------------------------------
     120{
     121  if(_exceptions) { return(false); }
     122  _errMsg[0]='\0';
     123  bool ok = true;
     124  try
     125  {
     126    if(pathInZip=="")
     127    {
     128      BText stdFilePath = GetStandardAbsolutePath(originalFilePath);
     129      BText stdZipPath = GetStandardAbsolutePath(_path);
     130      pathInZip = Replace(stdFilePath,stdZipPath,"");
     131    }
     132    ok = _zip.AddNewFile(originalFilePath.String(),pathInZip.String());
     133    if(!ok)
     134    {
     135      sprintf(_errMsg, "[ZipArchive] Error while adding to archive %s file %s",
     136        _path.String(), 
     137        originalFilePath.String());
     138    }
    116139  }
    117140  catch(CZipException ex)
    … …  
    122145      originalFilePath.String(),
    123146      (LPCTSTR)ex.GetErrorDescription());
     147    _zip.Close(CZipArchive::afAfterException);
     148    _exceptions ++;
    124149  }
    125150  if(!ok) { Error(_errMsg); }
    … …  
    130155//--------------------------------------------------------------------
    131156//Extrae un fichero del archivo
    132 bool StoreZipArchive::FileExtract(BText originalFilePath, BText destinationDirPath)
    133 //--------------------------------------------------------------------
    134 {
    135   _errMsg[0]='\0';
    136   bool ok = true;
     157bool StoreZipArchive::FileExtract(BText originalFilePath, BText destinationDirPath_)
     158//--------------------------------------------------------------------
     159{
     160  if(_exceptions) { return(false); }
     161  _errMsg[0]='\0';
     162  bool ok = true;
     163  BText destinationDirPath = GetStandardAbsolutePath(destinationDirPath_+"/");
    137164  try
    138165  {
    … …  
    140167    if((index>=0) && (index!=ZIP_FILE_INDEX_NOT_FOUND))
    141168    {
    142       _zip.ExtractFile(index, destinationDirPath.String());
     169      ok = _zip.ExtractFile(index, destinationDirPath.String());
     170      if(!ok)
     171      {
     172        sprintf(_errMsg, "[ZipArchive] Error while extracting from archive %s file %s to %s",
     173          _path.String(), 
     174          originalFilePath.String(),
     175          destinationDirPath.String());
     176      }
    143177    }
    144178    else
    145179    {
    146       ok = false; 
    147     }
    148   }
    149   catch(CZipException ex)
    150   {
    151     ok = false;
    152     sprintf(_errMsg, "[ZipArchive] Error while extracting from archive file %s to %s%s: %s",
     180      ok = false;
     181      sprintf(_errMsg, "[ZipArchive] Error while extracting from archive %s file %s to %s: File not found in ZIP",
     182        _path.String(), 
     183        originalFilePath.String(),
     184        destinationDirPath.String());
     185    }
     186  }
     187  catch(CZipException ex)
     188  {
     189    ok = false;
     190    sprintf(_errMsg, "[ZipArchive] Error while extracting from archive %s file %s to %s: %s",
    153191      _path.String(), 
    154192      originalFilePath.String(),
    155193      destinationDirPath.String(),
    156194      (LPCTSTR)ex.GetErrorDescription());
     195    _zip.Close(CZipArchive::afAfterException);
     196    _exceptions ++;
    157197  }
    158198  if(!ok) { Error(_errMsg); }
    … …  
    166206//--------------------------------------------------------------------
    167207{
     208  if(_exceptions) { return(false); }
    168209  _errMsg[0]='\0';
    169210  int index = -1;
    … …  
    177218  {
    178219    ok = false;
    179     sprintf(_errMsg, "[ZipArchive] Error while finding in archive %s file %s: %s",
     220    sprintf(_errMsg, "[ZipArchive] Error while searching in archive %s file %s: %s",
    180221      _path.String(), 
    181222      originalFilePath.String(),
    182223      (LPCTSTR)ex.GetErrorDescription());
     224    _zip.Close(CZipArchive::afAfterException);
     225    _exceptions ++;
    183226  }
    184227  if(!ok) { Error(_errMsg); }
    … …  
    192235//--------------------------------------------------------------------
    193236{
     237  if(_exceptions) { return(false); }
    194238  _errMsg[0]='\0';
    195239  bool ok = true;
    … …  
    202246      ZipArchiveLib::CNameFileFilter::toAll);
    203247    // This will include empty directories
    204     _zip.AddNewFiles(originalDirPath.String(), filter);
     248    ok = _zip.AddNewFiles(originalDirPath.String(), filter);
     249    if(!ok)
     250    {
     251      sprintf(_errMsg, "[ZipArchive] Error while adding to archive %s directory %s : %s",
     252        _path.String(), 
     253        originalDirPath.String());
     254    }
    205255  }
    206256  catch(CZipException ex)
    … …  
    211261      originalDirPath.String(),
    212262      (LPCTSTR)ex.GetErrorDescription());
     263    _zip.Close(CZipArchive::afAfterException);
     264    _exceptions ++;
    213265  }
    214266  if(!ok) { Error(_errMsg); }
    … …  
    222274//--------------------------------------------------------------------
    223275{
     276  if(_exceptions) { return(false); }
    224277  _errMsg[0]='\0';
    225278  bool ok = true;
    … …  
    253306      destinationDirPath.String(),
    254307      (LPCTSTR)ex.GetErrorDescription());
     308    _zip.Close(CZipArchive::afAfterException);
     309    _exceptions ++;
    255310  }
    256311  if(!ok) { Error(_errMsg); }
    … …  
    264319//--------------------------------------------------------------------
    265320{
     321  if(_exceptions) { return(false); }
    266322  _errMsg[0]='\0';
    267323  bool ok = true;
    … …  
    282338      originalDirPath.String(),
    283339      (LPCTSTR)ex.GetErrorDescription());
     340    _zip.Close(CZipArchive::afAfterException);
     341    _exceptions ++;
    284342  }
    285343  if(!ok) { Error(_errMsg); }
  • tol/PackArchive/tol_PackArchive.h

    rb9ea255 r387ce2b  
    7777  virtual bool Close();
    7878  //Añade un fichero al archivo
    79   virtual bool FileAdd(BText originalFilePath);
     79  virtual bool FileAdd(BText originalFilePath, BText pathInZip);
    8080  //Extrae un fichero del archivo
    8181  virtual bool FileExtract(BText originalFilePath, BText destinationDirPath) = 0;
  • tol/PackArchive/tol_StoreZipArchive.h

    rb9ea255 r387ce2b  
    4040 public:
    4141  CZipArchive _zip;
    42 
     42  int _exceptions;
    4343  StoreZipArchive();
    4444 ~StoreZipArchive();
    … …  
    4949  bool Close();
    5050  //Añade un fichero al archivo
    51   bool FileAdd(BText originalFilePath);
     51  bool FileAdd(BText originalFilePath, BText pathInZip);
    5252  //Extrae un fichero del archivo
    5353  bool FileExtract(BText originalFilePath, BText destinationDirPath);
  • tol/stdlib/general/system/PackArchive/PackArchive.tol

    rb9ea255 r387ce2b  
    2626  Text ext = @Store::Extension(engine);
    2727  @Store s = @Store::Create(engine, originalFilPath+ext, "w");
    28   Real ok = s::FileAdd(originalDirPath);
     28  Real ok = s::FileAdd([[originalFilPath]]);
    2929  s::Close(0);
    3030  Real If(ok & remove, OSFilRemove(originalFilPath));
    … …  
    4343  Text ext = @Store::Extension(engine);
    4444  @Store s = @Store::Create(engine, originalFilPath+ext, "r");
    45   Real ok = s::FileExtract("*",originalDirPath);
     45  Real ok = s::FileExtract(GetFileName(originalFilPath),
     46                           GetFilePath(originalFilPath));
    4647  s::Close(0);
    4748  Real If(ok & remove, OSFilRemove(originalFilPath+ext));
  • tol/stdlib/general/system/PackArchive/Store.tol

    rb9ea255 r387ce2b  
    7272
    7373  ////////////////////////////////////////////////////////////////////////////
    74   //Añade un fichero al archivo
    75   Real FileAdd(Set originalFilePath)
     74  //Añade un conjunto de ficheros al archivo
     75  Real FileAdd(Set originalFilPaths)
    7676  ////////////////////////////////////////////////////////////////////////////
    7777  {
    7878    Real If(Or(_handle<=0, _.openMode==" "),False,
    79      PackArchive.FileAdd(_handle, originalFilePath))
     79     SetMin(EvalSet(originalFilPaths, Real(Text originalFilPath)
     80     {
     81       PackArchive.FileAdd(_handle, originalFilPath, GetFileName(originalFilPath))
     82     })))
    8083  };
    8184
    8285  ////////////////////////////////////////////////////////////////////////////
    8386  //Extrae un fichero del archivo
    84   Real FileExtract(Text originalFilePath, Text destinationDirPath)
     87  Real FileExtract(Text originalFilPath, Text destinationDirPath)
    8588  ////////////////////////////////////////////////////////////////////////////
    8689  {
    8790    Real If(Or(_handle<=0, _.openMode==" "),False,
    88      PackArchive.FileExtract(_handle, originalFilePath, destinationDirPath))
     91     PackArchive.FileExtract(_handle, originalFilPath, destinationDirPath))
    8992  };
    9093
    9194  ////////////////////////////////////////////////////////////////////////////
    9295  //Determina si existe o no un fichero dentro del archivo
    93   Real FileExists(Text originalFilePath)
     96  Real FileExists(Text originalFilPath)
    9497  ////////////////////////////////////////////////////////////////////////////
    9598  {
    9699    Real If(Or(_handle<=0, _.openMode==" "),False,
    97      PackArchive.FileExists(_handle, originalFilePath))
     100     PackArchive.FileExists(_handle, originalFilPath))
    98101  };
    99102
Note: See TracChangeset for help on using the changeset viewer.