Windows目录永远不会包含临时文件的非ASCII字符? [英] Windows directory that will never contain non-ASCII characters for temp file?

查看:305
本文介绍了Windows目录永远不会包含临时文件的非ASCII字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于Windows的限制,Hunspell在Windows上使用MinGW 7.3.0,无法从具有非ASCII字符的位置加载字典文件.我已经尝试了一切[1],现在我将其复制到没有ASCII字符的路径之前,先将其提供给Hunspell.将其复制到什么位置?

[1]

  1. Windows需要wchar_tstd::iostream.open()的支持才能正常运行,而MinGW无法实现
  2. std::filesystem可以解决此问题,但仅在GCC 8中可用
  3. Hunspell坚持自行加载文件,无法将读取的文件作为字符串传递给它

解决方案

自然"适合使用的是用户选择的临时目录(或其子目录)(请参见%temp%c:\users\Ø¥Ć¼\AppData\LocalLow\Temp)或任意值(关于字符集).

因此,最有可能最好选择一些目录

a)不包含get do中的禁区字符.例如,您选择的C:\ProgramData下的目录(例如,应用程序名称)不包含非ASCII字符.

b)让用户决定将这些文件放置在何处,并确保不允许输入仅包含允许字符的路径.

c)传递短路径名称" (必须包含Hunspell),该名称不得包含非ASCII字符以与FAT文件系统特征兼容.例如,c:\temp\Ø¥Ć¼的短路径名称是c:\temp\571D~1.

您可以使用cmd.exe /c dir /x查看目录的简称:

C:\temp>dir /x
...    
19.07.2019  15:30    <DIR>                       .
19.07.2019  15:30    <DIR>                       ..
19.07.2019  15:30    <DIR>          571D~1       Ø¥Ć¼

我不知道如何从MinGW调用GetShortPathName Win32 API,但是我认为这是可能的.

还要确保查看MSDN页面以获取上述功能的特征,例如并非在任何地方都支持短名称(例如SMB +请参阅下面的评论).

Using MinGW 7.3.0 on Windows, Hunspell can't load the dictionary files from locations that have non-ASCII characters because of Windows limitations. I've tried everything[1] and I'm now resorting to copying the file to a path without ASCII characters before giving it to Hunspell. What is a good location to copy it to?

[1]

  1. Windows requires wchar_t support for std::iostream.open() to work right, which MinGW does not implement
  2. std::filesystem can solve this, but only available in GCC 8
  3. Hunspell insists on loading files on its own, it is not possible to pass the read files as strings to it

解决方案

The "natural" fit would be the use the user's choosen temporary directory (or subdirectory thereof) (see %temp% or GetTempPath()). However, that defaults to something that contains the user name (which can contain "non-ASCII" characters; e.g. c:\users\Ø¥Ć¼\AppData\LocalLow\Temp) or something arbitrary (regarding character set) all together.

So you're most likely best off to choose some directory that

a) does not contain off-limits characters from the get do. For example, a directory underneat C:\ProgramData that you choose yourself (e.g. the application name) that you know does not contain non-ASCII characters.

b) let the user decide where to put these files and make sure it is not permissible to enter a path that contains only allowed characters.

c) Pass the "short path name" to Hunspell, which should not contain non-ASCII characters for compatibility with FAT file system traits. For example, the short path name for c:\temp\Ø¥Ć¼ is c:\temp\571D~1.

You can see the short names for directories using cmd.exe /c dir /x:

C:\temp>dir /x
...    
19.07.2019  15:30    <DIR>                       .
19.07.2019  15:30    <DIR>                       ..
19.07.2019  15:30    <DIR>          571D~1       Ø¥Ć¼

How you can invoke the GetShortPathName Win32 API from MinGW I don't know, but I would assume that it is possible.

Also make sure to review the MSDN page for the above function for traitoffs, e.g. short names are not supported everywhere (e.g. SMB + see comments below).

这篇关于Windows目录永远不会包含临时文件的非ASCII字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆