Initial RetroNFS95 Win9x VxD prototype
This commit is contained in:
12
mounter/Makefile.mingw
Normal file
12
mounter/Makefile.mingw
Normal file
@@ -0,0 +1,12 @@
|
||||
CXX = g++
|
||||
EXE = RetroMap95.exe
|
||||
CXXFLAGS = -Os -Wall -Wextra -DWIN32_LEAN_AND_MEAN
|
||||
LDFLAGS = -lmpr
|
||||
|
||||
all: $(EXE)
|
||||
|
||||
$(EXE): retromap95.cpp ../include/retro_ioctl.h
|
||||
$(CXX) $(CXXFLAGS) -I../include -o $(EXE) retromap95.cpp $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
-del /Q $(EXE) 2>NUL
|
||||
186
mounter/retromap95.cpp
Normal file
186
mounter/retromap95.cpp
Normal file
@@ -0,0 +1,186 @@
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#include <winnetwk.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../include/retro_ioctl.h"
|
||||
|
||||
static const char* kRunKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
||||
static const char* kRunName = "RetroNFS95";
|
||||
static const char* kDeviceName = "\\\\.\\RETROVXD";
|
||||
|
||||
static void usage() {
|
||||
printf("RetroMap95\n");
|
||||
printf("Usage:\n");
|
||||
printf(" RetroMap95 /map R: \\\\RetroNFS\\\\server\\\\export_path\n");
|
||||
printf(" RetroMap95 /unmap R:\n");
|
||||
printf(" RetroMap95 /status [R:]\n");
|
||||
printf(" RetroMap95 /startup\n");
|
||||
printf(" RetroMap95 /install-startup\n");
|
||||
}
|
||||
|
||||
static int install_startup() {
|
||||
char exe[MAX_PATH];
|
||||
GetModuleFileNameA(NULL, exe, sizeof(exe));
|
||||
|
||||
char cmd[MAX_PATH + 32];
|
||||
wsprintfA(cmd, "\"%s\" /startup", exe);
|
||||
|
||||
HKEY key;
|
||||
LONG rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, kRunKey, 0, KEY_SET_VALUE, &key);
|
||||
if (rc != ERROR_SUCCESS) {
|
||||
rc = RegCreateKeyA(HKEY_LOCAL_MACHINE, kRunKey, &key);
|
||||
if (rc != ERROR_SUCCESS) return 1;
|
||||
}
|
||||
|
||||
RegSetValueExA(key, kRunName, 0, REG_SZ, (const BYTE*)cmd, lstrlenA(cmd) + 1);
|
||||
RegCloseKey(key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int map_drive(const char* local, const char* remote) {
|
||||
NETRESOURCEA nr;
|
||||
ZeroMemory(&nr, sizeof(nr));
|
||||
nr.dwType = RESOURCETYPE_DISK;
|
||||
nr.lpLocalName = (LPSTR)local;
|
||||
nr.lpRemoteName = (LPSTR)remote;
|
||||
nr.lpProvider = (LPSTR)"RetroNFS95";
|
||||
|
||||
DWORD rc = WNetAddConnection3A(NULL, &nr, NULL, NULL, CONNECT_UPDATE_PROFILE);
|
||||
if (rc != NO_ERROR) {
|
||||
printf("map failed: %lu\n", rc);
|
||||
return 1;
|
||||
}
|
||||
printf("%s mapped to %s\n", local, remote);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int unmap_drive(const char* local) {
|
||||
DWORD rc = WNetCancelConnection2A(local, CONNECT_UPDATE_PROFILE, TRUE);
|
||||
if (rc != NO_ERROR) {
|
||||
printf("unmap failed: %lu\n", rc);
|
||||
return 1;
|
||||
}
|
||||
printf("%s unmapped\n", local);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int print_vxd_status() {
|
||||
HANDLE h = CreateFileA(kDeviceName, 0, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (h == INVALID_HANDLE_VALUE) {
|
||||
printf("RETROVXD not loaded\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
RETRO_STATUS_INFO status;
|
||||
ZeroMemory(&status, sizeof(status));
|
||||
DWORD returned = 0;
|
||||
BOOL ok = DeviceIoControl(h,
|
||||
RETRO_IOCTL_STATUS,
|
||||
NULL,
|
||||
0,
|
||||
&status,
|
||||
sizeof(status),
|
||||
&returned,
|
||||
NULL);
|
||||
CloseHandle(h);
|
||||
if (!ok) {
|
||||
printf("RETROVXD status query failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("RETROVXD loaded, %lu/%lu mappings\n",
|
||||
status.mapping_count,
|
||||
status.max_mappings);
|
||||
printf("IFS scaffold: %s, registration: %s\n",
|
||||
(status.driver_flags & RETRO_DRIVER_FLAG_IFS_STUB) ? "ready" : "not ready",
|
||||
(status.driver_flags & RETRO_DRIVER_FLAG_IFS_REGISTERED) ? "prepared" : "not prepared");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int print_vxd_mapping(const char* local) {
|
||||
HANDLE h = CreateFileA(kDeviceName, 0, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (h == INVALID_HANDLE_VALUE) {
|
||||
printf("RETROVXD not loaded\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
RETRO_QUERY_REQUEST request;
|
||||
RETRO_MAPPING_INFO info;
|
||||
ZeroMemory(&request, sizeof(request));
|
||||
ZeroMemory(&info, sizeof(info));
|
||||
lstrcpynA(request.local, local ? local : "", sizeof(request.local));
|
||||
|
||||
DWORD returned = 0;
|
||||
BOOL ok = DeviceIoControl(h,
|
||||
RETRO_IOCTL_QUERY,
|
||||
&request,
|
||||
sizeof(request),
|
||||
&info,
|
||||
sizeof(info),
|
||||
&returned,
|
||||
NULL);
|
||||
CloseHandle(h);
|
||||
if (!ok) {
|
||||
printf("%s is not mapped in RETROVXD\n", local ? local : "");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("%s -> %s\n", info.local, info.remote);
|
||||
printf("server=%s export=%s\n", info.server, info.export_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void get_config_path(char* out, DWORD len) {
|
||||
GetWindowsDirectoryA(out, len);
|
||||
lstrcatA(out, "\\RETRO95\\mappings.ini");
|
||||
}
|
||||
|
||||
static int remap_startup() {
|
||||
char ini[MAX_PATH];
|
||||
get_config_path(ini, sizeof(ini));
|
||||
|
||||
for (char d = 'A'; d <= 'Z'; ++d) {
|
||||
char section[32];
|
||||
wsprintfA(section, "Drive.%c", d);
|
||||
|
||||
char local[16];
|
||||
char remote[MAX_PATH];
|
||||
GetPrivateProfileStringA(section, "Local", "", local, sizeof(local), ini);
|
||||
GetPrivateProfileStringA(section, "Remote", "", remote, sizeof(remote), ini);
|
||||
if (local[0] && remote[0]) {
|
||||
map_drive(local, remote);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc < 2) {
|
||||
usage();
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (lstrcmpiA(argv[1], "/install-startup") == 0) {
|
||||
return install_startup();
|
||||
}
|
||||
if (lstrcmpiA(argv[1], "/startup") == 0) {
|
||||
return remap_startup();
|
||||
}
|
||||
if (lstrcmpiA(argv[1], "/map") == 0 && argc >= 4) {
|
||||
return map_drive(argv[2], argv[3]);
|
||||
}
|
||||
if (lstrcmpiA(argv[1], "/unmap") == 0 && argc >= 3) {
|
||||
return unmap_drive(argv[2]);
|
||||
}
|
||||
if (lstrcmpiA(argv[1], "/status") == 0) {
|
||||
if (argc >= 3) return print_vxd_mapping(argv[2]);
|
||||
return print_vxd_status();
|
||||
}
|
||||
|
||||
usage();
|
||||
return 2;
|
||||
}
|
||||
Reference in New Issue
Block a user