Пример #1
0
BOOL My_LZCopy()
{
	INT hfSource=NULL;
	INT hfDest=NULL;
	
	DWORD error_Real = 0;
	DWORD error_Intercepted = 0;
	disableInterception();
	LZCopy (hfSource,hfDest);
	error_Real = GetLastError();
	enableInterception();
	LZCopy (hfSource,hfDest);
	error_Intercepted = GetLastError();
	return (error_Real == error_Intercepted);
}
Пример #2
0
int main(int argc, char *argv[])
{
  OFSTRUCT SourceOpenStruct1, SourceOpenStruct2;
  LONG ret;
  HFILE hSourceFile, hDestFile;

  if (argc < 2)
  {
      fprintf( stderr, "Usage: %s infile [outfile]\n", argv[0] );
      return 1;
  }
  hSourceFile = LZOpenFile(argv[1], &SourceOpenStruct1, OF_READ);
  if (argv[2])
      hDestFile = LZOpenFile(argv[2], &SourceOpenStruct2, OF_CREATE | OF_WRITE);
  else
  {
      char OriginalName[MAX_PATH];
      GetExpandedName(argv[1], OriginalName);
      hDestFile = LZOpenFile(OriginalName, &SourceOpenStruct2, OF_CREATE | OF_WRITE);
  }
  ret = LZCopy(hSourceFile, hDestFile);
  LZClose(hSourceFile);
  LZClose(hDestFile);
  if (ret <= 0) fprintf(stderr,"LZCopy failed: return is %ld\n",ret);
  return (ret <= 0);
}
Пример #3
0
static DWORD decompress_file_lz( LPCWSTR source, LPCWSTR target )
{
    DWORD ret;
    LONG error;
    INT src, dst;
    OFSTRUCT sof, dof;

    if ((src = LZOpenFileW( (LPWSTR)source, &sof, OF_READ )) < 0)
    {
        ERR("cannot open source file for reading\n");
        return ERROR_FILE_NOT_FOUND;
    }
    if ((dst = LZOpenFileW( (LPWSTR)target, &dof, OF_CREATE )) < 0)
    {
        ERR("cannot open target file for writing\n");
        LZClose( src );
        return ERROR_FILE_NOT_FOUND;
    }
    if ((error = LZCopy( src, dst )) >= 0) ret = ERROR_SUCCESS;
    else
    {
        WARN("failed to decompress file %d\n", error);
        ret = ERROR_INVALID_DATA;
    }

    LZClose( src );
    LZClose( dst );
    return ret;
}
Пример #4
0
/***********************************************************************
 *           LZCopy   (LZEXPAND.1)
 *
 */
LONG WINAPI LZCopy16( HFILE16 src, HFILE16 dest )
{
    /* already a LZ handle? */
    if (IS_LZ_HANDLE(src)) return LZCopy( src, (HFILE)DosFileHandleToWin32Handle(dest) );

    /* no, try to open one */
    src = LZInit16(src);
    if ((INT16)src <= 0) return 0;
    if (IS_LZ_HANDLE(src))
    {
        LONG ret = LZCopy( src, (HFILE)DosFileHandleToWin32Handle(dest) );
        LZClose( src );
        return ret;
    }
    /* it was not a compressed file */
    return LZCopy( (HFILE)DosFileHandleToWin32Handle(src), (HFILE)DosFileHandleToWin32Handle(dest) );
}
Пример #5
0
// @pymethod int|win32lz|Copy|Copies a source file to a destination file.
static PyObject *
PyLZCopy(PyObject *self, PyObject *args)
{
	int hSrc, hDest;
	if (!PyArg_ParseTuple(args, "ii:Copy", &hSrc, &hDest )) 
		// @pyparm int|hSrc||The handle of the source file to copy.
		// @pyparm int|hDest||The handle of the destination file.
		return NULL;
	// @comm If the source file is compressed with the Microsoft File Compression Utility
	// (COMPRESS.EXE), this function creates a decompressed destination file.
	// If the source file is not compressed, this function duplicates the original file. 
	// @pyseeapi LZCopy
	long ret = LZCopy( hSrc, hDest);
	if (ret < 0)
		return ReturnLZError("LZCopy",ret);
	return PyInt_FromLong(ret);
}
Пример #6
0
int main(int argc, char *argv[])
{
    int ret = 0;
    char infile[MAX_PATH], outfile[MAX_PATH], actual_name[MAX_PATH];
    char outfile_basename[MAX_PATH], *basename_index;
    UINT comp;

    if (argc < 3)
    {
        myprintf( "Usage:\n" );
        myprintf( "\t%s infile outfile\n", argv[0] );
        myprintf( "\t%s /r infile\n", argv[0] );
        return 1;
    }

    if (argc == 3 && (option_equal(argv[1], "R") || option_equal(argv[1], "r")))
        GetFullPathNameA( argv[2], sizeof(infile), infile, NULL );
    else
        GetFullPathNameA( argv[1], sizeof(infile), infile, NULL );

    if (!SetupGetFileCompressionInfoExA( infile, actual_name, sizeof(actual_name), NULL, NULL, NULL, &comp ))
    {
        myprintf( "%s: can't open input file %s\n", argv[0], infile );
        return 1;
    }

    if (argc == 3 && (option_equal(argv[1], "R") || option_equal(argv[1], "r")))
    {
        switch (comp)
        {
        case FILE_COMPRESSION_MSZIP:
            outfile_basename[0] = 0;
            if (!SetupIterateCabinetA( infile, 0, set_outfile, outfile_basename ))
            {
                myprintf( "%s: can't determine original name\n", argv[0] );
                return 1;
            }
            GetFullPathNameA( infile, sizeof(outfile), outfile, &basename_index );
            *basename_index = 0;
            strcat( outfile, outfile_basename );
            break;
        case FILE_COMPRESSION_WINLZA:
            GetExpandedNameA( infile, outfile_basename );
            break;
        default:
            myprintf( "%s: can't determine original\n", argv[0] );
            return 1;
        }
    }
    else
        GetFullPathNameA( argv[2], sizeof(outfile), outfile, NULL );

    if (!lstrcmpiA( infile, outfile ))
    {
        myprintf( "%s: can't expand file to itself\n", argv[0] );
        return 1;
    }

    switch (comp)
    {
    case FILE_COMPRESSION_MSZIP:
        if (!SetupIterateCabinetA( infile, 0, extract_callback, outfile ))
        {
            myprintf( "%s: cabinet extraction failed\n", argv[0] );
            return 1;
        }
        break;
    case FILE_COMPRESSION_WINLZA:
    {
        INT hin, hout;
        OFSTRUCT ofin, ofout;
        LONG error;

        if ((hin = LZOpenFileA( infile, &ofin, OF_READ )) < 0)
        {
            myprintf( "%s: can't open input file %s\n", argv[0], infile );
            return 1;
        }
        if ((hout = LZOpenFileA( outfile, &ofout, OF_CREATE | OF_WRITE )) < 0)
        {
            LZClose( hin );
            myprintf( "%s: can't open output file %s\n", argv[0], outfile );
            return 1;
        }
        error = LZCopy( hin, hout );

        LZClose( hin );
        LZClose( hout );

        if (error < 0)
        {
            myprintf( "%s: LZCopy failed, error is %d\n", argv[0], error );
            return 1;
        }
        break;
    }
    default:
        if (!CopyFileA( infile, outfile, FALSE ))
        {
            myprintf( "%s: CopyFileA failed\n", argv[0] );
            return 1;
        }
        break;
    }
    return ret;
}