Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- Source/build.cpp Tue Oct 18 16:30:26 2011
- +++ Source/build.cpp Tue Oct 18 18:25:31 2011
- @@ -121,6 +121,9 @@
- multiple_entries_instruction=0;
- build_include_depth=0;
- +#ifndef _UNICODE
- + build_include_isutf8=false;
- +#endif
- has_called_write_output=false;
- --- Source/build.h Tue Oct 18 16:30:26 2011
- +++ Source/build.h Tue Oct 18 19:18:29 2011
- @@ -328,6 +328,9 @@
- * this will return a PS_WARNING.
- */
- int SetLangString(TCHAR *name, LANGID lang, const TCHAR *str, BOOL unicode);
- +#ifndef _UNICODE
- + int SetUTF8LangString(TCHAR *name, LANGID lang, const char* stru8);
- +#endif
- /**
- * Sets the user string to the specific NLF_STRINGS id.
- @@ -424,6 +427,9 @@
- TCHAR build_output_filename[1024];
- int build_include_depth;
- +#ifndef _UNICODE
- + bool build_include_isutf8; // UTF-8 LangString in .nsh hack for ANSI builds
- +#endif
- // Added by ramon 6 jun 2003
- #ifdef NSIS_SUPPORT_VERSION_INFO
- --- Source/lang.cpp Tue Oct 18 16:30:26 2011
- +++ Source/lang.cpp Tue Oct 18 23:12:13 2011
- @@ -26,6 +26,7 @@
- #include "exehead/resource.h"
- #include <nsis-version.h>
- #include "tstring.h"
- +#include "utf.h"
- using namespace std;
- @@ -502,6 +503,21 @@
- return PS_OK;
- }
- +#ifndef _UNICODE
- +int CEXEBuild::SetUTF8LangString(TCHAR *name, LANGID lang, const char* stru8)
- +{
- + LanguageTable *table = GetLangTable(lang);
- + if (!table) return PS_ERROR;
- + if (!Platform_SupportsUTF8Conversion()) return PS_ERROR;
- +
- + WINTCHAR_T* bufWinTStr = UTF8ToWinTStr(stru8, table->nlf.m_uCodePage);
- + if (!bufWinTStr) return PS_ERROR;
- + const int ret = SetLangString(name, lang, bufWinTStr, sizeof(TCHAR)>1);
- + WinTStrFree(bufWinTStr);
- + return ret;
- +}
- +#endif
- +
- // Sets the user string to the specific NLF_STRINGS id.
- //
- // @return If the id is invalid or the string is not valid, it will return a
- @@ -925,6 +941,12 @@
- return 0;
- }
- +#ifndef _UNICODE
- + // 0 = ansi, 8 = utf-8 (16/17 for uft-16le/be not supported)
- + char fencoding = 0;
- + if (IsUTF8BOM(f)) fencoding = 8;
- +#endif
- +
- // Check header
- TCHAR buf[NSIS_MAX_STRLEN];
- buf[0] = SkipComments(f);
- @@ -1096,8 +1118,33 @@
- buf[0] = SkipComments(f);
- _fgetts(buf+1, NSIS_MAX_STRLEN, f);
- +
- +#ifndef _UNICODE
- + if (8 == fencoding)
- + {
- + if (!Platform_SupportsUTF8Conversion()) {
- + ERROR_MSG(_T("Error: UTF-8 language files not supported on this OS!\n"));
- + return 0;
- + }
- + WINTCHAR_T* bufConv = UTF8ToWinTStr(buf, nlf->m_uCodePage);
- + if (!bufConv) {
- + ERROR_MSG(_T("Error: Invalid UTF-8? (string #%d - \"%s\")\n"), i, NLFStrings[i].szLangStringName);
- + return 0;
- + }
- + else {
- + //NOTE: All this string handling code needs to use WinTStr* and not _t* under UNICODE+POSIX
- + UINT cch = _tcslen(bufConv);
- + _tcsnccpy(buf, bufConv, NSIS_MAX_STRLEN);
- + if (cch >= NSIS_MAX_STRLEN-1) {
- + buf[NSIS_MAX_STRLEN-1] = _T('\0'); // Make sure we fail the "String too long" check
- + }
- + }
- + WinTStrFree(bufConv);
- + }
- +#endif
- +
- if (_tcslen(buf) == NSIS_MAX_STRLEN-1) {
- - ERROR_MSG(_T("Error: String too long (string #%d - \"%s\")"), i, NLFStrings[i].szLangStringName);
- + ERROR_MSG(_T("Error: String too long (string #%d - \"%s\")\n"), i, NLFStrings[i].szLangStringName);
- return 0;
- }
- temp=_tcslen(buf);
- --- Source/SConscript Tue Oct 18 16:30:26 2011
- +++ Source/SConscript Tue Oct 18 18:59:47 2011
- @@ -24,6 +24,7 @@
- strlist.cpp
- tokens.cpp
- tstring.cpp
- + utf.cpp
- util.cpp
- validateunicode.cpp
- winchar.cpp
- --- Source/script.cpp Tue Oct 18 16:30:26 2011
- +++ Source/script.cpp Tue Oct 18 22:39:14 2011
- @@ -36,6 +36,7 @@
- #include "tstring.h"
- #include <algorithm>
- #include "boost/scoped_ptr.hpp"
- +#include "utf.h"
- using namespace std;
- @@ -787,6 +788,10 @@
- return PS_ERROR;
- }
- build_include_depth++;
- +#ifndef _UNICODE
- + const bool org_build_include_isutf8 = build_include_isutf8;
- + build_include_isutf8 = IsUTF8BOM(incfp);
- +#endif
- int last_linecnt=linecnt;
- linecnt=0;
- @@ -811,6 +816,10 @@
- restore_timestamp_predefine(oldtimestamp);
- #endif
- +#ifndef _UNICODE
- + build_include_isutf8 = org_build_include_isutf8;
- +#endif
- +
- int errlinecnt=linecnt;
- linecnt=last_linecnt;
- @@ -1620,13 +1629,21 @@
- TCHAR *name = line.gettoken_str(1);
- LANGID lang = line.gettoken_int(2);
- TCHAR *str = line.gettoken_str(3);
- - int ret = SetLangString(name, lang, str, curfile_unicode);
- + int ret;
- +#ifndef _UNICODE
- + if (build_include_isutf8)
- + ret = SetUTF8LangString(name, lang, str);
- + else
- +#endif
- + ret = SetLangString(name, lang, str, curfile_unicode);
- + // BUGBUG: TODO: Warn if langstring is > NSIS_MAX_STRLEN ?
- if (ret == PS_WARNING)
- warning_fl(_T("LangString \"%s\" set multiple times for %d, wasting space"), name, lang);
- else if (ret == PS_ERROR) {
- ERROR_MSG(_T("Error: can't set LangString \"%s\"!\n"), name);
- return PS_ERROR;
- }
- + //BUGBUG: Does not display UTF-8 properly.
- SCRIPT_MSG(_T("LangString: \"%s\" %d \"%s\"\n"), name, lang, str);
- }
- return PS_OK;
- --- Source/util.cpp Tue Oct 18 16:30:26 2011
- +++ Source/util.cpp Tue Oct 18 21:10:08 2011
- @@ -209,7 +209,7 @@
- int WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr,
- int cchWideChar, LPSTR lpMultiByteStr, int cbMultiByte, LPCSTR lpDefaultChar,
- LPBOOL lpUsedDefaultChar) {
- - static char buffer[4096];
- + static char buffer[4096]; // BUGBUG: Should this be 4*NSIS_MAX_STRLEN for large string build?
- char cp[128];
- create_code_page_string(cp, sizeof(cp), CodePage);
- @@ -245,7 +245,7 @@
- int MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr,
- int cbMultiByte, LPWSTR lpWideCharStr, int cchWideChar) {
- - static WCHAR buffer[4096];
- + static WCHAR buffer[4096]; // BUGBUG: Should this be 4*NSIS_MAX_STRLEN for large string build?
- char cp[128];
- create_code_page_string(cp, sizeof(cp), CodePage);
- @@ -847,3 +847,15 @@
- return false;
- }
- +
- +#ifdef _WIN32
- +BOOL Platform_IsWin95()
- +{
- + OSVERSIONINFO ovi;
- + ovi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- + GetVersionEx(&ovi);
- + return VER_PLATFORM_WIN32_WINDOWS == ovi.dwPlatformId &&
- + 4 == ovi.dwMajorVersion &&
- + ovi.dwMinorVersion < 10;
- +}
- +#endif
- \ No newline at end of file
- --- Source/util.h Tue Oct 18 16:30:26 2011
- +++ Source/util.h Tue Oct 18 21:13:24 2011
- @@ -159,4 +159,16 @@
- # define PATH_CONVERT(x)
- #endif
- +// Platform detection
- +#ifndef _WIN32
- +# define Platform_IsWin95() (FALSE)
- +#else
- +# ifndef _UNICODE
- + BOOL Platform_IsWin95();
- +# else
- +# define Platform_IsWin95() (FALSE)
- +# endif
- +#endif
- +#define Platform_SupportsUTF8Conversion() ( !Platform_IsWin95() ) // TODO: MSLU supports UTF-8 on Win95
- +
- #endif //_UTIL_H_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement