Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions WinHTTrack/Shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ httrackp *global_opt = NULL;
extern "C" {
HTSEXT_API void qsec2str(char *st,TStamp t);
HTSEXT_API char *hts_convertStringSystemToUTF8(const char *s, size_t size);
HTSEXT_API char *hts_convertStringUTF8ToSystem(const char *s, size_t size);
}

// construction index général
Expand Down Expand Up @@ -1676,6 +1677,18 @@ char *strdupt_utf8(const char *const s) {
return utf8 != NULL ? utf8 : strdupt(s);
}

// The other direction, for the ANSI-only Win32 calls left in this MBCS build.
// Contract in Shell.h.
void CopyTextUTF8ToCP(LPSTR dest, int destSize, LPCSTR lpString) {
if (destSize <= 0)
return;
// freet() nulls its argument, so not const.
char *cp = hts_convertStringUTF8ToSystem(lpString, strlen(lpString));
// On failure the raw bytes beat showing nothing at all.
lstrcpynA(dest, cp != NULL ? cp : lpString, destSize);
freet(cp);
}

bool ShellOpen(LPCSTR file, int nShowCmd) {
return (INT_PTR) ShellExecute(NULL, "open", file, NULL, NULL, nShowCmd) > 32;
}
Expand Down
5 changes: 5 additions & 0 deletions WinHTTrack/Shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ extern const char* WhttLocation;
// Caller frees with freet(); returns the bytes unchanged if conversion fails, never NULL.
char *strdupt_utf8(const char *const s);

// The reverse: copy a UTF-8 string into dest as the ANSI codepage, always
// NUL-terminated. For the ANSI-only APIs left in this MBCS build, such as
// TTN_NEEDTEXTA tooltip text. Falls back to the raw bytes if conversion fails.
void CopyTextUTF8ToCP(LPSTR dest, int destSize, LPCSTR lpString);

// Drop a trailing '/' or '\\', reporting whether there was one. Empty-string safe.
inline bool StripTrailingSlash(char* s) {
const size_t len = (s != NULL) ? strlen(s) : 0;
Expand Down
11 changes: 0 additions & 11 deletions WinHTTrack/newlang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,17 +624,6 @@ static _bstr_t ConvertCodepage(LPCSTR str, UINT codePage)
return returnValue;
}

void CopyTextUTF8ToCP(LPSTR dest, int destSize, LPCSTR lpString) {
if (destSize <= 0)
return;
_bstr_t s = ConvertCodepage(lpString, CP_UTF8);
if (s.length() != 0
&& WideCharToMultiByte(CP_ACP, 0, s, -1, dest, destSize, NULL, NULL) > 0)
return;
// Not valid UTF-8, or longer than dest: hand back the raw bytes rather than nothing.
lstrcpynA(dest, lpString, destSize);
}

BOOL SetDlgItemTextCP(HWND hDlg, int nIDDlgItem, LPCSTR lpString) {
if (NewLangCP != CP_THREAD_ACP)
return SetDlgItemTextW(hDlg, nIDDlgItem, ConvertCodepage(lpString, NewLangCP));
Expand Down
4 changes: 0 additions & 4 deletions WinHTTrack/newlang.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,5 @@ BOOL SetWindowTextUTF8(CWnd* wnd, LPCSTR lpString);
BOOL ModifyMenuCP(HMENU hMnu, UINT uPosition, UINT uFlags, UINT uIDNewItem, LPCSTR lpNewItem);
BOOL ModifyMenuCP(CMenu* menu, UINT uPosition, UINT uFlags, UINT uIDNewItem, LPCSTR lpNewItem);

/* UTF-8 -> the ANSI codepage, into dest (always NUL-terminated). For the ANSI-only
APIs left in this MBCS build, such as TTN_NEEDTEXTA tooltip text. */
void CopyTextUTF8ToCP(LPSTR dest, int destSize, LPCSTR lpString);

#endif

Loading