Changeset 1331 for trunk


Ignore:
Timestamp:
04/29/19 10:48:40 (5 years ago)
Author:
bln4
Message:

Added support for running with the old regime but with authentication. There is a slight limitation in that the new default profile frameset must be copied over upon resources extraction. This means that any existing changes to the default frameset are whipped when this occurs. However, this only occurs if resources are being extracted, so should only ever happen once. This means the user is able to restore their changes to the default after this has happened.

Location:
trunk/src/org/expeditee
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/auth/Actions.java

    r1323 r1331  
    529529               
    530530                // Copy private resources to personal area
    531                 Path personalResources = FrameIO.setupPersonalResources(username);
     531                Path personalResources = UserSettings.PublicAndPrivateResources ? FrameIO.setupPersonalResources(username) : Paths.get(FrameIO.PARENT_FOLDER);
    532532               
    533533                File contactsDir = new File(personalResources.resolve("contacts").toAbsolutePath().toString());
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r1270 r1331  
    2929import java.net.URL;
    3030import java.net.URLConnection;
     31import java.nio.file.FileVisitResult;
     32import java.nio.file.FileVisitor;
     33import java.nio.file.Files;
    3134import java.nio.file.Path;
    3235import java.nio.file.Paths;
     36import java.nio.file.attribute.BasicFileAttributes;
    3337import java.util.ArrayList;
    3438import java.util.Arrays;
     
    4953import org.expeditee.agents.ExistingFramesetException;
    5054import org.expeditee.agents.InvalidFramesetNameException;
     55import org.expeditee.auth.AuthenticatorBrowser;
    5156import org.expeditee.auth.gui.MailBay;
    5257import org.expeditee.core.Colour;
     
    18351840                        Path resourcesPublic = Paths.get(FrameIO.PARENT_FOLDER).resolve("resources-public");
    18361841                        extractResources("org/expeditee/assets/resources-public", resourcesPublic, force);
     1842                } else if (AuthenticatorBrowser.isAuthenticationRequired()) {
     1843                        // Deal with the instance of being in the old regime but using authentication.
     1844                       
     1845                        // Ensure additional framesets
     1846                        Path framesetsDir = Paths.get(FrameIO.FRAME_PATH);
     1847                        boolean extracted = extractResources("org/expeditee/assets/resources-public/framesets", framesetsDir, force);
     1848                       
     1849                        // Ensure additional images
     1850                        Path imagesDir = Paths.get(FrameIO.IMAGES_PATH);
     1851                        extracted |= extractResources("org/expeditee/assets/resources-public/images", imagesDir, force);
     1852                       
     1853                        // Ensure deaddrops area exists
     1854                        Paths.get(FrameIO.PARENT_FOLDER).resolve("deaddrops").toFile().mkdir();
     1855                       
     1856                        if (extracted) {
     1857                                // Ensure the default profile is 'update to date'. 
     1858                                //NB: this limits the potential for those running old regime with authentication the ability to customise the default profile.
     1859                                Path defaultProfile = Paths.get(FrameIO.PROFILE_PATH).resolve("default");
     1860                                try {
     1861                                        Files.walkFileTree(defaultProfile, new FileVisitor<Path>() {
     1862                                                @Override
     1863                                                public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
     1864                                                        dir.toFile().delete();
     1865                                                        return FileVisitResult.CONTINUE;
     1866                                                }
     1867                                                @Override
     1868                                                public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
     1869                                                        return FileVisitResult.CONTINUE;
     1870                                                }
     1871                                                @Override
     1872                                                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
     1873                                                        file.toFile().delete();
     1874                                                        return FileVisitResult.CONTINUE;
     1875                                                }
     1876                                                @Override
     1877                                                public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
     1878                                                        return FileVisitResult.CONTINUE;
     1879                                                }
     1880                                        });
     1881                                } catch (IOException e) {
     1882                                        e.printStackTrace();
     1883                                }
     1884                        }
    18371885                }
    18381886        }
    18391887       
    1840         private static void extractResources(String source, Path destination, boolean force) {
     1888        private static boolean extractResources(String source, Path destination, boolean force) {
    18411889                // If resources have already been extracted, and we are not forcing the extraction, there is nothing to do.
    18421890                if (!force && destination.resolve(".res").toFile().exists()) {
    1843                         return;
     1891                        return false;
    18441892                }
    18451893               
     
    18931941                        System.err.println("Error: FrameUtils::extractResources.  Unable to create the .res file to flag that resources have been extracted.  Message: " + e.getMessage());
    18941942                }
     1943               
     1944                return true;
    18951945        }
    18961946
Note: See TracChangeset for help on using the changeset viewer.