mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-26 22:17:41 +00:00
more unicode filenames (+ fix one possible initialization order bug in
needsUpdate() in src/lyx_main.C). toFilesystemEncoding() is now used in all places where it is needed if I did not forget anything. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16184 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
46ec9f0951
commit
95579c2a71
@ -115,7 +115,7 @@ void ConverterCache::Impl::readIndex()
|
||||
CacheItem item(orig_from_name, to_format, timestamp, checksum);
|
||||
|
||||
// Don't cache files that do not exist anymore
|
||||
if (!fs::exists(orig_from)) {
|
||||
if (!fs::exists(orig_from_name.toFilesystemEncoding())) {
|
||||
lyxerr[Debug::FILES] << "Not caching file `"
|
||||
<< orig_from << "' (does not exist anymore)."
|
||||
<< std::endl;
|
||||
|
@ -229,7 +229,7 @@ Buffer::~Buffer()
|
||||
|
||||
closing();
|
||||
|
||||
if (!temppath().empty() && !destroyDir(temppath())) {
|
||||
if (!temppath().empty() && !destroyDir(FileName(temppath()))) {
|
||||
Alert::warning(_("Could not remove temporary directory"),
|
||||
bformat(_("Could not remove the temporary directory %1$s"),
|
||||
from_utf8(temppath())));
|
||||
|
@ -511,7 +511,9 @@ bool Converters::move(string const & fmt,
|
||||
string const to_base = changeExtension(to.absFilename(), string());
|
||||
string const to_extension = getExtension(to.absFilename());
|
||||
|
||||
vector<string> files = dirList(onlyPath(from.absFilename()), getExtension(from.absFilename()));
|
||||
vector<string> const files = dirList(
|
||||
FileName(onlyPath(from.absFilename())),
|
||||
getExtension(from.absFilename()));
|
||||
for (vector<string>::const_iterator it = files.begin();
|
||||
it != files.end(); ++it)
|
||||
if (prefixIs(*it, base)) {
|
||||
|
@ -88,13 +88,14 @@ docstring const ControlGraphics::browse(docstring const & in_name) const
|
||||
|
||||
// Does user clipart directory exist?
|
||||
string clipdir = addName(package().user_support(), "clipart");
|
||||
if (!(fs::exists(clipdir) && fs::is_directory(clipdir)))
|
||||
string const encoded_clipdir = FileName(clipdir).toFilesystemEncoding();
|
||||
if (!(fs::exists(encoded_clipdir) && fs::is_directory(encoded_clipdir)))
|
||||
// No - bail out to system clipart directory
|
||||
clipdir = addName(package().system_support(), "clipart");
|
||||
pair<docstring, docstring> dir1(_("Clipart|#C#c"), lyx::from_utf8(clipdir));
|
||||
pair<docstring, docstring> dir2(_("Documents|#o#O"), lyx::from_utf8(lyxrc.document_path));
|
||||
pair<docstring, docstring> dir1(_("Clipart|#C#c"), from_utf8(clipdir));
|
||||
pair<docstring, docstring> dir2(_("Documents|#o#O"), from_utf8(lyxrc.document_path));
|
||||
// Show the file browser dialog
|
||||
return browseRelFile(in_name, lyx::from_utf8(kernel().bufferFilepath()),
|
||||
return browseRelFile(in_name, from_utf8(kernel().bufferFilepath()),
|
||||
title,
|
||||
FileFilterList(),
|
||||
false, dir1, dir2);
|
||||
|
@ -123,12 +123,12 @@ bool menuWrite(Buffer * buffer)
|
||||
|
||||
|
||||
|
||||
bool writeAs(Buffer * buffer, string const & filename)
|
||||
bool writeAs(Buffer * buffer, string const & newname)
|
||||
{
|
||||
string fname = buffer->fileName();
|
||||
string const oldname = fname;
|
||||
|
||||
if (filename.empty()) {
|
||||
if (newname.empty()) {
|
||||
|
||||
// FIXME UNICODE
|
||||
FileDialog fileDlg(_("Choose a filename to save document as"),
|
||||
@ -159,9 +159,10 @@ bool writeAs(Buffer * buffer, string const & filename)
|
||||
if (!isLyXFilename(fname))
|
||||
fname += ".lyx";
|
||||
} else
|
||||
fname = filename;
|
||||
fname = newname;
|
||||
|
||||
if (fs::exists(fname)) {
|
||||
FileName const filename(fname);
|
||||
if (fs::exists(filename.toFilesystemEncoding())) {
|
||||
docstring const file = makeDisplayPath(fname, 30);
|
||||
docstring text = bformat(_("The document %1$s already exists.\n\n"
|
||||
"Do you want to over-write that document?"), file);
|
||||
|
@ -426,7 +426,7 @@ void LyX::prepareExit()
|
||||
return;
|
||||
}
|
||||
|
||||
if (!destroyDir(package().temp_dir())) {
|
||||
if (!destroyDir(FileName(package().temp_dir()))) {
|
||||
docstring const msg =
|
||||
bformat(_("Unable to remove the temporary directory %1$s"),
|
||||
from_utf8(package().temp_dir()));
|
||||
@ -841,8 +841,9 @@ bool LyX::init()
|
||||
if (!lyxrc.path_prefix.empty())
|
||||
prependEnvPath("PATH", lyxrc.path_prefix);
|
||||
|
||||
if (fs::exists(lyxrc.document_path) &&
|
||||
fs::is_directory(lyxrc.document_path))
|
||||
FileName const document_path(lyxrc.document_path);
|
||||
if (fs::exists(document_path.toFilesystemEncoding()) &&
|
||||
fs::is_directory(document_path.toFilesystemEncoding()))
|
||||
package().document_dir() = lyxrc.document_path;
|
||||
|
||||
package().temp_dir() = createLyXTmpDir(FileName(lyxrc.tempdir_path)).absFilename();
|
||||
@ -975,11 +976,19 @@ namespace {
|
||||
// return true if file does not exist or is older than configure.py.
|
||||
bool needsUpdate(string const & file)
|
||||
{
|
||||
static string const configure_script =
|
||||
addName(package().system_support(), "configure.py");
|
||||
string const absfile =
|
||||
addName(package().user_support(), file);
|
||||
// We cannot initialize configure_script directly because the package
|
||||
// is not initialized yet when static objects are constructed.
|
||||
static string configure_script;
|
||||
static bool firstrun = true;
|
||||
if (firstrun) {
|
||||
configure_script = FileName(addName(
|
||||
package().system_support(),
|
||||
"configure.py")).toFilesystemEncoding();
|
||||
firstrun = false;
|
||||
}
|
||||
|
||||
string const absfile = FileName(addName(
|
||||
package().user_support(), file)).toFilesystemEncoding();
|
||||
return (! fs::exists(absfile))
|
||||
|| (fs::last_write_time(configure_script)
|
||||
> fs::last_write_time(absfile));
|
||||
@ -991,8 +1000,9 @@ bool needsUpdate(string const & file)
|
||||
bool LyX::queryUserLyXDir(bool explicit_userdir)
|
||||
{
|
||||
// Does user directory exist?
|
||||
if (fs::exists(package().user_support()) &&
|
||||
fs::is_directory(package().user_support())) {
|
||||
string const user_support =
|
||||
FileName(package().user_support()).toFilesystemEncoding();
|
||||
if (fs::exists(user_support) && fs::is_directory(user_support)) {
|
||||
first_start = false;
|
||||
|
||||
return needsUpdate("lyxrc.defaults")
|
||||
|
@ -1808,7 +1808,8 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate)
|
||||
if (filename.empty()) {
|
||||
filename = addName(lyxrc.document_path,
|
||||
"newfile" + convert<string>(++newfile_number) + ".lyx");
|
||||
while (theBufferList().exists(filename) || fs::is_readable(filename)) {
|
||||
while (theBufferList().exists(filename) ||
|
||||
fs::is_readable(FileName(filename).toFilesystemEncoding())) {
|
||||
++newfile_number;
|
||||
filename = addName(lyxrc.document_path,
|
||||
"newfile" + convert<string>(newfile_number) +
|
||||
@ -2101,10 +2102,10 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
|
||||
case LyXRC::RC_DISPLAY_GRAPHICS:
|
||||
case LyXRC::RC_DOCUMENTPATH:
|
||||
if (lyxrc_orig.document_path != lyxrc_new.document_path) {
|
||||
if (fs::exists(lyxrc_new.document_path) &&
|
||||
fs::is_directory(lyxrc_new.document_path)) {
|
||||
string const encoded = FileName(
|
||||
lyxrc_new.document_path).toFilesystemEncoding();
|
||||
if (fs::exists(encoded) && fs::is_directory(encoded))
|
||||
support::package().document_dir() = lyxrc.document_path;
|
||||
}
|
||||
}
|
||||
case LyXRC::RC_ESC_CHARS:
|
||||
case LyXRC::RC_FONT_ENCODING:
|
||||
|
@ -216,12 +216,13 @@ FileName const fileOpenSearch(string const & path, string const & name,
|
||||
|
||||
|
||||
/// Returns a vector of all files in directory dir having extension ext.
|
||||
vector<string> const dirList(string const & dir, string const & ext)
|
||||
vector<string> const dirList(FileName const & dir, string const & ext)
|
||||
{
|
||||
// EXCEPTIONS FIXME. Rewrite needed when we turn on exceptions. (Lgb)
|
||||
vector<string> dirlist;
|
||||
|
||||
if (!(fs::exists(dir) && fs::is_directory(dir))) {
|
||||
string const encoded_dir = dir.toFilesystemEncoding();
|
||||
if (!(fs::exists(encoded_dir) && fs::is_directory(encoded_dir))) {
|
||||
lyxerr[Debug::FILES]
|
||||
<< "Directory \"" << dir
|
||||
<< "\" does not exist to DirList." << endl;
|
||||
@ -233,11 +234,12 @@ vector<string> const dirList(string const & dir, string const & ext)
|
||||
extension += '.';
|
||||
extension += ext;
|
||||
|
||||
fs::directory_iterator dit(dir);
|
||||
fs::directory_iterator dit(encoded_dir);
|
||||
fs::directory_iterator end;
|
||||
for (; dit != end; ++dit) {
|
||||
string const & fil = dit->leaf();
|
||||
if (suffixIs(fil, extension)) {
|
||||
// FIXME UNICODE: We need to convert from filesystem encoding to utf8
|
||||
dirlist.push_back(fil);
|
||||
}
|
||||
}
|
||||
@ -386,10 +388,10 @@ FileName const createTmpDir(FileName const & tempdir, string const & mask)
|
||||
} // namespace anon
|
||||
|
||||
|
||||
bool destroyDir(string const & tmpdir)
|
||||
bool destroyDir(FileName const & tmpdir)
|
||||
{
|
||||
try {
|
||||
return fs::remove_all(tmpdir) > 0;
|
||||
return fs::remove_all(tmpdir.toFilesystemEncoding()) > 0;
|
||||
} catch (fs::filesystem_error const & fe){
|
||||
lyxerr << "Could not delete " << tmpdir << ". (" << fe.what() << ")" << std::endl;
|
||||
return false;
|
||||
|
@ -23,7 +23,7 @@ namespace lyx {
|
||||
namespace support {
|
||||
|
||||
/// remove directory and all contents, returns true on success
|
||||
bool destroyDir(std::string const & tmpdir);
|
||||
bool destroyDir(FileName const & tmpdir);
|
||||
|
||||
/// Creates the per buffer temporary directory
|
||||
std::string const createBufferTmpDir();
|
||||
@ -60,7 +60,7 @@ FileName const fileSearch(std::string const & path,
|
||||
std::string const & ext = std::string());
|
||||
|
||||
/// Returns a vector of all files in directory dir having extension ext.
|
||||
std::vector<std::string> const dirList(std::string const & dir,
|
||||
std::vector<std::string> const dirList(FileName const & dir,
|
||||
std::string const & ext = std::string());
|
||||
|
||||
/** Is directory read only?
|
||||
|
@ -358,7 +358,7 @@ string find_file(string const & name, string const & path,
|
||||
// We don't use ChangeExtension() because it does the wrong
|
||||
// thing if name contains a dot.
|
||||
string const trial = name + '.' + (*what);
|
||||
if (fs::exists(makeAbsPath(trial, path)))
|
||||
if (fs::exists(FileName(makeAbsPath(trial, path)).toFilesystemEncoding()))
|
||||
return trial;
|
||||
}
|
||||
return string();
|
||||
@ -1480,7 +1480,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
||||
string const path = getMasterFilePath();
|
||||
// We want to preserve relative / absolute filenames,
|
||||
// therefore path is only used for testing
|
||||
if (!fs::exists(makeAbsPath(name, path))) {
|
||||
if (!fs::exists(FileName(makeAbsPath(name, path)).toFilesystemEncoding())) {
|
||||
// The file extension is probably missing.
|
||||
// Now try to find it out.
|
||||
string const dvips_name =
|
||||
@ -1510,7 +1510,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
||||
name = pdftex_name;
|
||||
}
|
||||
|
||||
if (fs::exists(makeAbsPath(name, path)))
|
||||
if (fs::exists(FileName(makeAbsPath(name, path)).toFilesystemEncoding()))
|
||||
fix_relative_filename(name);
|
||||
else
|
||||
cerr << "Warning: Could not find graphics file '"
|
||||
@ -2132,7 +2132,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
||||
// We want to preserve relative / absolute filenames,
|
||||
// therefore path is only used for testing
|
||||
if (t.cs() == "include" &&
|
||||
!fs::exists(makeAbsPath(filename, path))) {
|
||||
!fs::exists(FileName(makeAbsPath(filename, path)).toFilesystemEncoding())) {
|
||||
// The file extension is probably missing.
|
||||
// Now try to find it out.
|
||||
string const tex_name =
|
||||
@ -2141,7 +2141,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
||||
if (!tex_name.empty())
|
||||
filename = tex_name;
|
||||
}
|
||||
if (fs::exists(makeAbsPath(filename, path))) {
|
||||
if (fs::exists(FileName(makeAbsPath(filename, path)).toFilesystemEncoding())) {
|
||||
string const abstexname =
|
||||
makeAbsPath(filename, path);
|
||||
string const abslyxname =
|
||||
|
Loading…
Reference in New Issue
Block a user