Unicode fixes

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6216 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2012-02-28 22:40:43 +00:00
parent 615ce82030
commit 382b2fa282
11 changed files with 150 additions and 49 deletions

View file

@ -49,8 +49,93 @@
#endif
typedef uint32_t TFileOffset;
typedef ifstream bifstream;
typedef istream bistream;
typedef ofstream bofstream;
typedef ostream bostream;
// This is a hacky partial replacement for <i|o>[f]stream so we can open wchar_t*
#include "tchar.h"
#include <stdio.h>
#include <assert.h>
class simplebfstream {
FILE*m_File;
ios_base::iostate m_state;
streamsize m_LastReadCount;
public:
simplebfstream() : m_File(0), m_state(ios_base::badbit|ios_base::failbit) {}
~simplebfstream()
{
if (m_File) fclose(m_File);
}
bool open(const TCHAR*filename, ios_base::openmode mode)
{
TCHAR mAcc, mFmt = _T('b');
if (ios::in&mode) mAcc = _T('r');
if (ios::out&mode) mAcc = _T('w');
assert(0==(mode&~(ios::in|ios::binary|ios::out)));
TCHAR modestr[3] = {mAcc, mFmt, _T('\0')};
m_File = FOPEN(filename, modestr);
m_state = m_File ? ios_base::goodbit : ios_base::badbit|ios_base::failbit;
return good();
}
void close()
{
if (!m_File || fclose(m_File))
{
m_state |= ios_base::failbit;
}
m_File = 0;
}
bool is_open() const {return !!m_File;}
bool eof() const {return !!(ios_base::eofbit & m_state);}
bool bad() const {return !!(ios_base::badbit & m_state);}
bool fail() const {return !!((ios_base::failbit|ios_base::badbit) & m_state);}
bool good() const {return ios_base::goodbit==m_state;}
streamsize gcount() const {return m_LastReadCount;}
streampos tellg() const {return ftell(m_File);}
simplebfstream& read(char*s,streamsize n)
{
size_t cbio = fread(s, 1, n, m_File);
m_LastReadCount = cbio;
if (cbio != n)
{
m_state |= ferror(m_File) ? ios_base::badbit : (ios_base::eofbit|ios_base::failbit);
}
return *this;
}
simplebfstream& seekg(streamoff off, ios_base::seekdir dir)
{
int origin = ios_base::beg==dir ? SEEK_SET : ios_base::cur==dir ? SEEK_CUR : SEEK_END;
if (fseek(m_File, off, origin))
{
// BUGBUG: Does not follow standard
m_state |= ios_base::badbit|ios_base::failbit;
}
return *this;
}
simplebfstream& seekp(streamoff off, ios_base::seekdir dir) {return seekg(off, dir);}
streampos tellp() const {return tellg();}
simplebfstream& write(const char* s, streamsize n)
{
size_t cbio = fwrite(s, 1, n, m_File);
if (cbio != n) m_state |= ios_base::badbit;
return *this;
}
bool operator ! () const {return fail();}
};
typedef simplebfstream bistream;
typedef bistream bifstream;
typedef simplebfstream bostream;
typedef bostream bofstream;
#endif // GlobalTypes_H

View file

@ -91,7 +91,7 @@ namespace POSIX {
#endif
uint32_t getFileSize(const TCHAR* sFileName) {
std::ifstream f;
bifstream f;
f.open(sFileName, std::ios_base::binary | std::ios_base::in);
if (!f.good() || f.eof() || !f.is_open()) {
throw _T("File could not be read (getFileSize)");

View file

@ -35,11 +35,17 @@
#include "tchar.h"
#ifdef __WIN32__
#if defined(__WIN32__) || defined(_WIN32)
#define OPT_CHAR _T('/')
#else
#define OPT_CHAR _T('-')
#endif
const TCHAR OPT_CHARSTR[] = {OPT_CHAR, _T('\0')} ;
// Win32 now supports "/" AND "-" switches (like makensis) but the filename warning only makes sense for "-"
#define OPT_FSCONFLICTCHARSTR _T("-")
inline bool ISSINGLESWITCHCHAR(const TCHAR c) { return ( OPT_CHAR==(c) || (OPT_CHAR!=_T('-') && _T('-')==(c)) ); }
#undef OPT_CHAR
#include "GlobalTypes.h"
#include "POSIXUtil.h"
@ -71,7 +77,7 @@ int _tmain( int argc, TCHAR * argv[] ) {
for(int i = 1; i < argc; i++) {
tstring s(argv[i]);
if(s.size() > 0) {
if(s[0] == OPT_CHAR) {
if(ISSINGLESWITCHCHAR(s[0])) {
if(s.size() > 1) {
if((s[1] == _T('v')) || (s[1] == _T('V'))) {
beVerbose = true;
@ -127,13 +133,13 @@ int _tmain( int argc, TCHAR * argv[] ) {
tout << _T(" GENPAT (sourcefile) (targetfile) (patchfile)\n\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 << OPT_CHARSTR << _T("R Replace a patch with same contents as source silently if it\n already exists.\n");
tout << OPT_CHARSTR << _T("B=64 Set blocksize (default=64), multiple of 2 is required.\n");
tout << OPT_CHARSTR << _T("V More verbose information during patch creation.\n");
tout << OPT_CHARSTR << _T("O Deactivate match limit of the ") << OPT_CHARSTR << _T("A switch (sometimes smaller patches).\n");
tout << OPT_CHARSTR << _T("A=500 Maximum number of block matches per block (improves performance).\n");
tout << _T(" Default is 500, larger is slower. Use ") << OPT_CHARSTR << _T("V to see the cut-off aborts.\n\n");
tout << _T("Note: filenames should never start with ") << OPT_FSCONFLICTCHARSTR << _T(" character!\n\n");
tout << _T("Possible exit codes:\n");
tout << _T(" 0 Success\n");
tout << _T(" 1 Arguments missing\n");
@ -189,7 +195,7 @@ int _tmain( int argc, TCHAR * argv[] ) {
previousPatchSize = POSIX::getFileSize(patchFileName.c_str());
} catch(const TCHAR* s) {
tout << _T("Patch file does not yet exist: ") << s << _T(", it will be created.\n");
std::ofstream newfile;
bofstream newfile;
newfile.open(patchFileName.c_str(), std::ios_base::binary | std::ios_base::out);
newfile.close();
}
@ -280,7 +286,7 @@ int _tmain( int argc, TCHAR * argv[] ) {
tempF.close();
// now empty the temporary file
std::ofstream clearF;
bofstream clearF;
clearF.open(tempFileName.c_str(), std::ios_base::binary | std::ios_base::out);
}
catch(tstring s) {

View file

@ -10,6 +10,7 @@
# define _T(x) __T(x)
# define _tmain wmain
# define _tunlink _wunlink
# define FOPEN _wfopen
typedef std::wstring tstring;
typedef std::wistringstream tistringstream;
@ -21,6 +22,7 @@
# define _T(x) x
# define _tmain main
# define _tunlink _unlink
# define FOPEN fopen
typedef std::string tstring;
typedef std::istringstream tistringstream;