fix a typo..
[AROS-Contrib.git] / pack / xad_rar / Rar_Extractor-0.2.1 / demo.cpp
blobd9d47b346213737ffc4e911378a618ad9f150c9d
2 // Use Rar_Extractor to open "test.rar" and list it and possibly extract files.
4 const int extract = 0; // 0: just list files, 1: extract
6 #include "unrar/Rar_Extractor.h"
8 #include <stdlib.h>
9 #include <stdio.h>
11 static void check_error( const char* str )
13 if ( str )
15 fprintf( stderr, "Error: %s\n", str );
16 exit( EXIT_FAILURE );
20 int main()
22 // Open file
23 Std_File_Reader file;
24 check_error( file.open( "test.rar" ) );
26 // Open archive
27 Rar_Extractor rar;
28 check_error( rar.open( &file ) );
30 // If not extracting, use faster scan-only mode
31 if ( !extract )
32 rar.scan_only();
34 // Iterate over each item in archive until end is reached
35 const char* error;
36 while ( (error = rar.next()) != end_of_rar )
38 check_error( error );
40 if ( !rar.info().is_file )
42 printf( "Directory %s\n", rar.info().name );
44 else
46 printf( "File %s\n", rar.info().name );
48 if ( extract )
50 // Create output file
51 Std_File_Writer out;
52 check_error( out.open( rar.info().name ) );
54 // Extract to it
55 error = rar.extract( out );
56 if ( error )
57 fprintf( stderr, "Error: %s\n", error );
62 return 0;