prevent infinite "sketch disappeared" warnings (fixes #4805)

This commit is contained in:
Ben Fry
2019-01-18 11:19:28 -08:00
parent 7236c84a63
commit fc6b8385bd
2 changed files with 32 additions and 23 deletions

View File

@@ -40,7 +40,9 @@ import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.swing.*;
@@ -1497,29 +1499,36 @@ public class Sketch {
*/
private Set<File> existenceWarnings = new HashSet<>();
/**
* Make sure the sketch hasn't been moved or deleted by some
* nefarious user. If they did, try to re-create it and save.
* Only checks to see if the main folder is still around,
* but not its contents.
* Make sure the sketch hasn't been moved or deleted by a nefarious user.
* If they did, try to re-create it and save. Only checks whether the
* main folder is still around, but not its contents.
*/
public void ensureExistence() {
if (!folder.exists()) {
// Disaster recovery, try to salvage what's there already.
Messages.showWarning(Language.text("ensure_exist.messages.missing_sketch"),
Language.text("ensure_exist.messages.missing_sketch.description"));
try {
folder.mkdirs();
modified = true;
// Avoid an infinite loop if we've already warned about this
// https://github.com/processing/processing/issues/4805
if (!existenceWarnings.contains(folder)) {
existenceWarnings.add(folder);
for (int i = 0; i < codeCount; i++) {
code[i].save(); // this will force a save
// Disaster recovery, try to salvage what's there already.
Messages.showWarning(Language.text("ensure_exist.messages.missing_sketch"),
Language.text("ensure_exist.messages.missing_sketch.description"));
try {
folder.mkdirs();
modified = true;
for (int i = 0; i < codeCount; i++) {
code[i].save(); // this will force a save
}
calcModified();
} catch (Exception e) {
Messages.showWarning(Language.text("ensure_exist.messages.unrecoverable"),
Language.text("ensure_exist.messages.unrecoverable.description"), e);
}
calcModified();
} catch (Exception e) {
Messages.showWarning(Language.text("ensure_exist.messages.unrecoverable"),
Language.text("ensure_exist.messages.unrecoverable.description"), e);
}
}
}

View File

@@ -22,6 +22,12 @@ jakub
X Fix sketch exception getting hidden by warning
X https://github.com/processing/processing/pull/5486
X https://github.com/processing/processing/issues/5412
X EventQueue problems with "could not find sketch size" message
X https://github.com/processing/processing/issues/4893
X https://github.com/processing/processing/pull/5708
X https://github.com/processing/processing/issues/5030 (duplicate)
X size(0, 0) just freezes instead of showing an error
X https://github.com/processing/processing/issues/5233 (duplicate)
_ Find in Reference disabled for various keywords (draw, for, if, catch, while)
@@ -38,12 +44,6 @@ _ seen in Eclipse; have to turn on the debugger
_ "Sketch disappeared" infinite pop up dialogs
_ https://github.com/processing/processing/pull/4808
_ https://github.com/processing/processing/issues/4805
_ EventQueue problems with "could not find sketch size" message
_ https://github.com/processing/processing/issues/4893
X https://github.com/processing/processing/pull/5708
X https://github.com/processing/processing/issues/5030 (duplicate)
_ size(0, 0) just freezes instead of showing an error
X https://github.com/processing/processing/issues/5233 (duplicate)
manager