2018-04-11 11:30:53 +00:00
|
|
|
/*
|
2003-08-28 19:34:10 +00:00
|
|
|
* LZ Decompression functions
|
|
|
|
*
|
|
|
|
* Copyright 1996 Marcus Meissner
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2009-06-07 14:10:13 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
*
|
|
|
|
* The LZ (Lempel Ziv) decompression was used in win16 installation programs.
|
|
|
|
* It is a simple tabledriven decompression engine, the algorithm is not
|
|
|
|
* documented as far as I know. WINE does not contain a compressor for
|
|
|
|
* this format.
|
|
|
|
*
|
|
|
|
* The implementation is complete and there have been no reports of failures
|
|
|
|
* for some time.
|
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
*
|
|
|
|
* o Check whether the return values are correct
|
|
|
|
*
|
2003-08-28 19:34:10 +00:00
|
|
|
*/
|
|
|
|
|
2018-04-11 11:30:53 +00:00
|
|
|
#ifdef __REACTOS__
|
|
|
|
|
2013-12-22 18:10:41 +00:00
|
|
|
#include <k32.h>
|
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
DEBUG_CHANNEL(kernel32file);
|
|
|
|
|
|
|
|
#define HFILE_ERROR ((HFILE)-1)
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
|
2003-08-28 19:34:10 +00:00
|
|
|
#include "lzexpand.h"
|
2005-06-17 08:02:05 +00:00
|
|
|
|
2011-07-21 17:21:43 +00:00
|
|
|
#define _lwrite(a, b, c) (long)(_hwrite(a, b, (long)c))
|
2013-12-22 18:10:41 +00:00
|
|
|
|
2018-04-11 11:30:53 +00:00
|
|
|
#else /* __REACTOS__ */
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "lzexpand.h"
|
|
|
|
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(file);
|
|
|
|
|
|
|
|
#endif /* __REACTOS__ */
|
|
|
|
|
2003-08-28 19:34:10 +00:00
|
|
|
/* The readahead length of the decompressor. Reading single bytes
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
* using _lread() would be SLOW.
|
2003-08-28 19:34:10 +00:00
|
|
|
*/
|
|
|
|
#define GETLEN 2048
|
|
|
|
|
2009-06-07 14:10:13 +00:00
|
|
|
#define LZ_MAGIC_LEN 8
|
|
|
|
#define LZ_HEADER_LEN 14
|
|
|
|
|
2003-08-28 19:34:10 +00:00
|
|
|
/* Format of first 14 byte of LZ compressed file */
|
|
|
|
struct lzfileheader {
|
2009-06-07 14:10:13 +00:00
|
|
|
BYTE magic[LZ_MAGIC_LEN];
|
2003-08-28 19:34:10 +00:00
|
|
|
BYTE compressiontype;
|
|
|
|
CHAR lastchar;
|
|
|
|
DWORD reallength;
|
|
|
|
};
|
2009-06-07 14:10:13 +00:00
|
|
|
static const BYTE LZMagic[LZ_MAGIC_LEN]={'S','Z','D','D',0x88,0xf0,0x27,0x33};
|
|
|
|
|
|
|
|
#define LZ_TABLE_SIZE 0x1000
|
2003-08-28 19:34:10 +00:00
|
|
|
|
|
|
|
struct lzstate {
|
|
|
|
HFILE realfd; /* the real filedescriptor */
|
|
|
|
CHAR lastchar; /* the last char of the filename */
|
|
|
|
|
|
|
|
DWORD reallength; /* the decompressed length of the file */
|
|
|
|
DWORD realcurrent; /* the position the decompressor currently is */
|
|
|
|
DWORD realwanted; /* the position the user wants to read from */
|
|
|
|
|
2009-06-07 14:10:13 +00:00
|
|
|
BYTE table[LZ_TABLE_SIZE]; /* the rotating LZ table */
|
2003-08-28 19:34:10 +00:00
|
|
|
UINT curtabent; /* CURrent TABle ENTry */
|
|
|
|
|
|
|
|
BYTE stringlen; /* length and position of current string */
|
|
|
|
DWORD stringpos; /* from stringtable */
|
|
|
|
|
|
|
|
|
|
|
|
WORD bytetype; /* bitmask within blocks */
|
|
|
|
|
|
|
|
BYTE *get; /* GETLEN bytes */
|
|
|
|
DWORD getcur; /* current read */
|
|
|
|
DWORD getlen; /* length last got */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MAX_LZSTATES 16
|
|
|
|
static struct lzstate *lzstates[MAX_LZSTATES];
|
|
|
|
|
2009-06-07 14:10:13 +00:00
|
|
|
#define LZ_MIN_HANDLE 0x400
|
|
|
|
#define IS_LZ_HANDLE(h) (((h) >= LZ_MIN_HANDLE) && ((h) < LZ_MIN_HANDLE+MAX_LZSTATES))
|
|
|
|
#define GET_LZ_STATE(h) (IS_LZ_HANDLE(h) ? lzstates[(h)-LZ_MIN_HANDLE] : NULL)
|
2003-08-28 19:34:10 +00:00
|
|
|
|
|
|
|
/* reads one compressed byte, including buffering */
|
|
|
|
#define GET(lzs,b) _lzget(lzs,&b)
|
|
|
|
#define GET_FLUSH(lzs) lzs->getcur=lzs->getlen;
|
|
|
|
|
|
|
|
static int
|
|
|
|
_lzget(struct lzstate *lzs,BYTE *b) {
|
|
|
|
if (lzs->getcur<lzs->getlen) {
|
|
|
|
*b = lzs->get[lzs->getcur++];
|
|
|
|
return 1;
|
|
|
|
} else {
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
int ret = _lread(lzs->realfd,lzs->get,GETLEN);
|
2003-08-28 19:34:10 +00:00
|
|
|
if (ret==HFILE_ERROR)
|
|
|
|
return HFILE_ERROR;
|
|
|
|
if (ret==0)
|
|
|
|
return 0;
|
|
|
|
lzs->getlen = ret;
|
|
|
|
lzs->getcur = 1;
|
|
|
|
*b = *(lzs->get);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* internal function, reads lzheader
|
|
|
|
* returns BADINHANDLE for non filedescriptors
|
|
|
|
* return 0 for file not compressed using LZ
|
|
|
|
* return UNKNOWNALG for unknown algorithm
|
|
|
|
* returns lzfileheader in *head
|
|
|
|
*/
|
|
|
|
static INT read_header(HFILE fd,struct lzfileheader *head)
|
|
|
|
{
|
2009-06-07 14:10:13 +00:00
|
|
|
BYTE buf[LZ_HEADER_LEN];
|
2003-08-28 19:34:10 +00:00
|
|
|
|
|
|
|
if (_llseek(fd,0,SEEK_SET)==-1)
|
|
|
|
return LZERROR_BADINHANDLE;
|
|
|
|
|
|
|
|
/* We can't directly read the lzfileheader struct due to
|
|
|
|
* structure element alignment
|
|
|
|
*/
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
if (_lread(fd,buf,LZ_HEADER_LEN)<LZ_HEADER_LEN)
|
2003-08-28 19:34:10 +00:00
|
|
|
return 0;
|
2009-06-07 14:10:13 +00:00
|
|
|
memcpy(head->magic,buf,LZ_MAGIC_LEN);
|
|
|
|
memcpy(&(head->compressiontype),buf+LZ_MAGIC_LEN,1);
|
|
|
|
memcpy(&(head->lastchar),buf+LZ_MAGIC_LEN+1,1);
|
2003-08-28 19:34:10 +00:00
|
|
|
|
2018-04-11 11:30:53 +00:00
|
|
|
/* FIXME: consider endianness on non-intel architectures */
|
2009-06-07 14:10:13 +00:00
|
|
|
memcpy(&(head->reallength),buf+LZ_MAGIC_LEN+2,4);
|
2003-08-28 19:34:10 +00:00
|
|
|
|
2009-06-07 14:10:13 +00:00
|
|
|
if (memcmp(head->magic,LZMagic,LZ_MAGIC_LEN))
|
2003-08-28 19:34:10 +00:00
|
|
|
return 0;
|
|
|
|
if (head->compressiontype!='A')
|
|
|
|
return LZERROR_UNKNOWNALG;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2009-06-07 14:10:13 +00:00
|
|
|
* LZStart (KERNEL32.@)
|
2003-08-28 19:34:10 +00:00
|
|
|
*/
|
|
|
|
INT WINAPI LZStart(void)
|
|
|
|
{
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
TRACE("(void)\n");
|
2003-08-28 19:34:10 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2009-06-07 14:10:13 +00:00
|
|
|
* LZInit (KERNEL32.@)
|
2003-08-28 19:34:10 +00:00
|
|
|
*
|
|
|
|
* initializes internal decompression buffers, returns lzfiledescriptor.
|
|
|
|
* (return value the same as hfSrc, if hfSrc is not compressed)
|
|
|
|
* on failure, returns error code <0
|
|
|
|
* lzfiledescriptors range from 0x400 to 0x410 (only 16 open files per process)
|
|
|
|
*
|
|
|
|
* since _llseek uses the same types as libc.lseek, we just use the macros of
|
|
|
|
* libc
|
|
|
|
*/
|
|
|
|
HFILE WINAPI LZInit( HFILE hfSrc )
|
|
|
|
{
|
|
|
|
|
|
|
|
struct lzfileheader head;
|
|
|
|
struct lzstate *lzs;
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
int i, ret;
|
2003-08-28 19:34:10 +00:00
|
|
|
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
TRACE("(%d)\n",hfSrc);
|
2003-08-28 19:34:10 +00:00
|
|
|
ret=read_header(hfSrc,&head);
|
|
|
|
if (ret<=0) {
|
|
|
|
_llseek(hfSrc,0,SEEK_SET);
|
2009-06-07 14:10:13 +00:00
|
|
|
return ret?ret:hfSrc;
|
2003-08-28 19:34:10 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < MAX_LZSTATES; i++) if (!lzstates[i]) break;
|
|
|
|
if (i == MAX_LZSTATES) return LZERROR_GLOBALLOC;
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
lzstates[i] = lzs = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*lzs) );
|
2003-08-28 19:34:10 +00:00
|
|
|
if(lzs == NULL) return LZERROR_GLOBALLOC;
|
|
|
|
|
|
|
|
lzs->realfd = hfSrc;
|
|
|
|
lzs->lastchar = head.lastchar;
|
|
|
|
lzs->reallength = head.reallength;
|
|
|
|
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
lzs->get = HeapAlloc( GetProcessHeap(), 0, GETLEN );
|
2003-08-28 19:34:10 +00:00
|
|
|
lzs->getlen = 0;
|
|
|
|
lzs->getcur = 0;
|
|
|
|
|
|
|
|
if(lzs->get == NULL) {
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, lzs);
|
2003-08-28 19:34:10 +00:00
|
|
|
lzstates[i] = NULL;
|
|
|
|
return LZERROR_GLOBALLOC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Yes, preinitialize with spaces */
|
2009-06-07 14:10:13 +00:00
|
|
|
memset(lzs->table,' ',LZ_TABLE_SIZE);
|
2003-08-28 19:34:10 +00:00
|
|
|
/* Yes, start 16 byte from the END of the table */
|
|
|
|
lzs->curtabent = 0xff0;
|
2009-06-07 14:10:13 +00:00
|
|
|
return LZ_MIN_HANDLE + i;
|
2003-08-28 19:34:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2009-06-07 14:10:13 +00:00
|
|
|
* LZDone (KERNEL32.@)
|
2003-08-28 19:34:10 +00:00
|
|
|
*/
|
|
|
|
void WINAPI LZDone(void)
|
|
|
|
{
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
TRACE("(void)\n");
|
2003-08-28 19:34:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2009-06-07 14:10:13 +00:00
|
|
|
* GetExpandedNameA (KERNEL32.@)
|
2003-08-28 19:34:10 +00:00
|
|
|
*
|
|
|
|
* gets the full filename of the compressed file 'in' by opening it
|
|
|
|
* and reading the header
|
|
|
|
*
|
|
|
|
* "file." is being translated to "file"
|
|
|
|
* "file.bl_" (with lastchar 'a') is being translated to "file.bla"
|
|
|
|
* "FILE.BL_" (with lastchar 'a') is being translated to "FILE.BLA"
|
|
|
|
*/
|
|
|
|
|
|
|
|
INT WINAPI GetExpandedNameA( LPSTR in, LPSTR out )
|
|
|
|
{
|
|
|
|
struct lzfileheader head;
|
|
|
|
HFILE fd;
|
|
|
|
OFSTRUCT ofs;
|
|
|
|
INT fnislowercased,ret,len;
|
|
|
|
LPSTR s,t;
|
|
|
|
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
TRACE("(%s)\n",in);
|
2003-08-28 19:34:10 +00:00
|
|
|
fd=OpenFile(in,&ofs,OF_READ);
|
|
|
|
if (fd==HFILE_ERROR)
|
|
|
|
return (INT)(INT16)LZERROR_BADINHANDLE;
|
|
|
|
strcpy(out,in);
|
|
|
|
ret=read_header(fd,&head);
|
|
|
|
if (ret<=0) {
|
|
|
|
/* not a LZ compressed file, so the expanded name is the same
|
|
|
|
* as the input name */
|
|
|
|
_lclose(fd);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* look for directory prefix and skip it. */
|
|
|
|
s=out;
|
|
|
|
while (NULL!=(t=strpbrk(s,"/\\:")))
|
|
|
|
s=t+1;
|
|
|
|
|
|
|
|
/* now mangle the basename */
|
|
|
|
if (!*s) {
|
|
|
|
/* FIXME: hmm. shouldn't happen? */
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
WARN("Specified a directory or what? (%s)\n",in);
|
2003-08-28 19:34:10 +00:00
|
|
|
_lclose(fd);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/* see if we should use lowercase or uppercase on the last char */
|
|
|
|
fnislowercased=1;
|
|
|
|
t=s+strlen(s)-1;
|
|
|
|
while (t>=out) {
|
|
|
|
if (!isalpha(*t)) {
|
|
|
|
t--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
fnislowercased=islower(*t);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (isalpha(head.lastchar)) {
|
|
|
|
if (fnislowercased)
|
2009-06-07 14:10:13 +00:00
|
|
|
head.lastchar=tolower(head.lastchar);
|
2003-08-28 19:34:10 +00:00
|
|
|
else
|
2009-06-07 14:10:13 +00:00
|
|
|
head.lastchar=toupper(head.lastchar);
|
2003-08-28 19:34:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* now look where to replace the last character */
|
|
|
|
if (NULL!=(t=strchr(s,'.'))) {
|
|
|
|
if (t[1]=='\0') {
|
|
|
|
t[0]='\0';
|
|
|
|
} else {
|
|
|
|
len=strlen(t)-1;
|
|
|
|
if (t[len]=='_')
|
|
|
|
t[len]=head.lastchar;
|
|
|
|
}
|
|
|
|
} /* else no modification necessary */
|
|
|
|
_lclose(fd);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2009-06-07 14:10:13 +00:00
|
|
|
* GetExpandedNameW (KERNEL32.@)
|
2003-08-28 19:34:10 +00:00
|
|
|
*/
|
|
|
|
INT WINAPI GetExpandedNameW( LPWSTR in, LPWSTR out )
|
|
|
|
{
|
|
|
|
INT ret;
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
DWORD len = WideCharToMultiByte( CP_ACP, 0, in, -1, NULL, 0, NULL, NULL );
|
|
|
|
char *xin = HeapAlloc( GetProcessHeap(), 0, len );
|
|
|
|
char *xout = HeapAlloc( GetProcessHeap(), 0, len+3 );
|
2003-08-28 19:34:10 +00:00
|
|
|
WideCharToMultiByte( CP_ACP, 0, in, -1, xin, len, NULL, NULL );
|
|
|
|
if ((ret = GetExpandedNameA( xin, xout )) > 0)
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, xout, -1, out, strlenW(in)+4 );
|
|
|
|
HeapFree( GetProcessHeap(), 0, xin );
|
|
|
|
HeapFree( GetProcessHeap(), 0, xout );
|
2003-08-28 19:34:10 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2009-06-07 14:10:13 +00:00
|
|
|
* LZRead (KERNEL32.@)
|
2003-08-28 19:34:10 +00:00
|
|
|
*/
|
|
|
|
INT WINAPI LZRead( HFILE fd, LPSTR vbuf, INT toread )
|
|
|
|
{
|
|
|
|
int howmuch;
|
|
|
|
BYTE b,*buf;
|
|
|
|
struct lzstate *lzs;
|
|
|
|
|
|
|
|
buf=(LPBYTE)vbuf;
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
TRACE("(%d,%p,%d)\n",fd,buf,toread);
|
2003-08-28 19:34:10 +00:00
|
|
|
howmuch=toread;
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
if (!(lzs = GET_LZ_STATE(fd))) return _lread(fd,buf,toread);
|
2003-08-28 19:34:10 +00:00
|
|
|
|
|
|
|
/* The decompressor itself is in a define, cause we need it twice
|
|
|
|
* in this function. (the decompressed byte will be in b)
|
|
|
|
*/
|
|
|
|
#define DECOMPRESS_ONE_BYTE \
|
|
|
|
if (lzs->stringlen) { \
|
|
|
|
b = lzs->table[lzs->stringpos]; \
|
|
|
|
lzs->stringpos = (lzs->stringpos+1)&0xFFF; \
|
|
|
|
lzs->stringlen--; \
|
|
|
|
} else { \
|
|
|
|
if (!(lzs->bytetype&0x100)) { \
|
|
|
|
if (1!=GET(lzs,b)) \
|
|
|
|
return toread-howmuch; \
|
|
|
|
lzs->bytetype = b|0xFF00; \
|
|
|
|
} \
|
|
|
|
if (lzs->bytetype & 1) { \
|
|
|
|
if (1!=GET(lzs,b)) \
|
|
|
|
return toread-howmuch; \
|
|
|
|
} else { \
|
|
|
|
BYTE b1,b2; \
|
|
|
|
\
|
|
|
|
if (1!=GET(lzs,b1)) \
|
|
|
|
return toread-howmuch; \
|
|
|
|
if (1!=GET(lzs,b2)) \
|
|
|
|
return toread-howmuch; \
|
|
|
|
/* Format: \
|
|
|
|
* b1 b2 \
|
|
|
|
* AB CD \
|
|
|
|
* where CAB is the stringoffset in the table\
|
|
|
|
* and D+3 is the len of the string \
|
|
|
|
*/ \
|
|
|
|
lzs->stringpos = b1|((b2&0xf0)<<4); \
|
|
|
|
lzs->stringlen = (b2&0xf)+2; \
|
|
|
|
/* 3, but we use a byte already below ... */\
|
|
|
|
b = lzs->table[lzs->stringpos];\
|
|
|
|
lzs->stringpos = (lzs->stringpos+1)&0xFFF;\
|
|
|
|
} \
|
|
|
|
lzs->bytetype>>=1; \
|
|
|
|
} \
|
|
|
|
/* store b in table */ \
|
|
|
|
lzs->table[lzs->curtabent++]= b; \
|
|
|
|
lzs->curtabent &= 0xFFF; \
|
|
|
|
lzs->realcurrent++;
|
|
|
|
|
|
|
|
/* if someone has seeked, we have to bring the decompressor
|
|
|
|
* to that position
|
|
|
|
*/
|
|
|
|
if (lzs->realcurrent!=lzs->realwanted) {
|
|
|
|
/* if the wanted position is before the current position
|
|
|
|
* I see no easy way to unroll ... We have to restart at
|
|
|
|
* the beginning. *sigh*
|
|
|
|
*/
|
|
|
|
if (lzs->realcurrent>lzs->realwanted) {
|
|
|
|
/* flush decompressor state */
|
2009-06-07 14:10:13 +00:00
|
|
|
_llseek(lzs->realfd,LZ_HEADER_LEN,SEEK_SET);
|
2003-08-28 19:34:10 +00:00
|
|
|
GET_FLUSH(lzs);
|
|
|
|
lzs->realcurrent= 0;
|
|
|
|
lzs->bytetype = 0;
|
|
|
|
lzs->stringlen = 0;
|
2009-06-07 14:10:13 +00:00
|
|
|
memset(lzs->table,' ',LZ_TABLE_SIZE);
|
2003-08-28 19:34:10 +00:00
|
|
|
lzs->curtabent = 0xFF0;
|
|
|
|
}
|
|
|
|
while (lzs->realcurrent<lzs->realwanted) {
|
|
|
|
DECOMPRESS_ONE_BYTE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (howmuch) {
|
|
|
|
DECOMPRESS_ONE_BYTE;
|
|
|
|
lzs->realwanted++;
|
|
|
|
*buf++ = b;
|
|
|
|
howmuch--;
|
|
|
|
}
|
|
|
|
return toread;
|
|
|
|
#undef DECOMPRESS_ONE_BYTE
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2009-06-07 14:10:13 +00:00
|
|
|
* LZSeek (KERNEL32.@)
|
2003-08-28 19:34:10 +00:00
|
|
|
*/
|
|
|
|
LONG WINAPI LZSeek( HFILE fd, LONG off, INT type )
|
|
|
|
{
|
|
|
|
struct lzstate *lzs;
|
|
|
|
LONG newwanted;
|
|
|
|
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
TRACE("(%d,%d,%d)\n",fd,off,type);
|
2003-08-28 19:34:10 +00:00
|
|
|
/* not compressed? just use normal _llseek() */
|
|
|
|
if (!(lzs = GET_LZ_STATE(fd))) return _llseek(fd,off,type);
|
|
|
|
newwanted = lzs->realwanted;
|
|
|
|
switch (type) {
|
|
|
|
case 1: /* SEEK_CUR */
|
|
|
|
newwanted += off;
|
|
|
|
break;
|
|
|
|
case 2: /* SEEK_END */
|
|
|
|
newwanted = lzs->reallength-off;
|
|
|
|
break;
|
|
|
|
default:/* SEEK_SET */
|
|
|
|
newwanted = off;
|
|
|
|
break;
|
|
|
|
}
|
2009-06-07 14:10:13 +00:00
|
|
|
if (newwanted>lzs->reallength)
|
2003-08-28 19:34:10 +00:00
|
|
|
return LZERROR_BADVALUE;
|
|
|
|
if (newwanted<0)
|
|
|
|
return LZERROR_BADVALUE;
|
|
|
|
lzs->realwanted = newwanted;
|
|
|
|
return newwanted;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2009-06-07 14:10:13 +00:00
|
|
|
* LZCopy (KERNEL32.@)
|
2003-08-28 19:34:10 +00:00
|
|
|
*
|
|
|
|
* Copies everything from src to dest
|
|
|
|
* if src is a LZ compressed file, it will be uncompressed.
|
|
|
|
* will return the number of bytes written to dest or errors.
|
|
|
|
*/
|
|
|
|
LONG WINAPI LZCopy( HFILE src, HFILE dest )
|
|
|
|
{
|
2009-06-07 14:10:13 +00:00
|
|
|
int usedlzinit = 0, ret, wret;
|
2003-08-28 19:34:10 +00:00
|
|
|
LONG len;
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
HFILE oldsrc = src, srcfd;
|
|
|
|
FILETIME filetime;
|
|
|
|
struct lzstate *lzs;
|
2003-08-28 19:34:10 +00:00
|
|
|
#define BUFLEN 1000
|
2004-12-25 11:22:37 +00:00
|
|
|
CHAR buf[BUFLEN];
|
2003-08-28 19:34:10 +00:00
|
|
|
/* we need that weird typedef, for i can't seem to get function pointer
|
|
|
|
* casts right. (Or they probably just do not like WINAPI in general)
|
|
|
|
*/
|
|
|
|
typedef UINT (WINAPI *_readfun)(HFILE,LPVOID,UINT);
|
|
|
|
|
|
|
|
_readfun xread;
|
|
|
|
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
TRACE("(%d,%d)\n",src,dest);
|
2003-08-28 19:34:10 +00:00
|
|
|
if (!IS_LZ_HANDLE(src)) {
|
|
|
|
src = LZInit(src);
|
|
|
|
if ((INT)src <= 0) return 0;
|
|
|
|
if (src != oldsrc) usedlzinit=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* not compressed? just copy */
|
|
|
|
if (!IS_LZ_HANDLE(src))
|
2018-04-11 11:30:53 +00:00
|
|
|
#ifdef __REACTOS__
|
2011-07-21 17:28:21 +00:00
|
|
|
xread=(_readfun)_hread; // ROSHACK
|
2018-04-11 11:30:53 +00:00
|
|
|
#else
|
|
|
|
xread=_lread;
|
|
|
|
#endif
|
2003-08-28 19:34:10 +00:00
|
|
|
else
|
|
|
|
xread=(_readfun)LZRead;
|
|
|
|
len=0;
|
|
|
|
while (1) {
|
|
|
|
ret=xread(src,buf,BUFLEN);
|
|
|
|
if (ret<=0) {
|
|
|
|
if (ret==0)
|
|
|
|
break;
|
|
|
|
if (ret==-1)
|
|
|
|
return LZERROR_READ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
len += ret;
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
wret = _lwrite(dest,buf,ret);
|
2003-08-28 19:34:10 +00:00
|
|
|
if (wret!=ret)
|
|
|
|
return LZERROR_WRITE;
|
|
|
|
}
|
|
|
|
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
/* Maintain the timestamp of source file to destination file */
|
|
|
|
srcfd = (!(lzs = GET_LZ_STATE(src))) ? src : lzs->realfd;
|
|
|
|
GetFileTime( LongToHandle(srcfd), NULL, NULL, &filetime );
|
|
|
|
SetFileTime( LongToHandle(dest), NULL, NULL, &filetime );
|
2005-05-09 01:46:57 +00:00
|
|
|
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
/* close handle */
|
2003-08-28 19:34:10 +00:00
|
|
|
if (usedlzinit)
|
|
|
|
LZClose(src);
|
|
|
|
return len;
|
|
|
|
#undef BUFLEN
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reverses GetExpandedPathname */
|
|
|
|
static LPSTR LZEXPAND_MangleName( LPCSTR fn )
|
|
|
|
{
|
|
|
|
char *p;
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
char *mfn = HeapAlloc( GetProcessHeap(), 0, strlen(fn) + 3 ); /* "._" and \0 */
|
2003-08-28 19:34:10 +00:00
|
|
|
if(mfn == NULL) return NULL;
|
|
|
|
strcpy( mfn, fn );
|
|
|
|
if (!(p = strrchr( mfn, '\\' ))) p = mfn;
|
|
|
|
if ((p = strchr( p, '.' )))
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
if (strlen(p) < 3) strcat( p, "_" ); /* append '_' */
|
|
|
|
else p[strlen(p)-1] = '_'; /* replace last character */
|
|
|
|
}
|
|
|
|
else strcat( mfn, "._" ); /* append "._" */
|
|
|
|
return mfn;
|
|
|
|
}
|
|
|
|
|
2009-06-07 14:10:13 +00:00
|
|
|
|
2003-08-28 19:34:10 +00:00
|
|
|
/***********************************************************************
|
2009-06-07 14:10:13 +00:00
|
|
|
* LZOpenFileA (KERNEL32.@)
|
2003-08-28 19:34:10 +00:00
|
|
|
*
|
|
|
|
* Opens a file. If not compressed, open it as a normal file.
|
|
|
|
*/
|
|
|
|
HFILE WINAPI LZOpenFileA( LPSTR fn, LPOFSTRUCT ofs, WORD mode )
|
|
|
|
{
|
|
|
|
HFILE fd,cfd;
|
2018-04-11 11:30:53 +00:00
|
|
|
BYTE ofs_cBytes = ofs->cBytes;
|
2003-08-28 19:34:10 +00:00
|
|
|
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
TRACE("(%s,%p,%d)\n",fn,ofs,mode);
|
2003-08-28 19:34:10 +00:00
|
|
|
/* 0x70 represents all OF_SHARE_* flags, ignore them for the check */
|
|
|
|
fd=OpenFile(fn,ofs,mode);
|
|
|
|
if (fd==HFILE_ERROR)
|
|
|
|
{
|
|
|
|
LPSTR mfn = LZEXPAND_MangleName(fn);
|
|
|
|
fd = OpenFile(mfn,ofs,mode);
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
HeapFree( GetProcessHeap(), 0, mfn );
|
2003-08-28 19:34:10 +00:00
|
|
|
}
|
2018-04-11 11:30:53 +00:00
|
|
|
if (fd==HFILE_ERROR)
|
|
|
|
ofs->cBytes = ofs_cBytes;
|
2003-08-28 19:34:10 +00:00
|
|
|
if ((mode&~0x70)!=OF_READ)
|
|
|
|
return fd;
|
|
|
|
if (fd==HFILE_ERROR)
|
|
|
|
return HFILE_ERROR;
|
|
|
|
cfd=LZInit(fd);
|
|
|
|
if ((INT)cfd <= 0) return fd;
|
|
|
|
return cfd;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2009-06-07 14:10:13 +00:00
|
|
|
* LZOpenFileW (KERNEL32.@)
|
2003-08-28 19:34:10 +00:00
|
|
|
*/
|
|
|
|
HFILE WINAPI LZOpenFileW( LPWSTR fn, LPOFSTRUCT ofs, WORD mode )
|
|
|
|
{
|
|
|
|
HFILE ret;
|
|
|
|
DWORD len = WideCharToMultiByte( CP_ACP, 0, fn, -1, NULL, 0, NULL, NULL );
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
LPSTR xfn = HeapAlloc( GetProcessHeap(), 0, len );
|
2003-08-28 19:34:10 +00:00
|
|
|
WideCharToMultiByte( CP_ACP, 0, fn, -1, xfn, len, NULL, NULL );
|
|
|
|
ret = LZOpenFileA(xfn,ofs,mode);
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
HeapFree( GetProcessHeap(), 0, xfn );
|
2003-08-28 19:34:10 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2009-06-07 14:10:13 +00:00
|
|
|
* LZClose (KERNEL32.@)
|
2003-08-28 19:34:10 +00:00
|
|
|
*/
|
|
|
|
void WINAPI LZClose( HFILE fd )
|
|
|
|
{
|
|
|
|
struct lzstate *lzs;
|
|
|
|
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
TRACE("(%d)\n",fd);
|
2003-08-28 19:34:10 +00:00
|
|
|
if (!(lzs = GET_LZ_STATE(fd))) _lclose(fd);
|
|
|
|
else
|
|
|
|
{
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
HeapFree( GetProcessHeap(), 0, lzs->get );
|
2009-06-07 14:10:13 +00:00
|
|
|
CloseHandle( LongToHandle(lzs->realfd) );
|
|
|
|
lzstates[fd - LZ_MIN_HANDLE] = NULL;
|
[KERNEL32]: Winesync all there is to Winesync in ReactOS' kernel32. This mainly affects LZ*, Comm*, *ProfileString* (INI), and *Resource* APIs, however the changes in there are relatively minor. More substantial changes affect the locale/NLS/language functions, many which were bitrotting for 6+ years.
In theory, this code is "better" than before, and it is closer to Wine (which arguably has better compatibility). It also resets things in sync with Wine however, and may lose and "fixes" ReactOS may have added over the years. But this is a good thing, since these fixes have been "lost" (they obviously never made it into Wine), and if regressions are now found due to this, actual upstream patches can be sent and picked up on the next sync. This avoids maintaining duplicate code, at the expenses of some potential short-term regressions in i18n.
Finally, note that much of /string seems to be taken from Wine's Unicode library (which a host "unicode" already exists in ReactOS' tools/. It may be better (for someone with more experience as to these wine-isms) to simply just pull-in whatever winelib files are not currently present in ReactOS, and have kernel32 and tools/unicode use winelib, instead of having 2 or 3 copies of the code.
svn path=/trunk/; revision=52754
2011-07-21 05:24:59 +00:00
|
|
|
HeapFree( GetProcessHeap(), 0, lzs );
|
2003-08-28 19:34:10 +00:00
|
|
|
}
|
|
|
|
}
|
2011-07-24 23:42:09 +00:00
|
|
|
|
2018-04-11 11:30:53 +00:00
|
|
|
#ifdef __REACTOS__
|
|
|
|
|
2011-07-24 23:42:09 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
WINAPI
|
|
|
|
LZCloseFile(IN HFILE FileHandle)
|
|
|
|
{
|
|
|
|
/* One function uses _lclose, the other CloseHandle -- same thing */
|
|
|
|
LZClose(FileHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
ULONG
|
|
|
|
WINAPI
|
|
|
|
LZCreateFileW(IN LPCWSTR FileName,
|
|
|
|
IN DWORD dwDesiredAccess,
|
|
|
|
IN DWORD dwShareMode,
|
|
|
|
IN DWORD dwCreationDisposition,
|
|
|
|
IN LPWSTR lpString1)
|
|
|
|
{
|
|
|
|
WARN(" LZCreateFileW Not implemented!\n");
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2018-04-11 11:30:53 +00:00
|
|
|
#endif /* __REACTOS__ */
|