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

Windows: declare UTF-8 through manifest #96

Merged
merged 1 commit into from
Feb 24, 2025

Conversation

scurest
Copy link
Contributor

@scurest scurest commented Feb 21, 2025

Fixes #61. Fixes #86.

Attaches a manifest to Windows .exes which makes char*s (narrow char strings) like argv be encoded in UTF-8, allowing tools to operate on files that can't be written in the system's narrow char encoding (eg. Japanese filenames on a Latin-1 system).

This is basically copy-pasted from the way libjxl/libavif does it.

All the tools are changed except xyz-thumbnailer (I didn't look into that one).

For lmu2png specifically, I believe it also fixes a bug where a narrow char path and a UTF-8 string are concatenated. This implicitly assumes the narrow char encoding is UTF-8. Previously, Japanese games wouldn't work on Windows even when the system narrow char encoding was Shift JIS.

More points:

  • Will not work on Windows older than Windows 10 2019 update.
  • I only tested lmu2png and png2xyz.
  • This is cmake only, I have no idea how to update autotools. (Does autotools run on Windows?)
  • As Ghabry says, mingw is not tested.
  • The manifest files are located in resources/. Tell me if you want them somewhere else.

@scurest scurest changed the title Windows: decalre UTF-8 through manifest Windows: declare UTF-8 through manifest Feb 21, 2025
@Ghabry
Copy link
Member

Ghabry commented Feb 21, 2025

Jenkins: test this please

Thanks. Though we have no way to test the mingw path

@scurest scurest marked this pull request as ready for review February 21, 2025 21:15
@carstene1ns
Copy link
Member

The relative paths to the manifest will break when you try to build a tool separate from e.g. archive checkout. For the "external" folder, I used symlinks, since they are supported on desktop platforms and git will make copies when archiving.

Do not worry too much about autotools, it will be removed in the future anyway. Mingw building is unsupported, so can be fixed when actually used.

@scurest
Copy link
Contributor Author

scurest commented Feb 22, 2025

The relative paths to the manifest will break when you try to build a tool separate from e.g. archive checkout.

Can you explain this in more detail please?


I do notice two problems. My intention was to give the path to the manifest relative to the Modules/ConfigureWindows.cmake file. But

  1. Using CMAKE_CURRENT_LIST_DIR is wrong for this. What I want is CMAKE_CURRENT_FUNCTION_LIST_DIR, which gives the path relative to where the function is defined, not called. Since that requires CMake 3.17 and this repo uses 3.16, I can use the pattern with a global variable shown on that doc page instead. But if I do that...
  2. Since Modules/ is included via symlink, the relative path (eg) lmu2png/CMakeModules/../resources/ leads to the non-existent lmu2png/resources/ instead of the desired Modules/../resources/. So I need to take the realpath to the ConfigureWindows.cmake dir too.

Putting those together, gives

get_filename_component(_CONFIGURE_WINDOWS_BASE_DIR "${CMAKE_CURRENT_LIST_DIR}" REALPATH)

function(target_use_utf8_codepage_on_windows target)
	set(RESOURCES_DIR "${_CONFIGURE_WINDOWS_BASE_DIR}/../resources")
	...

Does that look right?

@Ghabry
Copy link
Member

Ghabry commented Feb 22, 2025

He means that all files you access from within a tool must be inside the tool directory. So e.g. for xyz2png the resource must be somewhere in the xyz2png directory.

Iirc the command to create directory symlinks on Windows is mklink /D

So in every directory that references the resources you must do resources you must do mklink /D resources ..\resources. Then git add them.

And in ConfigureWindows change the target sources to resources/utf8.manifest.


In case this doesn't work because symlinks on Windows are a bit weird: I can add the commit for you.

@scurest
Copy link
Contributor Author

scurest commented Feb 22, 2025

He means that all files you access from within a tool must be inside the tool directory.

Why?

@Ghabry
Copy link
Member

Ghabry commented Feb 22, 2025

As c1 explained

The relative paths to the manifest will break when you try to build a tool separate from e.g. archive checkout.

The tool we use to create the final distribution archive resolves the symlinks and converts them back to "normal" files

@scurest
Copy link
Contributor Author

scurest commented Feb 22, 2025

I'm not sure why you use symlinks at all then but I guess it doesn't matter here.

So I should symlink resources->../resources in all the tool folders? Alternatively the utf8.manifest could be moved to Modules/. And do you want the .rc file if mingw isn't supported? (it's only used for that)

@Ghabry
Copy link
Member

Ghabry commented Feb 22, 2025

yeah pls symlink resources in all folders. You can keep the mingw rc file. It doesn't hurt even if untested :)

Should make tools work on non-ASCII paths.
@scurest
Copy link
Contributor Author

scurest commented Feb 22, 2025

Will CI run automatically or...?

@scurest
Copy link
Contributor Author

scurest commented Feb 22, 2025

Thanks.

Okay, how does that look? I can confirm it still works for me. Can anyone else test it?

@fdelapena
Copy link
Contributor

Sorry for the late reply, any suggested game file for testing this quickly?

@Ghabry
Copy link
Member

Ghabry commented Feb 24, 2025

You can use the Japanese version of Yume Nikki from here https://rmarchiv.de/games/1089

2007-10-01 Vollversion - 0.10

just e.g. pass a Japanese filename to xyz2png etc.

@fdelapena
Copy link
Contributor

Tested latest pr build from https://ci.easyrpg.org/job/tools-win32-pr/211/

imagen

Tried xyzcrush on Windows 11 24H2. I guess globbing is broken (possibly unrelated different bug), but on a codepage 1252 is not showing characters at least. But converting with xyz2png works as expected and the output file now exists with same Japanese filename with extension .png.

imagen

lmu2png also shows garbled characters without setting encoding at least.
When adding -e 932, it works without errors and outputs Map0001.png as expected:
imagen

@fdelapena
Copy link
Contributor

fdelapena commented Feb 24, 2025

imagen

The visual glitch goes away with chcp 65001, but commands work as expected.

@scurest
Copy link
Contributor Author

scurest commented Feb 24, 2025

@fdelapena

Yes, that's all correct.

Globbing is the responsibility of each program on Windows, the shell doesn't do it. There's an .obj you can link to to supposedly do it for you though, /link setargv.obj. But yeah, that's a different issue.

Copy link
Member

@carstene1ns carstene1ns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@Ghabry Ghabry merged commit 0e95909 into EasyRPG:master Feb 24, 2025
3 checks passed
@scurest scurest deleted the windows-utf8 branch February 24, 2025 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Windows: Declare UTF-8 through manifest lmu2png does not work with Japanese file names
4 participants