* reverted r225 as the license is still unclear
git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/branches/ZeroRadiant@226 8a3a26a2-13c4-0310-b231-cf6edde360e5
Before Width: | Height: | Size: 560 B |
Before Width: | Height: | Size: 556 B |
Before Width: | Height: | Size: 556 B |
Before Width: | Height: | Size: 556 B |
Before Width: | Height: | Size: 238 B |
Before Width: | Height: | Size: 564 B |
Before Width: | Height: | Size: 238 B |
Before Width: | Height: | Size: 568 B |
Before Width: | Height: | Size: 560 B |
|
@ -1,87 +0,0 @@
|
|||
// MainWnd.h: interface for the CMainWnd class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_MAINWND_H__E2FFC5D8_4D6E_4752_8976_811551035B7A__INCLUDED_)
|
||||
#define AFX_MAINWND_H__E2FFC5D8_4D6E_4752_8976_811551035B7A__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "tree.h"
|
||||
#include "pak.h"
|
||||
|
||||
|
||||
//void HandleCommand(GtkWidget *widget, gpointer data);
|
||||
|
||||
|
||||
class CMainWnd
|
||||
{
|
||||
public:
|
||||
CMainWnd();
|
||||
virtual ~CMainWnd();
|
||||
|
||||
GtkWidget* m_pMainWnd;
|
||||
GtkWidget *m_pStatusLabel[3];
|
||||
GtkWidget *m_ScrolledWin;
|
||||
GtkWidget *m_Toolbar;
|
||||
|
||||
GtkWidget* m_mnuDrop;
|
||||
|
||||
CTree m_Tree;
|
||||
CPak pak;
|
||||
|
||||
std::list<std::string> texlist;
|
||||
std::list<CPak*> paklist;
|
||||
std::list<std::string> exclusions;
|
||||
std::list<std::string> temp_files;
|
||||
|
||||
BOOL Create(GtkWidget *parent);
|
||||
BOOL CreateToolbar(GtkWidget *window,GtkWidget *vbox);
|
||||
BOOL CreateStatusBar(GtkWidget *window,GtkWidget *vbox);
|
||||
BOOL CreateTreeView(GtkWidget *window,GtkWidget *vbox);
|
||||
|
||||
void GetPaths();
|
||||
void UpdateTree();
|
||||
void UpdateStatus();
|
||||
void UpdateToolBar();
|
||||
|
||||
void HandleDrop();
|
||||
|
||||
// command handlers
|
||||
bool OnFileNew();
|
||||
void OnFileOpen();
|
||||
void OnFileSave();
|
||||
void OnWizard();
|
||||
void OnView();
|
||||
void OnExtract();
|
||||
void OnAdd();
|
||||
void OnRename();
|
||||
void OnDelete();
|
||||
bool OnClose();
|
||||
void OnDestroy();
|
||||
|
||||
bool ProcessFile(const char *name,const char *suffix,const char *folder);
|
||||
bool ProcessFile(const char *name);
|
||||
|
||||
std::string GetLine(FILE *fp);
|
||||
void SkipLines(FILE *fp, int n);
|
||||
void AddToTexList(const char *buf);
|
||||
bool IsInTexList(const char *tex);
|
||||
void ParseShader(const char*sname, const char *tex);
|
||||
std::string TrimString(const char *str);
|
||||
void ParseModel(const char *pathname);
|
||||
|
||||
void InitPakList();
|
||||
void InitPaksInDir(const char *folder);
|
||||
void FreePakList();
|
||||
bool FindInAPk3(const char *name);
|
||||
|
||||
void LoadExclusions();
|
||||
bool IsExcluded(const char *name);
|
||||
void DeleteTempFiles();
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_MAINWND_H__E2FFC5D8_4D6E_4752_8976_811551035B7A__INCLUDED_)
|
|
@ -1,111 +0,0 @@
|
|||
// MD3 file headers
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char ID[4]; //id of file, always "IDP3"
|
||||
int Version; //i suspect this is a version
|
||||
//number, always 15
|
||||
char FileName[68]; //sometimes left Blank...
|
||||
//65 chars, 32bit aligned ==
|
||||
//68 chars
|
||||
int BoneFrame_num; //number of BoneFrames
|
||||
int Tag_num; //number of 'tags' per BoneFrame
|
||||
int Mesh_num; //number of meshes/skins
|
||||
int MaxSkin_num; //maximum number of unique skins
|
||||
//used in md3 file
|
||||
int HeaderLength; //always equal to the length of
|
||||
//this header
|
||||
int Tag_Start; //starting position of
|
||||
//tag-structures
|
||||
int Tag_End; //ending position of
|
||||
//tag-structures/starting
|
||||
//position of mesh-structures
|
||||
int FileSize; //size of file
|
||||
} md3_header_t;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char Name[64]; //name of 'tag' as it's usually
|
||||
//called in the md3 files try to
|
||||
//see it as a sub-mesh/seperate
|
||||
//mesh-part.
|
||||
//sometimes this 64 string may
|
||||
//contain some garbage, but
|
||||
//i've been told this is because
|
||||
//some tools leave garbage in
|
||||
//those strings, but they ARE
|
||||
//strings...
|
||||
float Postition[3]; //relative position of tag
|
||||
float Rotation[3][3]; //the direction the tag is facing relative to the rest of the model
|
||||
} md3_tag_t;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
//unverified:
|
||||
float Mins[3];
|
||||
float Maxs[3];
|
||||
float Position[3];
|
||||
float scale;
|
||||
char Creator[16]; //i think this is the
|
||||
//"creator" name..
|
||||
//but i'm only guessing.
|
||||
} md3_boneframe_t;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char ID[4]; //id, must be IDP3
|
||||
char Name[68]; //name of mesh
|
||||
//65 chars,
|
||||
//32 bit aligned == 68 chars
|
||||
int MeshFrame_num; //number of meshframes
|
||||
//in mesh
|
||||
int Skin_num; //number of skins in mesh
|
||||
int Vertex_num; //number of vertices
|
||||
int Triangle_num; //number of Triangles
|
||||
int Triangle_Start; //starting position of
|
||||
//Triangle data, relative
|
||||
//to start of Mesh_Header
|
||||
int HeaderSize; //size of header
|
||||
int TexVec_Start; //starting position of
|
||||
//texvector data, relative
|
||||
//to start of Mesh_Header
|
||||
int Vertex_Start; //starting position of
|
||||
//vertex data,relative
|
||||
//to start of Mesh_Header
|
||||
int MeshSize; //size of mesh
|
||||
} md3_mesh_t;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char Name[68]; //name of skin used by mesh
|
||||
//65 chars,
|
||||
//32 bit aligned == 68 chars
|
||||
} md3_skin_t;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int Triangle[3]; //vertex 1,2,3 of triangle
|
||||
|
||||
} md3_triangles_t;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float TexVec[2]; //Texture U/V coordinates of vertex
|
||||
|
||||
} md3_texcoords_t;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
//!!!important!!! signed!
|
||||
signed short Vec[3]; //vertex X/Y/Z coordinate
|
||||
unsigned char EnvTex[2]; //enviromental mapping texture coordinates
|
||||
|
||||
} md3_vertices_t;
|
|
@ -1,36 +0,0 @@
|
|||
// MemFile.cpp: implementation of the CMemFile class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "memfile.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CMemFile::CMemFile()
|
||||
{
|
||||
data=NULL;
|
||||
ptr=NULL;
|
||||
end=NULL;
|
||||
}
|
||||
|
||||
CMemFile::CMemFile(char *block,long len)
|
||||
{
|
||||
data=block;
|
||||
ptr=block;
|
||||
end=block+len;
|
||||
}
|
||||
|
||||
|
||||
CMemFile::~CMemFile()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CMemFile::Read(void *to,long size)
|
||||
{
|
||||
memcpy(to,ptr,size);
|
||||
ptr+=size;
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
// MemFile.h: interface for the CMemFile class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_MEMFILE_H__FCA4B794_CC06_4F09_8B54_B1BF10291ECA__INCLUDED_)
|
||||
#define AFX_MEMFILE_H__FCA4B794_CC06_4F09_8B54_B1BF10291ECA__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
class CMemFile
|
||||
{
|
||||
public:
|
||||
CMemFile();
|
||||
CMemFile(char *data, long len);
|
||||
virtual ~CMemFile();
|
||||
|
||||
char *data;
|
||||
char *ptr;
|
||||
char *end;
|
||||
|
||||
void Read(void *to,long size);
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_MEMFILE_H__FCA4B794_CC06_4F09_8B54_B1BF10291ECA__INCLUDED_)
|
|
@ -1,421 +0,0 @@
|
|||
// Pak.cpp: implementation of the CPak class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "pak.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CPak::CPak()
|
||||
{
|
||||
m_bModified=FALSE;
|
||||
|
||||
}
|
||||
|
||||
CPak::~CPak()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
|
||||
bool CPak::Open(const char *filename)
|
||||
{
|
||||
Close();
|
||||
|
||||
unzFile uf=NULL;
|
||||
|
||||
uf = unzOpen(filename);
|
||||
if (uf==NULL)
|
||||
return FALSE;
|
||||
|
||||
unz_global_info gi;
|
||||
int err = unzGetGlobalInfo (uf,&gi);
|
||||
if (err!=UNZ_OK)
|
||||
{
|
||||
Close();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
m_filename=filename;
|
||||
|
||||
// ok, now build the internal list of entries
|
||||
|
||||
unzGoToFirstFile(uf);
|
||||
|
||||
do
|
||||
{
|
||||
pak_entry pe;
|
||||
|
||||
pe.frompak=TRUE;
|
||||
pe.pakname=m_filename;
|
||||
pe.rename=FALSE;
|
||||
|
||||
char filename_inzip[256];
|
||||
unz_file_info file_info;
|
||||
// uLong ratio=0;
|
||||
// const char *string_method;
|
||||
err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
|
||||
if (err!=UNZ_OK)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
pe.filename=filename_inzip;
|
||||
pe.compressed=file_info.compressed_size;
|
||||
pe.uncompressed=file_info.uncompressed_size;
|
||||
|
||||
entries.push_back(pe);
|
||||
|
||||
} while (unzGoToNextFile(uf)==UNZ_OK);
|
||||
|
||||
|
||||
unzClose(uf);
|
||||
m_bModified=FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool CPak::Save(const char *path)
|
||||
{
|
||||
if (!m_bModified)
|
||||
return FALSE;
|
||||
|
||||
if (path==NULL)
|
||||
return FALSE;
|
||||
|
||||
// unzFile uf=NULL;
|
||||
zipFile zf=NULL;
|
||||
|
||||
zf=zipOpen(path,0);
|
||||
|
||||
for ( std::list<pak_entry>::const_iterator iEntry = entries.begin() ; iEntry != entries.end() ; iEntry++)
|
||||
{
|
||||
pak_entry pe=*iEntry;
|
||||
|
||||
if (pe.frompak)
|
||||
{
|
||||
if (pe.pakname.compare(m_filename)==0)
|
||||
{
|
||||
// its in this pak
|
||||
long size;
|
||||
unsigned char *buf=Extract(pe.filename.c_str(),size);
|
||||
|
||||
if (!buf)
|
||||
continue;
|
||||
|
||||
zip_fileinfo zipfi;
|
||||
|
||||
std::string name=pe.filename;
|
||||
if (pe.rename)
|
||||
name=pe.newname;
|
||||
|
||||
zipOpenNewFileInZip(zf,name.c_str(),&zipfi,NULL,0,NULL,0,NULL,Z_DEFLATED,Z_DEFAULT_COMPRESSION);
|
||||
zipWriteInFileInZip(zf,buf,size);
|
||||
zipCloseFileInZip(zf);
|
||||
|
||||
delete buf;
|
||||
}
|
||||
else
|
||||
{
|
||||
// its in another pack
|
||||
|
||||
CPak p;
|
||||
if (!p.Open(pe.pakname.c_str()))
|
||||
continue;
|
||||
|
||||
long size;
|
||||
unsigned char *buf=p.Extract(pe.filename.c_str(),size);
|
||||
|
||||
if (!buf)
|
||||
continue;
|
||||
|
||||
zip_fileinfo zipfi;
|
||||
|
||||
std::string name=pe.filename;
|
||||
if (pe.rename)
|
||||
name=pe.newname;
|
||||
|
||||
zipOpenNewFileInZip(zf,name.c_str(),&zipfi,NULL,0,NULL,0,NULL,Z_DEFLATED,Z_DEFAULT_COMPRESSION);
|
||||
zipWriteInFileInZip(zf,buf,size);
|
||||
zipCloseFileInZip(zf);
|
||||
|
||||
delete buf;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// its an external file
|
||||
|
||||
FILE *fp;
|
||||
fp=fopen(pe.pathname.c_str(),"rb");
|
||||
|
||||
if (!fp)
|
||||
continue;
|
||||
|
||||
fseek(fp,0,SEEK_END);
|
||||
long size=ftell(fp);
|
||||
fseek(fp,0,0);
|
||||
unsigned char *buf=new unsigned char[size];
|
||||
fread(buf,sizeof(unsigned char),size,fp);
|
||||
fclose(fp);
|
||||
|
||||
if (!buf)
|
||||
continue;
|
||||
|
||||
zip_fileinfo zipfi;
|
||||
|
||||
std::string name=pe.filename;
|
||||
if (pe.rename)
|
||||
name=pe.newname;
|
||||
|
||||
zipOpenNewFileInZip(zf,name.c_str(),&zipfi,NULL,0,NULL,0,NULL,Z_DEFLATED,Z_DEFAULT_COMPRESSION);
|
||||
zipWriteInFileInZip(zf,buf,size);
|
||||
zipCloseFileInZip(zf);
|
||||
|
||||
delete buf;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
zipClose(zf,"Created by Pk3man - http://pk3man.sourceforge.net");
|
||||
|
||||
m_bModified=FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CPak::Close()
|
||||
{
|
||||
|
||||
m_filename="";
|
||||
entries.clear();
|
||||
m_bModified=FALSE;
|
||||
|
||||
}
|
||||
|
||||
bool CPak::IsModified()
|
||||
{
|
||||
return m_bModified;
|
||||
}
|
||||
|
||||
pak_entry CPak::FindPE(const char *path)
|
||||
{
|
||||
pak_entry pe;
|
||||
|
||||
for ( std::list<pak_entry>::const_iterator iEntry = entries.begin() ; iEntry != entries.end() ; iEntry++)
|
||||
{
|
||||
pe=*iEntry;
|
||||
|
||||
if (!pe.rename && pe.filename.compare(path)==0)
|
||||
return pe;
|
||||
|
||||
if (pe.rename && pe.newname.compare(path)==0)
|
||||
return pe;
|
||||
}
|
||||
|
||||
pe.compressed=0;
|
||||
pe.uncompressed=0;
|
||||
|
||||
return pe;
|
||||
}
|
||||
|
||||
bool CPak::IsEmpty()
|
||||
{
|
||||
return entries.empty();
|
||||
}
|
||||
|
||||
unsigned char *CPak::Extract(const char *path, long &size)
|
||||
{
|
||||
unzFile uf=NULL;
|
||||
|
||||
uf = unzOpen(m_filename.GetBuffer());
|
||||
if (uf==NULL)
|
||||
return FALSE;
|
||||
|
||||
unz_global_info gi;
|
||||
int err = unzGetGlobalInfo (uf,&gi);
|
||||
if (err!=UNZ_OK)
|
||||
{
|
||||
Close();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
unzGoToFirstFile(uf);
|
||||
|
||||
do
|
||||
{
|
||||
char filename_inzip[256];
|
||||
unz_file_info file_info;
|
||||
|
||||
err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
|
||||
|
||||
if (err!=UNZ_OK)
|
||||
{
|
||||
unzClose(uf);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
size=file_info.uncompressed_size;
|
||||
|
||||
if (strcmp(path,filename_inzip)==0)
|
||||
{
|
||||
// found it
|
||||
// extract it
|
||||
|
||||
if (unzOpenCurrentFile(uf)!=UNZ_OK)
|
||||
{
|
||||
unzClose(uf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned char *buf=new unsigned char[size];
|
||||
unzReadCurrentFile(uf,buf,size);
|
||||
unzCloseCurrentFile(uf);
|
||||
unzClose(uf);
|
||||
return buf;
|
||||
}
|
||||
|
||||
} while (unzGoToNextFile(uf)==UNZ_OK);
|
||||
|
||||
|
||||
unzClose(uf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool CPak::ExtractTo(const char *path, char *pathto)
|
||||
{
|
||||
long size;
|
||||
unsigned char *buf=Extract(path,size);
|
||||
|
||||
if (!buf)
|
||||
return FALSE;
|
||||
|
||||
FILE *f=fopen(pathto,"wb");
|
||||
if (f)
|
||||
{
|
||||
fwrite(buf,sizeof(unsigned char),size,f);
|
||||
fclose(f);
|
||||
delete buf;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
delete buf;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool CPak::IsInPak(const char *path)
|
||||
{
|
||||
pak_entry pe;
|
||||
|
||||
for ( std::list<pak_entry>::const_iterator iEntry = entries.begin() ; iEntry != entries.end() ; iEntry++)
|
||||
{
|
||||
pe=*iEntry;
|
||||
|
||||
if (!pe.rename && pe.filename.compare(path)==0)
|
||||
return TRUE;
|
||||
|
||||
if (pe.rename && pe.newname.compare(path)==0)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool CPak::AddExternalFile(const char *name,const char *path)
|
||||
{
|
||||
|
||||
FILE *fp;
|
||||
fp=fopen(path,"rb");
|
||||
|
||||
if (!fp)
|
||||
return FALSE;
|
||||
|
||||
fseek(fp,0,SEEK_END);
|
||||
long size=ftell(fp);
|
||||
fclose(fp);
|
||||
|
||||
pak_entry pe;
|
||||
|
||||
pe.rename=FALSE;
|
||||
pe.frompak=FALSE;
|
||||
pe.pathname=path;
|
||||
pe.filename=name;
|
||||
pe.compressed=size;
|
||||
pe.uncompressed=size;
|
||||
|
||||
entries.push_back(pe);
|
||||
|
||||
m_bModified=TRUE;
|
||||
|
||||
return TRUE;
|
||||
|
||||
}
|
||||
|
||||
bool CPak::AddPakFile(const char *name,const char *pakname,long comp, long uncomp)
|
||||
{
|
||||
pak_entry pe;
|
||||
|
||||
pe.rename=FALSE;
|
||||
pe.frompak=TRUE;
|
||||
|
||||
pe.filename=name;
|
||||
pe.pakname=pakname;
|
||||
pe.pathname="";
|
||||
|
||||
pe.compressed=comp;
|
||||
pe.uncompressed=uncomp;
|
||||
|
||||
entries.push_back(pe);
|
||||
|
||||
m_bModified=TRUE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool CPak::Delete(const char *path)
|
||||
{
|
||||
pak_entry pe;
|
||||
|
||||
for ( std::list<pak_entry>::iterator iEntry = entries.begin() ; iEntry != entries.end() ; iEntry++)
|
||||
{
|
||||
pe=*iEntry;
|
||||
|
||||
if ((!pe.rename && pe.filename.compare(path)==0) || (pe.rename && pe.newname.compare(path)==0))
|
||||
{
|
||||
entries.erase(iEntry);
|
||||
m_bModified=TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool CPak::Rename(const char *path,const char *newname)
|
||||
{
|
||||
pak_entry pe;
|
||||
|
||||
for ( std::list<pak_entry>::iterator iEntry = entries.begin() ; iEntry != entries.end() ; iEntry++)
|
||||
{
|
||||
pe=*iEntry;
|
||||
|
||||
if ((!pe.rename && pe.filename.compare(path)==0) || (pe.rename && pe.newname.compare(path)==0))
|
||||
{
|
||||
entries.erase(iEntry);
|
||||
|
||||
pe.rename=TRUE;
|
||||
pe.newname=newname;
|
||||
|
||||
entries.push_back(pe);
|
||||
m_bModified=TRUE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
// Pak.h: interface for the CPak class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_PAK_H__CB5AFBB6_E37C_4898_AB04_1ABEA6AC9B45__INCLUDED_)
|
||||
#define AFX_PAK_H__CB5AFBB6_E37C_4898_AB04_1ABEA6AC9B45__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "./zlib/zlib.h"
|
||||
#include "./zlib/unzip.h"
|
||||
#include "./zlib/zip.h"
|
||||
}
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// file
|
||||
std::string filename;
|
||||
std::string pathname;
|
||||
|
||||
// external pak
|
||||
BOOL frompak;
|
||||
std::string pakname;
|
||||
|
||||
// rename
|
||||
BOOL rename;
|
||||
std::string newname;
|
||||
|
||||
//sizes
|
||||
unsigned long uncompressed;
|
||||
unsigned long compressed;
|
||||
|
||||
} pak_entry;
|
||||
|
||||
|
||||
class CPak
|
||||
{
|
||||
public:
|
||||
CPak();
|
||||
virtual ~CPak();
|
||||
|
||||
|
||||
Str m_filename;
|
||||
std::list<pak_entry> entries;
|
||||
bool m_bModified;
|
||||
|
||||
bool Open(const char *filename);
|
||||
void Close();
|
||||
bool IsModified();
|
||||
bool Save(const char *);
|
||||
bool IsEmpty();
|
||||
|
||||
pak_entry FindPE(const char *path);
|
||||
bool IsInPak(const char *path);
|
||||
|
||||
bool AddExternalFile(const char *name,const char *path);
|
||||
bool AddPakFile(const char *name,const char *pakname,long comp, long uncomp);
|
||||
bool Delete(const char *path);
|
||||
bool Rename(const char *path,const char *newname);
|
||||
|
||||
bool ExtractTo(const char *path, char *pathto);
|
||||
unsigned char *Extract(const char *path, long &size);
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_PAK_H__CB5AFBB6_E37C_4898_AB04_1ABEA6AC9B45__INCLUDED_)
|
|
@ -1,581 +0,0 @@
|
|||
// PixMap.cpp: implementation of the CPixMap class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "pixmap.h"
|
||||
|
||||
#ifdef __linux__
|
||||
#include <gdk/gdkx.h>
|
||||
#else
|
||||
#include <gdk/win32/gdkwin32.h>
|
||||
#define NO_UNDERSCORE
|
||||
#endif
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CPixMap::CPixMap()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CPixMap::~CPixMap()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
unsigned char* CPixMap::load_bitmap_file (const char* filename,guint16* width, guint16* height)
|
||||
{
|
||||
gint32 bmWidth, bmHeight;
|
||||
guint16 bmPlanes, bmBitsPixel;
|
||||
typedef struct {
|
||||
unsigned char rgbBlue;
|
||||
unsigned char rgbGreen;
|
||||
unsigned char rgbRed;
|
||||
unsigned char rgbReserved;
|
||||
} RGBQUAD;
|
||||
unsigned char m1,m2;
|
||||
unsigned long sizeimage;
|
||||
short res1,res2;
|
||||
long filesize, pixoff;
|
||||
long bmisize, compression;
|
||||
long xscale, yscale;
|
||||
long colors, impcol;
|
||||
unsigned long m_bytesRead = 0;
|
||||
unsigned char *imagebits = NULL;
|
||||
FILE *fp;
|
||||
|
||||
*width = *height = 0;
|
||||
|
||||
fp = fopen(filename,"rb");
|
||||
if (fp == NULL)
|
||||
return NULL;
|
||||
|
||||
long rc;
|
||||
rc = fread(&m1, 1, 1, fp);
|
||||
m_bytesRead++;
|
||||
if (rc == -1)
|
||||
{
|
||||
fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rc = fread(&m2, 1, 1, fp);
|
||||
m_bytesRead++;
|
||||
if ((m1!='B') || (m2!='M'))
|
||||
{
|
||||
fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rc = fread((long*)&(filesize),4,1,fp); m_bytesRead+=4;
|
||||
if (rc != 1) { fclose(fp); return NULL; }
|
||||
|
||||
rc = fread((int*)&(res1),2,1,fp); m_bytesRead+=2;
|
||||
if (rc != 1) { fclose(fp); return NULL; }
|
||||
|
||||
rc = fread((int*)&(res2),2,1,fp); m_bytesRead+=2;
|
||||
if (rc != 1) { fclose(fp); return NULL; }
|
||||
|
||||
rc = fread((long*)&(pixoff),4,1,fp); m_bytesRead+=4;
|
||||
if (rc != 1) { fclose(fp); return NULL; }
|
||||
|
||||
rc = fread((long*)&(bmisize),4,1,fp); m_bytesRead+=4;
|
||||
if (rc != 1) { fclose(fp); return NULL; }
|
||||
|
||||
rc = fread((long*)&(bmWidth),4,1,fp); m_bytesRead+=4;
|
||||
if (rc != 1) { fclose(fp); return NULL; }
|
||||
|
||||
rc = fread((long*)&(bmHeight),4,1,fp); m_bytesRead+=4;
|
||||
if (rc != 1) { fclose(fp); return NULL; }
|
||||
|
||||
rc = fread((int*)&(bmPlanes),2,1,fp); m_bytesRead+=2;
|
||||
if (rc != 1) { fclose(fp); return NULL; }
|
||||
|
||||
rc = fread((int*)&(bmBitsPixel),2,1,fp); m_bytesRead+=2;
|
||||
if (rc != 1) { fclose(fp); return NULL; }
|
||||
|
||||
rc = fread((long*)&(compression),4,1,fp); m_bytesRead+=4;
|
||||
if (rc != 1) { fclose(fp); return NULL; }
|
||||
|
||||
rc = fread((long*)&(sizeimage),4,1,fp); m_bytesRead+=4;
|
||||
if (rc != 1) {fclose(fp); return NULL; }
|
||||
|
||||
rc = fread((long*)&(xscale),4,1,fp); m_bytesRead+=4;
|
||||
if (rc != 1) { fclose(fp); return NULL; }
|
||||
|
||||
rc = fread((long*)&(yscale),4,1,fp); m_bytesRead+=4;
|
||||
if (rc != 1) { fclose(fp); return NULL; }
|
||||
|
||||
rc = fread((long*)&(colors),4,1,fp); m_bytesRead+=4;
|
||||
if (rc != 1) { fclose(fp); return NULL; }
|
||||
|
||||
rc = fread((long*)&(impcol),4,1,fp); m_bytesRead+=4;
|
||||
if (rc != 1) { fclose(fp); return NULL; }
|
||||
|
||||
if (colors == 0)
|
||||
colors = 1 << bmBitsPixel;
|
||||
|
||||
RGBQUAD *colormap = NULL;
|
||||
|
||||
if (bmBitsPixel != 24)
|
||||
{
|
||||
colormap = new RGBQUAD[colors];
|
||||
if (colormap == NULL)
|
||||
{
|
||||
fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int i;
|
||||
for (i = 0; i < colors; i++)
|
||||
{
|
||||
unsigned char r ,g, b, dummy;
|
||||
|
||||
rc = fread(&b, 1, 1, fp);
|
||||
m_bytesRead++;
|
||||
if (rc!=1)
|
||||
{
|
||||
delete [] colormap;
|
||||
fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rc = fread(&g, 1, 1, fp);
|
||||
m_bytesRead++;
|
||||
if (rc!=1)
|
||||
{
|
||||
delete [] colormap;
|
||||
fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rc = fread(&r, 1, 1, fp);
|
||||
m_bytesRead++;
|
||||
if (rc != 1)
|
||||
{
|
||||
delete [] colormap;
|
||||
fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rc = fread(&dummy, 1, 1, fp);
|
||||
m_bytesRead++;
|
||||
if (rc != 1)
|
||||
{
|
||||
delete [] colormap;
|
||||
fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
colormap[i].rgbRed=r;
|
||||
colormap[i].rgbGreen=g;
|
||||
colormap[i].rgbBlue=b;
|
||||
}
|
||||
}
|
||||
|
||||
if ((long)m_bytesRead > pixoff)
|
||||
{
|
||||
delete [] colormap;
|
||||
fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while ((long)m_bytesRead < pixoff)
|
||||
{
|
||||
char dummy;
|
||||
fread(&dummy,1,1,fp);
|
||||
m_bytesRead++;
|
||||
}
|
||||
|
||||
int w = bmWidth;
|
||||
int h = bmHeight;
|
||||
|
||||
// set the output params
|
||||
imagebits = (unsigned char*)malloc(w*h*3);
|
||||
long row_size = w * 3;
|
||||
|
||||
if (imagebits != NULL)
|
||||
{
|
||||
*width = w;
|
||||
*height = h;
|
||||
unsigned char* outbuf = imagebits;
|
||||
long row = 0;
|
||||
long rowOffset = 0;
|
||||
|
||||
if (compression == 0) // BI_RGB
|
||||
{
|
||||
// read rows in reverse order
|
||||
for (row=bmHeight-1;row>=0;row--)
|
||||
{
|
||||
// which row are we working on?
|
||||
rowOffset = (long unsigned)row*row_size;
|
||||
|
||||
if (bmBitsPixel == 24)
|
||||
{
|
||||
for (int col=0;col<w;col++)
|
||||
{
|
||||
long offset = col * 3;
|
||||
char pixel[3];
|
||||
|
||||
if (fread((void*)(pixel),1,3,fp)==3)
|
||||
{
|
||||
// we swap red and blue here
|
||||
*(outbuf + rowOffset + offset + 0)=pixel[2]; // r
|
||||
*(outbuf + rowOffset + offset + 1)=pixel[1]; // g
|
||||
*(outbuf + rowOffset + offset + 2)=pixel[0]; // b
|
||||
}
|
||||
}
|
||||
m_bytesRead += row_size;
|
||||
|
||||
// read DWORD padding
|
||||
while ((m_bytesRead-pixoff)&3)
|
||||
{
|
||||
char dummy;
|
||||
if (fread(&dummy,1,1,fp) != 1)
|
||||
{
|
||||
free(imagebits);
|
||||
fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
m_bytesRead++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// pixels are packed as 1 , 4 or 8 bit vals. need to unpack them
|
||||
int bit_count = 0;
|
||||
unsigned long mask = (1 << bmBitsPixel) - 1;
|
||||
unsigned char inbyte = 0;
|
||||
|
||||
for (int col=0;col<w;col++)
|
||||
{
|
||||
int pix = 0;
|
||||
|
||||
// if we need another byte
|
||||
if (bit_count <= 0)
|
||||
{
|
||||
bit_count = 8;
|
||||
if (fread(&inbyte,1,1,fp) != 1)
|
||||
{
|
||||
free(imagebits);
|
||||
delete [] colormap;
|
||||
fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
m_bytesRead++;
|
||||
}
|
||||
|
||||
// keep track of where we are in the bytes
|
||||
bit_count -= bmBitsPixel;
|
||||
pix = ( inbyte >> bit_count) & mask;
|
||||
|
||||
// lookup the color from the colormap - stuff it in our buffer
|
||||
// swap red and blue
|
||||
*(outbuf + rowOffset + col * 3 + 2) = colormap[pix].rgbBlue;
|
||||
*(outbuf + rowOffset + col * 3 + 1) = colormap[pix].rgbGreen;
|
||||
*(outbuf + rowOffset + col * 3 + 0) = colormap[pix].rgbRed;
|
||||
}
|
||||
|
||||
// read DWORD padding
|
||||
while ((m_bytesRead-pixoff)&3)
|
||||
{
|
||||
char dummy;
|
||||
if (fread(&dummy,1,1,fp)!=1)
|
||||
{
|
||||
free(imagebits);
|
||||
if (colormap)
|
||||
delete [] colormap;
|
||||
fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
m_bytesRead++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int i, x = 0;
|
||||
unsigned char c, c1 = 0, *pp;
|
||||
row = 0;
|
||||
pp = outbuf + (bmHeight-1)*bmWidth*3;
|
||||
|
||||
if (bmBitsPixel == 8)
|
||||
{
|
||||
while (row < bmHeight)
|
||||
{
|
||||
c = getc(fp);
|
||||
|
||||
if (c)
|
||||
{
|
||||
// encoded mode
|
||||
c1 = getc(fp);
|
||||
for (i = 0; i < c; x++, i++)
|
||||
{
|
||||
*pp = colormap[c1].rgbRed; pp++;
|
||||
*pp = colormap[c1].rgbGreen; pp++;
|
||||
*pp = colormap[c1].rgbBlue; pp++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// c==0x00, escape codes
|
||||
c = getc(fp);
|
||||
|
||||
if (c == 0x00) // end of line
|
||||
{
|
||||
row++;
|
||||
x = 0;
|
||||
pp = outbuf + (bmHeight-row-1)*bmWidth*3;
|
||||
}
|
||||
else if (c == 0x01)
|
||||
break; // end of pic
|
||||
else if (c == 0x02) // delta
|
||||
{
|
||||
c = getc(fp);
|
||||
x += c;
|
||||
c = getc(fp);
|
||||
row += c;
|
||||
pp = outbuf + x*3 + (bmHeight-row-1)*bmWidth*3;
|
||||
}
|
||||
else // absolute mode
|
||||
{
|
||||
for (i = 0; i < c; x++, i++)
|
||||
{
|
||||
c1 = getc(fp);
|
||||
*pp = colormap[c1].rgbRed; pp++;
|
||||
*pp = colormap[c1].rgbGreen; pp++;
|
||||
*pp = colormap[c1].rgbBlue; pp++;
|
||||
}
|
||||
|
||||
if (c & 1)
|
||||
getc(fp); // odd length run: read an extra pad byte
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (bmBitsPixel == 4)
|
||||
{
|
||||
while (row < bmHeight)
|
||||
{
|
||||
c = getc(fp);
|
||||
|
||||
if (c)
|
||||
{
|
||||
// encoded mode
|
||||
c1 = getc(fp);
|
||||
for (i = 0; i < c; x++, i++)
|
||||
{
|
||||
*pp = colormap[(i&1) ? (c1 & 0x0f) : ((c1>>4)&0x0f)].rgbRed; pp++;
|
||||
*pp = colormap[(i&1) ? (c1 & 0x0f) : ((c1>>4)&0x0f)].rgbGreen; pp++;
|
||||
*pp = colormap[(i&1) ? (c1 & 0x0f) : ((c1>>4)&0x0f)].rgbBlue; pp++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// c==0x00, escape codes
|
||||
c = getc(fp);
|
||||
|
||||
if (c == 0x00) // end of line
|
||||
{
|
||||
row++;
|
||||
x = 0;
|
||||
pp = outbuf + (bmHeight-row-1)*bmWidth*3;
|
||||
}
|
||||
else if (c == 0x01)
|
||||
break; // end of pic
|
||||
else if (c == 0x02) // delta
|
||||
{
|
||||
c = getc(fp);
|
||||
x += c;
|
||||
c = getc(fp);
|
||||
row += c;
|
||||
pp = outbuf + x*3 + (bmHeight-row-1)*bmWidth*3;
|
||||
}
|
||||
else // absolute mode
|
||||
{
|
||||
for (i = 0; i < c; x++, i++)
|
||||
{
|
||||
if ((i&1) == 0)
|
||||
c1 = getc(fp);
|
||||
*pp = colormap[(i&1) ? (c1 & 0x0f) : ((c1>>4)&0x0f)].rgbRed; pp++;
|
||||
*pp = colormap[(i&1) ? (c1 & 0x0f) : ((c1>>4)&0x0f)].rgbGreen; pp++;
|
||||
*pp = colormap[(i&1) ? (c1 & 0x0f) : ((c1>>4)&0x0f)].rgbBlue; pp++;
|
||||
}
|
||||
|
||||
if (((c&3) == 1) || ((c&3) == 2))
|
||||
getc(fp); // odd length run: read an extra pad byte
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (colormap)
|
||||
delete [] colormap;
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
return imagebits;
|
||||
}
|
||||
|
||||
void CPixMap::bmp_to_pixmap (const char* filename, GdkPixmap **pixmap, GdkBitmap **mask)
|
||||
{
|
||||
guint16 width, height;
|
||||
unsigned char *buf;
|
||||
GdkWindow *window = GDK_ROOT_PARENT();
|
||||
GdkColormap *colormap;
|
||||
GdkGC* gc = gdk_gc_new (window);
|
||||
int i, j;
|
||||
GdkColor c;
|
||||
|
||||
*pixmap = *mask = NULL;
|
||||
buf = load_bitmap_file (filename, &width, &height);
|
||||
if (!buf)
|
||||
return;
|
||||
|
||||
colormap = gdk_window_get_colormap (window);
|
||||
*pixmap = gdk_pixmap_new (window, width, height, -1);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GdkColor c;
|
||||
unsigned char *p;
|
||||
} PAL;
|
||||
|
||||
GPtrArray* pal = g_ptr_array_new ();
|
||||
GdkColor** col = (GdkColor**)malloc (sizeof (GdkColor*) * height * width);
|
||||
guint32 k;
|
||||
|
||||
for (i = 0; i < height; i++)
|
||||
for (j = 0; j < width; j++)
|
||||
{
|
||||
unsigned char* p = &buf[(i*width+j)*3];
|
||||
|
||||
for (k = 0; k < pal->len; k++)
|
||||
{
|
||||
PAL *pe = (PAL*)pal->pdata[k];
|
||||
if ((pe->p[0] == p[0]) &&
|
||||
(pe->p[1] == p[1]) &&
|
||||
(pe->p[2] == p[2]))
|
||||
{
|
||||
col[(i*width+j)] = &pe->c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (k == pal->len)
|
||||
{
|
||||
PAL *pe = (PAL*)malloc (sizeof (PAL));
|
||||
|
||||
pe->c.red = (gushort)(p[0]*0xFF);
|
||||
pe->c.green = (gushort)(p[1]*0xFF);
|
||||
pe->c.blue = (gushort)(p[2]*0xFF);
|
||||
gdk_color_alloc (colormap, &pe->c);
|
||||
col[(i*width+j)] = &pe->c;
|
||||
pe->p = p;
|
||||
g_ptr_array_add (pal, pe);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < height; i++)
|
||||
for (j = 0; j < width; j++)
|
||||
{
|
||||
/*
|
||||
c.red = (gushort)(buf[(i*width+j)*3]*0xFF);
|
||||
c.green = (gushort)(buf[(i*width+j)*3+1]*0xFF);
|
||||
c.blue = (gushort)(buf[(i*width+j)*3+2]*0xFF);
|
||||
gdk_color_alloc (colormap, &c);
|
||||
gdk_gc_set_foreground(gc, &c);
|
||||
gdk_draw_point(*pixmap, gc, j, i);
|
||||
*/
|
||||
gdk_gc_set_foreground(gc, col[(i*width+j)]);
|
||||
gdk_draw_point(*pixmap, gc, j, i);
|
||||
}
|
||||
|
||||
free (col);
|
||||
for (k = 0; k < pal->len; k++)
|
||||
free (pal->pdata[k]);
|
||||
g_ptr_array_free (pal, TRUE);
|
||||
|
||||
gdk_gc_destroy (gc);
|
||||
*mask = gdk_pixmap_new (window, width, height, 1);
|
||||
gc = gdk_gc_new (*mask);
|
||||
|
||||
for (i = 0; i < height; i++)
|
||||
for (j = 0; j < width; j++)
|
||||
{
|
||||
GdkColor mask_pattern;
|
||||
|
||||
// pink is transparent
|
||||
if ((buf[(i*width+j)*3] == 0xff) &&
|
||||
(buf[(i*width+j)*3+1] == 0x00) &&
|
||||
(buf[(i*width+j)*3+2] == 0xff))
|
||||
mask_pattern.pixel = 0;
|
||||
else
|
||||
mask_pattern.pixel = 1;
|
||||
|
||||
gdk_gc_set_foreground (gc, &mask_pattern);
|
||||
// possible Win32 Gtk bug here
|
||||
// gdk_draw_point (*mask, gc, j, i);
|
||||
gdk_draw_line (*mask, gc, j, i, j + 1, i);
|
||||
}
|
||||
|
||||
gdk_gc_destroy(gc);
|
||||
free (buf);
|
||||
}
|
||||
|
||||
void CPixMap::load_pixmap (const char* filename, GdkPixmap **gdkpixmap, GdkBitmap **mask)
|
||||
{
|
||||
CString str;
|
||||
|
||||
str = g_strBitmapsPath;
|
||||
str += filename;
|
||||
bmp_to_pixmap (str.GetBuffer (),gdkpixmap, mask);
|
||||
|
||||
if (*gdkpixmap == NULL)
|
||||
{
|
||||
char *dummy[] = { "1 1 1 1", " c None", " " };
|
||||
*gdkpixmap = gdk_pixmap_create_from_xpm_d (GDK_ROOT_PARENT(), mask, NULL, dummy);
|
||||
}
|
||||
}
|
||||
|
||||
// Load a xpm file and return a pixmap widget.
|
||||
GtkWidget* CPixMap::new_pixmap (GtkWidget* widget, char* filename)
|
||||
{
|
||||
GdkPixmap *gdkpixmap;
|
||||
GdkBitmap *mask;
|
||||
GtkWidget *pixmap;
|
||||
|
||||
load_pixmap (filename, &gdkpixmap, &mask);
|
||||
pixmap = gtk_pixmap_new (gdkpixmap, mask);
|
||||
|
||||
gdk_pixmap_unref (gdkpixmap);
|
||||
gdk_pixmap_unref (mask);
|
||||
|
||||
// g_FuncTable.m_pfnLoadBitmap( filename, &pixmap, &mask )
|
||||
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
GtkWidget* CPixMap::pixmap_from_char(GtkWidget *window, gchar **xpm_data)
|
||||
{
|
||||
GdkPixmap *pixmap;
|
||||
GdkBitmap *mask;
|
||||
GtkStyle *style;
|
||||
GtkWidget *widget;
|
||||
|
||||
style = gtk_widget_get_style( window );
|
||||
pixmap = gdk_pixmap_create_from_xpm_d( window->window, &mask,
|
||||
&style->bg[GTK_STATE_NORMAL],
|
||||
(gchar **)xpm_data );
|
||||
|
||||
widget = gtk_pixmap_new( pixmap, mask );
|
||||
|
||||
return widget;
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
// PixMap.h: interface for the CPixMap class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_PIXMAP_H__5B978BDF_7DD1_4BA7_91B5_CCD49AA304AC__INCLUDED_)
|
||||
#define AFX_PIXMAP_H__5B978BDF_7DD1_4BA7_91B5_CCD49AA304AC__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
class CPixMap
|
||||
{
|
||||
public:
|
||||
CPixMap();
|
||||
virtual ~CPixMap();
|
||||
|
||||
static void load_pixmap (const char* filename, GdkPixmap **gdkpixmap, GdkBitmap **mask);
|
||||
static void bmp_to_pixmap (const char* filename, GdkPixmap **pixmap, GdkBitmap **mask);
|
||||
static unsigned char *load_bitmap_file (const char* filename, guint16* width, guint16* height);
|
||||
static GtkWidget *new_pixmap (GtkWidget* parent, char* filename);
|
||||
static GtkWidget* pixmap_from_char(GtkWidget *widget, gchar **xpm_data);
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_PIXMAP_H__5B978BDF_7DD1_4BA7_91B5_CCD49AA304AC__INCLUDED_)
|
|
@ -1,188 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// $LogFile$
|
||||
// $Revision: 1.7 $
|
||||
// $Author: ttimo $
|
||||
// $Date: 2002/05/02 14:41:21 $
|
||||
// $Log: pk3man.cpp,v $
|
||||
// Revision 1.7 2002/05/02 14:41:21 ttimo
|
||||
// fixes for 1.2.7
|
||||
//
|
||||
// Revision 1.6 2002/01/27 22:04:06 ttimo
|
||||
// fixes for linux ver
|
||||
//
|
||||
// Revision 1.5 2002/01/21 18:52:24 ttimo
|
||||
// fixes for 1.2 compile
|
||||
//
|
||||
// Revision 1.4 2001/01/24 22:37:19 mickey
|
||||
// Fixed projects for new radiant layout,
|
||||
// Changes all file/dir dialogs and messageboxs to use radiant interface.
|
||||
//
|
||||
// Revision 1.3 2000/12/22 16:53:28 mickey
|
||||
// fixed to support TA
|
||||
//
|
||||
// Revision 1.2 2000/11/01 14:05:01 lmz
|
||||
// Linux fixes
|
||||
//
|
||||
// Revision 1.1.1.1 2000/10/03 18:36:26 mickey
|
||||
// initial import
|
||||
//
|
||||
// Revision 1.3 2000/10/02 10:22:44 mickey
|
||||
// added rename dialog and some sanity checks for unsaved/modifed pk3's
|
||||
//
|
||||
// Revision 1.2 2000/10/01 20:35:40 mickey
|
||||
// beta stage
|
||||
//
|
||||
// Revision 1.1.1.1 2000/09/26 01:19:38 mickey
|
||||
// initial import of Gtk module
|
||||
//
|
||||
//
|
||||
// DESCRIPTION:
|
||||
// main plugin implementation
|
||||
// texturing tools for Q3Radiant
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "mainwnd.h"
|
||||
|
||||
// plugin interfaces
|
||||
static bool g_bShaderTableInitDone = false;
|
||||
_QERShadersTable g_ShadersTable;
|
||||
|
||||
// Radiant function table
|
||||
_QERFuncTable_1 g_FuncTable;
|
||||
|
||||
bool g_bEpairInitDone = false;
|
||||
#if 0 //mattn
|
||||
_QEREpairsTable g_EpairTable;
|
||||
#endif
|
||||
|
||||
// plugin name
|
||||
const char *PLUGIN_NAME = "Pk3Man";
|
||||
|
||||
// commands in the menu
|
||||
static const char *PLUGIN_COMMANDS = "About...;-;Go...";
|
||||
|
||||
// globals
|
||||
GtkWidget *g_pRadiantWnd=NULL;
|
||||
CMainWnd *g_pMainWnd=NULL;
|
||||
|
||||
CString g_strAppPath;
|
||||
CString g_strBitmapsPath;
|
||||
CString g_strBasePath;
|
||||
CString g_strTempPath;
|
||||
CString g_strModPath; // are we in TeamArena mode?
|
||||
|
||||
#include "version.h"
|
||||
static const char *PLUGIN_ABOUT = "Pk3Man for Q3Radiant\n"
|
||||
"http://pk3man.sourceforge.net\n\n"
|
||||
"Gtk & Original Version\n"
|
||||
"by Mike Jackman (mickey@planetquake.com)\n\n"
|
||||
"Built against GtkRadiant " RADIANT_VERSION "\n"
|
||||
__DATE__;
|
||||
|
||||
extern "C" LPVOID WINAPI QERPlug_GetFuncTable()
|
||||
{
|
||||
return &g_FuncTable;
|
||||
}
|
||||
|
||||
extern "C" LPCSTR WINAPI QERPlug_Init(HMODULE hApp, GtkWidget* pMainWidget)
|
||||
{
|
||||
g_pRadiantWnd = pMainWidget;
|
||||
memset(&g_FuncTable, 0, sizeof(_QERFuncTable_1));
|
||||
g_FuncTable.m_nSize = sizeof(_QERFuncTable_1);
|
||||
|
||||
return "Pk3Man for GTKRadiant";
|
||||
}
|
||||
|
||||
extern "C" LPCSTR WINAPI QERPlug_GetName()
|
||||
{
|
||||
return (char*)PLUGIN_NAME;
|
||||
}
|
||||
|
||||
extern "C" LPCSTR WINAPI QERPlug_GetCommandList()
|
||||
{
|
||||
return (char*)PLUGIN_COMMANDS;
|
||||
}
|
||||
|
||||
char *TranslateString (char *buf)
|
||||
{
|
||||
static char buf2[32768];
|
||||
int i, l;
|
||||
char *out;
|
||||
|
||||
l = strlen(buf);
|
||||
out = buf2;
|
||||
for (i=0 ; i<l ; i++)
|
||||
{
|
||||
if (buf[i] == '\n')
|
||||
{
|
||||
*out++ = '\r';
|
||||
*out++ = '\n';
|
||||
}
|
||||
else
|
||||
*out++ = buf[i];
|
||||
}
|
||||
|
||||
*out++ = 0;
|
||||
return buf2;
|
||||
}
|
||||
|
||||
/*
|
||||
extern "C" void Sys_Printf (char *text, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
char buf[32768];
|
||||
char *out;
|
||||
|
||||
va_start (argptr,text);
|
||||
vsprintf (buf, text,argptr);
|
||||
va_end (argptr);
|
||||
|
||||
//out = TranslateString (buf);
|
||||
|
||||
g_FuncTable.m_pfnSysMsg ( buf );
|
||||
}
|
||||
*/
|
||||
|
||||
extern "C" void WINAPI QERPlug_Dispatch (LPCSTR p, vec3_t vMin, vec3_t vMax, bool bSingleBrush)
|
||||
{
|
||||
if (!g_bShaderTableInitDone)
|
||||
{
|
||||
g_ShadersTable.m_nSize = sizeof (_QERShadersTable);
|
||||
if ( g_FuncTable.m_pfnRequestInterface( QERShadersTable_GUID, static_cast<LPVOID>(&g_ShadersTable) ) )
|
||||
{
|
||||
g_bShaderTableInitDone = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Sys_Printf("Pk3Man plugin: _QERShadersTable interface request failed\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0 //mattn
|
||||
if (!g_bEpairInitDone)
|
||||
{
|
||||
g_EpairTable.m_nSize = sizeof(_QEREpairsTable);
|
||||
if ( g_FuncTable.m_pfnRequestInterface( QEREpairsTable_GUID, static_cast<LPVOID>(&g_EpairTable) ) )
|
||||
g_bEpairInitDone = true;
|
||||
else
|
||||
{
|
||||
Sys_Printf("Pk3Man plugin: _QEREpairsTable interface request failed\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!strcmp(p, "About..."))
|
||||
{
|
||||
g_FuncTable.m_pfnMessageBox(g_pRadiantWnd,PLUGIN_ABOUT,"About ...",MB_OK, NULL);
|
||||
}
|
||||
else if (!strcmp(p, "Go..."))
|
||||
{
|
||||
Sys_Printf ("Pk3Man starting ...\n");
|
||||
g_pMainWnd = new CMainWnd ();
|
||||
g_pMainWnd->Create (g_pRadiantWnd);
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
; Pk3Man.def : Declares the module parameters for the DLL.
|
||||
|
||||
LIBRARY "Pk3Man"
|
||||
DESCRIPTION 'Pk3Man Windows Dynamic Link Library'
|
||||
|
||||
EXPORTS
|
||||
; Explicit exports can go here
|
||||
QERPlug_Init @1
|
||||
QERPlug_GetName @2
|
||||
QERPlug_GetCommandList @3
|
||||
QERPlug_Dispatch @4
|
||||
QERPlug_GetFuncTable @5
|
|
@ -1,32 +0,0 @@
|
|||
// pk3man exclusion file
|
||||
// (c) Mike Jackman 2000
|
||||
//
|
||||
// All files listed below will
|
||||
// be excluded by the wizzard
|
||||
|
||||
|
||||
pak?.pk3
|
||||
|
||||
scripts/base_door.shader
|
||||
scripts/base_floor.shader
|
||||
scripts/base_light.shader
|
||||
scripts/base_object.shader
|
||||
scripts/base_support.shader
|
||||
scripts/base_trim.shader
|
||||
scripts/base_wall.shader
|
||||
scripts/common.shader
|
||||
scripts/ctf.shader
|
||||
scripts/gothic_block.shader
|
||||
scripts/gothic_button.shader
|
||||
scripts/gothic_door.shader
|
||||
scripts/gothic_floor.shader
|
||||
scripts/gothic_light.shader
|
||||
scripts/gothic_trim.shader
|
||||
scripts/gothic_wall.shader
|
||||
scripts/liquid.shader
|
||||
scripts/organics.shader
|
||||
scripts/sfx.shader
|
||||
scripts/skin.shader
|
||||
scripts/sky.shader
|
||||
|
||||
|
|
@ -1,101 +0,0 @@
|
|||
<?xml version="1.0" ?><VisualStudioProject Name="pk3man" ProjectGUID="{65D02375-63EE-4A8A-9F8E-504B1D5A1D02}" ProjectType="Visual C++" RootNamespace="pk3mank" Version="8.00">
|
||||
<Platforms>
|
||||
<Platform Name="Win32"/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration CharacterSet="2" ConfigurationType="1" IntermediateDirectory="$(ConfigurationName)" Name="Debug|Win32" OutputDirectory="$(SolutionDir)$(ConfigurationName)">
|
||||
<Tool Name="VCPreBuildEventTool"/>
|
||||
<Tool Name="VCCustomBuildTool"/>
|
||||
<Tool Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool Name="VCMIDLTool"/>
|
||||
<Tool AdditionalIncludeDirectories=""$(SolutionDir)\include";"$(SolutionDir)\libs";"$(SolutionDir)\..\STLPort\stlport";"$(SolutionDir)\..\gtk2\include";"$(SolutionDir)\..\gtk2\include\glib-2.0";"$(SolutionDir)\..\gtk2\lib\glib-2.0\include";"$(SolutionDir)\..\libxml2\include"" BasicRuntimeChecks="3" DebugInformationFormat="4" Detect64BitPortabilityProblems="true" DisableSpecificWarnings="4996;4244;4267" MinimalRebuild="true" Name="VCCLCompilerTool" Optimization="0" PreprocessorDefinitions="_CRT_SECURE_NO_WARNINGS" RuntimeLibrary="3" WarningLevel="3"/>
|
||||
<Tool Name="VCManagedResourceCompilerTool"/>
|
||||
<Tool Name="VCResourceCompilerTool"/>
|
||||
<Tool Name="VCPreLinkEventTool"/>
|
||||
<Tool GenerateDebugInformation="true" Name="VCLinkerTool" TargetMachine="1"/>
|
||||
<Tool Name="VCALinkTool"/>
|
||||
<Tool Name="VCManifestTool"/>
|
||||
<Tool Name="VCXDCMakeTool"/>
|
||||
<Tool Name="VCBscMakeTool"/>
|
||||
<Tool Name="VCFxCopTool"/>
|
||||
<Tool Name="VCAppVerifierTool"/>
|
||||
<Tool Name="VCWebDeploymentTool"/>
|
||||
<Tool Name="VCPostBuildEventTool"/>
|
||||
</Configuration>
|
||||
<Configuration CharacterSet="2" ConfigurationType="1" IntermediateDirectory="$(ConfigurationName)" Name="Release|Win32" OutputDirectory="$(SolutionDir)$(ConfigurationName)" WholeProgramOptimization="1">
|
||||
<Tool Name="VCPreBuildEventTool"/>
|
||||
<Tool Name="VCCustomBuildTool"/>
|
||||
<Tool Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool Name="VCMIDLTool"/>
|
||||
<Tool AdditionalIncludeDirectories=""$(SolutionDir)\include";"$(SolutionDir)\libs";"$(SolutionDir)\..\STLPort\stlport";"$(SolutionDir)\..\gtk2\include";"$(SolutionDir)\..\gtk2\include\glib-2.0";"$(SolutionDir)\..\gtk2\lib\glib-2.0\include";"$(SolutionDir)\..\libxml2\include"" DebugInformationFormat="3" Detect64BitPortabilityProblems="true" DisableSpecificWarnings="4996;4244;4267" Name="VCCLCompilerTool" PreprocessorDefinitions="_CRT_SECURE_NO_WARNINGS" RuntimeLibrary="2" WarningLevel="3"/>
|
||||
<Tool Name="VCManagedResourceCompilerTool"/>
|
||||
<Tool Name="VCResourceCompilerTool"/>
|
||||
<Tool Name="VCPreLinkEventTool"/>
|
||||
<Tool EnableCOMDATFolding="2" GenerateDebugInformation="true" Name="VCLinkerTool" OptimizeReferences="2" TargetMachine="1"/>
|
||||
<Tool Name="VCALinkTool"/>
|
||||
<Tool Name="VCManifestTool"/>
|
||||
<Tool Name="VCXDCMakeTool"/>
|
||||
<Tool Name="VCBscMakeTool"/>
|
||||
<Tool Name="VCFxCopTool"/>
|
||||
<Tool Name="VCAppVerifierTool"/>
|
||||
<Tool Name="VCWebDeploymentTool"/>
|
||||
<Tool Name="VCPostBuildEventTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" Name="Source Files">
|
||||
<File RelativePath=".\mainwnd.cpp">
|
||||
</File>
|
||||
<File RelativePath=".\memfile.cpp">
|
||||
</File>
|
||||
<File RelativePath=".\pak.cpp">
|
||||
</File>
|
||||
<File RelativePath=".\pixmap.cpp">
|
||||
</File>
|
||||
<File RelativePath=".\pk3man.cpp">
|
||||
</File>
|
||||
<File RelativePath=".\pk3man.def">
|
||||
</File>
|
||||
<File RelativePath=".\renamedlg.cpp">
|
||||
</File>
|
||||
<File RelativePath=".\stdafx.cpp">
|
||||
</File>
|
||||
<File RelativePath=".\tree.cpp">
|
||||
</File>
|
||||
<File RelativePath=".\wild.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter Filter="h;hpp;hxx;hm;inl" Name="Header Files">
|
||||
<File RelativePath=".\mainwnd.h">
|
||||
</File>
|
||||
<File RelativePath=".\md3.h">
|
||||
</File>
|
||||
<File RelativePath=".\memfile.h">
|
||||
</File>
|
||||
<File RelativePath=".\pak.h">
|
||||
</File>
|
||||
<File RelativePath=".\pixmap.h">
|
||||
</File>
|
||||
<File RelativePath=".\pk3str.h">
|
||||
</File>
|
||||
<File RelativePath=".\renamedlg.h">
|
||||
</File>
|
||||
<File RelativePath=".\stdafx.h">
|
||||
</File>
|
||||
<File RelativePath=".\tree.h">
|
||||
</File>
|
||||
<File RelativePath=".\wild.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" Name="Resource Files">
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
|
@ -1,46 +0,0 @@
|
|||
Pk3Man
|
||||
------
|
||||
|
||||
Pk3Man is a plugin for Q3Radiant (GtkEdition).
|
||||
It allows the creation and editing of Q3 Pk3 files
|
||||
from within the Q3Radiant Editor.
|
||||
|
||||
It does NOT operate in the same way as WinZip so ill
|
||||
try to documented the differences here. Please read these
|
||||
before emailing me with suggestions or problems.
|
||||
|
||||
***************************************************************
|
||||
|
||||
1. Any modified or newly created Pk3 is only committed to disk,
|
||||
when you save.
|
||||
|
||||
2. Pk3Man uses your current base folder set in Q3Radiant (ie. BaseQ3)
|
||||
and adds files using there current path relative to this. This means
|
||||
that when you have finished your map, you just add the required files,
|
||||
and their paths are automatically correct (if they were in the correct place for
|
||||
Q3 to start with)
|
||||
|
||||
4. You can change the stored path of a file using the rename option. Rename
|
||||
the file with its full new relative path and name.
|
||||
|
||||
5. The wizzard will scan a .map file and add any textures/sounds/env maps e.t.c that
|
||||
are referenced, except those in the exclusion list.
|
||||
|
||||
6. files that have been added (and not saved) are shown with an appending * in the
|
||||
statusbar when selected.
|
||||
|
||||
7. The exclusion list applies to Pk3's and to individual files. eg 'pak?.pk3' would
|
||||
eliminate all ID pk3's, and 'textures/mickey/*.tga' would eliminate all tga's in
|
||||
a sub folder of textures called 'mickey'
|
||||
|
||||
|
||||
************************************************************
|
||||
|
||||
Please email and bugs/suggestions to me here : mickey@planetquake.com
|
||||
|
||||
|
||||
------------------------------------------------------------------------
|
||||
Remember this is a beta. I hold no responsibility for any damage done to
|
||||
files on your computer due to the action of this plugin.
|
||||
-------------------------------------------------------------------------
|
||||
|
|
@ -1,395 +0,0 @@
|
|||
#ifndef __STR__
|
||||
#define __STR__
|
||||
//
|
||||
// class Str
|
||||
// loose replacement for CString from MFC
|
||||
//
|
||||
//#include "cmdlib.h"
|
||||
//#include <glib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#define strcasecmp strcmpi
|
||||
#endif
|
||||
|
||||
//char* __StrDup(char* pStr);
|
||||
//char* __StrDup(const char* pStr);
|
||||
|
||||
#define __StrDup strdup
|
||||
|
||||
#ifdef __linux__
|
||||
#define strcmpi strcasecmp
|
||||
#define stricmp strcasecmp
|
||||
#define strnicmp strncasecmp
|
||||
|
||||
inline char* strlwr(char* string)
|
||||
{
|
||||
char *cp;
|
||||
for (cp = string; *cp; ++cp)
|
||||
{
|
||||
if ('A' <= *cp && *cp <= 'Z')
|
||||
*cp += 'a' - 'A';
|
||||
}
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
inline char* strupr(char* string)
|
||||
{
|
||||
char *cp;
|
||||
for (cp = string; *cp; ++cp)
|
||||
{
|
||||
if ('a' <= *cp && *cp <= 'z')
|
||||
*cp += 'A' - 'a';
|
||||
}
|
||||
|
||||
return string;
|
||||
}
|
||||
#endif
|
||||
|
||||
static char *g_pStrWork = NULL;
|
||||
|
||||
class Str
|
||||
{
|
||||
protected:
|
||||
bool m_bIgnoreCase;
|
||||
char *m_pStr;
|
||||
|
||||
public:
|
||||
Str()
|
||||
{
|
||||
m_bIgnoreCase = true;
|
||||
m_pStr = new char[1];
|
||||
m_pStr[0] = '\0';
|
||||
}
|
||||
|
||||
Str(char *p)
|
||||
{
|
||||
m_bIgnoreCase = true;
|
||||
m_pStr = __StrDup(p);
|
||||
}
|
||||
|
||||
Str(const char *p)
|
||||
{
|
||||
m_bIgnoreCase = true;
|
||||
m_pStr = __StrDup(p);
|
||||
}
|
||||
|
||||
Str(const char c)
|
||||
{
|
||||
m_bIgnoreCase = true;
|
||||
m_pStr = new char[2];
|
||||
m_pStr[0] = c;
|
||||
m_pStr[1] = '\0';
|
||||
}
|
||||
|
||||
void Deallocate()
|
||||
{
|
||||
delete []m_pStr;
|
||||
m_pStr = NULL;
|
||||
}
|
||||
|
||||
void Allocate(int n)
|
||||
{
|
||||
Deallocate();
|
||||
m_pStr = new char[n];
|
||||
}
|
||||
|
||||
const char* GetBuffer()
|
||||
{
|
||||
return m_pStr;
|
||||
}
|
||||
|
||||
void MakeEmpty()
|
||||
{
|
||||
Deallocate();
|
||||
m_pStr = __StrDup("");
|
||||
}
|
||||
|
||||
~Str()
|
||||
{
|
||||
Deallocate();
|
||||
delete []g_pStrWork;
|
||||
g_pStrWork = NULL;
|
||||
}
|
||||
|
||||
void MakeLower()
|
||||
{
|
||||
if (m_pStr)
|
||||
{
|
||||
strlwr(m_pStr);
|
||||
}
|
||||
}
|
||||
|
||||
void MakeUpper()
|
||||
{
|
||||
if (m_pStr)
|
||||
{
|
||||
strupr(m_pStr);
|
||||
}
|
||||
}
|
||||
|
||||
void TrimRight()
|
||||
{
|
||||
char* lpsz = m_pStr;
|
||||
char* lpszLast = NULL;
|
||||
while (*lpsz != '\0')
|
||||
{
|
||||
if (isspace(*lpsz))
|
||||
{
|
||||
if (lpszLast == NULL)
|
||||
lpszLast = lpsz;
|
||||
}
|
||||
else
|
||||
lpszLast = NULL;
|
||||
lpsz++;
|
||||
}
|
||||
|
||||
if (lpszLast != NULL)
|
||||
{
|
||||
// truncate at trailing space start
|
||||
*lpszLast = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
void TrimLeft()
|
||||
{
|
||||
// find first non-space character
|
||||
char* lpsz = m_pStr;
|
||||
while (isspace(*lpsz))
|
||||
lpsz++;
|
||||
|
||||
// fix up data and length
|
||||
int nDataLength = GetLength() - (lpsz - m_pStr);
|
||||
memmove(m_pStr, lpsz, (nDataLength+1));
|
||||
}
|
||||
|
||||
int Find(const char *p)
|
||||
{
|
||||
char *pf = strstr(m_pStr, p);
|
||||
return (pf) ? (pf - m_pStr) : -1;
|
||||
}
|
||||
|
||||
// search starting at a given offset
|
||||
int Find(const char *p, int offset)
|
||||
{
|
||||
char *pf = strstr(m_pStr+offset, p);
|
||||
return (pf) ? (pf - m_pStr) : -1;
|
||||
}
|
||||
|
||||
int Find(const char ch)
|
||||
{
|
||||
char *pf = strchr (m_pStr, ch);
|
||||
return (pf) ? (pf - m_pStr) : -1;
|
||||
}
|
||||
|
||||
int ReverseFind(const char ch)
|
||||
{
|
||||
char *pf = strrchr(m_pStr, ch);
|
||||
return (pf) ? (pf - m_pStr) : -1;
|
||||
}
|
||||
|
||||
int CompareNoCase (const char* str) const
|
||||
{
|
||||
return strcasecmp (m_pStr, str);
|
||||
}
|
||||
|
||||
int GetLength()
|
||||
{
|
||||
return (m_pStr) ? strlen(m_pStr) : 0;
|
||||
}
|
||||
|
||||
const char* Left(int n)
|
||||
{
|
||||
delete []g_pStrWork;
|
||||
if (n > 0)
|
||||
{
|
||||
g_pStrWork = new char[n+1];
|
||||
strncpy(g_pStrWork, m_pStr, n);
|
||||
g_pStrWork[n] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
g_pStrWork = "";
|
||||
g_pStrWork = new char[1];
|
||||
g_pStrWork[0] = '\0';
|
||||
}
|
||||
return g_pStrWork;
|
||||
}
|
||||
|
||||
const char* Right(int n)
|
||||
{
|
||||
delete []g_pStrWork;
|
||||
if (n > 0)
|
||||
{
|
||||
g_pStrWork = new char[n+1];
|
||||
int nStart = GetLength() - n;
|
||||
strncpy(g_pStrWork, &m_pStr[nStart], n);
|
||||
g_pStrWork[n] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
g_pStrWork = new char[1];
|
||||
g_pStrWork[0] = '\0';
|
||||
}
|
||||
return g_pStrWork;
|
||||
}
|
||||
|
||||
const char* Mid(int nFirst) const
|
||||
{
|
||||
return Mid(nFirst, strlen (m_pStr) - nFirst);
|
||||
}
|
||||
|
||||
const char* Mid(int first, int n) const
|
||||
{
|
||||
delete []g_pStrWork;
|
||||
if (n > 0)
|
||||
{
|
||||
g_pStrWork = new char[n+1];
|
||||
strncpy(g_pStrWork, m_pStr+first, n);
|
||||
g_pStrWork[n] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
g_pStrWork = "";
|
||||
g_pStrWork = new char[1];
|
||||
g_pStrWork[0] = '\0';
|
||||
}
|
||||
return g_pStrWork;
|
||||
}
|
||||
|
||||
#ifdef __G_LIB_H__
|
||||
void Format(const char* fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
char *buffer;
|
||||
|
||||
va_start (args, fmt);
|
||||
buffer = g_strdup_vprintf (fmt, args);
|
||||
va_end (args);
|
||||
|
||||
delete[] m_pStr;
|
||||
m_pStr = __StrDup(buffer);
|
||||
g_free (buffer);
|
||||
}
|
||||
#else
|
||||
void Format(const char* fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
m_pStr = new char[1024];
|
||||
|
||||
va_start (args, fmt);
|
||||
vsprintf (m_pStr, fmt, args);
|
||||
va_end (args);
|
||||
}
|
||||
#endif
|
||||
|
||||
void SetAt(int n, char ch)
|
||||
{
|
||||
if (n >= 0 && n < GetLength ())
|
||||
m_pStr[n] = ch;
|
||||
}
|
||||
|
||||
// NOTE: unlike CString, this looses the pointer
|
||||
void ReleaseBuffer(int n = -1)
|
||||
{
|
||||
if (n == -1)
|
||||
n = GetLength ();
|
||||
|
||||
char* tmp = m_pStr;
|
||||
tmp[n] = '\0';
|
||||
m_pStr = __StrDup(tmp);
|
||||
delete []tmp;
|
||||
}
|
||||
|
||||
char* GetBufferSetLength(int n)
|
||||
{
|
||||
if (n < 0)
|
||||
n = 0;
|
||||
|
||||
char *p = new char[n+1];
|
||||
strncpy (p, m_pStr, n);
|
||||
p[n] = '\0';
|
||||
delete []m_pStr;
|
||||
m_pStr = p;
|
||||
return m_pStr;
|
||||
}
|
||||
|
||||
// char& operator *() { return *m_pStr; }
|
||||
// char& operator *() const { return *const_cast<Str*>(this)->m_pStr; }
|
||||
operator void*() { return m_pStr; }
|
||||
operator char*() { return m_pStr; }
|
||||
operator const char*(){ return reinterpret_cast<const char*>(m_pStr); }
|
||||
operator unsigned char*() { return reinterpret_cast<unsigned char*>(m_pStr); }
|
||||
operator const unsigned char*() { return reinterpret_cast<const unsigned char*>(m_pStr); }
|
||||
Str& operator =(const Str& rhs)
|
||||
{
|
||||
if (&rhs != this)
|
||||
{
|
||||
delete[] m_pStr;
|
||||
m_pStr = __StrDup(rhs.m_pStr);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Str& operator =(const char* pStr)
|
||||
{
|
||||
if (m_pStr != pStr)
|
||||
{
|
||||
delete[] m_pStr;
|
||||
m_pStr = __StrDup(pStr);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Str& operator +=(const char ch)
|
||||
{
|
||||
int len = GetLength ();
|
||||
char *p = new char[len + 1 + 1];
|
||||
|
||||
if (m_pStr)
|
||||
{
|
||||
strcpy(p, m_pStr);
|
||||
delete[] m_pStr;
|
||||
}
|
||||
|
||||
m_pStr = p;
|
||||
m_pStr[len] = ch;
|
||||
m_pStr[len+1] = '\0';
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Str& operator +=(const char *pStr)
|
||||
{
|
||||
if (pStr)
|
||||
{
|
||||
if (m_pStr)
|
||||
{
|
||||
char *p = new char[strlen(m_pStr) + strlen(pStr) + 1];
|
||||
strcpy(p, m_pStr);
|
||||
strcat(p, pStr);
|
||||
delete[] m_pStr;
|
||||
m_pStr = p;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pStr = __StrDup(pStr);
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator ==(const Str& rhs) const { return (m_bIgnoreCase) ? stricmp(m_pStr, rhs.m_pStr) == 0 : strcmp(m_pStr, rhs.m_pStr) == 0; }
|
||||
bool operator ==(char* pStr) const { return (m_bIgnoreCase) ? stricmp(m_pStr, pStr) == 0 : strcmp(m_pStr, pStr) == 0; }
|
||||
bool operator ==(const char* pStr) const { return (m_bIgnoreCase) ? stricmp(m_pStr, pStr) == 0 : strcmp(m_pStr, pStr) == 0; }
|
||||
bool operator !=(Str& rhs) const { return (m_bIgnoreCase) ? stricmp(m_pStr, rhs.m_pStr) != 0 : strcmp(m_pStr, rhs.m_pStr) != 0; }
|
||||
bool operator !=(char* pStr) const { return (m_bIgnoreCase) ? stricmp(m_pStr, pStr) != 0 : strcmp(m_pStr, pStr) != 0; }
|
||||
bool operator !=(const char* pStr) const { return (m_bIgnoreCase) ? stricmp(m_pStr, pStr) != 0 : strcmp(m_pStr, pStr) != 0; }
|
||||
char& operator [](int nIndex) { return m_pStr[nIndex]; }
|
||||
char& operator [](int nIndex) const { return m_pStr[nIndex]; }
|
||||
const char GetAt (int nIndex) { return m_pStr[nIndex]; }
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,113 +0,0 @@
|
|||
// RenameDlg.cpp: implementation of the CRenameDlg class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "renamedlg.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void rename_dialog_button_callback (GtkWidget *widget, gpointer data)
|
||||
{
|
||||
GtkWidget *parent;
|
||||
int *loop, *ret;
|
||||
|
||||
parent = gtk_widget_get_toplevel (widget);
|
||||
loop = (int*)gtk_object_get_data (GTK_OBJECT (parent), "loop");
|
||||
ret = (int*)gtk_object_get_data (GTK_OBJECT (parent), "ret");
|
||||
|
||||
*loop = 0;
|
||||
*ret = (int)data;
|
||||
}
|
||||
|
||||
static gint rename_dialog_delete_callback (GtkWidget *widget, GdkEvent* event, gpointer data)
|
||||
{
|
||||
int *loop;
|
||||
|
||||
gtk_widget_hide (widget);
|
||||
loop = (int*)gtk_object_get_data (GTK_OBJECT (widget), "loop");
|
||||
*loop = 0;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CRenameDlg::CRenameDlg()
|
||||
{
|
||||
m_Name="foo";
|
||||
}
|
||||
|
||||
CRenameDlg::~CRenameDlg()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CRenameDlg::DoModal()
|
||||
{
|
||||
GtkWidget *window, *w, *vbox, *hbox, *edit;
|
||||
int ret, loop = 1;
|
||||
char *lpCaption="Rename File";
|
||||
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
|
||||
GTK_SIGNAL_FUNC (rename_dialog_delete_callback), NULL);
|
||||
gtk_signal_connect (GTK_OBJECT (window), "destroy",
|
||||
GTK_SIGNAL_FUNC (gtk_widget_destroy), NULL);
|
||||
gtk_window_set_title (GTK_WINDOW (window), lpCaption);
|
||||
gtk_container_border_width (GTK_CONTAINER (window), 10);
|
||||
gtk_object_set_data (GTK_OBJECT (window), "loop", &loop);
|
||||
gtk_object_set_data (GTK_OBJECT (window), "ret", &ret);
|
||||
gtk_widget_realize (window);
|
||||
|
||||
vbox = gtk_vbox_new (FALSE, 10);
|
||||
gtk_container_add (GTK_CONTAINER (window), vbox);
|
||||
gtk_widget_show (vbox);
|
||||
|
||||
edit = gtk_entry_new ();
|
||||
gtk_entry_set_text(GTK_ENTRY(edit),m_Name.c_str());
|
||||
gtk_box_pack_start (GTK_BOX (vbox), edit, FALSE, FALSE, 2);
|
||||
gtk_widget_show (edit);
|
||||
|
||||
w = gtk_hseparator_new ();
|
||||
gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 2);
|
||||
gtk_widget_show (w);
|
||||
|
||||
hbox = gtk_hbox_new (FALSE, 10);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 2);
|
||||
gtk_widget_show (hbox);
|
||||
|
||||
// buttons
|
||||
|
||||
w = gtk_button_new_with_label ("Ok");
|
||||
gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0);
|
||||
gtk_signal_connect (GTK_OBJECT (w), "clicked",
|
||||
GTK_SIGNAL_FUNC (rename_dialog_button_callback), GINT_TO_POINTER (IDOK));
|
||||
GTK_WIDGET_SET_FLAGS (w, GTK_CAN_DEFAULT);
|
||||
gtk_widget_grab_default (w);
|
||||
gtk_widget_show (w);
|
||||
|
||||
w = gtk_button_new_with_label ("Cancel");
|
||||
gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0);
|
||||
gtk_signal_connect (GTK_OBJECT (w), "clicked",
|
||||
GTK_SIGNAL_FUNC (rename_dialog_button_callback), GINT_TO_POINTER (IDCANCEL));
|
||||
gtk_widget_show (w);
|
||||
ret = IDCANCEL;
|
||||
|
||||
// show it
|
||||
|
||||
gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
|
||||
gtk_widget_show (window);
|
||||
gtk_grab_add (window);
|
||||
|
||||
while (loop)
|
||||
gtk_main_iteration ();
|
||||
|
||||
m_Name=gtk_entry_get_text(GTK_ENTRY(edit));
|
||||
|
||||
gtk_grab_remove (window);
|
||||
gtk_widget_destroy (window);
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
// RenameDlg.h: interface for the CRenameDlg class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_RENAMEDLG_H__6BF675B2_311E_42EE_A926_C52EA685EA75__INCLUDED_)
|
||||
#define AFX_RENAMEDLG_H__6BF675B2_311E_42EE_A926_C52EA685EA75__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include <string>
|
||||
|
||||
class CRenameDlg
|
||||
{
|
||||
public:
|
||||
CRenameDlg();
|
||||
virtual ~CRenameDlg();
|
||||
|
||||
std::string m_Name;
|
||||
|
||||
int DoModal();
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_RENAMEDLG_H__6BF675B2_311E_42EE_A926_C52EA685EA75__INCLUDED_)
|
|
@ -1,8 +0,0 @@
|
|||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// pk3man.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: reference any additional headers you need in STDAFX.H
|
||||
// and not in this file
|
|
@ -1,141 +0,0 @@
|
|||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently, but
|
||||
// are changed infrequently
|
||||
//
|
||||
|
||||
#if !defined(AFX_STDAFX_H__214D7491_03C8_444D_AAEB_73A8A21B84CB__INCLUDED_)
|
||||
#define AFX_STDAFX_H__214D7491_03C8_444D_AAEB_73A8A21B84CB__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#define GTK_ENABLE_BROKEN
|
||||
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "pk3str.h"
|
||||
#include "pixmap.h"
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
#include <GL/glx.h>
|
||||
|
||||
typedef void* HMODULE;
|
||||
typedef void* LPVOID;
|
||||
typedef int BOOL;
|
||||
typedef char* LPCSTR;
|
||||
|
||||
#define MB_OK 0x00000000L
|
||||
#define MB_OKCANCEL 0x00000001L
|
||||
#define MB_ABORTRETRYIGNORE 0x00000002L
|
||||
#define MB_YESNOCANCEL 0x00000003L
|
||||
#define MB_YESNO 0x00000004L
|
||||
#define MB_RETRYCANCEL 0x00000005L
|
||||
|
||||
|
||||
#define MB_ICONHAND 0x00000010L
|
||||
#define MB_ICONQUESTION 0x00000020L
|
||||
#define MB_ICONEXCLAMATION 0x00000030L
|
||||
#define MB_ICONASTERISK 0x00000040L
|
||||
|
||||
#define MB_USERICON 0x00000080L
|
||||
#define MB_ICONWARNING MB_ICONEXCLAMATION
|
||||
#define MB_ICONERROR MB_ICONHAND
|
||||
#define MB_ICONINFORMATION MB_ICONASTERISK
|
||||
#define MB_ICONSTOP MB_ICONHAND
|
||||
|
||||
#define MB_TYPEMASK 0x0000000FL
|
||||
#define MB_ICONMASK 0x000000F0L
|
||||
#define MB_DEFMASK 0x00000F00L
|
||||
#define MB_MODEMASK 0x00003000L
|
||||
#define MB_MISCMASK 0x0000C000L
|
||||
|
||||
#define IDOK 1
|
||||
#define IDCANCEL 2
|
||||
#define IDABORT 3
|
||||
#define IDRETRY 4
|
||||
#define IDIGNORE 5
|
||||
#define IDYES 6
|
||||
#define IDNO 7
|
||||
|
||||
#define WINAPI
|
||||
|
||||
#ifndef GUID_DEFINED
|
||||
#define GUID_DEFINED
|
||||
typedef struct _GUID
|
||||
{
|
||||
unsigned long Data1;
|
||||
unsigned short Data2;
|
||||
unsigned short Data3;
|
||||
unsigned char Data4[8];
|
||||
} GUID;
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#ifndef _REFGUID_DEFINED
|
||||
#define _REFGUID_DEFINED
|
||||
#define REFGUID const GUID &
|
||||
#endif // !_REFGUID_DEFINED
|
||||
#endif
|
||||
|
||||
typedef struct tagRECT
|
||||
{
|
||||
long left;
|
||||
long top;
|
||||
long right;
|
||||
long bottom;
|
||||
} RECT, *PRECT, *LPRECT;
|
||||
|
||||
#endif // __linux__
|
||||
|
||||
#include "qerplugin.h"
|
||||
#include "igl.h"
|
||||
#include "iselectedface.h"
|
||||
#include "isurfaceplugin.h"
|
||||
#include "ishaders.h"
|
||||
#if 0 //mattn
|
||||
#include "iepairs.h"
|
||||
#endif
|
||||
|
||||
extern _QERFuncTable_1 g_FuncTable;
|
||||
extern _QERShadersTable g_ShadersTable;
|
||||
#if 0 //mattn
|
||||
extern _QEREpairsTable g_EpairTable;
|
||||
#endif
|
||||
#define Sys_Printf g_FuncTable.m_pfnSysPrintf
|
||||
#define Sys_FPrintf g_FuncTable.m_pfnSysFPrintf
|
||||
|
||||
#define CString Str
|
||||
extern CString g_strBitmapsPath;
|
||||
extern CString g_strBasePath;
|
||||
extern CString g_strTempPath;
|
||||
extern CString g_strAppPath;
|
||||
extern CString g_strModPath;
|
||||
|
||||
|
||||
//extern int DoMessageBox (const char* lpText, const char* lpCaption, guint32 uType);
|
||||
|
||||
#define ID_FILE_OPEN 10000
|
||||
#define ID_FILE_SAVE 10001
|
||||
#define ID_FILE_NEW 10002
|
||||
#define ID_WIZARD 10003
|
||||
#define ID_VIEW 10004
|
||||
#define ID_EXTRACT 10005
|
||||
#define ID_ADD 10006
|
||||
#define ID_RENAME 10007
|
||||
#define ID_DELETE 10008
|
||||
#define ID_SPARE 10009
|
||||
|
||||
#ifndef __linux__
|
||||
#pragma warning(disable : 4786)
|
||||
#endif
|
||||
|
||||
// TODO: reference additional headers your program requires here
|
||||
|
||||
//{{AFX_INSERT_LOCATION}}
|
||||
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
|
||||
|
||||
#endif // !defined(AFX_STDAFX_H__214D7491_03C8_444D_AAEB_73A8A21B84CB__INCLUDED_)
|
|
@ -1,271 +0,0 @@
|
|||
// tree.cpp: implementation of the CTree class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "tree.h"
|
||||
#include <string>
|
||||
#include "mainwnd.h"
|
||||
|
||||
extern CMainWnd *g_pMainWnd;
|
||||
|
||||
|
||||
static void button_release (GtkWidget *widget, GdkEventButton *event, gpointer data)
|
||||
{
|
||||
if (event->button==3)
|
||||
g_pMainWnd->HandleDrop();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CTree::CTree()
|
||||
{
|
||||
m_Tree=NULL;
|
||||
m_Root=NULL;
|
||||
|
||||
}
|
||||
|
||||
CTree::~CTree()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CTree::Init(GtkWidget *win)
|
||||
{
|
||||
m_pMainWnd=win;
|
||||
|
||||
// create the tree
|
||||
m_Tree=gtk_tree_new();
|
||||
|
||||
// Add tree to passed scroll window
|
||||
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(win),(GtkWidget*)m_Tree);
|
||||
|
||||
// Show it
|
||||
gtk_widget_show(m_Tree);
|
||||
|
||||
// connect signal
|
||||
gtk_signal_connect (GTK_OBJECT(m_Tree), "select_child",
|
||||
GTK_SIGNAL_FUNC(cb_select_child), m_Tree);
|
||||
|
||||
// create the root item
|
||||
GtkWidget *item=gtk_tree_item_new_with_label("root");
|
||||
gtk_tree_append(GTK_TREE(m_Tree),item);
|
||||
gtk_widget_show(item);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (item), "button_release_event",GTK_SIGNAL_FUNC (button_release), NULL);
|
||||
|
||||
m_Root=gtk_tree_new();
|
||||
gtk_tree_item_set_subtree(GTK_TREE_ITEM(item),m_Root);
|
||||
gtk_tree_item_expand(GTK_TREE_ITEM(item));
|
||||
|
||||
|
||||
// connect signal
|
||||
gtk_signal_connect (GTK_OBJECT(m_Root), "select_child",
|
||||
GTK_SIGNAL_FUNC(cb_select_child), m_Tree);
|
||||
|
||||
// ok were done
|
||||
return;
|
||||
}
|
||||
|
||||
void CTree::Clear()
|
||||
{
|
||||
gtk_widget_destroy(m_Tree);
|
||||
Init(m_pMainWnd);
|
||||
}
|
||||
|
||||
void CTree::AddPath(const char *buff)
|
||||
{
|
||||
Str path(buff);
|
||||
|
||||
// convert '\' to '/'
|
||||
for (int c=0 ; c<path.GetLength() ; c++)
|
||||
{
|
||||
if (path.GetAt(c)=='\\')
|
||||
path.SetAt(c,'/');
|
||||
}
|
||||
|
||||
if (path[0]=='/')
|
||||
path=path.Mid(1);
|
||||
|
||||
// lets tokenize it first
|
||||
if (path.GetAt(path.GetLength()-1)=='/')
|
||||
{
|
||||
// its just a folder path, no file
|
||||
return;
|
||||
}
|
||||
|
||||
GtkWidget *node=m_Root;
|
||||
|
||||
long pos=path.Find('/');
|
||||
while (pos!=-1)
|
||||
{
|
||||
Str folder=path.Left(pos);
|
||||
path=path.Mid(pos+1);
|
||||
|
||||
// add a folder, or retrieve its node if it already exists
|
||||
node=AddFolder(folder.GetBuffer(),node);
|
||||
|
||||
pos=path.Find('/');
|
||||
}
|
||||
|
||||
// add the filename to the final nested node
|
||||
AddFile(path.GetBuffer(),node);
|
||||
}
|
||||
|
||||
|
||||
void CTree::AddFile(const char *buff, GtkWidget *node)
|
||||
{
|
||||
Str file(buff);
|
||||
|
||||
if (node==NULL)
|
||||
node=m_Root;
|
||||
|
||||
GtkWidget *item=gtk_tree_item_new_with_label(buff);
|
||||
gtk_tree_append(GTK_TREE(node),item);
|
||||
gtk_widget_show(item);
|
||||
|
||||
gtk_widget_set_name(item,file);
|
||||
|
||||
// gtk_signal_connect (GTK_OBJECT(item), "select_child",
|
||||
// GTK_SIGNAL_FUNC(cb_select_child), item);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (item), "button_release_event",GTK_SIGNAL_FUNC (button_release), NULL);
|
||||
|
||||
|
||||
// a file is the last item in the tree so no tree is needed
|
||||
}
|
||||
|
||||
GtkWidget* CTree::AddFolder(const char *buff,GtkWidget *node)
|
||||
{
|
||||
Str folder(buff);
|
||||
|
||||
if (node==NULL)
|
||||
node=m_Root;
|
||||
|
||||
// search the node's siblings for the folder
|
||||
GList *children = gtk_container_children (GTK_CONTAINER (node));
|
||||
while (children)
|
||||
{
|
||||
GtkTreeItem *tree_item=(GTK_TREE_ITEM (children->data));
|
||||
|
||||
// check item for equality with the folder
|
||||
// and weather it has a tree attached
|
||||
|
||||
if (GTK_TREE_ITEM_SUBTREE(tree_item))
|
||||
{
|
||||
GtkItem *item=GTK_ITEM(tree_item);
|
||||
|
||||
GList *item_children=gtk_container_children(GTK_CONTAINER(item));
|
||||
|
||||
GtkLabel *label=GTK_LABEL(item_children->data);
|
||||
|
||||
if (strcmp(label->label,buff)==0)
|
||||
{
|
||||
g_list_free(item_children);
|
||||
g_list_free(children);
|
||||
|
||||
// return tree attached to the item
|
||||
return GTK_TREE_ITEM_SUBTREE(tree_item);
|
||||
}
|
||||
|
||||
g_list_free(item_children);
|
||||
}
|
||||
|
||||
children = g_list_remove_link (children, children);
|
||||
}
|
||||
|
||||
g_list_free(children);
|
||||
|
||||
// ok, not found so we add it
|
||||
GtkWidget *item=gtk_tree_item_new_with_label(buff);
|
||||
gtk_tree_append(GTK_TREE(node),item);
|
||||
gtk_widget_show(item);
|
||||
|
||||
GtkWidget *tree=gtk_tree_new();
|
||||
gtk_tree_item_set_subtree(GTK_TREE_ITEM(item),tree);
|
||||
gtk_widget_set_name(tree,buff);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT(tree), "select_child",
|
||||
GTK_SIGNAL_FUNC(cb_select_child), tree);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (item), "button_release_event",GTK_SIGNAL_FUNC (button_release), NULL);
|
||||
|
||||
|
||||
//gtk_signal_connect (GTK_OBJECT(tree), "selection_changed",
|
||||
// GTK_SIGNAL_FUNC(cb_selection_changed), tree, this);
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
|
||||
std::string CTree::GetFullPath(GtkWidget *child)
|
||||
{
|
||||
std::string path;
|
||||
gchar *name;
|
||||
|
||||
GtkLabel *label = GTK_LABEL (GTK_BIN (child)->child);
|
||||
gtk_label_get (label, &name);
|
||||
path=name;
|
||||
|
||||
if (path.compare("root")==0)
|
||||
return "root";
|
||||
|
||||
while (1)
|
||||
{
|
||||
// this gets an items parent tree
|
||||
GtkWidget *tr=(child->parent);
|
||||
|
||||
if (GTK_WIDGET(tr)==m_Root)
|
||||
break;
|
||||
|
||||
// and now its item
|
||||
child=GTK_TREE(tr)->tree_owner;
|
||||
|
||||
// and now the items label
|
||||
label = GTK_LABEL (GTK_BIN (child)->child);
|
||||
gtk_label_get (label, &name);
|
||||
std::string lbl=name;
|
||||
path=lbl+"/"+path;
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
void CTree::RemovePath(const char *path)
|
||||
{
|
||||
// not used yet
|
||||
}
|
||||
|
||||
|
||||
void CTree::SelectChild(GtkWidget *child)
|
||||
{
|
||||
g_pMainWnd->UpdateStatus();
|
||||
g_pMainWnd->UpdateToolBar();
|
||||
}
|
||||
|
||||
void cb_select_child (GtkWidget *root_tree, GtkWidget *child, GtkWidget *subtree)
|
||||
{
|
||||
g_pMainWnd->m_Tree.SelectChild(child);
|
||||
}
|
||||
|
||||
|
||||
std::string CTree::GetSelected()
|
||||
{
|
||||
std::string path="";
|
||||
|
||||
if (!GTK_TREE(m_Tree)->selection)
|
||||
return path;
|
||||
|
||||
GList *selected = (GTK_TREE(m_Tree)->selection);
|
||||
|
||||
GtkWidget *item=GTK_WIDGET(selected->data);
|
||||
|
||||
if (GTK_TREE_ITEM(item)->subtree)
|
||||
return path;
|
||||
|
||||
path=GetFullPath(item);
|
||||
|
||||
return path;
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
// Tree.h: interface for the CTree class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_TREE_H__C0DDC824_48DF_4A80_B393_83FF736FCB98__INCLUDED_)
|
||||
#define AFX_TREE_H__C0DDC824_48DF_4A80_B393_83FF736FCB98__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "stdafx.h"
|
||||
#include <string>
|
||||
|
||||
void cb_select_child (GtkWidget *root_tree, GtkWidget *child, GtkWidget *subtree);
|
||||
|
||||
class CTree
|
||||
{
|
||||
public:
|
||||
CTree();
|
||||
virtual ~CTree();
|
||||
|
||||
GtkWidget *m_pMainWnd;
|
||||
GtkWidget *m_Tree;
|
||||
GtkWidget *m_Root;
|
||||
|
||||
void Init(GtkWidget *win);
|
||||
void AddPath(const char *path);
|
||||
void AddFile(const char *file,GtkWidget *node=NULL);
|
||||
GtkWidget *AddFolder(const char *folder, GtkWidget *node=NULL);
|
||||
void RemovePath(const char*path);
|
||||
|
||||
void SelectChild(GtkWidget *child);
|
||||
std::string GetSelected();
|
||||
std::string GetFullPath(GtkWidget *item);
|
||||
|
||||
void Clear();
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_TREE_H__C0DDC824_48DF_4A80_B393_83FF736FCB98__INCLUDED_)
|
|
@ -1,338 +0,0 @@
|
|||
// Wild.cpp: implementation of the CWild class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
//#include "pakman.h"
|
||||
#include "wild.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CWild::CWild()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CWild::~CWild()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CWild::fpattern_isvalid(const char *pat)
|
||||
{
|
||||
int len;
|
||||
|
||||
/* Check args */
|
||||
if (pat == NULL)
|
||||
return (FALSE);
|
||||
|
||||
/* Verify that the pattern is valid */
|
||||
for (len = 0; pat[len] != '\0'; len++)
|
||||
{
|
||||
switch (pat[len])
|
||||
{
|
||||
case FPAT_SET_L:
|
||||
/* Char set */
|
||||
len++;
|
||||
if (pat[len] == FPAT_SET_NOT)
|
||||
len++; /* Set negation */
|
||||
|
||||
while (pat[len] != FPAT_SET_R)
|
||||
{
|
||||
if (pat[len] == QUOTE)
|
||||
len++; /* Quoted char */
|
||||
if (pat[len] == '\0')
|
||||
return (FALSE); /* Missing closing bracket */
|
||||
len++;
|
||||
|
||||
if (pat[len] == FPAT_SET_THRU)
|
||||
{
|
||||
/* Char range */
|
||||
len++;
|
||||
if (pat[len] == QUOTE)
|
||||
len++; /* Quoted char */
|
||||
if (pat[len] == '\0')
|
||||
return (FALSE); /* Missing closing bracket */
|
||||
len++;
|
||||
}
|
||||
|
||||
if (pat[len] == '\0')
|
||||
return (FALSE); /* Missing closing bracket */
|
||||
}
|
||||
break;
|
||||
|
||||
case QUOTE:
|
||||
/* Quoted char */
|
||||
len++;
|
||||
if (pat[len] == '\0')
|
||||
return (FALSE); /* Missing quoted char */
|
||||
break;
|
||||
|
||||
case FPAT_NOT:
|
||||
/* Negated pattern */
|
||||
len++;
|
||||
if (pat[len] == '\0')
|
||||
return (FALSE); /* Missing subpattern */
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Valid character */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
|
||||
int CWild::fpattern_submatch(const char *pat, const char *fname)
|
||||
{
|
||||
int fch;
|
||||
int pch;
|
||||
int i;
|
||||
int yes, match;
|
||||
int lo, hi;
|
||||
|
||||
/* Attempt to match subpattern against subfilename */
|
||||
while (*pat != '\0')
|
||||
{
|
||||
fch = *fname;
|
||||
pch = *pat;
|
||||
pat++;
|
||||
|
||||
switch (pch)
|
||||
{
|
||||
case FPAT_ANY:
|
||||
/* Match a single char */
|
||||
if (fch == DEL || fch == DEL2 || fch == '\0')
|
||||
return (FALSE);
|
||||
fname++;
|
||||
break;
|
||||
|
||||
case FPAT_CLOS:
|
||||
/* Match zero or more chars */
|
||||
i = 0;
|
||||
while (fname[i] != '\0')// && fname[i] != DEL && fname[i] != DEL2)
|
||||
i++;
|
||||
|
||||
while (i >= 0)
|
||||
{
|
||||
if (fpattern_submatch(pat, fname+i))
|
||||
return (TRUE);
|
||||
i--;
|
||||
}
|
||||
return (FALSE);
|
||||
|
||||
case SUB:
|
||||
/* Match zero or more chars */
|
||||
i = 0;
|
||||
while (fname[i] != '\0' && fname[i] != DEL && fname[i] != DEL2 && fname[i] != '.')
|
||||
i++;
|
||||
while (i >= 0)
|
||||
{
|
||||
if (fpattern_submatch(pat, fname+i))
|
||||
return (TRUE);
|
||||
i--;
|
||||
}
|
||||
return (FALSE);
|
||||
|
||||
case QUOTE:
|
||||
/* Match a quoted char */
|
||||
pch = *pat;
|
||||
if (lowercase(fch) != lowercase(pch) || pch == '\0')
|
||||
return (FALSE);
|
||||
fname++;
|
||||
pat++;
|
||||
break;
|
||||
|
||||
case FPAT_SET_L:
|
||||
/* Match char set/range */
|
||||
yes = TRUE;
|
||||
if (*pat == FPAT_SET_NOT)
|
||||
{
|
||||
pat++;
|
||||
yes = FALSE; /* Set negation */
|
||||
}
|
||||
|
||||
/* Look for [s], [-], [abc], [a-c] */
|
||||
match = !yes;
|
||||
while (*pat != FPAT_SET_R && *pat != '\0')
|
||||
{
|
||||
if (*pat == QUOTE)
|
||||
pat++; /* Quoted char */
|
||||
|
||||
if (*pat == '\0')
|
||||
break;
|
||||
lo = *pat++;
|
||||
hi = lo;
|
||||
|
||||
if (*pat == FPAT_SET_THRU)
|
||||
{
|
||||
/* Range */
|
||||
pat++;
|
||||
|
||||
if (*pat == QUOTE)
|
||||
pat++; /* Quoted char */
|
||||
|
||||
if (*pat == '\0')
|
||||
break;
|
||||
hi = *pat++;
|
||||
}
|
||||
|
||||
if (*pat == '\0')
|
||||
break;
|
||||
|
||||
/* Compare character to set range */
|
||||
if (lowercase(fch) >= lowercase(lo) &&
|
||||
lowercase(fch) <= lowercase(hi))
|
||||
match = yes;
|
||||
}
|
||||
|
||||
if (!match)
|
||||
return (FALSE);
|
||||
|
||||
if (*pat == '\0')
|
||||
return (FALSE); /* Missing closing bracket */
|
||||
|
||||
fname++;
|
||||
pat++;
|
||||
break;
|
||||
|
||||
case FPAT_NOT:
|
||||
/* Match only if rest of pattern does not match */
|
||||
if (*pat == '\0')
|
||||
return (FALSE); /* Missing subpattern */
|
||||
i = fpattern_submatch(pat, fname);
|
||||
return !i;
|
||||
|
||||
|
||||
case DEL:
|
||||
case DEL2:
|
||||
|
||||
/* Match path delimiter char */
|
||||
if (fch != DEL && fch != DEL2)
|
||||
return (FALSE);
|
||||
fname++;
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Match a (non-null) char exactly */
|
||||
if (lowercase(fch) != lowercase(pch))
|
||||
return (FALSE);
|
||||
fname++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check for complete match */
|
||||
if (*fname != '\0')
|
||||
return (FALSE);
|
||||
|
||||
/* Successful match */
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
* fpattern_match()
|
||||
* Attempts to match pattern 'pat' to filename 'fname'.
|
||||
*
|
||||
* Returns
|
||||
* 1 (true) if the filename matches, otherwise 0 (false).
|
||||
*
|
||||
* Caveats
|
||||
* If 'fname' is null, zero (false) is returned.
|
||||
*
|
||||
* If 'pat' is null, zero (false) is returned.
|
||||
*
|
||||
* If 'pat' is empty (""), the only filename it matches is the empty
|
||||
* string ("").
|
||||
*
|
||||
* If 'fname' is empty, the only pattern that will match it is the empty
|
||||
* string ("").
|
||||
*
|
||||
* If 'pat' is not a well-formed pattern, zero (false) is returned.
|
||||
*
|
||||
* Upper and lower case letters are treated the same; alphabetic
|
||||
* characters are converted to lower case before matching occurs.
|
||||
* Conversion to lower case is dependent upon the current locale setting.
|
||||
*/
|
||||
|
||||
int CWild::fpattern_match(const char *pat, const char *fname)
|
||||
{
|
||||
int rc;
|
||||
|
||||
/* Check args */
|
||||
if (fname == NULL)
|
||||
return (FALSE);
|
||||
|
||||
if (pat == NULL)
|
||||
return (FALSE);
|
||||
|
||||
/* Verify that the pattern is valid, and get its length */
|
||||
if (!fpattern_isvalid(pat))
|
||||
return (FALSE);
|
||||
|
||||
/* Attempt to match pattern against filename */
|
||||
if (fname[0] == '\0')
|
||||
return (pat[0] == '\0'); /* Special case */
|
||||
rc = fpattern_submatch(pat, fname);
|
||||
|
||||
return (rc);
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
* fpattern_matchn()
|
||||
* Attempts to match pattern 'pat' to filename 'fname'.
|
||||
* This operates like fpattern_match() except that it does not verify that
|
||||
* pattern 'pat' is well-formed, assuming that it has been checked by a
|
||||
* prior call to fpattern_isvalid().
|
||||
*
|
||||
* Returns
|
||||
* 1 (true) if the filename matches, otherwise 0 (false).
|
||||
*
|
||||
* Caveats
|
||||
* If 'fname' is null, zero (false) is returned.
|
||||
*
|
||||
* If 'pat' is null, zero (false) is returned.
|
||||
*
|
||||
* If 'pat' is empty (""), the only filename it matches is the empty ("")
|
||||
* string.
|
||||
*
|
||||
* If 'pat' is not a well-formed pattern, unpredictable results may occur.
|
||||
*
|
||||
* Upper and lower case letters are treated the same; alphabetic
|
||||
* characters are converted to lower case before matching occurs.
|
||||
* Conversion to lower case is dependent upon the current locale setting.
|
||||
*
|
||||
* See also
|
||||
* fpattern_match().
|
||||
*/
|
||||
|
||||
int CWild::fpattern_matchn(const char *pat, const char *fname)
|
||||
{
|
||||
int rc;
|
||||
|
||||
/* Check args */
|
||||
if (fname == NULL)
|
||||
return (FALSE);
|
||||
|
||||
if (pat == NULL)
|
||||
return (FALSE);
|
||||
|
||||
/* Assume that pattern is well-formed */
|
||||
|
||||
/* Attempt to match pattern against filename */
|
||||
rc = fpattern_submatch(pat, fname);
|
||||
|
||||
return (rc);
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
// Wild.h: interface for the CWild class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_WILD_H__DC88A1E2_A432_40DE_A5B2_D8EF34272EFC__INCLUDED_)
|
||||
#define AFX_WILD_H__DC88A1E2_A432_40DE_A5B2_D8EF34272EFC__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#define FPAT_QUOTE '\\' /* Quotes a special char */
|
||||
#define FPAT_QUOTE2 '`' /* Quotes a special char */
|
||||
#define FPAT_DEL '/' /* Path delimiter */
|
||||
#define FPAT_DEL2 '\\' /* Path delimiter */
|
||||
#define FPAT_DOT '.' /* Dot char */
|
||||
#define FPAT_NOT '!' /* Exclusion */
|
||||
#define FPAT_ANY '?' /* Any one char */
|
||||
#define FPAT_CLOS '*' /* Zero or more chars */
|
||||
#define FPAT_CLOSP '\x1A' /* Zero or more nondelimiters */
|
||||
#define FPAT_SET_L '[' /* Set/range open bracket */
|
||||
#define FPAT_SET_R ']' /* Set/range close bracket */
|
||||
#define FPAT_SET_NOT '!' /* Set exclusion */
|
||||
#define FPAT_SET_THRU '-' /* Set range of chars */
|
||||
|
||||
#define DEL FPAT_DEL
|
||||
#define DEL2 FPAT_DEL2
|
||||
#define QUOTE FPAT_QUOTE2
|
||||
#define SUB FPAT_CLOSP
|
||||
|
||||
/* Local function macros */
|
||||
#define lowercase(c) tolower(c)
|
||||
|
||||
class CWild
|
||||
{
|
||||
public:
|
||||
CWild();
|
||||
virtual ~CWild();
|
||||
|
||||
static int fpattern_submatch(const char *pat, const char *fname);
|
||||
static int fpattern_isvalid(const char *pat);
|
||||
static int fpattern_match(const char *pat, const char *fname);
|
||||
static int fpattern_matchn(const char *pat, const char *fname);
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_WILD_H__DC88A1E2_A432_40DE_A5B2_D8EF34272EFC__INCLUDED_)
|
|
@ -1,13 +0,0 @@
|
|||
Precompiled stuff for zip/unzip on linux is in libz-zip.a
|
||||
Based on zlib + minizip package
|
||||
The zip.c and unzip.c files will not build out of the box on linux
|
||||
they are only relevant to the windows version
|
||||
|
||||
How to rebuild libz-zip.a:
|
||||
download zlib from: http://www.info-zip.org/pub/infozip/zlib/zlib.html
|
||||
patch the contrib/minizip code with http://www.winimage.com/zLibDll/unzip.html
|
||||
(I had to replace zip.c by a newer one)
|
||||
build everything, zlib.a zip.o and unzip.o
|
||||
|
||||
ar -rs libz.a zip.o unzip.o
|
||||
mv libz.a libz-zip.a
|
|
@ -1,275 +0,0 @@
|
|||
/* unzip.h -- IO for uncompress .zip files using zlib
|
||||
Version 0.15 beta, Mar 19th, 1998,
|
||||
|
||||
Copyright (C) 1998 Gilles Vollant
|
||||
|
||||
This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
|
||||
WinZip, InfoZip tools and compatible.
|
||||
Encryption and multi volume ZipFile (span) are not supported.
|
||||
Old compressions used by old PKZip 1.x are not supported
|
||||
|
||||
THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE
|
||||
CAN CHANGE IN FUTURE VERSION !!
|
||||
I WAIT FEEDBACK at mail info@winimage.com
|
||||
Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
|
||||
|
||||
Condition of use and distribution are the same than zlib :
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
|
||||
*/
|
||||
/* for more info about .ZIP format, see
|
||||
ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip
|
||||
PkWare has also a specification at :
|
||||
ftp://ftp.pkware.com/probdesc.zip */
|
||||
|
||||
#ifndef _unz_H
|
||||
#define _unz_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#include "zlib.h"
|
||||
#endif
|
||||
|
||||
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
|
||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||
from (void*) without cast */
|
||||
typedef struct TagunzFile__ { int unused; } unzFile__;
|
||||
typedef unzFile__ *unzFile;
|
||||
#else
|
||||
typedef voidp unzFile;
|
||||
#endif
|
||||
|
||||
|
||||
#define UNZ_OK (0)
|
||||
#define UNZ_END_OF_LIST_OF_FILE (-100)
|
||||
#define UNZ_ERRNO (Z_ERRNO)
|
||||
#define UNZ_EOF (0)
|
||||
#define UNZ_PARAMERROR (-102)
|
||||
#define UNZ_BADZIPFILE (-103)
|
||||
#define UNZ_INTERNALERROR (-104)
|
||||
#define UNZ_CRCERROR (-105)
|
||||
|
||||
/* tm_unz contain date/time info */
|
||||
typedef struct tm_unz_s
|
||||
{
|
||||
uInt tm_sec; /* seconds after the minute - [0,59] */
|
||||
uInt tm_min; /* minutes after the hour - [0,59] */
|
||||
uInt tm_hour; /* hours since midnight - [0,23] */
|
||||
uInt tm_mday; /* day of the month - [1,31] */
|
||||
uInt tm_mon; /* months since January - [0,11] */
|
||||
uInt tm_year; /* years - [1980..2044] */
|
||||
} tm_unz;
|
||||
|
||||
/* unz_global_info structure contain global data about the ZIPfile
|
||||
These data comes from the end of central dir */
|
||||
typedef struct unz_global_info_s
|
||||
{
|
||||
uLong number_entry; /* total number of entries in
|
||||
the central dir on this disk */
|
||||
uLong size_comment; /* size of the global comment of the zipfile */
|
||||
} unz_global_info;
|
||||
|
||||
|
||||
/* unz_file_info contain information about a file in the zipfile */
|
||||
typedef struct unz_file_info_s
|
||||
{
|
||||
uLong version; /* version made by 2 bytes */
|
||||
uLong version_needed; /* version needed to extract 2 bytes */
|
||||
uLong flag; /* general purpose bit flag 2 bytes */
|
||||
uLong compression_method; /* compression method 2 bytes */
|
||||
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
|
||||
uLong crc; /* crc-32 4 bytes */
|
||||
uLong compressed_size; /* compressed size 4 bytes */
|
||||
uLong uncompressed_size; /* uncompressed size 4 bytes */
|
||||
uLong size_filename; /* filename length 2 bytes */
|
||||
uLong size_file_extra; /* extra field length 2 bytes */
|
||||
uLong size_file_comment; /* file comment length 2 bytes */
|
||||
|
||||
uLong disk_num_start; /* disk number start 2 bytes */
|
||||
uLong internal_fa; /* internal file attributes 2 bytes */
|
||||
uLong external_fa; /* external file attributes 4 bytes */
|
||||
|
||||
tm_unz tmu_date;
|
||||
} unz_file_info;
|
||||
|
||||
extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
|
||||
const char* fileName2,
|
||||
int iCaseSensitivity));
|
||||
/*
|
||||
Compare two filename (fileName1,fileName2).
|
||||
If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
|
||||
If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
|
||||
or strcasecmp)
|
||||
If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
|
||||
(like 1 on Unix, 2 on Windows)
|
||||
*/
|
||||
|
||||
|
||||
extern unzFile ZEXPORT unzOpen OF((const char *path));
|
||||
/*
|
||||
Open a Zip file. path contain the full pathname (by example,
|
||||
on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer
|
||||
"zlib/zlib111.zip".
|
||||
If the zipfile cannot be opened (file don't exist or in not valid), the
|
||||
return value is NULL.
|
||||
Else, the return value is a unzFile Handle, usable with other function
|
||||
of this unzip package.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzClose OF((unzFile file));
|
||||
/*
|
||||
Close a ZipFile opened with unzipOpen.
|
||||
If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
|
||||
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
|
||||
return UNZ_OK if there is no problem. */
|
||||
|
||||
extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
|
||||
unz_global_info *pglobal_info));
|
||||
/*
|
||||
Write info about the ZipFile in the *pglobal_info structure.
|
||||
No preparation of the structure is needed
|
||||
return UNZ_OK if there is no problem. */
|
||||
|
||||
|
||||
extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
|
||||
char *szComment,
|
||||
uLong uSizeBuf));
|
||||
/*
|
||||
Get the global comment string of the ZipFile, in the szComment buffer.
|
||||
uSizeBuf is the size of the szComment buffer.
|
||||
return the number of byte copied or an error code <0
|
||||
*/
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/* Unzip package allow you browse the directory of the zipfile */
|
||||
|
||||
extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
|
||||
/*
|
||||
Set the current file of the zipfile to the first file.
|
||||
return UNZ_OK if there is no problem
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzGoToNextFile OF((unzFile file));
|
||||
/*
|
||||
Set the current file of the zipfile to the next file.
|
||||
return UNZ_OK if there is no problem
|
||||
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzLocateFile OF((unzFile file,
|
||||
const char *szFileName,
|
||||
int iCaseSensitivity));
|
||||
/*
|
||||
Try locate the file szFileName in the zipfile.
|
||||
For the iCaseSensitivity signification, see unzStringFileNameCompare
|
||||
|
||||
return value :
|
||||
UNZ_OK if the file is found. It becomes the current file.
|
||||
UNZ_END_OF_LIST_OF_FILE if the file is not found
|
||||
*/
|
||||
|
||||
|
||||
extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
|
||||
unz_file_info *pfile_info,
|
||||
char *szFileName,
|
||||
uLong fileNameBufferSize,
|
||||
void *extraField,
|
||||
uLong extraFieldBufferSize,
|
||||
char *szComment,
|
||||
uLong commentBufferSize));
|
||||
/*
|
||||
Get Info about the current file
|
||||
if pfile_info!=NULL, the *pfile_info structure will contain somes info about
|
||||
the current file
|
||||
if szFileName!=NULL, the filemane string will be copied in szFileName
|
||||
(fileNameBufferSize is the size of the buffer)
|
||||
if extraField!=NULL, the extra field information will be copied in extraField
|
||||
(extraFieldBufferSize is the size of the buffer).
|
||||
This is the Central-header version of the extra field
|
||||
if szComment!=NULL, the comment string of the file will be copied in szComment
|
||||
(commentBufferSize is the size of the buffer)
|
||||
*/
|
||||
|
||||
/***************************************************************************/
|
||||
/* for reading the content of the current zipfile, you can open it, read data
|
||||
from it, and close it (you can close it before reading all the file)
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
|
||||
/*
|
||||
Open for reading data the current file in the zipfile.
|
||||
If there is no error, the return value is UNZ_OK.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
|
||||
/*
|
||||
Close the file in zip opened with unzOpenCurrentFile
|
||||
Return UNZ_CRCERROR if all the file was read but the CRC is not good
|
||||
*/
|
||||
|
||||
|
||||
extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
|
||||
voidp buf,
|
||||
unsigned len));
|
||||
/*
|
||||
Read bytes from the current file (opened by unzOpenCurrentFile)
|
||||
buf contain buffer where data must be copied
|
||||
len the size of buf.
|
||||
|
||||
return the number of byte copied if somes bytes are copied
|
||||
return 0 if the end of file was reached
|
||||
return <0 with error code if there is an error
|
||||
(UNZ_ERRNO for IO error, or zLib error for uncompress error)
|
||||
*/
|
||||
|
||||
extern z_off_t ZEXPORT unztell OF((unzFile file));
|
||||
/*
|
||||
Give the current position in uncompressed data
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzeof OF((unzFile file));
|
||||
/*
|
||||
return 1 if the end of file was reached, 0 elsewhere
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
|
||||
voidp buf,
|
||||
unsigned len));
|
||||
/*
|
||||
Read extra field from the current file (opened by unzOpenCurrentFile)
|
||||
This is the local-header version of the extra field (sometimes, there is
|
||||
more info in the local-header version than in the central-header)
|
||||
|
||||
if buf==NULL, it return the size of the local extra field
|
||||
|
||||
if buf!=NULL, len is the size of the buffer, the extra header is copied in
|
||||
buf.
|
||||
the return value is the number of bytes copied in buf, or (if <0)
|
||||
the error code
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _unz_H */
|
|
@ -1,279 +0,0 @@
|
|||
/* zconf.h -- configuration of the zlib compression library
|
||||
* Copyright (C) 1995-1998 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id: zconf.h,v 1.1.1.1 2000/10/03 18:36:29 mickey Exp $ */
|
||||
|
||||
#ifndef _ZCONF_H
|
||||
#define _ZCONF_H
|
||||
|
||||
/*
|
||||
* If you *really* need a unique prefix for all types and library functions,
|
||||
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
|
||||
*/
|
||||
#ifdef Z_PREFIX
|
||||
# define deflateInit_ z_deflateInit_
|
||||
# define deflate z_deflate
|
||||
# define deflateEnd z_deflateEnd
|
||||
# define inflateInit_ z_inflateInit_
|
||||
# define inflate z_inflate
|
||||
# define inflateEnd z_inflateEnd
|
||||
# define deflateInit2_ z_deflateInit2_
|
||||
# define deflateSetDictionary z_deflateSetDictionary
|
||||
# define deflateCopy z_deflateCopy
|
||||
# define deflateReset z_deflateReset
|
||||
# define deflateParams z_deflateParams
|
||||
# define inflateInit2_ z_inflateInit2_
|
||||
# define inflateSetDictionary z_inflateSetDictionary
|
||||
# define inflateSync z_inflateSync
|
||||
# define inflateSyncPoint z_inflateSyncPoint
|
||||
# define inflateReset z_inflateReset
|
||||
# define compress z_compress
|
||||
# define compress2 z_compress2
|
||||
# define uncompress z_uncompress
|
||||
# define adler32 z_adler32
|
||||
# define crc32 z_crc32
|
||||
# define get_crc_table z_get_crc_table
|
||||
|
||||
# define Byte z_Byte
|
||||
# define uInt z_uInt
|
||||
# define uLong z_uLong
|
||||
# define Bytef z_Bytef
|
||||
# define charf z_charf
|
||||
# define intf z_intf
|
||||
# define uIntf z_uIntf
|
||||
# define uLongf z_uLongf
|
||||
# define voidpf z_voidpf
|
||||
# define voidp z_voidp
|
||||
#endif
|
||||
|
||||
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
|
||||
# define WIN32
|
||||
#endif
|
||||
#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386)
|
||||
# ifndef __32BIT__
|
||||
# define __32BIT__
|
||||
# endif
|
||||
#endif
|
||||
#if defined(__MSDOS__) && !defined(MSDOS)
|
||||
# define MSDOS
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
|
||||
* than 64k bytes at a time (needed on systems with 16-bit int).
|
||||
*/
|
||||
#if defined(MSDOS) && !defined(__32BIT__)
|
||||
# define MAXSEG_64K
|
||||
#endif
|
||||
#ifdef MSDOS
|
||||
# define UNALIGNED_OK
|
||||
#endif
|
||||
|
||||
#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC)
|
||||
# define STDC
|
||||
#endif
|
||||
#if defined(__STDC__) || defined(__cplusplus) || defined(__OS2__)
|
||||
# ifndef STDC
|
||||
# define STDC
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef STDC
|
||||
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
|
||||
# define const
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Some Mac compilers merge all .h files incorrectly: */
|
||||
#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__)
|
||||
# define NO_DUMMY_DECL
|
||||
#endif
|
||||
|
||||
/* Old Borland C incorrectly complains about missing returns: */
|
||||
#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
|
||||
# define NEED_DUMMY_RETURN
|
||||
#endif
|
||||
|
||||
|
||||
/* Maximum value for memLevel in deflateInit2 */
|
||||
#ifndef MAX_MEM_LEVEL
|
||||
# ifdef MAXSEG_64K
|
||||
# define MAX_MEM_LEVEL 8
|
||||
# else
|
||||
# define MAX_MEM_LEVEL 9
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
|
||||
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
|
||||
* created by gzip. (Files created by minigzip can still be extracted by
|
||||
* gzip.)
|
||||
*/
|
||||
#ifndef MAX_WBITS
|
||||
# define MAX_WBITS 15 /* 32K LZ77 window */
|
||||
#endif
|
||||
|
||||
/* The memory requirements for deflate are (in bytes):
|
||||
(1 << (windowBits+2)) + (1 << (memLevel+9))
|
||||
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
|
||||
plus a few kilobytes for small objects. For example, if you want to reduce
|
||||
the default memory requirements from 256K to 128K, compile with
|
||||
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
|
||||
Of course this will generally degrade compression (there's no free lunch).
|
||||
|
||||
The memory requirements for inflate are (in bytes) 1 << windowBits
|
||||
that is, 32K for windowBits=15 (default value) plus a few kilobytes
|
||||
for small objects.
|
||||
*/
|
||||
|
||||
/* Type declarations */
|
||||
|
||||
#ifndef OF /* function prototypes */
|
||||
# ifdef STDC
|
||||
# define OF(args) args
|
||||
# else
|
||||
# define OF(args) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The following definitions for FAR are needed only for MSDOS mixed
|
||||
* model programming (small or medium model with some far allocations).
|
||||
* This was tested only with MSC; for other MSDOS compilers you may have
|
||||
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
|
||||
* just define FAR to be empty.
|
||||
*/
|
||||
#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__)
|
||||
/* MSC small or medium model */
|
||||
# define SMALL_MEDIUM
|
||||
# ifdef _MSC_VER
|
||||
# define FAR _far
|
||||
# else
|
||||
# define FAR far
|
||||
# endif
|
||||
#endif
|
||||
#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
|
||||
# ifndef __32BIT__
|
||||
# define SMALL_MEDIUM
|
||||
# define FAR _far
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Compile with -DZLIB_DLL for Windows DLL support */
|
||||
#if defined(ZLIB_DLL)
|
||||
# if defined(_WINDOWS) || defined(WINDOWS)
|
||||
# ifdef FAR
|
||||
# undef FAR
|
||||
# endif
|
||||
# include <windows.h>
|
||||
# define ZEXPORT WINAPI
|
||||
# ifdef WIN32
|
||||
# define ZEXPORTVA WINAPIV
|
||||
# else
|
||||
# define ZEXPORTVA FAR _cdecl _export
|
||||
# endif
|
||||
# endif
|
||||
# if defined (__BORLANDC__)
|
||||
# if (__BORLANDC__ >= 0x0500) && defined (WIN32)
|
||||
# include <windows.h>
|
||||
# define ZEXPORT __declspec(dllexport) WINAPI
|
||||
# define ZEXPORTRVA __declspec(dllexport) WINAPIV
|
||||
# else
|
||||
# if defined (_Windows) && defined (__DLL__)
|
||||
# define ZEXPORT _export
|
||||
# define ZEXPORTVA _export
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined (__BEOS__)
|
||||
# if defined (ZLIB_DLL)
|
||||
# define ZEXTERN extern __declspec(dllexport)
|
||||
# else
|
||||
# define ZEXTERN extern __declspec(dllimport)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef ZEXPORT
|
||||
# define ZEXPORT
|
||||
#endif
|
||||
#ifndef ZEXPORTVA
|
||||
# define ZEXPORTVA
|
||||
#endif
|
||||
#ifndef ZEXTERN
|
||||
# define ZEXTERN extern
|
||||
#endif
|
||||
|
||||
#ifndef FAR
|
||||
# define FAR
|
||||
#endif
|
||||
|
||||
#if !defined(MACOS) && !defined(TARGET_OS_MAC)
|
||||
typedef unsigned char Byte; /* 8 bits */
|
||||
#endif
|
||||
typedef unsigned int uInt; /* 16 bits or more */
|
||||
typedef unsigned long uLong; /* 32 bits or more */
|
||||
|
||||
#ifdef SMALL_MEDIUM
|
||||
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
|
||||
# define Bytef Byte FAR
|
||||
#else
|
||||
typedef Byte FAR Bytef;
|
||||
#endif
|
||||
typedef char FAR charf;
|
||||
typedef int FAR intf;
|
||||
typedef uInt FAR uIntf;
|
||||
typedef uLong FAR uLongf;
|
||||
|
||||
#ifdef STDC
|
||||
typedef void FAR *voidpf;
|
||||
typedef void *voidp;
|
||||
#else
|
||||
typedef Byte FAR *voidpf;
|
||||
typedef Byte *voidp;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <sys/types.h> /* for off_t */
|
||||
# include <unistd.h> /* for SEEK_* and off_t */
|
||||
# define z_off_t off_t
|
||||
#endif
|
||||
#ifndef SEEK_SET
|
||||
# define SEEK_SET 0 /* Seek from beginning of file. */
|
||||
# define SEEK_CUR 1 /* Seek from current position. */
|
||||
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
||||
#endif
|
||||
#ifndef z_off_t
|
||||
# define z_off_t long
|
||||
#endif
|
||||
|
||||
/* MVS linker does not support external names larger than 8 bytes */
|
||||
#if defined(__MVS__)
|
||||
# pragma map(deflateInit_,"DEIN")
|
||||
# pragma map(deflateInit2_,"DEIN2")
|
||||
# pragma map(deflateEnd,"DEEND")
|
||||
# pragma map(inflateInit_,"ININ")
|
||||
# pragma map(inflateInit2_,"ININ2")
|
||||
# pragma map(inflateEnd,"INEND")
|
||||
# pragma map(inflateSync,"INSY")
|
||||
# pragma map(inflateSetDictionary,"INSEDI")
|
||||
# pragma map(inflate_blocks,"INBL")
|
||||
# pragma map(inflate_blocks_new,"INBLNE")
|
||||
# pragma map(inflate_blocks_free,"INBLFR")
|
||||
# pragma map(inflate_blocks_reset,"INBLRE")
|
||||
# pragma map(inflate_codes_free,"INCOFR")
|
||||
# pragma map(inflate_codes,"INCO")
|
||||
# pragma map(inflate_fast,"INFA")
|
||||
# pragma map(inflate_flush,"INFLU")
|
||||
# pragma map(inflate_mask,"INMA")
|
||||
# pragma map(inflate_set_dictionary,"INSEDI2")
|
||||
# pragma map(inflate_copyright,"INCOPY")
|
||||
# pragma map(inflate_trees_bits,"INTRBI")
|
||||
# pragma map(inflate_trees_dynamic,"INTRDY")
|
||||
# pragma map(inflate_trees_fixed,"INTRFI")
|
||||
# pragma map(inflate_trees_free,"INTRFR")
|
||||
#endif
|
||||
|
||||
#endif /* _ZCONF_H */
|
|
@ -1,720 +0,0 @@
|
|||
/* zip.c -- IO on .zip files using zlib
|
||||
Version 0.15 beta, Mar 19th, 1998,
|
||||
|
||||
Read zip.h for more info
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "zlib.h"
|
||||
#include "zip.h"
|
||||
|
||||
# define DEF_MEM_LEVEL 8
|
||||
|
||||
#ifdef STDC
|
||||
# include <stddef.h>
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
#ifdef NO_ERRNO_H
|
||||
extern int errno;
|
||||
#else
|
||||
# include <errno.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef local
|
||||
# define local static
|
||||
#endif
|
||||
/* compile with -Dlocal if your debugger can't find static symbols */
|
||||
|
||||
#ifndef VERSIONMADEBY
|
||||
# define VERSIONMADEBY (0x0) /* platform depedent */
|
||||
#endif
|
||||
|
||||
#ifndef Z_BUFSIZE
|
||||
#define Z_BUFSIZE (16384)
|
||||
#endif
|
||||
|
||||
#ifndef Z_MAXFILENAMEINZIP
|
||||
#define Z_MAXFILENAMEINZIP (256)
|
||||
#endif
|
||||
|
||||
#ifndef ALLOC
|
||||
# define ALLOC(size) (malloc(size))
|
||||
#endif
|
||||
#ifndef TRYFREE
|
||||
# define TRYFREE(p) {if (p) free(p);}
|
||||
#endif
|
||||
|
||||
/*
|
||||
#define SIZECENTRALDIRITEM (0x2e)
|
||||
#define SIZEZIPLOCALHEADER (0x1e)
|
||||
*/
|
||||
|
||||
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
|
||||
|
||||
#ifndef SEEK_CUR
|
||||
#define SEEK_CUR 1
|
||||
#endif
|
||||
|
||||
#ifndef SEEK_END
|
||||
#define SEEK_END 2
|
||||
#endif
|
||||
|
||||
#ifndef SEEK_SET
|
||||
#define SEEK_SET 0
|
||||
#endif
|
||||
|
||||
const char zip_copyright[] =
|
||||
" zip 0.15 Copyright 1998 Gilles Vollant ";
|
||||
|
||||
|
||||
#define SIZEDATA_INDATABLOCK (4096-(4*4))
|
||||
|
||||
#define LOCALHEADERMAGIC (0x04034b50)
|
||||
#define CENTRALHEADERMAGIC (0x02014b50)
|
||||
#define ENDHEADERMAGIC (0x06054b50)
|
||||
|
||||
#define FLAG_LOCALHEADER_OFFSET (0x06)
|
||||
#define CRC_LOCALHEADER_OFFSET (0x0e)
|
||||
|
||||
#define SIZECENTRALHEADER (0x2e) /* 46 */
|
||||
|
||||
typedef struct linkedlist_datablock_internal_s
|
||||
{
|
||||
struct linkedlist_datablock_internal_s* next_datablock;
|
||||
uLong avail_in_this_block;
|
||||
uLong filled_in_this_block;
|
||||
uLong unused; /* for future use and alignement */
|
||||
unsigned char data[SIZEDATA_INDATABLOCK];
|
||||
} linkedlist_datablock_internal;
|
||||
|
||||
typedef struct linkedlist_data_s
|
||||
{
|
||||
linkedlist_datablock_internal* first_block;
|
||||
linkedlist_datablock_internal* last_block;
|
||||
} linkedlist_data;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
z_stream stream; /* zLib stream structure for inflate */
|
||||
int stream_initialised; /* 1 is stream is initialised */
|
||||
uInt pos_in_buffered_data; /* last written byte in buffered_data */
|
||||
|
||||
uLong pos_local_header; /* offset of the local header of the file
|
||||
currenty writing */
|
||||
char* central_header; /* central header data for the current file */
|
||||
uLong size_centralheader; /* size of the central header for cur file */
|
||||
uLong flag; /* flag of the file currently writing */
|
||||
|
||||
int method; /* compression method of file currenty wr.*/
|
||||
Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/
|
||||
uLong dosDate;
|
||||
uLong crc32;
|
||||
} curfile_info;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
FILE * filezip;
|
||||
linkedlist_data central_dir;/* datablock with central dir in construction*/
|
||||
int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/
|
||||
curfile_info ci; /* info on the file curretly writing */
|
||||
|
||||
uLong begin_pos; /* position of the beginning of the zipfile */
|
||||
uLong number_entry;
|
||||
} zip_internal;
|
||||
|
||||
local linkedlist_datablock_internal* allocate_new_datablock()
|
||||
{
|
||||
linkedlist_datablock_internal* ldi;
|
||||
ldi = (linkedlist_datablock_internal*)
|
||||
ALLOC(sizeof(linkedlist_datablock_internal));
|
||||
if (ldi!=NULL)
|
||||
{
|
||||
ldi->next_datablock = NULL ;
|
||||
ldi->filled_in_this_block = 0 ;
|
||||
ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ;
|
||||
}
|
||||
return ldi;
|
||||
}
|
||||
|
||||
local void free_datablock(ldi)
|
||||
linkedlist_datablock_internal* ldi;
|
||||
{
|
||||
while (ldi!=NULL)
|
||||
{
|
||||
linkedlist_datablock_internal* ldinext = ldi->next_datablock;
|
||||
TRYFREE(ldi);
|
||||
ldi = ldinext;
|
||||
}
|
||||
}
|
||||
|
||||
local void init_linkedlist(ll)
|
||||
linkedlist_data* ll;
|
||||
{
|
||||
ll->first_block = ll->last_block = NULL;
|
||||
}
|
||||
|
||||
local void free_linkedlist(ll)
|
||||
linkedlist_data* ll;
|
||||
{
|
||||
free_datablock(ll->first_block);
|
||||
ll->first_block = ll->last_block = NULL;
|
||||
}
|
||||
|
||||
|
||||
local int add_data_in_datablock(ll,buf,len)
|
||||
linkedlist_data* ll;
|
||||
const void* buf;
|
||||
uLong len;
|
||||
{
|
||||
linkedlist_datablock_internal* ldi;
|
||||
const unsigned char* from_copy;
|
||||
|
||||
if (ll==NULL)
|
||||
return ZIP_INTERNALERROR;
|
||||
|
||||
if (ll->last_block == NULL)
|
||||
{
|
||||
ll->first_block = ll->last_block = allocate_new_datablock();
|
||||
if (ll->first_block == NULL)
|
||||
return ZIP_INTERNALERROR;
|
||||
}
|
||||
|
||||
ldi = ll->last_block;
|
||||
from_copy = (unsigned char*)buf;
|
||||
|
||||
while (len>0)
|
||||
{
|
||||
uInt copy_this;
|
||||
uInt i;
|
||||
unsigned char* to_copy;
|
||||
|
||||
if (ldi->avail_in_this_block==0)
|
||||
{
|
||||
ldi->next_datablock = allocate_new_datablock();
|
||||
if (ldi->next_datablock == NULL)
|
||||
return ZIP_INTERNALERROR;
|
||||
ldi = ldi->next_datablock ;
|
||||
ll->last_block = ldi;
|
||||
}
|
||||
|
||||
if (ldi->avail_in_this_block < len)
|
||||
copy_this = (uInt)ldi->avail_in_this_block;
|
||||
else
|
||||
copy_this = (uInt)len;
|
||||
|
||||
to_copy = &(ldi->data[ldi->filled_in_this_block]);
|
||||
|
||||
for (i=0;i<copy_this;i++)
|
||||
*(to_copy+i)=*(from_copy+i);
|
||||
|
||||
ldi->filled_in_this_block += copy_this;
|
||||
ldi->avail_in_this_block -= copy_this;
|
||||
from_copy += copy_this ;
|
||||
len -= copy_this;
|
||||
}
|
||||
return ZIP_OK;
|
||||
}
|
||||
|
||||
|
||||
local int write_datablock(fout,ll)
|
||||
FILE * fout;
|
||||
linkedlist_data* ll;
|
||||
{
|
||||
linkedlist_datablock_internal* ldi;
|
||||
ldi = ll->first_block;
|
||||
while (ldi!=NULL)
|
||||
{
|
||||
if (ldi->filled_in_this_block > 0)
|
||||
if (fwrite(ldi->data,(uInt)ldi->filled_in_this_block,1,fout)!=1)
|
||||
return ZIP_ERRNO;
|
||||
ldi = ldi->next_datablock;
|
||||
}
|
||||
return ZIP_OK;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/* ===========================================================================
|
||||
Outputs a long in LSB order to the given file
|
||||
nbByte == 1, 2 or 4 (byte, short or long)
|
||||
*/
|
||||
|
||||
local int ziplocal_putValue OF((FILE *file, uLong x, int nbByte));
|
||||
local int ziplocal_putValue (file, x, nbByte)
|
||||
FILE *file;
|
||||
uLong x;
|
||||
int nbByte;
|
||||
{
|
||||
unsigned char buf[4];
|
||||
int n;
|
||||
for (n = 0; n < nbByte; n++) {
|
||||
buf[n] = (unsigned char)(x & 0xff);
|
||||
x >>= 8;
|
||||
}
|
||||
if (fwrite(buf,nbByte,1,file)!=1)
|
||||
return ZIP_ERRNO;
|
||||
else
|
||||
return ZIP_OK;
|
||||
}
|
||||
|
||||
local void ziplocal_putValue_inmemory OF((void* dest, uLong x, int nbByte));
|
||||
local void ziplocal_putValue_inmemory (dest, x, nbByte)
|
||||
void* dest;
|
||||
uLong x;
|
||||
int nbByte;
|
||||
{
|
||||
unsigned char* buf=(unsigned char*)dest;
|
||||
int n;
|
||||
for (n = 0; n < nbByte; n++) {
|
||||
buf[n] = (unsigned char)(x & 0xff);
|
||||
x >>= 8;
|
||||
}
|
||||
}
|
||||
/****************************************************************************/
|
||||
|
||||
|
||||
local uLong ziplocal_TmzDateToDosDate(ptm,dosDate)
|
||||
tm_zip* ptm;
|
||||
uLong dosDate;
|
||||
{
|
||||
uLong year = (uLong)ptm->tm_year;
|
||||
if (year>1980)
|
||||
year-=1980;
|
||||
else if (year>80)
|
||||
year-=80;
|
||||
return
|
||||
(uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) |
|
||||
((ptm->tm_sec/2) + (32* ptm->tm_min) + (2048 * (uLong)ptm->tm_hour));
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
extern zipFile ZEXPORT zipOpen (pathname, append)
|
||||
const char *pathname;
|
||||
int append;
|
||||
{
|
||||
zip_internal ziinit;
|
||||
zip_internal* zi;
|
||||
|
||||
ziinit.filezip = fopen(pathname,(append == 0) ? "wb" : "ab");
|
||||
if (ziinit.filezip == NULL)
|
||||
return NULL;
|
||||
ziinit.begin_pos = ftell(ziinit.filezip);
|
||||
ziinit.in_opened_file_inzip = 0;
|
||||
ziinit.ci.stream_initialised = 0;
|
||||
ziinit.number_entry = 0;
|
||||
init_linkedlist(&(ziinit.central_dir));
|
||||
|
||||
|
||||
zi = (zip_internal*)ALLOC(sizeof(zip_internal));
|
||||
if (zi==NULL)
|
||||
{
|
||||
fclose(ziinit.filezip);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*zi = ziinit;
|
||||
return (zipFile)zi;
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
|
||||
extrafield_local, size_extrafield_local,
|
||||
extrafield_global, size_extrafield_global,
|
||||
comment, method, level)
|
||||
zipFile file;
|
||||
const char* filename;
|
||||
const zip_fileinfo* zipfi;
|
||||
const void* extrafield_local;
|
||||
uInt size_extrafield_local;
|
||||
const void* extrafield_global;
|
||||
uInt size_extrafield_global;
|
||||
const char* comment;
|
||||
int method;
|
||||
int level;
|
||||
{
|
||||
zip_internal* zi;
|
||||
uInt size_filename;
|
||||
uInt size_comment;
|
||||
uInt i;
|
||||
int err = ZIP_OK;
|
||||
|
||||
if (file == NULL)
|
||||
return ZIP_PARAMERROR;
|
||||
if ((method!=0) && (method!=Z_DEFLATED))
|
||||
return ZIP_PARAMERROR;
|
||||
|
||||
zi = (zip_internal*)file;
|
||||
|
||||
if (zi->in_opened_file_inzip == 1)
|
||||
{
|
||||
err = zipCloseFileInZip (file);
|
||||
if (err != ZIP_OK)
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
if (filename==NULL)
|
||||
filename="-";
|
||||
|
||||
if (comment==NULL)
|
||||
size_comment = 0;
|
||||
else
|
||||
size_comment = strlen(comment);
|
||||
|
||||
size_filename = strlen(filename);
|
||||
|
||||
if (zipfi == NULL)
|
||||
zi->ci.dosDate = 0;
|
||||
else
|
||||
{
|
||||
if (zipfi->dosDate != 0)
|
||||
zi->ci.dosDate = zipfi->dosDate;
|
||||
else zi->ci.dosDate = ziplocal_TmzDateToDosDate(&zipfi->tmz_date,zipfi->dosDate);
|
||||
}
|
||||
|
||||
zi->ci.flag = 0;
|
||||
if ((level==8) || (level==9))
|
||||
zi->ci.flag |= 2;
|
||||
if ((level==2))
|
||||
zi->ci.flag |= 4;
|
||||
if ((level==1))
|
||||
zi->ci.flag |= 6;
|
||||
|
||||
zi->ci.crc32 = 0;
|
||||
zi->ci.method = method;
|
||||
zi->ci.stream_initialised = 0;
|
||||
zi->ci.pos_in_buffered_data = 0;
|
||||
zi->ci.pos_local_header = ftell(zi->filezip);
|
||||
zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename +
|
||||
size_extrafield_global + size_comment;
|
||||
zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader);
|
||||
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4);
|
||||
/* version info */
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+4,(uLong)VERSIONMADEBY,2);
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2);
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2);
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2);
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4);
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2);
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2);
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2);
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/
|
||||
|
||||
if (zipfi==NULL)
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2);
|
||||
else
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2);
|
||||
|
||||
if (zipfi==NULL)
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4);
|
||||
else
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4);
|
||||
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header,4);
|
||||
|
||||
for (i=0;i<size_filename;i++)
|
||||
*(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i);
|
||||
|
||||
for (i=0;i<size_extrafield_global;i++)
|
||||
*(zi->ci.central_header+SIZECENTRALHEADER+size_filename+i) =
|
||||
*(((const char*)extrafield_global)+i);
|
||||
|
||||
for (i=0;i<size_comment;i++)
|
||||
*(zi->ci.central_header+SIZECENTRALHEADER+size_filename+
|
||||
size_extrafield_global+i) = *(filename+i);
|
||||
if (zi->ci.central_header == NULL)
|
||||
return ZIP_INTERNALERROR;
|
||||
|
||||
/* write the local header */
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)LOCALHEADERMAGIC,4);
|
||||
|
||||
if (err==ZIP_OK)
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)20,2);/* version needed to extract */
|
||||
if (err==ZIP_OK)
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.flag,2);
|
||||
|
||||
if (err==ZIP_OK)
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.method,2);
|
||||
|
||||
if (err==ZIP_OK)
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.dosDate,4);
|
||||
|
||||
if (err==ZIP_OK)
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)0,4); /* crc 32, unknown */
|
||||
if (err==ZIP_OK)
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)0,4); /* compressed size, unknown */
|
||||
if (err==ZIP_OK)
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)0,4); /* uncompressed size, unknown */
|
||||
|
||||
if (err==ZIP_OK)
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)size_filename,2);
|
||||
|
||||
if (err==ZIP_OK)
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)size_extrafield_local,2);
|
||||
|
||||
if ((err==ZIP_OK) && (size_filename>0))
|
||||
if (fwrite(filename,(uInt)size_filename,1,zi->filezip)!=1)
|
||||
err = ZIP_ERRNO;
|
||||
|
||||
if ((err==ZIP_OK) && (size_extrafield_local>0))
|
||||
if (fwrite(extrafield_local,(uInt)size_extrafield_local,1,zi->filezip)
|
||||
!=1)
|
||||
err = ZIP_ERRNO;
|
||||
|
||||
zi->ci.stream.avail_in = (uInt)0;
|
||||
zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
|
||||
zi->ci.stream.next_out = zi->ci.buffered_data;
|
||||
zi->ci.stream.total_in = 0;
|
||||
zi->ci.stream.total_out = 0;
|
||||
|
||||
if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED))
|
||||
{
|
||||
zi->ci.stream.zalloc = (alloc_func)0;
|
||||
zi->ci.stream.zfree = (free_func)0;
|
||||
zi->ci.stream.opaque = (voidpf)0;
|
||||
|
||||
err = deflateInit2(&zi->ci.stream, level,
|
||||
Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, 0);
|
||||
|
||||
if (err==Z_OK)
|
||||
zi->ci.stream_initialised = 1;
|
||||
}
|
||||
|
||||
|
||||
if (err==Z_OK)
|
||||
zi->in_opened_file_inzip = 1;
|
||||
return err;
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipWriteInFileInZip (file, buf, len)
|
||||
zipFile file;
|
||||
const voidp buf;
|
||||
unsigned len;
|
||||
{
|
||||
zip_internal* zi;
|
||||
int err=ZIP_OK;
|
||||
|
||||
if (file == NULL)
|
||||
return ZIP_PARAMERROR;
|
||||
zi = (zip_internal*)file;
|
||||
|
||||
if (zi->in_opened_file_inzip == 0)
|
||||
return ZIP_PARAMERROR;
|
||||
|
||||
zi->ci.stream.next_in = buf;
|
||||
zi->ci.stream.avail_in = len;
|
||||
zi->ci.crc32 = crc32(zi->ci.crc32,buf,len);
|
||||
|
||||
while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0))
|
||||
{
|
||||
if (zi->ci.stream.avail_out == 0)
|
||||
{
|
||||
if (fwrite(zi->ci.buffered_data,(uInt)zi->ci.pos_in_buffered_data,1,zi->filezip)
|
||||
!=1)
|
||||
err = ZIP_ERRNO;
|
||||
zi->ci.pos_in_buffered_data = 0;
|
||||
zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
|
||||
zi->ci.stream.next_out = zi->ci.buffered_data;
|
||||
}
|
||||
|
||||
if (zi->ci.method == Z_DEFLATED)
|
||||
{
|
||||
uLong uTotalOutBefore = zi->ci.stream.total_out;
|
||||
err=deflate(&zi->ci.stream, Z_NO_FLUSH);
|
||||
zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
uInt copy_this,i;
|
||||
if (zi->ci.stream.avail_in < zi->ci.stream.avail_out)
|
||||
copy_this = zi->ci.stream.avail_in;
|
||||
else
|
||||
copy_this = zi->ci.stream.avail_out;
|
||||
for (i=0;i<copy_this;i++)
|
||||
*(((char*)zi->ci.stream.next_out)+i) =
|
||||
*(((const char*)zi->ci.stream.next_in)+i);
|
||||
{
|
||||
zi->ci.stream.avail_in -= copy_this;
|
||||
zi->ci.stream.avail_out-= copy_this;
|
||||
zi->ci.stream.next_in+= copy_this;
|
||||
zi->ci.stream.next_out+= copy_this;
|
||||
zi->ci.stream.total_in+= copy_this;
|
||||
zi->ci.stream.total_out+= copy_this;
|
||||
zi->ci.pos_in_buffered_data += copy_this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipCloseFileInZip (file)
|
||||
zipFile file;
|
||||
{
|
||||
zip_internal* zi;
|
||||
int err=ZIP_OK;
|
||||
|
||||
if (file == NULL)
|
||||
return ZIP_PARAMERROR;
|
||||
zi = (zip_internal*)file;
|
||||
|
||||
if (zi->in_opened_file_inzip == 0)
|
||||
return ZIP_PARAMERROR;
|
||||
zi->ci.stream.avail_in = 0;
|
||||
|
||||
if (zi->ci.method == Z_DEFLATED)
|
||||
while (err==ZIP_OK)
|
||||
{
|
||||
uLong uTotalOutBefore;
|
||||
if (zi->ci.stream.avail_out == 0)
|
||||
{
|
||||
if (fwrite(zi->ci.buffered_data,(uInt)zi->ci.pos_in_buffered_data,1,zi->filezip)
|
||||
!=1)
|
||||
err = ZIP_ERRNO;
|
||||
zi->ci.pos_in_buffered_data = 0;
|
||||
zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
|
||||
zi->ci.stream.next_out = zi->ci.buffered_data;
|
||||
}
|
||||
uTotalOutBefore = zi->ci.stream.total_out;
|
||||
err=deflate(&zi->ci.stream, Z_FINISH);
|
||||
zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
|
||||
}
|
||||
|
||||
if (err==Z_STREAM_END)
|
||||
err=ZIP_OK; /* this is normal */
|
||||
|
||||
if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK))
|
||||
if (fwrite(zi->ci.buffered_data,(uInt)zi->ci.pos_in_buffered_data,1,zi->filezip)
|
||||
!=1)
|
||||
err = ZIP_ERRNO;
|
||||
|
||||
if ((zi->ci.method == Z_DEFLATED) && (err==ZIP_OK))
|
||||
{
|
||||
err=deflateEnd(&zi->ci.stream);
|
||||
zi->ci.stream_initialised = 0;
|
||||
}
|
||||
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+16,(uLong)zi->ci.crc32,4); /*crc*/
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+20,
|
||||
(uLong)zi->ci.stream.total_out,4); /*compr size*/
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+24,
|
||||
(uLong)zi->ci.stream.total_in,4); /*uncompr size*/
|
||||
|
||||
if (err==ZIP_OK)
|
||||
err = add_data_in_datablock(&zi->central_dir,zi->ci.central_header,
|
||||
(uLong)zi->ci.size_centralheader);
|
||||
free(zi->ci.central_header);
|
||||
|
||||
if (err==ZIP_OK)
|
||||
{
|
||||
long cur_pos_inzip = ftell(zi->filezip);
|
||||
if (fseek(zi->filezip,
|
||||
zi->ci.pos_local_header + 14,SEEK_SET)!=0)
|
||||
err = ZIP_ERRNO;
|
||||
|
||||
if (err==ZIP_OK)
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.crc32,4); /* crc 32, unknown */
|
||||
|
||||
if (err==ZIP_OK) /* compressed size, unknown */
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.stream.total_out,4);
|
||||
|
||||
if (err==ZIP_OK) /* uncompressed size, unknown */
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.stream.total_in,4);
|
||||
|
||||
if (fseek(zi->filezip,
|
||||
cur_pos_inzip,SEEK_SET)!=0)
|
||||
err = ZIP_ERRNO;
|
||||
}
|
||||
|
||||
zi->number_entry ++;
|
||||
zi->in_opened_file_inzip = 0;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipClose (file, global_comment)
|
||||
zipFile file;
|
||||
const char* global_comment;
|
||||
{
|
||||
zip_internal* zi;
|
||||
int err = 0;
|
||||
uLong size_centraldir = 0;
|
||||
uLong centraldir_pos_inzip ;
|
||||
uInt size_global_comment;
|
||||
if (file == NULL)
|
||||
return ZIP_PARAMERROR;
|
||||
zi = (zip_internal*)file;
|
||||
|
||||
if (zi->in_opened_file_inzip == 1)
|
||||
{
|
||||
err = zipCloseFileInZip (file);
|
||||
}
|
||||
|
||||
if (global_comment==NULL)
|
||||
size_global_comment = 0;
|
||||
else
|
||||
size_global_comment = strlen(global_comment);
|
||||
|
||||
|
||||
centraldir_pos_inzip = ftell(zi->filezip);
|
||||
if (err==ZIP_OK)
|
||||
{
|
||||
linkedlist_datablock_internal* ldi = zi->central_dir.first_block ;
|
||||
while (ldi!=NULL)
|
||||
{
|
||||
if ((err==ZIP_OK) && (ldi->filled_in_this_block>0))
|
||||
if (fwrite(ldi->data,(uInt)ldi->filled_in_this_block,
|
||||
1,zi->filezip) !=1 )
|
||||
err = ZIP_ERRNO;
|
||||
|
||||
size_centraldir += ldi->filled_in_this_block;
|
||||
ldi = ldi->next_datablock;
|
||||
}
|
||||
}
|
||||
free_datablock(zi->central_dir.first_block);
|
||||
|
||||
if (err==ZIP_OK) /* Magic End */
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)ENDHEADERMAGIC,4);
|
||||
|
||||
if (err==ZIP_OK) /* number of this disk */
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)0,2);
|
||||
|
||||
if (err==ZIP_OK) /* number of the disk with the start of the central directory */
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)0,2);
|
||||
|
||||
if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)zi->number_entry,2);
|
||||
|
||||
if (err==ZIP_OK) /* total number of entries in the central dir */
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)zi->number_entry,2);
|
||||
|
||||
if (err==ZIP_OK) /* size of the central directory */
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)size_centraldir,4);
|
||||
|
||||
if (err==ZIP_OK) /* offset of start of central directory with respect to the
|
||||
starting disk number */
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)centraldir_pos_inzip ,4);
|
||||
|
||||
if (err==ZIP_OK) /* zipfile comment length */
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)size_global_comment,2);
|
||||
|
||||
if ((err==ZIP_OK) && (size_global_comment>0))
|
||||
if (fwrite(global_comment,(uInt)size_global_comment,1,zi->filezip) !=1 )
|
||||
err = ZIP_ERRNO;
|
||||
fclose(zi->filezip);
|
||||
TRYFREE(zi);
|
||||
|
||||
return err;
|
||||
}
|
|
@ -1,150 +0,0 @@
|
|||
/* zip.h -- IO for compress .zip files using zlib
|
||||
Version 0.15 alpha, Mar 19th, 1998,
|
||||
|
||||
Copyright (C) 1998 Gilles Vollant
|
||||
|
||||
This unzip package allow creates .ZIP file, compatible with PKZip 2.04g
|
||||
WinZip, InfoZip tools and compatible.
|
||||
Encryption and multi volume ZipFile (span) are not supported.
|
||||
Old compressions used by old PKZip 1.x are not supported
|
||||
|
||||
For uncompress .zip file, look at unzip.h
|
||||
|
||||
THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE
|
||||
CAN CHANGE IN FUTURE VERSION !!
|
||||
I WAIT FEEDBACK at mail info@winimage.com
|
||||
Visit also http://www.winimage.com/zLibDll/zip.htm for evolution
|
||||
|
||||
Condition of use and distribution are the same than zlib :
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* for more info about .ZIP format, see
|
||||
ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip
|
||||
PkWare has also a specification at :
|
||||
ftp://ftp.pkware.com/probdesc.zip
|
||||
*/
|
||||
|
||||
#ifndef _zip_H
|
||||
#define _zip_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#include "zlib.h"
|
||||
#endif
|
||||
|
||||
#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
|
||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||
from (void*) without cast */
|
||||
typedef struct TagzipFile__ { int unused; } zipFile__;
|
||||
typedef zipFile__ *zipFile;
|
||||
#else
|
||||
typedef voidp zipFile;
|
||||
#endif
|
||||
|
||||
#define ZIP_OK (0)
|
||||
#define ZIP_ERRNO (Z_ERRNO)
|
||||
#define ZIP_PARAMERROR (-102)
|
||||
#define ZIP_INTERNALERROR (-104)
|
||||
|
||||
/* tm_zip contain date/time info */
|
||||
typedef struct tm_zip_s
|
||||
{
|
||||
uInt tm_sec; /* seconds after the minute - [0,59] */
|
||||
uInt tm_min; /* minutes after the hour - [0,59] */
|
||||
uInt tm_hour; /* hours since midnight - [0,23] */
|
||||
uInt tm_mday; /* day of the month - [1,31] */
|
||||
uInt tm_mon; /* months since January - [0,11] */
|
||||
uInt tm_year; /* years - [1980..2044] */
|
||||
} tm_zip;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
tm_zip tmz_date; /* date in understandable format */
|
||||
uLong dosDate; /* if dos_date == 0, tmu_date is used */
|
||||
/* uLong flag; */ /* general purpose bit flag 2 bytes */
|
||||
|
||||
uLong internal_fa; /* internal file attributes 2 bytes */
|
||||
uLong external_fa; /* external file attributes 4 bytes */
|
||||
} zip_fileinfo;
|
||||
|
||||
extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
|
||||
/*
|
||||
Create a zipfile.
|
||||
pathname contain on Windows NT a filename like "c:\\zlib\\zlib111.zip" or on
|
||||
an Unix computer "zlib/zlib111.zip".
|
||||
if the file pathname exist and append=1, the zip will be created at the end
|
||||
of the file. (useful if the file contain a self extractor code)
|
||||
If the zipfile cannot be opened, the return value is NULL.
|
||||
Else, the return value is a zipFile Handle, usable with other function
|
||||
of this zip package.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level));
|
||||
/*
|
||||
Open a file in the ZIP for writing.
|
||||
filename : the filename in zip (if NULL, '-' without quote will be used
|
||||
*zipfi contain supplemental information
|
||||
if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
|
||||
contains the extrafield data the the local header
|
||||
if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
|
||||
contains the extrafield data the the local header
|
||||
if comment != NULL, comment contain the comment string
|
||||
method contain the compression method (0 for store, Z_DEFLATED for deflate)
|
||||
level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
|
||||
const voidp buf,
|
||||
unsigned len));
|
||||
/*
|
||||
Write data in the zipfile
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
|
||||
/*
|
||||
Close the current file in the zipfile
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipClose OF((zipFile file,
|
||||
const char* global_comment));
|
||||
/*
|
||||
Close the zipfile
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _zip_H */
|
|
@ -1,893 +0,0 @@
|
|||
/* zlib.h -- interface of the 'zlib' general purpose compression library
|
||||
version 1.1.3, July 9th, 1998
|
||||
|
||||
Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Jean-loup Gailly Mark Adler
|
||||
jloup@gzip.org madler@alumni.caltech.edu
|
||||
|
||||
|
||||
The data format used by the zlib library is described by RFCs (Request for
|
||||
Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
|
||||
(zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
|
||||
*/
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#define _ZLIB_H
|
||||
|
||||
#include "zconf.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ZLIB_VERSION "1.1.3"
|
||||
|
||||
/*
|
||||
The 'zlib' compression library provides in-memory compression and
|
||||
decompression functions, including integrity checks of the uncompressed
|
||||
data. This version of the library supports only one compression method
|
||||
(deflation) but other algorithms will be added later and will have the same
|
||||
stream interface.
|
||||
|
||||
Compression can be done in a single step if the buffers are large
|
||||
enough (for example if an input file is mmap'ed), or can be done by
|
||||
repeated calls of the compression function. In the latter case, the
|
||||
application must provide more input and/or consume the output
|
||||
(providing more output space) before each call.
|
||||
|
||||
The library also supports reading and writing files in gzip (.gz) format
|
||||
with an interface similar to that of stdio.
|
||||
|
||||
The library does not install any signal handler. The decoder checks
|
||||
the consistency of the compressed data, so the library should never
|
||||
crash even in case of corrupted input.
|
||||
*/
|
||||
|
||||
typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
|
||||
typedef void (*free_func) OF((voidpf opaque, voidpf address));
|
||||
|
||||
struct internal_state;
|
||||
|
||||
typedef struct z_stream_s {
|
||||
Bytef *next_in; /* next input byte */
|
||||
uInt avail_in; /* number of bytes available at next_in */
|
||||
uLong total_in; /* total nb of input bytes read so far */
|
||||
|
||||
Bytef *next_out; /* next output byte should be put there */
|
||||
uInt avail_out; /* remaining free space at next_out */
|
||||
uLong total_out; /* total nb of bytes output so far */
|
||||
|
||||
char *msg; /* last error message, NULL if no error */
|
||||
struct internal_state FAR *state; /* not visible by applications */
|
||||
|
||||
alloc_func zalloc; /* used to allocate the internal state */
|
||||
free_func zfree; /* used to free the internal state */
|
||||
voidpf opaque; /* private data object passed to zalloc and zfree */
|
||||
|
||||
int data_type; /* best guess about the data type: ascii or binary */
|
||||
uLong adler; /* adler32 value of the uncompressed data */
|
||||
uLong reserved; /* reserved for future use */
|
||||
} z_stream;
|
||||
|
||||
typedef z_stream FAR *z_streamp;
|
||||
|
||||
/*
|
||||
The application must update next_in and avail_in when avail_in has
|
||||
dropped to zero. It must update next_out and avail_out when avail_out
|
||||
has dropped to zero. The application must initialize zalloc, zfree and
|
||||
opaque before calling the init function. All other fields are set by the
|
||||
compression library and must not be updated by the application.
|
||||
|
||||
The opaque value provided by the application will be passed as the first
|
||||
parameter for calls of zalloc and zfree. This can be useful for custom
|
||||
memory management. The compression library attaches no meaning to the
|
||||
opaque value.
|
||||
|
||||
zalloc must return Z_NULL if there is not enough memory for the object.
|
||||
If zlib is used in a multi-threaded application, zalloc and zfree must be
|
||||
thread safe.
|
||||
|
||||
On 16-bit systems, the functions zalloc and zfree must be able to allocate
|
||||
exactly 65536 bytes, but will not be required to allocate more than this
|
||||
if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
|
||||
pointers returned by zalloc for objects of exactly 65536 bytes *must*
|
||||
have their offset normalized to zero. The default allocation function
|
||||
provided by this library ensures this (see zutil.c). To reduce memory
|
||||
requirements and avoid any allocation of 64K objects, at the expense of
|
||||
compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
|
||||
|
||||
The fields total_in and total_out can be used for statistics or
|
||||
progress reports. After compression, total_in holds the total size of
|
||||
the uncompressed data and may be saved for use in the decompressor
|
||||
(particularly if the decompressor wants to decompress everything in
|
||||
a single step).
|
||||
*/
|
||||
|
||||
/* constants */
|
||||
|
||||
#define Z_NO_FLUSH 0
|
||||
#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
|
||||
#define Z_SYNC_FLUSH 2
|
||||
#define Z_FULL_FLUSH 3
|
||||
#define Z_FINISH 4
|
||||
/* Allowed flush values; see deflate() below for details */
|
||||
|
||||
#define Z_OK 0
|
||||
#define Z_STREAM_END 1
|
||||
#define Z_NEED_DICT 2
|
||||
#define Z_ERRNO (-1)
|
||||
#define Z_STREAM_ERROR (-2)
|
||||
#define Z_DATA_ERROR (-3)
|
||||
#define Z_MEM_ERROR (-4)
|
||||
#define Z_BUF_ERROR (-5)
|
||||
#define Z_VERSION_ERROR (-6)
|
||||
/* Return codes for the compression/decompression functions. Negative
|
||||
* values are errors, positive values are used for special but normal events.
|
||||
*/
|
||||
|
||||
#define Z_NO_COMPRESSION 0
|
||||
#define Z_BEST_SPEED 1
|
||||
#define Z_BEST_COMPRESSION 9
|
||||
#define Z_DEFAULT_COMPRESSION (-1)
|
||||
/* compression levels */
|
||||
|
||||
#define Z_FILTERED 1
|
||||
#define Z_HUFFMAN_ONLY 2
|
||||
#define Z_DEFAULT_STRATEGY 0
|
||||
/* compression strategy; see deflateInit2() below for details */
|
||||
|
||||
#define Z_BINARY 0
|
||||
#define Z_ASCII 1
|
||||
#define Z_UNKNOWN 2
|
||||
/* Possible values of the data_type field */
|
||||
|
||||
#define Z_DEFLATED 8
|
||||
/* The deflate compression method (the only one supported in this version) */
|
||||
|
||||
#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
|
||||
|
||||
#define zlib_version zlibVersion()
|
||||
/* for compatibility with versions < 1.0.2 */
|
||||
|
||||
/* basic functions */
|
||||
|
||||
ZEXTERN const char * ZEXPORT zlibVersion OF((void));
|
||||
/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
|
||||
If the first character differs, the library code actually used is
|
||||
not compatible with the zlib.h header file used by the application.
|
||||
This check is automatically made by deflateInit and inflateInit.
|
||||
*/
|
||||
|
||||
/*
|
||||
ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
|
||||
|
||||
Initializes the internal stream state for compression. The fields
|
||||
zalloc, zfree and opaque must be initialized before by the caller.
|
||||
If zalloc and zfree are set to Z_NULL, deflateInit updates them to
|
||||
use default allocation functions.
|
||||
|
||||
The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
|
||||
1 gives best speed, 9 gives best compression, 0 gives no compression at
|
||||
all (the input data is simply copied a block at a time).
|
||||
Z_DEFAULT_COMPRESSION requests a default compromise between speed and
|
||||
compression (currently equivalent to level 6).
|
||||
|
||||
deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_STREAM_ERROR if level is not a valid compression level,
|
||||
Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
|
||||
with the version assumed by the caller (ZLIB_VERSION).
|
||||
msg is set to null if there is no error message. deflateInit does not
|
||||
perform any compression: this will be done by deflate().
|
||||
*/
|
||||
|
||||
|
||||
ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
|
||||
/*
|
||||
deflate compresses as much data as possible, and stops when the input
|
||||
buffer becomes empty or the output buffer becomes full. It may introduce some
|
||||
output latency (reading input without producing any output) except when
|
||||
forced to flush.
|
||||
|
||||
The detailed semantics are as follows. deflate performs one or both of the
|
||||
following actions:
|
||||
|
||||
- Compress more input starting at next_in and update next_in and avail_in
|
||||
accordingly. If not all input can be processed (because there is not
|
||||
enough room in the output buffer), next_in and avail_in are updated and
|
||||
processing will resume at this point for the next call of deflate().
|
||||
|
||||
- Provide more output starting at next_out and update next_out and avail_out
|
||||
accordingly. This action is forced if the parameter flush is non zero.
|
||||
Forcing flush frequently degrades the compression ratio, so this parameter
|
||||
should be set only when necessary (in interactive applications).
|
||||
Some output may be provided even if flush is not set.
|
||||
|
||||
Before the call of deflate(), the application should ensure that at least
|
||||
one of the actions is possible, by providing more input and/or consuming
|
||||
more output, and updating avail_in or avail_out accordingly; avail_out
|
||||
should never be zero before the call. The application can consume the
|
||||
compressed output when it wants, for example when the output buffer is full
|
||||
(avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
|
||||
and with zero avail_out, it must be called again after making room in the
|
||||
output buffer because there might be more output pending.
|
||||
|
||||
If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
|
||||
flushed to the output buffer and the output is aligned on a byte boundary, so
|
||||
that the decompressor can get all input data available so far. (In particular
|
||||
avail_in is zero after the call if enough output space has been provided
|
||||
before the call.) Flushing may degrade compression for some compression
|
||||
algorithms and so it should be used only when necessary.
|
||||
|
||||
If flush is set to Z_FULL_FLUSH, all output is flushed as with
|
||||
Z_SYNC_FLUSH, and the compression state is reset so that decompression can
|
||||
restart from this point if previous compressed data has been damaged or if
|
||||
random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
|
||||
the compression.
|
||||
|
||||
If deflate returns with avail_out == 0, this function must be called again
|
||||
with the same value of the flush parameter and more output space (updated
|
||||
avail_out), until the flush is complete (deflate returns with non-zero
|
||||
avail_out).
|
||||
|
||||
If the parameter flush is set to Z_FINISH, pending input is processed,
|
||||
pending output is flushed and deflate returns with Z_STREAM_END if there
|
||||
was enough output space; if deflate returns with Z_OK, this function must be
|
||||
called again with Z_FINISH and more output space (updated avail_out) but no
|
||||
more input data, until it returns with Z_STREAM_END or an error. After
|
||||
deflate has returned Z_STREAM_END, the only possible operations on the
|
||||
stream are deflateReset or deflateEnd.
|
||||
|
||||
Z_FINISH can be used immediately after deflateInit if all the compression
|
||||
is to be done in a single step. In this case, avail_out must be at least
|
||||
0.1% larger than avail_in plus 12 bytes. If deflate does not return
|
||||
Z_STREAM_END, then it must be called again as described above.
|
||||
|
||||
deflate() sets strm->adler to the adler32 checksum of all input read
|
||||
so far (that is, total_in bytes).
|
||||
|
||||
deflate() may update data_type if it can make a good guess about
|
||||
the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
|
||||
binary. This field is only for information purposes and does not affect
|
||||
the compression algorithm in any manner.
|
||||
|
||||
deflate() returns Z_OK if some progress has been made (more input
|
||||
processed or more output produced), Z_STREAM_END if all input has been
|
||||
consumed and all output has been produced (only when flush is set to
|
||||
Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
|
||||
if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
|
||||
(for example avail_in or avail_out was zero).
|
||||
*/
|
||||
|
||||
|
||||
ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
|
||||
/*
|
||||
All dynamically allocated data structures for this stream are freed.
|
||||
This function discards any unprocessed input and does not flush any
|
||||
pending output.
|
||||
|
||||
deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
|
||||
stream state was inconsistent, Z_DATA_ERROR if the stream was freed
|
||||
prematurely (some input or output was discarded). In the error case,
|
||||
msg may be set but then points to a static string (which must not be
|
||||
deallocated).
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
|
||||
|
||||
Initializes the internal stream state for decompression. The fields
|
||||
next_in, avail_in, zalloc, zfree and opaque must be initialized before by
|
||||
the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
|
||||
value depends on the compression method), inflateInit determines the
|
||||
compression method from the zlib header and allocates all data structures
|
||||
accordingly; otherwise the allocation will be deferred to the first call of
|
||||
inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
|
||||
use default allocation functions.
|
||||
|
||||
inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||
memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
|
||||
version assumed by the caller. msg is set to null if there is no error
|
||||
message. inflateInit does not perform any decompression apart from reading
|
||||
the zlib header if present: this will be done by inflate(). (So next_in and
|
||||
avail_in may be modified, but next_out and avail_out are unchanged.)
|
||||
*/
|
||||
|
||||
|
||||
ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
|
||||
/*
|
||||
inflate decompresses as much data as possible, and stops when the input
|
||||
buffer becomes empty or the output buffer becomes full. It may some
|
||||
introduce some output latency (reading input without producing any output)
|
||||
except when forced to flush.
|
||||
|
||||
The detailed semantics are as follows. inflate performs one or both of the
|
||||
following actions:
|
||||
|
||||
- Decompress more input starting at next_in and update next_in and avail_in
|
||||
accordingly. If not all input can be processed (because there is not
|
||||
enough room in the output buffer), next_in is updated and processing
|
||||
will resume at this point for the next call of inflate().
|
||||
|
||||
- Provide more output starting at next_out and update next_out and avail_out
|
||||
accordingly. inflate() provides as much output as possible, until there
|
||||
is no more input data or no more space in the output buffer (see below
|
||||
about the flush parameter).
|
||||
|
||||
Before the call of inflate(), the application should ensure that at least
|
||||
one of the actions is possible, by providing more input and/or consuming
|
||||
more output, and updating the next_* and avail_* values accordingly.
|
||||
The application can consume the uncompressed output when it wants, for
|
||||
example when the output buffer is full (avail_out == 0), or after each
|
||||
call of inflate(). If inflate returns Z_OK and with zero avail_out, it
|
||||
must be called again after making room in the output buffer because there
|
||||
might be more output pending.
|
||||
|
||||
If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much
|
||||
output as possible to the output buffer. The flushing behavior of inflate is
|
||||
not specified for values of the flush parameter other than Z_SYNC_FLUSH
|
||||
and Z_FINISH, but the current implementation actually flushes as much output
|
||||
as possible anyway.
|
||||
|
||||
inflate() should normally be called until it returns Z_STREAM_END or an
|
||||
error. However if all decompression is to be performed in a single step
|
||||
(a single call of inflate), the parameter flush should be set to
|
||||
Z_FINISH. In this case all pending input is processed and all pending
|
||||
output is flushed; avail_out must be large enough to hold all the
|
||||
uncompressed data. (The size of the uncompressed data may have been saved
|
||||
by the compressor for this purpose.) The next operation on this stream must
|
||||
be inflateEnd to deallocate the decompression state. The use of Z_FINISH
|
||||
is never required, but can be used to inform inflate that a faster routine
|
||||
may be used for the single inflate() call.
|
||||
|
||||
If a preset dictionary is needed at this point (see inflateSetDictionary
|
||||
below), inflate sets strm-adler to the adler32 checksum of the
|
||||
dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise
|
||||
it sets strm->adler to the adler32 checksum of all output produced
|
||||
so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or
|
||||
an error code as described below. At the end of the stream, inflate()
|
||||
checks that its computed adler32 checksum is equal to that saved by the
|
||||
compressor and returns Z_STREAM_END only if the checksum is correct.
|
||||
|
||||
inflate() returns Z_OK if some progress has been made (more input processed
|
||||
or more output produced), Z_STREAM_END if the end of the compressed data has
|
||||
been reached and all uncompressed output has been produced, Z_NEED_DICT if a
|
||||
preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
|
||||
corrupted (input stream not conforming to the zlib format or incorrect
|
||||
adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent
|
||||
(for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not
|
||||
enough memory, Z_BUF_ERROR if no progress is possible or if there was not
|
||||
enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR
|
||||
case, the application may then call inflateSync to look for a good
|
||||
compression block.
|
||||
*/
|
||||
|
||||
|
||||
ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
|
||||
/*
|
||||
All dynamically allocated data structures for this stream are freed.
|
||||
This function discards any unprocessed input and does not flush any
|
||||
pending output.
|
||||
|
||||
inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
|
||||
was inconsistent. In the error case, msg may be set but then points to a
|
||||
static string (which must not be deallocated).
|
||||
*/
|
||||
|
||||
/* Advanced functions */
|
||||
|
||||
/*
|
||||
The following functions are needed only in some special applications.
|
||||
*/
|
||||
|
||||
/*
|
||||
ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
|
||||
int level,
|
||||
int method,
|
||||
int windowBits,
|
||||
int memLevel,
|
||||
int strategy));
|
||||
|
||||
This is another version of deflateInit with more compression options. The
|
||||
fields next_in, zalloc, zfree and opaque must be initialized before by
|
||||
the caller.
|
||||
|
||||
The method parameter is the compression method. It must be Z_DEFLATED in
|
||||
this version of the library.
|
||||
|
||||
The windowBits parameter is the base two logarithm of the window size
|
||||
(the size of the history buffer). It should be in the range 8..15 for this
|
||||
version of the library. Larger values of this parameter result in better
|
||||
compression at the expense of memory usage. The default value is 15 if
|
||||
deflateInit is used instead.
|
||||
|
||||
The memLevel parameter specifies how much memory should be allocated
|
||||
for the internal compression state. memLevel=1 uses minimum memory but
|
||||
is slow and reduces compression ratio; memLevel=9 uses maximum memory
|
||||
for optimal speed. The default value is 8. See zconf.h for total memory
|
||||
usage as a function of windowBits and memLevel.
|
||||
|
||||
The strategy parameter is used to tune the compression algorithm. Use the
|
||||
value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
|
||||
filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
|
||||
string match). Filtered data consists mostly of small values with a
|
||||
somewhat random distribution. In this case, the compression algorithm is
|
||||
tuned to compress them better. The effect of Z_FILTERED is to force more
|
||||
Huffman coding and less string matching; it is somewhat intermediate
|
||||
between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
|
||||
the compression ratio but not the correctness of the compressed output even
|
||||
if it is not set appropriately.
|
||||
|
||||
deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||
memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
|
||||
method). msg is set to null if there is no error message. deflateInit2 does
|
||||
not perform any compression: this will be done by deflate().
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
|
||||
const Bytef *dictionary,
|
||||
uInt dictLength));
|
||||
/*
|
||||
Initializes the compression dictionary from the given byte sequence
|
||||
without producing any compressed output. This function must be called
|
||||
immediately after deflateInit, deflateInit2 or deflateReset, before any
|
||||
call of deflate. The compressor and decompressor must use exactly the same
|
||||
dictionary (see inflateSetDictionary).
|
||||
|
||||
The dictionary should consist of strings (byte sequences) that are likely
|
||||
to be encountered later in the data to be compressed, with the most commonly
|
||||
used strings preferably put towards the end of the dictionary. Using a
|
||||
dictionary is most useful when the data to be compressed is short and can be
|
||||
predicted with good accuracy; the data can then be compressed better than
|
||||
with the default empty dictionary.
|
||||
|
||||
Depending on the size of the compression data structures selected by
|
||||
deflateInit or deflateInit2, a part of the dictionary may in effect be
|
||||
discarded, for example if the dictionary is larger than the window size in
|
||||
deflate or deflate2. Thus the strings most likely to be useful should be
|
||||
put at the end of the dictionary, not at the front.
|
||||
|
||||
Upon return of this function, strm->adler is set to the Adler32 value
|
||||
of the dictionary; the decompressor may later use this value to determine
|
||||
which dictionary has been used by the compressor. (The Adler32 value
|
||||
applies to the whole dictionary even if only a subset of the dictionary is
|
||||
actually used by the compressor.)
|
||||
|
||||
deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
|
||||
parameter is invalid (such as NULL dictionary) or the stream state is
|
||||
inconsistent (for example if deflate has already been called for this stream
|
||||
or if the compression method is bsort). deflateSetDictionary does not
|
||||
perform any compression: this will be done by deflate().
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
|
||||
z_streamp source));
|
||||
/*
|
||||
Sets the destination stream as a complete copy of the source stream.
|
||||
|
||||
This function can be useful when several compression strategies will be
|
||||
tried, for example when there are several ways of pre-processing the input
|
||||
data with a filter. The streams that will be discarded should then be freed
|
||||
by calling deflateEnd. Note that deflateCopy duplicates the internal
|
||||
compression state which can be quite large, so this strategy is slow and
|
||||
can consume lots of memory.
|
||||
|
||||
deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
|
||||
(such as zalloc being NULL). msg is left unchanged in both source and
|
||||
destination.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
|
||||
/*
|
||||
This function is equivalent to deflateEnd followed by deflateInit,
|
||||
but does not free and reallocate all the internal compression state.
|
||||
The stream will keep the same compression level and any other attributes
|
||||
that may have been set by deflateInit2.
|
||||
|
||||
deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||
stream state was inconsistent (such as zalloc or state being NULL).
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
|
||||
int level,
|
||||
int strategy));
|
||||
/*
|
||||
Dynamically update the compression level and compression strategy. The
|
||||
interpretation of level and strategy is as in deflateInit2. This can be
|
||||
used to switch between compression and straight copy of the input data, or
|
||||
to switch to a different kind of input data requiring a different
|
||||
strategy. If the compression level is changed, the input available so far
|
||||
is compressed with the old level (and may be flushed); the new level will
|
||||
take effect only at the next call of deflate().
|
||||
|
||||
Before the call of deflateParams, the stream state must be set as for
|
||||
a call of deflate(), since the currently available input may have to
|
||||
be compressed and flushed. In particular, strm->avail_out must be non-zero.
|
||||
|
||||
deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
|
||||
stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
|
||||
if strm->avail_out was zero.
|
||||
*/
|
||||
|
||||
/*
|
||||
ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
|
||||
int windowBits));
|
||||
|
||||
This is another version of inflateInit with an extra parameter. The
|
||||
fields next_in, avail_in, zalloc, zfree and opaque must be initialized
|
||||
before by the caller.
|
||||
|
||||
The windowBits parameter is the base two logarithm of the maximum window
|
||||
size (the size of the history buffer). It should be in the range 8..15 for
|
||||
this version of the library. The default value is 15 if inflateInit is used
|
||||
instead. If a compressed stream with a larger window size is given as
|
||||
input, inflate() will return with the error code Z_DATA_ERROR instead of
|
||||
trying to allocate a larger window.
|
||||
|
||||
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||
memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative
|
||||
memLevel). msg is set to null if there is no error message. inflateInit2
|
||||
does not perform any decompression apart from reading the zlib header if
|
||||
present: this will be done by inflate(). (So next_in and avail_in may be
|
||||
modified, but next_out and avail_out are unchanged.)
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
|
||||
const Bytef *dictionary,
|
||||
uInt dictLength));
|
||||
/*
|
||||
Initializes the decompression dictionary from the given uncompressed byte
|
||||
sequence. This function must be called immediately after a call of inflate
|
||||
if this call returned Z_NEED_DICT. The dictionary chosen by the compressor
|
||||
can be determined from the Adler32 value returned by this call of
|
||||
inflate. The compressor and decompressor must use exactly the same
|
||||
dictionary (see deflateSetDictionary).
|
||||
|
||||
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
|
||||
parameter is invalid (such as NULL dictionary) or the stream state is
|
||||
inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
|
||||
expected one (incorrect Adler32 value). inflateSetDictionary does not
|
||||
perform any decompression: this will be done by subsequent calls of
|
||||
inflate().
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
|
||||
/*
|
||||
Skips invalid compressed data until a full flush point (see above the
|
||||
description of deflate with Z_FULL_FLUSH) can be found, or until all
|
||||
available input is skipped. No output is provided.
|
||||
|
||||
inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
|
||||
if no more input was provided, Z_DATA_ERROR if no flush point has been found,
|
||||
or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
|
||||
case, the application may save the current current value of total_in which
|
||||
indicates where valid compressed data was found. In the error case, the
|
||||
application may repeatedly call inflateSync, providing more input each time,
|
||||
until success or end of the input data.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
|
||||
/*
|
||||
This function is equivalent to inflateEnd followed by inflateInit,
|
||||
but does not free and reallocate all the internal decompression state.
|
||||
The stream will keep attributes that may have been set by inflateInit2.
|
||||
|
||||
inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||
stream state was inconsistent (such as zalloc or state being NULL).
|
||||
*/
|
||||
|
||||
|
||||
/* utility functions */
|
||||
|
||||
/*
|
||||
The following utility functions are implemented on top of the
|
||||
basic stream-oriented functions. To simplify the interface, some
|
||||
default options are assumed (compression level and memory usage,
|
||||
standard memory allocation functions). The source code of these
|
||||
utility functions can easily be modified if you need special options.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
|
||||
const Bytef *source, uLong sourceLen));
|
||||
/*
|
||||
Compresses the source buffer into the destination buffer. sourceLen is
|
||||
the byte length of the source buffer. Upon entry, destLen is the total
|
||||
size of the destination buffer, which must be at least 0.1% larger than
|
||||
sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
|
||||
compressed buffer.
|
||||
This function can be used to compress a whole file at once if the
|
||||
input file is mmap'ed.
|
||||
compress returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_BUF_ERROR if there was not enough room in the output
|
||||
buffer.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
|
||||
const Bytef *source, uLong sourceLen,
|
||||
int level));
|
||||
/*
|
||||
Compresses the source buffer into the destination buffer. The level
|
||||
parameter has the same meaning as in deflateInit. sourceLen is the byte
|
||||
length of the source buffer. Upon entry, destLen is the total size of the
|
||||
destination buffer, which must be at least 0.1% larger than sourceLen plus
|
||||
12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
|
||||
|
||||
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
|
||||
Z_STREAM_ERROR if the level parameter is invalid.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
|
||||
const Bytef *source, uLong sourceLen));
|
||||
/*
|
||||
Decompresses the source buffer into the destination buffer. sourceLen is
|
||||
the byte length of the source buffer. Upon entry, destLen is the total
|
||||
size of the destination buffer, which must be large enough to hold the
|
||||
entire uncompressed data. (The size of the uncompressed data must have
|
||||
been saved previously by the compressor and transmitted to the decompressor
|
||||
by some mechanism outside the scope of this compression library.)
|
||||
Upon exit, destLen is the actual size of the compressed buffer.
|
||||
This function can be used to decompress a whole file at once if the
|
||||
input file is mmap'ed.
|
||||
|
||||
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_BUF_ERROR if there was not enough room in the output
|
||||
buffer, or Z_DATA_ERROR if the input data was corrupted.
|
||||
*/
|
||||
|
||||
|
||||
typedef voidp gzFile;
|
||||
|
||||
ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
|
||||
/*
|
||||
Opens a gzip (.gz) file for reading or writing. The mode parameter
|
||||
is as in fopen ("rb" or "wb") but can also include a compression level
|
||||
("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
|
||||
Huffman only compression as in "wb1h". (See the description
|
||||
of deflateInit2 for more information about the strategy parameter.)
|
||||
|
||||
gzopen can be used to read a file which is not in gzip format; in this
|
||||
case gzread will directly read from the file without decompression.
|
||||
|
||||
gzopen returns NULL if the file could not be opened or if there was
|
||||
insufficient memory to allocate the (de)compression state; errno
|
||||
can be checked to distinguish the two cases (if errno is zero, the
|
||||
zlib error is Z_MEM_ERROR). */
|
||||
|
||||
ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
|
||||
/*
|
||||
gzdopen() associates a gzFile with the file descriptor fd. File
|
||||
descriptors are obtained from calls like open, dup, creat, pipe or
|
||||
fileno (in the file has been previously opened with fopen).
|
||||
The mode parameter is as in gzopen.
|
||||
The next call of gzclose on the returned gzFile will also close the
|
||||
file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
|
||||
descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
|
||||
gzdopen returns NULL if there was insufficient memory to allocate
|
||||
the (de)compression state.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
|
||||
/*
|
||||
Dynamically update the compression level or strategy. See the description
|
||||
of deflateInit2 for the meaning of these parameters.
|
||||
gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
|
||||
opened for writing.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
|
||||
/*
|
||||
Reads the given number of uncompressed bytes from the compressed file.
|
||||
If the input file was not in gzip format, gzread copies the given number
|
||||
of bytes into the buffer.
|
||||
gzread returns the number of uncompressed bytes actually read (0 for
|
||||
end of file, -1 for error). */
|
||||
|
||||
ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
|
||||
const voidp buf, unsigned len));
|
||||
/*
|
||||
Writes the given number of uncompressed bytes into the compressed file.
|
||||
gzwrite returns the number of uncompressed bytes actually written
|
||||
(0 in case of error).
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
|
||||
/*
|
||||
Converts, formats, and writes the args to the compressed file under
|
||||
control of the format string, as in fprintf. gzprintf returns the number of
|
||||
uncompressed bytes actually written (0 in case of error).
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
|
||||
/*
|
||||
Writes the given null-terminated string to the compressed file, excluding
|
||||
the terminating null character.
|
||||
gzputs returns the number of characters written, or -1 in case of error.
|
||||
*/
|
||||
|
||||
ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
|
||||
/*
|
||||
Reads bytes from the compressed file until len-1 characters are read, or
|
||||
a newline character is read and transferred to buf, or an end-of-file
|
||||
condition is encountered. The string is then terminated with a null
|
||||
character.
|
||||
gzgets returns buf, or Z_NULL in case of error.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
|
||||
/*
|
||||
Writes c, converted to an unsigned char, into the compressed file.
|
||||
gzputc returns the value that was written, or -1 in case of error.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
|
||||
/*
|
||||
Reads one byte from the compressed file. gzgetc returns this byte
|
||||
or -1 in case of end of file or error.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
|
||||
/*
|
||||
Flushes all pending output into the compressed file. The parameter
|
||||
flush is as in the deflate() function. The return value is the zlib
|
||||
error number (see function gzerror below). gzflush returns Z_OK if
|
||||
the flush parameter is Z_FINISH and all output could be flushed.
|
||||
gzflush should be called only when strictly necessary because it can
|
||||
degrade compression.
|
||||
*/
|
||||
|
||||
ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
|
||||
z_off_t offset, int whence));
|
||||
/*
|
||||
Sets the starting position for the next gzread or gzwrite on the
|
||||
given compressed file. The offset represents a number of bytes in the
|
||||
uncompressed data stream. The whence parameter is defined as in lseek(2);
|
||||
the value SEEK_END is not supported.
|
||||
If the file is opened for reading, this function is emulated but can be
|
||||
extremely slow. If the file is opened for writing, only forward seeks are
|
||||
supported; gzseek then compresses a sequence of zeroes up to the new
|
||||
starting position.
|
||||
|
||||
gzseek returns the resulting offset location as measured in bytes from
|
||||
the beginning of the uncompressed stream, or -1 in case of error, in
|
||||
particular if the file is opened for writing and the new starting position
|
||||
would be before the current position.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
|
||||
/*
|
||||
Rewinds the given file. This function is supported only for reading.
|
||||
|
||||
gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
|
||||
*/
|
||||
|
||||
ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
|
||||
/*
|
||||
Returns the starting position for the next gzread or gzwrite on the
|
||||
given compressed file. This position represents a number of bytes in the
|
||||
uncompressed data stream.
|
||||
|
||||
gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzeof OF((gzFile file));
|
||||
/*
|
||||
Returns 1 when EOF has previously been detected reading the given
|
||||
input stream, otherwise zero.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzclose OF((gzFile file));
|
||||
/*
|
||||
Flushes all pending output if necessary, closes the compressed file
|
||||
and deallocates all the (de)compression state. The return value is the zlib
|
||||
error number (see function gzerror below).
|
||||
*/
|
||||
|
||||
ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
|
||||
/*
|
||||
Returns the error message for the last error which occurred on the
|
||||
given compressed file. errnum is set to zlib error number. If an
|
||||
error occurred in the file system and not in the compression library,
|
||||
errnum is set to Z_ERRNO and the application may consult errno
|
||||
to get the exact error code.
|
||||
*/
|
||||
|
||||
/* checksum functions */
|
||||
|
||||
/*
|
||||
These functions are not related to compression but are exported
|
||||
anyway because they might be useful in applications using the
|
||||
compression library.
|
||||
*/
|
||||
|
||||
ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
|
||||
|
||||
/*
|
||||
Update a running Adler-32 checksum with the bytes buf[0..len-1] and
|
||||
return the updated checksum. If buf is NULL, this function returns
|
||||
the required initial value for the checksum.
|
||||
An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
|
||||
much faster. Usage example:
|
||||
|
||||
uLong adler = adler32(0L, Z_NULL, 0);
|
||||
|
||||
while (read_buffer(buffer, length) != EOF) {
|
||||
adler = adler32(adler, buffer, length);
|
||||
}
|
||||
if (adler != original_adler) error();
|
||||
*/
|
||||
|
||||
ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
|
||||
/*
|
||||
Update a running crc with the bytes buf[0..len-1] and return the updated
|
||||
crc. If buf is NULL, this function returns the required initial value
|
||||
for the crc. Pre- and post-conditioning (one's complement) is performed
|
||||
within this function so it shouldn't be done by the application.
|
||||
Usage example:
|
||||
|
||||
uLong crc = crc32(0L, Z_NULL, 0);
|
||||
|
||||
while (read_buffer(buffer, length) != EOF) {
|
||||
crc = crc32(crc, buffer, length);
|
||||
}
|
||||
if (crc != original_crc) error();
|
||||
*/
|
||||
|
||||
|
||||
/* various hacks, don't look :) */
|
||||
|
||||
/* deflateInit and inflateInit are macros to allow checking the zlib version
|
||||
* and the compiler's view of z_stream:
|
||||
*/
|
||||
ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
|
||||
const char *version, int stream_size));
|
||||
ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
|
||||
const char *version, int stream_size));
|
||||
ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
|
||||
int windowBits, int memLevel,
|
||||
int strategy, const char *version,
|
||||
int stream_size));
|
||||
ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
|
||||
const char *version, int stream_size));
|
||||
#define deflateInit(strm, level) \
|
||||
deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
|
||||
#define inflateInit(strm) \
|
||||
inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
|
||||
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
|
||||
deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
|
||||
(strategy), ZLIB_VERSION, sizeof(z_stream))
|
||||
#define inflateInit2(strm, windowBits) \
|
||||
inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
|
||||
|
||||
|
||||
#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
|
||||
struct internal_state {int dummy;}; /* hack for buggy compilers */
|
||||
#endif
|
||||
|
||||
ZEXTERN const char * ZEXPORT zError OF((int err));
|
||||
ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
|
||||
ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ZLIB_H */
|