use of com.sun.jna.WString in project UniversalMediaServer by UniversalMediaServer.
the class WinUtils method getShortPathNameW.
/* (non-Javadoc)
* @see net.pms.io.SystemUtils#getShortPathNameW(java.lang.String)
*/
@Override
public String getShortPathNameW(String longPathName) {
boolean unicodeChars;
try {
byte[] b1 = longPathName.getBytes("UTF-8");
byte[] b2 = longPathName.getBytes("cp1252");
unicodeChars = b1.length != b2.length;
} catch (Exception e) {
return longPathName;
}
if (unicodeChars) {
try {
WString pathname = new WString(longPathName);
char[] test = new char[2 + pathname.length() * 2];
int r = Kernel32.INSTANCE.GetShortPathNameW(pathname, test, test.length);
if (r > 0) {
LOGGER.trace("Forcing short path name on " + pathname);
return Native.toString(test);
}
LOGGER.debug("Can't find \"{}\"", pathname);
return null;
} catch (Exception e) {
return longPathName;
}
}
return longPathName;
}
use of com.sun.jna.WString in project symmetric-ds by JumpMind.
the class WindowsService method relaunchAsPrivileged.
@Override
public void relaunchAsPrivileged(String cmd, String args) {
Shell32Ex.SHELLEXECUTEINFO execInfo = new Shell32Ex.SHELLEXECUTEINFO();
execInfo.lpFile = new WString(cmd);
if (args != null) {
execInfo.lpParameters = new WString(args);
}
execInfo.nShow = Shell32Ex.SW_SHOWDEFAULT;
execInfo.fMask = Shell32Ex.SEE_MASK_NOCLOSEPROCESS;
execInfo.lpVerb = new WString("runas");
if (!Shell32Ex.INSTANCE.ShellExecuteEx(execInfo)) {
throwException("ShellExecuteEx");
}
System.exit(0);
}
Aggregations