("1_3", [221], generate_minor_versions("1.3" , 7)),
("1_4", range(222,246), generate_minor_versions("1.4" , 5)),
("1_5", range(246,277), generate_minor_versions("1.5" , 1)),
- ("1_6", range(277,285), generate_minor_versions("1.6" , 0))]
+ ("1_6", range(277,286), generate_minor_versions("1.6" , 0))]
def formats_list():
self.default_layout = ''
self.header = []
self.preamble = []
+ self.manifest = []
self.body = []
self.status = 0
self.encoding = encoding
def read(self):
- """Reads a file into the self.header and self.body parts, from self.input."""
+ """Reads a file into the self.header, self.manifest and self.body parts, from self.input."""
while 1:
line = self.input.readline()
if check_token(line, '\\end_preamble'):
continue
+ if check_token(line, '\\begin_manifest'):
+ while 1:
+ line = self.input.readline()
+ if not line:
+ self.error("Invalid LyX file.")
+
+ line = trim_eol(line)
+ if check_token(line, "\\end_manifest"):
+ break
+
+ if not line.startswith('\\filename') and not line.startswith('\\inzipName') \
+ and not line.startswith('\\embed'):
+ self.warning("Malformed LyX file: Missing '\\end_manifest'.")
+
+ self.manifest.append(line)
+
+ if check_token(line, '\\end_manifest'):
+ continue
+
line = line.strip()
if not line:
continue
else:
header = self.header
- for line in header + [''] + self.body:
+ # LyX file format <= 284 does not have a manifest section
+ # so this section is set to None
+ if self.manifest is None:
+ manifest = []
+ else:
+ manifest = ['\\begin_manifest'] + self.manifest + ['\\end_manifest', '']
+
+ for line in header + [''] + manifest + self.body:
self.output.write(line.encode(self.encoding)+"\n")
document.body[i] = document.body[i].replace('\\begin_inset Flex', '\\begin_inset CharStyle')
+def remove_manifest(document):
+ "Remove the manifest section"
+ document.manifest = None
+
##
# Conversion hub
[281, []],
[282, []],
[283, [convert_flex]],
- [284, []]
+ [284, []],
+ [285, []], # an empty manifest is automatically added
]
revert = [
+ [284, [remove_manifest]],
[283, []],
[282, [revert_flex]],
[281, []],
namespace {
-int const LYX_FORMAT = 284;
+int const LYX_FORMAT = 285;
} // namespace anon
"\\lyxadded and \\lyxdeleted in the LaTeX preamble."));
}
}
+ // read manifest after header
+ embeddedFiles().readManifest(lex, errorList);
+ // read main text
bool const res = text().read(*this, lex, errorList);
for_each(text().paragraphs().begin(),
text().paragraphs().end(),
LYXERR(Debug::FILES) << filename << " is in zip format. Unzip to " << temppath() << endl;
::unzipToDir(filename.toFilesystemEncoding(), temppath());
//
- FileName manifest(addName(temppath(), "manifest.txt"));
- FileName lyxfile(addName(temppath(),
- onlyFilename(filename.toFilesystemEncoding())));
+ FileName lyxfile(addName(temppath(), "content.lyx"));
// if both manifest.txt and file.lyx exist, this is am embedded file
- if (fs::exists(manifest.toFilesystemEncoding()) &&
- fs::exists(lyxfile.toFilesystemEncoding())) {
+ if (fs::exists(lyxfile.toFilesystemEncoding())) {
params().embedded = true;
fname = lyxfile;
}
FileName content;
if (params().embedded)
// first write the .lyx file to the temporary directory
- content = FileName(addName(temppath(),
- onlyFilename(fname.toFilesystemEncoding())));
+ content = FileName(addName(temppath(), "content.lyx"));
else
content = fname;
if (retval && params().embedded) {
// write file.lyx and all the embedded files to the zip file fname
- // if embedding is enabled, and there is any embedded file
- pimpl_->embedded_files.update();
- return pimpl_->embedded_files.write(fname);
+ // if embedding is enabled
+ return pimpl_->embedded_files.writeFile(fname);
}
return retval;
}
params().writeFile(ofs);
ofs << "\\end_header\n";
+ // write the manifest after header
+ ofs << "\n\\begin_manifest\n";
+ pimpl_->embedded_files.update();
+ embeddedFiles().writeManifest(ofs);
+ ofs << "\\end_manifest\n";
+
// write the text
ofs << "\n\\begin_body\n";
text().write(*this, ofs);
}
-bool EmbeddedFiles::write(DocFileName const & filename)
+bool EmbeddedFiles::writeFile(DocFileName const & filename)
{
// file in the temporary path has the content
string const content = FileName(addName(buffer_->temppath(),
int begin_manifest_line = -1;
file_list_.clear();
- string filename = "";
- string inzipName = "";
- bool status = "";
+ string filename;
+ string inzipName;
+ bool embedded = false;
while (lex.isOK()) {
lex.next();
lex >> filename;
else if (token == "\\inzipName")
lex >> inzipName;
- else if (token == "\\status") {
- lex >> status;
- registerFile(filename, status, NULL, inzipName);
+ else if (token == "\\embed") {
+ lex >> embedded;
+ registerFile(filename, embedded, NULL, inzipName);
filename = "";
inzipName = "";
} else {
<< to_utf8(makeRelPath(from_utf8(it->absFilename()),
from_utf8(buffer_->filePath()))) << '\n'
<< "\\inzipName " << it->inzipName() << '\n'
- << "\\status " << (it->embedded() ? "true" : "false") << '\n';
+ << "\\embed " << (it->embedded() ? "true" : "false") << '\n';
}
}
3. When a lyx file file.lyx is saved, it is save to tmppath() first.
Embedded files are compressed along with file.lyx and a manifest.txt.
If embedding is disabled, file.lyx is saved in the usual pure-text form.
-(c.f. Buffer::writeFile(), EmbeddedFiles::write())
+(c.f. Buffer::writeFile(), EmbeddedFiles::writeFile())
4. When a lyx file.lyx file is opened, if it is a zip file, it is
decompressed to tmppath(). If manifest.txt and file.lyx exists in
void update();
/// write a zip file
- bool write(support::DocFileName const & filename);
+ bool writeFile(support::DocFileName const & filename);
void clear() { file_list_.clear(); }