Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ffhome opened this issue May 17, 2020 · 7 comments
Open

Comments

@ffhome
Copy link

ffhome commented May 17, 2020

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
Copy link

uaevuon commented May 17, 2020

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
Copy link

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
Copy link

Thesola10 commented Apr 13, 2022

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
Copy link
Owner

SciresM commented Apr 13, 2022

@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
Copy link

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
Copy link
Owner

SciresM commented Apr 13, 2022

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
Copy link

Guss42 commented Jun 19, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants