--- old/src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolder2.java 2015-05-07 10:18:41.321514500 +0300 +++ new/src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolder2.java 2015-05-07 10:18:40.845514500 +0300 @@ -163,6 +163,27 @@ } } + // Known Folder data + static class KnownfolderDefenition { + String guid; + int category; + String name; + String description; + String parent; + String relativePath; + String parsingName; + String tooltip; + String localizedName; + String icon; + String security; + long attributes; + int defenitionFlags; + String ftidType; + String path; + String saveLocation; + static final List libraries = getLibraries(); + } + static class FolderDisposer implements sun.java2d.DisposerRecord { /* * This is cached as a concession to getFolderType(), which needs @@ -578,7 +599,22 @@ return s; } } - return getDisplayNameOf(parentIShellFolder, relativePIDL, SHGDN_FORPARSING); + String path = getDisplayNameOf(parentIShellFolder, relativePIDL, + SHGDN_FORPARSING); + // if this is a library its default save location is taken as a path + // this is a temp fix until java.io starts support Libraries + if( path != null && path.startsWith("::{") && + path.toLowerCase().endsWith(".library-ms")) { + for (KnownfolderDefenition kf : KnownfolderDefenition.libraries) { + if( path.toLowerCase().endsWith( + kf.relativePath.toLowerCase()) && + path.toUpperCase().startsWith( + kf.parsingName.substring(0, 40).toUpperCase()) ) { + return kf.saveLocation; + } + } + } + return path; } // Needs to be accessible to Win32ShellFolderManager2 @@ -848,6 +884,9 @@ long relativePIDL, int attrs); + // Returns data of all Known Folders registered in the system + private static native KnownfolderDefenition[] loadKnownFolders(); + /** * @return The name used to display this shell folder */ @@ -1178,4 +1217,26 @@ return result == null ? 0 : result; } } + + // Extracts libraries and their default save locations from Known Folders list + private static List getLibraries() { + return invoke(new Callable>() { + @Override + public List call() throws Exception { + KnownfolderDefenition[] all = loadKnownFolders(); + List folders = new ArrayList<>(); + if (all != null) { + for (KnownfolderDefenition kf : all) { + if (kf.relativePath == null || kf.parsingName == null || + kf.saveLocation == null) { + continue; + } + folders.add(kf); + } + } + return folders; + } + }); + } + }