Ignore:
Timestamp:
03/17/19 22:29:23 (5 years ago)
Author:
davidb
Message:

After change to have resources-public and resources-private, some changes needed to support running Expeditee for a single user; other main change is to allow FrameDirs to specify relative directory paths, to help with when Expeditee is run on the cloud -- similar work still needs to occurr for ImageDir and AudioDir; some other minor changes also made.

Location:
trunk/src/org/expeditee/gui
Files:
4 edited

Legend:

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

    r1242 r1244  
    2222import java.io.IOException;
    2323import java.net.Authenticator;
     24import java.nio.file.Path;
    2425import java.security.KeyStoreException;
    2526import java.security.NoSuchAlgorithmException;
     
    148149        public static boolean _hasExited = false;
    149150
     151        public static String USER_NOBODY = "nobody";
     152       
    150153        /** A flag which is set once the application is exiting. */
    151154        protected boolean _isExiting = false;
     
    154157       
    155158        private static String _startFrame = null;
     159
    156160
    157161        /**
     
    162166        public static void main(String[] args)
    163167        {
     168                if (Boolean.getBoolean("auth")) {
     169                        String starting_user_name = System.getProperty("user.name");
     170                        System.setProperty("startinguser.name", starting_user_name);
     171                        System.setProperty("user.name", USER_NOBODY);
     172                }
     173               
    164174                // Parse the starting frame command-line argument
    165175                if(args.length > 0) {
     
    261271                Frame userProfile = loadProfiles();
    262272
     273                if (!Boolean.getBoolean("auth")) {
     274                        String userName = UserSettings.ProfileName.get();
     275                        FrameIO.setupPersonalResources(userName);
     276                }
    263277                // Listen for save status to display during and after runtime
    264278                EntitySaveManager.getInstance().addSaveStateChangedEventListener(this);
  • trunk/src/org/expeditee/gui/DisplayController.java

    r1216 r1244  
    6868                RIGHT
    6969        }
    70 
     70       
     71        // To help title calculations on frame
     72        public static final int MINIMUM_FRAME_WIDTH = 512;
     73       
    7174        /** Convenience definition of TwinFramesSide.LEFT. */
    7275        public static final TwinFramesSide LEFT = TwinFramesSide.LEFT;
  • trunk/src/org/expeditee/gui/FrameIO.java

    r1242 r1244  
    3333import java.io.Writer;
    3434import java.nio.channels.FileChannel;
     35import java.nio.file.Files;
     36import java.nio.file.Path;
    3537import java.nio.file.Paths;
    3638import java.sql.Time;
     
    4345import java.util.stream.Collectors;
    4446
     47import org.apollo.gui.IChangeParentAndSubFolders;
     48import org.apollo.io.AudioPathManager;
    4549import org.expeditee.actions.Actions;
    4650import org.expeditee.agents.ExistingFramesetException;
     
    8185 *
    8286 */
     87
     88
    8389public class FrameIO {
    8490
    8591        private static final char FRAME_NAME_LAST_CHAR = 'A';
    86 
    87         public static void changeParentFolder(String newFolder) {
    88                 // Partial Paths.
    89                 PARENT_FOLDER = newFolder;
    90                 String resourcesPublicPath = PARENT_FOLDER + "resources-public" + File.separator;
    91                 String resourcesPrivateIndividualPath = PARENT_FOLDER + "resources-" + UserSettings.UserName.get() + File.separator;
    92                
    93                 // Standard paths.
    94                 PUBLIC_PATH = PARENT_FOLDER + "public" + File.separator;
    95                 MESSAGES_PATH = PARENT_FOLDER + "messages" + File.separator;
    96                 TRASH_PATH = PARENT_FOLDER + "trash" + File.separator;
    97                 HELP_PATH = PARENT_FOLDER + "documentation" + File.separator;
    98                 PROFILE_PATH = PARENT_FOLDER + "profiles" + File.separator;
    99                 EXPORTS_DIR = PARENT_FOLDER + "exports" + File.separator;
    100                 STATISTICS_DIR = PARENT_FOLDER + "statistics" + File.separator;
    101                 LOGS_DIR = PARENT_FOLDER + "logs" + File.separator;
    102                                
    103                 // New regime paths.
    104                 if (UserSettings.multiUserMode) {
    105                         SHARED_FRAMESETS_PATH = resourcesPrivateIndividualPath + "framesets-shared" + File.separator;
    106                         RESOURCES_PRIVATE = PARENT_FOLDER + "resources-private" + File.separator;
    107                         RESOURCES_PATH = resourcesPublicPath + "documentation" + File.separator;
    108                         FRAME_PRIVATE_PATH = resourcesPrivateIndividualPath + "framesets" + File.separator;
    109                         IMAGES_PRIVATE_PATH = resourcesPrivateIndividualPath + "images" + File.separator;
    110                         CONTACTS_PATH = resourcesPrivateIndividualPath + "contacts" + File.separator;
    111                 } else {
    112                         // If we are using the old regime then these paths should not be used.
    113                         SHARED_FRAMESETS_PATH = null;
    114                         RESOURCES_PRIVATE = null;               
    115                         RESOURCES_PATH = null;
    116                         FRAME_PRIVATE_PATH = null;
    117                         IMAGES_PRIVATE_PATH = null;
    118                         CONTACTS_PATH = null;
    119                 }
    120                
    121                 // Conditional paths
    122                 if (UserSettings.multiUserMode) {
    123                         FONT_PATH = resourcesPublicPath + "fonts" + File.separator;
    124                         DICT_PATH = resourcesPublicPath + "dict" + File.separator;
    125                         IMAGES_PATH = resourcesPublicPath + "images" + File.separator;
    126                         FRAME_PATH = resourcesPublicPath + "framesets" + File.separator;
    127                 } else {
    128                         FONT_PATH = PARENT_FOLDER + "fonts" + File.separator;
    129                         DICT_PATH = PARENT_FOLDER + "dict" + File.separator;
    130                         IMAGES_PATH = PARENT_FOLDER + "images" + File.separator;
    131                         FRAME_PATH = PARENT_FOLDER + "framesets" + File.separator;
    132                 }
    133         }
    13492
    13593        // The parent path that all others are relative to.  Also referred to as Expeditee Home.
     
    142100        public static String MESSAGES_PATH;
    143101        public static String IMAGES_PATH;
     102        public static String AUDIO_PATH;
    144103        public static String PUBLIC_PATH;
    145104        public static String TRASH_PATH;
     
    159118        public static String FRAME_PRIVATE_PATH;
    160119        public static String IMAGES_PRIVATE_PATH;
     120        public static String AUDIO_PRIVATE_PATH;
    161121       
    162122        // Paths used only by old regime.
     
    175135       
    176136        private static final String INF_FILENAME = "frame.inf";
     137       
     138        public static void changeParentAndSubFolders(String newFolder) {
     139                // Partial Paths.
     140                PARENT_FOLDER = newFolder;
     141                       
     142                String resourcesPublicPath = PARENT_FOLDER + "resources-public" + File.separator;
     143
     144                // Standard paths.
     145                PUBLIC_PATH = PARENT_FOLDER + "public" + File.separator;
     146                MESSAGES_PATH = PARENT_FOLDER + "messages" + File.separator;
     147                TRASH_PATH = PARENT_FOLDER + "trash" + File.separator;
     148                HELP_PATH = PARENT_FOLDER + "documentation" + File.separator;
     149                PROFILE_PATH = PARENT_FOLDER + "profiles" + File.separator;
     150                EXPORTS_DIR = PARENT_FOLDER + "exports" + File.separator;
     151                STATISTICS_DIR = PARENT_FOLDER + "statistics" + File.separator;
     152                LOGS_DIR = PARENT_FOLDER + "logs" + File.separator;
     153                               
     154               
     155                // Conditional paths
     156                if (UserSettings.PublicAndPrivateResources) {
     157                        // Work with a system of public and private folders
     158                       
     159                        FONT_PATH = resourcesPublicPath + "fonts" + File.separator;
     160                        DICT_PATH = resourcesPublicPath + "dict" + File.separator;
     161                        IMAGES_PATH = resourcesPublicPath + "images" + File.separator;
     162                        AUDIO_PATH = resourcesPublicPath + "audio" + File.separator;
     163                        FRAME_PATH = resourcesPublicPath + "framesets" + File.separator;
     164                }
     165                else {
     166                        FONT_PATH = PARENT_FOLDER + "fonts" + File.separator;
     167                        DICT_PATH = PARENT_FOLDER + "dict" + File.separator;
     168                        IMAGES_PATH = PARENT_FOLDER + "images" + File.separator;
     169                        AUDIO_PATH = PARENT_FOLDER + "audio" + File.separator;
     170                        FRAME_PATH = PARENT_FOLDER + "framesets" + File.separator;
     171                }
     172               
     173                if (!UserSettings.PublicAndPrivateResources || System.getProperty("user.name").equals(Browser.USER_NOBODY)) {
     174                       
     175                        if (System.getProperty("user.name").equals(Browser.USER_NOBODY)) {
     176                                System.err.println("**** FrameIO::changeParentAndSubFolders(): Not setting subfolders for user '"+Browser.USER_NOBODY+"'");
     177                        }
     178                       
     179                        // If we are using the old regime, or user.name set to Browser.USER_NOBODY
     180                        // => then these paths should not be used.
     181                        RESOURCES_PATH = null;
     182                        SHARED_FRAMESETS_PATH = null;
     183                        RESOURCES_PRIVATE = null;               
     184                        FRAME_PRIVATE_PATH = null;
     185                        IMAGES_PRIVATE_PATH = null;
     186                        AUDIO_PRIVATE_PATH = null;
     187                        CONTACTS_PATH = null;
     188                }
     189                else {
     190                        String resourcesPrivateIndividualPath = PARENT_FOLDER + "resources-" + UserSettings.UserName.get() + File.separator;
     191                       
     192                        RESOURCES_PATH = resourcesPublicPath + "documentation" + File.separator;
     193                        SHARED_FRAMESETS_PATH = resourcesPrivateIndividualPath + "framesets-shared" + File.separator;
     194                       
     195                        RESOURCES_PRIVATE = PARENT_FOLDER + "resources-private" + File.separator;
     196                        FRAME_PRIVATE_PATH = resourcesPrivateIndividualPath + "framesets" + File.separator;
     197                        IMAGES_PRIVATE_PATH = resourcesPrivateIndividualPath + "images" + File.separator;
     198                        AUDIO_PRIVATE_PATH = resourcesPrivateIndividualPath + "audio" + File.separator;
     199                        CONTACTS_PATH = resourcesPrivateIndividualPath + "contacts" + File.separator;
     200                }
     201                       
     202               
     203                System.err.println("**** FrameIO::changeParentAndSubFolder(): Calling AudioPathManger.changeParentAndSubFolder()");
     204                AudioPathManager.changeParentAndSubFolders(newFolder);
     205        }
    177206       
    178207        // All methods are static, this should not be instantiated
     
    341370                        loaded = LoadKnownPath(knownPath, framename);
    342371                } else {
    343                         List<String> directoriesToSearch = FolderSettings.FrameDirs.get();
     372                        List<String> directoriesToSearch = FolderSettings.FrameDirs.getAbsoluteDirs();
    344373                       
    345374                        if (Authenticator.Authenticated) {
     
    378407                StringBuffer list = new StringBuffer();
    379408
    380                 for (String path : FolderSettings.FrameDirs.get()) {
     409                for (String path : FolderSettings.FrameDirs.getAbsoluteDirs()) {
    381410                        File files = new File(path);
    382411                        if (!files.exists()) {
     
    466495                }
    467496
    468                 for (String path : FolderSettings.FrameDirs.get()) {
     497                for (String path : FolderSettings.FrameDirs.getAbsoluteDirs()) {
    469498                        if (getFrameFullPathName(path, frameName) != null) {
    470499                                return true;
     
    478507                String fullPath = null;
    479508                if (path == null) {
    480                         for (String possiblePath : FolderSettings.FrameDirs.get()) {
     509                        for (String possiblePath : FolderSettings.FrameDirs.getAbsoluteDirs()) {
    481510                                fullPath = getFrameFullPathName(possiblePath, frameName);
    482511                                if (fullPath != null) {
     
    879908                if (!DisplayController.isTwinFramesOn() && !Justification.center.equals(((Text)titleItem).getJustification())) {
    880909                        if ((titleItem.getX() + 1) < template.getNameItem().getX()) {
    881                                 while (titleItem.getSize() > Text.MINIMUM_FONT_SIZE
    882                                                 && titleItem.getBoundsWidth() + titleItem.getX() > template
    883                                                                 .getNameItem().getX()) {
     910                                int title_item_xr = titleItem.getX() + titleItem.getBoundsWidth(); // should really be '... -1'
     911                                int frame_name_xl = template.getNameItem().getX();
     912                                if (frame_name_xl < DisplayController.MINIMUM_FRAME_WIDTH) {
     913                                        frame_name_xl = DisplayController.MINIMUM_FRAME_WIDTH;
     914                                }
     915                               
     916                                while ((titleItem.getSize() > Text.MINIMUM_FONT_SIZE) && title_item_xr > frame_name_xl) {
    884917                                        titleItem.setSize(titleItem.getSize() - 1);
     918                                        System.err.println("**** shrunk titleItem: " + titleItem + " to font size: " + titleItem.getSize());
    885919                                }
    886920                        } else {
     
    15441578        public static Boolean canAccessFrameset(String framesetName) {
    15451579                framesetName = framesetName.toLowerCase();
    1546                 for (String path : FolderSettings.FrameDirs.get()) {
     1580                for (String path : FolderSettings.FrameDirs.getAbsoluteDirs()) {
    15471581                        if ((new File(path + framesetName)).exists()) {
    15481582                                return true;
     
    16851719
    16861720                // Search all the available directories for the directory
    1687                 for (String path : FolderSettings.FrameDirs.get()) {
     1721                for (String path : FolderSettings.FrameDirs.getAbsoluteDirs()) {
    16881722                        String source = path + framesetName.toLowerCase() + File.separator;
    16891723                        File framesetDirectory = new File(source);
     
    17301764                // search through all the directories to find the frameset we are
    17311765                // copying
    1732                 for (String path : FolderSettings.FrameDirs.get()) {
     1766                for (String path : FolderSettings.FrameDirs.getAbsoluteDirs()) {
    17331767                        String source = path + framesetToCopy.toLowerCase()
    17341768                                        + File.separator;
     
    18901924                toSave.setActiveTime(activeTime);
    18911925        }
     1926       
     1927        public static Path setupPersonalResources(String username)
     1928        {
     1929                Path personalResources = Paths.get(FrameIO.PARENT_FOLDER).resolve("resources-" + username);
     1930                personalResources.toFile().mkdir();             
     1931                File[] globalResourcesToCopy = Paths.get(FrameIO.RESOURCES_PRIVATE).toFile().listFiles();
     1932               
     1933                try {
     1934                        for (File toCopy: globalResourcesToCopy) {
     1935                                Path p = Paths.get(toCopy.getAbsolutePath());
     1936                                if (!p.getFileName().toString().equals(".res") && !p.getFileName().toString().equals("about")) {
     1937                                        copyFileTree(p.toAbsolutePath(), personalResources.resolve(p.getFileName()));
     1938                                }
     1939                        }
     1940                }
     1941                catch (IOException e) {
     1942                        e.printStackTrace();
     1943                        personalResources = null;
     1944                }
     1945               
     1946                return personalResources;
     1947        }
     1948       
     1949        private static void copyFileTree(Path source, Path target) throws IOException {
     1950                Files.copy(source, target);
     1951                if (source.toFile().isDirectory()) {
     1952                        File[] files = source.toFile().listFiles();
     1953                        for (File file: files) {
     1954                                Path asPath = Paths.get(file.getAbsolutePath());
     1955                                copyFileTree(asPath, target.resolve(asPath.getFileName()));
     1956                        }
     1957                }
     1958        }
    18921959}
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r1242 r1244  
    10901090                                Logger.Log(e);
    10911091                                e.printStackTrace();
    1092                                 MessageBay.warningMessage("Exception occured when loading " + i.getClass().getSimpleName() + "(ID: "
    1093                                                 + i.getID() + ") " + e.getMessage() != null ? e.getMessage() : "");
     1092                                System.err.println("**** Have temporarily supressed MessageBay call, as resulted in infinite recursion");
     1093                                //MessageBay.warningMessage("Exception occured when loading " + i.getClass().getSimpleName() + "(ID: "
     1094                                //              + i.getID() + ") " + e.getMessage() != null ? e.getMessage() : "");
    10941095                        }
    10951096                }
     
    18201821         */
    18211822        public static void extractResources(boolean force) {
    1822                 // Extract private resources
    1823                 Path resourcesPrivate = Paths.get(FrameIO.PARENT_FOLDER).resolve("resources-private");
    1824                 extractResources("org/expeditee/assets/resources-private", resourcesPrivate, force);
    18251823               
    1826                 // Extract public resources
    1827                 Path resourcesPublic = Paths.get(FrameIO.PARENT_FOLDER).resolve("resources-public");
    1828                 extractResources("org/expeditee/assets/resources-public", resourcesPublic, force);
     1824                if (UserSettings.PublicAndPrivateResources) {
     1825                        // Extract private resources
     1826                        Path resourcesPrivate = Paths.get(FrameIO.PARENT_FOLDER).resolve("resources-private");
     1827                        extractResources("org/expeditee/assets/resources-private", resourcesPrivate, force);
     1828                       
     1829                        // Extract public resources
     1830                        Path resourcesPublic = Paths.get(FrameIO.PARENT_FOLDER).resolve("resources-public");
     1831                        extractResources("org/expeditee/assets/resources-public", resourcesPublic, force);
     1832                }
    18291833        }
    18301834       
Note: See TracChangeset for help on using the changeset viewer.