mirror of
https://github.com/id-Software/Wolf3D-iOS.git
synced 2026-03-20 00:49:35 +01:00
Source release of Wolfenstein 3D Classic Platinum for iOS, 2.1
This commit is contained in:
104
wolf3d/wolfextractor/zip/zip.h
Normal file
104
wolf3d/wolfextractor/zip/zip.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
|
||||
Copyright (C) 2004 Michael Liebscher
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef __ZIP_H__
|
||||
#define __ZIP_H__
|
||||
|
||||
#include "../../../common/arch.h"
|
||||
|
||||
/* compression method */
|
||||
#define CM_NO_COMPRESSION 0
|
||||
#define CM_SHRUNK 1
|
||||
#define CM_REDUCED_F1 2
|
||||
#define CM_REDUCED_F2 3
|
||||
#define CM_REDUCED_F3 4
|
||||
#define CM_REDUCED_F4 5
|
||||
#define CM_IMPLODED 6
|
||||
#define CM_RESERVED_7 7
|
||||
#define CM_DEFLATED 8
|
||||
#define CM_DEFLATE64 9
|
||||
#define CM_IMPLODING 10
|
||||
#define CM_RESERVED_11 11
|
||||
#define CM_BZIP2 12
|
||||
|
||||
|
||||
/* version made by */
|
||||
#define VMB_MSDOS_FAT 0
|
||||
#define VMB_AMIGA 1
|
||||
#define VMB_OPENVMS 2
|
||||
#define VMB_UNIX 3
|
||||
#define VMB_VM_CMS 4
|
||||
#define VMB_ATARI_ST 5
|
||||
#define VMB_OS_2_HPFS 6
|
||||
#define VMB_MACINTOSH 7
|
||||
#define VMB_Z_SYSTEM 8
|
||||
#define VMB_CP_M 9
|
||||
#define VMB_WINDOWS_NTFS 10
|
||||
#define VMB_MVS_OS_390_Z_OS 11
|
||||
#define VMB_VSE 12
|
||||
#define VMB_ACORN_RISC 13
|
||||
#define VMB_VFAT 14
|
||||
#define VMB_ALTERNATE_MVS 15
|
||||
#define VMB_BEOS 16
|
||||
#define VMB_TANDEM 17
|
||||
#define VMB_OS_400 18
|
||||
#define VMB_OS_X_DARWIN 19
|
||||
|
||||
|
||||
|
||||
|
||||
struct zlist
|
||||
{
|
||||
W16 versionmadeby;
|
||||
W16 versionneeded;
|
||||
W16 flag;
|
||||
W16 compression_method;
|
||||
W32 timedate;
|
||||
W32 crc32;
|
||||
W32 compressed_size;
|
||||
W32 uncompressed_size;
|
||||
W16 filename_length;
|
||||
W16 extrafield_length;
|
||||
W16 centralextra_length;
|
||||
W16 comment_length;
|
||||
W16 disknumstart;
|
||||
W16 internalattribute;
|
||||
W16 localflag;
|
||||
W32 externalattribute;
|
||||
W32 offset;
|
||||
_boolean deletefile;
|
||||
char filename[ 256 ];
|
||||
char extrafield[ 256 ];
|
||||
char centralextra[ 256 ];
|
||||
char comment[ 256 ];
|
||||
|
||||
struct zlist *next; /* Pointer to next header in chain */
|
||||
};
|
||||
|
||||
|
||||
extern _boolean zip_writelocalfileheader( struct zlist *z, FILE *f );
|
||||
extern _boolean zip_writeextended( struct zlist *z, FILE *f );
|
||||
extern _boolean zip_writecentral( struct zlist *z, FILE *f );
|
||||
extern _boolean zip_writeend( SW32 num, W32 size, W32 offset, W16 len, char *comment, FILE *f );
|
||||
|
||||
|
||||
|
||||
#endif /* __ZIP_H__ */
|
||||
|
||||
267
wolf3d/wolfextractor/zip/zipfile.c
Normal file
267
wolf3d/wolfextractor/zip/zipfile.c
Normal file
@@ -0,0 +1,267 @@
|
||||
/*
|
||||
|
||||
Copyright (C) 2004 Michael Liebscher
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
* zipfile.c: Write zip file
|
||||
*
|
||||
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
Notes:
|
||||
|
||||
Reference document:
|
||||
http://www.pkware.com/company/standards/appnote/appnote.txt
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../../../common/arch.h"
|
||||
#include "../../../common/common_utils.h"
|
||||
#include "zip.h"
|
||||
|
||||
/* Signatures for zip file information headers */
|
||||
#define SIG_LOCAL 0x04034b50L
|
||||
#define SIG_CENTRAL 0x02014b50L
|
||||
#define SIG_END 0x06054b50L
|
||||
#define SIG_EXTENDLOCAL 0x08074b50L
|
||||
#define SIG_EXTENDSPLOCAL 0x30304b50L
|
||||
|
||||
/* Length of header (not counting the signature) */
|
||||
#define LOCALHEAD_SIZE 26
|
||||
#define CENTRALHEAD_SIZE 42
|
||||
#define ENDHEAD_SIZE 18
|
||||
|
||||
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
Function: zip_writelocalfileheader -Write a local header to file.
|
||||
|
||||
Parameters:
|
||||
z -[in] zip entry to write local header for.
|
||||
f -[in] File to write to.
|
||||
|
||||
Returns:
|
||||
|
||||
Notes:
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
_boolean zip_writelocalfileheader( struct zlist *z, FILE *f )
|
||||
{
|
||||
W32 temp32;
|
||||
W16 temp16;
|
||||
W32 retval;
|
||||
|
||||
temp32 = LittleLong( SIG_LOCAL );
|
||||
retval = fwrite( &temp32, 1, 4, f );
|
||||
|
||||
temp16 = LittleShort( z->versionneeded );
|
||||
retval += fwrite( &temp16, 1, 2, f );
|
||||
|
||||
temp16 = LittleShort( z->localflag );
|
||||
retval += fwrite( &temp16, 1, 2, f );
|
||||
|
||||
temp16 = LittleShort( z->compression_method );
|
||||
retval += fwrite( &temp16, 1, 2, f );
|
||||
|
||||
temp32 = LittleLong( z->timedate );
|
||||
retval += fwrite( &temp32, 1, 4, f );
|
||||
|
||||
temp32 = LittleLong( z->crc32 );
|
||||
retval += fwrite( &temp32, 1, 4, f );
|
||||
|
||||
temp32 = LittleLong( z->compressed_size );
|
||||
retval += fwrite( &temp32, 1, 4, f );
|
||||
|
||||
temp32 = LittleLong( z->uncompressed_size );
|
||||
retval += fwrite( &temp32, 1, 4, f );
|
||||
|
||||
temp16 = LittleShort( z->filename_length );
|
||||
retval += fwrite( &temp16, 1, 2, f );
|
||||
|
||||
temp16 = LittleShort( z->extrafield_length );
|
||||
retval += fwrite( &temp16, 1, 2, f );
|
||||
|
||||
if( retval != LOCALHEAD_SIZE + 4 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( fwrite( z->filename, 1, z->filename_length, f ) != z->filename_length ||
|
||||
(z->extrafield && fwrite( z->extrafield, 1, z->extrafield_length, f) != z->extrafield_length) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
Function: zip_writecentral -Write a central header to file.
|
||||
|
||||
Parameters:
|
||||
z -[in] zip entry to write central header for.
|
||||
f -[in] File to write to.
|
||||
|
||||
Returns:
|
||||
|
||||
Notes:
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
_boolean zip_writecentral( struct zlist *z, FILE *f )
|
||||
{
|
||||
W32 temp32;
|
||||
W16 temp16;
|
||||
W32 retval;
|
||||
|
||||
temp32 = LittleLong( SIG_CENTRAL );
|
||||
retval = fwrite( &temp32, 1, 4, f );
|
||||
|
||||
temp16 = LittleShort( z->versionmadeby );
|
||||
retval += fwrite( &temp16, 1, 2, f );
|
||||
|
||||
temp16 = LittleShort( z->versionneeded );
|
||||
retval += fwrite( &temp16, 1, 2, f );
|
||||
|
||||
temp16 = LittleShort( z->flag );
|
||||
retval += fwrite( &temp16, 1, 2, f );
|
||||
|
||||
temp16 = LittleShort( z->compression_method );
|
||||
retval += fwrite( &temp16, 1, 2, f );
|
||||
|
||||
temp32 = LittleLong( z->timedate );
|
||||
retval += fwrite( &temp32, 1, 4, f );
|
||||
|
||||
temp32 = LittleLong( z->crc32 );
|
||||
retval += fwrite( &temp32, 1, 4, f );
|
||||
|
||||
temp32 = LittleLong( z->compressed_size );
|
||||
retval += fwrite( &temp32, 1, 4, f );
|
||||
|
||||
temp32 = LittleLong( z->uncompressed_size );
|
||||
retval += fwrite( &temp32, 1, 4, f );
|
||||
|
||||
temp16 = LittleShort( z->filename_length );
|
||||
retval += fwrite( &temp16, 1, 2, f );
|
||||
|
||||
temp16 = LittleShort( z->centralextra_length );
|
||||
retval += fwrite( &temp16, 1, 2, f );
|
||||
|
||||
temp16 = LittleShort( z->comment_length );
|
||||
retval += fwrite( &temp16, 1, 2, f );
|
||||
|
||||
temp16 = LittleShort( z->disknumstart );
|
||||
retval += fwrite( &temp16, 1, 2, f );
|
||||
|
||||
temp16 = LittleShort( z->internalattribute );
|
||||
retval += fwrite( &temp16, 1, 2, f );
|
||||
|
||||
temp32 = LittleLong( z->externalattribute );
|
||||
retval += fwrite( &temp32, 1, 4, f );
|
||||
|
||||
temp32 = LittleLong( z->offset );
|
||||
retval += fwrite( &temp32, 1, 4, f );
|
||||
|
||||
if( retval != CENTRALHEAD_SIZE + 4 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( fwrite(z->filename, 1, z->filename_length, f) != z->filename_length ||
|
||||
(z->centralextra_length && fwrite(z->centralextra, 1, z->centralextra_length, f) != z->centralextra_length) ||
|
||||
(z->comment_length && fwrite(z->comment, 1, z->comment_length, f) != z->comment_length) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
Function: zip_writeend -Write end of central directory data to file.
|
||||
|
||||
Parameters:
|
||||
num -[in] Number of entries in central directory.
|
||||
size -[in] Size of central directory.
|
||||
offset -[in] Offset of central directory.
|
||||
len -[in] Length of zip file comment (0 if none).
|
||||
comment -[in] Zip file comment if len != 0.
|
||||
f -[in] File to write to.
|
||||
|
||||
Returns:
|
||||
|
||||
Notes:
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
_boolean zip_writeend( SW32 num, W32 size, W32 offset, W16 len, char *comment, FILE *f )
|
||||
{
|
||||
W32 temp32;
|
||||
W16 temp16;
|
||||
W32 retval;
|
||||
|
||||
temp32 = LittleLong( SIG_END );
|
||||
retval = fwrite( &temp32, 1, 4, f );
|
||||
|
||||
temp16 = 0;
|
||||
retval += fwrite( &temp16, 1, 2, f );
|
||||
|
||||
temp16 = 0;
|
||||
retval += fwrite( &temp16, 1, 2, f );
|
||||
|
||||
temp16 = LittleShort( num );
|
||||
retval += fwrite( &temp16, 1, 2, f );
|
||||
|
||||
temp16 = LittleShort( num );
|
||||
retval += fwrite( &temp16, 1, 2, f );
|
||||
|
||||
temp32 = LittleLong( size );
|
||||
retval += fwrite( &temp32, 1, 4, f );
|
||||
|
||||
temp32 = LittleLong( offset );
|
||||
retval += fwrite( &temp32, 1, 4, f );
|
||||
|
||||
temp16 = LittleShort( len );
|
||||
retval += fwrite( &temp16, 1, 2, f );
|
||||
|
||||
if( retval != ENDHEAD_SIZE + 4 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if( len && fwrite( comment, 1, len, f ) != len )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user