@@ -168,6 +168,96 @@ public class ExportEditable : Export {
168168
169169 }
170170
171+ // -------------------------------------------------------------
172+ // Loads the XML file and updates the editor.
173+ private void load_xml ( string fname ) {
174+
175+ Xml . Doc * doc = Xml . Parser . read_file( fname, null , Xml . ParserOption . HUGE );
176+ if ( doc == null ) return ;
177+
178+ for ( Xml . Node * it= doc- > get_root_element()- > children; it!= null ; it= it- > next ) {
179+ if ( (it- > type == Xml . ElementType . ELEMENT_NODE ) && (it- > name == " canvas" ) ) {
180+ canvas. load( it );
181+ }
182+ }
183+
184+ delete doc;
185+
186+ }
187+
188+ // -------------------------------------------------------------
189+ // Imports the given filename.
190+ public void import ( string filename ) {
191+
192+ string temp_dir;
193+
194+ // Make the temporary directory
195+ try {
196+ temp_dir = DirUtils . make_tmp( " annotator-XXXXXX" );
197+ } catch ( Error e ) {
198+ critical( e. message );
199+ return ;
200+ }
201+
202+ Archive . Read archive = new Archive .Read ();
203+ archive. support_filter_gzip();
204+ archive. support_format_all();
205+
206+ Archive . ExtractFlags flags;
207+ flags = Archive . ExtractFlags . TIME ;
208+ flags |= Archive . ExtractFlags . PERM ;
209+ flags |= Archive . ExtractFlags . ACL ;
210+ flags |= Archive . ExtractFlags . FFLAGS ;
211+
212+ Archive . WriteDisk extractor = new Archive .WriteDisk ();
213+ extractor. set_options( flags );
214+ extractor. set_standard_lookup();
215+
216+ /* Open the portable Minder file for reading */
217+ if ( archive. open_filename( filename, 16384 ) != Archive . Result . OK ) {
218+ load_xml( filename );
219+ return ;
220+ }
221+
222+ unowned Archive . Entry entry;
223+
224+ while ( archive. next_header( out entry ) == Archive . Result . OK ) {
225+
226+ /*
227+ We will need to modify the entry pathname so the file is written to the
228+ proper location.
229+ */
230+ if ( entry. pathname() == " annotations.xml" ) {
231+ entry. set_pathname( GLib . Path . build_filename( temp_dir, entry. pathname() ) );
232+ } else {
233+ entry. set_pathname( GLib . Path . build_filename( temp_dir, " images" , entry. pathname() ) );
234+ }
235+
236+ /* Read from the archive and write the files to disk */
237+ if ( extractor. write_header( entry ) != Archive . Result . OK ) {
238+ continue ;
239+ }
240+ uint8 [] buffer;
241+ Archive . int64_t offset;
242+
243+ while ( archive. read_data_block( out buffer, out offset ) == Archive . Result . OK ) {
244+ if ( extractor. write_data_block( buffer, offset ) != Archive . Result . OK ) {
245+ break ;
246+ }
247+ }
248+
249+ }
250+
251+ /* Close the archive */
252+ if ( archive. close () != Archive . Result . OK ) {
253+ error( " Error: %s (%d )" , archive. error_string(), archive. errno() );
254+ }
255+
256+ /* Finally, load the XML file */
257+ load_xml( GLib . Path . build_filename( temp_dir, " annotations.xml" ) );
258+
259+ }
260+
171261 // -------------------------------------------------------------
172262 // Add the setting to enable/disable including the images included
173263 // in the annotation.
0 commit comments