Skip to content

Commit

Permalink
Merge pull request #768 from fesch/bugfix
Browse files Browse the repository at this point in the history
Version 3.30-01 candidate
  • Loading branch information
fesch authored Oct 16, 2019
2 parents a95f688 + ce311d2 commit dc70569
Show file tree
Hide file tree
Showing 23 changed files with 275 additions and 2,661 deletions.
4 changes: 2 additions & 2 deletions buildapp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
name="Structorizer"
displayname="Structorizer"
identifier="lu.fisch.Structorizer"
shortversion="3.30"
version="3.30"
shortversion="3.30-01"
version="3.30-01"
icon="icons/Structorizer.icns"
mainclassname="Structorizer"
copyright="Bob Fisch"
Expand Down
19 changes: 18 additions & 1 deletion src/lu/fisch/structorizer/archivar/Archivar.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* Kay Gürtzig 2019-03-14 Enh. #697: New method deriveArrangementList()
* Kay Gürtzig 2019-03-26 Enh. #697: Bugfixes in zipArrangement(), saveArrangement()
* Kay Gürtzig 2019-07-31 Bugfix #731 (also comprising #526): new static methods renameTo, copyFile
* Kay Gürtzig 2019-10-14 Bugfix #763: Missing references files now add to the problem list on loading
*
******************************************************************************************************
*
Expand Down Expand Up @@ -848,7 +849,7 @@ private String compressFiles(File _archive, StringList _filePaths) throws IOExce
/**
* Loads the arrangement described in {@code _arrFile} and returns the diagrams and their locations
* at least. If necessary and either {@code _arrFile} is given or the listed path is a virtual path
* into an archive tries to extract the files, eithe into {@code _tempDir} is given or into a new
* into an archive tries to extract the files, either into {@code _tempDir} if given or into a new
* temporary folder.
* @param _arrFile - the arrangement list file containing the names or paths of the diagram files
* @param _fromArchive - the arrangement archive file if the arangement originates in the archive (for extraction)
Expand All @@ -869,6 +870,7 @@ public List<ArchiveRecord> loadArrangement(File _arrFile, File _fromArchive, Fil
StringList fields = StringList.explode(line, ",");
if (fields.count() >= 3)
{
boolean fileMissing = false;
Root root = null;
Point point = new Point();
point.x = Integer.parseInt(fields.get(0));
Expand All @@ -893,10 +895,25 @@ else if (_fromArchive == null && nsdFileName.contains(".arrz")) {
if (arrzFile.exists()) {
root = extractNSDFrom(arrzFile, pureName, null, _troubles);
}
// START KGU#749 2019-10-14: Bugfix #763 - we must inform about missing files
else {
fileMissing = true;
}
// END KGU#749 2019-10-14
}
// START KGU#749 2019-10-14: Bugfix #763 - we must inform about missing files
else {
fileMissing = true;
}
// END KGU#749 2019-10-14
if (root != null) {
items.add(new ArchiveRecord(root, point));
}
// START KGU#749 2019-10-14: Bugfix #763 - we must inform about missing files
else if (fileMissing) {
_troubles.add(_arrFile.getName() + ": \"" + nsd.getAbsolutePath() + "\" MISSING!");
}
// END KGU#749 2019-10-14
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lu/fisch/structorizer/arranger/ArrangerIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ protected void arrangerIndexSave()
Group resultGroup = Arranger.getInstance().saveGroup(this, selectedGroup);
// Now update the list of recent files in case the saving was successful
if (resultGroup != null) {
File groupFile = resultGroup.getArrzFile();
File groupFile = resultGroup.getArrzFile(true);
if (groupFile != null || (groupFile = resultGroup.getFile()) != null) {
this.diagram.addRecentFile(groupFile.getAbsolutePath());
}
Expand Down
22 changes: 16 additions & 6 deletions src/lu/fisch/structorizer/arranger/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* Kay Gürtzig 2019-03-01 Enh. #691 Method rename() added (does only parts of what is to be done)
* Kay Gürtzig 2019-03-11 Modification in addDiagram() for bugfix #699
* Kay Gürtzig 2019-03-19 Issues #518, #544, #557: Drawing depends on visible rect now.
* Kay Gürtzig 2019-10-15 Issue #763: Method getArrzFile parameterized to address stale .arrz files
*
******************************************************************************************************
*
Expand Down Expand Up @@ -326,7 +327,7 @@ public String proposeFileName()
* @return a {@link File} object with the associated absolute path of the
* Arranger list file this group is associated to (stemming from or last saved to)
* or null if the group had never been associated to an arrangement file.
* @see #getArrzFile()
* @see #getArrzFile(boolean)
*/
public File getFile()
{
Expand All @@ -341,15 +342,24 @@ public File getFile()
* Arranger archive this group's Arranger list file and diagram files
* are residing in. Returns null if the group is not residing in an
* arrz file.
* @return either a {@link File} object for an arrz file or null
* @param onlyIfExistent - if true then in case of an invalid .arrz path null will be returned, otherwise
* a returned {@link File} object may represent a non-existent file (needs checking).
* @return either a {@link File} object for an .arrz file or null (not that the resulting file may not exist
* if {@code onlyIfExitent} was false
* @see #getFile()
*/
public File getArrzFile()
// START KGU#749 2019-10-15: Bugfix #763 - We need a possibility to identify even a stale arrz file
//public File getArrzFile()
public File getArrzFile(boolean onlyIfExistent)
// END KGU#749 2019-10-15
{
File file = this.getFile();
if (file != null && !file.exists() && this.filePath.toLowerCase().contains(".arrz")) {
file = file.getParentFile();
if (!file.isFile() || !file.getName().toLowerCase().endsWith(".arrz")) {
// START KGU#749 2019-10-15: Issue #763
//if (!file.isFile() || !file.getName().toLowerCase().endsWith(".arrz")) {
if (!file.getName().toLowerCase().endsWith(".arrz") || onlyIfExistent && !file.isFile()) {
// END KGU#749 2019-10-15
file = null;
}
}
Expand All @@ -371,7 +381,7 @@ public File getArrzFile()
* @param adaptDiagrams - if true and {@code arrzFile} isn't null then the virtual file
* paths of all diagrams matching the previous arrz path will be updated to {@code arrzFile}.
* @see #getFile()
* @see #getArrzFile()
* @see #getArrzFile(boolean)
* @see Surface#renameGroup(Group, String, java.awt.Component)
*/
protected void setFile(File arrFile, File arrzFile, boolean adaptDiagrams)
Expand Down Expand Up @@ -690,7 +700,7 @@ protected Rectangle getBounds(boolean forceUpdate) {
public ImageIcon getIcon(boolean withColor)
{
int iconNo = 94;
if (getArrzFile() != null) {
if (getArrzFile(false) != null) {
iconNo = 96;
}
else if (getFile() != null) {
Expand Down
88 changes: 72 additions & 16 deletions src/lu/fisch/structorizer/arranger/Surface.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@
* Kay Gürtzig 2019-05-14 Bugfix #722: Drawing within a BufferedImage (PNG export) failed.
* Kay Gürtzig 2019-07-31 Bugfix #731: File renaming failure on Linux made arrz files vanish
* Kay Gürtzig 2019-07-31 Bugfix #732: Diagrams cloned had shared the position rather than copied.
* Kay Gürtzig 2019-10-05 Bugfix #759: Missing reaction to closed Manforms impaired functioning
* Kay Gürtzig 2019-10-05 Bugfix #759: Missing reaction to closed Mainforms impaired functioning
* Kay Gürtzig 2019-10-13 Bugfix #763: Handling of stale file connections on saving and loading arrangements
* Kay Gürtzig 2019-10-14 Bugfix #764: Updating the .arr file of a modified group used to fail.
* Kay Gürtzig 2019-10-15 Bugfix #763: On resaving stale diagrams, the shadow path had to be cleared.
*
******************************************************************************************************
*
Expand Down Expand Up @@ -225,7 +228,6 @@
import javax.imageio.ImageIO;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
Expand Down Expand Up @@ -390,6 +392,9 @@ public class Surface extends LangPanel implements MouseListener, MouseMotionList
// START KGU#680 2019-03-11: Bugfix #699
public static final LangTextHolder msgSharedDiagrams = new LangTextHolder("The following diagrams will now be shared with the listed groups\n - %1\n\nBe aware that any modification to them will have an impact on all these groups\nand archive %2, even if the latter isn't loaded anymore!");
// END KGU#680 2019-03-11
// START KGU#749 2019-10-13: Bugfix #763
public static final LangTextHolder msgFileMissing = new LangTextHolder(" missing!");
// END KGU#749 2019-10-13

@Override
public void paintComponent(Graphics g)
Expand Down Expand Up @@ -951,7 +956,7 @@ else if (option < exactGroups.size()) {
else {
// The group originates from or has been saved to a file
File file = group.getFile();
File arrzFile = group.getArrzFile();
File arrzFile = group.getArrzFile(false);
if (arrzFile != null) {
portable = true;
extension += "z";
Expand Down Expand Up @@ -994,7 +999,7 @@ else if (option < exactGroups.size()) {
}
// END KGU#626 2019-01-02
// START KGU#679 2019-03-12: Enh. #698 - Inform associated Mainforms about the new file
File file = group.getArrzFile();
File file = group.getArrzFile(false);
if (done && !goingToClose && (file != null || (file = group.getFile()) != null)) {
for (Diagram diagr: group.getDiagrams()) {
if (diagr.mainform != null) {
Expand Down Expand Up @@ -1064,7 +1069,7 @@ private boolean saveArrangement(Component initiator, String filename, String ext
tempDir = dir.getParentFile();
}
}

LinkedList<Root> savedRoots = null;
try
{
// Prepare to save the arr file (if portable is false then this is the outfile)
Expand All @@ -1079,7 +1084,7 @@ private boolean saveArrangement(Component initiator, String filename, String ext
// name for the arr file to be zipped into the target file
arrFilename = tempDir + File.separator + (new File(filename)).getName() + ".arr";
// START KGU#650 2019-02-11: Issue #677 save all virgin group members to the temp dir
saveVirginRootsToTempDir(group, tempDir);
savedRoots = saveVirginRootsToTempDir(group, tempDir);
// END KGU#650 2019-02-11
}
else if (file.exists())
Expand Down Expand Up @@ -1122,7 +1127,13 @@ else if (file.exists())
}
}
Archivar archivar = new Archivar();
tmpFilename = archivar.saveArrangement(itemsToSave, arrFilename, (portable ? file : null), (portable ? tempDir : null), offset, null);
// START KGU#752 2019-10-14: Bugfix #764 - the update of the arr file if portable==false was averted
//tmpFilename = archivar.saveArrangement(itemsToSave, arrFilename, (portable ? file : null), (portable ? tempDir : null), offset, null);
String tmpArrzName = archivar.saveArrangement(itemsToSave, arrFilename, (portable ? file : null), (portable ? tempDir : null), offset, null);
if (portable) {
tmpFilename = tmpArrzName;
}
// END KGU#752 2019-10-14
// END KGU#679 2019-03-11

// START KGU#682 2019-03-15: Bugfix #703 - group change status must get a chance to be reset.
Expand Down Expand Up @@ -1219,6 +1230,15 @@ else if (portable) {
else if (diagr.root.shadowFilepath == null) {
sharedDiagrams.addOrdered(diagr.root.getSignatureString(false) + ": " +
groupNames.concatenate(", ").replace(Group.DEFAULT_GROUP_NAME, ArrangerIndex.msgDefaultGroupName.getText()));
if (savedRoots.contains(diagr.root)) {
for (String grName: diagr.getGroupNames()) {
Group gr = this.groups.get(grName);
if (gr != null && gr.getFile() != null && gr.getArrzFile(false) == null) {
// The arrangement list file is out of date (new diagram file path).
gr.membersChanged = true;
}
}
}
}
}
// Ensure all new copies are saved somewhere such that they will get a virtual path later
Expand All @@ -1237,7 +1257,7 @@ else if (diagr.root.shadowFilepath == null) {
msgSharedDiagrams.getText().replace("%1", sharedDiagrams.concatenate("\n - ")).replace("%2", (new File(outFilename).getName())),
this.msgSaveDialogTitle.getText(), JOptionPane.WARNING_MESSAGE);
}
// START KGU#682 2019-03-15: Issue #704 grop change status must be reset.
// START KGU#682 2019-03-15: Issue #704 group change status must be reset.
group.membersChanged = false;
// END KGU#682 2019-03-15
}
Expand All @@ -1261,13 +1281,35 @@ else if (diagr.root.shadowFilepath == null) {
}

// START KGU#650 2019-02-11: Issue #677 - Inconveniences on saving arrangement archives
/** Tries to save all unsaved group members in the given temporary directory with a unique name */
/** Tries to save all unsaved group members in the given temporary directory, ensuring
* unique names. Raises a message box with the names of all diagrams the saving attempt
* for which failed.
* @param group - the {@link Group} the diagrams of which are to be saved if not already associated to a file
* @param tempDir - the target directory
* @return a list of the {@link Root} objects that were successfully saved
*/
private LinkedList<Root> saveVirginRootsToTempDir(Group group, File tempDir) {
LinkedList<Root> savedRoots = new LinkedList<Root>();
StringList unsaved = new StringList();
StringList errors = new StringList();
for (Diagram diagr: group.getDiagrams()) {
if (diagr.root.getFile() == null) {
// START KGU#749 2019-10-13: Bugfix #763 - Diagrams with inaccessible files must also be saved
//if (diagr.root.getFile() == null) {
File assocFile = diagr.root.getFile();
// START KGU#749 2019-10-15: Bugfix #763 We must make sure that there is no obsolete shadow file path
// If there is a valid shadow file path then don't save it with a new file but wipe the file name
if (assocFile == null && diagr.root.shadowFilepath != null) {
assocFile = new File(diagr.root.shadowFilepath);
diagr.root.filename = assocFile.getAbsolutePath();
diagr.root.shadowFilepath = null;
if (assocFile.canRead()) {
// Formally this is a change as if the diagram had been saved again
savedRoots.add(diagr.root);
}
}
// END KGU#749 2019-10-15
if (assocFile == null || !assocFile.canRead()) {
// END KGU#749 2019-10-13
String filename = tempDir.getAbsolutePath() + File.separator + diagr.root.proposeFileName();
File file = new File(filename + ".nsd");
int count = 1;
Expand All @@ -1288,7 +1330,15 @@ private LinkedList<Root> saveVirginRootsToTempDir(Group group, File tempDir) {
diagr.mainform.doButtons();
}
} catch (IOException ex) {
unsaved.add(diagr.root.proposeFileName());
// START KGU#749 2019-10-13: Bugfix #763
//unsaved.add(diagr.root.proposeFileName());
if (assocFile != null) {
unsaved.add(assocFile.getAbsolutePath());
}
else {
unsaved.add(diagr.root.proposeFileName());
}
// END KGU#749 2019-10-13
errors.add(ex.toString());
}
finally {
Expand Down Expand Up @@ -1577,7 +1627,7 @@ public boolean loadArrangement(Frame frame, File arrFile, File unzippedFrom)
// Warn and ask for confirmation if this group has already been loaded
Group oldGroup = groups.get(groupName);
File oldFile = null;
if ((oldFile = oldGroup.getArrzFile()) != null && unzippedFrom != null && oldFile.compareTo(unzippedFrom) == 0 ||
if ((oldFile = oldGroup.getArrzFile(false)) != null && unzippedFrom != null && oldFile.compareTo(unzippedFrom) == 0 ||
(oldFile = oldGroup.getFile()) != null && oldFile.compareTo(arrFile) == 0) {
if (JOptionPane.showConfirmDialog(frame,
msgArrangementAlreadyLoaded.getText()
Expand Down Expand Up @@ -1680,7 +1730,7 @@ public boolean loadArrangement(Frame frame, File arrFile, File unzippedFrom)
StringList problems = new StringList();
List<ArchiveRecord> records = (new Archivar()).loadArrangement(arrFile, unzippedFrom, currentDirectory, problems);
if (!problems.isEmpty()) {
errorMessage = problems.getText();
errorMessage = problems.getText().replace(" MISSING!", msgFileMissing.getText());
}
Mainform form = (frame instanceof Mainform) ? (Mainform)frame : null;
for (ArchiveRecord record: records) {
Expand Down Expand Up @@ -3128,7 +3178,10 @@ private boolean saveDiagrams(Collection<Diagram> diagrams, boolean goingToClose,
Diagram diagram = iter.next();
Mainform form = diagram.mainform;
// START KGU#650 2019-02-11: Issue #677 - Ensure a Mainform if we have to archive diagrams
boolean hasFile = diagram.root.filename != null && !diagram.root.filename.trim().isEmpty();
// START KGU#749 2019-10-13: Bugfix #763 - make sure the file actually exists
//boolean hasFile = diagram.root.filename != null && !diagram.root.filename.trim().isEmpty();
boolean hasFile = diagram.root.getFile() != null;
// END KGU#749 2019-10-13
if (form == null && hasFile && forArchive && (form = someMainform) == null) {
form = someMainform = tempMainform = new Mainform(false);
}
Expand Down Expand Up @@ -3175,6 +3228,9 @@ else if (diagram.root.hasChanged())
}
// START KGU#650 2019-02-11: Issue #677
if (tempMainform != null) {
// START KGU#745 2019-10-14: Bugfix #759 - we must also remove it from the listeners (had added itself)
removeChangeListener(tempMainform);
// END KGU#745 2019-10-14
tempMainform.dispose();
}
// END KGU#650 2019-02-11
Expand Down Expand Up @@ -3870,7 +3926,7 @@ public void update(Root source)
for (String groupName: diagr.getGroupNames()) {
Group group = this.groups.get(groupName);
File arrzFile = null;
if (group != null && !group.membersChanged && (arrzFile = group.getArrzFile()) != null) {
if (group != null && !group.membersChanged && (arrzFile = group.getArrzFile(false)) != null) {
if (!source.getPath(true).equals(arrzFile.getAbsolutePath())) {
group.membersChanged = true;
}
Expand Down Expand Up @@ -5229,7 +5285,7 @@ public boolean renameGroup(Group group, String newName, Component initiator) {
if (group.getFile() != null) {
String ext = ".arrz";
File arrFile = group.getFile();
File file = group.getArrzFile();
File file = group.getArrzFile(true);
if (file == null) {
ext = ".arr";
file = arrFile;
Expand Down
Loading

0 comments on commit dc70569

Please sign in to comment.