/** * Converts a "list" of strings each null terminated * into a {@link List} of {@link String} values. The end of the * list is signaled by an extra NULL value at the end or by the * end of the buffer. * @param buf The buffer containing the strings * @return A {@link List} of all the strings in the buffer * @see #toStringList(char[], int, int) */ public static List<String> toStringList(char[] buf) { return toStringList(buf, 0, buf.length); }
/** * Converts a "list" of strings each null terminated * into a {@link List} of {@link String} values. The end of the * list is signaled by an extra NULL value at the end or by the * end of the buffer. * @param buf The buffer containing the strings * @return A {@link List} of all the strings in the buffer * @see #toStringList(char[], int, int) */ public static List<String> toStringList(char[] buf) { return toStringList(buf, 0, buf.length); }
/** * Invokes the {@link Kernel32#QueryDosDevice(String, char[], int)} method * and parses the result * @param lpszDeviceName The device name * @param maxTargetSize The work buffer size to use for the query * @return The parsed result */ public static final List<String> queryDosDevice(String lpszDeviceName, int maxTargetSize) { char[] lpTargetPath = new char[maxTargetSize]; int dwSize = Kernel32.INSTANCE.QueryDosDevice(lpszDeviceName, lpTargetPath, lpTargetPath.length); if (dwSize == 0) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } return Native.toStringList(lpTargetPath, 0, dwSize); }
/** * Returns valid drives in the system. * * @return A {@link List} of valid drives. */ public static List<String> getLogicalDriveStrings() { DWORD dwSize = Kernel32.INSTANCE.GetLogicalDriveStrings(new DWORD(0), null); if (dwSize.intValue() <= 0) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } char buf[] = new char[dwSize.intValue()]; dwSize = Kernel32.INSTANCE.GetLogicalDriveStrings(dwSize, buf); int bufSize = dwSize.intValue(); if (bufSize <= 0) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } return Native.toStringList(buf, 0, bufSize); }
/** * Invokes and parses the result of {@link Kernel32#GetVolumePathNamesForVolumeName(String, char[], int, IntByReference)} * @param lpszVolumeName The volume name * @return The parsed result * @throws Win32Exception If failed to retrieve the required information */ public static final List<String> getVolumePathNamesForVolumeName(String lpszVolumeName) { char[] lpszVolumePathNames = new char[WinDef.MAX_PATH + 1]; IntByReference lpcchReturnLength = new IntByReference(); if (!Kernel32.INSTANCE.GetVolumePathNamesForVolumeName(lpszVolumeName, lpszVolumePathNames, lpszVolumePathNames.length, lpcchReturnLength)) { int hr = Kernel32.INSTANCE.GetLastError(); if (hr != WinError.ERROR_MORE_DATA) { throw new Win32Exception(hr); } int required = lpcchReturnLength.getValue(); lpszVolumePathNames = new char[required]; // this time we MUST succeed if (!Kernel32.INSTANCE.GetVolumePathNamesForVolumeName(lpszVolumeName, lpszVolumePathNames, lpszVolumePathNames.length, lpcchReturnLength)) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } } int bufSize = lpcchReturnLength.getValue(); return Native.toStringList(lpszVolumePathNames, 0, bufSize); }