grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / c / Unpack / unpack.c
blobcb72455fc7629ccc287da489f5e964931f8aa717
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 #include <aros/shcommands.h>
63 #include "modes.h"
64 #include "package.h"
65 #include "gui.h"
67 struct IntuitionBase *IntuitionBase;
68 struct GfxBase *GfxBase;
69 struct Library *BZ2Base;
71 AROS_SH2
73 Unpack, 1.1,
74 AROS_SHA( STRPTR, , FILE, /A, NULL ),
75 AROS_SHA( STRPTR, , TO, /A, NULL )
78 AROS_SHCOMMAND_INIT
80 BPTR oldDir = BNULL,
81 newDir = BNULL;
82 APTR pkg = NULL;
84 if( SHArg(FILE) == NULL ) goto cleanup;
85 if( SHArg(TO) == NULL ) goto cleanup;
87 IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", 0 );
88 GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", 0 );
89 BZ2Base = OpenLibrary( "bz2.library", 0 );
91 //Printf( "%s, %s\n", SHArg(FILE), SHArg(TO) );
93 pkg = PKG_Open( SHArg(FILE), MODE_READ );
94 if( pkg == NULL ) goto cleanup;
96 newDir = Lock( SHArg(TO), SHARED_LOCK );
97 if( newDir == BNULL ) goto cleanup;
98 oldDir = CurrentDir( newDir );
100 if( !GUI_Open() ) goto cleanup;
102 PKG_ExtractEverything( pkg );
104 cleanup:
105 GUI_Close();
107 if( oldDir != BNULL ) CurrentDir( oldDir );
108 if( newDir != BNULL ) UnLock( newDir );
109 if( pkg != NULL ) PKG_Close( pkg );
111 if( BZ2Base != NULL ) CloseLibrary( BZ2Base );
112 if( IntuitionBase != NULL ) CloseLibrary( (struct Library *) IntuitionBase );
113 if( GfxBase != NULL ) CloseLibrary( (struct Library *) GfxBase );
115 return 0;
117 AROS_SHCOMMAND_EXIT