Changeset 387ce2b in tol
- Timestamp:
- Mar 17, 2011, 5:59:55 PM (16 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- 724c736
- Parents:
- b9ea255
- Location:
- tol
- Files:
-
- 6 edited
-
PackArchive/PackArchive.cpp (modified) (9 diffs)
-
PackArchive/StoreZipArchive.cpp (modified) (19 diffs)
-
PackArchive/tol_PackArchive.h (modified) (1 diff)
-
PackArchive/tol_StoreZipArchive.h (modified) (2 diffs)
-
stdlib/general/system/PackArchive/PackArchive.tol (modified) (2 diffs)
-
stdlib/general/system/PackArchive/Store.tol (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
tol/PackArchive/PackArchive.cpp
rb9ea255 r387ce2b 140 140 bool Store::Open(BText path, char openMode) { return(false); }; 141 141 bool Store::Close() { return(false); }; 142 bool Store::FileAdd(BText originalFilePath ) { return(false); };142 bool Store::FileAdd(BText originalFilePath, BText pathInZip) { return(false); }; 143 143 bool Store::FileExtract(BText originalFilePath, BText destinationDirPath) { return(false); }; 144 144 bool Store::FileExist(BText originalFilePath) { return(false); }; … … 185 185 //-------------------------------------------------------------------- 186 186 DeclareContensClass(BDat, BDatTemporary, BDatPackArchiveClose); 187 DefExtOpr(1, BDatPackArchiveClose, "PackArchive.Close", 1, 1, "Real", 187 DefExtOpr(1, BDatPackArchiveClose, "PackArchive.Close", 188 1, 1, "Real", 188 189 "(Real packArchiveId)", 189 190 I2("Closes a packed archive that was open with ", … … 212 213 DeclareContensClass(BDat, BDatTemporary, BDatPackArchiveFileAdd); 213 214 DefExtOpr(1, BDatPackArchiveFileAdd, "PackArchive.FileAdd", 214 1, 2, "RealText",215 "(Real packArchiveId, Text originalFilePath )",215 3, 3, "Real Text Text", 216 "(Real packArchiveId, Text originalFilePath, Text pathInZip)", 216 217 I2("Adds a file to a packed archive that was open with ", 217 218 "Añade un fichero a un archivo empaquetado que fue abierto con ")+ … … 226 227 if(store) 227 228 { 228 contens_ = store->FileAdd(Text(Arg(2)) );229 contens_ = store->FileAdd(Text(Arg(2)),Text(Arg(3))); 229 230 } 230 231 else … … 237 238 DeclareContensClass(BDat, BDatTemporary, BDatPackArchiveFileExtract); 238 239 DefExtOpr(1, BDatPackArchiveFileExtract, "PackArchive.FileExtract", 239 1, 3, "Real Text Text",240 3, 3, "Real Text Text", 240 241 "(Real packArchiveId, Text originalFilePath, Text destinationDirPath)", 241 242 I2("Extracts a file from a packed archive that was open with ", … … 262 263 DeclareContensClass(BDat, BDatTemporary, BDatPackArchiveFileExist); 263 264 DefExtOpr(1, BDatPackArchiveFileExist, "PackArchive.FileExist", 264 1, 2, "Real Text",265 2, 2, "Real Text", 265 266 "(Real packArchiveId, Text originalFilePath)", 266 267 I2("Checks if there is a file into a packed archive that was open with ", … … 287 288 DeclareContensClass(BDat, BDatTemporary, BDatPackArchiveDirAdd); 288 289 DefExtOpr(1, BDatPackArchiveDirAdd, "PackArchive.DirAdd", 289 1, 2, "Real Text",290 2, 2, "Real Text", 290 291 "(Real packArchiveId, Text originalDirPath)", 291 292 I2("Adds recursively a directory to a packed archive that was open " … … 314 315 DeclareContensClass(BDat, BDatTemporary, BDatPackArchiveDirExtract); 315 316 DefExtOpr(1, BDatPackArchiveDirExtract, "PackArchive.DirExtract", 316 1, 3, "Real Text Text",317 3, 3, "Real Text Text", 317 318 "(Real packArchiveId, Text originalFilePath, Text destinationDirPath)", 318 319 I2("Extracts recursively a directory from a packed archive that was open with ", … … 339 340 DeclareContensClass(BDat, BDatTemporary, BDatPackArchiveDirExist); 340 341 DefExtOpr(1, BDatPackArchiveDirExist, "PackArchive.DirExist", 341 1, 2, "Real Text",342 2, 2, "Real Text", 342 343 "(Real packArchiveId, Text originalFilePath)", 343 344 I2("Checks if there is a directory into a packed archive that was open with ", -
tol/PackArchive/StoreZipArchive.cpp
rb9ea255 r387ce2b 28 28 #include "tol_PackArchive.h" 29 29 #include "tol_StoreZipArchive.h" 30 #include "tol_bdir.h" 30 31 31 32 //-------------------------------------------------------------------- 32 33 StoreZipArchive::StoreZipArchive() 33 34 //-------------------------------------------------------------------- 34 : Store() 35 : Store(), _exceptions(0) 35 36 { 36 37 } … … 47 48 //-------------------------------------------------------------------- 48 49 { 50 if(_exceptions) { return(false); } 49 51 _errMsg[0]='\0'; 50 52 _path = path; … … 56 58 { 57 59 remove(_path); 58 _zip.Open(_path.String(), CZipArchive::zipCreate);60 ok = _zip.Open(_path.String(), CZipArchive::zipCreate); 59 61 } 60 62 else if(openMode=='r') 61 63 { 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()); 63 70 } 64 71 } … … 72 79 (LPCTSTR)ex.GetErrorDescription()); 73 80 _zip.Close(CZipArchive::afAfterException); 81 _exceptions ++; 74 82 } 75 83 if(!ok) { Error(_errMsg); } … … 82 90 //-------------------------------------------------------------------- 83 91 { 92 if(_exceptions) { return(false); } 84 93 _errMsg[0]='\0'; 85 94 if(_openMode == ' ') { return(true); } … … 97 106 (LPCTSTR)ex.GetErrorDescription()); 98 107 _zip.Close(CZipArchive::afAfterException); 108 _exceptions ++; 99 109 } 100 110 if(!ok) { Error(_errMsg); } … … 106 116 //-------------------------------------------------------------------- 107 117 //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()); 118 bool 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 } 116 139 } 117 140 catch(CZipException ex) … … 122 145 originalFilePath.String(), 123 146 (LPCTSTR)ex.GetErrorDescription()); 147 _zip.Close(CZipArchive::afAfterException); 148 _exceptions ++; 124 149 } 125 150 if(!ok) { Error(_errMsg); } … … 130 155 //-------------------------------------------------------------------- 131 156 //Extrae un fichero del archivo 132 bool StoreZipArchive::FileExtract(BText originalFilePath, BText destinationDirPath) 133 //-------------------------------------------------------------------- 134 { 135 _errMsg[0]='\0'; 136 bool ok = true; 157 bool 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_+"/"); 137 164 try 138 165 { … … 140 167 if((index>=0) && (index!=ZIP_FILE_INDEX_NOT_FOUND)) 141 168 { 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 } 143 177 } 144 178 else 145 179 { 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", 153 191 _path.String(), 154 192 originalFilePath.String(), 155 193 destinationDirPath.String(), 156 194 (LPCTSTR)ex.GetErrorDescription()); 195 _zip.Close(CZipArchive::afAfterException); 196 _exceptions ++; 157 197 } 158 198 if(!ok) { Error(_errMsg); } … … 166 206 //-------------------------------------------------------------------- 167 207 { 208 if(_exceptions) { return(false); } 168 209 _errMsg[0]='\0'; 169 210 int index = -1; … … 177 218 { 178 219 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", 180 221 _path.String(), 181 222 originalFilePath.String(), 182 223 (LPCTSTR)ex.GetErrorDescription()); 224 _zip.Close(CZipArchive::afAfterException); 225 _exceptions ++; 183 226 } 184 227 if(!ok) { Error(_errMsg); } … … 192 235 //-------------------------------------------------------------------- 193 236 { 237 if(_exceptions) { return(false); } 194 238 _errMsg[0]='\0'; 195 239 bool ok = true; … … 202 246 ZipArchiveLib::CNameFileFilter::toAll); 203 247 // 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 } 205 255 } 206 256 catch(CZipException ex) … … 211 261 originalDirPath.String(), 212 262 (LPCTSTR)ex.GetErrorDescription()); 263 _zip.Close(CZipArchive::afAfterException); 264 _exceptions ++; 213 265 } 214 266 if(!ok) { Error(_errMsg); } … … 222 274 //-------------------------------------------------------------------- 223 275 { 276 if(_exceptions) { return(false); } 224 277 _errMsg[0]='\0'; 225 278 bool ok = true; … … 253 306 destinationDirPath.String(), 254 307 (LPCTSTR)ex.GetErrorDescription()); 308 _zip.Close(CZipArchive::afAfterException); 309 _exceptions ++; 255 310 } 256 311 if(!ok) { Error(_errMsg); } … … 264 319 //-------------------------------------------------------------------- 265 320 { 321 if(_exceptions) { return(false); } 266 322 _errMsg[0]='\0'; 267 323 bool ok = true; … … 282 338 originalDirPath.String(), 283 339 (LPCTSTR)ex.GetErrorDescription()); 340 _zip.Close(CZipArchive::afAfterException); 341 _exceptions ++; 284 342 } 285 343 if(!ok) { Error(_errMsg); } -
tol/PackArchive/tol_PackArchive.h
rb9ea255 r387ce2b 77 77 virtual bool Close(); 78 78 //Añade un fichero al archivo 79 virtual bool FileAdd(BText originalFilePath );79 virtual bool FileAdd(BText originalFilePath, BText pathInZip); 80 80 //Extrae un fichero del archivo 81 81 virtual bool FileExtract(BText originalFilePath, BText destinationDirPath) = 0; -
tol/PackArchive/tol_StoreZipArchive.h
rb9ea255 r387ce2b 40 40 public: 41 41 CZipArchive _zip; 42 42 int _exceptions; 43 43 StoreZipArchive(); 44 44 ~StoreZipArchive(); … … 49 49 bool Close(); 50 50 //Añade un fichero al archivo 51 bool FileAdd(BText originalFilePath );51 bool FileAdd(BText originalFilePath, BText pathInZip); 52 52 //Extrae un fichero del archivo 53 53 bool FileExtract(BText originalFilePath, BText destinationDirPath); -
tol/stdlib/general/system/PackArchive/PackArchive.tol
rb9ea255 r387ce2b 26 26 Text ext = @Store::Extension(engine); 27 27 @Store s = @Store::Create(engine, originalFilPath+ext, "w"); 28 Real ok = s::FileAdd( originalDirPath);28 Real ok = s::FileAdd([[originalFilPath]]); 29 29 s::Close(0); 30 30 Real If(ok & remove, OSFilRemove(originalFilPath)); … … 43 43 Text ext = @Store::Extension(engine); 44 44 @Store s = @Store::Create(engine, originalFilPath+ext, "r"); 45 Real ok = s::FileExtract("*",originalDirPath); 45 Real ok = s::FileExtract(GetFileName(originalFilPath), 46 GetFilePath(originalFilPath)); 46 47 s::Close(0); 47 48 Real If(ok & remove, OSFilRemove(originalFilPath+ext)); -
tol/stdlib/general/system/PackArchive/Store.tol
rb9ea255 r387ce2b 72 72 73 73 //////////////////////////////////////////////////////////////////////////// 74 //Añade un ficheroal archivo75 Real FileAdd(Set originalFil ePath)74 //Añade un conjunto de ficheros al archivo 75 Real FileAdd(Set originalFilPaths) 76 76 //////////////////////////////////////////////////////////////////////////// 77 77 { 78 78 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 }))) 80 83 }; 81 84 82 85 //////////////////////////////////////////////////////////////////////////// 83 86 //Extrae un fichero del archivo 84 Real FileExtract(Text originalFil ePath, Text destinationDirPath)87 Real FileExtract(Text originalFilPath, Text destinationDirPath) 85 88 //////////////////////////////////////////////////////////////////////////// 86 89 { 87 90 Real If(Or(_handle<=0, _.openMode==" "),False, 88 PackArchive.FileExtract(_handle, originalFil ePath, destinationDirPath))91 PackArchive.FileExtract(_handle, originalFilPath, destinationDirPath)) 89 92 }; 90 93 91 94 //////////////////////////////////////////////////////////////////////////// 92 95 //Determina si existe o no un fichero dentro del archivo 93 Real FileExists(Text originalFil ePath)96 Real FileExists(Text originalFilPath) 94 97 //////////////////////////////////////////////////////////////////////////// 95 98 { 96 99 Real If(Or(_handle<=0, _.openMode==" "),False, 97 PackArchive.FileExists(_handle, originalFil ePath))100 PackArchive.FileExists(_handle, originalFilPath)) 98 101 }; 99 102
Note: See TracChangeset
for help on using the changeset viewer.
