> > Two suggestions:
> >   - include the manifest in the header. Possibly it can be place before the
> > preamble although the order is irrelevant.
>
> This will lead to more work in .cpp. I will see.

Looking at the code in Buffer.cpp, I do not think this is a good idea:

Write:
        // now write out the buffer parameters.
        ofs << "\\begin_header\n";
        params().writeFile(ofs);
        ofs << "\\end_header\n";

Read:
        while (lex.isOK()) {
        string unknown = params().readToken(lex, token);
                if (!unknown.empty()) {
        
You can see that header <==> params() so unless I move embedded_files_
to params(), this does not look right.

If you do not like version testing in LyX.py, the attached version
moves this to lyx_1_6.py,

in LyX.py:

+        # 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:

and in lyx_1_6.py:

+def remove_manifest(document):
+    "Remove the manifest section"
+    document.menifest = None

+ revert =  [
+           [284, [remove_manifest]],


Cheers,
Bo
Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp	(revision 20190)
+++ src/Buffer.cpp	(working copy)
@@ -142,7 +142,7 @@
 
 namespace {
 
-int const LYX_FORMAT = 284;
+int const LYX_FORMAT = 285;
 
 } // namespace anon
 
@@ -559,7 +559,10 @@
 					 "\\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(),
@@ -661,12 +664,9 @@
 		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;
 		}
@@ -890,7 +890,7 @@
 	if (params().embedded)
 		// first write the .lyx file to the temporary directory
 		content = FileName(addName(temppath(), 
-			onlyFilename(fname.toFilesystemEncoding())));
+			"content.lyx"));
 	else
 		content = fname;
 	
@@ -911,7 +911,6 @@
 	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);
 	}
 	return retval;
@@ -951,6 +950,12 @@
 	params().writeFile(ofs);
 	ofs << "\\end_header\n";
 
+	// write a manifest
+	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);
Index: lib/lyx2lyx/LyX.py
===================================================================
--- lib/lyx2lyx/LyX.py	(revision 20190)
+++ lib/lyx2lyx/LyX.py	(working copy)
@@ -78,7 +78,7 @@
                    ("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():
@@ -175,6 +175,7 @@
         self.default_layout = ''
         self.header = []
         self.preamble = []
+        self.manifest = []
         self.body = []
         self.status = 0
         self.encoding = encoding
@@ -198,7 +199,7 @@
 
 
     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()
@@ -225,6 +226,25 @@
             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('\\status'):
+                        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
@@ -275,7 +295,14 @@
         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")
 
 
Index: lib/lyx2lyx/lyx_1_6.py
===================================================================
--- lib/lyx2lyx/lyx_1_6.py	(revision 20190)
+++ lib/lyx2lyx/lyx_1_6.py	(working copy)
@@ -174,7 +174,11 @@
         document.body[i] = document.body[i].replace('\\begin_inset Flex', '\\begin_inset CharStyle')
 
 
+def remove_manifest(document):
+    "Remove the manifest section"
+    document.menifest = None
 
+
 ##
 # Conversion hub
 #
@@ -188,10 +192,12 @@
            [281, []],
            [282, []],
            [283, [convert_flex]],
-           [284, []]
+           [284, []],
+           [285, []], # an empty manifest is automatically added
           ]
 
 revert =  [
+           [284, [remove_manifest]],
            [283, []],
            [282, [revert_flex]],
            [281, []],

Reply via email to