Backport and version tag
[AROS.git] / workbench / c / Unpack / unpack.c
blobe6c95cd9357869fd2530b6f1c794d5cc3eeaa853
1 /*
2 Copyright © 2003-2014, 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 ******************************************************************************/
53 #include <dos/dos.h>
54 #include <dos/rdargs.h>
55 #include <proto/exec.h>
56 #include <proto/dos.h>
58 #define SH_GLOBAL_DOSBASE 1
59 #define SH_GLOBAL_SYSBASE 1
61 #ifdef __AROS__
62 #include <aros/shcommands.h>
63 #else
64 #define AROS_SH2(a,b,c,d) main()
65 #define AROS_SHCOMMAND_INIT
66 #define AROS_SHCOMMAND_EXIT
67 #define FILE 0
68 #define TO 0
69 #endif
71 #include "modes.h"
72 #include "package.h"
73 #include "gui.h"
75 struct IntuitionBase *IntuitionBase;
76 struct GfxBase *GfxBase;
77 struct Library *BZ2Base;
79 AROS_SH2
81 Unpack, 1.1,
82 AROS_SHA( STRPTR, , FILE, /A, NULL ),
83 AROS_SHA( STRPTR, , TO, /A, NULL )
86 AROS_SHCOMMAND_INIT
88 BPTR oldDir = BNULL,
89 newDir = BNULL;
90 APTR pkg = NULL;
92 if( SHArg(FILE) == NULL ) goto cleanup;
93 if( SHArg(TO) == NULL ) goto cleanup;
95 IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", 0 );
96 GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", 0 );
97 BZ2Base = OpenLibrary( "bz2.library", 0 );
99 //Printf( "%s, %s\n", SHArg(FILE), SHArg(TO) );
101 pkg = PKG_Open( SHArg(FILE), MODE_READ );
102 if( pkg == NULL ) goto cleanup;
104 newDir = Lock( SHArg(TO), SHARED_LOCK );
105 if( newDir == BNULL ) goto cleanup;
106 oldDir = CurrentDir( newDir );
108 if( !GUI_Open() ) goto cleanup;
110 PKG_ExtractEverything( pkg );
112 cleanup:
113 GUI_Close();
115 if( oldDir != BNULL ) CurrentDir( oldDir );
116 if( newDir != BNULL ) UnLock( newDir );
117 if( pkg != NULL ) PKG_Close( pkg );
119 if( BZ2Base != NULL ) CloseLibrary( BZ2Base );
120 if( IntuitionBase != NULL ) CloseLibrary( (struct Library *) IntuitionBase );
121 if( GfxBase != NULL ) CloseLibrary( (struct Library *) GfxBase );
123 return 0;
125 AROS_SHCOMMAND_EXIT