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

OpenInExplorer doesn't work with paths with non english characters. #548

Closed
Naahuel opened this issue Jan 6, 2025 · 7 comments · Fixed by #549
Closed

OpenInExplorer doesn't work with paths with non english characters. #548

Naahuel opened this issue Jan 6, 2025 · 7 comments · Fixed by #549

Comments

@Naahuel
Copy link
Contributor

Naahuel commented Jan 6, 2025

Hello!

Currently using DT 5.0 in Windows 11 with Lua API 9.4.0.

I read another issue that reported something similar and the reply was that #437 would fix the issue but apparently not for this script.

It works ok with paths with only english characters. I've modified the script to log the paths and commands it's tryint to open and they are Ok, not sure where it fails (it says LUA result from windows command was 1).

Here's the log with some example paths I tried. Notice the ones with accentuated characters fail (with the word "montaña")

darktable 5.0.0
Copyright (C) 2012-2024 Johannes Hanika and other contributors.

Compile options:
  Bit depth              -> 64 bit
  Debug                  -> DISABLED
  SSE2 optimizations     -> ENABLED
  OpenMP                 -> ENABLED
  OpenCL                 -> ENABLED
  Lua                    -> ENABLED  - API version 9.4.0
  Colord                 -> DISABLED
  gPhoto2                -> ENABLED
  GMIC                   -> ENABLED  - Compressed LUTs are supported
  GraphicsMagick         -> ENABLED
  ImageMagick            -> DISABLED
  libavif                -> ENABLED
  libheif                -> ENABLED
  libjxl                 -> ENABLED
  LibRaw                 -> ENABLED  - Version 0.22.0-Devel202403
  OpenJPEG               -> ENABLED
  OpenEXR                -> ENABLED
  WebP                   -> ENABLED

See https://www.darktable.org/resources/ for detailed documentation.
See https://github.com/darktable-org/darktable/issues/new/choose to report bugs.

     0.0002 [dt starting]
 C:\Program Files\darktable\bin\darktable -d lua
'xdg-user-dir' is not recognized as an internal or external command,
operable program or batch file.
    27.1862 LUA Windows path = E:\fotografia\olympus-35-rd\fuji-200\2024\12\08-21 -- varios calle luz dorada golden light navidad papa noel palomas gente frente casas guille yo espejo reflejo\23304.jpg
    27.1862 LUA Windows command = explorer.exe /select, "E:\fotografia\olympus-35-rd\fuji-200\2024\12\08-21 -- varios calle luz dorada golden light navidad papa noel palomas gente frente casas guille yo espejo reflejo\23304.jpg"
    27.1862 LUA OpenInExplorer run_cmd = explorer.exe /select, "E:\fotografia\olympus-35-rd\fuji-200\2024\12\08-21 -- varios calle luz dorada golden light navidad papa noel palomas gente frente casas guille yo espejo reflejo\23304.jpg"
    27.1864 LUA opened file

C:\Users\nahue\Downloads>explorer.exe /select, "E:\fotografia\olympus-35-rd\fuji-200\2024\12\08-21 -- varios calle luz dorada golden light navidad papa noel palomas gente frente casas guille yo espejo reflejo\23304.jpg" 
    27.3128 LUA result from windows command was 1
    49.1932 LUA Windows path = E:\fotografia\olympus-35-rd\fuji-200\2024\12\23-29 -- varios viaje salta calle ruta perros caballos  chicoana montaña cerro gato gata casas pueblo yo avion\23571.jpg
    49.1932 LUA Windows command = explorer.exe /select, "E:\fotografia\olympus-35-rd\fuji-200\2024\12\23-29 -- varios viaje salta calle ruta perros caballos  chicoana montaña cerro gato gata casas pueblo yo avion\23571.jpg"
    49.1932 LUA OpenInExplorer run_cmd = explorer.exe /select, "E:\fotografia\olympus-35-rd\fuji-200\2024\12\23-29 -- varios viaje salta calle ruta perros caballos  chicoana montaña cerro gato gata casas pueblo yo avion\23571.jpg"
    49.1934 LUA opened file

C:\Users\nahue\Downloads>explorer.exe /select, "E:\fotografia\olympus-35-rd\fuji-200\2024\12\23-29 -- varios viaje salta calle ruta perros caballos  chicoana montaña cerro gato gata casas pueblo yo avion\23571.jpg" 
    49.3184 LUA result from windows command was 1
   392.5142 LUA Windows path = E:\fotografia\olympus-35-rd\fuji-200\2024\12\23-29 -- varios viaje salta calle ruta perros caballos chicoana montaña cerro gato gata casas pueblo yo avion\23573.jpg
   392.5142 LUA Windows command = explorer.exe /select, "E:\fotografia\olympus-35-rd\fuji-200\2024\12\23-29 -- varios viaje salta calle ruta perros caballos chicoana montaña cerro gato gata casas pueblo yo avion\23573.jpg"
   392.5145 LUA opened file

C:\Users\nahue\Downloads>explorer.exe /select, "E:\fotografia\olympus-35-rd\fuji-200\2024\12\23-29 -- varios viaje salta calle ruta perros caballos chicoana montaña cerro gato gata casas pueblo yo avion\23573.jpg" 
   392.6504 LUA result from windows command was 1
   392.6505 LUA OpenInExplorer run_cmd = explorer.exe /select, "E:\fotografia\olympus-35-rd\fuji-200\2024\12\23-29 -- varios viaje salta calle ruta perros caballos chicoana montaña cerro gato gata casas pueblo yo avion\23573.jpg"

@wpferguson
Copy link
Member

wpferguson commented Jan 6, 2025

If you run explorer.exe /select, "E:\fotografia\olympus-35-rd\fuji-200\2024\12\23-29 -- varios viaje salta calle ruta perros caballos chicoana montaña cerro gato gata casas pueblo yo avion\23573.jpg" from the command line does it work or does it give an error?

EDIT: If it does give an error, can you figure out a way (probably some combination of quoting), to protect the string (or protect windows from the string)?

@Naahuel
Copy link
Contributor Author

Naahuel commented Jan 6, 2025

Hey @wpferguson

I thought I did mention that in my original issue, sorry! That's what I meant when I said the "commands it logs are OK"

Yes, first thing I did was try them in a terminal and from the "Run" utility and it works perfectly! The logs show that the commands are perfectly fine, but fail to be executed by dtutils_system.windows_command I assume.

EDIT: If it does give an error, can you figure out a way (probably some combination of quoting), to protect the string (or protect windows from the string)?

That's the first thing I tried wrapping the file path in quotes:

open_files.windows = "explorer.exe /select, \"%s\""

It made no difference :(

@wpferguson
Copy link
Member

Can you try open_files.windows = "\"explorer.exe /select, "%s\"" and open_files.windows = "\"explorer.exe /select, "\"%s\"\""

Thanks

@Naahuel
Copy link
Contributor Author

Naahuel commented Jan 6, 2025

Can you try open_files.windows = "\"explorer.exe /select, "%s\"" and open_files.windows = "\"explorer.exe /select, "\"%s\"\""

Thanks

I tried those and there's some syntax issues, it won't load. I tried this:
open_files.windows = "\"explorer.exe /select, \"%s\""

and it adds the quotes in the bat file, but it adds double quotes to the file:
"explorer.exe /select, ""E:\fotografia\olympus-35-rd\fuji-200\2024\12\23-29 -- varios viaje salta calle ruta perros caballos chicoana montaña cerro gato gata casas pueblo yo avion\23571.jpg""

That just does nothing, not even open the file explorer.

Ok here's another piece of the puzzle I guess.

I saw that to execute the command dtutils basically writes a bat file with the commands and then it runs that. If I see the contents of that file, the command looks good there (I thought it might have encoding issues):
image

Now running that command directly works just fine, and with the run utility as well. But if I run that bat file manually, it fails!

I tried storing the path in a variable, same result:

set "filePath=E:\fotografia\olympus-35-rd\fuji-200\2024\12\path-with-ññ\23580.jpg"
explorer.exe /select,"%filePath%"

I tried opening cmd and passing the command to it, same result:

cmd.exe /c explorer.exe /select,"E:\fotografia\olympus-35-rd\fuji-200\2024\12\path-with-ññ\23580.jpg"

Running that line manually in the Run utility works just fine! Just not from the BAT file.

So the problem is not with Lua or darktable, it's the bat file.

Why does the script run commands like that? can't it spawn executables directly?

-EDIT-
Adding a pause to the bat file reveals the issue:
image

@Naahuel
Copy link
Contributor Author

Naahuel commented Jan 6, 2025

Ok, appologies for so many comments.

This works:

open_files.windows = [[
@echo off
for /f "tokens=2 delims=:." %%x in ('chcp') do set cp=%%x
chcp 65001>nul
explorer.exe /select,%s
chcp %%cp%%>nul]]

It creates a BAT file like this (suggested by this stack overflow answer):

@echo off
for /f "tokens=2 delims=:." %%x in ('chcp') do set cp=%%x
chcp 65001>nul
explorer.exe /select,"E:\fotografia\olympus-35-rd\fuji-200\2024\12\conflicting-path-with-ññ\23571.jpg"
chcp %%cp%%>nul

It even works with multiple selected files.

Would that be acceptable in a PR? The 65001 encoding is apparently just UTF-8? Not sure why, but this works.

@wpferguson
Copy link
Member

Does the solution still work with normal strings?

Yes, a PR would be welcome 😄, though a better place to apply it would probably be in lib/dutils/system.lua so it fixes calls from all scripts and not just OpenInExplorer.

@Naahuel
Copy link
Contributor Author

Naahuel commented Jan 6, 2025

Ok, made the changes in system.lua. I've tried multiple actions that use that command (update lua scripts, run external editors, open in explorer) and so far they all work as expected. For normal paths and paths with accentuated characters.

I'll open a PR and maybe you guys can test it on your end.

Thank you!

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

Successfully merging a pull request may close this issue.

2 participants