home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2003 May / VPR0305.ISO / OLS / TAR32223 / tar32223.lzh / tar32_2 / src / susie.cpp < prev    next >
C/C++ Source or Header  |  2003-01-17  |  6KB  |  223 lines

  1. /* Special Thanks for patch to Jy. (jyz@cds.ne.jp) (2000/07/10)  */
  2. /*
  3.   TAR32.DLL version.2.xx
  4.   Susie 32bit Plug-in Spec Rev4 Interface.
  5. */
  6.  
  7. #include "tar32api.h"
  8. #include "tar32dll.h"
  9. #include <time.h>
  10. #include <windows.h>
  11.  
  12. /*********************************************************
  13.      Susie Plug-In APIs 
  14. **********************************************************/
  15.  
  16. #pragma pack(push,1)
  17. typedef struct
  18. {
  19.     unsigned char method[8];    /*圧縮法の種類*/
  20.     unsigned long position;        /*ファイル上での位置*/
  21.     unsigned long compsize;        /*圧縮されたサイズ*/
  22.     unsigned long filesize;        /*元のファイルサイズ*/
  23.     time_t timestamp;        /*ファイルの更新日時*/
  24.     char path[200];            /*相対パス*/
  25.     char filename[200];        /*ファイルネーム*/
  26.     unsigned long crc;        /*CRC*/
  27. } fileInfo;
  28. #pragma pack(pop)
  29.  
  30. extern "C" int WINAPI _export GetPluginInfo(int infono, LPSTR buf,int buflen)
  31. {
  32.     int nRet=0;
  33.  
  34.     if(0==infono) {
  35.         memcpy(buf,"00AM",nRet=min(buflen,5));
  36.     } else if(1==infono) {
  37.         const char *pPluginName="Tar32.DLL by Yoshioka Tsuneo(QWF00133@nifty.ne.jp)";
  38.         memcpy(buf,pPluginName,nRet=min(buflen,strlen(pPluginName)+1));
  39.     } else {
  40.         const char *ppExtNames[]={"*.tar;*.tgz;*.tbz;*.gz;*.bz2;*.Z;"};
  41.         const char *ppFmtNames[]={"tar/gz/bz2/Z format"};
  42.         int nExtNum=sizeof(ppExtNames)/sizeof(ppExtNames[0]);
  43.         infono-=2;
  44.         if(infono>=nExtNum*2) {
  45.             return 0;
  46.         }
  47.         if(0==(infono&1)) {
  48.             memcpy(buf,ppExtNames[infono>>1],nRet=min(buflen,strlen(ppExtNames[infono>>1])+1));
  49.         } else {
  50.             memcpy(buf,ppFmtNames[infono>>1],nRet=min(buflen,strlen(ppFmtNames[infono>>1])+1));
  51.         }
  52.     }
  53.  
  54.     return nRet;
  55. }
  56.  
  57. extern "C" int WINAPI _export IsSupported(LPSTR filename,DWORD dw)
  58. {
  59.     char szBuf[2000];
  60.     int nRet;
  61.  
  62.     nRet=1;
  63.     if(0==(HIWORD(dw))) {
  64.         DWORD n;
  65.         if(!ReadFile((HANDLE)dw,szBuf,sizeof(szBuf),&n,NULL)) {
  66.             nRet=0;
  67.         }
  68.     } else {
  69.         memcpy(szBuf,(void*)dw,2000);
  70.     }
  71.  
  72.     if(1==nRet) {
  73.         HANDLE hFile;
  74.         char szTmpDir[MAX_PATH],szTmpFile[MAX_PATH];
  75.         GetTempPath(MAX_PATH,szTmpDir);
  76.         GetTempFileName(szTmpDir,"TAR",0,szTmpFile);
  77.         if(INVALID_HANDLE_VALUE==(hFile=CreateFile(szTmpFile,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL))) {
  78.             nRet=0;
  79.         } else {
  80.             DWORD nWrite;
  81.             WriteFile(hFile,szBuf,sizeof(szBuf),&nWrite,NULL);
  82.             CloseHandle(hFile);
  83.             nRet=TarCheckArchive(szTmpFile,0);
  84.             DeleteFile(szTmpFile);
  85.         }
  86.     }
  87.  
  88.     return nRet;
  89. }
  90.  
  91. extern "C" int WINAPI _export GetArchiveInfo(LPSTR buf,long len, unsigned int flag,HLOCAL *lphInf)
  92. {
  93.     int nCnt,nPos,nStatus;
  94.     HARC hArc;
  95.     fileInfo *pInf;
  96.     HLOCAL hInf;
  97.     INDIVIDUALINFO iInfo;
  98.  
  99.     if(0!=(flag&0x0007)) {
  100.         // FileImage Pointer not supported.
  101.         return -1;
  102.     }
  103.  
  104.     nCnt=TarGetFileCount(buf);
  105.     if(NULL==(hInf=LocalAlloc(LHND,(nCnt+1)*sizeof(fileInfo)))) {
  106.         return 4;
  107.     }
  108.     if(NULL==(pInf=(fileInfo*)LocalLock(hInf))) {
  109.         return 5;
  110.     }
  111.  
  112.     if(NULL==(hArc=TarOpenArchive(NULL,buf,0))) {
  113.         LocalUnlock(hInf);
  114.         LocalFree(hInf);
  115.         return -1;
  116.     }
  117.  
  118.     nPos=0;
  119.     nStatus=TarFindFirst(hArc,"*",&iInfo);
  120.     while(-1!=nStatus) {
  121.         memset(pInf,0,sizeof(fileInfo));
  122.         memcpy(pInf->method,iInfo.szMode,8);
  123.         pInf->position=nPos++;
  124.         pInf->compsize=iInfo.dwCompressedSize;
  125.         pInf->filesize=iInfo.dwOriginalSize;
  126.         pInf->timestamp=0; //iinfo.wData + iinfo.wTime;
  127.         memcpy(pInf->filename,iInfo.szFileName,200);
  128.         pInf->crc=iInfo.dwCRC;
  129.         pInf++;
  130.         nStatus=TarFindNext(hArc,&iInfo);
  131.     }
  132.     TarCloseArchive(hArc);
  133.     LocalUnlock(hInf);
  134.     *lphInf=hInf;
  135.  
  136.     return 0;
  137. }
  138. extern "C" int WINAPI _export GetFileInfo(LPSTR buf,long len, LPSTR filename, unsigned int flag,fileInfo *lpInfo)
  139. {
  140.     int nRet;
  141.     HANDLE hInf;
  142.     fileInfo *pInf;
  143.     int (*CompareFunction)(const char*,const char*);
  144.  
  145.     CompareFunction=((0x0080==(flag&0x0080))?stricmp:strcmp);
  146.  
  147.     nRet=8;
  148.     GetArchiveInfo(buf,0,flag,&hInf);
  149.     pInf=(fileInfo*)GlobalLock(hInf);
  150.     while('\0'!=pInf->method[0]) {
  151.         if(0==((CompareFunction)(pInf->filename,filename))) {
  152.             memcpy(lpInfo,pInf,sizeof(fileInfo));
  153.             nRet=0;
  154.             break;
  155.         }
  156.         pInf++;
  157.     }
  158.     GlobalUnlock(hInf);
  159.     GlobalFree(hInf);
  160.  
  161.     return nRet;
  162. }
  163.  
  164. extern "C" int WINAPI _export GetFile(LPSTR src,long len, LPSTR dest,unsigned int flag, FARPROC prgressCallback,long lData)
  165. {
  166.     int nRet;
  167.     HANDLE hInf;
  168.     fileInfo *pInf;
  169.     char szCmd[1000],szName[MAX_PATH];
  170.     unsigned long nSize;
  171.  
  172.     if(0!=(flag&0x0007)) {
  173.         return -1;                        // input must be file
  174.     }
  175.  
  176.     GetArchiveInfo(src,0,flag,&hInf);
  177.     pInf=(fileInfo*)GlobalLock(hInf);
  178.     while('\0'!=pInf->method[0]) {
  179.         if((unsigned long)pInf->position==(unsigned long)len) {
  180.             nSize=pInf->filesize;
  181.             strcpy(szName,pInf->filename);
  182.             nRet=0;
  183.             break;
  184.         }
  185.         pInf++;
  186.     }
  187.     GlobalUnlock(hInf);
  188.     GlobalFree(hInf);
  189.     if(0!=nRet) {
  190.         return -1;
  191.     }
  192.  
  193.     nRet=8;
  194.     if(0x0000==(flag&0x0700)) {            // output is file
  195.         char szBuf[1000];
  196.         wsprintf(szCmd,"--display-dialog=0 --use-directory=0 -o \"%s\" -x \"%s\" \"%s\"",dest,src,szName);
  197.         nRet=Tar(NULL,szCmd,szBuf,sizeof(szBuf));
  198.     } else if(0x0100==(flag&0x0700)) {    // output is memory
  199.         unsigned long nWrite=0;
  200.         HANDLE hBuf;
  201.         void *pBuf;
  202.         wsprintf(szCmd,"--display-dialog=0 --use-directory=0 \"%s\" \"%s\"",src,szName);
  203.         if(NULL==(hBuf=LocalAlloc(LHND,nSize+1))) {
  204.             nRet=4;
  205.         } else {
  206.             if(NULL==(pBuf=LocalLock(hBuf))) {
  207.                 LocalFree(hBuf);
  208.                 nRet=5;
  209.             } else {
  210.                 nRet=TarExtractMem(NULL,szCmd,(unsigned char*)pBuf,nSize,NULL,NULL,&nWrite);
  211.                 LocalUnlock(hBuf);
  212.                 *((HANDLE*)dest)=hBuf;
  213.                 nRet=0;
  214.             }
  215.         }
  216.     } else {
  217.         nRet=-1;
  218.     }
  219.  
  220.     return nRet;
  221. }
  222.  
  223.