|
|
|
|
@ -6,6 +6,20 @@
|
|
|
|
|
#include "all.h" |
|
|
|
|
#include "../3rdParty/Storm/Source/storm.h" |
|
|
|
|
|
|
|
|
|
static void WGetFileArchive(HANDLE hsFile, DWORD *retries, const char *FileName) |
|
|
|
|
{ |
|
|
|
|
HANDLE archive; |
|
|
|
|
|
|
|
|
|
if (*retries >= 5) |
|
|
|
|
FileErrDlg(FileName); |
|
|
|
|
|
|
|
|
|
if (hsFile && SFileGetFileArchive(hsFile, &archive) && archive != diabdat_mpq) { |
|
|
|
|
Sleep(20); |
|
|
|
|
(*retries)++; |
|
|
|
|
} else if (!InsertCDDlg()) |
|
|
|
|
FileErrDlg(FileName); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void WCloseFile(HANDLE file) |
|
|
|
|
{ |
|
|
|
|
SFileCloseFile(file); |
|
|
|
|
@ -22,20 +36,6 @@ LONG WGetFileSize(HANDLE hsFile, DWORD *lpFileSizeHigh)
|
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void WGetFileArchive(HANDLE hsFile, DWORD *retries, const char *FileName) |
|
|
|
|
{ |
|
|
|
|
HANDLE archive; |
|
|
|
|
|
|
|
|
|
if (*retries >= 5) |
|
|
|
|
FileErrDlg(FileName); |
|
|
|
|
|
|
|
|
|
if (hsFile && SFileGetFileArchive(hsFile, &archive) && archive != diabdat_mpq) { |
|
|
|
|
Sleep(20); |
|
|
|
|
(*retries)++; |
|
|
|
|
} else if (!InsertCDDlg()) |
|
|
|
|
FileErrDlg(FileName); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BOOL WOpenFile(const char *FileName, HANDLE *phsFile, BOOL mayNotExist) |
|
|
|
|
{ |
|
|
|
|
DWORD retry = 0; |
|
|
|
|
@ -76,71 +76,25 @@ int WSetFilePointer(HANDLE file1, int offset, HANDLE file2, int whence)
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BOOL LoadWaveFormat(HANDLE hsFile, WAVEFORMATEX *pwfx) |
|
|
|
|
{ |
|
|
|
|
BOOL ret; |
|
|
|
|
MEMFILE wave_file; |
|
|
|
|
|
|
|
|
|
AllocateMemFile(hsFile, &wave_file, 0); |
|
|
|
|
ret = ReadWaveFile(&wave_file, pwfx, NULL); |
|
|
|
|
FreeMemFile(&wave_file); |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AllocateMemFile(HANDLE hsFile, MEMFILE *pMemFile, DWORD dwPos) |
|
|
|
|
static void FillMemFile(MEMFILE *pMemFile) |
|
|
|
|
{ |
|
|
|
|
DWORD length; |
|
|
|
|
|
|
|
|
|
memset(pMemFile, 0, sizeof(*pMemFile)); |
|
|
|
|
pMemFile->end = WGetFileSize(hsFile, NULL); |
|
|
|
|
length = 4096; |
|
|
|
|
if (dwPos > length) |
|
|
|
|
length = dwPos; |
|
|
|
|
pMemFile->buf_len = length; |
|
|
|
|
if (length >= pMemFile->end) |
|
|
|
|
length = pMemFile->end; |
|
|
|
|
pMemFile->buf_len = length; |
|
|
|
|
pMemFile->buf = DiabloAllocPtr(length); |
|
|
|
|
pMemFile->file = hsFile; |
|
|
|
|
DWORD to_read; |
|
|
|
|
WSetFilePointer(pMemFile->file, pMemFile->offset, NULL, FILE_BEGIN); |
|
|
|
|
to_read = pMemFile->end - pMemFile->offset; |
|
|
|
|
if (pMemFile->buf_len < to_read) |
|
|
|
|
to_read = pMemFile->buf_len; |
|
|
|
|
if (to_read) |
|
|
|
|
WReadFile(pMemFile->file, pMemFile->buf, to_read); |
|
|
|
|
pMemFile->dist = 0; |
|
|
|
|
pMemFile->bytes_to_read = to_read; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void FreeMemFile(MEMFILE *pMemFile) |
|
|
|
|
static void FreeMemFile(MEMFILE *pMemFile) |
|
|
|
|
{ |
|
|
|
|
MemFreeDbg(pMemFile->buf); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BOOL ReadWaveFile(MEMFILE *pMemFile, WAVEFORMATEX *pwfx, CKINFO *chunk) |
|
|
|
|
{ |
|
|
|
|
MMCKINFO hdr; |
|
|
|
|
CKINFO fmt; |
|
|
|
|
PCMWAVEFORMAT wf; |
|
|
|
|
|
|
|
|
|
if (!ReadMemFile(pMemFile, &hdr, 12)) |
|
|
|
|
return FALSE; |
|
|
|
|
if (hdr.ckid != FOURCC_RIFF || hdr.fccType != MAKEFOURCC('W', 'A', 'V', 'E')) |
|
|
|
|
return FALSE; |
|
|
|
|
if (!ReadWaveSection(pMemFile, MAKEFOURCC('f', 'm', 't', ' '), &fmt)) |
|
|
|
|
return FALSE; |
|
|
|
|
if (fmt.dwSize < sizeof(PCMWAVEFORMAT)) |
|
|
|
|
return FALSE; |
|
|
|
|
if (!ReadMemFile(pMemFile, &wf, sizeof(wf))) |
|
|
|
|
return FALSE; |
|
|
|
|
if (SeekMemFile(pMemFile, fmt.dwSize - sizeof(wf), FILE_CURRENT) == -1) |
|
|
|
|
return FALSE; |
|
|
|
|
|
|
|
|
|
pwfx->cbSize = 0; |
|
|
|
|
pwfx->wFormatTag = wf.wf.wFormatTag; |
|
|
|
|
pwfx->nChannels = wf.wf.nChannels; |
|
|
|
|
pwfx->nSamplesPerSec = wf.wf.nSamplesPerSec; |
|
|
|
|
pwfx->nAvgBytesPerSec = wf.wf.nAvgBytesPerSec; |
|
|
|
|
pwfx->nBlockAlign = wf.wf.nBlockAlign; |
|
|
|
|
pwfx->wBitsPerSample = wf.wBitsPerSample; |
|
|
|
|
if (chunk == NULL) |
|
|
|
|
return TRUE; |
|
|
|
|
return ReadWaveSection(pMemFile, MAKEFOURCC('d', 'a', 't', 'a'), chunk); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BOOL ReadMemFile(MEMFILE *pMemFile, void *lpBuf, size_t length) |
|
|
|
|
static BOOL ReadMemFile(MEMFILE *pMemFile, void *lpBuf, size_t length) |
|
|
|
|
{ |
|
|
|
|
while (length) { |
|
|
|
|
size_t to_copy; |
|
|
|
|
@ -161,20 +115,7 @@ BOOL ReadMemFile(MEMFILE *pMemFile, void *lpBuf, size_t length)
|
|
|
|
|
return TRUE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void FillMemFile(MEMFILE *pMemFile) |
|
|
|
|
{ |
|
|
|
|
DWORD to_read; |
|
|
|
|
WSetFilePointer(pMemFile->file, pMemFile->offset, NULL, FILE_BEGIN); |
|
|
|
|
to_read = pMemFile->end - pMemFile->offset; |
|
|
|
|
if (pMemFile->buf_len < to_read) |
|
|
|
|
to_read = pMemFile->buf_len; |
|
|
|
|
if (to_read) |
|
|
|
|
WReadFile(pMemFile->file, pMemFile->buf, to_read); |
|
|
|
|
pMemFile->dist = 0; |
|
|
|
|
pMemFile->bytes_to_read = to_read; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int SeekMemFile(MEMFILE *pMemFile, ULONG lDist, DWORD dwMethod) |
|
|
|
|
static int SeekMemFile(MEMFILE *pMemFile, ULONG lDist, DWORD dwMethod) |
|
|
|
|
{ |
|
|
|
|
if (lDist < pMemFile->bytes_to_read) { |
|
|
|
|
pMemFile->bytes_to_read -= lDist; |
|
|
|
|
@ -185,7 +126,7 @@ int SeekMemFile(MEMFILE *pMemFile, ULONG lDist, DWORD dwMethod)
|
|
|
|
|
return pMemFile->offset; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BOOL ReadWaveSection(MEMFILE *pMemFile, DWORD id, CKINFO *chunk) |
|
|
|
|
static BOOL ReadWaveSection(MEMFILE *pMemFile, DWORD id, CKINFO *chunk) |
|
|
|
|
{ |
|
|
|
|
DWORD hdr[2]; |
|
|
|
|
|
|
|
|
|
@ -203,6 +144,65 @@ BOOL ReadWaveSection(MEMFILE *pMemFile, DWORD id, CKINFO *chunk)
|
|
|
|
|
return chunk->dwOffset != (DWORD)-1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static BOOL ReadWaveFile(MEMFILE *pMemFile, WAVEFORMATEX *pwfx, CKINFO *chunk) |
|
|
|
|
{ |
|
|
|
|
MMCKINFO hdr; |
|
|
|
|
CKINFO fmt; |
|
|
|
|
PCMWAVEFORMAT wf; |
|
|
|
|
|
|
|
|
|
if (!ReadMemFile(pMemFile, &hdr, 12)) |
|
|
|
|
return FALSE; |
|
|
|
|
if (hdr.ckid != FOURCC_RIFF || hdr.fccType != MAKEFOURCC('W', 'A', 'V', 'E')) |
|
|
|
|
return FALSE; |
|
|
|
|
if (!ReadWaveSection(pMemFile, MAKEFOURCC('f', 'm', 't', ' '), &fmt)) |
|
|
|
|
return FALSE; |
|
|
|
|
if (fmt.dwSize < sizeof(PCMWAVEFORMAT)) |
|
|
|
|
return FALSE; |
|
|
|
|
if (!ReadMemFile(pMemFile, &wf, sizeof(wf))) |
|
|
|
|
return FALSE; |
|
|
|
|
if (SeekMemFile(pMemFile, fmt.dwSize - sizeof(wf), FILE_CURRENT) == -1) |
|
|
|
|
return FALSE; |
|
|
|
|
|
|
|
|
|
pwfx->cbSize = 0; |
|
|
|
|
pwfx->wFormatTag = wf.wf.wFormatTag; |
|
|
|
|
pwfx->nChannels = wf.wf.nChannels; |
|
|
|
|
pwfx->nSamplesPerSec = wf.wf.nSamplesPerSec; |
|
|
|
|
pwfx->nAvgBytesPerSec = wf.wf.nAvgBytesPerSec; |
|
|
|
|
pwfx->nBlockAlign = wf.wf.nBlockAlign; |
|
|
|
|
pwfx->wBitsPerSample = wf.wBitsPerSample; |
|
|
|
|
if (chunk == NULL) |
|
|
|
|
return TRUE; |
|
|
|
|
return ReadWaveSection(pMemFile, MAKEFOURCC('d', 'a', 't', 'a'), chunk); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BOOL LoadWaveFormat(HANDLE hsFile, WAVEFORMATEX *pwfx) |
|
|
|
|
{ |
|
|
|
|
BOOL ret; |
|
|
|
|
MEMFILE wave_file; |
|
|
|
|
|
|
|
|
|
AllocateMemFile(hsFile, &wave_file, 0); |
|
|
|
|
ret = ReadWaveFile(&wave_file, pwfx, NULL); |
|
|
|
|
FreeMemFile(&wave_file); |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AllocateMemFile(HANDLE hsFile, MEMFILE *pMemFile, DWORD dwPos) |
|
|
|
|
{ |
|
|
|
|
DWORD length; |
|
|
|
|
|
|
|
|
|
memset(pMemFile, 0, sizeof(*pMemFile)); |
|
|
|
|
pMemFile->end = WGetFileSize(hsFile, NULL); |
|
|
|
|
length = 4096; |
|
|
|
|
if (dwPos > length) |
|
|
|
|
length = dwPos; |
|
|
|
|
pMemFile->buf_len = length; |
|
|
|
|
if (length >= pMemFile->end) |
|
|
|
|
length = pMemFile->end; |
|
|
|
|
pMemFile->buf_len = length; |
|
|
|
|
pMemFile->buf = DiabloAllocPtr(length); |
|
|
|
|
pMemFile->file = hsFile; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BYTE *LoadWaveFile(HANDLE hsFile, WAVEFORMATEX *pwfx, CKINFO *chunk) |
|
|
|
|
{ |
|
|
|
|
MEMFILE wave_file; |
|
|
|
|
|