EnglishРусский  

   ..

   DOCS

   read.me

   unrar.g

The project is closed! You can look at a new scripting language. It is available on GitHub.
Also, try our open source cross-platform automation software.

Ads

Installer and installation software
Commercial and Freeware installers.

source\lib\unrar\unrar.g
  1 #exe = 0
  2 #norun = 0
  3 #gefile = 1
  4 #libdir = %EXEPATH%\lib
  5 #libdir1 = %EXEPATH%\..\lib\vis
  6 #include = %EXEPATH%\lib\stdlib.ge
  7 //#wait = 1
  8 /******************************************************************************
  9 *
 10 * Copyright (C) 2009, The Gentee Group. All rights reserved. 
 11 * This file is part of the Gentee open source project - http://www.gentee.com. 
 12 * 
 13 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT"). 
 14 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS 
 15 * ACCEPTANCE OF THE AGREEMENT.
 16 *
 17 * Author: Alexander Antypenko ( santy ) v. 1.01
 18 *
 19 ******************************************************************************/
 20 
 21 define 
 22 {
 23  ERAR_END_ARCHIVE        =10
 24  ERAR_NO_MEMORY          =11
 25  ERAR_BAD_DATA           =12
 26  ERAR_BAD_ARCHIVE        =13
 27  ERAR_UNKNOWN_FORMAT     =14
 28  ERAR_EOPEN              =15
 29  ERAR_ECREATE            =16
 30  ERAR_ECLOSE             =17
 31  ERAR_EREAD              =18
 32  ERAR_EWRITE             =19
 33  ERAR_SMALL_BUF          =20
 34  ERAR_UNKNOWN            =21
 35  ERAR_MISSING_PASSWORD   =22
 36 
 37  // OpenMode
 38  RAR_OM_LIST             = 0
 39  RAR_OM_EXTRACT          = 1
 40  RAR_OM_LIST_INCSPLIT    = 2
 41 
 42  // File operation
 43  RAR_SKIP              = 0
 44  RAR_TEST              = 1
 45  RAR_EXTRACT           = 2
 46                        
 47  RAR_VOL_ASK           = 0
 48  RAR_VOL_NOTIFY        = 1
 49 
 50  RAR_DLL_VERSION       = 4
 51 
 52  UCM_CHANGEVOLUME      = 0
 53  UCM_PROCESSDATA       = 1
 54  UCM_NEEDPASSWORD      = 2
 55 
 56 }
 57 
 58 type RARHeaderData
 59 {
 60   uint         ArcName
 61   uint         FileName
 62   uint	       Flags
 63   uint	       PackSize
 64   uint	       UnpSize
 65   uint	       HostOS
 66   uint	       FileCRC
 67   uint	       FileTime
 68   uint	       UnpVer
 69   uint	       Method
 70   uint	       FileAttr
 71   uint         CmtBuf
 72   uint	       CmtBufSize
 73   uint	       CmtSize
 74   uint	       CmtState
 75 }
 76 
 77 
 78 type RARHeaderDataEx
 79 {
 80   uint          ArcName
 81   uint         ArcNameW
 82   uint          FileName
 83   uint         FileNameW
 84   uint	       Flags
 85   uint	       PackSize
 86   uint	       PackSizeHigh
 87   uint	       UnpSize
 88   uint	       UnpSizeHigh
 89   uint	       HostOS
 90   uint	       FileCRC
 91   uint	       FileTime
 92   uint	       UnpVer
 93   uint	       Method
 94   uint	       FileAttr
 95   uint          CmtBuf
 96   uint	       CmtBufSize
 97   uint	       CmtSize
 98   uint	       CmtState
 99   arr Reserved[[1024]] of uint
100 }
101 
102 
103 type RAROpenArchiveData
104 {
105   uint	       ArcName
106   uint         OpenMode
107   uint         OpenResult
108   uint         CmtBuf
109   uint         CmtBufSize
110   uint         CmtSize
111   uint         CmtState
112 }
113 
114 type RAROpenArchiveDataEx
115 {
116   uint          ArcName
117   uint         ArcNameW
118   uint         OpenMode
119   uint         OpenResult
120   uint          CmtBuf
121   uint         CmtBufSize
122   uint         CmtSize
123   uint         CmtState
124   uint         Flags
125   arr Reserved[32] of uint
126 }
127 
128 import "unrar.dll" 
129 {
130   uint RAROpenArchive(uint) -> _RAROpenArchive
131   uint RAROpenArchiveEx(uint) -> _RAROpenArchiveEx
132   int  RARCloseArchive(uint) -> _RARCloseArchive
133   int  RARReadHeader(uint,uint) -> _RARReadHeader
134   int  RARReadHeaderEx(uint,uint) -> _RARReadHeaderEx
135   int  RARProcessFile(uint,int ,uint,uint) -> _RARProcessFile
136   int  RARProcessFileW(uint,int,uint,uint) -> _RARProcessFileW
137        RARSetCallback(uint,uint,uint) -> _RARSetCallback
138        RARSetChangeVolProc(uint,uint)
139        RARSetProcessDataProc(uint,uint)
140        RARSetPassword(uint,uint) -> _RARSetPassword
141   int  RARGetDllVersion() ->_RARGetDllVersion
142 } 
143 
144 /*-----------------------------------------------------------------------------
145 * @syntax  [ RAROpenArchive(RAROpenArchiveData ArchiveData) ]
146 *
147 * @param ArchiveData RAROpenArchiveData structure
148 *
149 * @return Archive handle or NULL in case of error.
150 *
151 * Open RAR archive
152 -----------------------------------------------------------------------------*/
153 func uint RAROpenArchive(RAROpenArchiveData ArchiveData)
154 {
155   return _RAROpenArchive(&ArchiveData)
156 }
157  
158 /*-----------------------------------------------------------------------------
159 * @syntax  [ RAROpenArchiveEx(RAROpenArchiveDataEx ArchiveDataEx) ]
160 *
161 * @param ArchiveDataEx RAROpenArchiveDataEx structure
162 *
163 * @return Archive handle or NULL in case of error.
164 *
165 * Open RAR archive but uses RAROpenArchiveDataEx structure
166 * allowing to specify Unicode archive name and returning information
167 * about archive flags
168 -----------------------------------------------------------------------------*/
169 func uint RAROpenArchiveEx(RAROpenArchiveDataEx ArchiveDataEx)
170 {
171   return _RAROpenArchiveEx(&ArchiveDataEx)
172 }
173  
174 /*-----------------------------------------------------------------------------
175 * @syntax  [ RARCloseArchive(uint handleArc) ]
176 *
177 * @param handleArc archive handle obtained from the RAROpenArchive function call
178 *
179 * @return  0 - Success; $ERAR_ECLOSE - error.
180 *
181 * Close RAR archive
182 -----------------------------------------------------------------------------*/
183 func int RARCloseArchive(uint handleArc) : return _RARCloseArchive(handleArc)
184  
185 /*-----------------------------------------------------------------------------
186 * @syntax  [ RARReadHeader(uint handleArc,RARHeaderData HeaderData) ]
187 *
188 * @param handleArc archive handle obtained from the RAROpenArchive function call
189 *
190 * @param HeaderData Pointer to RARHeaderData structure
191 *
192 * @return  0 - Success;   $ERAR_END_ARCHIVE   -   End of archive
193 *			  $ERAR_BAD_DATA      -   File header broken
194 *
195 * Read header of file in RAR archive
196 -----------------------------------------------------------------------------*/
197 func int RARReadHeader(uint handleArc,uint HeaderData)
198 {
199   return  _RARReadHeader(handleArc,HeaderData)
200 }
201 
202 /*-----------------------------------------------------------------------------
203 * @syntax  [ RARReadHeaderEx(uint handleArc,RARHeaderDataEx HeaderData) ]
204 *
205 * @param handleArc archive handle obtained from the RAROpenArchive function call
206 *
207 * @param HeaderData Pointer to RARHeaderDataEx structure
208 *
209 * @return  0 - Success;   $ERAR_END_ARCHIVE   -   End of archive
210 *			  $ERAR_BAD_DATA      -   File header broken
211 *
212 * Read header of file in RAR archive but uses RARHeaderDataEx structure
213 * containing information about Unicode file names
214 -----------------------------------------------------------------------------*/
215 func int RARReadHeaderEx(uint handleArc,uint HeaderData)
216 {
217   return _RARReadHeaderEx(handleArc,HeaderData)
218 }
219 
220 /*-----------------------------------------------------------------------------
221 * @syntax  [ RARProcessFile(uint handleArc,int operation,str destPath,str destName) ]
222 *
223 * @param handleArc archive handle obtained from the RAROpenArchive function call
224 * @param operation File operation
225 * @param destPath This parameter containing the destination directory to which to extract files to
226 * @param destName This parameter should a string containing the full path and name 
227 *                 to assign to extracted file or it can be NULL to use the default name
228 *
229 * @return  0 - Success;   
230 *  or
231 *  $ERAR_BAD_DATA         File CRC error
232 *  $ERAR_BAD_ARCHIVE      Volume is not valid RAR archive
233 *  $ERAR_UNKNOWN_FORMAT   Unknown archive format
234 *  $ERAR_EOPEN            Volume open error
235 *  $ERAR_ECREATE          File create error
236 *  $ERAR_ECLOSE           File close error
237 *  $ERAR_EREAD            Read error
238 *  $ERAR_EWRITE           Write error
239 *
240 * Performs action and moves the current position in the archive to 
241 *  the next file
242 -----------------------------------------------------------------------------*/
243 func int RARProcessFile(uint handleArc,int operation,str destPath,str destName)
244 {
245   return _RARProcessFile(handleArc,operation,destPath.ptr(),destName.ptr())
246 }
247 
248 /*-----------------------------------------------------------------------------
249 * @syntax  [ RARProcessFileW(uint handleArc,int operation,ustr destPath,ustr destName) ]
250 *
251 * @param handleArc archive handle obtained from the RAROpenArchive function call
252 * @param operation File operation
253 * @param destPath This parameter containing the destination directory to which to extract files to
254 * @param destName This parameter should a string containing the full path and name 
255 *                 to assign to extracted file or it can be NULL to use the default name
256 *
257 * @return  0 - Success;   
258 *  or
259 *  $ERAR_BAD_DATA         File CRC error
260 *  $ERAR_BAD_ARCHIVE      Volume is not valid RAR archive
261 *  $ERAR_UNKNOWN_FORMAT   Unknown archive format
262 *  $ERAR_EOPEN            Volume open error
263 *  $ERAR_ECREATE          File create error
264 *  $ERAR_ECLOSE           File close error
265 *  $ERAR_EREAD            Read error
266 *  $ERAR_EWRITE           Write error
267 *
268 * Unicode version of RARProcessFile 
269 * Performs action and moves the current position in the archive to 
270 *  the next file
271 -----------------------------------------------------------------------------*/
272 func int RARProcessFileW(uint handleArc,int operation,ustr destPath,ustr destName)
273 {
274   return _RARProcessFileW(handleArc,operation,destPath.ptr(),destName.ptr())
275 }
276 
277 /*-----------------------------------------------------------------------------
278 * @syntax  [ RARSetCallback(uint handleArc,uint callBackFunc,uint userData) ]
279 *
280 * @param handleArc Archive handle obtained from the RAROpenArchive function call
281 * @param callBackFunc User-defined callback function
282 * @param userData User data passed to callback function
283 *
284 * Set a user-defined callback function to process Unrar events
285 -----------------------------------------------------------------------------*/
286 func RARSetCallback(uint handleArc,uint callBackFunc,uint userData)
287 {
288   uint addrFunc = callback(callBackFunc,4)
289   _RARSetCallback(handleArc,addrFunc,userData)
290 }
291 
292 /*-----------------------------------------------------------------------------
293 * @syntax  [ RARSetPassword(uint handleArc,str password) ]
294 *
295 * @param handleArc Archive handle obtained from the RAROpenArchive function call
296 * @param password String containing a zero terminated password
297 *
298 * Set a password to decrypt files.
299 -----------------------------------------------------------------------------*/
300 func RARSetPassword(uint handleArc,str password)
301 {
302   _RARSetPassword(handleArc,password.ptr())
303 }
304  
305 
306 type rarfile
307 {
308   str arcName
309   RARHeaderData headerData
310   RAROpenArchiveData openArchiveData
311   uint errorCode 
312   uint arcHandle
313   uint headerData_ptr
314 }
315 
316 method rarfile.init()
317 {
318 }
319 
320 method int rarfile.open(str arcName)
321 {
322   buf CmtBuf[16384]
323   this.arcName = arcName
324   mzero( &this.openArchiveData, sizeof( RAROpenArchiveData ))
325   with this.openArchiveData
326   {
327    .ArcName=this.arcName.ptr()
328    .CmtBuf=CmtBuf.ptr()
329    .CmtBufSize=16384
330    .OpenMode=$RAR_OM_EXTRACT
331   }
332 
333   this.arcHandle=RAROpenArchive(this.openArchiveData)
334   this.errorCode = this.openArchiveData.OpenResult
335   if (this.openArchiveData.OpenResult == 0) : this.headerData_ptr  = malloc(sizeof( RARHeaderData ))
336   return this.openArchiveData.OpenResult
337 }
338 
339 method rarfile.close(str arcName)
340 {
341   mfree(this.headerData_ptr)
342   RARCloseArchive(this.arcHandle)
343 }
344 
345 method int rarfile.readHeader()
346 {
347   return RARReadHeader(this.arcHandle,this.headerData_ptr)
348 }
349 
350 method int rarfile.processFile(int operation,str destpath,str destName)
351 {
352   return RARProcessFile(this.arcHandle,operation,destpath,destName)
353 }
354 
355 method arrstr rarfile.operationWithFiles<result>(int iOper)
356 {
357   int RHCode,PFCode
358   str sFileName
359   arrstr retFlNames
360 
361   while ((RHCode=this.readHeader()) == 0)
362   {
363     sFileName.load(this.headerData_ptr+260,260).setlenptr()
364     PFCode = this.processFile(iOper,"","")
365     this.errorCode = PFCode
366     if (PFCode != 0) : break
367     else : retFlNames+=sFileName
368     sFileName.clear()
369   }
370   result = retFlNames
371 }
372 
373 method rarfile.extractFiles(arrstr extrNames) : extrNames = this.operationWithFiles($RAR_EXTRACT)
374 method rarfile.testFiles(arrstr testNames) : testNames = this.operationWithFiles($RAR_TEST)
375 
376 method rarfile.setPassword(str passw) : RARSetPassword(this.arcHandle,passw)
377 
378 method rarfile.openArchiveError()
379 {
380   switch (this.errorCode)
381   {
382     case $ERAR_NO_MEMORY: print("\nNot enough memory")
383     case $ERAR_EOPEN: print("\nCannot open " + this.arcName)
384     case $ERAR_BAD_ARCHIVE: print("\n "+this.arcName+" is not RAR archive")
385     case $ERAR_BAD_DATA: print("\n "+this.arcName+"  : archive header broken")
386     case $ERAR_UNKNOWN:  print("Unknown error")
387   }
388 }
389