--- old/src/java.desktop/windows/native/libawt/windows/awt_Desktop.cpp 2015-11-23 09:32:55.786226605 +0300 +++ new/src/java.desktop/windows/native/libawt/windows/awt_Desktop.cpp 2015-11-23 09:32:55.682226554 +0300 @@ -28,6 +28,16 @@ #include #include #include +#include +#include "awt_Toolkit.h" + +#define BUFFER_LIMIT MAX_PATH+1 + +#define NOTIFY_FOR_ALL_SESSIONS 1 +#define NOTIFY_FOR_THIS_SESSION 0 + +typedef BOOL (WINAPI *WTSRegisterSessionNotification)(HWND,DWORD); +static WTSRegisterSessionNotification fn_WTSRegisterSessionNotification; #ifdef __cplusplus extern "C" { @@ -35,6 +45,29 @@ /* * Class: sun_awt_windows_WDesktopPeer + * Method: init + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_sun_awt_windows_WDesktopPeer_init + (JNIEnv *, jclass) { + static HMODULE libWtsapi32 = NULL; + if (libWtsapi32 == NULL) { + libWtsapi32 = JDK_LoadSystemLibrary("Wtsapi32.dll"); + if (libWtsapi32) { + fn_WTSRegisterSessionNotification = (WTSRegisterSessionNotification) + GetProcAddress(libWtsapi32, "WTSRegisterSessionNotification"); + if (fn_WTSRegisterSessionNotification) { + HWND hwnd = AwtToolkit::GetInstance().GetHWnd(); + //used for UserSessionListener + fn_WTSRegisterSessionNotification(hwnd, NOTIFY_FOR_THIS_SESSION); + } + } + } + ::CoInitialize(NULL); +} + +/* + * Class: sun_awt_windows_WDesktopPeer * Method: ShellExecute * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; */ @@ -82,6 +115,42 @@ return NULL; } +/* + * Class: sun_awt_windows_WDesktopPeer + * Method: moveToTrash + * Signature: (Ljava/lang/String;)Z + */ +JNIEXPORT jboolean JNICALL Java_sun_awt_windows_WDesktopPeer_moveToTrash + (JNIEnv *env, jclass, jstring jpath) +{ + LPCTSTR pathStr = JNU_GetStringPlatformChars(env, jpath, (jboolean *)NULL); + if (pathStr) { + try { + LPTSTR fileBuffer = new TCHAR[BUFFER_LIMIT]; + memset(fileBuffer, 0, BUFFER_LIMIT * sizeof(TCHAR)); + // the fileBuffer is double null terminated string + _tcsncpy(fileBuffer, pathStr, BUFFER_LIMIT - 2); + + SHFILEOPSTRUCT fop; + memset(&fop, 0, sizeof(SHFILEOPSTRUCT)); + fop.hwnd = NULL; + fop.wFunc = FO_DELETE; + fop.pFrom = fileBuffer; + fop.fFlags = FOF_ALLOWUNDO; + + int res = SHFileOperation(&fop); + + delete[] fileBuffer; + JNU_ReleaseStringPlatformChars(env, jpath, pathStr); + + return !res ? JNI_TRUE : JNI_FALSE; + } catch (std::bad_alloc&) { + JNU_ReleaseStringPlatformChars(env, jpath, pathStr); + } + } + return JNI_FALSE; +} + #ifdef __cplusplus } #endif