home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2003 August / VPR0308.ISO / OLS / ZIP3J037 / zip3j037.lzh / zip32j / SRC / ZIP32J / ZIP32J.C < prev    next >
C/C++ Source or Header  |  2000-12-16  |  18KB  |  665 lines

  1. /*
  2.     zip32j.c
  3.         by Yoshioka Tsuneo(QWF00133@niftyserve.or.jp)
  4.  
  5.   統合化アーカイバプロジェクト(仮称(?))に合わせた
  6.   ZIP圧縮ライブラリ
  7.  
  8.         by Yoshioka Tsuneo(QWF00133@niftyserve.or.jp)
  9.         welcome any e-mail!!
  10.         You can use this file as Public Domain Software.
  11.         Copy,Edit,Re-distibute and for any purpose,you can use this file.
  12.  
  13. */
  14. #include "resource.h"
  15. #include "zip32j.h"
  16. #include "cmdline.h"
  17. #include "zipapi.h"
  18. #include <windows.h>
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <mbstring.h>
  23.  
  24. static BOOL flagInProcess=0;
  25. static char *zip_output;
  26. static DWORD zip_output_size;
  27.  
  28. static char password[81];
  29. static int use_password;
  30. static char comment[32*1024];
  31. static char tempdir[MAX_PATH];
  32. static BOOL use_tempdir;
  33.  
  34. static HINSTANCE _hInst;
  35. static HWND parent_hwnd = NULL;
  36. static HWND status_hwnd = NULL;
  37. static ZPOPT22 *_ZpOptPtr;
  38. static int StatusDialogCancel;
  39. static char sfxdat[1000]="";
  40.  
  41. WORD WINAPI ZipGetVersion(VOID)
  42. {
  43.     WORD ver;
  44.     VS_FIXEDFILEINFO *verinfo;
  45.     HRSRC res;
  46.     HGLOBAL hres;
  47.     
  48.     res = FindResource(_hInst,VS_VERSION_INFO,RT_VERSION);
  49.     hres = LoadResource(_hInst,res);
  50.     verinfo = (VS_FIXEDFILEINFO *)((char *)LockResource(hres) + 40);
  51.     ver = (verinfo->dwFileVersionMS >> 16) * 100 + (verinfo->dwFileVersionMS & 0xffff);
  52.     return ver;
  53.     /* return ZIP_VERSION; */
  54. }
  55.  
  56. BOOL WINAPI ZipGetRunning(VOID)
  57. {
  58.     return flagInProcess;
  59. }
  60.  
  61. BOOL WINAPI ZipConfigDialog(const HWND _hwnd
  62.     , LPSTR _lpszComBuffer,const int _iMode)
  63. {
  64.     MessageBox(_hwnd,"ZIP32J","ZIP32J.DLL Configration",MB_OK);
  65.     return TRUE;
  66. }
  67.  
  68. static void doevents()
  69. {
  70.     MSG msg;
  71.     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
  72.     {
  73.         TranslateMessage(&msg);
  74.         DispatchMessage(&msg);
  75.     }
  76. }
  77.  
  78. static BOOL CALLBACK PrintDialogProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
  79. {
  80.     switch(message){
  81.     case WM_INITDIALOG:
  82.         return 1;
  83.     case WM_COMMAND:
  84.         switch(LOWORD(wParam)){
  85.         case IDCANCEL:
  86.             StatusDialogCancel = 1;
  87.             break;
  88.         }
  89.         break;
  90.     }
  91.     return 0;
  92. }
  93.  
  94. static int WINAPI DummyPrint(LPSTR buf, unsigned long size)
  95. {
  96.     unsigned long out_size;
  97.  
  98.     doevents();
  99.     if(_ZpOptPtr->fQuiet == 0){
  100.         char tmpbuf[1002];
  101.         int len;
  102.         char *ptr=tmpbuf;
  103.         char *bufptr = buf;
  104.         if(status_hwnd ==NULL){
  105.             StatusDialogCancel = 0;
  106.             status_hwnd = CreateDialog(_hInst,MAKEINTRESOURCE(IDD_DIALOG_STATUS),parent_hwnd,PrintDialogProc);
  107.             ShowWindow(status_hwnd,SW_SHOW);
  108.             SendDlgItemMessage(status_hwnd,IDC_EDIT_STATUS,EM_SETSEL,0,0);
  109.         }
  110.         //len = strlen(tmpbuf);
  111.         //if(len>1000){len=1000;}
  112.         len = size;
  113.         if(len>1000){len = 1000;}
  114.         while(len--){
  115.             if(*bufptr =='\n'){
  116.                 *ptr++='\r';
  117.                 *ptr++='\n';
  118.             }else if(*buf >= 32){
  119.                 *ptr++=*bufptr;
  120.             }
  121.             bufptr++;
  122.         }
  123.         *ptr='\0';
  124.         //strncpy(tmpbuf,buf,len);tmpbuf[len]='\0';
  125.         /*if(len>0 && tmpbuf[len-1] == '\n' && tmpbuf[len-2] != '\r'){
  126.             tmpbuf[len-1] = '\0';
  127.             tmpbuf[len] = '\n';
  128.             tmpbuf[len+1] = 'A';
  129.             tmpbuf[len+2] = '\0';
  130.         }*/
  131.         //SendDlgItemMessage(status_hwnd,IDC_EDIT_STATUS,EM_SETSEL,0,0);
  132.         SendDlgItemMessage(status_hwnd,IDC_EDIT_STATUS,EM_REPLACESEL,1,tmpbuf);
  133.         //SendDlgItemMessage(status_hwnd,IDC_EDIT_STATUS,EM_REPLACESEL,1,"\r\n");
  134.         //SetDlgItemText(status_hwnd,IDC_EDIT_STATUS,buf);        
  135.         UpdateWindow(status_hwnd);
  136.     }
  137.     /*
  138.         printf("ZIP32J.DLL:[%s]\n", buf);
  139.     */
  140.     if(zip_output==NULL){out_size=0; goto endlabel;}
  141.     if(zip_output_size==0){out_size=0;goto endlabel;}
  142.     if(zip_output_size > size){
  143.         out_size=size;
  144.     }else{
  145.         out_size=zip_output_size-1;
  146.     }
  147.     strncpy(zip_output,buf,out_size);
  148.     zip_output+=out_size;
  149.     *zip_output='\0';
  150.     zip_output_size-=out_size;
  151.     if(zip_output_size==1){zip_output_size=0;}
  152. endlabel:
  153.     return (unsigned int) out_size;
  154. }
  155.  
  156. static BOOL CALLBACK PasswordDialogProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
  157. {
  158.     char pass1[81],pass2[81];
  159.     switch(message){
  160.     case WM_COMMAND:
  161.         switch(LOWORD(wParam)){
  162.         case IDCANCEL:
  163.             EndDialog(hwnd,0);
  164.         case IDOK:
  165.             GetDlgItemText(hwnd,IDC_EDIT_PASS1,pass1,sizeof(pass1));
  166.             GetDlgItemText(hwnd,IDC_EDIT_PASS2,pass2,sizeof(pass2));
  167.             if(strcmp(pass1,pass2)==0){
  168.                 strcpy(password,pass1);
  169.                 EndDialog(hwnd,0);
  170.             }else{
  171.                 MessageBox(NULL,"Please Input the same password.","ZIP32J.DLL",0);
  172.                 SetDlgItemText(hwnd,IDC_EDIT_PASS1,"");
  173.                 SetDlgItemText(hwnd,IDC_EDIT_PASS2,"");
  174.             }
  175.         }
  176.     }
  177.     return 0;
  178. }
  179.  
  180. static void PasswordPrompt(void)
  181. {
  182.     DialogBox(_hInst,MAKEINTRESOURCE(IDD_DIALOG_PASSWORD),parent_hwnd,PasswordDialogProc);
  183. }
  184.  
  185. static int WINAPI DummyPassword(LPSTR p, int n, const LPSTR m, const LPSTR name)
  186. {
  187.     if(use_password){
  188.         if(password[0]=='\0'){
  189.             PasswordPrompt();
  190.         }
  191.         strcpy(p,password);
  192.         /* p[strlen(password)]='\0'; */
  193.         return 0;
  194.     }else{
  195.         return 1;
  196.     }
  197. }
  198.  
  199. static int WINAPI DummyService(LPCSTR filename, unsigned long size)
  200. {
  201. //    _RPTF2 (_CRT_WARN, "%s (%d)\n", filename, size);
  202.     return StatusDialogCancel;
  203. }
  204.  
  205. static BOOL CALLBACK CommentDialogProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
  206. {
  207.     switch(message){
  208.     case WM_INITDIALOG:
  209.         SetDlgItemText(hwnd,IDC_EDIT_COMMENT,comment);
  210.         break;
  211.     case WM_COMMAND:
  212.         switch(LOWORD(wParam)){
  213.         case IDCANCEL:
  214.             EndDialog(hwnd,FALSE);
  215.             return TRUE;
  216.         case IDOK:
  217.             GetDlgItemText(hwnd,IDC_EDIT_COMMENT,comment,sizeof(comment));
  218.             EndDialog(hwnd,TRUE);
  219.             return TRUE;
  220.         }
  221.         break;
  222.     }
  223.     return FALSE;
  224. }
  225.  
  226. static LPSTR WINAPI DummyComment(LPSTR buf)
  227. {
  228.     strcpy(comment,buf);
  229.     DialogBox(_hInst,MAKEINTRESOURCE(IDD_DIALOG_COMMENT),parent_hwnd,CommentDialogProc);
  230.     strcpy(buf,comment);
  231.     return buf;
  232. }
  233.  
  234. /*
  235.     コマンドライン(cmdline)を解析してオプション等(ZpOpt,ZpZCL)を設定
  236.     Zcl.FNV,Zcl.lpszZipFNはfreeする必要がある。
  237. */
  238. static int ParseCommandLine(ZPOPT22 *ZpOpt,ZCL *ZpZCL,char *cmdline)
  239. {
  240.     char **argv=NULL;
  241.     int argc;
  242.     char *arcname=NULL;
  243.     char **files=NULL;
  244.     int filenum=0;
  245.     char **files_clean=NULL;    
  246.     int i;
  247.     char *opt;
  248.     char *rootdir=NULL;
  249.     int return_code=-1;
  250.     char *p;
  251.  
  252.     memset(ZpOpt,'\0',sizeof(ZPOPT22));
  253.     ZpOpt->fLevel='6';
  254.     ZpOpt->fVerbose=TRUE;    // (^_^;
  255.  
  256.     use_password=0;
  257.     password[0]='\0';
  258.     sfxdat[0]='\0';
  259.  
  260.     if((argv=split_cmdline_with_response(cmdline))==NULL) goto endlabel;
  261.     argc=ptrarraylen(argv);
  262.     if((files=malloc(sizeof(char *)*(argc+1)))==NULL) goto endlabel;
  263.     if(argc<2) goto endlabel;
  264.     
  265.  
  266.     for(i=0;i<argc;i++){
  267.         if(*argv[i]=='-'){
  268.             opt=argv[i]+1;
  269.             if((strncmp(opt,"-sfx",4))==0){
  270.                 p=opt+4;
  271.                 if(*p=='\0'){
  272.                     strcpy(sfxdat,"sfx32gui.dat");
  273.                 }else if(*p=='='){
  274.                     strcpy(sfxdat,p+1);
  275.                 }else{
  276.                     goto endlabel;
  277.                 }
  278.                 continue;
  279.             }
  280.             while(*opt){
  281.                 switch(*opt){
  282.                 case 'b':
  283.                     use_tempdir=TRUE;
  284.                     i++;
  285.                     if(i>=argc){goto endlabel;}
  286.                     strcpy(tempdir,argv[i]);
  287.                     break;
  288.                 case 'e':
  289.                     ZpOpt->fEncrypt=1;
  290.                     use_password = 1;
  291.                     break;
  292.                 case 'P':
  293.                     ZpOpt -> fEncrypt = 1;
  294.                     i++;
  295.                     if(i>=argc){goto endlabel;}
  296.                     strcpy(password,argv[i]);
  297.                     use_password = 1;
  298.                     break;
  299.                 case 'S':ZpOpt->fSystem=1;break;
  300.                 case '$':ZpOpt->fVolume=TRUE;break;
  301.                 case 'X':ZpOpt->fExtra=TRUE;break;
  302.                 case 'D': ZpOpt->fNoDirEntries=TRUE; break;
  303.                 case 't':
  304.                     if (*(opt+1)=='t'){
  305.                         ZpOpt->fExcludeDate=1;
  306.                     }else if(*(opt+1)=='\0'){
  307.                         ZpOpt->fIncludeDate=1;
  308.                     }else{
  309.                         goto endlabel;
  310.                     }
  311.                     if(++i>=argc){goto endlabel;}
  312.                     strcpy(ZpOpt->Date,argv[i]);
  313.                     continue;
  314.                     break;
  315.                 case 'v':ZpOpt->fVerbose=TRUE;break;
  316.                 case 'q':ZpOpt->fQuiet=1;break;
  317.                 case 'l':
  318.                     if(*(opt+1)=='l'){
  319.                         ZpOpt->fCRLF_LF=1;
  320.                         opt++;
  321.                     }else{
  322.                         ZpOpt->fLF_CRLF=1;
  323.                     }
  324.                     break;
  325.                 case 'j': ZpOpt->fJunkDir=1; break;
  326.                 case 'g': ZpOpt->fGrow=1; break;
  327.                 case 'k': ZpOpt->fForce=TRUE;break;
  328.                 case 'm':ZpOpt->fMove=1;break;
  329.                 case 'd': ZpOpt->fDeleteEntries=TRUE; break;
  330.                 case 'u':ZpOpt->fUpdate=TRUE;break;
  331.                 case 'f': ZpOpt->fFreshen=TRUE; break;
  332.                 case 'J': ZpOpt->fJunkSFX=1;break;
  333.                 case 'o':ZpOpt->fLatestTime=1;break;
  334.                 case 'z':ZpOpt->fComment=1;break;
  335.                 case 'A': ZpOpt->fOffsets=TRUE; break;
  336.                 case '!':ZpOpt->fPrivilege=TRUE;break;
  337.                 case 'r':
  338.                     ZpOpt->fRecurse=TRUE;
  339.                     break;
  340.                 case 'R':ZpOpt->fRecurse=2;break;
  341.                 case 'F': 
  342.                     if(*(opt+1)=='F'){
  343.                         ZpOpt->fRepair=2;
  344.                         opt++;
  345.                     }else{
  346.                         ZpOpt->fRepair=1;
  347.                     }
  348.                     break;
  349.                 default:
  350.                     if(isdigit(*opt)){
  351.                         ZpOpt->fLevel=*opt;
  352.                     }else{
  353.                     goto endlabel;
  354.                     }
  355.                     break;
  356.                 }
  357.                 opt++;
  358.             }
  359.             continue;
  360.         }else{
  361.             if(arcname==NULL){
  362.                 if((arcname=strdup(argv[i]))==NULL) goto endlabel;
  363.             }else if(rootdir==NULL  && *argv[i]!='\0' 
  364.                 /* && *(argv[i]+strlen(argv[i])-1)=='\\'){ */
  365.                 && ((_mbsrchr(argv[i],'\\')==argv[i]+strlen(argv[i])-1)
  366.                     ||(_mbsrchr(argv[i],'/')==argv[i]+strlen(argv[i])-1))
  367.                 ){
  368.                 if( (rootdir=strdup(argv[i]))==NULL  )goto endlabel;
  369.             }else{
  370.                 if(realloc2(&files,sizeof(char*)*(filenum+1))==NULL){
  371.                     goto endlabel;
  372.                 }
  373.                 if((files[filenum]=strdup(argv[i]))==NULL)goto endlabel;
  374.                 filenum++;
  375.             }
  376.         }
  377.     }
  378.     if(realloc2(&files,sizeof(char*)*(filenum+1))==NULL){
  379.         goto endlabel;
  380.     }
  381.     files[filenum]=NULL;
  382.     if((files_clean=strarraydup(files))==NULL) goto endlabel;
  383.     if(rootdir!=NULL && *rootdir != '\0'){
  384.         if(rootdir[strlen(rootdir)-1]=='\\'){
  385.             rootdir[strlen(rootdir)-1]='\0';
  386.         }
  387.         strcpy(ZpOpt->szRootDir,rootdir);
  388.     }
  389.     ZpZCL->argc=filenum;
  390.     ZpZCL->lpszZipFN=arcname;
  391.     ZpZCL->FNV=files_clean;
  392.     return_code=0;
  393. endlabel:
  394.     if(files_clean==NULL && arcname!=NULL){free(arcname);arcname=NULL;}
  395.     if(files!=NULL){free(files);files=NULL;}
  396.     if(rootdir!=NULL){free(rootdir);rootdir=NULL;}
  397.     if(argv!=NULL){free(argv);argv=NULL;}
  398.     return return_code;
  399. }
  400.  
  401. static void ZPOPT22TO23(ZPOPT22 *ZpOpt22,ZPOPT23 *ZpOpt23)
  402. {
  403.     memset(ZpOpt23,0,sizeof(*ZpOpt23));
  404. /* struct for zip2.3 */
  405.     ZpOpt23->Date=ZpOpt22->Date;               /* Date to include after */
  406.     ZpOpt23->szRootDir=ZpOpt22->szRootDir;          /* Directory to use as base for zipping */
  407.     ZpOpt23->fSuffix = ZpOpt22->fSuffix;             /* include suffixes (not implemented) */
  408.     ZpOpt23->fEncrypt = ZpOpt22->fEncrypt;            /* encrypt files */
  409.     ZpOpt23->fSystem = ZpOpt22->fSystem;             /* include system and hidden files */
  410.     ZpOpt23->fVolume = ZpOpt22->fVolume;             /* Include volume label */
  411.     ZpOpt23->fExtra = ZpOpt22->fExtra;              /* Include extra attributes */
  412.     ZpOpt23->fNoDirEntries = ZpOpt22->fNoDirEntries;       /* Do not add directory entries */
  413.     ZpOpt23->fExcludeDate = ZpOpt22->fExcludeDate;        /* Exclude files earlier than specified date */
  414.     ZpOpt23->fIncludeDate = ZpOpt22->fIncludeDate;        /* Include only files earlier than specified date */
  415.     ZpOpt23->fVerbose = ZpOpt22->fVerbose;            /* Mention oddities in zip file structure */
  416.     ZpOpt23->fQuiet = ZpOpt22->fQuiet;              /* Quiet operation */
  417.     ZpOpt23->fCRLF_LF = ZpOpt22->fCRLF_LF;            /* Translate CR/LF to LF */
  418.     ZpOpt23->fLF_CRLF = ZpOpt22->fLF_CRLF;            /* Translate LF to CR/LF */
  419.     ZpOpt23->fJunkDir = ZpOpt22->fJunkDir;            /* Junk directory names */
  420.     ZpOpt23->fGrow = ZpOpt22->fGrow;               /* Allow appending to a zip file */
  421.     ZpOpt23->fForce = ZpOpt22->fForce;              /* Make entries using DOS names (k for Katz) */
  422.     ZpOpt23->fMove = ZpOpt22->fMove;               /* Delete files added or updated in zip file */
  423.     ZpOpt23->fDeleteEntries = ZpOpt22->fDeleteEntries;      /* Delete files from zip file */
  424.     ZpOpt23->fUpdate = ZpOpt22->fUpdate;             /* Update zip file--overwrite only if newer */
  425.     ZpOpt23->fFreshen = ZpOpt22->fFreshen;            /* Freshen zip file--overwrite only */
  426.     ZpOpt23->fJunkSFX = ZpOpt22->fJunkSFX;            /* Junk SFX prefix */
  427.     ZpOpt23->fLatestTime = ZpOpt22->fLatestTime;         /* Set zip file time to time of latest file in it */
  428.     ZpOpt23->fComment = ZpOpt22->fComment;            /* Put comment in zip file */
  429.     ZpOpt23->fOffsets = ZpOpt22->fOffsets;            /* Update archive offsets for SFX files */
  430.     ZpOpt23->fPrivilege = ZpOpt22->fPrivilege;          /* Use privileges (WIN32 only) */
  431.     ZpOpt23->fEncryption = ZpOpt22->fEncryption;         /* TRUE if encryption supported, else FALSE.this is a read only flag */
  432.     ZpOpt23->fRecurse = ZpOpt22->fRecurse;            /* Recurse into subdirectories. 1 => -R, 2 => -r */
  433. #if 0    // zip23 beta
  434.     if(ZpOpt22->fRecurse==2)ZpOpt23->fRecurse=1;}else if(ZpOpt22->fRecurse==1){ZpOpt23->fRecurse=2;}
  435. #else   // zip23 release
  436.     ZpOpt23->fRecurse = ZpOpt22->fRecurse;
  437.     ZpOpt23->szTempDir = tempdir;
  438.     ZpOpt23->fTemp = use_tempdir;
  439. #endif
  440.     ZpOpt23->fRepair = ZpOpt22->fRepair;             /* Repair archive. 1 => -F, 2 => -FF */
  441.     ZpOpt23->fLevel = ZpOpt22->fLevel;              /* Compression level (0 - 9) */
  442. }
  443.  
  444. static int ZpMakeSFX(const HWND hwnd,char *_sfxdat,char *arcname,ZPOPT22 *ZpOpt)
  445. {
  446.     char sfxname[1000]="";
  447.     FILE *sfxdatfp;
  448.     FILE *sfxexefp;
  449.     FILE *arcfp;
  450.     char sfxdat[1000]="";
  451.     char buf[1024];
  452.     int n,n2;
  453.  
  454. #if 0
  455.     if(!(_sfxdat[1]==':' && _sfxdat[2]=='\\')){
  456.         GetSystemDirectory(sfxdat,200);
  457.         strcat(sfxdat,"\\");
  458.     }
  459.     strcat(sfxdat,_sfxdat);
  460. #else
  461.     if(!(_sfxdat[1]==':' && _sfxdat[2]=='\\')){
  462.         char *filepart=NULL;
  463.         char path[MAX_PATH];
  464.         DWORD ret = SearchPath(NULL,_sfxdat,NULL,sizeof(path),path,filepart);
  465.         if(ret!=0 && ret<sizeof(path)){
  466.             strcpy(sfxdat,path);
  467.         }
  468.         // GetSystemDirectory(sfxdat,200);
  469.         // strcat(sfxdat,"\\");
  470.     }
  471.     if(sfxdat[0]=='\0'){
  472.         strcpy(sfxdat,_sfxdat);
  473.     }
  474. #endif
  475.     if(!(strlen(arcname)>=4 && stricmp(arcname+strlen(arcname)-4,".ZIP")==0)){
  476.         sprintf(buf,"File Extension is not '.ZIP'. File=[%s]",arcname);
  477.         MessageBox(hwnd,buf,"ZIP32J",0);
  478.         return -1;
  479.     }
  480.     strcpy(sfxname,arcname);
  481.     strcpy(sfxname+strlen(sfxname)-4,".EXE");
  482.     if((sfxdatfp=fopen(sfxdat,"rb"))==NULL){
  483.         sprintf(buf,"Can't open sfx data file[%s]",sfxdat);
  484.         MessageBox(hwnd,buf,"ZIP32J",0);
  485.         return -1;
  486.     }
  487.     if((sfxexefp=fopen(sfxname,"wb"))==NULL){
  488.         sprintf(buf,"Can't open sfx file[%s]",sfxname);
  489.         MessageBox(hwnd,buf,"ZIP32J",0);
  490.         fclose(sfxdatfp);
  491.         return -1;
  492.     }
  493.     while((n=fread(buf,1,1024,sfxdatfp))>0){
  494.         n2 = fwrite(buf,1,n,sfxexefp);
  495.         if(n!=n2){
  496.             MessageBox(hwnd,"Write Error","ZIP32J",0);
  497.             fclose(sfxdatfp);
  498.             fclose(sfxexefp);
  499.             return -1;
  500.         }
  501.     }
  502.     fclose(sfxdatfp);
  503.     if((arcfp=fopen(arcname,"rb"))==NULL){
  504.         sprintf(buf,"Can't open archive file[%s]",arcname);
  505.         MessageBox(hwnd,buf,"ZIP32J",0);
  506.         fclose(sfxexefp);
  507.         return -1;
  508.     }
  509.     while((n=fread(buf,1,1024,arcfp))>0){
  510.         n2 = fwrite(buf,1,n,sfxexefp);
  511.         if(n!=n2){
  512.             MessageBox(hwnd,"Write Error","ZIP32J",0);
  513.             fclose(arcfp);
  514.             fclose(sfxexefp);
  515.             return -1;
  516.         }
  517.     }
  518.     fclose(arcfp);
  519.     fclose(sfxexefp);
  520.     unlink(arcname);
  521.     strcpy(arcname,sfxname);
  522.     ZpOpt->fOffsets = 1;
  523.     return 0;
  524. }
  525.  
  526. /*
  527.     Zipをコマンドライン形式で呼び出す
  528. */
  529. int WINAPI Zip(const HWND _hwnd,LPCSTR _szCmdLine,LPSTR _szOutput,const DWORD _dwSize)
  530. {
  531.     ZIPUSERFUNCTIONS ZipUserFunctions;
  532.     ZPOPT22 ZpOpt;
  533.     ZCL Zcl;
  534.     int ret;
  535.     int zip_return_code=1;
  536.  
  537.     flagInProcess++;
  538.     parent_hwnd = _hwnd;
  539.     /* ZpInit=NULL;ZpArchive=NULL;*/
  540.     Zcl.FNV=NULL;Zcl.lpszZipFN=NULL;
  541.     zip_output=_szOutput; zip_output_size=_dwSize;
  542.     _ZpOptPtr = &ZpOpt;
  543.  
  544. #ifndef NODLL_TEST
  545.     if(ZIP32DLLLoadLibrary()==-1){return -1;}
  546. #endif
  547.     ZipUserFunctions.print=DummyPrint;
  548.     ZipUserFunctions.password=DummyPassword;
  549.     ZipUserFunctions.comment=DummyComment;
  550.     ZipUserFunctions.ServiceApplication = DummyService;
  551.     if(ZpInit!=NULL){
  552.         ret=(*ZpInit)(&ZipUserFunctions);
  553.         if(ret==0){ goto endlabel;}
  554.     }
  555.     ret=ParseCommandLine(&ZpOpt,&Zcl,(char *)_szCmdLine);
  556.     if(ret==-1){
  557.         goto endlabel;
  558.     }
  559.     if(sfxdat[0]!='\0'){
  560.         ret = ZpMakeSFX(parent_hwnd,sfxdat,Zcl.lpszZipFN,&ZpOpt);
  561.         if(ret!=0)goto endlabel;
  562.     }
  563.     if(ZpSetOptions22!=NULL || ZpSetOptions23!=NULL){
  564.         if(ZIP32DLLVersion()>= (2<<8)+3){
  565.             ZPOPT23 ZpOpt23;
  566.             ZPOPT22TO23(&ZpOpt,&ZpOpt23);
  567.             ret=(*ZpSetOptions23)(&ZpOpt23);
  568.         }else{
  569.             ret=(*ZpSetOptions22)(ZpOpt);
  570.         }
  571.     }
  572.     if(ZpArchive!=NULL){
  573.         ret=(*ZpArchive)(Zcl);
  574.         if(ret!=0){goto endlabel;}
  575.     }
  576.     zip_return_code=1;
  577.  
  578. endlabel:
  579.     if(status_hwnd){
  580.         /* EndDialog(status_hwnd,0);*/
  581.         DestroyWindow(status_hwnd);
  582.         status_hwnd=NULL;
  583.     }
  584.     if(Zcl.FNV!=NULL)free(Zcl.FNV);
  585.     if(Zcl.lpszZipFN!=NULL)free(Zcl.lpszZipFN);    
  586.     parent_hwnd = NULL;
  587.     flagInProcess--;
  588.     return ret;
  589. }
  590.  
  591. /*
  592.     現在利用できる関数ならTrue
  593. */
  594. BOOL WINAPI ZipQueryFunctionList(const int _iFunction)
  595. {
  596.     int r;
  597.     switch( _iFunction){
  598.     case ISARC                        :r=TRUE;break;
  599.     case ISARC_GET_VERSION            :r=TRUE;break;
  600.     case ISARC_GET_RUNNING            :r=TRUE;break;
  601.  
  602.     case ISARC_CONFIG_DIALOG        :r=TRUE;break;
  603.     case ISARC_QUERY_FUNCTION_LIST    :r=TRUE;break;
  604.  
  605.     default:
  606.         r=FALSE;
  607.         break;
  608.     }
  609.     return r;
  610. }
  611.  
  612. /*
  613.     暗号化をサポートしていたらTrue
  614. */
  615. BOOL WINAPI ZipQueryEncryption(VOID)
  616. {
  617.     if (ZIP32DLLLoadLibrary() == -1)
  618.     {
  619.         return FALSE;
  620.     }
  621.     if (strcmp(ZIP32DLLLibName(), "IZIP32J.DLL") == 0)
  622.     {
  623.         char dat[MAX_PATH];
  624.         return SearchPath(NULL, "ZCRYPT32.DLL", NULL, sizeof(dat), dat, NULL);
  625.     }
  626.     if (ZpGetOptions22 != NULL || ZpGetOptions23 != NULL)
  627.     {
  628.         if (ZIP32DLLVersion() >= (2<<8)+3)
  629.         {
  630.             ZPOPT23 ZpOpt23 = (*ZpGetOptions23)();
  631.             return ZpOpt23.fEncryption;
  632.         }
  633.         else
  634.         {
  635.             ZPOPT22 ZpOpt22 = (*ZpGetOptions22)();
  636.             return ZpOpt22.fEncryption;
  637.         }
  638.     }
  639.     return FALSE;
  640. }
  641.  
  642. #include "findzip.h"
  643. /*
  644.     DLLのメイン関数、、だけど今のところ何も使ってない。
  645. */
  646. BOOL APIENTRY DllMain( HANDLE hModule, 
  647.                         DWORD ul_reason_for_call, 
  648.                         LPVOID lpReserved )
  649. {
  650.     _hInst = hModule;
  651.     switch( ul_reason_for_call) {
  652.     case DLL_PROCESS_ATTACH:
  653.     break;
  654.     case DLL_THREAD_ATTACH:
  655.     break;
  656.     case DLL_THREAD_DETACH:
  657.     break;
  658.     case DLL_PROCESS_DETACH:
  659.         finddll_end();
  660.         ZIP32DLLFreeLibrary();
  661.     break;
  662.     }
  663.     return TRUE;
  664. }
  665.