From 77b9dbd5570e9da3cf7644f93de821b58d97368b Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Thu, 18 Jan 2007 20:47:27 +0000 Subject: [PATCH] Fix several filename and environment variable encoding problems * src/LaTeX.C (LaTeX::deplog): Assume that filenames in log files are stored in the file system encoding * src/frontends/qt4/qt_helpers.[Ch] (internal_path): delete * src/frontends/qt4/QGraphics.C: Adjust to change above * src/frontends/qt4/QPrefsDialog.C: ditto * src/frontends/qt4/QExternal.C: ditto * src/frontends/qt4/QInclude.C: ditto * src/support/os.h: Document the encoding of filename arguments * src/support/os_win32.h: ditto * src/support/filetools.C (findtexfile): Convert filename from file system encoding * src/support/os_win32.C: Convert filenames from utf8 to file system encoding and vice versa where needed * src/support/os_cygwin.C: ditto * src/support/getcwd.C (getcwd): Use internal_path() with correct encoding * src/support/docstring.[Ch] (from_filesystem8bit): new conversion function * src/support/environment.C (getEnv): convert environment variable from local 8bit encoding to utf8 (setEnv): convert environment variable from utf8 to local 8bit encoding * src/support/environment.h: document encoding of function arguments git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16753 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/LaTeX.C | 4 ++ src/frontends/qt4/QExternal.C | 3 +- src/frontends/qt4/QGraphics.C | 3 +- src/frontends/qt4/QInclude.C | 2 +- src/frontends/qt4/QPrefsDialog.C | 92 +++++++++++++------------------- src/frontends/qt4/qt_helpers.C | 9 ---- src/frontends/qt4/qt_helpers.h | 3 -- src/lyx_main.C | 2 +- src/support/docstring.C | 9 ++++ src/support/docstring.h | 3 ++ src/support/environment.C | 8 +-- src/support/environment.h | 12 +++-- src/support/filetools.C | 7 +-- src/support/getcwd.C | 2 +- src/support/os.h | 9 +++- src/support/os_cygwin.C | 19 +++++-- src/support/os_win32.C | 21 ++++---- src/support/os_win32.h | 2 +- 18 files changed, 107 insertions(+), 103 deletions(-) diff --git a/src/LaTeX.C b/src/LaTeX.C index c6734bb2bd..7ec8adc0a1 100644 --- a/src/LaTeX.C +++ b/src/LaTeX.C @@ -836,6 +836,10 @@ void LaTeX::deplog(DepTable & head) smatch sub; + // FIXME UNICODE: We assume that the file names in the log + // file are in the file system encoding. + token = to_utf8(from_filesystem8bit(token)); + if (regex_match(token, sub, reg1)) { static regex reg1_1("\\(([^()]+)"); smatch what; diff --git a/src/frontends/qt4/QExternal.C b/src/frontends/qt4/QExternal.C index 7ed801317d..8d7a131bf8 100644 --- a/src/frontends/qt4/QExternal.C +++ b/src/frontends/qt4/QExternal.C @@ -455,8 +455,7 @@ void QExternal::apply() { InsetExternalParams params = controller().params(); - // FIXME: UNICODE - params.filename.set(to_utf8(internal_path(dialog_->fileED->text())), + params.filename.set(internal_path(fromqstr(dialog_->fileED->text())), kernel().bufferFilepath()); params.settemplate(controller().getTemplate( diff --git a/src/frontends/qt4/QGraphics.C b/src/frontends/qt4/QGraphics.C index 8f813ec946..5c3c7c53b1 100644 --- a/src/frontends/qt4/QGraphics.C +++ b/src/frontends/qt4/QGraphics.C @@ -270,8 +270,7 @@ void QGraphics::apply() { InsetGraphicsParams & igp = controller().params(); - // FIXME: UNICODE - igp.filename.set(to_utf8(internal_path(dialog_->filename->text())), + igp.filename.set(internal_path(fromqstr(dialog_->filename->text())), kernel().bufferFilepath()); // the bb section diff --git a/src/frontends/qt4/QInclude.C b/src/frontends/qt4/QInclude.C index b58491ba43..62a0fac901 100644 --- a/src/frontends/qt4/QInclude.C +++ b/src/frontends/qt4/QInclude.C @@ -103,7 +103,7 @@ void QInclude::apply() { InsetCommandParams params = controller().params(); - params["filename"] = internal_path(dialog_->filenameED->text()); + params["filename"] = from_utf8(internal_path(fromqstr(dialog_->filenameED->text()))); params.preview(dialog_->previewCB->isChecked()); int const item = dialog_->typeCO->currentIndex(); diff --git a/src/frontends/qt4/QPrefsDialog.C b/src/frontends/qt4/QPrefsDialog.C index 39d95184f4..4347dc8069 100644 --- a/src/frontends/qt4/QPrefsDialog.C +++ b/src/frontends/qt4/QPrefsDialog.C @@ -57,6 +57,10 @@ #include using lyx::support::compare_no_case; +using lyx::support::os::external_path; +using lyx::support::os::external_path_list; +using lyx::support::os::internal_path; +using lyx::support::os::internal_path_list; using std::distance; using std::endl; @@ -163,24 +167,6 @@ void setComboxFont(QComboBox * cb, string const & family, string const & foundry << foundry << "', '" << family << '\'' <isChecked(); - // FIXME: UNICODE - rc.primary_kbmap = to_utf8(internal_path(firstKeymapED->text())); - rc.secondary_kbmap = to_utf8(internal_path(secondKeymapED->text())); + rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text())); + rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text())); } @@ -259,8 +244,8 @@ void PrefKeyboard::update(LyXRC const & rc) { // FIXME: can derive CB from the two EDs keymapCB->setChecked(rc.use_kbmap); - firstKeymapED->setText(external_path(rc.primary_kbmap)); - secondKeymapED->setText(external_path(rc.secondary_kbmap)); + firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap))); + secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap))); } @@ -679,32 +664,32 @@ PrefPaths::PrefPaths(QPrefs * form, QWidget * parent) void PrefPaths::apply(LyXRC & rc) const { - // FIXME: UNICODE - rc.document_path = to_utf8(internal_path(workingDirED->text())); - rc.template_path = to_utf8(internal_path(templateDirED->text())); - rc.backupdir_path = to_utf8(internal_path(backupDirED->text())); - rc.tempdir_path = to_utf8(internal_path(tempDirED->text())); - rc.path_prefix = internal_path_list(pathPrefixED->text()); + rc.document_path = internal_path(fromqstr(workingDirED->text())); + rc.template_path = internal_path(fromqstr(templateDirED->text())); + rc.backupdir_path = internal_path(fromqstr(backupDirED->text())); + rc.tempdir_path = internal_path(fromqstr(tempDirED->text())); + rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text())); // FIXME: should be a checkbox only - rc.lyxpipes = to_utf8(internal_path(lyxserverDirED->text())); + rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text())); } void PrefPaths::update(LyXRC const & rc) { - workingDirED->setText(external_path(rc.document_path)); - templateDirED->setText(external_path(rc.template_path)); - backupDirED->setText(external_path(rc.backupdir_path)); - tempDirED->setText(external_path(rc.tempdir_path)); - pathPrefixED->setText(external_path_list(rc.path_prefix)); + workingDirED->setText(toqstr(external_path(rc.document_path))); + templateDirED->setText(toqstr(external_path(rc.template_path))); + backupDirED->setText(toqstr(external_path(rc.backupdir_path))); + tempDirED->setText(toqstr(external_path(rc.tempdir_path))); + pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix))); // FIXME: should be a checkbox only - lyxserverDirED->setText(external_path(rc.lyxpipes)); + lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes))); } + void PrefPaths::select_templatedir() { docstring file(form_->controller().browsedir( - internal_path(templateDirED->text()), + from_utf8(internal_path(fromqstr(templateDirED->text()))), _("Select a document templates directory"))); if (!file.empty()) templateDirED->setText(toqstr(file)); @@ -714,7 +699,7 @@ void PrefPaths::select_templatedir() void PrefPaths::select_tempdir() { docstring file(form_->controller().browsedir( - internal_path(tempDirED->text()), + from_utf8(internal_path(fromqstr(tempDirED->text()))), _("Select a temporary directory"))); if (!file.empty()) tempDirED->setText(toqstr(file)); @@ -724,7 +709,7 @@ void PrefPaths::select_tempdir() void PrefPaths::select_backupdir() { docstring file(form_->controller().browsedir( - internal_path(backupDirED->text()), + from_utf8(internal_path(fromqstr(backupDirED->text()))), _("Select a backups directory"))); if (!file.empty()) backupDirED->setText(toqstr(file)); @@ -734,7 +719,7 @@ void PrefPaths::select_backupdir() void PrefPaths::select_workingdir() { docstring file(form_->controller().browsedir( - internal_path(workingDirED->text()), + from_utf8(internal_path(fromqstr(workingDirED->text()))), _("Select a document directory"))); if (!file.empty()) workingDirED->setText(toqstr(file)); @@ -744,7 +729,7 @@ void PrefPaths::select_workingdir() void PrefPaths::select_lyxpipe() { docstring file(form_->controller().browse( - internal_path(lyxserverDirED->text()), + from_utf8(internal_path(fromqstr(lyxserverDirED->text()))), _("Give a filename for the LyX server pipe"))); if (!file.empty()) lyxserverDirED->setText(toqstr(file)); @@ -807,9 +792,8 @@ void PrefSpellchecker::apply(LyXRC & rc) const // FIXME: remove isp_use_esc_chars rc.isp_esc_chars = fromqstr(escapeCharactersED->text()); rc.isp_use_esc_chars = !rc.isp_esc_chars.empty(); - // FIXME: UNICODE // FIXME: remove isp_use_pers_dict - rc.isp_pers_dict = to_utf8(internal_path(persDictionaryED->text())); + rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text())); rc.isp_use_pers_dict = !rc.isp_pers_dict.empty(); rc.isp_accept_compound = compoundWordCB->isChecked(); rc.isp_use_input_encoding = inputEncodingCB->isChecked(); @@ -839,7 +823,7 @@ void PrefSpellchecker::update(LyXRC const & rc) // FIXME: remove isp_use_esc_chars escapeCharactersED->setText(toqstr(rc.isp_esc_chars)); // FIXME: remove isp_use_pers_dict - persDictionaryED->setText(external_path(rc.isp_pers_dict)); + persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict))); compoundWordCB->setChecked(rc.isp_accept_compound); inputEncodingCB->setChecked(rc.isp_use_input_encoding); } @@ -848,7 +832,7 @@ void PrefSpellchecker::update(LyXRC const & rc) void PrefSpellchecker::select_dict() { docstring file(form_->controller().browsedict( - internal_path(persDictionaryED->text()))); + from_utf8(internal_path(fromqstr(persDictionaryED->text()))))); if (!file.empty()) persDictionaryED->setText(toqstr(file)); } @@ -1605,8 +1589,7 @@ void PrefPrinter::apply(LyXRC & rc) const rc.print_oddpage_flag = fromqstr(printerOddED->text()); rc.print_collcopies_flag = fromqstr(printerCollatedED->text()); rc.print_landscape_flag = fromqstr(printerLandscapeED->text()); - // FIXME: UNICODE - rc.print_to_file = to_utf8(internal_path(printerToFileED->text())); + rc.print_to_file = internal_path(fromqstr(printerToFileED->text())); rc.print_extra_options = fromqstr(printerExtraED->text()); rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text()); rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text()); @@ -1630,7 +1613,7 @@ void PrefPrinter::update(LyXRC const & rc) printerOddED->setText(toqstr(rc.print_oddpage_flag)); printerCollatedED->setText(toqstr(rc.print_collcopies_flag)); printerLandscapeED->setText(toqstr(rc.print_landscape_flag)); - printerToFileED->setText(external_path(rc.print_to_file)); + printerToFileED->setText(toqstr(external_path(rc.print_to_file))); printerExtraED->setText(toqstr(rc.print_extra_options)); printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix)); printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag)); @@ -1677,9 +1660,8 @@ PrefUserInterface::PrefUserInterface(QPrefs * form, QWidget * parent) void PrefUserInterface::apply(LyXRC & rc) const { - // FIXME: UNICODE - rc.ui_file = to_utf8(internal_path(uiFileED->text())); - rc.bind_file = to_utf8(internal_path(bindFileED->text())); + rc.ui_file = internal_path(fromqstr(uiFileED->text())); + rc.bind_file = internal_path(fromqstr(bindFileED->text())); rc.use_lastfilepos = restoreCursorCB->isChecked(); rc.load_session = loadSessionCB->isChecked(); if (loadWindowSizeCB->isChecked()) { @@ -1699,8 +1681,8 @@ void PrefUserInterface::apply(LyXRC & rc) const void PrefUserInterface::update(LyXRC const & rc) { - uiFileED->setText(external_path(rc.ui_file)); - bindFileED->setText(external_path(rc.bind_file)); + uiFileED->setText(toqstr(external_path(rc.ui_file))); + bindFileED->setText(toqstr(external_path(rc.bind_file))); restoreCursorCB->setChecked(rc.use_lastfilepos); loadSessionCB->setChecked(rc.load_session); bool loadWindowSize = rc.geometry_width == 0 && rc.geometry_height == 0; @@ -1725,7 +1707,7 @@ void PrefUserInterface::update(LyXRC const & rc) void PrefUserInterface::select_ui() { docstring const name = - internal_path(uiFileED->text()); + from_utf8(internal_path(fromqstr(uiFileED->text()))); docstring file(form_->controller().browseUI(name)); if (!file.empty()) uiFileED->setText(toqstr(file)); @@ -1735,7 +1717,7 @@ void PrefUserInterface::select_ui() void PrefUserInterface::select_bind() { docstring const name = - internal_path(bindFileED->text()); + from_utf8(internal_path(fromqstr(bindFileED->text()))); docstring file(form_->controller().browsebind(name)); if (!file.empty()) bindFileED->setText(toqstr(file)); diff --git a/src/frontends/qt4/qt_helpers.C b/src/frontends/qt4/qt_helpers.C index c1ede0f9c9..8c9b7a3729 100644 --- a/src/frontends/qt4/qt_helpers.C +++ b/src/frontends/qt4/qt_helpers.C @@ -179,13 +179,4 @@ docstring const formatted(docstring const & text, int w) return sout; } - -docstring const internal_path(QString const & input) -{ - // FIXME UNICODE - return from_utf8(lyx::support::os::internal_path( - to_utf8(qstring_to_ucs4(input)))); -} - - } // namespace lyx diff --git a/src/frontends/qt4/qt_helpers.h b/src/frontends/qt4/qt_helpers.h index acaf3c3eeb..5c52b1fdfa 100644 --- a/src/frontends/qt4/qt_helpers.h +++ b/src/frontends/qt4/qt_helpers.h @@ -59,9 +59,6 @@ QString const qt_(char const * str, const char * comment = 0); */ QString const qt_(std::string const & str); -/// -docstring const internal_path(QString const & input); - } // namespace lyx #endif // QTHELPERS_H diff --git a/src/lyx_main.C b/src/lyx_main.C index f274ae189c..a98d69f3dd 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -457,7 +457,7 @@ int LyX::exec(int & argc, char * argv[]) // such that package().temp_dir() is properly initialized. pimpl_->lyx_server_.reset(new LyXServer(&pimpl_->lyxfunc_, lyxrc.lyxpipes)); pimpl_->lyx_socket_.reset(new LyXServerSocket(&pimpl_->lyxfunc_, - support::os::internal_path(package().temp_dir() + "/lyxsocket"))); + os::internal_path(package().temp_dir() + "/lyxsocket"))); // Start the real execution loop. exit_status = pimpl_->application_->exec(); diff --git a/src/support/docstring.C b/src/support/docstring.C index 0b7f796628..dd5069acac 100644 --- a/src/support/docstring.C +++ b/src/support/docstring.C @@ -17,6 +17,8 @@ #include #include +#include + #include @@ -116,6 +118,13 @@ std::string const to_local8bit(docstring const & s) } +docstring const from_filesystem8bit(std::string const & s) +{ + QByteArray const encoded(s.c_str(), s.length()); + return qstring_to_ucs4(QFile::decodeName(encoded)); +} + + bool operator==(lyx::docstring const & l, char const * r) { int const len = l.length(); diff --git a/src/support/docstring.h b/src/support/docstring.h index 0f09706307..ec5f4012c9 100644 --- a/src/support/docstring.h +++ b/src/support/docstring.h @@ -56,6 +56,9 @@ public: */ std::string const to_local8bit(docstring const & s); +/// convert \p s from the encoding of the file system to ucs4. +docstring const from_filesystem8bit(std::string const & s); + /// Compare a docstring with a C string of ASCII characters bool operator==(lyx::docstring const &, char const *); diff --git a/src/support/environment.C b/src/support/environment.C index c1a5710978..9325446b3f 100644 --- a/src/support/environment.C +++ b/src/support/environment.C @@ -32,8 +32,7 @@ string const getEnv(string const & envname) { // f.ex. what about error checking? char const * const ch = getenv(envname.c_str()); - string const envstr = !ch ? "" : ch; - return envstr; + return ch ? to_utf8(from_local8bit(ch)) : string(); } @@ -61,13 +60,14 @@ bool setEnv(string const & name, string const & value) // CHECK Look at and fix this. // f.ex. what about error checking? + string const encoded(to_local8bit(from_utf8(value))); #if defined (HAVE_SETENV) - int const retval = ::setenv(name.c_str(), value.c_str(), true); + int const retval = ::setenv(name.c_str(), encoded.c_str(), true); #elif defined (HAVE_PUTENV) static std::map varmap; - string envstr = name + '=' + value; + string envstr = name + '=' + encoded; char * newptr = new char[envstr.size() + 1]; envstr.copy(newptr, envstr.length()); newptr[envstr.length()] = '\0'; diff --git a/src/support/environment.h b/src/support/environment.h index d38bd01c34..d312bffe63 100644 --- a/src/support/environment.h +++ b/src/support/environment.h @@ -18,11 +18,12 @@ namespace lyx { namespace support { -/// @returns the contents of the environment variable @c name. +/// @returns the contents of the environment variable @c name encoded in utf8. std::string const getEnv(std::string const & envname); /** @returns the contents of the environment variable @c name, - * split into path elements using the OS-dependent separator token. + * split into path elements using the OS-dependent separator token + * and encoded in utf8. * Each element is then passed through os::internal_path() to * guarantee that it is in the form of a unix-style path. * If the environment variable is not set, then the function returns @@ -31,12 +32,13 @@ std::string const getEnv(std::string const & envname); std::vector const getEnvPath(std::string const & name); /** Set the contents of the environment variable @c name to @c value. + * \p value is encoded in utf8. * @returns true if the variable was set successfully. */ bool setEnv(std::string const & name, std::string const & value); /** Set the contents of the environment variable @c name - * using the paths stored in the @c env vector. + * using the paths stored in the @c env vector (encoded in utf8). * Each element is passed through os::external_path(). * Multiple elements are concatenated into a single string using * os::path_separator(). @@ -45,8 +47,8 @@ void setEnvPath(std::string const & name, std::vector const & env); /** Prepend a list of paths to that returned by the environment variable. * Identical paths occurring later in the list are removed. - * @param name the name of the environment variable. - * @prefix the list of paths in OS-native syntax. + * @param name the name of the environment variable (encoded in utf8). + * @prefix the list of paths in OS-native syntax (encoded in utf8). * Eg "/foo/bar:/usr/bin:/usr/local/bin" on *nix, * "C:\foo\bar;C:\windows" on Windows. */ diff --git a/src/support/filetools.C b/src/support/filetools.C index 264291d16e..7a8448df49 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -999,7 +999,7 @@ docstring const makeDisplayPath(string const & path, unsigned int threshold) str = subst(str, home, "~"); if (str.length() <= threshold) - return lyx::from_utf8(os::external_path(str)); + return from_utf8(os::external_path(str)); string const prefix = ".../"; string temp; @@ -1020,7 +1020,7 @@ docstring const makeDisplayPath(string const & path, unsigned int threshold) str = head + "..." + tail; } - return lyx::from_utf8(os::external_path(prefix + str)); + return from_utf8(os::external_path(prefix + str)); } @@ -1138,7 +1138,8 @@ FileName const findtexfile(string const & fil, string const & /*format*/) << "kpse result = `" << rtrim(c.second, "\n\r") << '\'' << endl; if (c.first != -1) - return FileName(os::internal_path(rtrim(c.second, "\n\r"))); + return FileName(os::internal_path(rtrim(to_utf8(from_filesystem8bit(c.second)), + "\n\r"))); else return FileName(); } diff --git a/src/support/getcwd.C b/src/support/getcwd.C index e7aea7277f..1a0c3f213f 100644 --- a/src/support/getcwd.C +++ b/src/support/getcwd.C @@ -66,7 +66,7 @@ FileName const getcwd() string result; if (err) result = tbuf.get(); - return FileName::fromFilesystemEncoding(os::internal_path(result)); + return FileName(os::internal_path(to_utf8(from_filesystem8bit(result)))); } } // namespace support diff --git a/src/support/os.h b/src/support/os.h index 0fce6c1d16..c42cfedbff 100644 --- a/src/support/os.h +++ b/src/support/os.h @@ -44,29 +44,36 @@ shell_type shell(); std::string const python(); /// Extract the path common to both @c p1 and @c p2. DBCS aware! +/// \p p1, \p p2 and the return value are encoded in utf8. std::string::size_type common_path(std::string const & p1, std::string const & p2); /// Converts a unix style path to host OS style. +/// \p p and the return value are encoded in utf8. std::string external_path(std::string const & p); /// Converts a host OS style path to unix style. +/// \p p and the return value are encoded in utf8. std::string internal_path(std::string const & p); /// Converts a unix style path list to host OS style. +/// \p p and the return value are encoded in utf8. std::string external_path_list(std::string const & p); /// Converts a host OS style path list to unix style. +/// \p p and the return value are encoded in utf8. std::string internal_path_list(std::string const & p); /** * Converts a unix style path into a form suitable for inclusion in a LaTeX * document. + * \p p is encoded in utf8. * Caution: This function handles only the OS specific part of that task. * Never use it directly, use lyx::support::latex_path instead. */ std::string latex_path(std::string const & p); /// Is the path absolute? +/// \p p is encoded in utf8. bool is_absolute_path(std::string const & p); /** Returns a string suitable to be passed to popen when @@ -98,7 +105,7 @@ enum auto_open_mode { bool canAutoOpenFile(std::string const & ext, auto_open_mode const mode = VIEW); /** View or edit a file with the default viewer or editor. - * \param filename file to open + * \param filename file to open (encoded in utf8) * \param mode open in VIEW or EDIT mode * \returns whether or not the file is viewed (or edited) successfully. */ diff --git a/src/support/os_cygwin.C b/src/support/os_cygwin.C index d281294ab7..6cb2f22590 100644 --- a/src/support/os_cygwin.C +++ b/src/support/os_cygwin.C @@ -78,6 +78,9 @@ enum PathStyle { }; +/// Convert a path to or from posix style. +/// \p p is encoded in local 8bit encoding or utf8. +/// The result is returned in the same encoding as \p p. string convert_path(string const & p, PathStyle const & target) { char path_buf[PATH_MAX]; @@ -88,6 +91,8 @@ string convert_path(string const & p, PathStyle const & target) path_buf[0] = '\0'; + // cygwin_conv_to_posix_path and cygwin_conv_to_win32_path do not + // care about the encoding. if (target == posix) cygwin_conv_to_posix_path(p.c_str(), path_buf); else @@ -97,6 +102,9 @@ string convert_path(string const & p, PathStyle const & target) } +/// Convert a path list to or from posix style. +/// \p p is encoded in local 8bit encoding or utf8. +/// The result is returned in the same encoding as \p p. string convert_path_list(string const & p, PathStyle const & target) { if (p.empty()) @@ -113,6 +121,7 @@ string convert_path_list(string const & p, PathStyle const & target) char * ptr = new char[target_size]; if (ptr) { + // FIXME: See comment in convert_path() above if (target == posix) cygwin_win32_to_posix_path_list(pc, ptr); else @@ -308,7 +317,7 @@ bool autoOpenFile(string const & filename, auto_open_mode const mode) { // reference: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc // /platform/shell/reference/functions/shellexecute.asp - string const win_path = convert_path(filename, PathStyle(windows)); + string const win_path = to_local8bit(from_utf8(convert_path(filename, PathStyle(windows)))); char const * action = (mode == VIEW) ? "open" : "edit"; return reinterpret_cast(ShellExecute(NULL, action, win_path.c_str(), NULL, NULL, 1)) > 32; @@ -322,9 +331,9 @@ void addFontResources() string const fonts_dir = addPath(package().system_support(), "fonts"); for (int i = 0 ; i < num_fonts_truetype ; ++i) { - string const font_current = convert_path( + string const font_current = to_local8bit(from_utf8(convert_path( addName(fonts_dir, win_fonts_truetype[i] + ".ttf"), - PathStyle(windows)); + PathStyle(windows)))); AddFontResource(font_current.c_str()); } #endif @@ -338,9 +347,9 @@ void restoreFontResources() string const fonts_dir = addPath(package().system_support(), "fonts"); for(int i = 0 ; i < num_fonts_truetype ; ++i) { - string const font_current = convert_path( + string const font_current = to_local8bit(from_utf8(convert_path( addName(fonts_dir, win_fonts_truetype[i] + ".ttf"), - PathStyle(windows)); + PathStyle(windows)))); RemoveFontResource(font_current.c_str()); } #endif diff --git a/src/support/os_win32.C b/src/support/os_win32.C index 468e8491c2..daa977b73f 100644 --- a/src/support/os_win32.C +++ b/src/support/os_win32.C @@ -28,8 +28,6 @@ #include #include -#include - /* The GetLongPathName macro may be defined on the compiling machine, * but we must use a bit of trickery if the resulting executable is * to run on a Win95 machine. @@ -217,8 +215,11 @@ namespace { string const get_long_path(string const & short_path) { + // GetLongPathName needs the path in file system encoding. + // We can use to_local8bit, since file system encoding and the + // local 8 bit encoding are identical on windows. std::vector long_path(MAX_PATH); - DWORD result = GetLongPathName(short_path.c_str(), + DWORD result = GetLongPathName(to_local8bit(from_utf8(short_path)).c_str(), &long_path[0], long_path.size()); if (result > long_path.size()) { @@ -228,7 +229,7 @@ string const get_long_path(string const & short_path) BOOST_ASSERT(result <= long_path.size()); } - return (result == 0) ? short_path : &long_path[0]; + return (result == 0) ? short_path : to_utf8(from_filesystem8bit(&long_path[0])); } } // namespace anon @@ -384,7 +385,7 @@ string const GetFolderPath::operator()(folder_id _id) const HRESULT const result = (folder_path_func_)(0, id, 0, SHGFP_TYPE_CURRENT, folder_path); - return (result == 0) ? os::internal_path(folder_path) : string(); + return (result == 0) ? os::internal_path(to_utf8(from_filesystem8bit(folder_path))) : string(); } @@ -411,7 +412,7 @@ bool autoOpenFile(string const & filename, auto_open_mode const mode) // /platform/shell/reference/functions/shellexecute.asp char const * action = (mode == VIEW) ? "open" : "edit"; return reinterpret_cast(ShellExecute(NULL, action, - filename.c_str(), NULL, NULL, 1)) > 32; + to_local8bit(from_utf8(filename)).c_str(), NULL, NULL, 1)) > 32; } @@ -421,9 +422,9 @@ void addFontResources() string const fonts_dir = addPath(package().system_support(), "fonts"); for (int i = 0 ; i < num_fonts_truetype ; ++i) { - string const font_current = + string const font_current = addName(fonts_dir, win_fonts_truetype[i] + ".ttf"); - AddFontResource(external_path(font_current).c_str()); + AddFontResource(to_local8bit(from_utf8(external_path(font_current))).c_str()); } } @@ -434,9 +435,9 @@ void restoreFontResources() string const fonts_dir = addPath(package().system_support(), "fonts"); for(int i = 0 ; i < num_fonts_truetype ; ++i) { - string const font_current = + string const font_current = addName(fonts_dir, win_fonts_truetype[i] + ".ttf"); - RemoveFontResource(external_path(font_current).c_str()); + RemoveFontResource(to_local8bit(from_utf8(external_path(font_current))).c_str()); } } diff --git a/src/support/os_win32.h b/src/support/os_win32.h index 77af7fb984..bf748f629a 100644 --- a/src/support/os_win32.h +++ b/src/support/os_win32.h @@ -74,7 +74,7 @@ public: ~GetFolderPath(); /** Wrapper for SHGetFolderPathA, returning - * the path asscociated with @c id. + * the path asscociated with @c id in utf8 encoding. */ std::string const operator()(folder_id id) const; private: -- 2.39.2