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

View File

@ -99,7 +99,7 @@ public:
void loadAutoSaveFile();
/// load a new file
bool readFile(std::string const & filename);
bool readFile(support::FileName const & filename);
/// read the header, returns number of unknown tokens
int readHeader(LyXLex & lex);
@ -367,7 +367,7 @@ private:
/** Inserts a file into a document
\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;

View File

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