├── zpCmd ├── Stdafx.h ├── pthreadVCE2.dll ├── pthreadVCE2.lib ├── fileEnum.h ├── zpCmd-vs2010.vcxproj.filters ├── zpCmd-vs2012.vcxproj.filters ├── fileEnum.cpp ├── zpExplorer.h ├── zpCmd-vs2005.vcproj ├── zpCmd.cpp ├── zpCmd-vs2010.vcxproj └── zpCmd-vs2012.vcxproj ├── README.md ├── bin ├── zpCmd.exe ├── zpEditor.exe └── pthreadVCE2.dll ├── zpEditor ├── resource.h ├── zpEditor.rc ├── UserImages.bmp ├── pthreadVCE2.dll ├── pthreadVCE2.lib ├── res │ ├── Toolbar.bmp │ ├── ImageLeft.bmp │ ├── Toolbar256.bmp │ ├── zpEditor.ico │ ├── zpEditor.rc2 │ └── zpEditorDoc.ico ├── ProgressDialog.cpp ├── stdafx.cpp ├── targetver.h ├── zpEditor.h ├── ProgressDialog.h ├── FolderDialog.h ├── zpEditorDoc.h ├── MainFrm.h ├── LeftView.h ├── zpEditorView.h ├── stdafx.h ├── zpEditor_vs2010.vcxproj.filters ├── zpEditor_vs2012.vcxproj.filters ├── FolderDialog.cpp ├── zpEditorDoc.cpp ├── zpEditor.cpp └── LeftView.cpp ├── zpack ├── zpPackage.cpp ├── WriteCompressFile.h ├── zlib │ ├── inffast.h │ ├── uncompr.c │ ├── inftrees.h │ ├── compress.c │ ├── adler32.c │ ├── inflate.h │ ├── inffixed.h │ ├── zutil.h │ ├── zutil.c │ ├── trees.h │ └── zconf.h ├── zpack-vs2010.vcxproj.filters ├── zpack-vs2012.vcxproj.filters ├── zpFile.h ├── zpWriteFile.h ├── zpCompressedFile.h ├── zpack-vs2005.sln ├── zpack.cpp ├── WriteCompressFile.cpp ├── zpWriteFile.cpp ├── zpFile.cpp ├── zpack-vs2010.sln ├── zpack-vs2012.sln ├── pthread │ ├── semaphore.h │ └── sched.h ├── zpack.h ├── zpack-vs2005.vcproj ├── zpPackage.h ├── zpack_vs2010.vcxproj ├── zpack_vs2012.vcxproj └── zpCompressedFile.cpp └── LICENSE /zpCmd/Stdafx.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | zpack 2 | ===== 3 | 4 | 打包系统及工具 5 | -------------------------------------------------------------------------------- /bin/zpCmd.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dxmgame/zpack/HEAD/bin/zpCmd.exe -------------------------------------------------------------------------------- /bin/zpEditor.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dxmgame/zpack/HEAD/bin/zpEditor.exe -------------------------------------------------------------------------------- /bin/pthreadVCE2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dxmgame/zpack/HEAD/bin/pthreadVCE2.dll -------------------------------------------------------------------------------- /zpEditor/resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dxmgame/zpack/HEAD/zpEditor/resource.h -------------------------------------------------------------------------------- /zpack/zpPackage.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dxmgame/zpack/HEAD/zpack/zpPackage.cpp -------------------------------------------------------------------------------- /zpCmd/pthreadVCE2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dxmgame/zpack/HEAD/zpCmd/pthreadVCE2.dll -------------------------------------------------------------------------------- /zpCmd/pthreadVCE2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dxmgame/zpack/HEAD/zpCmd/pthreadVCE2.lib -------------------------------------------------------------------------------- /zpEditor/zpEditor.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dxmgame/zpack/HEAD/zpEditor/zpEditor.rc -------------------------------------------------------------------------------- /zpEditor/UserImages.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dxmgame/zpack/HEAD/zpEditor/UserImages.bmp -------------------------------------------------------------------------------- /zpEditor/pthreadVCE2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dxmgame/zpack/HEAD/zpEditor/pthreadVCE2.dll -------------------------------------------------------------------------------- /zpEditor/pthreadVCE2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dxmgame/zpack/HEAD/zpEditor/pthreadVCE2.lib -------------------------------------------------------------------------------- /zpEditor/res/Toolbar.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dxmgame/zpack/HEAD/zpEditor/res/Toolbar.bmp -------------------------------------------------------------------------------- /zpEditor/ProgressDialog.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dxmgame/zpack/HEAD/zpEditor/ProgressDialog.cpp -------------------------------------------------------------------------------- /zpEditor/res/ImageLeft.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dxmgame/zpack/HEAD/zpEditor/res/ImageLeft.bmp -------------------------------------------------------------------------------- /zpEditor/res/Toolbar256.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dxmgame/zpack/HEAD/zpEditor/res/Toolbar256.bmp -------------------------------------------------------------------------------- /zpEditor/res/zpEditor.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dxmgame/zpack/HEAD/zpEditor/res/zpEditor.ico -------------------------------------------------------------------------------- /zpEditor/res/zpEditor.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dxmgame/zpack/HEAD/zpEditor/res/zpEditor.rc2 -------------------------------------------------------------------------------- /zpEditor/res/zpEditorDoc.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dxmgame/zpack/HEAD/zpEditor/res/zpEditorDoc.ico -------------------------------------------------------------------------------- /zpEditor/stdafx.cpp: -------------------------------------------------------------------------------- 1 | 2 | // stdafx.cpp : source file that includes just the standard includes 3 | // zpEditor.pch will be the pre-compiled header 4 | // stdafx.obj will contain the pre-compiled type information 5 | 6 | #include "stdafx.h" 7 | 8 | 9 | -------------------------------------------------------------------------------- /zpEditor/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /zpack/WriteCompressFile.h: -------------------------------------------------------------------------------- 1 | #ifndef __ZP_WRITE_COMPRESS_FILE_H__ 2 | #define __ZP_WRITE_COMPRESS_FILE_H__ 3 | 4 | #include 5 | 6 | namespace zp 7 | { 8 | 9 | u32 writeCompressFile(FILE* dstFile, u64 offset, FILE* srcFile, u32 srcFileSize, u32 chunkSize, u32& flag, 10 | std::vector& chunkData, std::vector& compressBuffer, std::vector& chunkPosBuffer); 11 | 12 | } 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /zpack/zlib/inffast.h: -------------------------------------------------------------------------------- 1 | /* inffast.h -- header to use inffast.c 2 | * Copyright (C) 1995-2003 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | void inflate_fast OF((z_streamp strm, unsigned start)); 12 | -------------------------------------------------------------------------------- /zpCmd/fileEnum.h: -------------------------------------------------------------------------------- 1 | #ifndef __FILE_ENUM_H__ 2 | #define __FILE_ENUM_H__ 3 | 4 | #include 5 | #include "zpack.h" 6 | 7 | typedef bool (*EnumCallback)(const zp::String& path, zp::u32 fileSize, void* param); 8 | 9 | bool enumFile(const zp::String& searchPath, EnumCallback callback, void* param); 10 | 11 | bool addPackFile(const zp::String& filename, zp::u32 fileSize, void* param); 12 | 13 | bool countFile(const zp::String& filename, zp::u32 fileSize, void* param); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /zpack/zpack-vs2010.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /zpack/zpack-vs2012.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /zpCmd/zpCmd-vs2010.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /zpCmd/zpCmd-vs2012.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /zpack/zpFile.h: -------------------------------------------------------------------------------- 1 | #ifndef __ZP_FILE_H__ 2 | #define __ZP_FILE_H__ 3 | 4 | #include "zpack.h" 5 | 6 | namespace zp 7 | { 8 | 9 | class Package; 10 | 11 | class File : public IReadFile 12 | { 13 | public: 14 | File(const Package* package, u64 offset, u32 size, u32 flag, u64 nameHash); 15 | ~File(); 16 | 17 | virtual u32 size() const; 18 | 19 | virtual u32 availableSize() const; 20 | 21 | virtual u32 flag() const; 22 | 23 | virtual void seek(u32 pos); 24 | 25 | virtual u32 tell() const; 26 | 27 | virtual u32 read(u8* buffer, u32 size); 28 | 29 | private: 30 | void seekInPackage(); 31 | 32 | private: 33 | u64 m_offset; 34 | u64 m_nameHash; 35 | const Package* m_package; 36 | u32 m_flag; 37 | u32 m_size; 38 | u32 m_readPos; 39 | }; 40 | 41 | } 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /zpack/zpWriteFile.h: -------------------------------------------------------------------------------- 1 | #ifndef __ZP_WRITE_FILE_H__ 2 | #define __ZP_WRITE_FILE_H__ 3 | 4 | #include "zpack.h" 5 | 6 | namespace zp 7 | { 8 | 9 | class Package; 10 | 11 | class WriteFile : public IWriteFile 12 | { 13 | public: 14 | WriteFile(Package* package, u64 offset, u32 size, u32 flag, u64 nameHash); 15 | ~WriteFile(); 16 | 17 | virtual u32 size() const; 18 | 19 | virtual u32 flag() const; 20 | 21 | virtual void seek(u32 pos); 22 | 23 | virtual u32 tell() const; 24 | 25 | virtual u32 write(const u8* buffer, u32 size); 26 | 27 | private: 28 | void seekInPackage(); 29 | 30 | private: 31 | Package* m_package; 32 | u64 m_offset; 33 | u32 m_flag; 34 | u32 m_size; //for compressed file, this is packSize 35 | u64 m_nameHash; 36 | u32 m_writePos; 37 | }; 38 | 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /zpEditor/zpEditor.h: -------------------------------------------------------------------------------- 1 | 2 | // zpEditor.h : main header file for the zpEditor application 3 | // 4 | #pragma once 5 | 6 | #ifndef __AFXWIN_H__ 7 | #error "include 'stdafx.h' before including this file for PCH" 8 | #endif 9 | 10 | #include "resource.h" // main symbols 11 | 12 | 13 | // CzpEditorApp: 14 | // See zpEditor.cpp for the implementation of this class 15 | // 16 | 17 | class CzpEditorApp : public CWinAppEx 18 | { 19 | public: 20 | CzpEditorApp(); 21 | 22 | 23 | // Overrides 24 | public: 25 | virtual BOOL InitInstance(); 26 | virtual int ExitInstance(); 27 | 28 | // Implementation 29 | BOOL m_bHiColorIcons; 30 | 31 | virtual void PreLoadState(); 32 | virtual void LoadCustomState(); 33 | virtual void SaveCustomState(); 34 | 35 | afx_msg void OnAppAbout(); 36 | DECLARE_MESSAGE_MAP() 37 | }; 38 | 39 | extern CzpEditorApp theApp; 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 dxmgame 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /zpack/zpCompressedFile.h: -------------------------------------------------------------------------------- 1 | #ifndef __ZP_COMPRESSED_FILE_H__ 2 | #define __ZP_COMPRESSED_FILE_H__ 3 | 4 | #include "zpack.h" 5 | 6 | namespace zp 7 | { 8 | 9 | class Package; 10 | 11 | class CompressedFile : public IReadFile 12 | { 13 | public: 14 | CompressedFile(const Package* package, u64 offset, u32 compressedSize, u32 originSize, 15 | u32 chunkSize, u32 flag, u64 nameHash); 16 | virtual ~CompressedFile(); 17 | 18 | //from IFiled 19 | virtual u32 size() const; 20 | 21 | virtual u32 availableSize() const; 22 | 23 | virtual u32 flag() const; 24 | 25 | virtual void seek(u32 pos); 26 | 27 | virtual u32 tell() const; 28 | 29 | virtual u32 read(u8* buffer, u32 size); 30 | 31 | private: 32 | bool checkChunkPos() const; 33 | 34 | void seekInPackage(u32 offset); 35 | 36 | u32 oneChunkRead(u8* buffer, u32 size); 37 | 38 | bool readChunk(u32 chunkIndex, u32 offset, u32 readSize, u8* buffer); 39 | 40 | private: 41 | u64 m_offset; 42 | u64 m_nameHash; 43 | const Package* m_package; 44 | u32 m_chunkSize; 45 | u32 m_flag; 46 | u32 m_compressedSize; 47 | u32 m_originSize; 48 | 49 | u32 m_readPos; 50 | u32 m_chunkCount; 51 | u32* m_chunkPos; 52 | u8* m_fileData; //available when there's only 1 chunk 53 | u8** m_chunkData; //available when there's more than 1 chunk 54 | }; 55 | 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /zpEditor/ProgressDialog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "afxcmn.h" 3 | #include 4 | #include 5 | 6 | class ZpExplorer; 7 | // ProgressDialog dialog 8 | 9 | class ProgressDialog : public CDialogEx 10 | { 11 | friend class CzpEditorView; 12 | 13 | DECLARE_DYNAMIC(ProgressDialog) 14 | 15 | public: 16 | ProgressDialog(CWnd* pParent = NULL); // standard constructor 17 | virtual ~ProgressDialog(); 18 | 19 | virtual BOOL OnInitDialog(); 20 | 21 | // Dialog Data 22 | enum { IDD = IDD_DLG_PROGRESS }; 23 | 24 | void setProgress(const zp::String& currentFilename, float progress); 25 | 26 | protected: 27 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support 28 | 29 | static DWORD WINAPI threadFunc(LPVOID pointer); 30 | 31 | DECLARE_MESSAGE_MAP() 32 | 33 | public: 34 | ZpExplorer* m_explorer; 35 | bool m_running; 36 | 37 | CRITICAL_SECTION m_lock; 38 | zp::String m_currentFilename; 39 | zp::u64 m_totalFileSize; 40 | zp::u64 m_doneFileSize; 41 | int m_progress; 42 | 43 | CString m_filename; 44 | CProgressCtrl m_progressCtrl; 45 | 46 | enum Operation 47 | { 48 | OP_ADD = 0, 49 | OP_EXTRACT, 50 | OP_DEFRAG 51 | }; 52 | Operation m_operation; 53 | const std::vector>* m_params; 54 | 55 | HANDLE m_thread; 56 | 57 | afx_msg void OnBnClickedCancel(); 58 | afx_msg void OnTimer(UINT_PTR nIDEvent); 59 | }; 60 | -------------------------------------------------------------------------------- /zpEditor/FolderDialog.h: -------------------------------------------------------------------------------- 1 | // FolderDialog.h: interface for the CFolderDialog class. 2 | // $Copyright ?1998, Kenneth M. Reed, All Rights Reserved. $ 3 | // $Header: FolderDialog.h Revision:1.11 Mon Apr 06 12:04:50 1998 KenReed $ 4 | 5 | #ifndef _CFolderDialog_ 6 | #define _CFolderDialog_ 7 | 8 | //#include 9 | 10 | class CFolderDialog 11 | { 12 | friend static int CALLBACK BrowseDirectoryCallback( 13 | HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM lpData); 14 | 15 | public: 16 | CFolderDialog( LPCTSTR lpszFolderName = NULL, 17 | LPCTSTR lpszTitle = NULL, 18 | DWORD dwFlags = NULL/*BIF_RETURNONLYFSDIRS*/, 19 | CWnd* pParentWnd = NULL); 20 | virtual ~CFolderDialog(); 21 | virtual int DoModal(); 22 | CString GetPathName() const; 23 | 24 | protected: 25 | virtual void OnInitDialog(); 26 | virtual void OnSelChanged(ITEMIDLIST* pIdl); 27 | virtual void CallbackFunction(HWND hWnd, UINT uMsg, LPARAM lParam); 28 | 29 | void EnableOK(BOOL bEnable = TRUE); 30 | void SetSelection(LPCTSTR pszSelection); 31 | void SetSelection(ITEMIDLIST* pIdl); 32 | void SetStatusText(LPCTSTR pszStatusText); 33 | CString ShortName(const CString& strName); 34 | 35 | public: 36 | BROWSEINFO m_bi; 37 | 38 | protected: 39 | CString m_strInitialFolderName; 40 | CString m_strFinalFolderName; 41 | 42 | TCHAR m_szDisplayName[MAX_PATH]; 43 | TCHAR m_szPath[MAX_PATH]; 44 | 45 | HWND m_hDialogBox; 46 | 47 | 48 | }; 49 | 50 | #endif // _CFolderDialog_ 51 | -------------------------------------------------------------------------------- /zpEditor/zpEditorDoc.h: -------------------------------------------------------------------------------- 1 | 2 | // zpEditorDoc.h : interface of the CzpEditorDoc class 3 | // 4 | #pragma once 5 | 6 | #include "ProgressDialog.h" 7 | #include "zpExplorer.h" 8 | #include 9 | 10 | class CzpEditorDoc : public CDocument 11 | { 12 | protected: // create from serialization only 13 | CzpEditorDoc(); 14 | DECLARE_DYNCREATE(CzpEditorDoc) 15 | 16 | // Attributes 17 | public: 18 | ZpExplorer& GetZpExplorer(); 19 | 20 | public: 21 | 22 | // Overrides 23 | public: 24 | virtual BOOL OnNewDocument(); 25 | virtual BOOL OnOpenDocument(LPCTSTR lpszPathName); 26 | virtual void Serialize(CArchive& ar); 27 | #ifdef SHARED_HANDLERS 28 | virtual void InitializeSearchContent(); 29 | virtual void OnDrawThumbnail(CDC& dc, LPRECT lprcBounds); 30 | #endif // SHARED_HANDLERS 31 | 32 | // Implementation 33 | public: 34 | virtual ~CzpEditorDoc(); 35 | #ifdef _DEBUG 36 | virtual void AssertValid() const; 37 | virtual void Dump(CDumpContext& dc) const; 38 | #endif 39 | 40 | void addFilesToPackage(std::vector& filenames); 41 | 42 | protected: 43 | void startOperation(ProgressDialog::Operation op, zp::u64 totalFileSize, 44 | const std::vector>* params); 45 | 46 | // Generated message map functions 47 | protected: 48 | DECLARE_MESSAGE_MAP() 49 | 50 | #ifdef SHARED_HANDLERS 51 | // Helper function that sets search content for a Search Handler 52 | void SetSearchContent(const CString& value); 53 | #endif // SHARED_HANDLERS 54 | 55 | private: 56 | ZpExplorer m_explorer; 57 | 58 | public: 59 | afx_msg void OnEditDefrag(); 60 | }; 61 | -------------------------------------------------------------------------------- /zpack/zpack-vs2005.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 9.00 3 | # Visual Studio 2005 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zpack", "zpack-vs2005.vcproj", "{0566CBD4-94CB-43CC-9233-A07A63455E62}" 5 | EndProject 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zpCmd", "..\zpCmd\zpCmd-vs2005.vcproj", "{79ABFEDD-5F1D-4CF3-9156-8AE0B7586DB5}" 7 | ProjectSection(ProjectDependencies) = postProject 8 | {0566CBD4-94CB-43CC-9233-A07A63455E62} = {0566CBD4-94CB-43CC-9233-A07A63455E62} 9 | EndProjectSection 10 | EndProject 11 | Global 12 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 13 | Debug|Win32 = Debug|Win32 14 | Release|Win32 = Release|Win32 15 | EndGlobalSection 16 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 17 | {0566CBD4-94CB-43CC-9233-A07A63455E62}.Debug|Win32.ActiveCfg = Debug|Win32 18 | {0566CBD4-94CB-43CC-9233-A07A63455E62}.Debug|Win32.Build.0 = Debug|Win32 19 | {0566CBD4-94CB-43CC-9233-A07A63455E62}.Release|Win32.ActiveCfg = Release|Win32 20 | {0566CBD4-94CB-43CC-9233-A07A63455E62}.Release|Win32.Build.0 = Release|Win32 21 | {79ABFEDD-5F1D-4CF3-9156-8AE0B7586DB5}.Debug|Win32.ActiveCfg = Debug|Win32 22 | {79ABFEDD-5F1D-4CF3-9156-8AE0B7586DB5}.Debug|Win32.Build.0 = Debug|Win32 23 | {79ABFEDD-5F1D-4CF3-9156-8AE0B7586DB5}.Release|Win32.ActiveCfg = Release|Win32 24 | {79ABFEDD-5F1D-4CF3-9156-8AE0B7586DB5}.Release|Win32.Build.0 = Release|Win32 25 | EndGlobalSection 26 | GlobalSection(SolutionProperties) = preSolution 27 | HideSolutionNode = FALSE 28 | EndGlobalSection 29 | EndGlobal 30 | -------------------------------------------------------------------------------- /zpEditor/MainFrm.h: -------------------------------------------------------------------------------- 1 | 2 | // MainFrm.h : interface of the CMainFrame class 3 | // 4 | 5 | #pragma once 6 | class CzpEditorView; 7 | 8 | class CMainFrame : public CFrameWndEx 9 | { 10 | 11 | protected: // create from serialization only 12 | CMainFrame(); 13 | DECLARE_DYNCREATE(CMainFrame) 14 | 15 | // Attributes 16 | protected: 17 | CSplitterWnd m_wndSplitter; 18 | public: 19 | 20 | // Operations 21 | public: 22 | 23 | // Overrides 24 | public: 25 | virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext); 26 | virtual BOOL PreCreateWindow(CREATESTRUCT& cs); 27 | virtual BOOL LoadFrame(UINT nIDResource, DWORD dwDefaultStyle = WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, CWnd* pParentWnd = NULL, CCreateContext* pContext = NULL); 28 | 29 | // Implementation 30 | public: 31 | virtual ~CMainFrame(); 32 | CzpEditorView* GetRightPane(); 33 | #ifdef _DEBUG 34 | virtual void AssertValid() const; 35 | virtual void Dump(CDumpContext& dc) const; 36 | #endif 37 | 38 | protected: // control bar embedded members 39 | //CMFCMenuBar m_wndMenuBar; 40 | CMFCToolBar m_wndToolBar; 41 | CMFCStatusBar m_wndStatusBar; 42 | CMFCToolBarImages m_UserImages; 43 | 44 | // Generated message map functions 45 | protected: 46 | afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); 47 | afx_msg LRESULT OnToolbarCreateNew(WPARAM wp, LPARAM lp); 48 | DECLARE_MESSAGE_MAP() 49 | public: 50 | afx_msg void OnFileNew(); 51 | afx_msg void OnFileOpen(); 52 | afx_msg void OnFileDefrag(); 53 | afx_msg void OnUpdateMenu(CCmdUI* pCmdUI); 54 | afx_msg void OnDropFiles(HDROP hDropInfo); 55 | }; 56 | 57 | 58 | -------------------------------------------------------------------------------- /zpEditor/LeftView.h: -------------------------------------------------------------------------------- 1 | 2 | // LeftView.h : interface of the CLeftView class 3 | // 4 | 5 | #pragma once 6 | #include "ProgressDialog.h" 7 | 8 | struct ZpNode; 9 | class CzpEditorDoc; 10 | 11 | class CLeftView : public CTreeView 12 | { 13 | protected: // create from serialization only 14 | CLeftView(); 15 | DECLARE_DYNCREATE(CLeftView) 16 | 17 | // Attributes 18 | public: 19 | CzpEditorDoc* GetDocument(); 20 | 21 | // Operations 22 | public: 23 | 24 | // Overrides 25 | public: 26 | virtual BOOL PreCreateWindow(CREATESTRUCT& cs); 27 | protected: 28 | virtual void OnInitialUpdate(); // called first time after construct 29 | 30 | virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint); 31 | // Implementation 32 | public: 33 | virtual ~CLeftView(); 34 | #ifdef _DEBUG 35 | virtual void AssertValid() const; 36 | virtual void Dump(CDumpContext& dc) const; 37 | #endif 38 | 39 | protected: 40 | void updateNode(HTREEITEM ti); 41 | void OnSelectChanged(NMHDR *pNMHDR, LRESULT *pResult); 42 | 43 | ZpNode* getSelectedNode(); 44 | void startOperation(ProgressDialog::Operation op, zp::u64 totalFileSize, 45 | const std::vector>* operations); 46 | 47 | void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); 48 | 49 | private: 50 | CImageList m_imageList; 51 | 52 | // Generated message map functions 53 | protected: 54 | DECLARE_MESSAGE_MAP() 55 | public: 56 | afx_msg void OnEditAdd(); 57 | afx_msg void OnEditAddFolder(); 58 | afx_msg void OnEditDelete(); 59 | afx_msg void OnEditExtract(); 60 | }; 61 | 62 | #ifndef _DEBUG // debug version in LeftView.cpp 63 | inline CzpEditorDoc* CLeftView::GetDocument() 64 | { return reinterpret_cast(m_pDocument); } 65 | #endif 66 | 67 | -------------------------------------------------------------------------------- /zpCmd/fileEnum.cpp: -------------------------------------------------------------------------------- 1 | #include "Stdafx.h" 2 | #include "fileEnum.h" 3 | #include 4 | #include 5 | #include 6 | #include "zpack.h" 7 | #include "zpExplorer.h" 8 | #include "windows.h" 9 | 10 | #ifdef UNICODE 11 | #define Strcmp wcscmp 12 | #else 13 | #define Strcmp strcmp 14 | #endif 15 | 16 | bool enumFile(const zp::String& searchPath, EnumCallback callback, void* param) 17 | { 18 | WIN32_FIND_DATA fd; 19 | HANDLE findFile = ::FindFirstFile((searchPath + _T("*")).c_str(), &fd); 20 | 21 | if (findFile == INVALID_HANDLE_VALUE) 22 | { 23 | ::FindClose(findFile); 24 | return true; 25 | } 26 | 27 | while (true) 28 | { 29 | if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) 30 | { 31 | //file 32 | if (fd.nFileSizeHigh == 0) //4g top 33 | { 34 | if (!callback(searchPath + fd.cFileName, fd.nFileSizeLow, param)) 35 | { 36 | return false; 37 | } 38 | } 39 | } 40 | else if (Strcmp(fd.cFileName, _T(".")) != 0 && Strcmp(fd.cFileName, _T("..")) != 0) 41 | { 42 | //folder 43 | if (!enumFile(searchPath + fd.cFileName + DIR_STR, callback, param)) 44 | { 45 | return false; 46 | } 47 | } 48 | if (!FindNextFile(findFile, &fd)) 49 | { 50 | ::FindClose(findFile); 51 | return true; 52 | } 53 | } 54 | ::FindClose(findFile); 55 | return true; 56 | } 57 | 58 | bool addPackFile(const zp::String& filename, zp::u32 fileSize, void* param) 59 | { 60 | ZpExplorer* explorer = reinterpret_cast(param); 61 | zp::String relativePath = filename.substr(explorer->m_basePath.length(), filename.length() - explorer->m_basePath.length()); 62 | return explorer->addFile(filename, relativePath, fileSize); 63 | } 64 | 65 | bool countFile(const zp::String& filename, zp::u32 fileSize, void* param) 66 | { 67 | ZpExplorer* explorer = reinterpret_cast(param); 68 | //++explorer->m_fileCount; 69 | explorer->m_totalFileSize += fileSize; 70 | return true; 71 | } 72 | -------------------------------------------------------------------------------- /zpack/zpack.cpp: -------------------------------------------------------------------------------- 1 | #include "zpack.h" 2 | #include "zpPackage.h" 3 | #include "zpFile.h" 4 | #include 5 | 6 | using namespace std; 7 | 8 | namespace zp 9 | { 10 | 11 | /////////////////////////////////////////////////////////////////////////////////////////////////// 12 | IPackage* open(const Char* filename, u32 flag) 13 | { 14 | Package* package = new Package(filename, 15 | (flag & OPEN_READONLY) != 0, 16 | (flag & OPEN_NO_FILENAME) == 0); 17 | if (!package->valid()) 18 | { 19 | delete package; 20 | package = NULL; 21 | } 22 | return package; 23 | } 24 | 25 | /////////////////////////////////////////////////////////////////////////////////////////////////// 26 | void close(IPackage* package) 27 | { 28 | delete static_cast(package); 29 | } 30 | 31 | /////////////////////////////////////////////////////////////////////////////////////////////////// 32 | IPackage* create(const Char* filename, u32 chunkSize, u32 fileUserDataSize) 33 | { 34 | fstream stream; 35 | locale loc = locale::global(locale("")); 36 | stream.open(filename, ios_base::out | ios_base::trunc | ios_base::binary); 37 | locale::global(loc); 38 | if (!stream.is_open()) 39 | { 40 | return NULL; 41 | } 42 | PackageHeader header; 43 | header.sign = PACKAGE_FILE_SIGN; 44 | header.version = CURRENT_VERSION; 45 | header.headerSize = sizeof(PackageHeader); 46 | header.fileCount = 0; 47 | header.fileEntryOffset = sizeof(PackageHeader); 48 | header.filenameOffset = sizeof(PackageHeader); 49 | header.allFileEntrySize = 0; 50 | header.allFilenameSize = 0; 51 | header.originFilenamesSize = 0; 52 | header.chunkSize = chunkSize; 53 | #ifdef ZP_USE_WCHAR 54 | header.flag = PACK_UNICODE; 55 | #else 56 | header.flag = 0; 57 | #endif 58 | header.fileEntrySize = sizeof(FileEntry) + fileUserDataSize; 59 | memset(header.reserved, 0, sizeof(header.reserved)); 60 | 61 | stream.write((char*)&header, sizeof(header)); 62 | stream.close(); 63 | 64 | return open(filename, 0); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /zpEditor/zpEditorView.h: -------------------------------------------------------------------------------- 1 | 2 | // zpEditorView.h : interface of the CzpEditorView class 3 | // 4 | 5 | #pragma once 6 | 7 | #include "ProgressDialog.h" 8 | 9 | struct ZpNode; 10 | 11 | class CzpEditorView : public CListView 12 | { 13 | protected: // create from serialization only 14 | CzpEditorView(); 15 | DECLARE_DYNCREATE(CzpEditorView) 16 | 17 | // Attributes 18 | public: 19 | CzpEditorDoc* GetDocument() const; 20 | 21 | // Operations 22 | public: 23 | 24 | // Overrides 25 | public: 26 | virtual BOOL PreCreateWindow(CREATESTRUCT& cs); 27 | protected: 28 | virtual void OnInitialUpdate(); // called first time after construct 29 | 30 | void OnDbClick(NMHDR *pNMHDR, LRESULT *pResult); 31 | 32 | // Implementation 33 | public: 34 | virtual ~CzpEditorView(); 35 | #ifdef _DEBUG 36 | virtual void AssertValid() const; 37 | virtual void Dump(CDumpContext& dc) const; 38 | #endif 39 | 40 | protected: 41 | void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint); 42 | 43 | ZpNode* getSelectedNode(); 44 | 45 | void startOperation(ProgressDialog::Operation op, zp::u64 totalFileSize, 46 | const std::vector>* operations); 47 | 48 | void openNode(ZpNode* node); 49 | 50 | protected: 51 | afx_msg void OnStyleChanged(int nStyleType, LPSTYLESTRUCT lpStyleStruct); 52 | afx_msg void OnFilePrintPreview(); 53 | afx_msg void OnRButtonUp(UINT nFlags, CPoint point); 54 | afx_msg void OnContextMenu(CWnd* pWnd, CPoint point); 55 | DECLARE_MESSAGE_MAP() 56 | public: 57 | afx_msg void OnEditDelete(); 58 | afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); 59 | afx_msg void OnEditAddFolder(); 60 | afx_msg void OnEditAdd(); 61 | afx_msg void OnEditExtract(); 62 | afx_msg void OnUpdateMenu(CCmdUI* pCmdUI); 63 | afx_msg void OnEditOpen(); 64 | afx_msg void OnEditExtractCur(); 65 | 66 | private: 67 | bool m_initiallized; 68 | }; 69 | 70 | #ifndef _DEBUG // debug version in zpEditorView.cpp 71 | inline CzpEditorDoc* CzpEditorView::GetDocument() const 72 | { return reinterpret_cast(m_pDocument); } 73 | #endif 74 | 75 | -------------------------------------------------------------------------------- /zpack/WriteCompressFile.cpp: -------------------------------------------------------------------------------- 1 | #include "zpack.h" 2 | #include "WriteCompressFile.h" 3 | #include "zlib.h" 4 | 5 | namespace zp 6 | { 7 | 8 | /////////////////////////////////////////////////////////////////////////////////////////////////// 9 | //also needed by hasher, make it global 10 | u32 writeCompressFile(FILE* dstFile, u64 offset, FILE* srcFile, u32 srcFileSize, u32 chunkSize, u32& flag, 11 | std::vector& chunkData, std::vector& compressBuffer, std::vector& chunkPosBuffer) 12 | { 13 | fseek(dstFile, offset, SEEK_SET); 14 | 15 | u32 chunkCount = (srcFileSize + chunkSize - 1) / chunkSize; 16 | chunkPosBuffer.resize(chunkCount); 17 | 18 | u32 packSize = 0; 19 | if (chunkCount > 1) 20 | { 21 | chunkPosBuffer[0] = chunkCount * sizeof(u32); 22 | fwrite(&chunkPosBuffer[0], chunkCount * sizeof(u32), 1, dstFile); 23 | } 24 | 25 | //BEGIN_PERF("compress"); 26 | 27 | u8* dstBuffer = &compressBuffer[0]; 28 | for (u32 i = 0; i < chunkCount; ++i) 29 | { 30 | u32 curChunkSize = chunkSize; 31 | if (i == chunkCount - 1 && srcFileSize % chunkSize != 0) 32 | { 33 | curChunkSize = srcFileSize % chunkSize; 34 | } 35 | fread(&chunkData[0], curChunkSize, 1, srcFile); 36 | 37 | u32 dstSize = chunkSize; 38 | int ret = compress(dstBuffer, &dstSize, &chunkData[0], curChunkSize); 39 | 40 | if (ret != Z_OK || dstSize >= curChunkSize) 41 | { 42 | //compress failed or compressed size greater than origin, write raw data 43 | fwrite(&chunkData[0], curChunkSize, 1, dstFile); 44 | dstSize = curChunkSize; 45 | } 46 | else 47 | { 48 | fwrite(dstBuffer, dstSize, 1, dstFile); 49 | } 50 | if (i + 1 < chunkCount) 51 | { 52 | chunkPosBuffer[i + 1] = chunkPosBuffer[i] + dstSize; 53 | } 54 | packSize += dstSize; 55 | } 56 | 57 | //END_PERF 58 | 59 | if (chunkCount > 1) 60 | { 61 | packSize += chunkCount * sizeof(u32); 62 | fseek(dstFile, offset, SEEK_SET); 63 | fwrite(&chunkPosBuffer[0], chunkCount * sizeof(u32), 1, dstFile); 64 | } 65 | else if (packSize == srcFileSize) 66 | { 67 | //only 1 chunk and not compressed, entire file should not be compressed 68 | flag &= (~FILE_COMPRESS); 69 | } 70 | return packSize; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /zpEditor/stdafx.h: -------------------------------------------------------------------------------- 1 | 2 | // stdafx.h : include file for standard system include files, 3 | // or project specific include files that are used frequently, 4 | // but are changed infrequently 5 | 6 | #pragma once 7 | 8 | #ifndef _SECURE_ATL 9 | #define _SECURE_ATL 1 10 | #endif 11 | 12 | #ifndef VC_EXTRALEAN 13 | #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers 14 | #endif 15 | 16 | #include "targetver.h" 17 | 18 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit 19 | 20 | // turns off MFC's hiding of some common and often safely ignored warning messages 21 | #define _AFX_ALL_WARNINGS 22 | 23 | #include // MFC core and standard components 24 | //#include // MFC extensions 25 | #include 26 | 27 | 28 | //#include // MFC Automation classes 29 | 30 | 31 | 32 | #ifndef _AFX_NO_OLE_SUPPORT 33 | //#include // MFC support for Internet Explorer 4 Common Controls 34 | #endif 35 | #ifndef _AFX_NO_AFXCMN_SUPPORT 36 | //#include // MFC support for Windows Common Controls 37 | #endif // _AFX_NO_AFXCMN_SUPPORT 38 | 39 | #include // MFC support for ribbons and control bars 40 | 41 | 42 | #include 43 | 44 | #ifdef UNICODE 45 | typedef std::wstringstream StringStream; 46 | typedef std::wostringstream OStringStream; 47 | #else 48 | typedef std::stringstream StringStream; 49 | typedef std::ostringstream OStringStream; 50 | #endif 51 | 52 | #ifdef _UNICODE 53 | #if defined _M_IX86 54 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 55 | #elif defined _M_X64 56 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") 57 | #else 58 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 59 | #endif 60 | 61 | #endif 62 | 63 | #include "zpack.h" -------------------------------------------------------------------------------- /zpack/zlib/uncompr.c: -------------------------------------------------------------------------------- 1 | /* uncompr.c -- decompress a memory buffer 2 | * Copyright (C) 1995-2003 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Decompresses the source buffer into the destination buffer. sourceLen is 13 | the byte length of the source buffer. Upon entry, destLen is the total 14 | size of the destination buffer, which must be large enough to hold the 15 | entire uncompressed data. (The size of the uncompressed data must have 16 | been saved previously by the compressor and transmitted to the decompressor 17 | by some mechanism outside the scope of this compression library.) 18 | Upon exit, destLen is the actual size of the compressed buffer. 19 | This function can be used to decompress a whole file at once if the 20 | input file is mmap'ed. 21 | 22 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 23 | enough memory, Z_BUF_ERROR if there was not enough room in the output 24 | buffer, or Z_DATA_ERROR if the input data was corrupted. 25 | */ 26 | int ZEXPORT uncompress (dest, destLen, source, sourceLen) 27 | Bytef *dest; 28 | uLongf *destLen; 29 | const Bytef *source; 30 | uLong sourceLen; 31 | { 32 | z_stream stream; 33 | int err; 34 | 35 | stream.next_in = (Bytef*)source; 36 | stream.avail_in = (uInt)sourceLen; 37 | /* Check for source > 64K on 16-bit machine: */ 38 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 39 | 40 | stream.next_out = dest; 41 | stream.avail_out = (uInt)*destLen; 42 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 43 | 44 | stream.zalloc = (alloc_func)0; 45 | stream.zfree = (free_func)0; 46 | 47 | err = inflateInit(&stream); 48 | if (err != Z_OK) return err; 49 | 50 | err = inflate(&stream, Z_FINISH); 51 | if (err != Z_STREAM_END) { 52 | inflateEnd(&stream); 53 | if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) 54 | return Z_DATA_ERROR; 55 | return err; 56 | } 57 | *destLen = stream.total_out; 58 | 59 | err = inflateEnd(&stream); 60 | return err; 61 | } 62 | -------------------------------------------------------------------------------- /zpack/zpWriteFile.cpp: -------------------------------------------------------------------------------- 1 | #include "zpWriteFile.h" 2 | #include "zpPackage.h" 3 | 4 | namespace zp 5 | { 6 | 7 | /////////////////////////////////////////////////////////////////////////////////////////////////// 8 | WriteFile::WriteFile(Package* package, u64 offset, u32 size, u32 flag, u64 nameHash) 9 | : m_package(package) 10 | , m_offset(offset) 11 | , m_size(size) 12 | , m_flag(flag) 13 | , m_nameHash(nameHash) 14 | , m_writePos(0) 15 | { 16 | } 17 | 18 | /////////////////////////////////////////////////////////////////////////////////////////////////// 19 | WriteFile::~WriteFile() 20 | { 21 | if (m_package->m_lastSeekFile == this) 22 | { 23 | m_package->m_lastSeekFile = NULL; 24 | } 25 | } 26 | 27 | /////////////////////////////////////////////////////////////////////////////////////////////////// 28 | u32 WriteFile::size() const 29 | { 30 | return m_size; 31 | } 32 | 33 | /////////////////////////////////////////////////////////////////////////////////////////////////// 34 | u32 WriteFile::flag() const 35 | { 36 | return m_flag; 37 | } 38 | 39 | /////////////////////////////////////////////////////////////////////////////////////////////////// 40 | void WriteFile::seek(u32 pos) 41 | { 42 | if (pos > m_size) 43 | { 44 | m_writePos = m_size; 45 | } 46 | else 47 | { 48 | m_writePos = pos; 49 | } 50 | } 51 | 52 | //////////////////////////////////////////////////////////////////////////////////////////////////// 53 | u32 WriteFile::tell() const 54 | { 55 | return m_writePos; 56 | } 57 | 58 | /////////////////////////////////////////////////////////////////////////////////////////////////// 59 | u32 WriteFile::write(const u8* buffer, u32 size) 60 | { 61 | PACKAGE_LOCK; 62 | 63 | if (m_writePos + size > m_size) 64 | { 65 | size = m_size - m_writePos; 66 | } 67 | if (size == 0) 68 | { 69 | return 0; 70 | } 71 | if (m_package->m_lastSeekFile != this) 72 | { 73 | seekInPackage(); 74 | } 75 | fwrite(buffer, size, 1, m_package->m_stream); 76 | m_writePos += size; 77 | 78 | if (!m_package->setFileAvailableSize(m_nameHash, m_writePos)) 79 | { 80 | //something wrong, stop writing 81 | m_size = 0; 82 | return 0; 83 | } 84 | return size; 85 | } 86 | 87 | //////////////////////////////////////////////////////////////////////////////////////////////////// 88 | void WriteFile::seekInPackage() 89 | { 90 | fseek(m_package->m_stream, m_offset + m_writePos, SEEK_SET); 91 | m_package->m_lastSeekFile = this; 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /zpack/zlib/inftrees.h: -------------------------------------------------------------------------------- 1 | /* inftrees.h -- header to use inftrees.c 2 | * Copyright (C) 1995-2005 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* Structure for decoding tables. Each entry provides either the 12 | information needed to do the operation requested by the code that 13 | indexed that table entry, or it provides a pointer to another 14 | table that indexes more bits of the code. op indicates whether 15 | the entry is a pointer to another table, a literal, a length or 16 | distance, an end-of-block, or an invalid code. For a table 17 | pointer, the low four bits of op is the number of index bits of 18 | that table. For a length or distance, the low four bits of op 19 | is the number of extra bits to get after the code. bits is 20 | the number of bits in this code or part of the code to drop off 21 | of the bit buffer. val is the actual byte to output in the case 22 | of a literal, the base length or distance, or the offset from 23 | the current table to the next table. Each entry is four bytes. */ 24 | typedef struct { 25 | unsigned char op; /* operation, extra bits, table bits */ 26 | unsigned char bits; /* bits in this part of the code */ 27 | unsigned short val; /* offset in table or code value */ 28 | } code; 29 | 30 | /* op values as set by inflate_table(): 31 | 00000000 - literal 32 | 0000tttt - table link, tttt != 0 is the number of table index bits 33 | 0001eeee - length or distance, eeee is the number of extra bits 34 | 01100000 - end of block 35 | 01000000 - invalid code 36 | */ 37 | 38 | /* Maximum size of dynamic tree. The maximum found in a long but non- 39 | exhaustive search was 1444 code structures (852 for length/literals 40 | and 592 for distances, the latter actually the result of an 41 | exhaustive search). The true maximum is not known, but the value 42 | below is more than safe. */ 43 | #define ENOUGH 2048 44 | #define MAXD 592 45 | 46 | /* Type of code to build for inftable() */ 47 | typedef enum { 48 | CODES, 49 | LENS, 50 | DISTS 51 | } codetype; 52 | 53 | extern int inflate_table OF((codetype type, unsigned short FAR *lens, 54 | unsigned codes, code FAR * FAR *table, 55 | unsigned FAR *bits, unsigned short FAR *work)); 56 | -------------------------------------------------------------------------------- /zpack/zpFile.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "zpFile.h" 3 | #include "zpPackage.h" 4 | #include 5 | 6 | namespace zp 7 | { 8 | 9 | //////////////////////////////////////////////////////////////////////////////////////////////////// 10 | File::File(const Package* package, u64 offset, u32 size, u32 flag, u64 nameHash) 11 | : m_package(package) 12 | , m_offset(offset) 13 | , m_flag(flag) 14 | , m_size(size) 15 | , m_nameHash(nameHash) 16 | , m_readPos(0) 17 | { 18 | assert(package != NULL); 19 | assert(package->m_stream != NULL); 20 | } 21 | 22 | //////////////////////////////////////////////////////////////////////////////////////////////////// 23 | File::~File() 24 | { 25 | if (m_package->m_lastSeekFile == this) 26 | { 27 | m_package->m_lastSeekFile = NULL; 28 | } 29 | } 30 | 31 | //////////////////////////////////////////////////////////////////////////////////////////////////// 32 | u32 File::size() const 33 | { 34 | return m_size; 35 | } 36 | 37 | //////////////////////////////////////////////////////////////////////////////////////////////////// 38 | u32 File::availableSize() const 39 | { 40 | PACKAGE_LOCK; 41 | 42 | return m_package->getFileAvailableSize(m_nameHash); 43 | } 44 | 45 | //////////////////////////////////////////////////////////////////////////////////////////////////// 46 | u32 File::flag() const 47 | { 48 | return m_flag; 49 | } 50 | 51 | //////////////////////////////////////////////////////////////////////////////////////////////////// 52 | void File::seek(u32 pos) 53 | { 54 | if (pos > m_size) 55 | { 56 | m_readPos = m_size; 57 | } 58 | else 59 | { 60 | m_readPos = pos; 61 | } 62 | } 63 | 64 | //////////////////////////////////////////////////////////////////////////////////////////////////// 65 | u32 File::tell() const 66 | { 67 | return m_readPos; 68 | } 69 | 70 | //////////////////////////////////////////////////////////////////////////////////////////////////// 71 | u32 File::read(u8* buffer, u32 size) 72 | { 73 | PACKAGE_LOCK; 74 | //not preventing user from reading over available size here 75 | if (m_readPos + size > m_size) 76 | { 77 | size = m_size - m_readPos; 78 | } 79 | if (size == 0) 80 | { 81 | return 0; 82 | } 83 | if (m_package->m_lastSeekFile != this) 84 | { 85 | seekInPackage(); 86 | } 87 | fread(buffer, size, 1, m_package->m_stream); 88 | m_readPos += size; 89 | return size; 90 | } 91 | 92 | //////////////////////////////////////////////////////////////////////////////////////////////////// 93 | void File::seekInPackage() 94 | { 95 | fseek(m_package->m_stream, m_offset + m_readPos, SEEK_SET); 96 | m_package->m_lastSeekFile = this; 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /zpEditor/zpEditor_vs2010.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 6 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 7 | 8 | 9 | {718846e0-a3e7-4ca3-b7c3-2da7509146ff} 10 | 11 | 12 | 13 | 14 | Resource Files 15 | 16 | 17 | Resource Files 18 | 19 | 20 | Resource Files 21 | 22 | 23 | Resource Files 24 | 25 | 26 | Resource Files 27 | 28 | 29 | Resource Files 30 | 31 | 32 | Resource Files 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | zp 46 | 47 | 48 | zp 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | zp 62 | 63 | 64 | zp 65 | 66 | 67 | 68 | 69 | 70 | 71 | Resource Files 72 | 73 | 74 | -------------------------------------------------------------------------------- /zpEditor/zpEditor_vs2012.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 6 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 7 | 8 | 9 | {718846e0-a3e7-4ca3-b7c3-2da7509146ff} 10 | 11 | 12 | 13 | 14 | Resource Files 15 | 16 | 17 | Resource Files 18 | 19 | 20 | Resource Files 21 | 22 | 23 | Resource Files 24 | 25 | 26 | Resource Files 27 | 28 | 29 | Resource Files 30 | 31 | 32 | Resource Files 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | zp 46 | 47 | 48 | zp 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | zp 62 | 63 | 64 | zp 65 | 66 | 67 | 68 | 69 | 70 | 71 | Resource Files 72 | 73 | 74 | -------------------------------------------------------------------------------- /zpack/zlib/compress.c: -------------------------------------------------------------------------------- 1 | /* compress.c -- compress a memory buffer 2 | * Copyright (C) 1995-2003 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Compresses the source buffer into the destination buffer. The level 13 | parameter has the same meaning as in deflateInit. sourceLen is the byte 14 | length of the source buffer. Upon entry, destLen is the total size of the 15 | destination buffer, which must be at least 0.1% larger than sourceLen plus 16 | 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. 17 | 18 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 19 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, 20 | Z_STREAM_ERROR if the level parameter is invalid. 21 | */ 22 | int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) 23 | Bytef *dest; 24 | uLongf *destLen; 25 | const Bytef *source; 26 | uLong sourceLen; 27 | int level; 28 | { 29 | z_stream stream; 30 | int err; 31 | 32 | stream.next_in = (Bytef*)source; 33 | stream.avail_in = (uInt)sourceLen; 34 | #ifdef MAXSEG_64K 35 | /* Check for source > 64K on 16-bit machine: */ 36 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 37 | #endif 38 | stream.next_out = dest; 39 | stream.avail_out = (uInt)*destLen; 40 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 41 | 42 | stream.zalloc = (alloc_func)0; 43 | stream.zfree = (free_func)0; 44 | stream.opaque = (voidpf)0; 45 | 46 | err = deflateInit(&stream, level); 47 | if (err != Z_OK) return err; 48 | 49 | err = deflate(&stream, Z_FINISH); 50 | if (err != Z_STREAM_END) { 51 | deflateEnd(&stream); 52 | return err == Z_OK ? Z_BUF_ERROR : err; 53 | } 54 | *destLen = stream.total_out; 55 | 56 | err = deflateEnd(&stream); 57 | return err; 58 | } 59 | 60 | /* =========================================================================== 61 | */ 62 | int ZEXPORT compress (dest, destLen, source, sourceLen) 63 | Bytef *dest; 64 | uLongf *destLen; 65 | const Bytef *source; 66 | uLong sourceLen; 67 | { 68 | return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); 69 | } 70 | 71 | /* =========================================================================== 72 | If the default memLevel or windowBits for deflateInit() is changed, then 73 | this function needs to be updated. 74 | */ 75 | uLong ZEXPORT compressBound (sourceLen) 76 | uLong sourceLen; 77 | { 78 | return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11; 79 | } 80 | -------------------------------------------------------------------------------- /zpack/zpack-vs2010.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zpack", "zpack_vs2010.vcxproj", "{287EEAD4-7FEF-4444-A683-0A088A33D655}" 5 | EndProject 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zpCmd", "..\zpCmd\zpcmd-vs2010.vcxproj", "{64EC7A26-97C8-4526-A29A-097D53D7C9B5}" 7 | ProjectSection(ProjectDependencies) = postProject 8 | {287EEAD4-7FEF-4444-A683-0A088A33D655} = {287EEAD4-7FEF-4444-A683-0A088A33D655} 9 | EndProjectSection 10 | EndProject 11 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zpEditor", "..\zpEditor\zpEditor_vs2010.vcxproj", "{DA24099C-7164-49A4-BFC5-5CDD91A6D7B1}" 12 | ProjectSection(ProjectDependencies) = postProject 13 | {287EEAD4-7FEF-4444-A683-0A088A33D655} = {287EEAD4-7FEF-4444-A683-0A088A33D655} 14 | EndProjectSection 15 | EndProject 16 | Global 17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 18 | Debug|Win32 = Debug|Win32 19 | Release_editor|Win32 = Release_editor|Win32 20 | Release|Win32 = Release|Win32 21 | EndGlobalSection 22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 23 | {287EEAD4-7FEF-4444-A683-0A088A33D655}.Debug|Win32.ActiveCfg = Debug|Win32 24 | {287EEAD4-7FEF-4444-A683-0A088A33D655}.Debug|Win32.Build.0 = Debug|Win32 25 | {287EEAD4-7FEF-4444-A683-0A088A33D655}.Release_editor|Win32.ActiveCfg = Release_editor|Win32 26 | {287EEAD4-7FEF-4444-A683-0A088A33D655}.Release_editor|Win32.Build.0 = Release_editor|Win32 27 | {287EEAD4-7FEF-4444-A683-0A088A33D655}.Release|Win32.ActiveCfg = Release|Win32 28 | {287EEAD4-7FEF-4444-A683-0A088A33D655}.Release|Win32.Build.0 = Release|Win32 29 | {64EC7A26-97C8-4526-A29A-097D53D7C9B5}.Debug|Win32.ActiveCfg = Debug|Win32 30 | {64EC7A26-97C8-4526-A29A-097D53D7C9B5}.Debug|Win32.Build.0 = Debug|Win32 31 | {64EC7A26-97C8-4526-A29A-097D53D7C9B5}.Release_editor|Win32.ActiveCfg = Release_editor|Win32 32 | {64EC7A26-97C8-4526-A29A-097D53D7C9B5}.Release_editor|Win32.Build.0 = Release_editor|Win32 33 | {64EC7A26-97C8-4526-A29A-097D53D7C9B5}.Release|Win32.ActiveCfg = Release|Win32 34 | {64EC7A26-97C8-4526-A29A-097D53D7C9B5}.Release|Win32.Build.0 = Release|Win32 35 | {DA24099C-7164-49A4-BFC5-5CDD91A6D7B1}.Debug|Win32.ActiveCfg = Debug|Win32 36 | {DA24099C-7164-49A4-BFC5-5CDD91A6D7B1}.Debug|Win32.Build.0 = Debug|Win32 37 | {DA24099C-7164-49A4-BFC5-5CDD91A6D7B1}.Release_editor|Win32.ActiveCfg = Release_editor|Win32 38 | {DA24099C-7164-49A4-BFC5-5CDD91A6D7B1}.Release_editor|Win32.Build.0 = Release_editor|Win32 39 | {DA24099C-7164-49A4-BFC5-5CDD91A6D7B1}.Release|Win32.ActiveCfg = Release|Win32 40 | {DA24099C-7164-49A4-BFC5-5CDD91A6D7B1}.Release|Win32.Build.0 = Release|Win32 41 | EndGlobalSection 42 | GlobalSection(SolutionProperties) = preSolution 43 | HideSolutionNode = FALSE 44 | EndGlobalSection 45 | EndGlobal 46 | -------------------------------------------------------------------------------- /zpack/zpack-vs2012.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2012 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zpack", "zpack_vs2012.vcxproj", "{287EEAD4-7FEF-4444-A683-0A088A33D655}" 5 | EndProject 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zpCmd", "..\zpCmd\zpcmd-vs2012.vcxproj", "{64EC7A26-97C8-4526-A29A-097D53D7C9B5}" 7 | ProjectSection(ProjectDependencies) = postProject 8 | {287EEAD4-7FEF-4444-A683-0A088A33D655} = {287EEAD4-7FEF-4444-A683-0A088A33D655} 9 | EndProjectSection 10 | EndProject 11 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zpEditor", "..\zpEditor\zpEditor_vs2012.vcxproj", "{DA24099C-7164-49A4-BFC5-5CDD91A6D7B1}" 12 | ProjectSection(ProjectDependencies) = postProject 13 | {287EEAD4-7FEF-4444-A683-0A088A33D655} = {287EEAD4-7FEF-4444-A683-0A088A33D655} 14 | EndProjectSection 15 | EndProject 16 | Global 17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 18 | Debug|Win32 = Debug|Win32 19 | Release_editor|Win32 = Release_editor|Win32 20 | Release|Win32 = Release|Win32 21 | EndGlobalSection 22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 23 | {287EEAD4-7FEF-4444-A683-0A088A33D655}.Debug|Win32.ActiveCfg = Debug|Win32 24 | {287EEAD4-7FEF-4444-A683-0A088A33D655}.Debug|Win32.Build.0 = Debug|Win32 25 | {287EEAD4-7FEF-4444-A683-0A088A33D655}.Release_editor|Win32.ActiveCfg = Release_editor|Win32 26 | {287EEAD4-7FEF-4444-A683-0A088A33D655}.Release_editor|Win32.Build.0 = Release_editor|Win32 27 | {287EEAD4-7FEF-4444-A683-0A088A33D655}.Release|Win32.ActiveCfg = Release|Win32 28 | {287EEAD4-7FEF-4444-A683-0A088A33D655}.Release|Win32.Build.0 = Release|Win32 29 | {64EC7A26-97C8-4526-A29A-097D53D7C9B5}.Debug|Win32.ActiveCfg = Debug|Win32 30 | {64EC7A26-97C8-4526-A29A-097D53D7C9B5}.Debug|Win32.Build.0 = Debug|Win32 31 | {64EC7A26-97C8-4526-A29A-097D53D7C9B5}.Release_editor|Win32.ActiveCfg = Release_editor|Win32 32 | {64EC7A26-97C8-4526-A29A-097D53D7C9B5}.Release_editor|Win32.Build.0 = Release_editor|Win32 33 | {64EC7A26-97C8-4526-A29A-097D53D7C9B5}.Release|Win32.ActiveCfg = Release|Win32 34 | {64EC7A26-97C8-4526-A29A-097D53D7C9B5}.Release|Win32.Build.0 = Release|Win32 35 | {DA24099C-7164-49A4-BFC5-5CDD91A6D7B1}.Debug|Win32.ActiveCfg = Debug|Win32 36 | {DA24099C-7164-49A4-BFC5-5CDD91A6D7B1}.Debug|Win32.Build.0 = Debug|Win32 37 | {DA24099C-7164-49A4-BFC5-5CDD91A6D7B1}.Release_editor|Win32.ActiveCfg = Release_editor|Win32 38 | {DA24099C-7164-49A4-BFC5-5CDD91A6D7B1}.Release_editor|Win32.Build.0 = Release_editor|Win32 39 | {DA24099C-7164-49A4-BFC5-5CDD91A6D7B1}.Release|Win32.ActiveCfg = Release|Win32 40 | {DA24099C-7164-49A4-BFC5-5CDD91A6D7B1}.Release|Win32.Build.0 = Release|Win32 41 | EndGlobalSection 42 | GlobalSection(SolutionProperties) = preSolution 43 | HideSolutionNode = FALSE 44 | EndGlobalSection 45 | EndGlobal 46 | -------------------------------------------------------------------------------- /zpCmd/zpExplorer.h: -------------------------------------------------------------------------------- 1 | #ifndef __ZP_EXPLORER_H__ 2 | #define __ZP_EXPLORER_H__ 3 | 4 | #include 5 | #include 6 | #include "zpack.h" 7 | 8 | namespace zp 9 | { 10 | class IPackage; 11 | } 12 | 13 | //use '/' and "/" on linux or mac 14 | #define DIR_CHAR _T('\\') 15 | #define DIR_STR _T("\\") 16 | 17 | struct ZpNode 18 | { 19 | ZpNode() : userData(NULL){} 20 | 21 | zp::String name; 22 | #if !(ZP_CASE_SENSITIVE) 23 | zp::String lowerName; 24 | #endif 25 | std::list children; 26 | ZpNode* parent; 27 | zp::u64 fileSize; 28 | zp::u64 compressSize; 29 | zp::u32 flag; 30 | mutable void* userData; 31 | bool isDirectory; 32 | }; 33 | 34 | class ZpExplorer 35 | { 36 | friend bool addPackFile(const zp::String& filename, zp::u32 fileSize, void* param); 37 | friend bool countFile(const zp::String& filename, zp::u32 fileSize, void* param); 38 | 39 | public: 40 | ZpExplorer(); 41 | ~ZpExplorer(); 42 | 43 | void setCallback(zp::Callback callback, void* param); 44 | 45 | bool open(const zp::String& path, bool readonly = false); 46 | bool create(const zp::String& path, const zp::String& inputPath); 47 | void close(); 48 | bool isOpen() const; 49 | 50 | bool defrag(); 51 | 52 | zp::IPackage* getPack() const; 53 | 54 | const zp::Char* packageFilename() const; 55 | 56 | bool enterDir(const zp::String& path); 57 | 58 | //srcPath can't be empty 59 | //if dstPath is empty, file/dir will be add to current path of package 60 | bool add(const zp::String& srcPath, const zp::String& dstPath, bool flush = true); 61 | 62 | bool remove(const zp::String& path); 63 | 64 | void flush(); 65 | 66 | //if srcPath is empty, current path of package will be extracted 67 | //if dstPath is empty, file/dir will be extracted to current path of system 68 | bool extract(const zp::String& srcPath, const zp::String& dstPath); 69 | 70 | void setCurrentNode(const ZpNode* node); 71 | const ZpNode* currentNode() const; 72 | const ZpNode* rootNode() const; 73 | 74 | const zp::String& currentPath() const; 75 | void getNodePath(const ZpNode* node, zp::String& path) const; 76 | 77 | zp::u64 countDiskFileSize(const zp::String& path); 78 | zp::u64 countNodeFileSize(const ZpNode* node); 79 | 80 | private: 81 | void clear(); 82 | 83 | void build(); 84 | 85 | bool addFile(const zp::String& externalPath, const zp::String& internalPath, zp::u32 fileSize); 86 | bool extractFile(const zp::String& externalPath, const zp::String& internalPath); 87 | 88 | void countChildRecursively(const ZpNode* node); 89 | 90 | bool removeChild(ZpNode* node, ZpNode* child); 91 | bool removeChildRecursively(ZpNode* node, zp::String path); 92 | 93 | bool extractRecursively(ZpNode* node, zp::String externalPath, zp::String internalPath); 94 | 95 | void insertFileToTree(const zp::String& filename, zp::u32 fileSize, zp::u32 compressSize, 96 | zp::u32 flag, bool checkFileExist); 97 | 98 | enum FindType 99 | { 100 | FIND_ANY = 0, 101 | FIND_FILE = 1, 102 | FIND_DIR = 2 103 | }; 104 | ZpNode* findChild(ZpNode* node, const zp::String& name, FindType type); 105 | ZpNode* findChildRecursively(ZpNode* node, const zp::String& name, FindType type); 106 | 107 | zp::String getArchivedName(const zp::String& filename); 108 | 109 | void minusAncesterSize(ZpNode* node); 110 | 111 | private: 112 | zp::IPackage* m_pack; 113 | ZpNode m_root; 114 | ZpNode* m_currentNode; 115 | zp::String m_currentPath; 116 | zp::String m_workingPath; //user can operate on directory other than current one 117 | zp::String m_basePath; //base path of external path (of file system) 118 | zp::Callback m_callback; 119 | void* m_callbackParam; 120 | //zp::u32 m_fileCount; 121 | zp::u64 m_totalFileSize; 122 | }; 123 | 124 | void stringToLower(zp::String& dst, const zp::String& src); 125 | 126 | #endif 127 | -------------------------------------------------------------------------------- /zpEditor/FolderDialog.cpp: -------------------------------------------------------------------------------- 1 | // FolderDialog.cpp: implementation of the CFolderDialog class. 2 | // $Copyright ?1998, Kenneth M. Reed, All Rights Reserved. $ 3 | // $Header: FolderDialog.cpp Revision:1.10 Mon Apr 06 12:04:50 1998 KenReed $ 4 | 5 | #include "stdafx.h" 6 | #include "FolderDialog.h" 7 | 8 | //#ifdef _DEBUG 9 | //#undef THIS_FILE 10 | //static char THIS_FILE[]=__FILE__; 11 | //#define new DEBUG_NEW 12 | //#endif 13 | 14 | ////////////////////////////////////////////////////////////////////// 15 | // Construction/Destruction 16 | ////////////////////////////////////////////////////////////////////// 17 | static int CALLBACK BrowseDirectoryCallback( 18 | HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM lpData) 19 | { 20 | // Context was pointer to CFolderDialog instance 21 | CFolderDialog* pFd = (CFolderDialog*)lpData; 22 | 23 | // Let the class handle it 24 | pFd->CallbackFunction(hWnd, uMsg, lParam); 25 | 26 | // Always return 0 as per SHBrowseFolder spec 27 | return 0; 28 | } 29 | 30 | CFolderDialog::CFolderDialog(LPCTSTR lpszFolderName, LPCTSTR lpszTitle, DWORD dwFlags, CWnd* pParentWnd) 31 | { 32 | // Use the supplied initial folder if non-null. 33 | if (lpszFolderName == NULL) 34 | { 35 | TCHAR curDir[MAX_PATH]; 36 | GetCurrentDirectory(MAX_PATH, curDir); 37 | m_strInitialFolderName = curDir; 38 | } 39 | else 40 | m_strInitialFolderName = lpszFolderName; 41 | 42 | memset(&m_bi, '\0', sizeof(BROWSEINFO)); 43 | 44 | if (pParentWnd == NULL) 45 | m_bi.hwndOwner = 0; 46 | else 47 | m_bi.hwndOwner = pParentWnd->GetSafeHwnd(); 48 | 49 | // Fill in the rest of the structure 50 | m_bi.pidlRoot = NULL; 51 | m_bi.pszDisplayName = m_szDisplayName; 52 | m_bi.lpszTitle = lpszTitle; 53 | m_bi.ulFlags = dwFlags | BIF_STATUSTEXT | BIF_USENEWUI; 54 | m_bi.lpfn = BrowseDirectoryCallback; 55 | m_bi.lParam = (LPARAM)this; 56 | 57 | OleInitialize(NULL); 58 | } 59 | 60 | CFolderDialog::~CFolderDialog() 61 | { 62 | 63 | } 64 | 65 | void CFolderDialog::CallbackFunction(HWND hWnd, UINT uMsg, LPARAM lParam) 66 | { 67 | // Save the window handle. The Set* functions need it and they may 68 | // be called by the virtual funtions. 69 | m_hDialogBox = hWnd; 70 | 71 | // Dispatch the two message types to the virtual functions 72 | switch (uMsg) 73 | { 74 | case BFFM_INITIALIZED: 75 | OnInitDialog(); 76 | break; 77 | case BFFM_SELCHANGED: 78 | OnSelChanged((ITEMIDLIST*) lParam); 79 | break; 80 | } 81 | } 82 | 83 | int CFolderDialog::DoModal() 84 | { 85 | int nReturn = IDOK; 86 | 87 | // initialize the result to the starting folder value 88 | m_strFinalFolderName = m_strInitialFolderName; 89 | 90 | ITEMIDLIST* piid = NULL; 91 | 92 | // call the shell function 93 | piid = ::SHBrowseForFolder(&m_bi); 94 | 95 | // process the result 96 | if (piid && ::SHGetPathFromIDList(piid, m_szPath)) 97 | { 98 | m_strFinalFolderName = m_szPath; 99 | nReturn = IDOK; 100 | } 101 | else 102 | { 103 | nReturn = IDCANCEL; 104 | } 105 | 106 | // Release the ITEMIDLIST if we got one 107 | if (piid) 108 | { 109 | LPMALLOC lpMalloc; 110 | VERIFY(::SHGetMalloc(&lpMalloc) == NOERROR); 111 | lpMalloc->Free(piid); 112 | lpMalloc->Release(); 113 | } 114 | 115 | return nReturn; 116 | } 117 | 118 | CString CFolderDialog::GetPathName() const 119 | { 120 | return m_strFinalFolderName; 121 | } 122 | 123 | void CFolderDialog::EnableOK(BOOL bEnable) 124 | { 125 | ::SendMessage(m_hDialogBox, BFFM_ENABLEOK, (bEnable ? 1 : 0), 0); 126 | } 127 | 128 | void CFolderDialog::SetSelection(LPCTSTR pszSelection) 129 | { 130 | ::SendMessage(m_hDialogBox, BFFM_SETSELECTION, TRUE, (LPARAM) pszSelection); 131 | } 132 | 133 | void CFolderDialog::SetSelection(ITEMIDLIST* pIdl) 134 | { 135 | ::SendMessage(m_hDialogBox, BFFM_SETSELECTION, FALSE, (LPARAM) pIdl); 136 | } 137 | 138 | void CFolderDialog::SetStatusText(LPCTSTR pszStatusText) 139 | { 140 | ::SendMessage(m_hDialogBox, BFFM_SETSTATUSTEXT, 0, (LPARAM) pszStatusText); 141 | } 142 | 143 | CString CFolderDialog::ShortName(const CString& strName) 144 | { 145 | CString strShort; 146 | if (strName.GetLength() <= 35) 147 | strShort = strName; 148 | else 149 | strShort = strName.Left(35) + _T("..."); 150 | 151 | return strShort; 152 | } 153 | 154 | void CFolderDialog::OnInitDialog() 155 | { 156 | // Default handing of the init dialog message sets the selection to 157 | // the initial folder 158 | SetSelection(m_strInitialFolderName); 159 | SetStatusText(ShortName(m_strInitialFolderName)); 160 | } 161 | 162 | void CFolderDialog::OnSelChanged(ITEMIDLIST* pIdl) 163 | { 164 | ::SHGetPathFromIDList(pIdl, m_szPath); 165 | m_strFinalFolderName = m_szPath; 166 | SetStatusText(ShortName(m_strFinalFolderName)); 167 | } 168 | -------------------------------------------------------------------------------- /zpCmd/zpCmd-vs2005.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 25 | 28 | 31 | 34 | 37 | 40 | 53 | 56 | 59 | 62 | 71 | 74 | 77 | 80 | 83 | 86 | 89 | 92 | 95 | 96 | 104 | 107 | 110 | 113 | 116 | 119 | 129 | 132 | 135 | 138 | 149 | 152 | 155 | 158 | 161 | 164 | 167 | 170 | 173 | 174 | 175 | 176 | 177 | 178 | 181 | 182 | 185 | 186 | 189 | 190 | 193 | 194 | 197 | 198 | 199 | 200 | 201 | 202 | -------------------------------------------------------------------------------- /zpack/pthread/semaphore.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Module: semaphore.h 3 | * 4 | * Purpose: 5 | * Semaphores aren't actually part of the PThreads standard. 6 | * They are defined by the POSIX Standard: 7 | * 8 | * POSIX 1003.1b-1993 (POSIX.1b) 9 | * 10 | * -------------------------------------------------------------------------- 11 | * 12 | * Pthreads-win32 - POSIX Threads Library for Win32 13 | * Copyright(C) 1998 John E. Bossom 14 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 15 | * 16 | * Contact Email: rpj@callisto.canberra.edu.au 17 | * 18 | * The current list of contributors is contained 19 | * in the file CONTRIBUTORS included with the source 20 | * code distribution. The list can also be seen at the 21 | * following World Wide Web location: 22 | * http://sources.redhat.com/pthreads-win32/contributors.html 23 | * 24 | * This library is free software; you can redistribute it and/or 25 | * modify it under the terms of the GNU Lesser General Public 26 | * License as published by the Free Software Foundation; either 27 | * version 2 of the License, or (at your option) any later version. 28 | * 29 | * This library is distributed in the hope that it will be useful, 30 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 31 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 32 | * Lesser General Public License for more details. 33 | * 34 | * You should have received a copy of the GNU Lesser General Public 35 | * License along with this library in the file COPYING.LIB; 36 | * if not, write to the Free Software Foundation, Inc., 37 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 38 | */ 39 | #if !defined( SEMAPHORE_H ) 40 | #define SEMAPHORE_H 41 | 42 | #undef PTW32_LEVEL 43 | 44 | #if defined(_POSIX_SOURCE) 45 | #define PTW32_LEVEL 0 46 | /* Early POSIX */ 47 | #endif 48 | 49 | #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309 50 | #undef PTW32_LEVEL 51 | #define PTW32_LEVEL 1 52 | /* Include 1b, 1c and 1d */ 53 | #endif 54 | 55 | #if defined(INCLUDE_NP) 56 | #undef PTW32_LEVEL 57 | #define PTW32_LEVEL 2 58 | /* Include Non-Portable extensions */ 59 | #endif 60 | 61 | #define PTW32_LEVEL_MAX 3 62 | 63 | #if !defined(PTW32_LEVEL) 64 | #define PTW32_LEVEL PTW32_LEVEL_MAX 65 | /* Include everything */ 66 | #endif 67 | 68 | #if __GNUC__ && ! defined (__declspec) 69 | # error Please upgrade your GNU compiler to one that supports __declspec. 70 | #endif 71 | 72 | /* 73 | * When building the DLL code, you should define PTW32_BUILD so that 74 | * the variables/functions are exported correctly. When using the DLL, 75 | * do NOT define PTW32_BUILD, and then the variables/functions will 76 | * be imported correctly. 77 | */ 78 | #ifndef PTW32_STATIC_LIB 79 | # ifdef PTW32_BUILD 80 | # define PTW32_DLLPORT __declspec (dllexport) 81 | # else 82 | # define PTW32_DLLPORT __declspec (dllimport) 83 | # endif 84 | #else 85 | # define PTW32_DLLPORT 86 | #endif 87 | 88 | /* 89 | * This is a duplicate of what is in the autoconf config.h, 90 | * which is only used when building the pthread-win32 libraries. 91 | */ 92 | 93 | #ifndef PTW32_CONFIG_H 94 | # if defined(WINCE) 95 | # define NEED_ERRNO 96 | # define NEED_SEM 97 | # endif 98 | # if defined(_UWIN) || defined(__MINGW32__) 99 | # define HAVE_MODE_T 100 | # endif 101 | #endif 102 | 103 | /* 104 | * 105 | */ 106 | 107 | #if PTW32_LEVEL >= PTW32_LEVEL_MAX 108 | #ifdef NEED_ERRNO 109 | #include "need_errno.h" 110 | #else 111 | #include 112 | #endif 113 | #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ 114 | 115 | #define _POSIX_SEMAPHORES 116 | 117 | #ifdef __cplusplus 118 | extern "C" 119 | { 120 | #endif /* __cplusplus */ 121 | 122 | #ifndef HAVE_MODE_T 123 | typedef unsigned int mode_t; 124 | #endif 125 | 126 | 127 | typedef struct sem_t_ * sem_t; 128 | 129 | PTW32_DLLPORT int __cdecl sem_init (sem_t * sem, 130 | int pshared, 131 | unsigned int value); 132 | 133 | PTW32_DLLPORT int __cdecl sem_destroy (sem_t * sem); 134 | 135 | PTW32_DLLPORT int __cdecl sem_trywait (sem_t * sem); 136 | 137 | PTW32_DLLPORT int __cdecl sem_wait (sem_t * sem); 138 | 139 | PTW32_DLLPORT int __cdecl sem_timedwait (sem_t * sem, 140 | const struct timespec * abstime); 141 | 142 | PTW32_DLLPORT int __cdecl sem_post (sem_t * sem); 143 | 144 | PTW32_DLLPORT int __cdecl sem_post_multiple (sem_t * sem, 145 | int count); 146 | 147 | PTW32_DLLPORT int __cdecl sem_open (const char * name, 148 | int oflag, 149 | mode_t mode, 150 | unsigned int value); 151 | 152 | PTW32_DLLPORT int __cdecl sem_close (sem_t * sem); 153 | 154 | PTW32_DLLPORT int __cdecl sem_unlink (const char * name); 155 | 156 | PTW32_DLLPORT int __cdecl sem_getvalue (sem_t * sem, 157 | int * sval); 158 | 159 | #ifdef __cplusplus 160 | } /* End of extern "C" */ 161 | #endif /* __cplusplus */ 162 | 163 | #undef PTW32_LEVEL 164 | #undef PTW32_LEVEL_MAX 165 | 166 | #endif /* !SEMAPHORE_H */ 167 | -------------------------------------------------------------------------------- /zpack/zlib/adler32.c: -------------------------------------------------------------------------------- 1 | /* adler32.c -- compute the Adler-32 checksum of a data stream 2 | * Copyright (C) 1995-2004 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | #define BASE 65521UL /* largest prime smaller than 65536 */ 12 | #define NMAX 5552 13 | /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ 14 | 15 | #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} 16 | #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); 17 | #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); 18 | #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); 19 | #define DO16(buf) DO8(buf,0); DO8(buf,8); 20 | 21 | /* use NO_DIVIDE if your processor does not do division in hardware */ 22 | #ifdef NO_DIVIDE 23 | # define MOD(a) \ 24 | do { \ 25 | if (a >= (BASE << 16)) a -= (BASE << 16); \ 26 | if (a >= (BASE << 15)) a -= (BASE << 15); \ 27 | if (a >= (BASE << 14)) a -= (BASE << 14); \ 28 | if (a >= (BASE << 13)) a -= (BASE << 13); \ 29 | if (a >= (BASE << 12)) a -= (BASE << 12); \ 30 | if (a >= (BASE << 11)) a -= (BASE << 11); \ 31 | if (a >= (BASE << 10)) a -= (BASE << 10); \ 32 | if (a >= (BASE << 9)) a -= (BASE << 9); \ 33 | if (a >= (BASE << 8)) a -= (BASE << 8); \ 34 | if (a >= (BASE << 7)) a -= (BASE << 7); \ 35 | if (a >= (BASE << 6)) a -= (BASE << 6); \ 36 | if (a >= (BASE << 5)) a -= (BASE << 5); \ 37 | if (a >= (BASE << 4)) a -= (BASE << 4); \ 38 | if (a >= (BASE << 3)) a -= (BASE << 3); \ 39 | if (a >= (BASE << 2)) a -= (BASE << 2); \ 40 | if (a >= (BASE << 1)) a -= (BASE << 1); \ 41 | if (a >= BASE) a -= BASE; \ 42 | } while (0) 43 | # define MOD4(a) \ 44 | do { \ 45 | if (a >= (BASE << 4)) a -= (BASE << 4); \ 46 | if (a >= (BASE << 3)) a -= (BASE << 3); \ 47 | if (a >= (BASE << 2)) a -= (BASE << 2); \ 48 | if (a >= (BASE << 1)) a -= (BASE << 1); \ 49 | if (a >= BASE) a -= BASE; \ 50 | } while (0) 51 | #else 52 | # define MOD(a) a %= BASE 53 | # define MOD4(a) a %= BASE 54 | #endif 55 | 56 | /* ========================================================================= */ 57 | uLong ZEXPORT adler32(adler, buf, len) 58 | uLong adler; 59 | const Bytef *buf; 60 | uInt len; 61 | { 62 | unsigned long sum2; 63 | unsigned n; 64 | 65 | /* split Adler-32 into component sums */ 66 | sum2 = (adler >> 16) & 0xffff; 67 | adler &= 0xffff; 68 | 69 | /* in case user likes doing a byte at a time, keep it fast */ 70 | if (len == 1) { 71 | adler += buf[0]; 72 | if (adler >= BASE) 73 | adler -= BASE; 74 | sum2 += adler; 75 | if (sum2 >= BASE) 76 | sum2 -= BASE; 77 | return adler | (sum2 << 16); 78 | } 79 | 80 | /* initial Adler-32 value (deferred check for len == 1 speed) */ 81 | if (buf == Z_NULL) 82 | return 1L; 83 | 84 | /* in case short lengths are provided, keep it somewhat fast */ 85 | if (len < 16) { 86 | while (len--) { 87 | adler += *buf++; 88 | sum2 += adler; 89 | } 90 | if (adler >= BASE) 91 | adler -= BASE; 92 | MOD4(sum2); /* only added so many BASE's */ 93 | return adler | (sum2 << 16); 94 | } 95 | 96 | /* do length NMAX blocks -- requires just one modulo operation */ 97 | while (len >= NMAX) { 98 | len -= NMAX; 99 | n = NMAX / 16; /* NMAX is divisible by 16 */ 100 | do { 101 | DO16(buf); /* 16 sums unrolled */ 102 | buf += 16; 103 | } while (--n); 104 | MOD(adler); 105 | MOD(sum2); 106 | } 107 | 108 | /* do remaining bytes (less than NMAX, still just one modulo) */ 109 | if (len) { /* avoid modulos if none remaining */ 110 | while (len >= 16) { 111 | len -= 16; 112 | DO16(buf); 113 | buf += 16; 114 | } 115 | while (len--) { 116 | adler += *buf++; 117 | sum2 += adler; 118 | } 119 | MOD(adler); 120 | MOD(sum2); 121 | } 122 | 123 | /* return recombined sums */ 124 | return adler | (sum2 << 16); 125 | } 126 | 127 | /* ========================================================================= */ 128 | uLong ZEXPORT adler32_combine(adler1, adler2, len2) 129 | uLong adler1; 130 | uLong adler2; 131 | z_off_t len2; 132 | { 133 | unsigned long sum1; 134 | unsigned long sum2; 135 | unsigned rem; 136 | 137 | /* the derivation of this formula is left as an exercise for the reader */ 138 | rem = (unsigned)(len2 % BASE); 139 | sum1 = adler1 & 0xffff; 140 | sum2 = rem * sum1; 141 | MOD(sum2); 142 | sum1 += (adler2 & 0xffff) + BASE - 1; 143 | sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; 144 | if (sum1 > BASE) sum1 -= BASE; 145 | if (sum1 > BASE) sum1 -= BASE; 146 | if (sum2 > (BASE << 1)) sum2 -= (BASE << 1); 147 | if (sum2 > BASE) sum2 -= BASE; 148 | return sum1 | (sum2 << 16); 149 | } 150 | -------------------------------------------------------------------------------- /zpack/zpack.h: -------------------------------------------------------------------------------- 1 | #ifndef __ZPACK_H__ 2 | #define __ZPACK_H__ 3 | 4 | #include 5 | 6 | // #if defined (_MSC_VER) && defined (UNICODE) 7 | // #define ZP_USE_WCHAR 8 | // #endif 9 | 10 | //#if defined (_MSC_VER) 11 | #define ZP_CASE_SENSITIVE 0 12 | //#else 13 | // #define ZP_CASE_SENSITIVE 1 14 | //#endif 15 | 16 | namespace zp 17 | { 18 | #if defined (ZP_USE_WCHAR) 19 | typedef wchar_t Char; 20 | #ifndef _T 21 | #define _T(str) L##str 22 | #endif 23 | typedef std::wstring String; 24 | #define Fopen _wfopen 25 | #define Strcpy wcscpy_s 26 | #else 27 | typedef char Char; 28 | #ifndef _T 29 | #define _T(str) str 30 | #endif 31 | typedef std::string String; 32 | #define Fopen fopen 33 | #define Strcpy strcpy_s 34 | #endif 35 | 36 | typedef unsigned char u8; 37 | typedef unsigned short u16; 38 | typedef unsigned long u32; 39 | typedef unsigned long long u64; 40 | 41 | const u32 MAX_FILENAME_LEN = 1024; 42 | 43 | const u32 OPEN_READONLY = 1; 44 | const u32 OPEN_NO_FILENAME = 2; 45 | 46 | const u32 PACK_UNICODE = 1; 47 | 48 | const u32 FILE_DELETE = (1<<0); 49 | const u32 FILE_COMPRESS = (1<<1); 50 | //const u32 FILE_WRITING = (1<<2); 51 | 52 | const u32 FILE_FLAG_USER0 = (1<<10); 53 | const u32 FILE_FLAG_USER1 = (1<<11); 54 | 55 | typedef bool (*Callback)(const Char* path, zp::u32 fileSize, void* param); 56 | 57 | class IReadFile; 58 | class IWriteFile; 59 | 60 | /////////////////////////////////////////////////////////////////////////////////////////////////// 61 | class IPackage 62 | { 63 | public: 64 | virtual bool readonly() const = 0; 65 | 66 | virtual const Char* packageFilename() const = 0; 67 | 68 | /////////////////////////////////////////////////////////////////////////////////////////////// 69 | //readonly functions, not available when package is dirty 70 | //IFile will become unavailable after package is modified 71 | 72 | virtual bool hasFile(const Char* filename) const = 0; 73 | virtual IReadFile* openFile(const Char* filename) = 0; 74 | virtual void closeFile(IReadFile* file) = 0; 75 | 76 | virtual u32 getFileCount() const = 0; 77 | virtual bool getFileInfo(u32 index, Char* filenameBuffer, u32 filenameBufferSize, u32* fileSize = 0, 78 | u32* packSize = 0, u32* flag = 0, u32* availableSize = 0, u64* contentHash = 0) const = 0; 79 | virtual bool getFileInfo(const Char* filename, u32* fileSize = 0, u32* packSize = 0, 80 | u32* flag = 0, u32* availableSize = 0, u64* contentHash = 0) const = 0; 81 | 82 | /////////////////////////////////////////////////////////////////////////////////////////////// 83 | //package manipulation fuctions, not available in read only mode 84 | 85 | //do not add same file more than once between flush() call 86 | //outFileSize origin file size 87 | //outPackSize size in package 88 | virtual bool addFile(const Char* filename, const Char* externalFilename, u32 fileSize, u32 flag, 89 | u32* outPackSize = 0, u32* outFlag = 0, u32 chunkSize = 0) = 0; 90 | 91 | virtual IWriteFile* createFile(const Char* filename, u32 fileSize, u32 packSize, 92 | u32 chunkSize = 0, u32 flag = 0, u64 contentHash = 0) = 0; 93 | virtual IWriteFile* openFileToWrite(const Char* filename) = 0; 94 | virtual void closeFile(IWriteFile* file) = 0; 95 | 96 | //can not remove files added after last flush() call 97 | virtual bool removeFile(const Char* filename) = 0; 98 | 99 | //return true if there's any unsaved change of package 100 | virtual bool dirty() const = 0; 101 | 102 | //package file won't change before calling this function 103 | virtual void flush() = 0; 104 | 105 | virtual bool defrag(Callback callback, void* callbackParam) = 0; //can be very slow, don't call this all the time 106 | 107 | virtual u32 getFileUserDataSize() const = 0; 108 | 109 | virtual bool writeFileUserData(const Char* filename, const u8* data, u32 dataLen) = 0; 110 | virtual bool readFileUserData(const Char* filename, u8* data, u32 dataLen) = 0; 111 | 112 | protected: 113 | virtual ~IPackage(){} 114 | }; 115 | 116 | /////////////////////////////////////////////////////////////////////////////////////////////////// 117 | class IReadFile 118 | { 119 | public: 120 | virtual u32 size() const = 0; 121 | 122 | virtual u32 availableSize() const = 0; 123 | 124 | virtual u32 flag() const = 0; 125 | 126 | virtual void seek(u32 pos) = 0; 127 | 128 | virtual u32 tell() const = 0; 129 | 130 | virtual u32 read(u8* buffer, u32 size) = 0; 131 | 132 | protected: 133 | virtual ~IReadFile(){} 134 | }; 135 | 136 | /////////////////////////////////////////////////////////////////////////////////////////////////// 137 | class IWriteFile 138 | { 139 | public: 140 | virtual u32 size() const = 0; 141 | 142 | virtual u32 flag() const = 0; 143 | 144 | virtual void seek(u32 pos) = 0; 145 | 146 | virtual u32 tell() const = 0; 147 | 148 | virtual u32 write(const u8* buffer, u32 size) = 0; 149 | 150 | protected: 151 | virtual ~IWriteFile(){} 152 | }; 153 | 154 | /////////////////////////////////////////////////////////////////////////////////////////////////// 155 | IPackage* create(const Char* filename, u32 chunkSize = 0x40000, u32 fileUserDataSize = 0); 156 | IPackage* open(const Char* filename, u32 flag = OPEN_READONLY | OPEN_NO_FILENAME); 157 | void close(IPackage* package); 158 | 159 | } 160 | 161 | #endif 162 | -------------------------------------------------------------------------------- /zpack/zpack-vs2005.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 25 | 28 | 31 | 34 | 37 | 40 | 53 | 56 | 59 | 62 | 65 | 68 | 71 | 74 | 77 | 80 | 81 | 89 | 92 | 95 | 98 | 101 | 104 | 114 | 117 | 120 | 123 | 126 | 129 | 132 | 135 | 138 | 141 | 142 | 143 | 144 | 145 | 146 | 149 | 152 | 153 | 156 | 157 | 160 | 161 | 164 | 165 | 168 | 169 | 172 | 173 | 176 | 177 | 180 | 181 | 184 | 185 | 188 | 189 | 192 | 193 | 194 | 197 | 198 | 201 | 202 | 205 | 206 | 209 | 210 | 213 | 214 | 217 | 218 | 221 | 222 | 225 | 226 | 229 | 230 | 233 | 234 | 237 | 238 | 241 | 242 | 243 | 244 | 245 | 246 | -------------------------------------------------------------------------------- /zpack/pthread/sched.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Module: sched.h 3 | * 4 | * Purpose: 5 | * Provides an implementation of POSIX realtime extensions 6 | * as defined in 7 | * 8 | * POSIX 1003.1b-1993 (POSIX.1b) 9 | * 10 | * -------------------------------------------------------------------------- 11 | * 12 | * Pthreads-win32 - POSIX Threads Library for Win32 13 | * Copyright(C) 1998 John E. Bossom 14 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 15 | * 16 | * Contact Email: rpj@callisto.canberra.edu.au 17 | * 18 | * The current list of contributors is contained 19 | * in the file CONTRIBUTORS included with the source 20 | * code distribution. The list can also be seen at the 21 | * following World Wide Web location: 22 | * http://sources.redhat.com/pthreads-win32/contributors.html 23 | * 24 | * This library is free software; you can redistribute it and/or 25 | * modify it under the terms of the GNU Lesser General Public 26 | * License as published by the Free Software Foundation; either 27 | * version 2 of the License, or (at your option) any later version. 28 | * 29 | * This library is distributed in the hope that it will be useful, 30 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 31 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 32 | * Lesser General Public License for more details. 33 | * 34 | * You should have received a copy of the GNU Lesser General Public 35 | * License along with this library in the file COPYING.LIB; 36 | * if not, write to the Free Software Foundation, Inc., 37 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 38 | */ 39 | #ifndef _SCHED_H 40 | #define _SCHED_H 41 | 42 | #undef PTW32_LEVEL 43 | 44 | #if defined(_POSIX_SOURCE) 45 | #define PTW32_LEVEL 0 46 | /* Early POSIX */ 47 | #endif 48 | 49 | #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309 50 | #undef PTW32_LEVEL 51 | #define PTW32_LEVEL 1 52 | /* Include 1b, 1c and 1d */ 53 | #endif 54 | 55 | #if defined(INCLUDE_NP) 56 | #undef PTW32_LEVEL 57 | #define PTW32_LEVEL 2 58 | /* Include Non-Portable extensions */ 59 | #endif 60 | 61 | #define PTW32_LEVEL_MAX 3 62 | 63 | #if !defined(PTW32_LEVEL) 64 | #define PTW32_LEVEL PTW32_LEVEL_MAX 65 | /* Include everything */ 66 | #endif 67 | 68 | 69 | #if __GNUC__ && ! defined (__declspec) 70 | # error Please upgrade your GNU compiler to one that supports __declspec. 71 | #endif 72 | 73 | /* 74 | * When building the DLL code, you should define PTW32_BUILD so that 75 | * the variables/functions are exported correctly. When using the DLL, 76 | * do NOT define PTW32_BUILD, and then the variables/functions will 77 | * be imported correctly. 78 | */ 79 | #ifndef PTW32_STATIC_LIB 80 | # ifdef PTW32_BUILD 81 | # define PTW32_DLLPORT __declspec (dllexport) 82 | # else 83 | # define PTW32_DLLPORT __declspec (dllimport) 84 | # endif 85 | #else 86 | # define PTW32_DLLPORT 87 | #endif 88 | 89 | /* 90 | * This is a duplicate of what is in the autoconf config.h, 91 | * which is only used when building the pthread-win32 libraries. 92 | */ 93 | 94 | #ifndef PTW32_CONFIG_H 95 | # if defined(WINCE) 96 | # define NEED_ERRNO 97 | # define NEED_SEM 98 | # endif 99 | # if defined(_UWIN) || defined(__MINGW32__) 100 | # define HAVE_MODE_T 101 | # endif 102 | #endif 103 | 104 | /* 105 | * 106 | */ 107 | 108 | #if PTW32_LEVEL >= PTW32_LEVEL_MAX 109 | #ifdef NEED_ERRNO 110 | #include "need_errno.h" 111 | #else 112 | #include 113 | #endif 114 | #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ 115 | 116 | #if defined(__MINGW32__) || defined(_UWIN) 117 | #if PTW32_LEVEL >= PTW32_LEVEL_MAX 118 | /* For pid_t */ 119 | # include 120 | /* Required by Unix 98 */ 121 | # include 122 | #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ 123 | #else 124 | typedef int pid_t; 125 | #endif 126 | 127 | /* Thread scheduling policies */ 128 | 129 | enum { 130 | SCHED_OTHER = 0, 131 | SCHED_FIFO, 132 | SCHED_RR, 133 | SCHED_MIN = SCHED_OTHER, 134 | SCHED_MAX = SCHED_RR 135 | }; 136 | 137 | struct sched_param { 138 | int sched_priority; 139 | }; 140 | 141 | #ifdef __cplusplus 142 | extern "C" 143 | { 144 | #endif /* __cplusplus */ 145 | 146 | PTW32_DLLPORT int __cdecl sched_yield (void); 147 | 148 | PTW32_DLLPORT int __cdecl sched_get_priority_min (int policy); 149 | 150 | PTW32_DLLPORT int __cdecl sched_get_priority_max (int policy); 151 | 152 | PTW32_DLLPORT int __cdecl sched_setscheduler (pid_t pid, int policy); 153 | 154 | PTW32_DLLPORT int __cdecl sched_getscheduler (pid_t pid); 155 | 156 | /* 157 | * Note that this macro returns ENOTSUP rather than 158 | * ENOSYS as might be expected. However, returning ENOSYS 159 | * should mean that sched_get_priority_{min,max} are 160 | * not implemented as well as sched_rr_get_interval. 161 | * This is not the case, since we just don't support 162 | * round-robin scheduling. Therefore I have chosen to 163 | * return the same value as sched_setscheduler when 164 | * SCHED_RR is passed to it. 165 | */ 166 | #define sched_rr_get_interval(_pid, _interval) \ 167 | ( errno = ENOTSUP, (int) -1 ) 168 | 169 | 170 | #ifdef __cplusplus 171 | } /* End of extern "C" */ 172 | #endif /* __cplusplus */ 173 | 174 | #undef PTW32_LEVEL 175 | #undef PTW32_LEVEL_MAX 176 | 177 | #endif /* !_SCHED_H */ 178 | 179 | -------------------------------------------------------------------------------- /zpack/zpPackage.h: -------------------------------------------------------------------------------- 1 | #ifndef __ZP_PACKAGE_H__ 2 | #define __ZP_PACKAGE_H__ 3 | 4 | #include "zpack.h" 5 | #include 6 | #include 7 | #include "stdio.h" 8 | 9 | #include "pthread.h" 10 | 11 | namespace zp 12 | { 13 | 14 | #if defined (ZP_USE_WCHAR) 15 | #define Remove _wremove 16 | #define Rename _wrename 17 | typedef std::wistringstream IStringStream; 18 | #else 19 | #define Remove remove 20 | #define Rename rename 21 | typedef std::istringstream IStringStream; 22 | #endif 23 | 24 | // fix: modify PACKAGE_FILE_SIGN to DXMP 25 | const u32 PACKAGE_FILE_SIGN = 'DXMP'; 26 | const u32 CURRENT_VERSION = '0030'; 27 | 28 | /////////////////////////////////////////////////////////////////////////////////////////////////// 29 | struct PackageHeader 30 | { 31 | u32 sign; 32 | u32 version; 33 | u32 headerSize; 34 | u32 fileCount; 35 | u64 fileEntryOffset; 36 | u64 filenameOffset; 37 | u32 allFileEntrySize; 38 | u32 allFilenameSize; 39 | u32 originFilenamesSize; //filename size before compression 40 | u32 chunkSize; //file compress unit 41 | u32 flag; 42 | u32 fileEntrySize; 43 | u32 reserved[18]; 44 | }; 45 | 46 | /////////////////////////////////////////////////////////////////////////////////////////////////// 47 | struct FileEntry 48 | { 49 | u64 byteOffset; 50 | u64 nameHash; 51 | u32 packSize; //size in package(may be compressed) 52 | u32 originSize; 53 | u32 flag; 54 | u32 chunkSize; //can be different with chunkSize in package header 55 | u64 contentHash; 56 | u32 availableSize; 57 | u32 reserved; 58 | }; 59 | 60 | /////////////////////////////////////////////////////////////////////////////////////////////////// 61 | class Package : public IPackage 62 | { 63 | friend class File; 64 | friend class CompressedFile; 65 | friend class WriteFile; 66 | 67 | public: 68 | Package(const Char* filename, bool readonly, bool readFilename); 69 | ~Package(); 70 | 71 | bool valid() const; 72 | 73 | virtual bool readonly() const; 74 | 75 | virtual const Char* packageFilename() const; 76 | 77 | virtual bool hasFile(const Char* filename) const; 78 | virtual IReadFile* openFile(const Char* filename); 79 | virtual void closeFile(IReadFile* file); 80 | 81 | virtual u32 getFileCount() const; 82 | virtual bool getFileInfo(u32 index, Char* filenameBuffer, u32 filenameBufferSize, u32* fileSize = 0, 83 | u32* packSize = 0, u32* flag = 0, u32* availableSize = 0, u64* contentHash = 0) const; 84 | virtual bool getFileInfo(const Char* filename, u32* fileSize = 0, u32* packSize = 0, 85 | u32* flag = 0, u32* availableSize = 0, u64* contentHash = 0) const; 86 | 87 | virtual bool addFile(const Char* filename, const Char* exterFilename, u32 fileSize, u32 flag, 88 | u32* outPackSize = 0, u32* outFlag = 0, u32 chunkSize = 0); 89 | virtual IWriteFile* createFile(const Char* filename, u32 fileSize, u32 packSize, 90 | u32 chunkSize = 0, u32 flag = 0, u64 contentHash = 0); 91 | virtual IWriteFile* openFileToWrite(const Char* filename); 92 | virtual void closeFile(IWriteFile* file); 93 | 94 | virtual bool removeFile(const Char* filename); 95 | virtual bool dirty() const; 96 | virtual void flush(); 97 | 98 | virtual bool defrag(Callback callback, void* callbackParam); 99 | 100 | virtual u32 getFileUserDataSize() const; 101 | 102 | virtual bool writeFileUserData(const Char* filename, const u8* data, u32 dataLen); 103 | virtual bool readFileUserData(const Char* filename, u8* data, u32 dataLen); 104 | 105 | private: 106 | bool readHeader(); 107 | bool readFileEntries(); 108 | bool readFilenames(); 109 | 110 | void removeDeletedEntries(); 111 | 112 | void writeTables(bool avoidOverwrite); 113 | 114 | bool buildHashTable(); 115 | int getFileIndex(const Char* filename) const; 116 | int getFileIndex(u64 nameHash) const; 117 | u32 insertFileEntry(FileEntry& entry, const Char* filename); 118 | bool insertFileHash(u64 nameHash, u32 entryIndex); 119 | 120 | u64 stringHash(const Char* str, u32 seed) const; 121 | 122 | void fixHashTable(u32 index); 123 | 124 | void writeRawFile(FileEntry& entry, FILE* file); 125 | 126 | //for writing file 127 | u32 getFileAvailableSize(u64 nameHash) const; 128 | bool setFileAvailableSize(u64 nameHash, u32 size); 129 | 130 | FileEntry& getFileEntry(u32 index) const; 131 | 132 | private: 133 | 134 | mutable pthread_mutex_t mutex_; 135 | 136 | String m_packageFilename; 137 | mutable FILE* m_stream; 138 | PackageHeader m_header; 139 | u32 m_hashBits; 140 | std::vector m_hashTable; 141 | std::vector m_fileEntries; 142 | std::vector m_filenames; 143 | u64 m_packageEnd; 144 | u32 m_hashMask; 145 | std::vector m_chunkData; 146 | std::vector m_compressBuffer; 147 | std::vector m_chunkPosBuffer; 148 | mutable void* m_lastSeekFile; 149 | bool m_readonly; 150 | bool m_dirty; 151 | }; 152 | 153 | /////////////////////////////////////////////////////////////////////////////////////////////////// 154 | inline u32 Package::getFileCount() const 155 | { 156 | return (u32)(m_fileEntries.size() / m_header.fileEntrySize); 157 | } 158 | 159 | //////////////////////////////////////////////////////////////////////////////////////////////////// 160 | inline FileEntry& Package::getFileEntry(u32 index) const 161 | { 162 | return *((FileEntry*)&m_fileEntries[index * m_header.fileEntrySize]); 163 | } 164 | 165 | //////////////////////////////////////////////////////////////////////////////////////////////////// 166 | class Lock 167 | { 168 | public: 169 | Lock(pthread_mutex_t* mutex) : mutex_(mutex){ pthread_mutex_lock(mutex_); } 170 | ~Lock() { pthread_mutex_unlock(mutex_); } 171 | pthread_mutex_t* mutex_; 172 | }; 173 | 174 | #define SCOPE_LOCK Lock localLock(&mutex_) 175 | #define PACKAGE_LOCK Lock localLock(&(m_package->mutex_)) 176 | }; 177 | #endif -------------------------------------------------------------------------------- /zpEditor/zpEditorDoc.cpp: -------------------------------------------------------------------------------- 1 | 2 | // zpEditorDoc.cpp : implementation of the CzpEditorDoc class 3 | // 4 | 5 | #include "stdafx.h" 6 | // SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail 7 | // and search filter handlers and allows sharing of document code with that project. 8 | #ifndef SHARED_HANDLERS 9 | #include "zpEditor.h" 10 | #endif 11 | 12 | #include "zpEditorDoc.h" 13 | #include "ProgressDialog.h" 14 | 15 | #include 16 | #include 17 | 18 | #ifdef _DEBUG 19 | #define new DEBUG_NEW 20 | #endif 21 | 22 | // CzpEditorDoc 23 | 24 | IMPLEMENT_DYNCREATE(CzpEditorDoc, CDocument) 25 | 26 | BEGIN_MESSAGE_MAP(CzpEditorDoc, CDocument) 27 | END_MESSAGE_MAP() 28 | 29 | 30 | // CzpEditorDoc construction/destruction 31 | 32 | CzpEditorDoc::CzpEditorDoc() 33 | { 34 | // TODO: add one-time construction code here 35 | 36 | } 37 | 38 | CzpEditorDoc::~CzpEditorDoc() 39 | { 40 | } 41 | 42 | BOOL CzpEditorDoc::OnNewDocument() 43 | { 44 | if (!CDocument::OnNewDocument()) 45 | return FALSE; 46 | 47 | // TODO: add reinitialization code here 48 | // (SDI documents will reuse this document) 49 | 50 | return TRUE; 51 | } 52 | 53 | BOOL CzpEditorDoc::OnOpenDocument(LPCTSTR lpszPathName) 54 | { 55 | zp::String filename = lpszPathName; 56 | 57 | if (!m_explorer.open(lpszPathName, false) 58 | && !m_explorer.open(lpszPathName, true)) 59 | { 60 | ::MessageBox(NULL, _T("Invalid zpack file or version mismatch."), _T("Error"), MB_OK | MB_ICONERROR); 61 | return FALSE; 62 | } 63 | size_t pos = filename.find_last_of(_T('\\')); 64 | if (pos != std::string::npos) 65 | { 66 | ::SetCurrentDirectory(filename.substr(0, pos).c_str()); 67 | } 68 | 69 | UpdateAllViews(NULL, TRUE); 70 | return TRUE; 71 | } 72 | 73 | //double g_addTime = 0; 74 | 75 | void CzpEditorDoc::addFilesToPackage(std::vector& filenames) 76 | { 77 | if (!m_explorer.isOpen()) 78 | { 79 | return; 80 | } 81 | 82 | //__int64 perfBefore, perfAfter, perfFreq; 83 | //::QueryPerformanceFrequency((LARGE_INTEGER*)&perfFreq); 84 | //::QueryPerformanceCounter((LARGE_INTEGER*)&perfBefore); 85 | 86 | std::vector> params; 87 | zp::u64 totalFileSize = 0; 88 | for (zp::u32 i = 0; i < filenames.size(); ++i) 89 | { 90 | totalFileSize += m_explorer.countDiskFileSize(filenames[i]); 91 | params.push_back(std::make_pair(filenames[i], _T(""))); 92 | } 93 | startOperation(ProgressDialog::OP_ADD, totalFileSize, ¶ms); 94 | 95 | //::QueryPerformanceCounter((LARGE_INTEGER*)&perfAfter); 96 | //double perfTime = 1000.0 * (perfAfter - perfBefore) / perfFreq; 97 | //g_addTime += perfTime; 98 | 99 | //temp 100 | //extern double g_compressTime; 101 | //extern double g_addFileTime; 102 | //extern double g_readTime; 103 | //char out[128]; 104 | //sprintf(out, "total:%fms, readTime:%fms, addFile:%fms, compress:%fms", g_addTime, g_readTime, g_addFileTime, g_compressTime); 105 | //::MessageBoxA(NULL, out, "compress", MB_OK); 106 | //g_compressTime = 0; 107 | //g_addFileTime = 0; 108 | //g_addTime = 0; 109 | //g_readTime = 0; 110 | 111 | UpdateAllViews(NULL); 112 | } 113 | 114 | // CzpEditorDoc serialization 115 | 116 | void CzpEditorDoc::Serialize(CArchive& ar) 117 | { 118 | if (ar.IsStoring()) 119 | { 120 | // TODO: add storing code here 121 | } 122 | else 123 | { 124 | // TODO: add loading code here 125 | } 126 | } 127 | 128 | #ifdef SHARED_HANDLERS 129 | 130 | // Support for thumbnails 131 | void CzpEditorDoc::OnDrawThumbnail(CDC& dc, LPRECT lprcBounds) 132 | { 133 | // Modify this code to draw the document's data 134 | dc.FillSolidRect(lprcBounds, RGB(255, 255, 255)); 135 | 136 | CString strText = _T("TODO: implement thumbnail drawing here"); 137 | LOGFONT lf; 138 | 139 | CFont* pDefaultGUIFont = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT)); 140 | pDefaultGUIFont->GetLogFont(&lf); 141 | lf.lfHeight = 36; 142 | 143 | CFont fontDraw; 144 | fontDraw.CreateFontIndirect(&lf); 145 | 146 | CFont* pOldFont = dc.SelectObject(&fontDraw); 147 | dc.DrawText(strText, lprcBounds, DT_CENTER | DT_WORDBREAK); 148 | dc.SelectObject(pOldFont); 149 | } 150 | 151 | // Support for Search Handlers 152 | void CzpEditorDoc::InitializeSearchContent() 153 | { 154 | CString strSearchContent; 155 | // Set search contents from document's data. 156 | // The content parts should be separated by ";" 157 | 158 | // For example: strSearchContent = _T("point;rectangle;circle;ole object;"); 159 | SetSearchContent(strSearchContent); 160 | } 161 | 162 | void CzpEditorDoc::SetSearchContent(const CString& value) 163 | { 164 | if (value.IsEmpty()) 165 | { 166 | RemoveChunk(PKEY_Search_Contents.fmtid, PKEY_Search_Contents.pid); 167 | } 168 | else 169 | { 170 | CMFCFilterChunkValueImpl *pChunk = NULL; 171 | ATLTRY(pChunk = new CMFCFilterChunkValueImpl); 172 | if (pChunk != NULL) 173 | { 174 | pChunk->SetTextValue(PKEY_Search_Contents, value, CHUNK_TEXT); 175 | SetChunkValue(pChunk); 176 | } 177 | } 178 | } 179 | 180 | #endif // SHARED_HANDLERS 181 | 182 | // CzpEditorDoc diagnostics 183 | 184 | #ifdef _DEBUG 185 | void CzpEditorDoc::AssertValid() const 186 | { 187 | CDocument::AssertValid(); 188 | } 189 | 190 | void CzpEditorDoc::Dump(CDumpContext& dc) const 191 | { 192 | CDocument::Dump(dc); 193 | } 194 | #endif //_DEBUG 195 | 196 | 197 | // CzpEditorDoc commands 198 | 199 | ZpExplorer& CzpEditorDoc::GetZpExplorer() 200 | { 201 | return m_explorer; 202 | } 203 | 204 | void CzpEditorDoc::startOperation(ProgressDialog::Operation op, zp::u64 totalFileSize, 205 | const std::vector>* params) 206 | { 207 | ProgressDialog progressDlg; 208 | progressDlg.m_explorer = &m_explorer; 209 | progressDlg.m_running = true; 210 | progressDlg.m_params = params; 211 | progressDlg.m_operation = op; 212 | progressDlg.m_totalFileSize = totalFileSize; 213 | progressDlg.DoModal(); 214 | } -------------------------------------------------------------------------------- /zpEditor/zpEditor.cpp: -------------------------------------------------------------------------------- 1 | 2 | // zpEditor.cpp : Defines the class behaviors for the application. 3 | // 4 | 5 | #include "stdafx.h" 6 | #include "afxwinappex.h" 7 | #include "afxdialogex.h" 8 | #include "zpEditor.h" 9 | #include "MainFrm.h" 10 | 11 | #include "zpEditorDoc.h" 12 | #include "LeftView.h" 13 | 14 | #ifdef _DEBUG 15 | #define new DEBUG_NEW 16 | #endif 17 | 18 | 19 | // CzpEditorApp 20 | 21 | BEGIN_MESSAGE_MAP(CzpEditorApp, CWinAppEx) 22 | ON_COMMAND(ID_APP_ABOUT, &CzpEditorApp::OnAppAbout) 23 | END_MESSAGE_MAP() 24 | 25 | 26 | // CzpEditorApp construction 27 | 28 | CzpEditorApp::CzpEditorApp() 29 | { 30 | m_bHiColorIcons = TRUE; 31 | 32 | // TODO: replace application ID string below with unique ID string; recommended 33 | // format for string is CompanyName.ProductName.SubProduct.VersionInformation 34 | SetAppID(_T("zpEditor.AppID.NoVersion")); 35 | 36 | // TODO: add construction code here, 37 | // Place all significant initialization in InitInstance 38 | } 39 | 40 | // The one and only CzpEditorApp object 41 | 42 | CzpEditorApp theApp; 43 | 44 | 45 | // CzpEditorApp initialization 46 | 47 | BOOL CzpEditorApp::InitInstance() 48 | { 49 | // InitCommonControlsEx() is required on Windows XP if an application 50 | // manifest specifies use of ComCtl32.dll version 6 or later to enable 51 | // visual styles. Otherwise, any window creation will fail. 52 | INITCOMMONCONTROLSEX InitCtrls; 53 | InitCtrls.dwSize = sizeof(InitCtrls); 54 | // Set this to include all the common control classes you want to use 55 | // in your application. 56 | InitCtrls.dwICC = ICC_WIN95_CLASSES; 57 | InitCommonControlsEx(&InitCtrls); 58 | 59 | CWinAppEx::InitInstance(); 60 | 61 | 62 | // Initialize OLE libraries 63 | if (!AfxOleInit()) 64 | { 65 | AfxMessageBox(IDP_OLE_INIT_FAILED); 66 | return FALSE; 67 | } 68 | 69 | AfxEnableControlContainer(); 70 | 71 | EnableTaskbarInteraction(FALSE); 72 | 73 | // AfxInitRichEdit2() is required to use RichEdit control 74 | // AfxInitRichEdit2(); 75 | 76 | // Standard initialization 77 | // If you are not using these features and wish to reduce the size 78 | // of your final executable, you should remove from the following 79 | // the specific initialization routines you do not need 80 | // Change the registry key under which our settings are stored 81 | // TODO: You should modify this string to be something appropriate 82 | // such as the name of your company or organization 83 | SetRegistryKey(_T("Local AppWizard-Generated Applications")); 84 | LoadStdProfileSettings(4); // Load standard INI file options (including MRU) 85 | 86 | 87 | InitContextMenuManager(); 88 | 89 | InitKeyboardManager(); 90 | 91 | InitTooltipManager(); 92 | CMFCToolTipInfo ttParams; 93 | ttParams.m_bVislManagerTheme = TRUE; 94 | theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL, 95 | RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams); 96 | 97 | // Register the application's document templates. Document templates 98 | // serve as the connection between documents, frame windows and views 99 | CSingleDocTemplate* pDocTemplate; 100 | pDocTemplate = new CSingleDocTemplate( 101 | IDR_MAINFRAME, 102 | RUNTIME_CLASS(CzpEditorDoc), 103 | RUNTIME_CLASS(CMainFrame), // main SDI frame window 104 | RUNTIME_CLASS(CLeftView)); 105 | if (!pDocTemplate) 106 | return FALSE; 107 | AddDocTemplate(pDocTemplate); 108 | 109 | 110 | // Parse command line for standard shell commands, DDE, file open 111 | CCommandLineInfo cmdInfo; 112 | ParseCommandLine(cmdInfo); 113 | 114 | // Enable DDE Execute open 115 | EnableShellOpen(); 116 | RegisterShellFileTypes(TRUE); 117 | 118 | 119 | // Dispatch commands specified on the command line. Will return FALSE if 120 | // app was launched with /RegServer, /Register, /Unregserver or /Unregister. 121 | if (!ProcessShellCommand(cmdInfo)) 122 | return FALSE; 123 | 124 | // The one and only window has been initialized, so show and update it 125 | m_pMainWnd->ShowWindow(SW_SHOW); 126 | m_pMainWnd->UpdateWindow(); 127 | // call DragAcceptFiles only if there's a suffix 128 | // In an SDI app, this should occur after ProcessShellCommand 129 | // Enable drag/drop open 130 | m_pMainWnd->DragAcceptFiles(); 131 | return TRUE; 132 | } 133 | 134 | int CzpEditorApp::ExitInstance() 135 | { 136 | //TODO: handle additional resources you may have added 137 | AfxOleTerm(FALSE); 138 | 139 | return CWinAppEx::ExitInstance(); 140 | } 141 | 142 | // CzpEditorApp message handlers 143 | 144 | 145 | // CAboutDlg dialog used for App About 146 | 147 | class CAboutDlg : public CDialogEx 148 | { 149 | public: 150 | CAboutDlg(); 151 | 152 | // Dialog Data 153 | enum { IDD = IDD_ABOUTBOX }; 154 | 155 | protected: 156 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support 157 | 158 | // Implementation 159 | protected: 160 | DECLARE_MESSAGE_MAP() 161 | public: 162 | CString m_encode; 163 | }; 164 | 165 | CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD) 166 | , m_encode(_T("")) 167 | { 168 | #if defined (UNICODE) 169 | m_encode = _T("Unicode Build"); 170 | #else 171 | m_encode = _T("ANSI Build"); 172 | #endif 173 | } 174 | 175 | void CAboutDlg::DoDataExchange(CDataExchange* pDX) 176 | { 177 | CDialogEx::DoDataExchange(pDX); 178 | DDX_Text(pDX, IDC_STATIC_ENCODE, m_encode); 179 | } 180 | 181 | BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx) 182 | END_MESSAGE_MAP() 183 | 184 | // App command to run the dialog 185 | void CzpEditorApp::OnAppAbout() 186 | { 187 | CAboutDlg aboutDlg; 188 | aboutDlg.DoModal(); 189 | } 190 | 191 | // CzpEditorApp customization load/save methods 192 | 193 | void CzpEditorApp::PreLoadState() 194 | { 195 | BOOL bNameValid; 196 | CString strName; 197 | bNameValid = strName.LoadString(IDS_EDIT_MENU); 198 | ASSERT(bNameValid); 199 | GetContextMenuManager()->AddMenu(strName, IDR_POPUP_EDIT); 200 | } 201 | 202 | void CzpEditorApp::LoadCustomState() 203 | { 204 | } 205 | 206 | void CzpEditorApp::SaveCustomState() 207 | { 208 | } 209 | 210 | // CzpEditorApp message handlers 211 | 212 | 213 | 214 | -------------------------------------------------------------------------------- /zpCmd/zpCmd.cpp: -------------------------------------------------------------------------------- 1 | // ptest.cpp : Defines the entry point for the console application. 2 | // 3 | #include 4 | #include 5 | #include "zpack.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "zpExplorer.h" 12 | 13 | using namespace std; 14 | 15 | #ifdef UNICODE 16 | #define COUT wcout 17 | #define CIN wcin 18 | typedef std::wistringstream IStringStream; 19 | #else 20 | #define COUT cout 21 | #define CIN cin 22 | typedef std::istringstream IStringStream; 23 | #endif 24 | 25 | bool zpcallback(const zp::Char* path, zp::u32 fileSize, void* param) 26 | { 27 | COUT << path << endl; 28 | return true; 29 | } 30 | 31 | typedef bool (*CommandProc)(const zp::String& param0, const zp::String& param1); 32 | 33 | map g_commandHandlers; 34 | 35 | #define CMD_PROC(cmd) bool cmd##_proc(const zp::String& param0, const zp::String& param1) 36 | #define REGISTER_CMD(cmd) g_commandHandlers[_T(#cmd)] = &cmd##_proc; 37 | 38 | ZpExplorer g_explorer; 39 | 40 | CMD_PROC(exit) 41 | { 42 | exit(0); 43 | return true; 44 | } 45 | 46 | CMD_PROC(open) 47 | { 48 | return g_explorer.open(param0, false) || g_explorer.open(param0, true); 49 | } 50 | 51 | CMD_PROC(create) 52 | { 53 | return g_explorer.create(param0, param1); 54 | } 55 | 56 | CMD_PROC(close) 57 | { 58 | g_explorer.close(); 59 | return true; 60 | } 61 | 62 | CMD_PROC(dir) 63 | { 64 | const ZpNode* node = g_explorer.currentNode(); 65 | for (list::const_iterator iter = node->children.begin(); 66 | iter != node->children.end(); 67 | ++iter) 68 | { 69 | if (iter->isDirectory) 70 | { 71 | COUT << _T(" <") << iter->name << _T(">") << endl; 72 | } 73 | else 74 | { 75 | COUT << _T(" ") << iter->name << endl; 76 | } 77 | } 78 | return true; 79 | } 80 | 81 | CMD_PROC(cd) 82 | { 83 | return g_explorer.enterDir(param0); 84 | } 85 | 86 | CMD_PROC(add) 87 | { 88 | return g_explorer.add(param0, param1); 89 | } 90 | 91 | CMD_PROC(del) 92 | { 93 | return g_explorer.remove(param0); 94 | } 95 | 96 | CMD_PROC(extract) 97 | { 98 | return g_explorer.extract(param0, param1); 99 | } 100 | 101 | //CMD_PROC(fragment) 102 | //{ 103 | // zp::IPackage* pack = g_explorer.getPack(); 104 | // if (pack == NULL) 105 | // { 106 | // return false; 107 | // } 108 | // unsigned __int64 fragSize = pack->countFragmentSize(); 109 | // COUT << "fragment:" << fragSize << " bytes" << endl; 110 | // return true; 111 | //} 112 | 113 | CMD_PROC(defrag) 114 | { 115 | zp::IPackage* pack = g_explorer.getPack(); 116 | if (pack == NULL) 117 | { 118 | return false; 119 | } 120 | return (pack != NULL && pack->defrag(NULL, NULL)); 121 | } 122 | 123 | CMD_PROC(help) 124 | { 125 | #define HELP_ITEM(cmd, explain) COUT << cmd << endl << " "explain << endl; 126 | HELP_ITEM("create [package path] [initial dir path]", "create a package from scratch"); 127 | HELP_ITEM("open [package path]", "open an existing package"); 128 | HELP_ITEM("close", "close current package"); 129 | HELP_ITEM("cd [internal path]", "enter specified directory of package"); 130 | HELP_ITEM("dir", "show files and sub-directories of current directory of package"); 131 | HELP_ITEM("add [soure path] [dest path]", "add a disk file or directory to package"); 132 | HELP_ITEM("del [internal path]", "delete a file or directory from package"); 133 | HELP_ITEM("extract [source path] [dest path]", "extrace file or directories to disk"); 134 | //HELP_ITEM("fragment", "calculate fragment bytes and how many bytes to move to defrag"); 135 | HELP_ITEM("defrag", "compact file, remove all fragments"); 136 | HELP_ITEM("exit", "exit program"); 137 | return true; 138 | } 139 | 140 | bool processCmdLine(int argc, _TCHAR* argv[]) 141 | { 142 | if (argc < 4) 143 | { 144 | return false; 145 | } 146 | zp::String cmd = argv[1]; 147 | zp::String packPath = argv[2]; 148 | zp::String filePath = argv[3]; 149 | 150 | if (cmd == _T("add")) 151 | { 152 | if (!g_explorer.open(packPath)) 153 | { 154 | g_explorer.create(packPath, _T("")); 155 | } 156 | zp::String relativePath; 157 | if (argc > 4) 158 | { 159 | relativePath = argv[4]; 160 | } 161 | g_explorer.add(filePath, relativePath); 162 | } 163 | else if (cmd == _T("extract")) 164 | { 165 | if (g_explorer.open(packPath)) 166 | { 167 | g_explorer.extract(_T("."), filePath); 168 | } 169 | } 170 | g_explorer.close(); 171 | return true; 172 | } 173 | 174 | int _tmain(int argc, _TCHAR* argv[]) 175 | { 176 | g_explorer.setCallback(zpcallback, NULL); 177 | 178 | if (processCmdLine(argc, argv)) 179 | { 180 | return 0; 181 | } 182 | REGISTER_CMD(exit); 183 | REGISTER_CMD(create); 184 | REGISTER_CMD(open); 185 | REGISTER_CMD(add); 186 | REGISTER_CMD(del); 187 | REGISTER_CMD(extract); 188 | REGISTER_CMD(close); 189 | REGISTER_CMD(dir); 190 | REGISTER_CMD(cd); 191 | //REGISTER_CMD(fragment); 192 | REGISTER_CMD(defrag); 193 | REGISTER_CMD(help); 194 | 195 | while (true) 196 | { 197 | const zp::String packName = g_explorer.packageFilename(); 198 | if (!packName.empty()) 199 | { 200 | COUT << packName; 201 | if (g_explorer.isOpen()) 202 | { 203 | COUT << DIR_STR << g_explorer.currentPath() << _T("\b"); //delete extra '\' 204 | } 205 | if (g_explorer.getPack()->readonly()) 206 | { 207 | COUT << _T("-readonly"); 208 | } 209 | COUT << _T(">"); 210 | } 211 | else 212 | { 213 | COUT << _T("zp>"); 214 | } 215 | zp::String input, command, param0, param1; 216 | getline(CIN, input); 217 | 218 | size_t pos = 0; 219 | 220 | IStringStream iss(input, IStringStream::in); 221 | iss >> command; 222 | iss >> param0; 223 | iss >> param1; 224 | map::iterator found = g_commandHandlers.find(command); 225 | if (found == g_commandHandlers.end()) 226 | { 227 | COUT << _T("<") << command << _T("> command not found. try 'help' command.") << endl; 228 | } 229 | else if (!found->second(param0, param1)) 230 | { 231 | COUT << _T("<") << command << _T("> execute failed.") << endl; 232 | } 233 | } 234 | return 0; 235 | } 236 | -------------------------------------------------------------------------------- /zpack/zlib/inflate.h: -------------------------------------------------------------------------------- 1 | /* inflate.h -- internal inflate state definition 2 | * Copyright (C) 1995-2004 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* define NO_GZIP when compiling if you want to disable gzip header and 12 | trailer decoding by inflate(). NO_GZIP would be used to avoid linking in 13 | the crc code when it is not needed. For shared libraries, gzip decoding 14 | should be left enabled. */ 15 | #ifndef NO_GZIP 16 | # define GUNZIP 17 | #endif 18 | 19 | /* Possible inflate modes between inflate() calls */ 20 | typedef enum { 21 | HEAD, /* i: waiting for magic header */ 22 | FLAGS, /* i: waiting for method and flags (gzip) */ 23 | TIME, /* i: waiting for modification time (gzip) */ 24 | OS, /* i: waiting for extra flags and operating system (gzip) */ 25 | EXLEN, /* i: waiting for extra length (gzip) */ 26 | EXTRA, /* i: waiting for extra bytes (gzip) */ 27 | NAME, /* i: waiting for end of file name (gzip) */ 28 | COMMENT, /* i: waiting for end of comment (gzip) */ 29 | HCRC, /* i: waiting for header crc (gzip) */ 30 | DICTID, /* i: waiting for dictionary check value */ 31 | DICT, /* waiting for inflateSetDictionary() call */ 32 | TYPE, /* i: waiting for type bits, including last-flag bit */ 33 | TYPEDO, /* i: same, but skip check to exit inflate on new block */ 34 | STORED, /* i: waiting for stored size (length and complement) */ 35 | COPY, /* i/o: waiting for input or output to copy stored block */ 36 | TABLE, /* i: waiting for dynamic block table lengths */ 37 | LENLENS, /* i: waiting for code length code lengths */ 38 | CODELENS, /* i: waiting for length/lit and distance code lengths */ 39 | LEN, /* i: waiting for length/lit code */ 40 | LENEXT, /* i: waiting for length extra bits */ 41 | DIST, /* i: waiting for distance code */ 42 | DISTEXT, /* i: waiting for distance extra bits */ 43 | MATCH, /* o: waiting for output space to copy string */ 44 | LIT, /* o: waiting for output space to write literal */ 45 | CHECK, /* i: waiting for 32-bit check value */ 46 | LENGTH, /* i: waiting for 32-bit length (gzip) */ 47 | DONE, /* finished check, done -- remain here until reset */ 48 | BAD, /* got a data error -- remain here until reset */ 49 | MEM, /* got an inflate() memory error -- remain here until reset */ 50 | SYNC /* looking for synchronization bytes to restart inflate() */ 51 | } inflate_mode; 52 | 53 | /* 54 | State transitions between above modes - 55 | 56 | (most modes can go to the BAD or MEM mode -- not shown for clarity) 57 | 58 | Process header: 59 | HEAD -> (gzip) or (zlib) 60 | (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME 61 | NAME -> COMMENT -> HCRC -> TYPE 62 | (zlib) -> DICTID or TYPE 63 | DICTID -> DICT -> TYPE 64 | Read deflate blocks: 65 | TYPE -> STORED or TABLE or LEN or CHECK 66 | STORED -> COPY -> TYPE 67 | TABLE -> LENLENS -> CODELENS -> LEN 68 | Read deflate codes: 69 | LEN -> LENEXT or LIT or TYPE 70 | LENEXT -> DIST -> DISTEXT -> MATCH -> LEN 71 | LIT -> LEN 72 | Process trailer: 73 | CHECK -> LENGTH -> DONE 74 | */ 75 | 76 | /* state maintained between inflate() calls. Approximately 7K bytes. */ 77 | struct inflate_state { 78 | inflate_mode mode; /* current inflate mode */ 79 | int last; /* true if processing last block */ 80 | int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ 81 | int havedict; /* true if dictionary provided */ 82 | int flags; /* gzip header method and flags (0 if zlib) */ 83 | unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ 84 | unsigned long check; /* protected copy of check value */ 85 | unsigned long total; /* protected copy of output count */ 86 | gz_headerp head; /* where to save gzip header information */ 87 | /* sliding window */ 88 | unsigned wbits; /* log base 2 of requested window size */ 89 | unsigned wsize; /* window size or zero if not using window */ 90 | unsigned whave; /* valid bytes in the window */ 91 | unsigned write; /* window write index */ 92 | unsigned char FAR *window; /* allocated sliding window, if needed */ 93 | /* bit accumulator */ 94 | unsigned long hold; /* input bit accumulator */ 95 | unsigned bits; /* number of bits in "in" */ 96 | /* for string and stored block copying */ 97 | unsigned length; /* literal or length of data to copy */ 98 | unsigned offset; /* distance back to copy string from */ 99 | /* for table and code decoding */ 100 | unsigned extra; /* extra bits needed */ 101 | /* fixed and dynamic code tables */ 102 | code const FAR *lencode; /* starting table for length/literal codes */ 103 | code const FAR *distcode; /* starting table for distance codes */ 104 | unsigned lenbits; /* index bits for lencode */ 105 | unsigned distbits; /* index bits for distcode */ 106 | /* dynamic table building */ 107 | unsigned ncode; /* number of code length code lengths */ 108 | unsigned nlen; /* number of length code lengths */ 109 | unsigned ndist; /* number of distance code lengths */ 110 | unsigned have; /* number of code lengths in lens[] */ 111 | code FAR *next; /* next available space in codes[] */ 112 | unsigned short lens[320]; /* temporary storage for code lengths */ 113 | unsigned short work[288]; /* work area for code table building */ 114 | code codes[ENOUGH]; /* space for code tables */ 115 | }; 116 | -------------------------------------------------------------------------------- /zpack/zlib/inffixed.h: -------------------------------------------------------------------------------- 1 | /* inffixed.h -- table for decoding fixed codes 2 | * Generated automatically by makefixed(). 3 | */ 4 | 5 | /* WARNING: this file should *not* be used by applications. It 6 | is part of the implementation of the compression library and 7 | is subject to change. Applications should only use zlib.h. 8 | */ 9 | 10 | static const code lenfix[512] = { 11 | {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, 12 | {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, 13 | {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, 14 | {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, 15 | {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, 16 | {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, 17 | {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, 18 | {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, 19 | {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, 20 | {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, 21 | {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, 22 | {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, 23 | {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, 24 | {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, 25 | {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, 26 | {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, 27 | {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, 28 | {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, 29 | {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, 30 | {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, 31 | {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, 32 | {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, 33 | {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, 34 | {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, 35 | {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, 36 | {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, 37 | {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, 38 | {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, 39 | {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, 40 | {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, 41 | {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, 42 | {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, 43 | {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, 44 | {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, 45 | {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, 46 | {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, 47 | {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, 48 | {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, 49 | {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, 50 | {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, 51 | {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, 52 | {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, 53 | {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, 54 | {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, 55 | {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, 56 | {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, 57 | {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, 58 | {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, 59 | {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, 60 | {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, 61 | {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, 62 | {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, 63 | {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, 64 | {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, 65 | {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, 66 | {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, 67 | {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, 68 | {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, 69 | {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, 70 | {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, 71 | {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, 72 | {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, 73 | {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, 74 | {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, 75 | {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, 76 | {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, 77 | {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, 78 | {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, 79 | {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, 80 | {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, 81 | {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, 82 | {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, 83 | {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, 84 | {0,9,255} 85 | }; 86 | 87 | static const code distfix[32] = { 88 | {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, 89 | {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, 90 | {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, 91 | {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, 92 | {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, 93 | {22,5,193},{64,5,0} 94 | }; 95 | -------------------------------------------------------------------------------- /zpCmd/zpCmd-vs2010.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release_editor 10 | Win32 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | {64EC7A26-97C8-4526-A29A-097D53D7C9B5} 29 | Win32Proj 30 | ptest 31 | zpCmd 32 | 33 | 34 | 35 | Application 36 | true 37 | MultiByte 38 | 39 | 40 | Application 41 | false 42 | true 43 | MultiByte 44 | 45 | 46 | Application 47 | false 48 | true 49 | MultiByte 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | true 66 | $(ProjectName)D 67 | 68 | 69 | false 70 | $(ProjectName) 71 | 72 | 73 | false 74 | $(ProjectName) 75 | 76 | 77 | 78 | 79 | 80 | Level3 81 | Disabled 82 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS 83 | ../zpack 84 | MultiThreadedDebugDLL 85 | 86 | 87 | Console 88 | true 89 | zpackD.lib;pthreadVCE2.lib;%(AdditionalDependencies) 90 | ../zpack/$(Configuration) 91 | 92 | 93 | 94 | 95 | Level3 96 | 97 | 98 | MaxSpeed 99 | true 100 | true 101 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS 102 | ../zpack 103 | MultiThreadedDLL 104 | 105 | 106 | Console 107 | true 108 | true 109 | true 110 | ../zpack/$(Configuration) 111 | zpack.lib;pthreadVCE2.lib;%(AdditionalDependencies) 112 | 113 | 114 | 115 | 116 | Level3 117 | 118 | 119 | MaxSpeed 120 | true 121 | true 122 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS 123 | ../zpack 124 | MultiThreaded 125 | 126 | 127 | Console 128 | true 129 | true 130 | true 131 | ../zpack/$(Configuration) 132 | zpack.lib;pthreadVCE2.lib;%(AdditionalDependencies) 133 | 134 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /zpCmd/zpCmd-vs2012.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release_editor 10 | Win32 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | {64EC7A26-97C8-4526-A29A-097D53D7C9B5} 29 | Win32Proj 30 | ptest 31 | zpCmd 32 | 33 | 34 | 35 | Application 36 | true 37 | MultiByte 38 | v110 39 | 40 | 41 | Application 42 | false 43 | true 44 | MultiByte 45 | v110 46 | 47 | 48 | Application 49 | false 50 | true 51 | MultiByte 52 | v110 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | true 69 | $(ProjectName)D 70 | 71 | 72 | false 73 | $(ProjectName) 74 | 75 | 76 | false 77 | $(ProjectName) 78 | 79 | 80 | 81 | 82 | 83 | Level3 84 | Disabled 85 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS 86 | ../zpack 87 | MultiThreadedDebugDLL 88 | 89 | 90 | Console 91 | true 92 | zpackD.lib;pthreadVCE2.lib;%(AdditionalDependencies) 93 | ../zpack/$(Configuration) 94 | 95 | 96 | 97 | 98 | Level3 99 | 100 | 101 | MaxSpeed 102 | true 103 | true 104 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS 105 | ../zpack 106 | MultiThreadedDLL 107 | 108 | 109 | Console 110 | true 111 | true 112 | true 113 | ../zpack/$(Configuration) 114 | zpack.lib;pthreadVCE2.lib;%(AdditionalDependencies) 115 | 116 | 117 | 118 | 119 | Level3 120 | 121 | 122 | MaxSpeed 123 | true 124 | true 125 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS 126 | ../zpack 127 | MultiThreaded 128 | 129 | 130 | Console 131 | true 132 | true 133 | true 134 | ../zpack/$(Configuration) 135 | zpack.lib;pthreadVCE2.lib;%(AdditionalDependencies) 136 | 137 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /zpack/zpack_vs2010.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release_editor 10 | Win32 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | {287EEAD4-7FEF-4444-A683-0A088A33D655} 46 | Win32Proj 47 | p 48 | zpack 49 | 50 | 51 | 52 | StaticLibrary 53 | true 54 | MultiByte 55 | false 56 | 57 | 58 | StaticLibrary 59 | false 60 | true 61 | MultiByte 62 | 63 | 64 | StaticLibrary 65 | false 66 | true 67 | MultiByte 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | $(Configuration)\ 84 | $(ProjectName)D 85 | 86 | 87 | $(Configuration)\ 88 | $(ProjectName) 89 | 90 | 91 | $(Configuration)\ 92 | $(ProjectName) 93 | 94 | 95 | 96 | 97 | 98 | Level3 99 | Disabled 100 | WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_ZP_WIN32_THREAD_SAFE;%(PreprocessorDefinitions) 101 | MultiThreadedDebugDLL 102 | zlib;pthread;%(AdditionalIncludeDirectories) 103 | 104 | 105 | Windows 106 | true 107 | 108 | 109 | 110 | 111 | Level3 112 | 113 | 114 | MaxSpeed 115 | true 116 | true 117 | WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_ZP_WIN32_THREAD_SAFE;%(PreprocessorDefinitions) 118 | MultiThreadedDLL 119 | zlib;pthread;%(AdditionalIncludeDirectories) 120 | 121 | 122 | Windows 123 | true 124 | true 125 | true 126 | 127 | 128 | 129 | 130 | Level3 131 | 132 | 133 | MaxSpeed 134 | true 135 | true 136 | WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_ZP_WIN32_THREAD_SAFE;%(PreprocessorDefinitions) 137 | MultiThreaded 138 | zlib;pthread;%(AdditionalIncludeDirectories) 139 | 140 | 141 | Windows 142 | true 143 | true 144 | true 145 | 146 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /zpack/zpack_vs2012.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release_editor 10 | Win32 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | {287EEAD4-7FEF-4444-A683-0A088A33D655} 46 | Win32Proj 47 | p 48 | zpack 49 | 50 | 51 | 52 | StaticLibrary 53 | true 54 | Unicode 55 | false 56 | v110 57 | 58 | 59 | StaticLibrary 60 | false 61 | true 62 | Unicode 63 | v110 64 | 65 | 66 | StaticLibrary 67 | false 68 | true 69 | Unicode 70 | v110 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | $(Configuration)\ 87 | $(ProjectName)D 88 | 89 | 90 | $(Configuration)\ 91 | $(ProjectName) 92 | 93 | 94 | $(Configuration)\ 95 | $(ProjectName) 96 | 97 | 98 | 99 | 100 | 101 | Level3 102 | Disabled 103 | WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_ZP_WIN32_THREAD_SAFE;%(PreprocessorDefinitions) 104 | MultiThreadedDebugDLL 105 | zlib;pthread;%(AdditionalIncludeDirectories) 106 | 107 | 108 | Windows 109 | true 110 | 111 | 112 | 113 | 114 | Level3 115 | 116 | 117 | MaxSpeed 118 | true 119 | true 120 | WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_ZP_WIN32_THREAD_SAFE;%(PreprocessorDefinitions) 121 | MultiThreadedDLL 122 | zlib;pthread;%(AdditionalIncludeDirectories) 123 | 124 | 125 | Windows 126 | true 127 | true 128 | true 129 | 130 | 131 | 132 | 133 | Level3 134 | 135 | 136 | MaxSpeed 137 | true 138 | true 139 | WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_ZP_WIN32_THREAD_SAFE;%(PreprocessorDefinitions) 140 | MultiThreaded 141 | zlib;pthread;%(AdditionalIncludeDirectories) 142 | 143 | 144 | Windows 145 | true 146 | true 147 | true 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /zpack/zlib/zutil.h: -------------------------------------------------------------------------------- 1 | /* zutil.h -- internal interface and configuration of the compression library 2 | * Copyright (C) 1995-2005 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* @(#) $Id$ */ 12 | 13 | #ifndef ZUTIL_H 14 | #define ZUTIL_H 15 | 16 | #define ZLIB_INTERNAL 17 | #include "zlib.h" 18 | 19 | #ifdef STDC 20 | # ifndef _WIN32_WCE 21 | # include 22 | # endif 23 | # include 24 | # include 25 | #endif 26 | #ifdef NO_ERRNO_H 27 | # ifdef _WIN32_WCE 28 | /* The Microsoft C Run-Time Library for Windows CE doesn't have 29 | * errno. We define it as a global variable to simplify porting. 30 | * Its value is always 0 and should not be used. We rename it to 31 | * avoid conflict with other libraries that use the same workaround. 32 | */ 33 | # define errno z_errno 34 | # endif 35 | extern int errno; 36 | #else 37 | # ifndef _WIN32_WCE 38 | # include 39 | # endif 40 | #endif 41 | 42 | #ifndef local 43 | # define local static 44 | #endif 45 | /* compile with -Dlocal if your debugger can't find static symbols */ 46 | 47 | typedef unsigned char uch; 48 | typedef uch FAR uchf; 49 | typedef unsigned short ush; 50 | typedef ush FAR ushf; 51 | typedef unsigned long ulg; 52 | 53 | extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ 54 | /* (size given to avoid silly warnings with Visual C++) */ 55 | 56 | #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] 57 | 58 | #define ERR_RETURN(strm,err) \ 59 | return (strm->msg = (char*)ERR_MSG(err), (err)) 60 | /* To be used only when the state is known to be valid */ 61 | 62 | /* common constants */ 63 | 64 | #ifndef DEF_WBITS 65 | # define DEF_WBITS MAX_WBITS 66 | #endif 67 | /* default windowBits for decompression. MAX_WBITS is for compression only */ 68 | 69 | #if MAX_MEM_LEVEL >= 9 70 | # define DEF_MEM_LEVEL 9 71 | #else 72 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL 73 | #endif 74 | /* default memLevel */ 75 | 76 | #define STORED_BLOCK 0 77 | #define STATIC_TREES 1 78 | #define DYN_TREES 2 79 | /* The three kinds of block type */ 80 | 81 | #define MIN_MATCH 3 82 | #define MAX_MATCH 258 83 | /* The minimum and maximum match lengths */ 84 | 85 | #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ 86 | 87 | /* target dependencies */ 88 | 89 | #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) 90 | # define OS_CODE 0x00 91 | # if defined(__TURBOC__) || defined(__BORLANDC__) 92 | # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) 93 | /* Allow compilation with ANSI keywords only enabled */ 94 | void _Cdecl farfree( void *block ); 95 | void *_Cdecl farmalloc( unsigned long nbytes ); 96 | # else 97 | # include 98 | # endif 99 | # else /* MSC or DJGPP */ 100 | # include 101 | # endif 102 | #endif 103 | 104 | #ifdef AMIGA 105 | # define OS_CODE 0x01 106 | #endif 107 | 108 | #if defined(VAXC) || defined(VMS) 109 | # define OS_CODE 0x02 110 | # define F_OPEN(name, mode) \ 111 | fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") 112 | #endif 113 | 114 | #if defined(ATARI) || defined(atarist) 115 | # define OS_CODE 0x05 116 | #endif 117 | 118 | #ifdef OS2 119 | # define OS_CODE 0x06 120 | # ifdef M_I86 121 | #include 122 | # endif 123 | #endif 124 | 125 | #if defined(MACOS) || defined(TARGET_OS_MAC) 126 | # define OS_CODE 0x07 127 | # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os 128 | # include /* for fdopen */ 129 | # else 130 | # ifndef fdopen 131 | # define fdopen(fd,mode) NULL /* No fdopen() */ 132 | # endif 133 | # endif 134 | #endif 135 | 136 | #ifdef TOPS20 137 | # define OS_CODE 0x0a 138 | #endif 139 | 140 | #ifdef WIN32 141 | # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ 142 | # define OS_CODE 0x0b 143 | # endif 144 | #endif 145 | 146 | #ifdef __50SERIES /* Prime/PRIMOS */ 147 | # define OS_CODE 0x0f 148 | #endif 149 | 150 | #if defined(_BEOS_) || defined(RISCOS) 151 | # define fdopen(fd,mode) NULL /* No fdopen() */ 152 | #endif 153 | 154 | #if (defined(_MSC_VER) && (_MSC_VER > 600)) 155 | # if defined(_WIN32_WCE) 156 | # define fdopen(fd,mode) NULL /* No fdopen() */ 157 | # ifndef _PTRDIFF_T_DEFINED 158 | typedef int ptrdiff_t; 159 | # define _PTRDIFF_T_DEFINED 160 | # endif 161 | # else 162 | # define fdopen(fd,type) _fdopen(fd,type) 163 | # endif 164 | #endif 165 | 166 | /* common defaults */ 167 | 168 | #ifndef OS_CODE 169 | # define OS_CODE 0x03 /* assume Unix */ 170 | #endif 171 | 172 | #ifndef F_OPEN 173 | # define F_OPEN(name, mode) fopen((name), (mode)) 174 | #endif 175 | 176 | /* functions */ 177 | 178 | #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) 179 | # ifndef HAVE_VSNPRINTF 180 | # define HAVE_VSNPRINTF 181 | # endif 182 | #endif 183 | #if defined(__CYGWIN__) 184 | # ifndef HAVE_VSNPRINTF 185 | # define HAVE_VSNPRINTF 186 | # endif 187 | #endif 188 | #ifndef HAVE_VSNPRINTF 189 | # ifdef MSDOS 190 | /* vsnprintf may exist on some MS-DOS compilers (DJGPP?), 191 | but for now we just assume it doesn't. */ 192 | # define NO_vsnprintf 193 | # endif 194 | # ifdef __TURBOC__ 195 | # define NO_vsnprintf 196 | # endif 197 | # ifdef WIN32 198 | /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ 199 | # if !defined(vsnprintf) && !defined(NO_vsnprintf) 200 | # define vsnprintf _vsnprintf 201 | # endif 202 | # endif 203 | # ifdef __SASC 204 | # define NO_vsnprintf 205 | # endif 206 | #endif 207 | #ifdef VMS 208 | # define NO_vsnprintf 209 | #endif 210 | 211 | #if defined(pyr) 212 | # define NO_MEMCPY 213 | #endif 214 | #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) 215 | /* Use our own functions for small and medium model with MSC <= 5.0. 216 | * You may have to use the same strategy for Borland C (untested). 217 | * The __SC__ check is for Symantec. 218 | */ 219 | # define NO_MEMCPY 220 | #endif 221 | #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) 222 | # define HAVE_MEMCPY 223 | #endif 224 | #ifdef HAVE_MEMCPY 225 | # ifdef SMALL_MEDIUM /* MSDOS small or medium model */ 226 | # define zmemcpy _fmemcpy 227 | # define zmemcmp _fmemcmp 228 | # define zmemzero(dest, len) _fmemset(dest, 0, len) 229 | # else 230 | # define zmemcpy memcpy 231 | # define zmemcmp memcmp 232 | # define zmemzero(dest, len) memset(dest, 0, len) 233 | # endif 234 | #else 235 | extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); 236 | extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); 237 | extern void zmemzero OF((Bytef* dest, uInt len)); 238 | #endif 239 | 240 | /* Diagnostic functions */ 241 | #ifdef DEBUG 242 | # include 243 | extern int z_verbose; 244 | extern void z_error OF((char *m)); 245 | # define Assert(cond,msg) {if(!(cond)) z_error(msg);} 246 | # define Trace(x) {if (z_verbose>=0) fprintf x ;} 247 | # define Tracev(x) {if (z_verbose>0) fprintf x ;} 248 | # define Tracevv(x) {if (z_verbose>1) fprintf x ;} 249 | # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} 250 | # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} 251 | #else 252 | # define Assert(cond,msg) 253 | # define Trace(x) 254 | # define Tracev(x) 255 | # define Tracevv(x) 256 | # define Tracec(c,x) 257 | # define Tracecv(c,x) 258 | #endif 259 | 260 | 261 | voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); 262 | void zcfree OF((voidpf opaque, voidpf ptr)); 263 | 264 | #define ZALLOC(strm, items, size) \ 265 | (*((strm)->zalloc))((strm)->opaque, (items), (size)) 266 | #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) 267 | #define TRY_FREE(s, p) {if (p) ZFREE(s, p);} 268 | 269 | #endif /* ZUTIL_H */ 270 | -------------------------------------------------------------------------------- /zpack/zlib/zutil.c: -------------------------------------------------------------------------------- 1 | /* zutil.c -- target dependent utility functions for the compression library 2 | * Copyright (C) 1995-2005 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #include "zutil.h" 9 | 10 | #ifndef NO_DUMMY_DECL 11 | struct internal_state {int dummy;}; /* for buggy compilers */ 12 | #endif 13 | 14 | const char * const z_errmsg[10] = { 15 | "need dictionary", /* Z_NEED_DICT 2 */ 16 | "stream end", /* Z_STREAM_END 1 */ 17 | "", /* Z_OK 0 */ 18 | "file error", /* Z_ERRNO (-1) */ 19 | "stream error", /* Z_STREAM_ERROR (-2) */ 20 | "data error", /* Z_DATA_ERROR (-3) */ 21 | "insufficient memory", /* Z_MEM_ERROR (-4) */ 22 | "buffer error", /* Z_BUF_ERROR (-5) */ 23 | "incompatible version",/* Z_VERSION_ERROR (-6) */ 24 | ""}; 25 | 26 | 27 | const char * ZEXPORT zlibVersion() 28 | { 29 | return ZLIB_VERSION; 30 | } 31 | 32 | uLong ZEXPORT zlibCompileFlags() 33 | { 34 | uLong flags; 35 | 36 | flags = 0; 37 | switch (sizeof(uInt)) { 38 | case 2: break; 39 | case 4: flags += 1; break; 40 | case 8: flags += 2; break; 41 | default: flags += 3; 42 | } 43 | switch (sizeof(uLong)) { 44 | case 2: break; 45 | case 4: flags += 1 << 2; break; 46 | case 8: flags += 2 << 2; break; 47 | default: flags += 3 << 2; 48 | } 49 | switch (sizeof(voidpf)) { 50 | case 2: break; 51 | case 4: flags += 1 << 4; break; 52 | case 8: flags += 2 << 4; break; 53 | default: flags += 3 << 4; 54 | } 55 | switch (sizeof(z_off_t)) { 56 | case 2: break; 57 | case 4: flags += 1 << 6; break; 58 | case 8: flags += 2 << 6; break; 59 | default: flags += 3 << 6; 60 | } 61 | #ifdef DEBUG 62 | flags += 1 << 8; 63 | #endif 64 | #if defined(ASMV) || defined(ASMINF) 65 | flags += 1 << 9; 66 | #endif 67 | #ifdef ZLIB_WINAPI 68 | flags += 1 << 10; 69 | #endif 70 | #ifdef BUILDFIXED 71 | flags += 1 << 12; 72 | #endif 73 | #ifdef DYNAMIC_CRC_TABLE 74 | flags += 1 << 13; 75 | #endif 76 | #ifdef NO_GZCOMPRESS 77 | flags += 1L << 16; 78 | #endif 79 | #ifdef NO_GZIP 80 | flags += 1L << 17; 81 | #endif 82 | #ifdef PKZIP_BUG_WORKAROUND 83 | flags += 1L << 20; 84 | #endif 85 | #ifdef FASTEST 86 | flags += 1L << 21; 87 | #endif 88 | #ifdef STDC 89 | # ifdef NO_vsnprintf 90 | flags += 1L << 25; 91 | # ifdef HAS_vsprintf_void 92 | flags += 1L << 26; 93 | # endif 94 | # else 95 | # ifdef HAS_vsnprintf_void 96 | flags += 1L << 26; 97 | # endif 98 | # endif 99 | #else 100 | flags += 1L << 24; 101 | # ifdef NO_snprintf 102 | flags += 1L << 25; 103 | # ifdef HAS_sprintf_void 104 | flags += 1L << 26; 105 | # endif 106 | # else 107 | # ifdef HAS_snprintf_void 108 | flags += 1L << 26; 109 | # endif 110 | # endif 111 | #endif 112 | return flags; 113 | } 114 | 115 | #ifdef DEBUG 116 | 117 | # ifndef verbose 118 | # define verbose 0 119 | # endif 120 | int z_verbose = verbose; 121 | 122 | void z_error (m) 123 | char *m; 124 | { 125 | fprintf(stderr, "%s\n", m); 126 | exit(1); 127 | } 128 | #endif 129 | 130 | /* exported to allow conversion of error code to string for compress() and 131 | * uncompress() 132 | */ 133 | const char * ZEXPORT zError(err) 134 | int err; 135 | { 136 | return ERR_MSG(err); 137 | } 138 | 139 | #if defined(_WIN32_WCE) 140 | /* The Microsoft C Run-Time Library for Windows CE doesn't have 141 | * errno. We define it as a global variable to simplify porting. 142 | * Its value is always 0 and should not be used. 143 | */ 144 | int errno = 0; 145 | #endif 146 | 147 | #ifndef HAVE_MEMCPY 148 | 149 | void zmemcpy(dest, source, len) 150 | Bytef* dest; 151 | const Bytef* source; 152 | uInt len; 153 | { 154 | if (len == 0) return; 155 | do { 156 | *dest++ = *source++; /* ??? to be unrolled */ 157 | } while (--len != 0); 158 | } 159 | 160 | int zmemcmp(s1, s2, len) 161 | const Bytef* s1; 162 | const Bytef* s2; 163 | uInt len; 164 | { 165 | uInt j; 166 | 167 | for (j = 0; j < len; j++) { 168 | if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; 169 | } 170 | return 0; 171 | } 172 | 173 | void zmemzero(dest, len) 174 | Bytef* dest; 175 | uInt len; 176 | { 177 | if (len == 0) return; 178 | do { 179 | *dest++ = 0; /* ??? to be unrolled */ 180 | } while (--len != 0); 181 | } 182 | #endif 183 | 184 | 185 | #ifdef SYS16BIT 186 | 187 | #ifdef __TURBOC__ 188 | /* Turbo C in 16-bit mode */ 189 | 190 | # define MY_ZCALLOC 191 | 192 | /* Turbo C malloc() does not allow dynamic allocation of 64K bytes 193 | * and farmalloc(64K) returns a pointer with an offset of 8, so we 194 | * must fix the pointer. Warning: the pointer must be put back to its 195 | * original form in order to free it, use zcfree(). 196 | */ 197 | 198 | #define MAX_PTR 10 199 | /* 10*64K = 640K */ 200 | 201 | local int next_ptr = 0; 202 | 203 | typedef struct ptr_table_s { 204 | voidpf org_ptr; 205 | voidpf new_ptr; 206 | } ptr_table; 207 | 208 | local ptr_table table[MAX_PTR]; 209 | /* This table is used to remember the original form of pointers 210 | * to large buffers (64K). Such pointers are normalized with a zero offset. 211 | * Since MSDOS is not a preemptive multitasking OS, this table is not 212 | * protected from concurrent access. This hack doesn't work anyway on 213 | * a protected system like OS/2. Use Microsoft C instead. 214 | */ 215 | 216 | voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) 217 | { 218 | voidpf buf = opaque; /* just to make some compilers happy */ 219 | ulg bsize = (ulg)items*size; 220 | 221 | /* If we allocate less than 65520 bytes, we assume that farmalloc 222 | * will return a usable pointer which doesn't have to be normalized. 223 | */ 224 | if (bsize < 65520L) { 225 | buf = farmalloc(bsize); 226 | if (*(ush*)&buf != 0) return buf; 227 | } else { 228 | buf = farmalloc(bsize + 16L); 229 | } 230 | if (buf == NULL || next_ptr >= MAX_PTR) return NULL; 231 | table[next_ptr].org_ptr = buf; 232 | 233 | /* Normalize the pointer to seg:0 */ 234 | *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; 235 | *(ush*)&buf = 0; 236 | table[next_ptr++].new_ptr = buf; 237 | return buf; 238 | } 239 | 240 | void zcfree (voidpf opaque, voidpf ptr) 241 | { 242 | int n; 243 | if (*(ush*)&ptr != 0) { /* object < 64K */ 244 | farfree(ptr); 245 | return; 246 | } 247 | /* Find the original pointer */ 248 | for (n = 0; n < next_ptr; n++) { 249 | if (ptr != table[n].new_ptr) continue; 250 | 251 | farfree(table[n].org_ptr); 252 | while (++n < next_ptr) { 253 | table[n-1] = table[n]; 254 | } 255 | next_ptr--; 256 | return; 257 | } 258 | ptr = opaque; /* just to make some compilers happy */ 259 | Assert(0, "zcfree: ptr not found"); 260 | } 261 | 262 | #endif /* __TURBOC__ */ 263 | 264 | 265 | #ifdef M_I86 266 | /* Microsoft C in 16-bit mode */ 267 | 268 | # define MY_ZCALLOC 269 | 270 | #if (!defined(_MSC_VER) || (_MSC_VER <= 600)) 271 | # define _halloc halloc 272 | # define _hfree hfree 273 | #endif 274 | 275 | voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) 276 | { 277 | if (opaque) opaque = 0; /* to make compiler happy */ 278 | return _halloc((long)items, size); 279 | } 280 | 281 | void zcfree (voidpf opaque, voidpf ptr) 282 | { 283 | if (opaque) opaque = 0; /* to make compiler happy */ 284 | _hfree(ptr); 285 | } 286 | 287 | #endif /* M_I86 */ 288 | 289 | #endif /* SYS16BIT */ 290 | 291 | 292 | #ifndef MY_ZCALLOC /* Any system without a special alloc function */ 293 | 294 | #ifndef STDC 295 | extern voidp malloc OF((uInt size)); 296 | extern voidp calloc OF((uInt items, uInt size)); 297 | extern void free OF((voidpf ptr)); 298 | #endif 299 | 300 | voidpf zcalloc (opaque, items, size) 301 | voidpf opaque; 302 | unsigned items; 303 | unsigned size; 304 | { 305 | if (opaque) items += size - size; /* make compiler happy */ 306 | return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : 307 | (voidpf)calloc(items, size); 308 | } 309 | 310 | void zcfree (opaque, ptr) 311 | voidpf opaque; 312 | voidpf ptr; 313 | { 314 | free(ptr); 315 | if (opaque) return; /* make compiler happy */ 316 | } 317 | 318 | #endif /* MY_ZCALLOC */ 319 | -------------------------------------------------------------------------------- /zpEditor/LeftView.cpp: -------------------------------------------------------------------------------- 1 | 2 | // LeftView.cpp : implementation of the CLeftView class 3 | // 4 | 5 | #include "stdafx.h" 6 | #include "zpEditor.h" 7 | 8 | #include "zpEditorDoc.h" 9 | #include "LeftView.h" 10 | #include "ProgressDialog.h" 11 | #include "FolderDialog.h" 12 | 13 | #ifdef _DEBUG 14 | #define new DEBUG_NEW 15 | #endif 16 | 17 | 18 | // CLeftView 19 | 20 | IMPLEMENT_DYNCREATE(CLeftView, CTreeView) 21 | 22 | BEGIN_MESSAGE_MAP(CLeftView, CTreeView) 23 | ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelectChanged) 24 | ON_WM_KEYDOWN() 25 | ON_COMMAND(ID_EDIT_ADD, &CLeftView::OnEditAdd) 26 | ON_COMMAND(ID_EDIT_ADD_FOLDER, &CLeftView::OnEditAddFolder) 27 | ON_COMMAND(ID_EDIT_DELETE, &CLeftView::OnEditDelete) 28 | ON_COMMAND(ID_EDIT_EXTRACT, &CLeftView::OnEditExtract) 29 | END_MESSAGE_MAP() 30 | 31 | 32 | // CLeftView construction/destruction 33 | 34 | CLeftView::CLeftView() 35 | { 36 | // TODO: add construction code here 37 | } 38 | 39 | CLeftView::~CLeftView() 40 | { 41 | } 42 | 43 | BOOL CLeftView::PreCreateWindow(CREATESTRUCT& cs) 44 | { 45 | CBitmap bm; 46 | bm.LoadBitmap(IDB_BITMAP_FOLDER); 47 | m_imageList.Create(16, 16, ILC_COLOR24 | ILC_MASK, 0, 0); 48 | m_imageList.Add(&bm, RGB(255, 255, 255)); 49 | return CTreeView::PreCreateWindow(cs); 50 | } 51 | 52 | void CLeftView::OnInitialUpdate() 53 | { 54 | CTreeView::OnInitialUpdate(); 55 | 56 | CTreeCtrl& treeCtrl = GetTreeCtrl(); 57 | treeCtrl.ModifyStyle(0, TVS_HASBUTTONS | TVS_HASLINES | TVS_SHOWSELALWAYS); 58 | treeCtrl.SetImageList(&m_imageList, TVSIL_NORMAL); 59 | } 60 | 61 | void CLeftView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 62 | { 63 | CTreeCtrl& treeCtrl = GetTreeCtrl(); 64 | BOOL reset = (BOOL)lHint; 65 | if (reset) 66 | { 67 | treeCtrl.DeleteAllItems(); 68 | } 69 | 70 | const ZpExplorer& explorer = GetDocument()->GetZpExplorer(); 71 | const ZpNode* node = explorer.currentNode(); 72 | HTREEITEM currentItem = (HTREEITEM)node->userData; 73 | if (currentItem != NULL) 74 | { 75 | updateNode(currentItem); 76 | treeCtrl.SelectItem(currentItem); 77 | return; 78 | } 79 | 80 | const ZpNode* rootNode = explorer.rootNode(); 81 | if (!explorer.isOpen()) 82 | { 83 | return; 84 | } 85 | zp::String packName; 86 | const zp::String& packFilename = explorer.packageFilename(); 87 | size_t slashPos = packFilename.find_last_of(_T('\\')); 88 | if (slashPos == zp::String::npos) 89 | { 90 | packName = packFilename; 91 | } 92 | else 93 | { 94 | packName = packFilename.substr(slashPos + 1, packFilename.length() - slashPos - 1); 95 | } 96 | if (explorer.getPack()->readonly()) 97 | { 98 | packName += _T(" (read only)"); 99 | } 100 | HTREEITEM rootItem = treeCtrl.InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_STATE | TVIF_PARAM, 101 | packName.c_str(), 102 | 0, 103 | 1, 104 | TVIS_EXPANDED | INDEXTOSTATEIMAGEMASK(1), 105 | TVIS_EXPANDED | TVIS_STATEIMAGEMASK, 106 | (LPARAM)rootNode, 107 | TVI_ROOT, 108 | TVI_LAST); 109 | rootNode->userData = rootItem; 110 | 111 | updateNode(rootItem); 112 | 113 | treeCtrl.Select(rootItem, TVGN_CARET); 114 | } 115 | 116 | void CLeftView::updateNode(HTREEITEM ti) 117 | { 118 | CTreeCtrl& treeCtrl = GetTreeCtrl(); 119 | //delete old children 120 | if (treeCtrl.ItemHasChildren(ti)) 121 | { 122 | HTREEITEM childItem = treeCtrl.GetChildItem(ti); 123 | while (childItem != NULL) 124 | { 125 | HTREEITEM nextItem = treeCtrl.GetNextItem(childItem, TVGN_NEXT); 126 | treeCtrl.DeleteItem(childItem); 127 | childItem = nextItem; 128 | } 129 | } 130 | //add new children 131 | const ZpNode* node = (const ZpNode*)treeCtrl.GetItemData(ti); 132 | for (std::list::const_iterator iter = node->children.cbegin(); 133 | iter != node->children.cend(); 134 | ++iter) 135 | { 136 | const ZpNode& child = *iter; 137 | if (!child.isDirectory) 138 | { 139 | continue; 140 | } 141 | HTREEITEM childItem = treeCtrl.InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM, 142 | child.name.c_str(), 143 | 0, 144 | 1, 145 | TVIS_EXPANDED | INDEXTOSTATEIMAGEMASK(1), 146 | TVIS_EXPANDED | TVIS_STATEIMAGEMASK, 147 | (LPARAM)&child, 148 | ti, 149 | TVI_LAST); 150 | child.userData = childItem; 151 | updateNode(childItem); 152 | } 153 | } 154 | 155 | void CLeftView::OnSelectChanged(NMHDR *pNMHDR, LRESULT *pResult) 156 | { 157 | CTreeCtrl& treeCtrl = GetTreeCtrl(); 158 | HTREEITEM selectedItem = treeCtrl.GetSelectedItem(); 159 | if (selectedItem != NULL) 160 | { 161 | const ZpNode* selectedNode = (const ZpNode*)treeCtrl.GetItemData(selectedItem); 162 | ZpExplorer& explorer = GetDocument()->GetZpExplorer(); 163 | explorer.setCurrentNode(selectedNode); 164 | m_pDocument->UpdateAllViews(this); 165 | } 166 | } 167 | 168 | // CLeftView diagnostics 169 | 170 | #ifdef _DEBUG 171 | void CLeftView::AssertValid() const 172 | { 173 | CTreeView::AssertValid(); 174 | } 175 | 176 | void CLeftView::Dump(CDumpContext& dc) const 177 | { 178 | CTreeView::Dump(dc); 179 | } 180 | 181 | CzpEditorDoc* CLeftView::GetDocument() // non-debug version is inline 182 | { 183 | ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CzpEditorDoc))); 184 | return (CzpEditorDoc*)m_pDocument; 185 | } 186 | #endif //_DEBUG 187 | 188 | 189 | // CLeftView message handlers 190 | 191 | void CLeftView::OnEditAdd() 192 | { 193 | CFileDialog dlg(TRUE, NULL, NULL, OFN_ALLOWMULTISELECT); 194 | if (dlg.DoModal() != IDOK) 195 | { 196 | return; 197 | } 198 | zp::u64 totalFileSize = 0; 199 | std::vector> params; 200 | ZpExplorer& explorer = GetDocument()->GetZpExplorer(); 201 | POSITION pos = dlg.GetStartPosition(); 202 | while (pos) 203 | { 204 | CString filename = dlg.GetNextPathName(pos); 205 | totalFileSize += explorer.countDiskFileSize(filename.GetString()); 206 | params.push_back(std::make_pair(filename.GetString(), _T(""))); 207 | } 208 | startOperation(ProgressDialog::OP_ADD, totalFileSize, ¶ms); 209 | m_pDocument->UpdateAllViews(NULL); 210 | } 211 | 212 | void CLeftView::OnEditAddFolder() 213 | { 214 | CFolderDialog folderDlg(NULL, _T("Select folder to add to package.")); 215 | if (folderDlg.DoModal() != IDOK) 216 | { 217 | return; 218 | } 219 | CString path = folderDlg.GetPathName(); 220 | ZpExplorer& explorer = GetDocument()->GetZpExplorer(); 221 | zp::u64 totalFileSize = explorer.countDiskFileSize(path.GetString()); 222 | 223 | std::vector> params; 224 | params.push_back(std::make_pair(path.GetString(), _T(""))); 225 | startOperation(ProgressDialog::OP_ADD, totalFileSize, ¶ms); 226 | m_pDocument->UpdateAllViews(NULL); 227 | } 228 | 229 | void CLeftView::OnEditDelete() 230 | { 231 | ZpExplorer& explorer = GetDocument()->GetZpExplorer(); 232 | explorer.setCallback(NULL, NULL); 233 | if (explorer.currentNode() == explorer.rootNode()) 234 | { 235 | ::MessageBox(NULL, _T("This folder can not be deleted."), _T("Information"), MB_OK | MB_ICONINFORMATION); 236 | return; 237 | } 238 | zp::String warning = _T("Do you want to delete "); 239 | warning += _T("\""); 240 | warning += explorer.currentNode()->name; 241 | warning += _T("\"?"); 242 | if (::MessageBox(NULL, warning.c_str(), _T("Question"), MB_YESNO | MB_ICONQUESTION) != IDYES) 243 | { 244 | return; 245 | } 246 | explorer.remove(_T(".")); 247 | m_pDocument->UpdateAllViews(NULL); 248 | } 249 | 250 | void CLeftView::OnEditExtract() 251 | { 252 | CFolderDialog dlg(NULL, _T("Select dest folder to extract.")); 253 | if (dlg.DoModal() != IDOK) 254 | { 255 | return; 256 | } 257 | zp::String destPath = dlg.GetPathName().GetString(); 258 | 259 | ZpExplorer& explorer = GetDocument()->GetZpExplorer(); 260 | 261 | zp::u64 totalFileSize = explorer.countNodeFileSize(explorer.currentNode()); 262 | std::vector> params; 263 | params.push_back(std::make_pair(_T("."), destPath)); 264 | startOperation(ProgressDialog::OP_EXTRACT, totalFileSize, ¶ms); 265 | } 266 | 267 | void CLeftView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 268 | { 269 | if (nChar == VK_DELETE) 270 | { 271 | OnEditDelete(); 272 | } 273 | CTreeView::OnKeyDown(nChar, nRepCnt, nFlags); 274 | } 275 | 276 | void CLeftView::startOperation(ProgressDialog::Operation op, zp::u64 totalFileSize, 277 | const std::vector>* params) 278 | { 279 | ProgressDialog progressDlg; 280 | progressDlg.m_explorer = &(GetDocument()->GetZpExplorer()); 281 | progressDlg.m_running = true; 282 | progressDlg.m_params = params; 283 | progressDlg.m_operation = op; 284 | progressDlg.m_totalFileSize = totalFileSize; 285 | progressDlg.DoModal(); 286 | } 287 | 288 | -------------------------------------------------------------------------------- /zpack/zlib/trees.h: -------------------------------------------------------------------------------- 1 | /* header created automatically with -DGEN_TREES_H */ 2 | 3 | local const ct_data static_ltree[L_CODES+2] = { 4 | {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}}, 5 | {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}}, 6 | {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}}, 7 | {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}}, 8 | {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}}, 9 | {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}}, 10 | {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}}, 11 | {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}}, 12 | {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}}, 13 | {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}}, 14 | {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}}, 15 | {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}}, 16 | {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}}, 17 | {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}}, 18 | {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}}, 19 | {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}}, 20 | {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}}, 21 | {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}}, 22 | {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}}, 23 | {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}}, 24 | {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}}, 25 | {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}}, 26 | {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}}, 27 | {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}}, 28 | {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}}, 29 | {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}}, 30 | {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}}, 31 | {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}}, 32 | {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}}, 33 | {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}}, 34 | {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}}, 35 | {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}}, 36 | {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}}, 37 | {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}}, 38 | {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}}, 39 | {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}}, 40 | {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}}, 41 | {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}}, 42 | {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}}, 43 | {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}}, 44 | {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}}, 45 | {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}}, 46 | {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}}, 47 | {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}}, 48 | {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}}, 49 | {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}}, 50 | {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}}, 51 | {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}}, 52 | {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}}, 53 | {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}}, 54 | {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}}, 55 | {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}}, 56 | {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}}, 57 | {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}}, 58 | {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}}, 59 | {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}}, 60 | {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}}, 61 | {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}} 62 | }; 63 | 64 | local const ct_data static_dtree[D_CODES] = { 65 | {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}}, 66 | {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}}, 67 | {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}}, 68 | {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}}, 69 | {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}}, 70 | {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}} 71 | }; 72 | 73 | const uch _dist_code[DIST_CODE_LEN] = { 74 | 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 75 | 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 76 | 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 77 | 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 78 | 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 79 | 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 80 | 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 81 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 82 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 83 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 84 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 85 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 86 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17, 87 | 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 88 | 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 89 | 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 90 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 91 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 92 | 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 93 | 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 94 | 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 95 | 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 96 | 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 97 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 98 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 99 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 100 | }; 101 | 102 | const uch _length_code[MAX_MATCH-MIN_MATCH+1]= { 103 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, 104 | 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 105 | 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 106 | 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 107 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 108 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 109 | 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 110 | 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 111 | 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 112 | 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 113 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 114 | 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 115 | 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28 116 | }; 117 | 118 | local const int base_length[LENGTH_CODES] = { 119 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 120 | 64, 80, 96, 112, 128, 160, 192, 224, 0 121 | }; 122 | 123 | local const int base_dist[D_CODES] = { 124 | 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 125 | 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 126 | 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576 127 | }; 128 | 129 | -------------------------------------------------------------------------------- /zpack/zpCompressedFile.cpp: -------------------------------------------------------------------------------- 1 | #include "zpCompressedFile.h" 2 | #include "zpPackage.h" 3 | #include 4 | #include "zlib.h" 5 | //#include "PerfUtil.h" 6 | 7 | namespace zp 8 | { 9 | 10 | //////////////////////////////////////////////////////////////////////////////////////////////////// 11 | CompressedFile::CompressedFile(const Package* package, u64 offset, u32 compressedSize, u32 originSize, 12 | u32 chunkSize, u32 flag, u64 nameHash) 13 | : m_package(package) 14 | , m_offset(offset) 15 | , m_chunkSize(chunkSize) 16 | , m_flag(flag) 17 | , m_compressedSize(compressedSize) 18 | , m_originSize(originSize) 19 | , m_nameHash(nameHash) 20 | , m_readPos(0) 21 | , m_chunkPos(NULL) 22 | , m_fileData(NULL) 23 | , m_chunkData(NULL) 24 | { 25 | assert(package != NULL); 26 | assert(package->m_stream != NULL); 27 | 28 | if (compressedSize <= 0) 29 | { 30 | m_originSize = 0; 31 | } 32 | assert(m_chunkSize != 0); 33 | m_chunkCount = (m_originSize + m_chunkSize - 1) / m_chunkSize; 34 | //no chunk size array for files have only 1 chunk 35 | if (m_chunkCount <= 1) 36 | { 37 | return; 38 | } 39 | 40 | u32 availableSize = m_package->getFileAvailableSize(nameHash); 41 | if (availableSize < m_chunkCount * sizeof(u32)) 42 | { 43 | m_flag |= FILE_DELETE; 44 | return; 45 | } 46 | //array of pointer to chunk data buffer 47 | m_chunkData = new u8*[m_chunkCount]; 48 | memset(m_chunkData, 0, m_chunkCount * sizeof(u8*)); 49 | 50 | //raw data position of each chunk 51 | m_chunkPos = new u32[m_chunkCount]; 52 | seekInPackage(0); 53 | fread((char*)m_chunkPos, m_chunkCount * sizeof(u32), 1, m_package->m_stream); 54 | if (!checkChunkPos()) 55 | { 56 | //let package delete me 57 | m_flag |= FILE_DELETE; 58 | } 59 | } 60 | 61 | //////////////////////////////////////////////////////////////////////////////////////////////////// 62 | CompressedFile::~CompressedFile() 63 | { 64 | if (m_chunkPos != NULL) 65 | { 66 | delete[] m_chunkPos; 67 | m_chunkPos = NULL; 68 | } 69 | if (m_chunkData != NULL) 70 | { 71 | for (u32 i = 0; i < m_chunkCount; ++i) 72 | { 73 | if (m_chunkData[i] != NULL) 74 | { 75 | delete[] m_chunkData[i]; 76 | } 77 | } 78 | delete[] m_chunkData; 79 | m_chunkData = NULL; 80 | } 81 | if (m_fileData != NULL) 82 | { 83 | delete[] m_fileData; 84 | m_fileData = NULL; 85 | } 86 | if (m_package->m_lastSeekFile == this) 87 | { 88 | m_package->m_lastSeekFile = NULL; 89 | } 90 | } 91 | 92 | //////////////////////////////////////////////////////////////////////////////////////////////////// 93 | u32 CompressedFile::size() const 94 | { 95 | return m_originSize; 96 | } 97 | 98 | //////////////////////////////////////////////////////////////////////////////////////////////////// 99 | u32 CompressedFile::availableSize() const 100 | { 101 | PACKAGE_LOCK; 102 | 103 | u32 rawAvailableSize = m_package->getFileAvailableSize(m_nameHash); 104 | if (rawAvailableSize == m_compressedSize) 105 | { 106 | return m_originSize; 107 | } 108 | //not finished, convert to origin size 109 | if (m_chunkCount <= 1) 110 | { 111 | return 0; 112 | } 113 | if (rawAvailableSize < m_chunkCount * sizeof(u32)) 114 | { 115 | return 0; 116 | } 117 | u32 available = 0; 118 | for (u32 i = 1; i < m_chunkCount; ++i) 119 | { 120 | if (rawAvailableSize > m_chunkPos[i]) 121 | { 122 | available += m_chunkSize; 123 | } 124 | } 125 | return available; 126 | } 127 | 128 | //////////////////////////////////////////////////////////////////////////////////////////////////// 129 | u32 CompressedFile::flag() const 130 | { 131 | return m_flag; 132 | } 133 | 134 | //////////////////////////////////////////////////////////////////////////////////////////////////// 135 | void CompressedFile::seek(u32 pos) 136 | { 137 | if (pos > m_originSize) 138 | { 139 | m_readPos = m_originSize; 140 | } 141 | else 142 | { 143 | m_readPos = pos; 144 | } 145 | } 146 | 147 | //////////////////////////////////////////////////////////////////////////////////////////////////// 148 | u32 CompressedFile::tell() const 149 | { 150 | return m_readPos; 151 | } 152 | 153 | //////////////////////////////////////////////////////////////////////////////////////////////////// 154 | u32 CompressedFile::read(u8* buffer, u32 size) 155 | { 156 | PACKAGE_LOCK; 157 | 158 | //BEGIN_PERF("read") 159 | 160 | if (m_readPos + size > m_originSize) 161 | { 162 | size = m_originSize - m_readPos; 163 | } 164 | if (size == 0) 165 | { 166 | return 0; 167 | } 168 | if (m_chunkCount == 1) 169 | { 170 | size = oneChunkRead(buffer, size); 171 | } 172 | else 173 | { 174 | //let's do something real! 175 | u32 startChunk = m_readPos / m_chunkSize; 176 | u32 endChunk = (m_readPos + size + m_chunkSize - 1) / m_chunkSize; 177 | u32 dstOffset = 0; 178 | for (u32 chunkIndex = startChunk; chunkIndex < endChunk; ++chunkIndex) 179 | { 180 | u32 readOffset = 0; 181 | u32 readSize = m_chunkSize; 182 | if (chunkIndex == startChunk) 183 | { 184 | readOffset = m_readPos % m_chunkSize; 185 | } 186 | if (chunkIndex == endChunk - 1) 187 | { 188 | //last chunk 189 | readSize = (m_readPos + size) - chunkIndex * m_chunkSize; 190 | } 191 | if (!readChunk(chunkIndex, readOffset, readSize, buffer + dstOffset)) 192 | { 193 | return 0; 194 | } 195 | dstOffset += readSize; 196 | } 197 | } 198 | m_readPos += size; 199 | 200 | //END_PERF 201 | 202 | return size; 203 | } 204 | 205 | //////////////////////////////////////////////////////////////////////////////////////////////////// 206 | bool CompressedFile::checkChunkPos() const 207 | { 208 | assert(m_chunkCount > 1); 209 | 210 | if (m_chunkPos[0] != sizeof(m_chunkPos[0]) * m_chunkCount) 211 | { 212 | return false; 213 | } 214 | for (u32 i = 1; i < m_chunkCount; ++i) 215 | { 216 | if (m_chunkPos[i] <= m_chunkPos[i - 1]) 217 | { 218 | return false; 219 | } 220 | if (m_chunkPos[i] >= m_compressedSize) 221 | { 222 | return false; 223 | } 224 | } 225 | return true; 226 | } 227 | 228 | //////////////////////////////////////////////////////////////////////////////////////////////////// 229 | u32 CompressedFile::oneChunkRead(u8* buffer, u32 size) 230 | { 231 | assert(m_readPos + size <= m_originSize); 232 | assert(m_compressedSize != m_originSize); 233 | 234 | //cached 235 | if (m_fileData != NULL) 236 | { 237 | memcpy(buffer, m_fileData + m_readPos, size); 238 | return size; 239 | } 240 | 241 | seekInPackage(0); 242 | 243 | u8* dstBuffer = NULL; 244 | if (m_readPos == 0 && size == m_originSize) 245 | { 246 | //want entire file, no need to cache, just fill user buffer 247 | dstBuffer = buffer; 248 | } 249 | else 250 | { 251 | m_fileData = new u8[m_originSize]; 252 | dstBuffer = m_fileData; 253 | } 254 | 255 | u8* compressed = new u8[m_compressedSize]; 256 | fread((char*)compressed, m_compressedSize, 1, m_package->m_stream); 257 | 258 | u32 dstSize = m_originSize; //don't want m_originSize to be changed 259 | if (uncompress(dstBuffer, &dstSize, compressed, m_compressedSize) != Z_OK) 260 | { 261 | size = 0; 262 | } 263 | if (m_fileData != NULL && size > 0) 264 | { 265 | memcpy(buffer, m_fileData + m_readPos, size); 266 | } 267 | delete[] compressed; 268 | return size; 269 | } 270 | 271 | //////////////////////////////////////////////////////////////////////////////////////////////////// 272 | bool CompressedFile::readChunk(u32 chunkIndex, u32 offset, u32 readSize, u8* buffer) 273 | { 274 | assert(m_chunkData != NULL); 275 | 276 | if (m_chunkData[chunkIndex] != NULL) 277 | { 278 | //cached 279 | memcpy(buffer, m_chunkData[chunkIndex] + offset, readSize); 280 | return true; 281 | } 282 | 283 | assert(m_chunkPos != NULL); 284 | seekInPackage(m_chunkPos[chunkIndex]); 285 | 286 | u32 compressedChunkSize = 0; 287 | u32 originChunkSize = 0; 288 | if (chunkIndex + 1 < m_chunkCount) 289 | { 290 | compressedChunkSize = m_chunkPos[chunkIndex + 1] - m_chunkPos[chunkIndex]; 291 | originChunkSize = m_chunkSize; 292 | } 293 | else 294 | { 295 | //last chunk 296 | compressedChunkSize = m_compressedSize - m_chunkPos[m_chunkCount - 1]; 297 | originChunkSize = m_originSize % m_chunkSize; 298 | } 299 | 300 | u8* dstBuffer = NULL; 301 | if (offset == 0 && readSize == originChunkSize) 302 | { 303 | //want entire chunk, no need to cache, just fill user buffer 304 | dstBuffer = buffer; 305 | } 306 | else 307 | { 308 | m_chunkData[chunkIndex] = new u8[originChunkSize]; 309 | dstBuffer = m_chunkData[chunkIndex]; 310 | } 311 | 312 | if (compressedChunkSize == originChunkSize) 313 | { 314 | //this chunk was not compressed at all, read directly to the dstBuffer 315 | fread((char*)dstBuffer, originChunkSize, 1, m_package->m_stream); 316 | } 317 | else 318 | { 319 | u8* compressed = new u8[compressedChunkSize]; 320 | fread((char*)compressed, compressedChunkSize, 1, m_package->m_stream); 321 | 322 | int ret = uncompress(dstBuffer, &originChunkSize, compressed, compressedChunkSize); 323 | delete[] compressed; 324 | if (ret != Z_OK) 325 | { 326 | return false; 327 | } 328 | } 329 | if (m_chunkData[chunkIndex] != NULL) 330 | { 331 | memcpy(buffer, m_chunkData[chunkIndex] + offset, readSize); 332 | } 333 | return true; 334 | } 335 | 336 | //////////////////////////////////////////////////////////////////////////////////////////////////// 337 | void CompressedFile::seekInPackage(u32 offset) 338 | { 339 | fseek(m_package->m_stream, m_offset + offset, SEEK_SET); 340 | m_package->m_lastSeekFile = this; 341 | } 342 | 343 | } 344 | -------------------------------------------------------------------------------- /zpack/zlib/zconf.h: -------------------------------------------------------------------------------- 1 | /* zconf.h -- configuration of the zlib compression library 2 | * Copyright (C) 1995-2005 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #ifndef ZCONF_H 9 | #define ZCONF_H 10 | 11 | /* 12 | * If you *really* need a unique prefix for all types and library functions, 13 | * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. 14 | */ 15 | #ifdef Z_PREFIX 16 | # define deflateInit_ z_deflateInit_ 17 | # define deflate z_deflate 18 | # define deflateEnd z_deflateEnd 19 | # define inflateInit_ z_inflateInit_ 20 | # define inflate z_inflate 21 | # define inflateEnd z_inflateEnd 22 | # define deflateInit2_ z_deflateInit2_ 23 | # define deflateSetDictionary z_deflateSetDictionary 24 | # define deflateCopy z_deflateCopy 25 | # define deflateReset z_deflateReset 26 | # define deflateParams z_deflateParams 27 | # define deflateBound z_deflateBound 28 | # define deflatePrime z_deflatePrime 29 | # define inflateInit2_ z_inflateInit2_ 30 | # define inflateSetDictionary z_inflateSetDictionary 31 | # define inflateSync z_inflateSync 32 | # define inflateSyncPoint z_inflateSyncPoint 33 | # define inflateCopy z_inflateCopy 34 | # define inflateReset z_inflateReset 35 | # define inflateBack z_inflateBack 36 | # define inflateBackEnd z_inflateBackEnd 37 | # define compress z_compress 38 | # define compress2 z_compress2 39 | # define compressBound z_compressBound 40 | # define uncompress z_uncompress 41 | # define adler32 z_adler32 42 | # define crc32 z_crc32 43 | # define get_crc_table z_get_crc_table 44 | # define zError z_zError 45 | 46 | # define alloc_func z_alloc_func 47 | # define free_func z_free_func 48 | # define in_func z_in_func 49 | # define out_func z_out_func 50 | # define Byte z_Byte 51 | # define uInt z_uInt 52 | # define uLong z_uLong 53 | # define Bytef z_Bytef 54 | # define charf z_charf 55 | # define intf z_intf 56 | # define uIntf z_uIntf 57 | # define uLongf z_uLongf 58 | # define voidpf z_voidpf 59 | # define voidp z_voidp 60 | #endif 61 | 62 | #if defined(__MSDOS__) && !defined(MSDOS) 63 | # define MSDOS 64 | #endif 65 | #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) 66 | # define OS2 67 | #endif 68 | #if defined(_WINDOWS) && !defined(WINDOWS) 69 | # define WINDOWS 70 | #endif 71 | #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) 72 | # ifndef WIN32 73 | # define WIN32 74 | # endif 75 | #endif 76 | #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) 77 | # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) 78 | # ifndef SYS16BIT 79 | # define SYS16BIT 80 | # endif 81 | # endif 82 | #endif 83 | 84 | /* 85 | * Compile with -DMAXSEG_64K if the alloc function cannot allocate more 86 | * than 64k bytes at a time (needed on systems with 16-bit int). 87 | */ 88 | #ifdef SYS16BIT 89 | # define MAXSEG_64K 90 | #endif 91 | #ifdef MSDOS 92 | # define UNALIGNED_OK 93 | #endif 94 | 95 | #ifdef __STDC_VERSION__ 96 | # ifndef STDC 97 | # define STDC 98 | # endif 99 | # if __STDC_VERSION__ >= 199901L 100 | # ifndef STDC99 101 | # define STDC99 102 | # endif 103 | # endif 104 | #endif 105 | #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) 106 | # define STDC 107 | #endif 108 | #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) 109 | # define STDC 110 | #endif 111 | #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) 112 | # define STDC 113 | #endif 114 | #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) 115 | # define STDC 116 | #endif 117 | 118 | #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ 119 | # define STDC 120 | #endif 121 | 122 | #ifndef STDC 123 | # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ 124 | # define const /* note: need a more gentle solution here */ 125 | # endif 126 | #endif 127 | 128 | /* Some Mac compilers merge all .h files incorrectly: */ 129 | #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) 130 | # define NO_DUMMY_DECL 131 | #endif 132 | 133 | /* Maximum value for memLevel in deflateInit2 */ 134 | #ifndef MAX_MEM_LEVEL 135 | # ifdef MAXSEG_64K 136 | # define MAX_MEM_LEVEL 8 137 | # else 138 | # define MAX_MEM_LEVEL 9 139 | # endif 140 | #endif 141 | 142 | /* Maximum value for windowBits in deflateInit2 and inflateInit2. 143 | * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files 144 | * created by gzip. (Files created by minigzip can still be extracted by 145 | * gzip.) 146 | */ 147 | #ifndef MAX_WBITS 148 | # define MAX_WBITS 15 /* 32K LZ77 window */ 149 | #endif 150 | 151 | /* The memory requirements for deflate are (in bytes): 152 | (1 << (windowBits+2)) + (1 << (memLevel+9)) 153 | that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) 154 | plus a few kilobytes for small objects. For example, if you want to reduce 155 | the default memory requirements from 256K to 128K, compile with 156 | make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" 157 | Of course this will generally degrade compression (there's no free lunch). 158 | 159 | The memory requirements for inflate are (in bytes) 1 << windowBits 160 | that is, 32K for windowBits=15 (default value) plus a few kilobytes 161 | for small objects. 162 | */ 163 | 164 | /* Type declarations */ 165 | 166 | #ifndef OF /* function prototypes */ 167 | # ifdef STDC 168 | # define OF(args) args 169 | # else 170 | # define OF(args) () 171 | # endif 172 | #endif 173 | 174 | /* The following definitions for FAR are needed only for MSDOS mixed 175 | * model programming (small or medium model with some far allocations). 176 | * This was tested only with MSC; for other MSDOS compilers you may have 177 | * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, 178 | * just define FAR to be empty. 179 | */ 180 | #ifdef SYS16BIT 181 | # if defined(M_I86SM) || defined(M_I86MM) 182 | /* MSC small or medium model */ 183 | # define SMALL_MEDIUM 184 | # ifdef _MSC_VER 185 | # define FAR _far 186 | # else 187 | # define FAR far 188 | # endif 189 | # endif 190 | # if (defined(__SMALL__) || defined(__MEDIUM__)) 191 | /* Turbo C small or medium model */ 192 | # define SMALL_MEDIUM 193 | # ifdef __BORLANDC__ 194 | # define FAR _far 195 | # else 196 | # define FAR far 197 | # endif 198 | # endif 199 | #endif 200 | 201 | #if defined(WINDOWS) || defined(WIN32) 202 | /* If building or using zlib as a DLL, define ZLIB_DLL. 203 | * This is not mandatory, but it offers a little performance increase. 204 | */ 205 | # ifdef ZLIB_DLL 206 | # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) 207 | # ifdef ZLIB_INTERNAL 208 | # define ZEXTERN extern __declspec(dllexport) 209 | # else 210 | # define ZEXTERN extern __declspec(dllimport) 211 | # endif 212 | # endif 213 | # endif /* ZLIB_DLL */ 214 | /* If building or using zlib with the WINAPI/WINAPIV calling convention, 215 | * define ZLIB_WINAPI. 216 | * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. 217 | */ 218 | # ifdef ZLIB_WINAPI 219 | # ifdef FAR 220 | # undef FAR 221 | # endif 222 | # include 223 | /* No need for _export, use ZLIB.DEF instead. */ 224 | /* For complete Windows compatibility, use WINAPI, not __stdcall. */ 225 | # define ZEXPORT WINAPI 226 | # ifdef WIN32 227 | # define ZEXPORTVA WINAPIV 228 | # else 229 | # define ZEXPORTVA FAR CDECL 230 | # endif 231 | # endif 232 | #endif 233 | 234 | #if defined (__BEOS__) 235 | # ifdef ZLIB_DLL 236 | # ifdef ZLIB_INTERNAL 237 | # define ZEXPORT __declspec(dllexport) 238 | # define ZEXPORTVA __declspec(dllexport) 239 | # else 240 | # define ZEXPORT __declspec(dllimport) 241 | # define ZEXPORTVA __declspec(dllimport) 242 | # endif 243 | # endif 244 | #endif 245 | 246 | #ifndef ZEXTERN 247 | # define ZEXTERN extern 248 | #endif 249 | #ifndef ZEXPORT 250 | # define ZEXPORT 251 | #endif 252 | #ifndef ZEXPORTVA 253 | # define ZEXPORTVA 254 | #endif 255 | 256 | #ifndef FAR 257 | # define FAR 258 | #endif 259 | 260 | #if !defined(__MACTYPES__) 261 | typedef unsigned char Byte; /* 8 bits */ 262 | #endif 263 | typedef unsigned int uInt; /* 16 bits or more */ 264 | typedef unsigned long uLong; /* 32 bits or more */ 265 | 266 | #ifdef SMALL_MEDIUM 267 | /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ 268 | # define Bytef Byte FAR 269 | #else 270 | typedef Byte FAR Bytef; 271 | #endif 272 | typedef char FAR charf; 273 | typedef int FAR intf; 274 | typedef uInt FAR uIntf; 275 | typedef uLong FAR uLongf; 276 | 277 | #ifdef STDC 278 | typedef void const *voidpc; 279 | typedef void FAR *voidpf; 280 | typedef void *voidp; 281 | #else 282 | typedef Byte const *voidpc; 283 | typedef Byte FAR *voidpf; 284 | typedef Byte *voidp; 285 | #endif 286 | 287 | #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */ 288 | # include /* for off_t */ 289 | # include /* for SEEK_* and off_t */ 290 | # ifdef VMS 291 | # include /* for off_t */ 292 | # endif 293 | # define z_off_t off_t 294 | #endif 295 | #ifndef SEEK_SET 296 | # define SEEK_SET 0 /* Seek from beginning of file. */ 297 | # define SEEK_CUR 1 /* Seek from current position. */ 298 | # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ 299 | #endif 300 | #ifndef z_off_t 301 | # define z_off_t long 302 | #endif 303 | 304 | #if defined(__OS400__) 305 | # define NO_vsnprintf 306 | #endif 307 | 308 | #if defined(__MVS__) 309 | # define NO_vsnprintf 310 | # ifdef FAR 311 | # undef FAR 312 | # endif 313 | #endif 314 | 315 | /* MVS linker does not support external names larger than 8 bytes */ 316 | #if defined(__MVS__) 317 | # pragma map(deflateInit_,"DEIN") 318 | # pragma map(deflateInit2_,"DEIN2") 319 | # pragma map(deflateEnd,"DEEND") 320 | # pragma map(deflateBound,"DEBND") 321 | # pragma map(inflateInit_,"ININ") 322 | # pragma map(inflateInit2_,"ININ2") 323 | # pragma map(inflateEnd,"INEND") 324 | # pragma map(inflateSync,"INSY") 325 | # pragma map(inflateSetDictionary,"INSEDI") 326 | # pragma map(compressBound,"CMBND") 327 | # pragma map(inflate_table,"INTABL") 328 | # pragma map(inflate_fast,"INFA") 329 | # pragma map(inflate_copyright,"INCOPY") 330 | #endif 331 | 332 | #endif /* ZCONF_H */ 333 | --------------------------------------------------------------------------------