home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 2000 March
/
VPR0003A.BIN
/
OLS
/
UNRAR32005
/
unrar32005.lzh
/
src
/
unrarapi.cxx
< prev
next >
Wrap
C/C++ Source or Header
|
1998-04-03
|
4KB
|
147 lines
/*
* Copyright (c) 1998 T. Kamei (kamei@jsdlab.co.jp)
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for any purpose is hereby granted provided
* that the above copyright notice and this permission notice appear
* in all copies of the software and related documentation.
*
* NO WARRANTY
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY WARRANTIES;
* WITHOUT EVEN THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS
* FOR A PARTICULAR PURPOSE.
*/
#include <windows.h>
#include <stdio.h>
#include "comm-arc.h"
#include "unrarapi.h"
HINSTANCE
load_rarapi ()
{
HINSTANCE h = LoadLibrary ("unrar.dll");
if (!h)
return 0;
if ((rarOpenArchive = (HANDLE (__stdcall *)(RAROpenArchiveData *))
GetProcAddress (h, "RAROpenArchive"))
&& (rarCloseArchive = (int (__stdcall *)(HANDLE))
GetProcAddress (h, "RARCloseArchive"))
&& (rarReadHeader = (int (__stdcall *)(HANDLE, RARHeaderData *))
GetProcAddress (h, "RARReadHeader"))
&& (rarProcessFile = (int (__stdcall *)(HANDLE, int, char *, char *))
GetProcAddress (h, "RARProcessFile"))
&& (rarSetChangeVolProc = (void (__stdcall *)(HANDLE, int (__cdecl *)(char *, int)))
GetProcAddress (h, "RARSetChangeVolProc"))
&& (rarSetProcessDataProc = (void (__stdcall *)(HANDLE, int (__cdecl *)(unsigned char *, int)))
GetProcAddress (h, "RARSetProcessDataProc"))
&& (rarSetPassword = (void (__stdcall *)(HANDLE, const char *))
GetProcAddress (h, "RARSetPassword")))
return h;
FreeLibrary (h);
return 0;
}
int
rarData::open (const char *path, int mode, char *buf, int size)
{
oad.ArcName = (char *)path;
oad.CmtBuf = buf;
oad.CmtBufSize = size;
oad.OpenMode = mode;
hd.CmtBuf = 0;
hd.CmtBufSize = 0;
h = rarOpenArchive (&oad);
return int (h);
}
int
rarData::close ()
{
if (!h)
return 0;
int x = rarCloseArchive (h);
h = 0;
return x;
}
int
file_executable_p (const char *path)
{
int f = 0;
FILE *fp = fopen (path, "rb");
if (fp)
{
IMAGE_DOS_HEADER dos;
IMAGE_NT_HEADERS nt;
f = (fread (&dos, sizeof dos, 1, fp) == 1
&& dos.e_magic == IMAGE_DOS_SIGNATURE
&& !fseek (fp, dos.e_lfanew, SEEK_SET)
&& fread (&nt, sizeof nt, 1, fp) == 1
&& nt.Signature == IMAGE_NT_SIGNATURE);
fclose (fp);
}
return f;
}
int
calc_ratio (u_long comp_sz, u_long orig_sz)
{
return orig_sz ? int (double (comp_sz) / orig_sz * 1000) : 0;
}
const char *
method_string (int method)
{
switch (method)
{
case 0x30:
return "storing";
case 0x31:
return "fastest";
case 0x32:
return "fast";
case 0x33:
return "normal";
case 0x34:
return "good";
case 0x35:
return "best";
default:
return "unknown";
}
}
int
os_type (int os)
{
switch (os)
{
case 0:
return OSTYPE_MSDOS;
case 1:
return OSTYPE_OS2;
case 2:
return OSTYPE_WINDOWS95; // Win32
case 3:
return OSTYPE_UNIX;
default:
return OSTYPE_UNKNOWN;
}
}
const char *
attr_string (int attr)
{
static char b[5];
b[0] = (attr & FILE_ATTRIBUTE_DIRECTORY
? 'd'
: (attr & FILE_ATTRIBUTE_ARCHIVE
? 'a' : '-'));
b[1] = attr & FILE_ATTRIBUTE_SYSTEM ? 's' : '-';
b[2] = attr & FILE_ATTRIBUTE_HIDDEN ? 'h' : '-';
b[3] = attr & FILE_ATTRIBUTE_READONLY ? '-' : 'w';
return b;
}