Implemented bz2 as shared library.
[AROS.git] / workbench / c / Unpack / unpack.c
blob92c9cc90427388414ba01a2175618cd2654d0cd0
1 /*
2 Copyright © 2003, 2009, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /******************************************************************************
8 NAME
10 Unpack
12 SYNOPSIS
14 FILE/A, TO/A
16 LOCATION
20 FUNCTION
22 Command to unpack/unarchive AROS .pkg files.
24 INPUTS
26 NAME - The name of the file to unpack.
27 TO – The drive or path to be unpacked.
30 RESULT
32 Standard DOS error codes.
34 NOTES
36 This command is not a tool like lha, lzx or unzip.
37 The .pkg files may be created with the python program
38 in tools/package/pkg and compressed with bzip2 afterwards.
41 EXAMPLE
43 Unpack AROS.pkg TO Ram:
45 BUGS
47 SEE ALSO
49 INTERNALS
51 HISTORY
53 04.05.2000 SDuvan implemented
55 ******************************************************************************/
57 #include <dos/dos.h>
58 #include <dos/rdargs.h>
59 #include <proto/exec.h>
60 #include <proto/dos.h>
62 #define SH_GLOBAL_DOSBASE 1
63 #define SH_GLOBAL_SYSBASE 1
65 #include <aros/shcommands.h>
67 #include "modes.h"
68 #include "package.h"
69 #include "gui.h"
71 struct IntuitionBase *IntuitionBase;
72 struct GfxBase *GfxBase;
73 struct Library *BZ2Base;
75 AROS_SH2
77 Unpack, 1.1,
78 AROS_SHA( STRPTR, , FILE, /A, NULL ),
79 AROS_SHA( STRPTR, , TO, /A, NULL )
82 AROS_SHCOMMAND_INIT
84 BPTR oldDir = BNULL,
85 newDir = BNULL;
86 APTR pkg = NULL;
88 if( SHArg(FILE) == NULL ) goto cleanup;
89 if( SHArg(TO) == NULL ) goto cleanup;
91 IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", 0 );
92 GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", 0 );
93 BZ2Base = OpenLibrary( "bz2.library", 0 );
95 //Printf( "%s, %s\n", SHArg(FILE), SHArg(TO) );
97 pkg = PKG_Open( SHArg(FILE), MODE_READ );
98 if( pkg == NULL ) goto cleanup;
100 newDir = Lock( SHArg(TO), SHARED_LOCK );
101 if( newDir == BNULL ) goto cleanup;
102 oldDir = CurrentDir( newDir );
104 if( !GUI_Open() ) goto cleanup;
106 PKG_ExtractEverything( pkg );
108 cleanup:
109 GUI_Close();
111 if( oldDir != BNULL ) CurrentDir( oldDir );
112 if( newDir != BNULL ) UnLock( newDir );
113 if( pkg != NULL ) PKG_Close( pkg );
115 if( BZ2Base != NULL ) CloseLibrary( BZ2Base );
116 if( IntuitionBase != NULL ) CloseLibrary( (struct Library *) IntuitionBase );
117 if( GfxBase != NULL ) CloseLibrary( (struct Library *) GfxBase );
119 return 0;
121 AROS_SHCOMMAND_EXIT