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 >
C/C++ Source or Header  |  2000-12-26  |  6KB  |  210 lines

  1. /*
  2.     API's for Susie Plug-in Specification.
  3.         by Yoshioka Tsuneo(QWF00133@niftyserve.or.jp) 1998/05/02
  4.         *This File* can use as PDS(Public Domain Software).
  5. */
  6. #include <windows.h>
  7. #include "tar32.h"
  8. #include <string.h>
  9. #include <mbstring.h>
  10. #include "version.h"
  11. #include <winbase.h>
  12. #include <time.h>
  13.  
  14. typedef struct
  15. {
  16.     unsigned char method[8];    /*圧縮法の種類*/
  17.     unsigned long position;     /*ファイル上での位置*/
  18.     unsigned long compsize;     /*圧縮されたサイズ*/
  19.     unsigned long filesize;     /*元のファイルサイズ*/
  20.     time_t timestamp;           /*ファイルの更新日時*/
  21.     char path[200];             /*相対パス*/
  22.     char filename[200];         /*ファイルネーム*/
  23.     unsigned long crc;          /*CRC*/
  24. } fileInfo;
  25. char *SpiVerString     ="00AM";
  26. char SpiAboutString[1000];
  27. char *SpiAboutStringFmt   ="Tar32.dll ver %d.%02d by Yoshioka Tsuneo";
  28. char *SpiFileExtString[1] ={"*.TAR;*.TGZ;*.tar.gz;*.TAZ;*.tar.Z;*.tar.bz2;*.gz;*.z;*.bz2"};
  29. char *SpiFileTypeString[1]={"*.TAR;*.TGZ;*.tar.gz;*.TAZ;*.tar.Z;*.tar.bz2;*.gz;*.z;*.bz2"};
  30.  
  31. int WINAPI GetPluginInfo(int infono,char *buf,int buflen)
  32. {
  33.     char *bufstr;
  34.     int ret=0;
  35.     int ver;
  36.  
  37.     ver = TarGetVersion();
  38.     sprintf(SpiAboutString,SpiAboutStringFmt,ver/100,ver%100);
  39.     switch(infono){
  40.     case 0:    /* Plug-in API version */
  41.         bufstr = SpiVerString;
  42.         break;
  43.     case 1:
  44.         bufstr = SpiAboutString;
  45.         break;
  46.     case 2:
  47.         bufstr = SpiFileExtString[0];
  48.         break;
  49.     case 3:
  50.         bufstr = SpiFileTypeString[0];
  51.         break;
  52.     default:
  53.         return 0;
  54.     }
  55.     strcpy(buf,bufstr);
  56.     ret = strlen(bufstr);
  57.     return ret;
  58. }
  59. int WINAPI IsSupported(char *filename,long dw)
  60. {
  61.     return TarCheckArchive(filename,0);
  62. }
  63. /* 画像用のダミー関数 */
  64. int WINAPI GetPictureInfo(LPSTR buf,long len,unsigned int flag,struct PictureInfo *lpInfo)
  65. {
  66.     return -1;
  67. }
  68. int WINAPI GetPicture(
  69.               LPSTR buf,long len,unsigned int flag,
  70.               HANDLE *pHBInfo,HANDLE *pHBm,
  71.               FARPROC lpPrgressCallback,long lData)
  72. {
  73.     return -1;
  74. }
  75. int WINAPI GetPreview(
  76.               LPSTR buf,long len,unsigned int flag,
  77.               HANDLE *pHBInfo,HANDLE *pHBm,
  78.               FARPROC lpPrgressCallback,long lData)
  79. {
  80.     return -1;
  81. }
  82. /************/
  83.  
  84. static void IndividualInfoToFileInfo(fileInfo *fileInfo_ptr,INDIVIDUALINFO *individual_info_ptr,time_t ti)
  85. {
  86.     memcpy(fileInfo_ptr->method,individual_info_ptr->szMode,8);    /*圧縮法の種類*/
  87.     fileInfo_ptr->position=0;     /*ファイル上での位置*/
  88.     fileInfo_ptr->compsize=0; // individual_info_ptr->dwCompressedSize;     /*圧縮されたサイズ*/
  89.     fileInfo_ptr->filesize=individual_info_ptr->dwOriginalSize;     /*元のファイルサイズ*/
  90.     fileInfo_ptr->timestamp = ti;           /*ファイルの更新日時*/
  91.     if(0){
  92.         strcpy(fileInfo_ptr->path,"PATH");
  93.         strcpy(fileInfo_ptr->filename,"FILENAME");
  94.     }else{
  95.         char *p;
  96.         char *srcfn=individual_info_ptr->szFileName;
  97.  
  98.         if((p=_mbschr(srcfn,'\\'))>0){
  99.             strncpy(fileInfo_ptr->path,srcfn,p-srcfn-1);
  100.             (fileInfo_ptr->path)[p-srcfn] = '\0';
  101.             strcpy(fileInfo_ptr->filename,p+1);
  102.         }else{
  103.             strcpy(fileInfo_ptr->path,"");
  104.             strcpy(fileInfo_ptr->filename,srcfn);
  105.         }
  106.     }
  107.  
  108.     fileInfo_ptr->crc=individual_info_ptr->dwCRC;          /*CRC*/
  109.  
  110. }
  111. static int GetArchiveInfoItr(char *buf,long len,unsigned int flag,HANDLE * lphInf,char *wildname)
  112. {
  113.     HANDLE harc;
  114.     INDIVIDUALINFO individual_info;
  115.     int ret;
  116.     int fileInfo_count = 0;
  117.     fileInfo *fileInfo_array=NULL;
  118.     char *ptr;
  119.  
  120.     if((flag & 0x0007)!=0){return -1;}
  121.     if((harc = TarOpenArchive(NULL,buf,0))==NULL){return -1;}
  122.     ret = TarFindFirst(harc,wildname,&individual_info);
  123.     while(ret==0){
  124.         fileInfo_array = realloc(fileInfo_array,sizeof(fileInfo)*(fileInfo_count+1));
  125.         if(fileInfo_array==0){
  126.             MessageBox(NULL,"realloc failed!","tar32.dll",0);
  127.             return -1;
  128.         }
  129.         IndividualInfoToFileInfo(fileInfo_array+fileInfo_count,&individual_info,TarGetWriteTime(harc));
  130.  
  131.         fileInfo_count++;
  132.         ret=TarFindNext(harc,&individual_info);
  133.     }
  134.     TarCloseArchive(harc);
  135.     {
  136.         HANDLE h;
  137.         h = LocalAlloc(GMEM_ZEROINIT|GMEM_MOVEABLE,sizeof(fileInfo)*(fileInfo_count+1));
  138.         *lphInf=h;
  139.     }
  140.     ptr=LocalLock(*lphInf);
  141.     if(ptr==NULL){
  142.         int err;
  143.         err=GetLastError();
  144.     }
  145.     memcpy(ptr,fileInfo_array,sizeof(fileInfo)*fileInfo_count);
  146.     LocalUnlock(*lphInf);
  147.     return 0;
  148. }
  149. int WINAPI GetArchiveInfo(char *buf,long len,unsigned int flag,HANDLE * lphInf)
  150. {
  151.     return GetArchiveInfoItr(buf,len,flag,lphInf,"");
  152. }
  153. int WINAPI GetFileInfo(char *buf,long len,char *filename,int flag,fileInfo *lpInfo)
  154. {
  155.     HANDLE lphInf;
  156.     int ret;
  157.     char *ptr;
  158.  
  159.     ret = GetArchiveInfoItr(buf,len,flag,&lphInf,filename);
  160.     ptr=GlobalLock(lphInf);
  161.     memcpy(lpInfo,ptr,sizeof(fileInfo));
  162.     GlobalUnlock(lphInf);
  163.     GlobalFree(lphInf);
  164.     return ret;
  165. }
  166. int WINAPI GetFile(char *src,long len,char *dest,unsigned int flag,FARPROC prgressCallback,long lData)
  167. {
  168.     int ret;
  169.     char *fname=NULL;
  170.  
  171.     if((flag & 0x0007)!=0){return -1;}
  172.  
  173.     if(src[strlen(src)+1]){
  174.         fname = src+strlen(src)+1;
  175.     }
  176.     if((flag & 0x0700)==0){
  177.         char outbuf[1001];
  178.         int outbuf_len=1000;
  179.         char cmd[1000];
  180.  
  181.         if(fname){
  182.             sprintf(cmd,"-xvf \"%s\" \"%s\"",src,fname);
  183.         }else{
  184.             sprintf(cmd,"-xvf \"%s\"",src);
  185.         }
  186.         ret=Tar(NULL,cmd,outbuf,outbuf_len);
  187.     }else if((flag & 0x0700)==0x0100){
  188.         char outbuf[60001];
  189.         int outbuf_len=60000;
  190.         char cmd[1000];
  191.         char *ptr;
  192.         HANDLE h;
  193.         //return -1;
  194.         if(fname){
  195.             sprintf(cmd,"-xpf \"%s\" \"%s\"",src,fname);
  196.         }else{
  197.             sprintf(cmd,"-xpf \"%s\"",src);
  198.         }
  199.         ret=Tar(NULL,cmd,outbuf,outbuf_len);
  200.         h = LocalAlloc(GMEM_MOVEABLE,60000);
  201.         ptr = LocalLock(h);
  202.         memcpy(ptr,outbuf,60000);
  203.         LocalUnlock(h);
  204.         *((HANDLE *)dest) = h;
  205.     }else{
  206.         return -1;
  207.     }
  208.     if(ret==0){return 0;}else{return -1;}
  209. }
  210.