()
| 69 | |
| 70 | |
| 71 | public void run() { |
| 72 | SketchController sketch = editor.getSketchController(); |
| 73 | |
| 74 | // first save the sketch so that things don't archive strangely |
| 75 | boolean success = false; |
| 76 | try { |
| 77 | success = sketch.save(); |
| 78 | } catch (Exception e) { |
| 79 | e.printStackTrace(); |
| 80 | } |
| 81 | if (!success) { |
| 82 | Base.showWarning(tr("Couldn't archive sketch"), |
| 83 | tr("Archiving the sketch has been canceled because\nthe sketch couldn't save properly."), null); |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | File location = sketch.getSketch().getFolder(); |
| 88 | String name = location.getName(); |
| 89 | File parent = new File(location.getParent()); |
| 90 | |
| 91 | //System.out.println("loc " + location); |
| 92 | //System.out.println("par " + parent); |
| 93 | |
| 94 | File newbie = null; |
| 95 | String namely = null; |
| 96 | int index = 0; |
| 97 | do { |
| 98 | // only use the date if the sketch name isn't the default name |
| 99 | useDate = !name.startsWith("sketch_"); |
| 100 | |
| 101 | if (useDate) { |
| 102 | String purty = dateFormat.format(new Date()); |
| 103 | String stamp = purty + ((char) ('a' + index)); |
| 104 | namely = name + "-" + stamp; |
| 105 | newbie = new File(parent, namely + ".zip"); |
| 106 | |
| 107 | } else { |
| 108 | String diggie = numberFormat.format(index + 1); |
| 109 | namely = name + "-" + diggie; |
| 110 | newbie = new File(parent, namely + ".zip"); |
| 111 | } |
| 112 | index++; |
| 113 | } while (newbie.exists()); |
| 114 | |
| 115 | // open up a prompt for where to save this fella |
| 116 | FileDialog fd = new FileDialog(editor, tr("Archive sketch as:"), FileDialog.SAVE); |
| 117 | fd.setDirectory(parent.getAbsolutePath()); |
| 118 | fd.setFile(newbie.getName()); |
| 119 | fd.setVisible(true); |
| 120 | |
| 121 | String directory = fd.getDirectory(); |
| 122 | String filename = fd.getFile(); |
| 123 | |
| 124 | // only write the file if not canceled |
| 125 | if (filename != null) { |
| 126 | newbie = new File(directory, filename); |
| 127 | |
| 128 | ZipOutputStream zos = null; |
nothing calls this directly
no test coverage detected