home *** CD-ROM | disk | FTP | other *** search
/ napalm.napnet.hu / 2015-02-12.napalm.napnet.hu.tar / napalm.napnet.hu / programok / kommunikacio / mpp700.exe / nGZIPn.cpp < prev    next >
C/C++ Source or Header  |  2001-01-30  |  2KB  |  84 lines

  1. //----------------------------------------------------------------------------
  2. // nGZIPn.dll - compression engine for mIRC
  3. // 01.02.2001 (c) Necroman - necroman@europe.com, irc://irc.undernet.org/mIRC
  4. //----------------------------------------------------------------------------
  5.  
  6. #define WIN32_LEAN_AND_MEAN
  7. #include <windows.h>
  8. #include <stdio.h>
  9. #include "zlib\\zlib.h"
  10.  
  11. #define BUFSIZE 0x80000
  12.  
  13. extern "C"
  14. {
  15.     //----------------------------------------------------------------------------
  16.     int __stdcall zip(HWND mWnd, HWND aWnd, char *data, char *parms, BOOL show, BOOL nopause)
  17.     {
  18.         const char *result = "$false";
  19.         
  20.         //open source (decompressed) file
  21.         FILE *src_file;
  22.         if (src_file = fopen(data,"rb"))
  23.         {
  24.             //open destionation (compressed) file
  25.             gzFile dest_file;
  26.             if (dest_file = gzopen(strcat(data,".gz"),"wb9"))
  27.             {
  28.                 //compress data
  29.                 char buf[BUFSIZE];
  30.                 do
  31.                 {
  32.                     int bytes = fread(buf,1,BUFSIZE,src_file);
  33.                     if (!gzwrite(dest_file,buf,bytes)) break;
  34.                     if (feof(src_file)) result = "$true";
  35.                     if (bytes != BUFSIZE) break;
  36.                 } while (true);
  37.                 gzclose(dest_file);
  38.             }
  39.             fclose(src_file);
  40.         }
  41.         strcpy(data,result);
  42.         return 3;
  43.     }
  44.     
  45.     //----------------------------------------------------------------------------
  46.     int __stdcall unzip(HWND mWnd, HWND aWnd, char *data, char *parms, BOOL show, BOOL nopause)
  47.     {
  48.         const char *result = "$false";
  49.         
  50.         //open source (compressed) file
  51.         gzFile src_file;
  52.         if (src_file = gzopen(strcat(strcpy(parms,data),".gz"),"rb"))
  53.         {
  54.             //open destination (uncompressed) file
  55.             FILE *dest_file;
  56.             if (dest_file = fopen(data,"wb"))
  57.             {
  58.                 //decompress data
  59.                 char buf[BUFSIZE];
  60.                 do
  61.                 {
  62.                     int bytes = gzread(src_file,buf,BUFSIZE);
  63.                     if (!bytes) result = "$true";
  64.                     if (bytes < 1) break;
  65.                     if ((DWORD)bytes != fwrite(buf,1,bytes,dest_file)) break;
  66.                 } while (true);
  67.                 fclose(dest_file);
  68.             }
  69.             gzclose(src_file);
  70.         }
  71.         strcpy(data,result);
  72.         return 3;
  73.     }
  74.  
  75.     //----------------------------------------------------------------------------
  76.     int __stdcall version(HWND mWnd, HWND aWnd, char *data, char *parms, BOOL show, BOOL nopause)
  77.     {
  78.         strcpy(data,"nGZIPn 1.0 - (c) 2001 Necroman - necroman@europe.com, #mIRC @ Undernet");
  79.         return 3;
  80.     }
  81.     
  82.     //----------------------------------------------------------------------------
  83.     void __stdcall LoadDll(PVOID) {}
  84. }