Search in sources :

Example 11 with WString

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;
}
Also used : WString(com.sun.jna.WString) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 12 with WString

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);
}
Also used : WString(com.sun.jna.WString) Shell32Ex(org.jumpmind.symmetric.wrapper.jna.Shell32Ex)

Aggregations

WString (com.sun.jna.WString)12 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)7 REFIID (com.sun.jna.platform.win32.Guid.REFIID)4 PointerByReference (com.sun.jna.ptr.PointerByReference)4 DISPIDByReference (com.sun.jna.platform.win32.OaIdl.DISPIDByReference)3 CLSID (com.sun.jna.platform.win32.Guid.CLSID)2 LCID (com.sun.jna.platform.win32.WinDef.LCID)2 StringArray (com.sun.jna.StringArray)1 COMException (com.sun.jna.platform.win32.COM.COMException)1 USHORTByReference (com.sun.jna.platform.win32.WinDef.USHORTByReference)1 IntByReference (com.sun.jna.ptr.IntByReference)1 LongByReference (com.sun.jna.ptr.LongByReference)1 SplashScreen (java.awt.SplashScreen)1 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 JFrame (javax.swing.JFrame)1 Shell32Ex (org.jumpmind.symmetric.wrapper.jna.Shell32Ex)1 Before (org.junit.Before)1