Convert filenames to local encoding for running lyx2lyx

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16311 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2006-12-17 12:12:17 +00:00
parent e4c3ce4627
commit 29b6f5cad9
3 changed files with 27 additions and 26 deletions

View File

@ -569,11 +569,10 @@ void Buffer::insertStringAsLines(ParagraphList & pars,
} }
bool Buffer::readFile(string const & filename) bool Buffer::readFile(FileName const & filename)
{ {
// Check if the file is compressed. // Check if the file is compressed.
FileName const name(makeAbsPath(filename)); string const format = getFormatFromContents(filename);
string const format = getFormatFromContents(name);
if (format == "gzip" || format == "zip" || format == "compress") { if (format == "gzip" || format == "zip" || format == "compress") {
params().compressed = true; params().compressed = true;
} }
@ -581,7 +580,7 @@ bool Buffer::readFile(string const & filename)
// remove dummy empty par // remove dummy empty par
paragraphs().clear(); paragraphs().clear();
LyXLex lex(0, 0); LyXLex lex(0, 0);
lex.setFile(name); lex.setFile(filename);
if (!readFile(lex, filename)) if (!readFile(lex, filename))
return false; return false;
@ -606,13 +605,13 @@ void Buffer::fully_loaded(bool const value)
} }
bool Buffer::readFile(LyXLex & lex, string const & filename) bool Buffer::readFile(LyXLex & lex, FileName const & filename)
{ {
BOOST_ASSERT(!filename.empty()); BOOST_ASSERT(!filename.empty());
if (!lex.isOK()) { if (!lex.isOK()) {
Alert::error(_("Document could not be read"), Alert::error(_("Document could not be read"),
bformat(_("%1$s could not be read."), from_utf8(filename))); bformat(_("%1$s could not be read."), from_utf8(filename.absFilename())));
return false; return false;
} }
@ -621,7 +620,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
if (!lex.isOK()) { if (!lex.isOK()) {
Alert::error(_("Document could not be read"), Alert::error(_("Document could not be read"),
bformat(_("%1$s could not be read."), from_utf8(filename))); bformat(_("%1$s could not be read."), from_utf8(filename.absFilename())));
return false; return false;
} }
@ -631,7 +630,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
Alert::error(_("Document format failure"), Alert::error(_("Document format failure"),
bformat(_("%1$s is not a LyX document."), bformat(_("%1$s is not a LyX document."),
from_utf8(filename))); from_utf8(filename.absFilename())));
return false; return false;
} }
@ -647,14 +646,14 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
//lyxerr << "format: " << file_format << endl; //lyxerr << "format: " << file_format << endl;
if (file_format != LYX_FORMAT) { if (file_format != LYX_FORMAT) {
string const tmpfile = tempName(); FileName const tmpfile(tempName());
if (tmpfile.empty()) { if (tmpfile.empty()) {
Alert::error(_("Conversion failed"), Alert::error(_("Conversion failed"),
bformat(_("%1$s is from an earlier" bformat(_("%1$s is from an earlier"
" version of LyX, but a temporary" " version of LyX, but a temporary"
" file for converting it could" " file for converting it could"
" not be created."), " not be created."),
from_utf8(filename))); from_utf8(filename.absFilename())));
return false; return false;
} }
FileName const lyx2lyx = libFileSearch("lyx2lyx", "lyx2lyx"); FileName const lyx2lyx = libFileSearch("lyx2lyx", "lyx2lyx");
@ -664,14 +663,15 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
" version of LyX, but the" " version of LyX, but the"
" conversion script lyx2lyx" " conversion script lyx2lyx"
" could not be found."), " could not be found."),
from_utf8(filename))); from_utf8(filename.absFilename())));
return false; return false;
} }
ostringstream command; ostringstream command;
command << os::python() << ' ' << quoteName(lyx2lyx.toFilesystemEncoding()) command << os::python()
<< ' ' << quoteName(lyx2lyx.toFilesystemEncoding())
<< " -t " << convert<string>(LYX_FORMAT) << " -t " << convert<string>(LYX_FORMAT)
<< " -o " << quoteName(tmpfile) << ' ' << " -o " << quoteName(tmpfile.toFilesystemEncoding())
<< quoteName(filename); << ' ' << quoteName(filename.toFilesystemEncoding());
string const command_str = command.str(); string const command_str = command.str();
lyxerr[Debug::INFO] << "Running '" lyxerr[Debug::INFO] << "Running '"
@ -684,7 +684,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
bformat(_("%1$s is from an earlier version" bformat(_("%1$s is from an earlier version"
" of LyX, but the lyx2lyx script" " of LyX, but the lyx2lyx script"
" failed to convert it."), " failed to convert it."),
from_utf8(filename))); from_utf8(filename.absFilename())));
return false; return false;
} else { } else {
bool const ret = readFile(tmpfile); bool const ret = readFile(tmpfile);
@ -698,7 +698,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
Alert::error(_("Document format failure"), Alert::error(_("Document format failure"),
bformat(_("%1$s ended unexpectedly, which means" bformat(_("%1$s ended unexpectedly, which means"
" that it is probably corrupted."), " that it is probably corrupted."),
from_utf8(filename))); from_utf8(filename.absFilename())));
} }
//lyxerr << "removing " << MacroTable::localMacros().size() //lyxerr << "removing " << MacroTable::localMacros().size()

View File

@ -99,7 +99,7 @@ public:
void loadAutoSaveFile(); void loadAutoSaveFile();
/// load a new file /// load a new file
bool readFile(std::string const & filename); bool readFile(support::FileName const & filename);
/// read the header, returns number of unknown tokens /// read the header, returns number of unknown tokens
int readHeader(LyXLex & lex); int readHeader(LyXLex & lex);
@ -367,7 +367,7 @@ private:
/** Inserts a file into a document /** Inserts a file into a document
\return \c false if method fails. \return \c false if method fails.
*/ */
bool readFile(LyXLex &, std::string const & filename); bool readFile(LyXLex &, support::FileName const & filename);
bool do_writeFile(std::ostream & ofs) const; bool do_writeFile(std::ostream & ofs) const;

View File

@ -55,6 +55,7 @@ using namespace std;
using support::bformat; using support::bformat;
using support::FileName; using support::FileName;
using support::libFileSearch; using support::libFileSearch;
using support::makeAbsPath;
using support::makeDisplayPath; using support::makeDisplayPath;
using support::onlyFilename; using support::onlyFilename;
using support::onlyPath; using support::onlyPath;
@ -100,7 +101,7 @@ bool readFile(Buffer * const b, FileName const & s)
case 0: case 0:
// the file is not saved if we load the emergency file. // the file is not saved if we load the emergency file.
b->markDirty(); b->markDirty();
return b->readFile(e.absFilename()); return b->readFile(e);
case 1: case 1:
break; break;
default: default:
@ -127,7 +128,7 @@ bool readFile(Buffer * const b, FileName const & s)
case 0: case 0:
// the file is not saved if we load the autosave file. // the file is not saved if we load the autosave file.
b->markDirty(); b->markDirty();
return b->readFile(a.absFilename()); return b->readFile(a);
case 1: case 1:
// Here we delete the autosave // Here we delete the autosave
unlink(a); unlink(a);
@ -136,7 +137,7 @@ bool readFile(Buffer * const b, FileName const & s)
return false; return false;
} }
} }
return b->readFile(s.absFilename()); return b->readFile(s);
} }
@ -185,16 +186,16 @@ Buffer * newFile(string const & filename, string const & templatename,
Buffer * b = theBufferList().newBuffer(filename); Buffer * b = theBufferList().newBuffer(filename);
BOOST_ASSERT(b); BOOST_ASSERT(b);
string tname; FileName tname;
// use defaults.lyx as a default template if it exists. // use defaults.lyx as a default template if it exists.
if (templatename.empty()) if (templatename.empty())
tname = libFileSearch("templates", "defaults.lyx").absFilename(); tname = libFileSearch("templates", "defaults.lyx");
else else
tname = templatename; tname = FileName(makeAbsPath(templatename));
if (!tname.empty()) { if (!tname.empty()) {
if (!b->readFile(tname)) { if (!b->readFile(tname)) {
docstring const file = makeDisplayPath(tname, 50); docstring const file = makeDisplayPath(tname.absFilename(), 50);
docstring const text = bformat( docstring const text = bformat(
_("The specified document template\n%1$s\ncould not be read."), _("The specified document template\n%1$s\ncould not be read."),
file); file);