1
6
7 import java.util.zip.*;
8 import java.util.*;
9 import java.util.jar.*;
10 import java.io.*;
11 import javax.swing.*;
12
13 public class DebugFile {
14
15 JarOutputStream out = null;
16
17 public void addFile(String name) {
18 addFile(new File(Carto.filebase+"/"+name));
19 }
20
21 public void addFile(File infile) {
22 if (infile==null || !infile.exists()) return;
23
24 try {
25 InputStream in = new FileInputStream(infile);
26
27 JarEntry entry = new JarEntry(infile.toString());
28 out.putNextEntry(entry);
29
30 byte[] buff = new byte[1000];
31 for (int num = in.read(buff);num>0;num=in.read(buff)) {
32 out.write(buff,0,num);
33 }
34 out.closeEntry();
35 in.close();
36 }
37 catch (IOException ex) {ErrorLog.exception(ex,"Trouble saving "+infile+" to debug file");}
38
39 }
40
41
42 public DebugFile(CartoFrame source) {
43 try {
44 ErrorLog.log("Creating debug file\nFirst, save the .cto file");
45 source.save(null);
46
47 ErrorLog.flushLog();
48 JFileChooser choose = Persist.current.getFileChooser();
49 choose.setFileFilter(new FileTypes(FileTypes.JAR));
50 choose.rescanCurrentDirectory();
51 if (choose.showSaveDialog(null)!=choose.APPROVE_OPTION) return;
52 File savefile = choose.getSelectedFile();
53 if (!savefile.getName().endsWith(".jar"))
54 savefile = new File(savefile.toString().concat(".jar"));
55
56 out = new JarOutputStream(new FileOutputStream(savefile));
57
58 addFile("Version.txt");
59 addFile("error.txt");
60 addFile("persist.sta");
61
62 addFile(source.file);
63
64 for (Iterator it = source.carto.segmentlist.iterator();it.hasNext();) {
65 Segment seg = (Segment)it.next();
66 addFile(seg.isource.getFile());
67
68 }
69
70 out.finish();
71 out.close();
72 }
73 catch (IOException ex) {ErrorLog.exception(ex,"Trouble making debug file");}
74
75 out = null;
76 }
77 }
78