- Improvements to fetching file system information on Windows.
- Fixes for reset and clearing to end of line for Windows console.
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
#include "native.h"
|
#include "native.h"
|
||||||
#include "generic.h"
|
#include "generic.h"
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Marks the given result as failed, using the current value of GetLastError()
|
* Marks the given result as failed, using the current value of GetLastError()
|
||||||
@@ -55,36 +56,53 @@ Java_net_rubygrapefruit_platform_internal_jni_PosixProcessFunctions_getPid(JNIEn
|
|||||||
*/
|
*/
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_net_rubygrapefruit_platform_internal_jni_PosixFileSystemFunctions_listFileSystems(JNIEnv *env, jclass target, jobject info, jobject result) {
|
Java_net_rubygrapefruit_platform_internal_jni_PosixFileSystemFunctions_listFileSystems(JNIEnv *env, jclass target, jobject info, jobject result) {
|
||||||
// TODO - don't use the stack
|
wchar_t* volumeName = (wchar_t*)malloc(sizeof(wchar_t) * (MAX_PATH+1));
|
||||||
wchar_t volumeName[MAX_PATH+1];
|
|
||||||
wchar_t deviceName[MAX_PATH+1];
|
|
||||||
wchar_t pathNames[MAX_PATH+1];
|
|
||||||
wchar_t fsName[MAX_PATH+1];
|
|
||||||
|
|
||||||
jclass info_class = env->GetObjectClass(info);
|
jclass info_class = env->GetObjectClass(info);
|
||||||
jmethodID method = env->GetMethodID(info_class, "add", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)V");
|
jmethodID method = env->GetMethodID(info_class, "add", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)V");
|
||||||
|
|
||||||
HANDLE handle = FindFirstVolumeW(volumeName, MAX_PATH+1);
|
HANDLE handle = FindFirstVolumeW(volumeName, MAX_PATH+1);
|
||||||
if (handle == INVALID_HANDLE_VALUE) {
|
if (handle == INVALID_HANDLE_VALUE) {
|
||||||
printf("no volumes\r\n");
|
free(volumeName);
|
||||||
|
mark_failed_with_errno(env, "could not find first volume", result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wchar_t* deviceName = (wchar_t*)malloc(sizeof(wchar_t) * (MAX_PATH+1));
|
||||||
|
wchar_t* pathNames = (wchar_t*)malloc(sizeof(wchar_t) * (MAX_PATH+1));
|
||||||
|
wchar_t* fsName = (wchar_t*)malloc(sizeof(wchar_t) * (MAX_PATH+1));
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
// Chop off the trailing '\'
|
// Chop off the trailing '\'
|
||||||
size_t len = wcslen(volumeName);
|
size_t len = wcslen(volumeName);
|
||||||
|
if (len < 5) {
|
||||||
|
mark_failed_with_message(env, "volume name is too short", result);
|
||||||
|
break;
|
||||||
|
}
|
||||||
volumeName[len-1] = L'\0';
|
volumeName[len-1] = L'\0';
|
||||||
|
|
||||||
QueryDosDeviceW(&volumeName[4], deviceName, MAX_PATH+1);
|
if (QueryDosDeviceW(&volumeName[4], deviceName, MAX_PATH+1) == 0) {
|
||||||
// TODO - error
|
mark_failed_with_errno(env, "could not query dos device", result);
|
||||||
|
break;
|
||||||
|
}
|
||||||
volumeName[len-1] = L'\\';
|
volumeName[len-1] = L'\\';
|
||||||
|
|
||||||
DWORD used;
|
DWORD used;
|
||||||
GetVolumePathNamesForVolumeNameW(volumeName, pathNames, MAX_PATH+1, &used);
|
if (GetVolumePathNamesForVolumeNameW(volumeName, pathNames, MAX_PATH+1, &used) == 0) {
|
||||||
// TODO - error
|
// TODO - try again if the buffer is too small
|
||||||
|
mark_failed_with_errno(env, "could not query volume paths", result);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
wchar_t* cur = pathNames;
|
wchar_t* cur = pathNames;
|
||||||
if (cur[0] != L'\0') {
|
if (cur[0] != L'\0') {
|
||||||
GetVolumeInformationW(cur, NULL, 0, NULL, NULL, NULL, fsName, MAX_PATH+1);
|
if(GetVolumeInformationW(cur, NULL, 0, NULL, NULL, NULL, fsName, MAX_PATH+1) == 0) {
|
||||||
// TODO - error
|
if (GetLastError() != ERROR_NOT_READY) {
|
||||||
|
mark_failed_with_errno(env, "could not query volume information", result);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
wcscpy(fsName, L"unknown");
|
||||||
|
}
|
||||||
for (;cur[0] != L'\0'; cur += wcslen(cur) + 1) {
|
for (;cur[0] != L'\0'; cur += wcslen(cur) + 1) {
|
||||||
env->CallVoidMethod(info, method, env->NewString((jchar*)deviceName, wcslen(deviceName)),
|
env->CallVoidMethod(info, method, env->NewString((jchar*)deviceName, wcslen(deviceName)),
|
||||||
env->NewString((jchar*)fsName, wcslen(fsName)), env->NewString((jchar*)cur, wcslen(cur)), JNI_FALSE);
|
env->NewString((jchar*)fsName, wcslen(fsName)), env->NewString((jchar*)cur, wcslen(cur)), JNI_FALSE);
|
||||||
@@ -93,11 +111,15 @@ Java_net_rubygrapefruit_platform_internal_jni_PosixFileSystemFunctions_listFileS
|
|||||||
|
|
||||||
if (FindNextVolumeW(handle, volumeName, MAX_PATH) == 0) {
|
if (FindNextVolumeW(handle, volumeName, MAX_PATH) == 0) {
|
||||||
if (GetLastError() != ERROR_NO_MORE_FILES) {
|
if (GetLastError() != ERROR_NO_MORE_FILES) {
|
||||||
// TODO - fail
|
mark_failed_with_errno(env, "could find next volume", result);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
free(volumeName);
|
||||||
|
free(deviceName);
|
||||||
|
free(pathNames);
|
||||||
|
free(fsName);
|
||||||
FindVolumeClose(handle);
|
FindVolumeClose(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,8 +218,7 @@ Java_net_rubygrapefruit_platform_internal_jni_WindowsConsoleFunctions_normal(JNI
|
|||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_net_rubygrapefruit_platform_internal_jni_WindowsConsoleFunctions_reset(JNIEnv *env, jclass target, jobject result) {
|
Java_net_rubygrapefruit_platform_internal_jni_WindowsConsoleFunctions_reset(JNIEnv *env, jclass target, jobject result) {
|
||||||
SetConsoleTextAttribute(current_console, original_attributes);
|
if (!SetConsoleTextAttribute(current_console, original_attributes)) {
|
||||||
if (!SetConsoleTextAttribute(current_console, current_attributes)) {
|
|
||||||
mark_failed_with_errno(env, "could not set text attributes", result);
|
mark_failed_with_errno(env, "could not set text attributes", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -309,8 +330,9 @@ Java_net_rubygrapefruit_platform_internal_jni_WindowsConsoleFunctions_clearToEnd
|
|||||||
mark_failed_with_errno(env, "could not get console buffer", result);
|
mark_failed_with_errno(env, "could not get console buffer", result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int i = console_info.dwCursorPosition.X; i < console_info.dwSize.X; i++) {
|
DWORD count;
|
||||||
WriteConsole(current_console, " ", 1, NULL, NULL);
|
if (!FillConsoleOutputCharacterW(current_console, L' ', console_info.dwSize.X - console_info.dwCursorPosition.X, console_info.dwCursorPosition, &count)) {
|
||||||
|
mark_failed_with_errno(env, "could not clear console", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,9 +72,10 @@ public class Main {
|
|||||||
System.out.print("[3]");
|
System.out.print("[3]");
|
||||||
terminal.cursorDown(1);
|
terminal.cursorDown(1);
|
||||||
terminal.cursorStartOfLine();
|
terminal.cursorStartOfLine();
|
||||||
terminal.clearToEndOfLine();
|
|
||||||
terminal.foreground(Terminal.Color.Blue).bold();
|
terminal.foreground(Terminal.Color.Blue).bold();
|
||||||
System.out.println("done!");
|
System.out.print("done");
|
||||||
|
terminal.clearToEndOfLine();
|
||||||
|
System.out.println("!");
|
||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user