Jim Park's Unicode NSIS merging - Step 1 : switch to TCHARs where relevant.

Compiler output is identical before & after this step

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/branches/wizou@6036 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
wizou 2010-03-24 17:22:56 +00:00
parent 4e48722b63
commit 752d7d239a
209 changed files with 9698 additions and 7658 deletions

View file

@ -22,6 +22,8 @@
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
// Unicode support by Jim Park -- 08/29/2007
#include "Checksums.h"
@ -82,7 +84,8 @@ void streamMD5(bistream& data, md5_byte_t digest[16]) {
md5_finish(&state, digest);
}
TChecksum::TChecksum(std::string& fileName) : mode(MD5) {
// Jim Park: string -> tstring.
TChecksum::TChecksum(tstring& fileName) : mode(MD5) {
bifstream data;
data.open(fileName.c_str(), ios::binary | ios::in);
data.seekg(0, ios::beg);

View file

@ -22,6 +22,8 @@
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
// Unicode support by Jim Park -- 08/29/2007
#if !defined(Checksums_H)
#define Checksums_H
@ -29,6 +31,7 @@
#include "md5.h"
#include <string>
#include "GlobalTypes.h"
#include "tchar.h"
typedef uint32_t crc32_t;
@ -39,7 +42,7 @@
enum { CRC32, MD5 } mode;
TChecksum() : mode(MD5) { }
TChecksum(std::string& fileName);
TChecksum(tstring& fileName);
void loadMD5(md5_byte_t newdigest[16]);
void loadCRC32(crc32_t newcrc);

View file

@ -22,9 +22,12 @@
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
// Unicode support by Jim Park -- 08/29/2007
#include "ChunkedFile.h"
#include "tchar.h"
using namespace std;
@ -32,15 +35,15 @@ using namespace std;
chunks(NULL) {
chunkCount = fSize / chunkSize;
cout << "[ChunkedFile] Filesize of " << static_cast<unsigned int>(fSize) << " gives " << static_cast<unsigned int>(chunkCount) << " chunks.\n";
tout << _T("[ChunkedFile] Filesize of ") << static_cast<unsigned int>(fSize) << _T(" gives ") << static_cast<unsigned int>(chunkCount) << _T(" chunks.\n");
cout << "[ChunkedFile] Memory to be used by those chunks: " << sizeof(FileChunk) * chunkCount << " bytes...";
tout << _T("[ChunkedFile] Memory to be used by those chunks: ") << sizeof(FileChunk) * chunkCount << _T(" bytes...");
if(chunkCount == 0) {
chunks = NULL;
return;
}
chunks = new FileChunk[chunkCount];
cout << " allocated.\n";
tout << _T(" allocated.\n");
unsigned char* data = new unsigned char[chunkSize];
for(TFileOffset i = 0; i < chunkCount; i++) {
@ -50,9 +53,9 @@ using namespace std;
}
delete[] data;
cout << "[ChunkedFile] Sorting chunks... ";
tout << _T("[ChunkedFile] Sorting chunks... ");
std::sort(chunks,chunks + chunkCount);
cout << "done.\n";
tout << _T("done.\n");
}

View file

@ -22,6 +22,8 @@
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
// Reviewed for Unicode support by Jim Park -- 08/29/2007
#if !defined(ChunkedFile_H)
#define ChunkedFile_H

View file

@ -22,6 +22,8 @@
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
// Reviewed for Unicode support by Jim Park -- 08/29/2007
#include "FileFormat1.h"
#include "GlobalTypes.h"
@ -126,7 +128,7 @@ namespace FileFormat1 {
TFileOffset endOffset = in.tellg();
if(sourceChecksum == *removeCRC) {
if(existanceIsError) {
throw "Source file with the exact same contents already exists in patch!\nUse /R option (replace) to replace it with this patch!";
throw _T("Source file with the exact same contents already exists in patch!\nUse /R option (replace) to replace it with this patch!");
}
fileCount--;
} else {
@ -192,7 +194,7 @@ namespace FileFormat1 {
// calculate area inbetween this block and the next
TFileOffset notFoundStart = current->targetOffset+current->size;
if(notFoundStart > next->targetOffset) {
throw "makeBinaryPatch input problem: there was overlap";
throw _T("makeBinaryPatch input problem: there was overlap");
}
TFileOffset notFoundSize = next->targetOffset - notFoundStart;
if(notFoundSize > 0) {

View file

@ -22,6 +22,8 @@
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
// Reviewed for Unicode support by Jim Park -- 08/29/2007
#if !defined(FileFormat1_H)
#define FileFormat1_H

View file

@ -22,6 +22,8 @@
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
// Reviewed for Unicode support by Jim Park -- 08/29/2007
#include "GlobalTypes.h"

View file

@ -22,6 +22,8 @@
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
// Reviewed for Unicode support by Jim Park -- 08/29/2007
#if !defined(GlobalTypes_H)
#define GlobalTypes_H

View file

@ -22,6 +22,8 @@
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
// Unicode support by Jim Park -- 08/29/2007
#include "POSIXUtil.h"
@ -54,13 +56,13 @@ namespace POSIX {
#ifdef __WIN32__
/* do it the old way on Win32, because POSIX does not get timezone stuff right */
ALT_FILETIME getFileTime(const char* sFileName) {
ALT_FILETIME getFileTime(const TCHAR* sFileName) {
FILETIME temp;
GetSystemTimeAsFileTime(&temp);
HANDLE h = CreateFile(sFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (h == INVALID_HANDLE_VALUE) {
cerr << "Cannot read file time of " << sFileName << "\n";
terr << _T("Cannot read file time of ") << sFileName << _T("\n");
} else {
GetFileTime(h, NULL, NULL, &temp);
CloseHandle(h);
@ -77,7 +79,7 @@ namespace POSIX {
time_t currentTime = time(NULL);
if(stat(sFileName, &buf)) {
cerr << "Cannot read file time of " << sFileName << "\n";
terr << _T("Cannot read file time of ") << sFileName << _T("\n");
} else {
/* get the time from the file */
currentTime = buf.st_mtime;
@ -88,11 +90,11 @@ namespace POSIX {
}
#endif
uint32_t getFileSize(const char* sFileName) {
uint32_t getFileSize(const TCHAR* sFileName) {
std::ifstream f;
f.open(sFileName, std::ios_base::binary | std::ios_base::in);
if (!f.good() || f.eof() || !f.is_open()) {
throw "File could not be read (getFileSize)";
throw _T("File could not be read (getFileSize)");
}
f.seekg(0, std::ios_base::beg);
std::ifstream::pos_type begin_pos = f.tellg();
@ -101,29 +103,29 @@ namespace POSIX {
}
#ifdef __WIN32__
string getTempFile() {
char buffer[MAX_PATH];
if(GetTempFileName(".","vpatch",0,buffer) == 0) {
cerr << "Cannot create temporary filename";
tstring getTempFile() {
TCHAR buffer[MAX_PATH];
if(GetTempFileName(_T("."),_T("vpatch"),0,buffer) == 0) {
terr << _T("Cannot create temporary filename");
}
return string(buffer);
return tstring(buffer);
}
#else
string getTempFile() {
char t[] = "/tmp/genpatXXXXXX";
tstring getTempFile() {
TCHAR t[] = _T("/tmp/genpatXXXXXX");
mode_t old_umask = umask(0077);
int fd = mkstemp(t);
if (fd == -1) {
cerr << "Cannot create temporary filename";
return "";
terr << _T("Cannot create temporary filename");
return _T("");
}
close(fd);
umask(old_umask);
return string(t);
return tstring(t);
}
#endif

View file

@ -22,11 +22,14 @@
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
// Unicode support by Jim Park -- 08/29/2007
#if !defined(POSIXUtil_H)
#define POSIXUtil_H
#include "GlobalTypes.h"
#include <string>
#include "tchar.h"
using namespace std;
@ -36,9 +39,9 @@
uint32_t dwHighDateTime;
} ALT_FILETIME;
ALT_FILETIME getFileTime(const char* sFileName);
uint32_t getFileSize(const char* sFileName);
string getTempFile();
ALT_FILETIME getFileTime(const TCHAR* sFileName);
uint32_t getFileSize(const TCHAR* sFileName);
tstring getTempFile();
}
#endif // POSIXUtil_H

View file

@ -22,7 +22,10 @@
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
// Unicode support by Jim Park -- 08/29/2007
#include "tchar.h"
#include "PatchGenerator.h"
#include <algorithm>
@ -85,12 +88,12 @@ void PatchGenerator::execute(vector<SameBlock*>& sameBlocks) {
}
// we need to update the memory cache of target
cout << "[CacheReload] File position = " << static_cast<unsigned int>(targetCDataBaseOffset) << "\n";
tout << _T("[CacheReload] File position = ") << static_cast<unsigned int>(targetCDataBaseOffset) << _T("\n");
target.seekg(targetCDataBaseOffset,ios::beg);
target.read(reinterpret_cast<char*>(targetCData),targetCDataSize);
}
//cout << currentOffset << " ";
//tout << currentOffset << _T(" ");
SameBlock* currentSameBlock = findBlock(sourceTree,currentOffset);
@ -108,9 +111,9 @@ void PatchGenerator::execute(vector<SameBlock*>& sameBlocks) {
// debug info
if(beVerbose) {
cout << "Block found: " << static_cast<unsigned int>(currentSameBlock->targetOffset)
<< " " << static_cast<unsigned int>(currentSameBlock->size)
<< " (source offset=" << static_cast<unsigned int>(currentSameBlock->sourceOffset) << ")\n";
tout << _T("Block found: ") << static_cast<unsigned int>(currentSameBlock->targetOffset)
<< _T(" ") << static_cast<unsigned int>(currentSameBlock->size)
<< _T(" (source offset=") << static_cast<unsigned int>(currentSameBlock->sourceOffset) << _T(")\n");
}
currentOffset = currentSameBlock->targetOffset + currentSameBlock->size;
@ -172,8 +175,8 @@ SameBlock* PatchGenerator::findBlock(ChunkedFile* sourceTree,
if(beVerbose) {
if(maxMatches != 0) {
if(matchCount == maxMatches) {
cout << "[FindBlock] Abort due to >" << static_cast<unsigned int>(maxMatches)
<< " matches; file position = " << static_cast<unsigned int>(targetFileStartOffset) << "\n";
tout << _T("[FindBlock] Abort due to >") << static_cast<unsigned int>(maxMatches)
<< _T(" matches; file position = ") << static_cast<unsigned int>(targetFileStartOffset) << _T("\n");
}
}
}

View file

@ -22,6 +22,8 @@
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
// Reviewed for Unicode support by Jim Park -- 08/29/2007
#if !defined(PatchGenerator_H)
#define PatchGenerator_H

View file

@ -21,6 +21,8 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Reviewed for Unicode support by Jim Park -- 08/29/2007
(nothing changed.)
*/
#include "adler32.h"

View file

@ -1,6 +1,8 @@
//---------------------------------------------------------------------------
// Adler32
//---------------------------------------------------------------------------
//
// Reviewed for Unicode support by Jim Park -- 08/29/2007
#if !defined(Adler32_H)
#define Adler32_H

View file

@ -22,6 +22,8 @@
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
// Unicode support by Jim Park -- 08/29/2007
#ifdef __BORLANDC__
#pragma argsused
@ -31,10 +33,12 @@
#include <unistd.h>
#endif
#include "tchar.h"
#ifdef __WIN32__
#define OPT_CHAR '/'
#define OPT_CHAR _T('/')
#else
#define OPT_CHAR '-'
#define OPT_CHAR _T('-')
#endif
#include "GlobalTypes.h"
@ -46,14 +50,14 @@
#include <fstream>
#include <sstream>
int main( int argc, char * argv[] ) {
cout << "GenPat v3.1\n";
cout << "===========\n\n(c) 2001-2005 Van de Sande Productions\n";
cout << "Website: http://www.tibed.net/vpatch\n\n";
int _tmain( int argc, TCHAR * argv[] ) {
tout << _T("GenPat v3.1\n");
tout << _T("===========\n\n(c) 2001-2005 Van de Sande Productions\n");
tout << _T("Website: http://www.tibed.net/vpatch\n\n");
string sourceFileName;
string targetFileName;
string patchFileName;
tstring sourceFileName;
tstring targetFileName;
tstring patchFileName;
bool showHelp = true;
@ -65,30 +69,30 @@ int main( int argc, char * argv[] ) {
int fileNameArgument = 0;
if(argc > 1) {
for(int i = 1; i < argc; i++) {
string s(argv[i]);
tstring s(argv[i]);
if(s.size() > 0) {
if(s[0] == OPT_CHAR) {
if(s.size() > 1) {
if((s[1] == 'v') || (s[1] == 'V')) {
if((s[1] == _T('v')) || (s[1] == _T('V'))) {
beVerbose = true;
}
if((s[1] == 'o') || (s[1] == 'O')) {
if((s[1] == _T('o')) || (s[1] == _T('O'))) {
beOptimal = true;
}
if((s[1] == 'r') || (s[1] == 'R')) {
if((s[1] == _T('r')) || (s[1] == _T('R'))) {
existanceIsError = false;
}
}
if(s.size() > 2) {
if((s[1] == 'b') || (s[1] == 'B')) {
if(s[2] == '=') {
istringstream ss(s.substr(3));
if((s[1] == _T('b')) || (s[1] == _T('B'))) {
if(s[2] == _T('=')) {
tistringstream ss(s.substr(3));
ss >> blockSize;
}
}
if((s[1] == 'a') || (s[1] == 'A')) {
if(s[2] == '=') {
istringstream ss(s.substr(3));
if((s[1] == _T('a')) || (s[1] == _T('A'))) {
if(s[2] == _T('=')) {
tistringstream ss(s.substr(3));
ss >> maxMatches;
}
}
@ -106,7 +110,7 @@ int main( int argc, char * argv[] ) {
showHelp = false;
break;
default:
cerr << "WARNING: extra filename argument not used: " << s << "\n";
terr << _T("WARNING: extra filename argument not used: ") << s << _T("\n");
}
fileNameArgument++;
}
@ -117,45 +121,45 @@ int main( int argc, char * argv[] ) {
maxMatches = 0;
}
if(showHelp) {
cout << "This program will take (sourcefile) as input and create a (patchfile).\n";
cout << "With this patchfile, you can convert a (sourcefile) into (targetfile).\n\n";
cout << "Command line info:\n";
cout << " GENPAT (sourcefile) (targetfile) (patchfile)\n\n";
tout << _T("This program will take (sourcefile) as input and create a (patchfile).\n");
tout << _T("With this patchfile, you can convert a (sourcefile) into (targetfile).\n\n");
tout << _T("Command line info:\n");
tout << _T(" GENPAT (sourcefile) (targetfile) (patchfile)\n\n");
cout << "Command line option (optional):\n";
cout << OPT_CHAR << "R Replace a patch with same contents as source silently if it\n already exists.\n";
cout << OPT_CHAR << "B=64 Set blocksize (default=64), multiple of 2 is required.\n";
cout << OPT_CHAR << "V More verbose information during patch creation.\n";
cout << OPT_CHAR << "O Deactivate match limit of the " << OPT_CHAR << "A switch (sometimes smaller patches).\n";
cout << OPT_CHAR << "A=500 Maximum number of block matches per block (improves performance).\n";
cout << " Default is 500, larger is slower. Use " << OPT_CHAR << "V to see the cut-off aborts.\n\n";
cout << "Note: filenames should never start with " << OPT_CHAR << " character!\n\n";
cout << "Possible exit codes:\n";
cout << " 0 Success\n";
cout << " 1 Arguments missing\n";
cout << " 2 Other error\n";
cout << " 3 Source file already has a patch in specified patch file (=error)\n";
tout << _T("Command line option (optional):\n");
tout << OPT_CHAR << _T("R Replace a patch with same contents as source silently if it\n already exists.\n");
tout << OPT_CHAR << _T("B=64 Set blocksize (default=64), multiple of 2 is required.\n");
tout << OPT_CHAR << _T("V More verbose information during patch creation.\n");
tout << OPT_CHAR << _T("O Deactivate match limit of the ") << OPT_CHAR << _T("A switch (sometimes smaller patches).\n");
tout << OPT_CHAR << _T("A=500 Maximum number of block matches per block (improves performance).\n");
tout << _T(" Default is 500, larger is slower. Use ") << OPT_CHAR << _T("V to see the cut-off aborts.\n\n");
tout << _T("Note: filenames should never start with ") << OPT_CHAR << _T(" character!\n\n");
tout << _T("Possible exit codes:\n");
tout << _T(" 0 Success\n");
tout << _T(" 1 Arguments missing\n");
tout << _T(" 2 Other error\n");
tout << _T(" 3 Source file already has a patch in specified patch file (=error)\n");
return 1;
}
cout << "[Source] " << sourceFileName.c_str() << "\n";
cout << "[Target] " << targetFileName.c_str() << "\n[PatchFile] " << patchFileName.c_str() << "\n";
tout << _T("[Source] ") << sourceFileName.c_str() << _T("\n");
tout << _T("[Target] ") << targetFileName.c_str() << _T("\n[PatchFile] ") << patchFileName.c_str() << _T("\n");
// get the file sizes
TFileOffset sourceSize = 0;
try {
sourceSize = POSIX::getFileSize(sourceFileName.c_str());
}
catch(char* s) {
cerr << "Source file size reading failed: " << s << "\n";
catch(TCHAR* s) {
terr << _T("Source file size reading failed: ") << s << _T("\n");
return 2;
}
TFileOffset targetSize;
try {
targetSize = POSIX::getFileSize(targetFileName.c_str());
}
catch(const char* s) {
cerr << "Target file size reading failed: " << s << "\n";
catch(const TCHAR* s) {
terr << _T("Target file size reading failed: ") << s << _T("\n");
return 2;
}
@ -165,8 +169,8 @@ int main( int argc, char * argv[] ) {
TChecksum* targetCRC = new TChecksum(targetFileName);
targetCRC->mode = TChecksum::MD5; // default
string tempFileName = POSIX::getTempFile();
if (tempFileName == "")
tstring tempFileName = POSIX::getTempFile();
if (tempFileName == _T(""))
return 2;
// open the files
@ -183,8 +187,8 @@ int main( int argc, char * argv[] ) {
TFileOffset previousPatchSize = 0;
try {
previousPatchSize = POSIX::getFileSize(patchFileName.c_str());
} catch(const char* s) {
cout << "Patch file does not yet exist: " << s << ", it will be created.\n";
} catch(const TCHAR* s) {
tout << _T("Patch file does not yet exist: ") << s << _T(", it will be created.\n");
std::ofstream newfile;
newfile.open(patchFileName.c_str(), std::ios_base::binary | std::ios_base::out);
newfile.close();
@ -195,8 +199,8 @@ int main( int argc, char * argv[] ) {
try {
// this will copy the contents of previousPatch to patch, but without sourceCRC
fileCount = FileFormat1::removeExistingPatch(previousPatch,previousPatchSize,patch,sourceCRC,existanceIsError);
} catch(const char* s) {
cerr << "ERROR: " << s << "\n";
} catch(const TCHAR* s) {
terr << _T("ERROR: ") << s << _T("\n");
patch.close();
unlink(tempFileName.c_str());
return 3;
@ -204,9 +208,9 @@ int main( int argc, char * argv[] ) {
// set them to the same checksum mode
targetCRC->mode = sourceCRC->mode;
cout << "[Checksum] Kind of checksums used: ";
if(targetCRC->mode == TChecksum::MD5) cout << "MD5\n";
if(targetCRC->mode == TChecksum::CRC32) cout << "CRC32\n";
tout << _T("[Checksum] Kind of checksums used: ");
if(targetCRC->mode == TChecksum::MD5) tout << _T("MD5\n");
if(targetCRC->mode == TChecksum::CRC32) tout << _T("CRC32\n");
break;
}
@ -227,26 +231,26 @@ int main( int argc, char * argv[] ) {
}
if((blockSize >> 1) == orgBlockSize) blockSize = orgBlockSize;
if(blockSize != orgBlockSize) {
cout << "[BlockSizeFix] Your blocksize had to be fixed since it is not a multiple of 2\n";
tout << _T("[BlockSizeFix] Your blocksize had to be fixed since it is not a multiple of 2\n");
}
if(blockSize < 16) {
blockSize = 16;
cout << "[BlockSizeFix] Your blocksize had to be fixed since it is smaller than 16\n";
tout << _T("[BlockSizeFix] Your blocksize had to be fixed since it is smaller than 16\n");
}
gen->blockSize = blockSize;
cout << "[BlockSize] " << static_cast<unsigned int>(gen->blockSize) << " bytes\n";
tout << _T("[BlockSize] ") << static_cast<unsigned int>(gen->blockSize) << _T(" bytes\n");
gen->maxMatches = maxMatches;
if(gen->maxMatches == 0) {
cout << "[FindBlockMatchLimit] Unlimited matches\n";
tout << _T("[FindBlockMatchLimit] Unlimited matches\n");
} else {
cout << "[FindBlockMatchLimit] " << gen->maxMatches << " matches\n";
tout << _T("[FindBlockMatchLimit] ") << gen->maxMatches << _T(" matches\n");
}
gen->beVerbose = beVerbose;
if(beVerbose) {
cout << "[Debug] Verbose output during patch generation activated.\n";
tout << _T("[Debug] Verbose output during patch generation activated.\n");
}
// create sameBlock storage
@ -279,20 +283,20 @@ int main( int argc, char * argv[] ) {
std::ofstream clearF;
clearF.open(tempFileName.c_str(), std::ios_base::binary | std::ios_base::out);
}
catch(string s) {
cerr << "Error thrown: " << s.c_str();
catch(tstring s) {
terr << _T("Error thrown: ") << s.c_str();
return 2;
}
catch(const char* s) {
cerr << "Error thrown: " << s;
catch(const TCHAR* s) {
terr << _T("Error thrown: ") << s;
return 2;
}
} else {
cerr << "There was a problem opening the files.\n";
terr << _T("There was a problem opening the files.\n");
return 2;
}
if(*sourceCRC == *targetCRC)
cerr << "WARNING: source and target file have equal CRCs!";
terr << _T("WARNING: source and target file have equal CRCs!");
delete sourceCRC;
delete targetCRC;
unlink(tempFileName.c_str());

View file

@ -20,8 +20,9 @@
L. Peter Deutsch
ghost@aladdin.com
Reviewed for Unicode support by Jim Park -- 08/29/2007
*/
/* $Id: md5.c,v 1.6 2002/04/13 19:20:28 lpd Exp $ */
/* $Id: md5.c,v 1.1 2005/09/17 09:25:44 kichik Exp $ */
/*
Independent implementation of MD5 (RFC 1321).

View file

@ -20,8 +20,9 @@
L. Peter Deutsch
ghost@aladdin.com
Reviewed for Unicode support by Jim Park -- 08/29/2007
*/
/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */
/* $Id: md5.h,v 1.1 2005/09/17 09:25:44 kichik Exp $ */
/*
Independent implementation of MD5 (RFC 1321).

View file

@ -0,0 +1,28 @@
// Added for Unicode support by Jim Park -- 08/29/2007
#pragma once
#include <string>
#include <sstream>
#ifdef _UNICODE
# define tout wcout
# define terr wcerr
# define __T(x) L ## x
# define _T(x) __T(x)
# define _tmain wmain
# define _tunlink _wunlink
typedef std::wstring tstring;
typedef std::wistringstream tistringstream;
typedef wchar_t TCHAR;
#else
# define tout cout
# define terr cerr
# define _T(x) x
# define _tmain main
# define _tunlink _unlink
typedef std::string tstring;
typedef std::istringstream tistringstream;
typedef char TCHAR;
#endif

View file

@ -22,6 +22,8 @@
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
// Reviewed for Unicode support by Jim Park -- 08/29/2007
#include "apply_patch.h"
#include "checksum.h"

View file

@ -22,6 +22,8 @@
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
// Reviewed for Unicode support by Jim Park -- 08/29/2007
#ifndef apply_patch_INCLUDED
#define apply_patch_INCLUDED

View file

@ -22,6 +22,8 @@
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
// Reviewed for Unicode support by Jim Park -- 08/29/2007
#include "checksum.h"

View file

@ -22,6 +22,10 @@
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
// Reviewed for Unicode support by Jim Park -- 08/29/2007
// The functions return ANSI strings so we use PushStringA to push it on
// to the return stack correctly.
#ifndef checksum_INCLUDED
#define checksum_INCLUDED

View file

@ -20,8 +20,9 @@
L. Peter Deutsch
ghost@aladdin.com
Reviewed for Unicode support by Jim Park -- 08/29/2007
*/
/* $Id: md5.c,v 1.1 2005/09/17 09:25:44 kichik Exp $ */
/* $Id: md5.c,v 1.2 2005/09/20 17:42:28 kichik Exp $ */
/*
Independent implementation of MD5 (RFC 1321).

View file

@ -20,8 +20,10 @@
L. Peter Deutsch
ghost@aladdin.com
Reviewed for Unicode support by Jim Park -- 08/29/2007
*/
/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */
/* $Id: md5.h,v 1.1 2005/09/17 09:25:44 kichik Exp $ */
/*
Independent implementation of MD5 (RFC 1321).

View file

@ -22,6 +22,8 @@
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
// Unicode support by Jim Park -- 08/29/2007
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
@ -36,15 +38,15 @@ HINSTANCE g_hInstance;
HWND g_hwndParent;
void __declspec(dllexport) vpatchfile(HWND hwndParent, int string_size,
char *variables, stack_t **stacktop) {
TCHAR *variables, stack_t **stacktop) {
g_hwndParent=hwndParent;
EXDLL_INIT();
{
char source[MAX_PATH];
char dest[MAX_PATH];
char exename[MAX_PATH];
TCHAR source[MAX_PATH];
TCHAR dest[MAX_PATH];
TCHAR exename[MAX_PATH];
HANDLE hPatch, hSource, hDest;
int result;
@ -55,7 +57,7 @@ void __declspec(dllexport) vpatchfile(HWND hwndParent, int string_size,
hPatch = CreateFile(exename, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (hPatch == INVALID_HANDLE_VALUE) {
pushstring("Unable to open patch file");
pushstring(_T("Unable to open patch file"));
return;
}
@ -63,7 +65,7 @@ void __declspec(dllexport) vpatchfile(HWND hwndParent, int string_size,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (hSource == INVALID_HANDLE_VALUE) {
CloseHandle(hPatch);
pushstring("Unable to open source file");
pushstring(_T("Unable to open source file"));
return;
}
@ -72,7 +74,7 @@ void __declspec(dllexport) vpatchfile(HWND hwndParent, int string_size,
if (hDest == INVALID_HANDLE_VALUE) {
CloseHandle(hPatch);
CloseHandle(hSource);
pushstring("Unable to open output file");
pushstring(_T("Unable to open output file"));
return;
}
@ -84,16 +86,16 @@ void __declspec(dllexport) vpatchfile(HWND hwndParent, int string_size,
if ((result != PATCH_SUCCESS)) {
if (result == PATCH_ERROR)
pushstring("An error occured while patching");
pushstring(_T("An error occured while patching"));
else if (result == PATCH_CORRUPT)
pushstring("Patch data is invalid or corrupt");
pushstring(_T("Patch data is invalid or corrupt"));
else if (result == PATCH_NOMATCH)
pushstring("No suitable patches were found");
pushstring(_T("No suitable patches were found"));
else if (result == PATCH_UPTODATE)
pushstring("OK, new version already installed");
pushstring(_T("OK, new version already installed"));
DeleteFile(dest);
} else {
pushstring("OK");
pushstring(_T("OK"));
}
return;
@ -102,13 +104,13 @@ void __declspec(dllexport) vpatchfile(HWND hwndParent, int string_size,
#ifdef DLL_CHECKSUMS
void __declspec(dllexport) GetFileCRC32(HWND hwndParent, int string_size,
char *variables, stack_t **stacktop) {
TCHAR *variables, stack_t **stacktop) {
g_hwndParent=hwndParent;
EXDLL_INIT();
{
char filename[MAX_PATH];
TCHAR filename[MAX_PATH];
char crc_string[9];
HANDLE hFile;
unsigned long crc;
@ -119,17 +121,17 @@ void __declspec(dllexport) GetFileCRC32(HWND hwndParent, int string_size,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (hFile == INVALID_HANDLE_VALUE) {
//pushstring("ERROR: Unable to open file for CRC32 calculation");
pushstring("");
pushstring(_T(""));
return;
}
if (!FileCRC(hFile, &crc)) {
//pushstring("ERROR: Unable to calculate CRC32");
pushstring("");
pushstring(_T(""));
} else {
crc_string[8] = '\0';
CRC32ToString(crc_string,crc);
pushstring(crc_string);
PushStringA(crc_string);
}
CloseHandle(hFile);
@ -137,13 +139,13 @@ void __declspec(dllexport) GetFileCRC32(HWND hwndParent, int string_size,
}
void __declspec(dllexport) GetFileMD5(HWND hwndParent, int string_size,
char *variables, stack_t **stacktop) {
TCHAR *variables, stack_t **stacktop) {
g_hwndParent=hwndParent;
EXDLL_INIT();
{
char filename[MAX_PATH];
TCHAR filename[MAX_PATH];
char md5_string[33];
HANDLE hFile;
md5_byte_t digest[16];
@ -154,17 +156,17 @@ void __declspec(dllexport) GetFileMD5(HWND hwndParent, int string_size,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (hFile == INVALID_HANDLE_VALUE) {
//pushstring("ERROR: Unable to open file for MD5 calculation");
pushstring("");
pushstring(_T(""));
return;
}
if (!FileMD5(hFile, digest)) {
//pushstring("ERROR: Unable to calculate MD5");
pushstring("");
pushstring(_T(""));
} else {
md5_string[32] = '\0';
MD5ToString(md5_string,digest);
pushstring(md5_string);
PushStringA(md5_string);
}
CloseHandle(hFile);