MCPcopy
hub / github.com/arduino/Arduino / Archiver

Class Archiver

app/src/processing/app/tools/Archiver.java:44–181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42
43
44public class Archiver implements Tool {
45 Editor editor;
46
47 // someday these will be settable
48 boolean useDate;
49 int digits = 3;
50
51 NumberFormat numberFormat;
52 SimpleDateFormat dateFormat;
53
54
55 public String getMenuTitle() {
56 return tr("Archive Sketch");
57 }
58
59
60 public void init(Editor editor) {
61 this.editor = editor;
62
63 numberFormat = NumberFormat.getInstance();
64 numberFormat.setGroupingUsed(false); // no commas
65 numberFormat.setMinimumIntegerDigits(digits);
66
67 dateFormat = new SimpleDateFormat("yyMMdd");
68 }
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) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected