hactool icon indicating copy to clipboard operation
hactool copied to clipboard

Error: Failed to convert C:\Users\李明(Some wide characters) to UTF-16!

Open ffhome opened this issue 5 years ago • 7 comments

I'm from China. In my Windows 10 Simplified Chinese, I found a problem that if you log in Windows with a user name in Chinese, the software will show an error: Failed to convert C:\Users\李明 to UTF-16! If you log in with an English username, everything's fine. In Windows, character encoding is ANSI, like GB2312. In Linux, it's UTF8. Is there a problem here? I would appreciate it if you could fix this. Thanks. (My operating environment: hactool 1.33, Windows 10 Simplified Chinese Version 2004 x64)

ffhome avatar May 17 '20 04:05 ffhome

Just don't use folders and files name other than ascii. Not just hactool, every other programs can cause issue. Using user name as CJK on windows messes up everything.

uaevuon avatar May 17 '20 06:05 uaevuon

It is because the program assumes that the paths read from %HOME%, %USERPROFILE% etc. are in UTF-8, while normally they are in your system locale. I changed the code to the following in filepath.c, not sure if it doesn't introduce any other bugs:

void os_strcpy(oschar_t *dst, const char *src) {
#ifdef _WIN32
    if (src == NULL) return;
    size_t srcLen = strlen(src);
    int requiredSize = MultiByteToWideChar(CP_ACP,0,src,srcLen,0,0);
    if (requiredSize > MAX_PATH-1) {
        fprintf(stderr, "Failed to convert %s to UTF-16: required size too large!\n", src);
        exit(EXIT_FAILURE);
    }
    int retval = MultiByteToWideChar(CP_ACP,0,src,srcLen,dst,requiredSize);
    if (!retval) {
        fprintf(stderr, "Failed to convert %s to UTF-16!\n", src);
        exit(EXIT_FAILURE);
    }
#else
    strcpy(dst, src);
#endif
}

gyorokpeter avatar Jul 10 '21 20:07 gyorokpeter

~~windows can be a real pain sometimes~~ I plan on including a Python-based frontend to my (currently wip) wrapper around hactool, this will probably fix all file-related issues, since Python can handle multiple encodings without issue.

Thesola10 avatar Apr 13 '22 18:04 Thesola10

@Thesola10 hactool isn't really maintained or maintainable any more fyi.

Its replacement is currently a work in progress, and unicode should work fine with it.

SciresM avatar Apr 13 '22 18:04 SciresM

Cool! Do you have a rough timeframe as to when that tool might be ready, so I know if I should keep working on my wrapper or wait for the new tool? I'm trying to automate my translation patcher so I'll probably need to make a Python wrapper anyway.

Thesola10 avatar Apr 13 '22 18:04 Thesola10

I don't like to provide ETAs, as a matter of course. Source for the wip stuff is available at Atmosphere-NX/hac2l though.

SciresM avatar Apr 13 '22 18:04 SciresM

@SciresM this comment does nothing related to this issue, but as I start a project to get some data about game from nintendo cdn, from my research I seen your name on many pages, and I wish to ask you some question to get more information that can be helpfull for my project and help me to win some time), and I haven't some ohter place where I have an account to contact you.

feel free to choose the wayto contact you if you are agree to discuss with me, just delete this message else. thanks for reading, hope to get news from you.

thread example where your answers looks use full: https://gbatemp.net/threads/hacdn-download-game-nca-files-directly-from-nintendos-cdn.503847/page-5#post-7973812

Guss42 avatar Jun 19 '24 20:06 Guss42