Ignore:
Timestamp:
2019-12-07T01:40:13+13:00 (4 years ago)
Author:
ak19
Message:
  1. Windows bugfix for getting exMeta to be loaded into GLI where there are subdirs involved in the Gather pane, or there are non-ASCII filenames, or the file rename method is set to base64. 2. Bugfix for Linux and Windows: Using Base64 to rename files was still a problem despite the previous commit (which was supposed to have fixed all GLI exMeta loading issues on Linux) in the special case where a subfolder was pure ASCII. The perl code wouldn't base64 encode such subdirs. However, GLI won't know which part of a relative file path to decode based on the file rename method used and which parts are not to be decoded. So GLI uniformly decoded them, and ASCII named subfolders that were not base64 encoded (but contained files that were to be renamed with base64) got base64 decoded into garbage, so that exMeta still did not get attached. 3. This commit contains debug stmts.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/util/Utility.java

    r33729 r33757  
    114114     
    115115      return result;
     116    }
     117   
     118    /**
     119     * The following calls a method in WindowsNativeFunctions.java to retrieve Windows short file names
     120     * taken from http://dolf.trieschnigg.nl/eightpointthree/eightpointthree.html
     121     * which uses the the non-JNI NativeCall jar file for which WindowsNativeFunctions imports com.eaio.nativecall.*
     122     *
     123     * returns the short filename (8.3) for a file in Windows
     124     *
     125     * @param longFileName - must be the full path to an actual existing file
     126     * @return a string with the short filename, or null if an error occurred or the
     127     *         file does not exist.
     128     */
     129    public static String getWindowsShortFileName(String longFileName) throws Exception {
     130        if(!Utility.isWindows()) {
     131            return longFileName;
     132        } else {
     133            //return WindowsNativeFunctions.getEightPointThree(longFileName);
     134            return getMSDOSName(longFileName);
     135        }
     136    }
     137   
     138    /** 
     139     * getMSDOSName() and its helper function getAbsolutePath(fileName)
     140     * are from https://stackoverflow.com/questions/18893284/how-to-get-short-filenames-in-windows-using-java
     141     * getMSDOSName() modified to use our SafeProcess class.
     142     *
     143     * @param fileName - the regular fileName to be converted. Must be the full path to an actual existing file
     144     * @return Windows shortfile name for the fileName parameter given.
     145     */
     146    public static String getMSDOSName(String fileName)
     147        throws IOException, InterruptedException {
     148
     149        /*
     150        String path = getAbsolutePath(fileName);
     151       
     152        changed "+ fileName.toUpperCase() +" to "path"
     153        Process process =
     154            Runtime.getRuntime().exec(
     155                "cmd /c for %I in (\"" + path + "\") do @echo %~fsI");
     156       
     157        process.waitFor();
     158       
     159        byte[] data = new byte[65536];
     160        int size = process.getInputStream().read(data);
     161
     162        if (size <= 0) {
     163            return null;
     164        }
     165
     166        return new String(data, 0, size).replaceAll("\\r\\n", "");
     167        */
     168        String path = getAbsolutePath(fileName);
     169       
     170        SafeProcess process = new SafeProcess("cmd /c for %I in (\"" + path + "\") do @echo %~fsI");
     171        int returnVal = process.runProcess();
     172        if(returnVal != 0) {
     173            return null;
     174        }
     175
     176        String data = process.getStdOutput();
     177        if(data == null) {
     178            return null;           
     179        }
     180        else return data.replaceAll("\\r\\n", "");
     181    }
     182    public static String getAbsolutePath(String fileName)
     183        throws IOException {
     184        File file = new File(fileName);
     185        String path = file.getAbsolutePath();
     186
     187        if (file.exists() == false)
     188            file = new File(path);
     189
     190        path = file.getCanonicalPath();
     191
     192        if (file.isDirectory() && (path.endsWith(File.separator) == false))
     193            path += File.separator;
     194
     195        return path;
    116196    }
    117197   
Note: See TracChangeset for help on using the changeset viewer.