home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2001 January / VPR0101A.BIN / OLS / TAR32053 / tar32053.exe / SRC / TAR32.C < prev    next >
C/C++ Source or Header  |  1999-05-23  |  21KB  |  848 lines

  1. /* tar32.cpp */
  2. /*    -> tar32.c */
  3.  
  4. #ifdef __cplusplus
  5. extern "C"{
  6. #endif
  7.  
  8. #include "defconf.h"
  9. #ifdef DLL
  10. #include <wtypes.h>
  11. #include <time.h>
  12. #include "tar32.h"
  13.  
  14.  
  15. #include <mbstring.h>
  16. #include "version.h"
  17. #include "ioctrl.h"
  18. #include "defs.h"
  19. #include "main.h"
  20. #include <stdio.h>
  21. #include "tar.h"
  22. #include <stdlib.h>
  23. #include "misc.h"
  24. #include "archio.h"
  25. #include <sys/stat.h>
  26. #include "tardir.h"
  27. #include <fcntl.h>    /* _O_BINARY */
  28. #include <winuser.h>
  29. #include "nkf.h"
  30. /* #include "tarwin.h" */
  31. #include "tarmsg.h"
  32. #include "dlgconf.h"
  33.  
  34. #include "dllmain.h"
  35.  
  36. #include "gzip.h"
  37. #undef head
  38.  
  39. /*#include "gzip.h"*/
  40. /* Compression methods (see algorithm.doc) */
  41. #define STORED      0
  42. #define COMPRESSED  1
  43. #define PACKED      2
  44. #define LZHED       3
  45.  
  46. #define BZIP2ED        4    /* added by tsuneo (1998/04/02) */
  47.  
  48. /* methods 4 to 7 reserved */
  49. #define DEFLATED    8
  50. #define MAX_METHODS 9
  51. #define NO_COMP     100
  52. extern int method;         /* compression method */
  53.  
  54.  
  55. static INDIVIDUALINFO Minfo;            /* init at FindFirst */
  56. static HEADER Mhead;            /* Setted by Find Next. Use at GetWriteTime ,etc..*/
  57. static    char *Margv[10000];        /* Save _szWildName at FindFirst.use at FindNext */ 
  58. static    char *MargvStr=NULL;    /* Save _szWildName at FindFirst.use at FindNext */     
  59. static int SumdwOriginalSize;    /* init at OpenArchive */
  60. static int SumdwCompressedSize;    /* init at OpenArchive */
  61. static char MArcFileName[1000];    /* init at OpenArchive */
  62. static int MFirstSearch;    /* flag of the first call of findfirst */
  63. static int MFindEnd;        /* end mark of tarfindfirst/tarfindnext */
  64. static int MFindCount;        /* counter of findfirst/next */
  65. static ARCH_FILE *March_fp;    /* handle of archive(gzip/bzip2/normal) */
  66.  
  67. #if 0
  68. typedef struct TAR32_FIND_HANDLE_{
  69.     INDIVIDUALINFO info;            /* init at FindFirst */
  70.     HEADER head;            /* Setted by Find Next. Use at GetWriteTime ,etc..*/
  71.     char *argv[10000];        /* Save _szWildName at FindFirst.use at FindNext */ 
  72.     char *argvStr=NULL;    /* Save _szWildName at FindFirst.use at FindNext */     
  73.     int SumdwOriginalSize;    /* init at OpenArchive */
  74.     int SumdwCompressedSize;    /* init at OpenArchive */
  75.     char ArcFileName[1000];    /* init at OpenArchive */
  76.     int FirstSearch;    /* flag of the first call of findfirst */
  77.     int FindEnd;        /* end mark of tarfindfirst/tarfindnext */
  78.     int FindCount;        /* counter of findfirst/next */
  79.     ARCH_FILE *arch_fp;    /* handle of archive(gzip/bzip2/normal) */
  80. }TAR32_FIND_HANDLE;
  81. #endif
  82.  
  83. static BOOL flagInProcess = FALSE;        /* use only PreAPI/PostAPI/GetRunning */
  84. /* static BOOL flagBackGroundMode = FALSE;    
  85. static BOOL flagCursorMode = FALSE;
  86. */
  87.  
  88. static void PreAPI(void){flagInProcess=TRUE;}
  89. static void PostAPI(void){flagInProcess=FALSE;}
  90. static int GetRunning(void){return flagInProcess;}
  91.  
  92. HWND api_hwnd=0;    /* ウインドウのハンドル*/
  93.  
  94. WORD WINAPI _export TarGetVersion(VOID)
  95. {
  96.     WORD ver;
  97.     VS_FIXEDFILEINFO *verinfo;
  98.     HRSRC res;
  99.     HGLOBAL hres;
  100.     
  101.     res = FindResource(application_instance,MAKEINTRESOURCE(VS_VERSION_INFO),RT_VERSION);
  102.     hres = LoadResource(application_instance,res);
  103.     verinfo = (VS_FIXEDFILEINFO *)((char *)LockResource(hres) + 40);
  104.     ver = (WORD)((verinfo->dwFileVersionMS >> 16) * 100 + (verinfo->dwFileVersionMS & 0xffff));
  105.     return ver;
  106. }
  107. BOOL WINAPI _export TarGetRunning(VOID)
  108. {
  109.     return GetRunning();
  110. }
  111. BOOL WINAPI _export TarGetBackGroundMode(VOID)/* NO IMPLEMENT:return FALSE */
  112. {
  113.     /* return flagBackGroundMode();*/
  114.     return FALSE;
  115. }
  116. BOOL WINAPI _export TarSetBackGroundMode(const BOOL _BackGroundMode)/* NO IMPLEMENT:return FALSE */
  117. {
  118.     /*flagBackGroundMode = bBackGroundMode;
  119.     return TRUE;*/
  120.     return FALSE;
  121. }
  122. BOOL WINAPI _export TarGetCursorMode(VOID)/* NO IMPLEMENT:return FALSE */
  123. {
  124.     return FALSE;
  125. }
  126. BOOL WINAPI _export TarSetCursorMode(const BOOL _CursorMode)/* NO IMPLEMENT:return FALSE */
  127. {
  128.     return FALSE;
  129. }
  130. WORD WINAPI _export TarGetCursorInterval(VOID)/* NO IMPLEMENT:return 80 */
  131. {
  132.     return 80;
  133. }
  134. BOOL WINAPI _export TarSetCursorInterval(const WORD _Interval)/* NO IMPLEMENT:return FALSE */
  135. {
  136.     return FALSE;
  137. }
  138. int WINAPI _export Tar(const HWND _hwnd, LPCSTR _szCmdLine,
  139.                         LPSTR _szOutput, const DWORD _dwSize)
  140. {
  141.     int argc;
  142.     char *argv[10000];
  143.     int ret;
  144.     char *argvstr;
  145.  
  146.     api_hwnd=_hwnd;
  147.     PreAPI();
  148.     argv[0]="tar";
  149.     argvstr=splitCmdLine(&argc,argv+1,_szCmdLine);
  150.     argc++;
  151.     ioctrl_output_init(_szOutput,_dwSize);
  152.     ret=tar_main(argc,argv);
  153.     free(argvstr);
  154.     PostAPI();
  155. /*MessageBox(api_hwnd,"Tar()TarMsgEnd(pre)","tar32.dll debug",0);*/
  156.     TarMsgEnd();
  157. /*MessageBox(api_hwnd,"Tar()TarMsgEnd(post)","tar32.dll debug",0);*/
  158.     return ret-1;
  159. }
  160. /* NO IMPLEMENT:return -1 */
  161. int WINAPI _export TarExtractMem(const HWND _hwndParent,
  162.         LPCSTR _szCmdLine, LPBYTE _lpBuffer, const DWORD _dwSize,
  163.         time_t *_lpTime, LPWORD _lpwAttr, LPDWORD _lpdwWriteSize)
  164. {
  165.     return -1;
  166. }
  167. /* NO IMPLEMENT:return -1 */
  168. int WINAPI _export TarCompressMem(const HWND _hwndParent,
  169.         LPCSTR _szCmdLine, const LPBYTE _lpBuffer, const DWORD _dwSize,
  170.         const time_t *_lpTime, const LPWORD _lpwAttr,
  171.         LPDWORD _lpdwWriteSize)
  172. {
  173.     return -1;
  174. }
  175. /* File Existans Check Only */
  176. BOOL WINAPI _export TarCheckArchive(LPCSTR _szFileName, const int _iMode)
  177. {
  178.     if((int)TarGetArchiveType(_szFileName)>0){
  179.         return TRUE;
  180.     }else{
  181.         return FALSE;
  182.     }
  183.     /*
  184.     FILE *fp;
  185.     if((fp=fopen(_szFileName,"r"))==NULL){
  186.         return FALSE;
  187.     }
  188.     fclose(fp);
  189.     return TRUE;
  190.     */
  191. }
  192. int WINAPI _export TarGetArchiveType(LPCSTR _szFileName)
  193. {
  194.     int return_value;
  195.     extern int gzip_flag; /* main.c */
  196.     int archive_method=-1;
  197.     int access_method=0;
  198.     int crccheck=0;
  199.     unsigned int sum;
  200.     HEADER *phead;
  201.     ARCH_FILE *arch_fp;
  202.  
  203.     return_value=setjmp(start_env);
  204.     if(return_value!=0){
  205.         return -1;
  206.     }
  207.     ioctrl_output_init_test();
  208.  
  209.     static_init_all();
  210.     // Archives[0]=_szFileName;
  211.     Archives[0]=NULL;
  212.     Archives[1]=NULL;
  213.  
  214.     _fmode = O_BINARY;
  215.  
  216.     
  217.  
  218.     if((arch_fp = open_arch((char*)_szFileName, "r"))==NULL){
  219.         return -1;
  220.     }
  221.     if(read_arch(arch_fp, TBLOCK, (char **)&phead) == TBLOCK){
  222.         sum=strtol(phead->dbuf.chksum,NULL,8);
  223.         if(sum == compsum(phead)){
  224.             crccheck=1;
  225.         }
  226.     }
  227.     access_method=get_access_method();
  228.     close_arch(arch_fp/*'t'*/);arch_fp=NULL;
  229.  
  230.     switch(crccheck){
  231.     case 1:
  232.         switch(access_method){
  233.         case DEFLATED:
  234.             archive_method=ARCHIVETYPE_TARGZ;break;
  235.         case COMPRESSED:
  236.             archive_method=ARCHIVETYPE_TARZ;break;
  237.         case BZIP2ED:
  238.             archive_method=ARCHIVETYPE_TARBZ2;break;
  239.         case NO_COMP:
  240.             archive_method=ARCHIVETYPE_TAR;break;
  241.         default:
  242.             break;
  243.         }
  244.         break;
  245.     case 0:
  246.         switch(access_method){
  247.         case DEFLATED:
  248.             archive_method=ARCHIVETYPE_GZ;break;
  249.         case COMPRESSED:
  250.             archive_method=ARCHIVETYPE_Z;break;
  251.         case BZIP2ED:
  252.             archive_method=ARCHIVETYPE_BZ2;break;
  253.         default:
  254.             break;
  255.         }
  256.     }
  257.     return archive_method;
  258. }
  259. /* NO IMPLEMENT:return FALSE */
  260. BOOL WINAPI _export TarConfigDialog(const HWND _hwnd, LPSTR _lpszComBuffer,
  261.                         const int _iMode)
  262. {
  263.     int ret;
  264.  
  265.     PreAPI();
  266.     api_hwnd=_hwnd;
  267.     static_init_all();
  268.     ret=config_dialog(_hwnd,_lpszComBuffer,_iMode);
  269.     PostAPI();
  270.     return ret;
  271.     /*
  272.     int r;
  273.     char NkfVersion[100];
  274.     char message[1000];
  275.  
  276.     strcpy(message,"TAR32.DLL version " DLL_VERSION_STR);
  277. #ifdef USE_NKF_DLL
  278.     GetNkfVersion(NkfVersion);
  279.     if(strcmp(NkfVersion,"")==0){
  280.         strcat(message,"\n(NKF32.DLL not found)");
  281.     }else{
  282.         strcat(message,"\n(NKF32.DLL version ");
  283.         strcat(message,NkfVersion);
  284.         strcat(message,")");
  285.     }
  286. #endif
  287.     r=MessageBox(_hwnd,message,"TAR32.DLLの設定",MB_OK);
  288.     return TRUE;
  289.     */
  290.  }
  291. int WINAPI _export TarGetFileCount(LPCSTR _szArcFile)
  292. {
  293.     HARC harc;
  294.     int ret;
  295.     int count = 0;
  296.  
  297.     harc = TarOpenArchive(NULL,_szArcFile,0);
  298.     if(harc==0){return 0;}
  299.     ret = TarFindFirst(harc,"",NULL);
  300.     while(ret==0){
  301.         count++;
  302.         ret = TarFindNext(harc,NULL);
  303.     }
  304.     TarCloseArchive(harc);
  305.     return count;
  306. }
  307. #if 0
  308. void SetHARC(HARC *harc)
  309. {
  310.     arch_SetAfd((int)(harc-(void *)NULL));
  311. }
  312. HARC GetHARC(void)
  313. {
  314.     return (HARC)((void*)NULL+arch_GetAfd());
  315. }
  316. #endif
  317.  
  318. HARC WINAPI _export TarOpenArchive(const HWND _hwnd, LPCSTR _szFileName,
  319.                             const DWORD _dwMode)
  320. {
  321.     int return_value;
  322.     extern int gzip_flag; /* main.c */
  323.     // TAR32_FIND_HANDLE *find_handle;
  324.  
  325.     api_hwnd=_hwnd;
  326.     return_value=setjmp(start_env);
  327.     if(return_value!=0){
  328.         return NULL;
  329.     }
  330.     ioctrl_output_init_test();
  331.  
  332.     static_init_all();
  333.     strcpy(MArcFileName,_szFileName);
  334.     // Archives[0]=MArcFileName;
  335.     Archives[0]=NULL;
  336.     Archives[1]=NULL;
  337.     if(_dwMode & M_CHECK_ALL_PATH){
  338.         OPTION_check_all_path=1;
  339.     }else{
  340.         OPTION_check_all_path=0;
  341.     }
  342.     if(_dwMode & M_BAR_WINDOW_OFF){
  343.         OPTION_display_dialog=0;
  344.     }else{
  345.         OPTION_display_dialog=1;
  346.     }
  347.     _fmode = O_BINARY;
  348.     March_fp = open_arch(MArcFileName, "r");
  349.     SumdwOriginalSize=0;
  350.     SumdwCompressedSize=0;
  351.  
  352. #if 0
  353.     harc = GlobalAlloc(...);
  354.     find_handle = GlobalLock(harc);
  355.     //if((find_handle = malloc(sizeof(*find_handle)))==NULL){
  356.     //    return NULL;
  357.     //}
  358.     memset(find_handle,0,sizeof(*find_handle));
  359.  
  360.     find_handle->hwnd = _hwnd;
  361.     strcpy(find_handle->ArcFileName,_szFileName);
  362.     find_handle->arch_fp = March_fp;
  363.     find_handle->SumdwOriginalSize = 0;
  364.     find_handle->SumdwCompressSize = 0;
  365.  
  366.     GlobalUnlock(harc(find_handle?));
  367.     return harc;
  368. #endif
  369.     return /* GetHARC()*/ (HARC)1;
  370. }
  371.     
  372. int WINAPI _export TarCloseArchive(HARC _harc)
  373. {
  374.     int return_value;
  375.     /* HEADER *head;*/
  376.     
  377.     return_value=setjmp(start_env);
  378.     if(return_value!=0){
  379.         return return_value;
  380.     }
  381.     
  382.     /* SetARC(_harc);*/
  383.     if(MargvStr!=NULL){
  384.         free(MargvStr);
  385.         MargvStr=NULL;
  386.     }
  387.     close_arch(March_fp/*'t'*/);March_fp = NULL;
  388.     return 0;
  389. }
  390. WORD GetARCDate(time_t ti)
  391. {
  392.     struct tm *tm;
  393.     
  394.     tm=localtime(&ti);
  395.     return (((unsigned)tm->tm_year-(unsigned)80)<<9)+((tm->tm_mon+1)<<5)+(tm->tm_mday);
  396. }
  397. WORD GetARCTime(time_t ti)
  398. {
  399.     struct tm *tm;
  400.     
  401.     tm=localtime(&ti);
  402.     return ((tm->tm_hour)<<11)+((tm->tm_min)<<5)+((tm->tm_sec)/2);
  403. }
  404.  
  405. /* headからinfoへ変換する。fnameはdecode_dir(_e)で得られた値。*/
  406. /* 早い話がhead->dbuf.nameのこと。*/
  407. void HeaderToIndividualInfo(INDIVIDUALINFO *info,HEADER *head,char *fname)
  408. {
  409.     time_t ti;
  410.     unsigned short st_mode;
  411.  
  412.     info->dwOriginalSize=strtol(head->dbuf.size,NULL,8);
  413.     info->dwCompressedSize=0;
  414.     info->dwCRC=head->dbuf.magic[0]*256+head->dbuf.magic[1];
  415.     info->uFlag=0;
  416.     info->uOSType=(UINT)-1;
  417.     if(info->dwOriginalSize==0){
  418.         info->wRatio=0;
  419.     }else{
  420.         info->wRatio=(WORD)(((float)info->dwCompressedSize/(float)info->dwOriginalSize)*1000);
  421.     }
  422.     ti=strtol(head->dbuf.mtime,NULL,8);
  423.     info->wDate=GetARCDate(ti);
  424.     info->wTime=GetARCTime(ti);
  425.     
  426.     // strcpy(info->szFileName,fname/* head->dbuf.name*/);
  427.     strncpy2(info->szFileName,fname,sizeof(info->szFileName));
  428.     
  429.     /* strcpy(info->szAttribute,"????") *//* strtol(block0->dbuf.mode,NULL,8)*/;
  430.     st_mode=(unsigned short)strtol(head->dbuf.mode,NULL,8);
  431.     info->szAttribute[0]='?'; /* Archive */
  432.     info->szAttribute[1]='?'; /* System */
  433.     info->szAttribute[2]=(st_mode & _S_IREAD) ? '-' : 'H'; /* Hide */
  434.     info->szAttribute[3]=(st_mode & _S_IWRITE) ? '-' : 'R'; /* Read Only*/
  435.     info->szAttribute[4]='\0';
  436.     switch(get_access_method()){
  437.     case NO_COMP:
  438.         strcpy(info->szMode,"-tar-");break;
  439.     case DEFLATED:
  440.         strcpy(info->szMode,"-tgz-");break;
  441.     case COMPRESSED:
  442.         strcpy(info->szMode,"-taz-");break;
  443.     case BZIP2ED:
  444.         strcpy(info->szMode,"tar.bz2");break;
  445.     default:
  446.         strcpy(info->szMode,"-???-");break;
  447.     }
  448. }
  449.  
  450. int SetIndividualInfoForNotTar(INDIVIDUALINFO *info,int fd,char *arcfname,int method,int time_stamp,char *fname)
  451. {
  452.     int ti;
  453.     extern int get_gunzip_fname(char *unpackfn,char *packfn); /* in archio.c */
  454.     struct stat stat;
  455.     
  456.     memset(info,0,sizeof(*info));
  457.     if(*fname){
  458.         strcpy(info->szFileName,fname);
  459.     }else{
  460.         char *ptr;
  461.  
  462.         get_gunzip_fname(info->szFileName,arcfname);
  463.         if((ptr=_mbsrchr(info->szFileName,'/')) || (ptr=_mbsrchr(info->szFileName,'\\'))){
  464.             memmove(info->szFileName,ptr+1,strlen(ptr+1)+1);
  465.         }
  466.     }
  467.     strcpy(info->szAttribute,"????");
  468.     if(method == COMPRESSED){
  469.         strcpy(info->szMode,"-z-");
  470.     }else if(method == DEFLATED){
  471.         strcpy(info->szMode,"-gz-");
  472.     }else if(method == BZIP2ED){
  473.         strcpy(info->szMode,"-bz2-");
  474.     }else{
  475.         strcpy(info->szMode,"-???-");
  476.     }
  477.     if(time_stamp){
  478.         ti = time_stamp;
  479.     }else{
  480.         ti = time(NULL);
  481.     }
  482.     info->wDate = GetARCDate(ti);
  483.     info->wTime = GetARCTime(ti);
  484.     if(fd!=0 && fd!=-1){
  485.         fstat(fd,&stat);
  486.         info->dwOriginalSize = stat.st_size;
  487.     }
  488.     return 0;
  489. }
  490. int WINAPI _export TarFindFirst(HARC _harc, LPCSTR _szWildName,
  491.                             INDIVIDUALINFO *_lpSubInfo)
  492. {
  493.     int r;
  494.     int argc;
  495.     MargvStr=splitCmdLine(&argc,Margv,_szWildName);
  496.     MFirstSearch = 1;
  497.     MFindEnd = 0;
  498.     MFindCount = 0;
  499.     r=TarFindNext(_harc,_lpSubInfo);
  500.     
  501.     return r;
  502. }
  503.  
  504. int WINAPI _export TarFindNext(HARC _harc, INDIVIDUALINFO *_lpSubInfo)
  505. {
  506.     int return_value,api_return_value;
  507.     /* HEADER *head=Mhead;*/
  508.     /*int argc;*/
  509.     int longlink=0;
  510.     char longlink_name[FNAME_BUF];
  511.     HEADER *head;
  512.     int crccheck=0;
  513.  
  514.     if(MFindEnd){return -1;}
  515.     /* どうもうまくダイアログが表示されない。
  516.         しかも時間がかかるのでやめようかな。 */
  517.     //tarwin_executing_dialog_display();
  518.     // MessageBox(api_hwnd,"TarFindNext","TAR32.DLL",0);    
  519.     return_value=setjmp(start_env);
  520.     if(return_value!=0){
  521.         api_return_value=-1;
  522.         goto endfunc;    /* 後処理へ... */
  523.     }
  524.     /* SetHARC(_harc);*/
  525.     
  526.     /* get from function do_t() at main.c */
  527.     while(read_arch(March_fp, TBLOCK, (char **)&head) == TBLOCK) {
  528.         char type;
  529.         struct stat statbuf;
  530.         char name[FNAME_BUF];
  531.         /*HEADER *head=Mhead;*/
  532.         crccheck = ((unsigned)strtol(head->dbuf.chksum,NULL,8) == compsum(head));
  533.         
  534.         if(crccheck == 0){break;}
  535.  
  536.         if (eofblock(head->dummy))
  537.             break;
  538.  
  539.         MFirstSearch = 0;
  540.         /*        write(fileno(stderr),head,TBLOCK);*/
  541.         type = decode_dir(name, &statbuf, head);
  542.         if(type=='e'){
  543.             api_return_value=-1;
  544.             goto endfunc;    /* 後処理へ... */
  545.         }
  546.         if (longlink){
  547.             strcpy(name,longlink_name);
  548.             longlink = 0;
  549.         }
  550.         
  551.         if (type == VOLTYPE)
  552.             check_vol(name, &statbuf);
  553.         Current_file_name = name;
  554.         Current_file_mode = statbuf.st_mode;
  555.         Current_file_mtime = statbuf.st_mtime;
  556.         Current_file_size = Current_file_left = statbuf.st_size;
  557.         Mhead = *head;
  558.  
  559.         switch (type) {
  560.         case LNKTYPE:
  561.         case SYMTYPE:
  562.             break;
  563.         case LONGLINK:
  564.             /* 100文字以上の長いファイル名の場合はそのデータ領域にファイル名が、
  565.                 次のデータ領域にファイルの中味がある。
  566.                 そのため、continueで次のファイルを読みに行く。*/
  567.             longlink = 1;
  568.             read_longlink_name(March_fp, statbuf.st_size,longlink_name);
  569.             continue;
  570.         default:
  571.             skip_file(March_fp);
  572.             break;
  573.         }
  574.         if(TarMsgFileBegin(head,Current_file_name,Current_file_name)==-1){
  575.             break;
  576.         }
  577.  
  578.         Current_file_left = 0;
  579.         
  580.         if(main_match(name, Margv)) {
  581.             /* added next 4 line for Get Dll info */
  582.             HeaderToIndividualInfo(&Minfo,&Mhead,name);
  583.             if(_lpSubInfo){*_lpSubInfo = Minfo;}
  584.             SumdwOriginalSize+=Minfo.dwOriginalSize;
  585.             SumdwCompressedSize+=Minfo.dwCompressedSize;
  586.             MFindCount ++;
  587.             api_return_value=0;goto endfunc;
  588.         }
  589.     }
  590.  
  591.     MFindEnd =1;
  592.     /* for gzip only file */
  593.     if(MFirstSearch && MFindCount==0){
  594.         int access_method = get_access_method();
  595.  
  596.         MFirstSearch = 0;
  597.         if(access_method == DEFLATED || access_method == BZIP2ED || access_method == COMPRESSED){
  598.             if(crccheck==0/*false(not tar)*/){
  599.                 SetIndividualInfoForNotTar(&Minfo
  600.                     ,arch_GetAfd()
  601.                     ,MArcFileName
  602.                     ,access_method
  603.                     ,gzip_time_stamp
  604.                     ,gzip_filename);
  605.                 if(_lpSubInfo){*_lpSubInfo = Minfo;}                
  606.                 memset(&Mhead,0,sizeof(Mhead));
  607.                 MFindCount = 1;
  608.                 api_return_value = 0;
  609.                 goto endfunc;
  610.             }
  611.         }
  612.     }
  613.     api_return_value=-1;
  614.  
  615. endfunc:
  616.     TarMsgEnd();
  617.     return api_return_value;
  618. }
  619. int WINAPI _export TarGetArcFileName(HARC _harc, LPSTR _lpBuffer,
  620.                             const int _nSize)
  621. {
  622.     strncpy2(_lpBuffer,MArcFileName,_nSize);
  623.     return 0;
  624. }
  625. /* NO IMPLEMENT:return -1: */
  626.  
  627. DWORD WINAPI _export TarGetArcFileSize(HARC _harc)
  628. {
  629.     struct stat buf;
  630.     int fh,result;
  631.     
  632.     fh=arch_GetAfd();
  633.     result=fstat(fh,&buf);
  634.     if(result!=0){return (DWORD)-1;}
  635.     
  636.     return buf.st_size;
  637. }
  638.  
  639. DWORD WINAPI _export TarGetArcOriginalSize(HARC _harc)
  640. {
  641.     return SumdwOriginalSize;
  642. }
  643. DWORD WINAPI _export TarGetArcCompressedSize(HARC _harc)
  644. {
  645.     return SumdwCompressedSize;
  646. }
  647. WORD WINAPI _export TarGetArcRatio(HARC _harc)
  648. {
  649.     if (SumdwOriginalSize==0){
  650.         return 0;
  651.     }else{
  652.         return (WORD)(((float)SumdwCompressedSize/(float)SumdwOriginalSize)*1000);
  653.     }
  654. }
  655.  
  656. /* NO IMPLEMENT:return -1: */
  657. WORD WINAPI _export TarGetArcDate(HARC _harc)
  658. {
  659.     struct stat buf;
  660.     int fh,result;
  661.     
  662.     fh=arch_GetAfd();
  663.     result=fstat(fh,&buf);
  664.     if(result!=0){return (WORD)-1;}
  665.     
  666.     return GetARCDate(buf.st_mtime);
  667. }
  668.  
  669. /* NO IMPLEMENT:return -1: */
  670. WORD WINAPI _export TarGetArcTime(HARC _harc)
  671. {
  672.     struct stat buf;
  673.     int fh,result;
  674.     
  675.     fh=arch_GetAfd();
  676.     result=fstat(fh,&buf);
  677.     if(result!=0){return (WORD)-1;}
  678.     
  679.     return GetARCTime(buf.st_mtime);
  680. }
  681.  
  682. /* NO IMPLEMENT:return -1: */
  683. UINT WINAPI _export TarGetArcOSType(HARC _harc)
  684. {
  685.     return (WORD)-1;
  686. }
  687. int WINAPI _export TarGetFileName(HARC _harc, LPSTR _lpBuffer,
  688.                             const int _nSize)
  689. {
  690.     strncpy2(_lpBuffer,Minfo.szFileName,_nSize);
  691.     return 0;
  692. }
  693. int WINAPI _export TarGetMethod(HARC _harc, LPSTR _lpBuffer,
  694.                             const int _nSize)
  695. {
  696.     if(_nSize>=4){
  697.         strncpy(_lpBuffer,Minfo.szMode+1,3);
  698.         _lpBuffer[3]='\0';
  699.         return 0;
  700.     }else{
  701.         return -1;
  702.     }
  703. }
  704. DWORD WINAPI _export TarGetOriginalSize(HARC _harc)
  705. {
  706.     return Minfo.dwOriginalSize;
  707. }
  708. DWORD WINAPI _export TarGetCompressedSize(HARC _harc)
  709. {
  710.     return Minfo.dwCompressedSize;
  711. }
  712. WORD WINAPI _export TarGetRatio(HARC _harc)
  713. {
  714.     return Minfo.wRatio;
  715. }
  716. WORD WINAPI _export TarGetDate(HARC _harc)
  717. {
  718.     return Minfo.wDate;
  719. }
  720. WORD WINAPI _export TarGetTime(HARC _harc)
  721. {
  722.     return Minfo.wTime;
  723. }
  724. DWORD WINAPI _export TarGetWriteTime(HARC _harc)
  725. {
  726.     return strtol(Mhead.dbuf.mtime,NULL,8);
  727. }
  728. DWORD WINAPI _export TarGetAccessTime(HARC _harc)
  729. {
  730.     return strtol(Mhead.dbuf.atime,NULL,8);
  731. }
  732. DWORD WINAPI _export TarGetCreateTime(HARC _harc)
  733. {
  734.     return strtol(Mhead.dbuf.ctime,NULL,8);
  735. }
  736. DWORD WINAPI _export TarGetCRC(HARC _harc)
  737. {
  738.     return Minfo.dwCRC;
  739. }
  740. int WINAPI _export TarGetAttribute(HARC _harc)
  741. {
  742.     unsigned short st_mode;
  743.     
  744.     st_mode=(unsigned short)strtol(Mhead.dbuf.mode,NULL,8);
  745.     return 
  746.         (st_mode & _S_IWRITE)*FA_RDONLY /* Read Only */
  747.         +(st_mode & _S_IREAD)*FA_HIDDEN /* Hidden */
  748.         +(st_mode & 0)*FA_SYSTEM    /* System File */
  749.         +(st_mode & 0)*FA_LABEL        /* volume label */
  750.         +(st_mode & _S_IFDIR)*FA_DIREC /* Directory */
  751.         +(st_mode & 0)*FA_ARCH;    /* Archive Attribute */
  752. }
  753.  
  754. UINT WINAPI _export TarGetOSType(HARC _harc)
  755. {
  756.     return Minfo.uOSType;
  757. }
  758. BOOL WINAPI _export TarQueryFunctionList(const int _iFunction)
  759. {
  760.     int r;
  761.     switch( _iFunction){
  762.     case ISARC                        :r=TRUE;break;
  763.     case ISARC_GET_VERSION            :r=TRUE;break;
  764.     case ISARC_GET_CURSOR_INTERVAL    :r=FALSE;break;
  765.     case ISARC_SET_CURSOR_INTERVAL    :r=FALSE;break;
  766.     case ISARC_GET_BACK_GROUND_MODE    :r=FALSE;break;
  767.     case ISARC_SET_BACK_GROUND_MODE    :r=FALSE;break;
  768.     case ISARC_GET_CURSOR_MODE        :r=FALSE;break;
  769.     case ISARC_SET_CURSOR_MODE        :r=FALSE;break;
  770.     case ISARC_GET_RUNNING            :r=TRUE;break;
  771.  
  772.     case ISARC_CHECK_ARCHIVE        :r=TRUE;break;
  773.     case ISARC_CONFIG_DIALOG        :r=TRUE;break;
  774.     case ISARC_GET_FILE_COUNT        :r=TRUE;break;
  775.     case ISARC_QUERY_FUNCTION_LIST    :r=TRUE;break;
  776.     case ISARC_HOUT                    :r=FALSE;break;                    
  777.     case ISARC_STRUCTOUT            :r=TRUE;break;
  778.     case ISARC_GET_ARC_FILE_INFO    :r=TRUE;break;
  779.  
  780.     case ISARC_OPEN_ARCHIVE            :r=TRUE;break;
  781.     case ISARC_CLOSE_ARCHIVE        :r=TRUE;break;
  782.     case ISARC_FIND_FIRST            :r=TRUE;break;
  783.     case ISARC_FIND_NEXT            :r=TRUE;break;
  784.     case ISARC_EXTRACT                :r=FALSE;break;
  785.     case ISARC_ADD                    :r=FALSE;break;
  786.     case ISARC_MOVE                    :r=FALSE;break;
  787.     case ISARC_DELETE                :r=FALSE;break;
  788.  
  789.     case ISARC_GET_ARC_FILE_NAME    :r=TRUE;break;
  790.     case ISARC_GET_ARC_FILE_SIZE    :r=TRUE;break;
  791.     case ISARC_GET_ARC_ORIGINAL_SIZE    :r=TRUE;break;
  792.     case ISARC_GET_ARC_COMPRESSED_SIZE    :r=FALSE;break;
  793.     case ISARC_GET_ARC_RATIO            :r=FALSE;break;
  794.     case ISARC_GET_ARC_DATE                :r=TRUE;break;
  795.     case ISARC_GET_ARC_TIME                :r=TRUE;break;
  796.     case ISARC_GET_ARC_OS_TYPE            :r=FALSE;break;
  797.     case ISARC_GET_ARC_IS_SFX_FILE        :r=FALSE;break;
  798.     case ISARC_GET_FILE_NAME            :r=TRUE;break;
  799.     case ISARC_GET_ORIGINAL_SIZE        :r=TRUE;break;
  800.     case ISARC_GET_COMPRESSED_SIZE        :r=FALSE;break;
  801.     case ISARC_GET_RATIO                :r=FALSE;break;
  802.     case ISARC_GET_DATE                    :r=TRUE;break;
  803.     case ISARC_GET_TIME                    :r=TRUE;break;
  804.     case ISARC_GET_CRC                    :r=TRUE;break;
  805.     case ISARC_GET_ATTRIBUTE            :r=TRUE;break;
  806.     case ISARC_GET_OS_TYPE                :r=FALSE;break;
  807.     case ISARC_GET_METHOD                :r=FALSE;break;
  808.     case ISARC_GET_WRITE_TIME            :r=TRUE;break;
  809.     case ISARC_GET_CREATE_TIME            :r=TRUE;break;
  810.     case ISARC_GET_ACCESS_TIME            :r=TRUE;break;
  811.  
  812.     default:
  813.         r=FALSE;
  814.         break;
  815.     }
  816.     return r;
  817. }
  818.  
  819.  
  820. BOOL WINAPI _export TarSetOwnerWindow(const HWND _hwnd)
  821. {
  822.     OwnerWindow = _hwnd;
  823.     return TRUE;
  824. }
  825. BOOL WINAPI _export TarClearOwnerWindow(void)
  826. {
  827.     OwnerWindow = NULL;
  828.     return TRUE;
  829. }
  830. BOOL WINAPI _export TarSetOwnerWindowEx(HWND _hwnd,ARCHIVERPROC *_lpArcProc)
  831. {
  832.     OwnerWindow = _hwnd;
  833.     ArchiverProc = _lpArcProc;
  834.     return TRUE;
  835. }
  836. BOOL WINAPI _export TarKillOwnerWindowEx(HWND _hwnd)
  837. {
  838.     OwnerWindow = NULL;
  839.     ArchiverProc = NULL;
  840.     return TRUE;
  841. }
  842.  
  843. #endif /* DLL */
  844.  
  845. #ifdef __cplusplus
  846. }
  847. #endif
  848.