home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 2003 August
/
VPR0308.ISO
/
OLS
/
TAR32_1-20001226-140023
/
tar32_1-20001226-140023.lzh
/
tar32_1
/
Src
/
SRC
/
SUSIE.C
< prev
next >
Wrap
C/C++ Source or Header
|
2000-12-26
|
6KB
|
210 lines
/*
API's for Susie Plug-in Specification.
by Yoshioka Tsuneo(QWF00133@niftyserve.or.jp) 1998/05/02
*This File* can use as PDS(Public Domain Software).
*/
#include <windows.h>
#include "tar32.h"
#include <string.h>
#include <mbstring.h>
#include "version.h"
#include <winbase.h>
#include <time.h>
typedef struct
{
unsigned char method[8]; /*圧縮法の種類*/
unsigned long position; /*ファイル上での位置*/
unsigned long compsize; /*圧縮されたサイズ*/
unsigned long filesize; /*元のファイルサイズ*/
time_t timestamp; /*ファイルの更新日時*/
char path[200]; /*相対パス*/
char filename[200]; /*ファイルネーム*/
unsigned long crc; /*CRC*/
} fileInfo;
char *SpiVerString ="00AM";
char SpiAboutString[1000];
char *SpiAboutStringFmt ="Tar32.dll ver %d.%02d by Yoshioka Tsuneo";
char *SpiFileExtString[1] ={"*.TAR;*.TGZ;*.tar.gz;*.TAZ;*.tar.Z;*.tar.bz2;*.gz;*.z;*.bz2"};
char *SpiFileTypeString[1]={"*.TAR;*.TGZ;*.tar.gz;*.TAZ;*.tar.Z;*.tar.bz2;*.gz;*.z;*.bz2"};
int WINAPI GetPluginInfo(int infono,char *buf,int buflen)
{
char *bufstr;
int ret=0;
int ver;
ver = TarGetVersion();
sprintf(SpiAboutString,SpiAboutStringFmt,ver/100,ver%100);
switch(infono){
case 0: /* Plug-in API version */
bufstr = SpiVerString;
break;
case 1:
bufstr = SpiAboutString;
break;
case 2:
bufstr = SpiFileExtString[0];
break;
case 3:
bufstr = SpiFileTypeString[0];
break;
default:
return 0;
}
strcpy(buf,bufstr);
ret = strlen(bufstr);
return ret;
}
int WINAPI IsSupported(char *filename,long dw)
{
return TarCheckArchive(filename,0);
}
/* 画像用のダミー関数 */
int WINAPI GetPictureInfo(LPSTR buf,long len,unsigned int flag,struct PictureInfo *lpInfo)
{
return -1;
}
int WINAPI GetPicture(
LPSTR buf,long len,unsigned int flag,
HANDLE *pHBInfo,HANDLE *pHBm,
FARPROC lpPrgressCallback,long lData)
{
return -1;
}
int WINAPI GetPreview(
LPSTR buf,long len,unsigned int flag,
HANDLE *pHBInfo,HANDLE *pHBm,
FARPROC lpPrgressCallback,long lData)
{
return -1;
}
/************/
static void IndividualInfoToFileInfo(fileInfo *fileInfo_ptr,INDIVIDUALINFO *individual_info_ptr,time_t ti)
{
memcpy(fileInfo_ptr->method,individual_info_ptr->szMode,8); /*圧縮法の種類*/
fileInfo_ptr->position=0; /*ファイル上での位置*/
fileInfo_ptr->compsize=0; // individual_info_ptr->dwCompressedSize; /*圧縮されたサイズ*/
fileInfo_ptr->filesize=individual_info_ptr->dwOriginalSize; /*元のファイルサイズ*/
fileInfo_ptr->timestamp = ti; /*ファイルの更新日時*/
if(0){
strcpy(fileInfo_ptr->path,"PATH");
strcpy(fileInfo_ptr->filename,"FILENAME");
}else{
char *p;
char *srcfn=individual_info_ptr->szFileName;
if((p=_mbschr(srcfn,'\\'))>0){
strncpy(fileInfo_ptr->path,srcfn,p-srcfn-1);
(fileInfo_ptr->path)[p-srcfn] = '\0';
strcpy(fileInfo_ptr->filename,p+1);
}else{
strcpy(fileInfo_ptr->path,"");
strcpy(fileInfo_ptr->filename,srcfn);
}
}
fileInfo_ptr->crc=individual_info_ptr->dwCRC; /*CRC*/
}
static int GetArchiveInfoItr(char *buf,long len,unsigned int flag,HANDLE * lphInf,char *wildname)
{
HANDLE harc;
INDIVIDUALINFO individual_info;
int ret;
int fileInfo_count = 0;
fileInfo *fileInfo_array=NULL;
char *ptr;
if((flag & 0x0007)!=0){return -1;}
if((harc = TarOpenArchive(NULL,buf,0))==NULL){return -1;}
ret = TarFindFirst(harc,wildname,&individual_info);
while(ret==0){
fileInfo_array = realloc(fileInfo_array,sizeof(fileInfo)*(fileInfo_count+1));
if(fileInfo_array==0){
MessageBox(NULL,"realloc failed!","tar32.dll",0);
return -1;
}
IndividualInfoToFileInfo(fileInfo_array+fileInfo_count,&individual_info,TarGetWriteTime(harc));
fileInfo_count++;
ret=TarFindNext(harc,&individual_info);
}
TarCloseArchive(harc);
{
HANDLE h;
h = LocalAlloc(GMEM_ZEROINIT|GMEM_MOVEABLE,sizeof(fileInfo)*(fileInfo_count+1));
*lphInf=h;
}
ptr=LocalLock(*lphInf);
if(ptr==NULL){
int err;
err=GetLastError();
}
memcpy(ptr,fileInfo_array,sizeof(fileInfo)*fileInfo_count);
LocalUnlock(*lphInf);
return 0;
}
int WINAPI GetArchiveInfo(char *buf,long len,unsigned int flag,HANDLE * lphInf)
{
return GetArchiveInfoItr(buf,len,flag,lphInf,"");
}
int WINAPI GetFileInfo(char *buf,long len,char *filename,int flag,fileInfo *lpInfo)
{
HANDLE lphInf;
int ret;
char *ptr;
ret = GetArchiveInfoItr(buf,len,flag,&lphInf,filename);
ptr=GlobalLock(lphInf);
memcpy(lpInfo,ptr,sizeof(fileInfo));
GlobalUnlock(lphInf);
GlobalFree(lphInf);
return ret;
}
int WINAPI GetFile(char *src,long len,char *dest,unsigned int flag,FARPROC prgressCallback,long lData)
{
int ret;
char *fname=NULL;
if((flag & 0x0007)!=0){return -1;}
if(src[strlen(src)+1]){
fname = src+strlen(src)+1;
}
if((flag & 0x0700)==0){
char outbuf[1001];
int outbuf_len=1000;
char cmd[1000];
if(fname){
sprintf(cmd,"-xvf \"%s\" \"%s\"",src,fname);
}else{
sprintf(cmd,"-xvf \"%s\"",src);
}
ret=Tar(NULL,cmd,outbuf,outbuf_len);
}else if((flag & 0x0700)==0x0100){
char outbuf[60001];
int outbuf_len=60000;
char cmd[1000];
char *ptr;
HANDLE h;
//return -1;
if(fname){
sprintf(cmd,"-xpf \"%s\" \"%s\"",src,fname);
}else{
sprintf(cmd,"-xpf \"%s\"",src);
}
ret=Tar(NULL,cmd,outbuf,outbuf_len);
h = LocalAlloc(GMEM_MOVEABLE,60000);
ptr = LocalLock(h);
memcpy(ptr,outbuf,60000);
LocalUnlock(h);
*((HANDLE *)dest) = h;
}else{
return -1;
}
if(ret==0){return 0;}else{return -1;}
}