MIME detection: use libmagic's default path on Windows, too

On Windows libmagic uses the ANSI file functions for opening
files. Therefore passing file names with non-ASCII/non-ANSI characters
won't work a lot of the time. Therefore letting libmagic's look for
and use its default location algorithm is safer. As a result
`magic.mgc` must be stored in `share/misc` instead of `data`.

Fixes #2212.
This commit is contained in:
Moritz Bunkus 2018-02-03 11:10:20 +01:00
parent b74a67a79d
commit bbb2f069eb
5 changed files with 13 additions and 13 deletions

View File

@ -28,6 +28,9 @@
* mkvmerge, mkvextract: Matroska parser: fixed a segmentation fault that
occurred whenever the first level 1 element after resyncing after an error
in the file structure isn't a cluster. Fixes #2211.
* mkvmerge, MKVToolNix GUI multiplexer & header editor: fixed a crash during
file type detection for attachments if MKVToolNix is installed in a path
with non-ASCII characters (e.g. German Umlauts). Fixes #2212.
# Version 20.0.0 "I Am The Sun" 2018-01-15

View File

@ -157,11 +157,13 @@ Section "Program files" SEC01
File /r "../doc"
File /r "../examples"
File /r "../locale"
File /r "../share"
# Delete files that might be present from older installation
# if this is just an upgrade.
Delete "$INSTDIR\mkv*.ico"
Delete "$INSTDIR\mmg.exe"
Delete "$INSTDIR\data\magic.mgc"
Delete "$INSTDIR\doc\command_line_references_and_guide.html"
Delete "$INSTDIR\doc\en\mmg.html"
Delete "$INSTDIR\doc\de\mmg.html"
@ -404,6 +406,7 @@ Section Uninstall
RMDir /r "$INSTDIR\doc"
RMDir /r "$INSTDIR\examples"
RMDir /r "$INSTDIR\locale"
RMDir /r "$INSTDIR\share"
RMDir "$INSTDIR"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"

View File

@ -92,20 +92,14 @@ guess_type_internal(std::string ext,
m = magic_open(MAGIC_MIME | MAGIC_SYMLINK);
# endif // MAGIC_MIME_TYPE
# ifdef SYS_WINDOWS
auto magic_filename = (mtx::sys::get_installation_path() / "data" / "magic").string();
if (!m || (-1 == magic_load(m, magic_filename.c_str())))
return guess_type_by_ext(ext);
# else // defined(SYS_WINDOWS)
# ifdef MTX_APPIMAGE
# ifdef MTX_APPIMAGE
auto magic_filename = (mtx::sys::get_installation_path() / ".." / "share" / "file" / "magic.mgc").string();
if (!m || (-1 == magic_load(m, magic_filename.c_str())) || (-1 == magic_load(m, nullptr)))
return guess_type_by_ext(ext);
# else
# else
if (!m || (-1 == magic_load(m, nullptr)))
return guess_type_by_ext(ext);
# endif // defined(MTX_APPIMAGE)
# endif // defined(SYS_WINDOWS)
# endif // defined(MTX_APPIMAGE)
ret = guess_type_by_content(m, ext);
magic_close(m);

View File

@ -51,9 +51,9 @@ InstallationChecker::runChecks() {
}
#if defined(SYS_WINDOWS)
auto magicFile = App::applicationDirPath() + "/data/magic.mgc";
auto magicFile = App::applicationDirPath() + "/share/misc/magic.mgc";
if (!QFileInfo{magicFile}.exists())
problems << Problem{ ProblemType::FileNotFound, Q("data\\magic.mgc") };
problems << Problem{ ProblemType::FileNotFound, Q("share\\misc\\magic.mgc") };
#endif // SYS_WINDOWS

View File

@ -51,7 +51,7 @@ function create_directories {
cd ${tgt_dir}
rm -rf *
mkdir -p examples data/sounds doc/licenses locale/libqt
mkdir -p examples data/sounds doc/licenses locale/libqt share/misc
print -- " done"
}
@ -67,7 +67,7 @@ function copy_files {
cp src/*.exe src/mkvtoolnix-gui/*.exe installer/*.url ${tgt_dir}/
cp share/icons/windows/mkvtoolnix-gui.ico ${tgt_dir}/installer/
cp ${mxe_usr_dir}/share/misc/magic.mgc ${tgt_dir}/data/
cp ${mxe_usr_dir}/share/misc/magic.mgc ${tgt_dir}/share/misc/
cp share/sounds/* ${tgt_dir}/data/sounds/
touch ${tgt_dir}/data/portable-app