Ignore:
Timestamp:
04/04/19 14:41:47 (5 years ago)
Author:
bln4
Message:

Renamed MailMode action to ToggleBay
Renamed FrameCreator enums to more desirable names (David request)
Created test for altered functionality of FrameCreator as documented below.

FrameCreator now more cleanly obeys the specification of the enum parameter to its constructor. For example, override existing frameset ensures that the old frameset has been deleted (moved to trash).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/gui/FrameIO.java

    r1277 r1280  
    15791579         * @return
    15801580         */
    1581         public static Boolean canAccessFrameset(String framesetName) {
     1581        public static boolean canAccessFrameset(String framesetName) {
    15821582                framesetName = framesetName.toLowerCase();
    15831583                for (String path : FolderSettings.FrameDirs.getAbsoluteDirs()) {
    1584                         if ((new File(path + framesetName)).exists()) {
     1584                        if (canAccessFrameset(framesetName, Paths.get(path))) {
    15851585                                return true;
    15861586                        }
    15871587                }
    15881588                return false;
     1589        }
     1590       
     1591        public static boolean canAccessFrameset(String framesetName, Path path) {
     1592                File framesetDir = path.resolve(framesetName).toFile();
     1593                if (framesetDir.exists() && framesetDir.isDirectory()) {
     1594                        return true;
     1595                } else {
     1596                        return false;
     1597                }
    15891598        }
    15901599
     
    17231732                // Search all the available directories for the directory
    17241733                for (String path : FolderSettings.FrameDirs.getAbsoluteDirs()) {
    1725                         String source = path + framesetName.toLowerCase() + File.separator;
    1726                         File framesetDirectory = new File(source);
    1727                         // Once we have found the directory move it
    1728                         if (framesetDirectory.exists()) {
    1729                                 String destPath = destinationFolder
    1730                                                 + framesetName.toLowerCase();
    1731                                 int copyNumber = 1;
    1732                                 File dest = new File(destPath + File.separator);
    1733                                 // Create the destination folder if it doesnt already exist
    1734                                 if (!dest.getParentFile().exists()) {
    1735                                         dest.mkdirs();
     1734                        return moveFrameset(framesetName, path, destinationFolder);
     1735                }
     1736                return false;
     1737        }
     1738
     1739        public static boolean moveFrameset(String framesetName, String path, String destinationFolder) {
     1740                String source = path + framesetName.toLowerCase() + File.separator;
     1741                File framesetDirectory = new File(source);
     1742                // Once we have found the directory move it
     1743                if (framesetDirectory.exists()) {
     1744                        String destPath = destinationFolder
     1745                                        + framesetName.toLowerCase();
     1746                        int copyNumber = 1;
     1747                        File dest = new File(destPath + File.separator);
     1748                        // Create the destination folder if it doesnt already exist
     1749                        if (!dest.getParentFile().exists()) {
     1750                                dest.mkdirs();
     1751                        }
     1752                        // If a frameset with the same name is already in the
     1753                        // destination add
     1754                        // a number to the end
     1755                        while (dest.exists()) {
     1756                                dest = new File(destPath + ++copyNumber + File.separator);
     1757                        }
     1758                        try {
     1759                                copyFileTree(framesetDirectory.toPath(), dest.toPath());       
     1760                        } catch (IOException e) {
     1761                                e.printStackTrace();
     1762                                return false;
     1763                        }
     1764                       
     1765                        for (File f : framesetDirectory.listFiles()) {
     1766                                if (!f.delete()) {
     1767                                        return false;
    17361768                                }
    1737                                 // If a frameset with the same name is already in the
    1738                                 // destination add
    1739                                 // a number to the end
    1740                                 while (dest.exists()) {
    1741                                         dest = new File(destPath + ++copyNumber + File.separator);
    1742                                 }
    1743                                 if (!framesetDirectory.renameTo(dest)) {
    1744                                         for (File f : framesetDirectory.listFiles()) {
    1745                                                 if (!f.delete()) {
    1746                                                         return false;
    1747                                                 }
    1748                                         }
    1749                                         if (!framesetDirectory.delete()) {
    1750                                                 return false;
    1751                                         }
    1752                                 }
    1753                                 return true;
    1754                         }
    1755                 }
    1756                 return false;
     1769                        }
     1770                        if (!framesetDirectory.delete()) {
     1771                                return false;
     1772                        }
     1773                        return true;
     1774                } else {
     1775                        return false;
     1776                }
    17571777        }
    17581778
Note: See TracChangeset for help on using the changeset viewer.