// LTZ.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "LTZ.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // The one and only application object CWinApp theApp; using namespace std; #define F_ASCII 1 #define F_MAKE 2 #define F_EXTRACT 4 #define F_COMPRESS 8 #define F_EXPAND 16 DWORD ltz_flags,pfile_blks,cur_signature=0x78123456; char cur_dir[MAX_PATH],cur_pfile[MAX_PATH]; class tree_node { public: tree_node *next_sibling,*first_child,*parent; TCHAR name[MAX_PATH]; tree_node(tree_node *_parent); ~tree_node(); CString path(); CString full_name(); }; typedef tree_node *tree_node_ptr; tree_node::tree_node(tree_node *_parent) { parent=_parent; next_sibling=NULL; first_child=NULL; *name=0; //So path() works for root } tree_node::~tree_node() { delete first_child; delete next_sibling; } CString tree_node::path() { CString result; if (parent) { result=parent->path(); if (result.Right(1)==CString(_T("\\"))) result+=parent->name; else result+=CString(_T("\\"))+parent->name; } else result=cur_dir; return result; } CString tree_node::full_name() { CString result=path(); if (result.Right(1)!=CString(_T("\\"))) result+=_T("\\"); result+=name; return result; } void convert(CString nname,double in_size) { DWORD out_size,i; ArcCompressStruct *in_buf; BYTE *out_buf; FILE *io_file; char name[512]; strcpy(name,nname.GetBuffer(512)); nname.ReleaseBuffer(); in_buf=(ArcCompressStruct *)malloc(in_size); io_file=fopen(name,"rb"); fread(in_buf,1,in_size,io_file); out_size=in_buf->expanded_size; printf("%-45s %d-->%d\r\n",name,(DWORD) in_size,out_size); fclose(io_file); out_buf=ExpandBuf(in_buf); if (out_buf) { if (ltz_flags & F_ASCII) { for (i=0;ifirst_child); str=path; if (str.Right(1)==CString(_T("\\"))) str+=_T("*.*"); else str+=_T("\\*.*"); if ((file_search=FindFirstFile(str,&find_data)) !=INVALID_HANDLE_VALUE) { do { if (strcmp(find_data.cFileName,_T(".")) && strcmp(find_data.cFileName,_T("..")) ) { tempt=new tree_node(parent); strcpy(tempt->name,find_data.cFileName); *back_link=tempt; back_link=&(tempt->next_sibling); if (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { str=path; if (str.Right(1)!=CString(_T("\\"))) str+=_T("\\"); str+=find_data.cFileName; total+=AddFolder(str,tempt); } else { total+=find_data.nFileSizeLow+ ((double)0xFFFFFFFF+1)*find_data.nFileSizeHigh; if (find_data.cFileName[strlen(find_data.cFileName)-1]=='Z') { str2=path; if (str2.Right(1)!=CString(_T("\\"))) str2+=_T("\\"); str2+=find_data.cFileName; convert(str2,find_data.nFileSizeLow+ ((double)0xFFFFFFFF+1)*find_data.nFileSizeHigh); } } } } while (FindNextFile(file_search,&find_data)); FindClose(file_search); } return total; } void SetBlk(FILE *f,DWORD blk) { fseek(f,blk*512,SEEK_SET); } void SetCluster(FILE *f,DWORD cluster_lo,LTBootStruct *b) { SetBlk(f,(cluster_lo-1)*b->sectors_per_cluster+1+b->bitmap_sectors); } void ExtractFile(CString str,FILE *in_file,LTDirEntry *d,LTBootStruct *b) { FILE *out_file; BYTE *buf=(BYTE *)malloc(d->size_lo); SetCluster(in_file,d->cluster_lo,b); fread(buf,d->size_lo,1,in_file); out_file=fopen((const char *)str,"wb"); fwrite(buf,d->size_lo,1,out_file); fclose(out_file); free(buf); } void ExtractDir(CString str,FILE *in_file,DWORD lo,DWORD size,LTBootStruct *b) { LTDirEntry *d=(LTDirEntry *)malloc(size); DWORD i; CString str2; char sysbuf[MAX_PATH]; sprintf(sysbuf,"MD %s",(const char *)str); system(sysbuf); if (str.Right(1)!=CString(_T("\\"))) str+=_T("\\"); SetCluster(in_file,lo,b); fread(d,size,1,in_file); for (i=2;i