SciresM / hactool

hactool is a tool to view information about, decrypt, and extract common file formats for the Nintendo Switch, especially Nintendo Content Archives.
ISC License
982 stars 151 forks source link

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

Open ffhome opened 4 years ago

ffhome commented 4 years ago

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)

uaevuon commented 4 years ago

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.

gyorokpeter commented 3 years ago

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
}
Thesola10 commented 2 years ago

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.

SciresM commented 2 years ago

@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.

Thesola10 commented 2 years ago

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.

SciresM commented 2 years ago

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

Guss42 commented 4 weeks ago

@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