/************************************************************************* * Reads the current location of the app data folder from the registry. * * @return a path to the folder. ************************************************************************/ private String getAppFolder() { return Shell32Util.getFolderPath(ShlObj.CSIDL_APPDATA); }
/** * Get a special folder path. * @param nFolder * Folder CSLID. * @return * Special folder path. */ public static String getFolderPath(int nFolder) { return getFolderPath(null, nFolder, ShlObj.SHGFP_TYPE_CURRENT); }
/** * Get a special folder path. * @param nFolder * Folder CSLID. * @return * Special folder path. */ public static String getFolderPath(int nFolder) { return getFolderPath(null, nFolder, ShlObj.SHGFP_TYPE_CURRENT); }
/************************************************************************* * Reads the current location of the app data folder from the registry. * * @return a path to the folder. ************************************************************************/ private String getAppFolder() { return Shell32Util.getFolderPath(ShlObj.CSIDL_APPDATA); }
String getWindowsAppDataPath() { if (getOs().toLowerCase().contains("windows")) { return Shell32Util.getFolderPath(ShlObj.CSIDL_LOCAL_APPDATA); } return ""; }
private static Optional<File> getFolderPath(final int csidl, final String dirName) { try { final String folderPath = Shell32Util.getFolderPath(csidl); if (StringUtils.isEmpty(folderPath)) { return Optional.empty(); } final File file = new File(folderPath); if (file.isDirectory()) { return Optional.of(file); } log.warn(dirName + " is not a directory"); return Optional.empty(); } catch (final Win32Exception e) { log.warn("Could not find the " + dirName + " directory", e); return Optional.empty(); } } }
public String resolveFolder(FolderId folderId) { try { logger.debug("Invoking SHGetKnownFolderPath"); return Shell32Util.getKnownFolderPath(convertFolderIdToGuid(folderId)); } catch (Win32Exception e) { logger.error("SHGetKnownFolderPath returns an error: {}", e.getErrorCode()); throw new AppDirsException( "SHGetKnownFolderPath returns an error: " + e.getErrorCode()); } catch (UnsatisfiedLinkError e) { // Fallback for pre-vista OSes. #5 try { logger.debug("SHGetKnownFolderPath failed. Trying SHGetFolderPath."); int folder = convertFolderIdToCsidl(folderId); return Shell32Util.getFolderPath(folder); } catch (Win32Exception e2) { logger.error("SHGetFolderPath returns an error: {}", e2); throw new AppDirsException( "SHGetFolderPath returns an error: " + e2.getErrorCode()); } } }