Unicode friendly!

This commit is contained in:
James Touton 2015-08-06 02:34:24 -07:00
parent 47e95ba2e6
commit a6a46a2697
32 changed files with 736 additions and 520 deletions

View File

@ -50,11 +50,11 @@ typedef struct _PACKET {
BOOLEAN StartPacketDriver(
LPTSTR ServiceName
LPCTSTR ServiceName
);
LPADAPTER PacketOpenAdapter(
LPCSTR AdapterName,
LPCTSTR AdapterName,
int16 mode
);
@ -95,8 +95,7 @@ BOOLEAN PacketGetMAC( LPADAPTER AdapterObject, LPBYTE address, BOOL permanent );
BOOLEAN PacketAddMulticast( LPADAPTER AdapterObject, LPBYTE address );
BOOLEAN PacketDelMulticast( LPADAPTER AdapterObject, LPBYTE address );
ULONG PacketGetAdapterNames( LPADAPTER lpAdapter, PTSTR pStr, PULONG BufferSize );
ULONG PacketSelectAdapterByName( LPADAPTER AdapterObject, LPCSTR name );
ULONG PacketGetAdapterNames( LPADAPTER lpAdapter, LPTSTR pStr, PULONG BufferSize );
// callbacks
void recycle_write_packet( LPPACKET Packet );

View File

@ -21,7 +21,8 @@
*/
#include "sysdeps.h"
#include <windows.h>
#include "main.h"
#include "util_windows.h"
#include <windowsx.h>
#include <winioctl.h>
#include "cpu_emulation.h"
@ -73,26 +74,18 @@ extern "C" {
#define MAX_MULTICAST 100
#define MAX_MULTICAST_SZ (20*ETH_802_3_ADDRESS_LENGTH)
static int os = VER_PLATFORM_WIN32_WINDOWS;
static ULONG packet_filter = 0;
LPADAPTER PacketOpenAdapter( LPCSTR AdapterName, int16 mode )
LPADAPTER PacketOpenAdapter( LPCTSTR AdapterName, int16 mode )
{
LPADAPTER lpAdapter;
BOOLEAN Result = TRUE;
OSVERSIONINFO osv;
D(bug("Packet32: PacketOpenAdapter\n"));
osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if(GetVersionEx( &osv )) os = osv.dwPlatformId;
if(os == VER_PLATFORM_WIN32_NT) {
// May fail if user is not an Administrator.
StartPacketDriver( "B2ether" );
}
// May fail if user is not an Administrator.
StartPacketDriver( TEXT("B2ether") );
lpAdapter = (LPADAPTER)GlobalAllocPtr( GMEM_MOVEABLE|GMEM_ZEROINIT, sizeof(ADAPTER) );
if (lpAdapter==NULL) {
@ -100,25 +93,21 @@ LPADAPTER PacketOpenAdapter( LPCSTR AdapterName, int16 mode )
return NULL;
}
if(os == VER_PLATFORM_WIN32_NT) {
char device_name[256];
wsprintf( lpAdapter->SymbolicLink, "\\\\.\\B2ether_%s", AdapterName );
wsprintf( device_name, "\\Device\\B2ether_%s", AdapterName );
TCHAR device_name[256];
_sntprintf(lpAdapter->SymbolicLink, lengthof(lpAdapter->SymbolicLink), TEXT("\\\\.\\B2ether_%s"), AdapterName );
_sntprintf(device_name, lengthof(device_name), TEXT("\\Device\\B2ether_%s"), AdapterName );
// Work around one subtle NT4 bug.
DefineDosDevice(
DDD_REMOVE_DEFINITION,
&lpAdapter->SymbolicLink[4],
NULL
);
DefineDosDevice(
DDD_RAW_TARGET_PATH,
&lpAdapter->SymbolicLink[4],
device_name
);
} else {
wsprintf( lpAdapter->SymbolicLink, "\\\\.\\B2ether" );
}
// Work around one subtle NT4 bug.
DefineDosDevice(
DDD_REMOVE_DEFINITION,
&lpAdapter->SymbolicLink[4],
NULL
);
DefineDosDevice(
DDD_RAW_TARGET_PATH,
&lpAdapter->SymbolicLink[4],
device_name
);
packet_filter = NDIS_PACKET_TYPE_DIRECTED |
NDIS_PACKET_TYPE_MULTICAST |
@ -138,10 +127,7 @@ LPADAPTER PacketOpenAdapter( LPCSTR AdapterName, int16 mode )
0
);
if (lpAdapter->hFile != INVALID_HANDLE_VALUE) {
if(*AdapterName && strcmp(AdapterName,"<None>") != 0) {
if(os == VER_PLATFORM_WIN32_WINDOWS) {
PacketSelectAdapterByName( lpAdapter, AdapterName );
}
if(*AdapterName && _tcscmp(AdapterName,TEXT("<None>")) != 0) {
PacketSetFilter( lpAdapter, packet_filter );
}
return lpAdapter;
@ -282,58 +268,48 @@ BOOLEAN PacketSendPacket(
D(bug("Packet32: PacketSendPacket bytes=%d, sync=%d\n",lpPacket->Length,Sync));
#endif
if(os == VER_PLATFORM_WIN32_NT) {
lpPacket->OverLapped.Offset = 0;
lpPacket->OverLapped.OffsetHigh = 0;
lpPacket->bIoComplete = FALSE;
lpPacket->OverLapped.Offset = 0;
lpPacket->OverLapped.OffsetHigh = 0;
lpPacket->bIoComplete = FALSE;
if(Sync) {
Result = WriteFile(
AdapterObject->hFile,
lpPacket->Buffer,
lpPacket->Length,
&lpPacket->BytesReceived,
&lpPacket->OverLapped
);
if(Result) {
Result = GetOverlappedResult(
AdapterObject->hFile,
&lpPacket->OverLapped,
&lpPacket->BytesReceived,
TRUE
);
} else {
D(bug("Packet32: PacketSendPacket WriteFile failed, err=%d\n",(int)GetLastError()));
}
lpPacket->bIoComplete = TRUE;
if(RecyclingAllowed) PacketFreePacket(lpPacket);
#if DEBUG_PACKETS
D(bug("Packet32: PacketSendPacket result=%d, bytes=%d\n",(int)Result,(int)lpPacket->BytesReceived));
#endif
if(Sync) {
Result = WriteFile(
AdapterObject->hFile,
lpPacket->Buffer,
lpPacket->Length,
&lpPacket->BytesReceived,
&lpPacket->OverLapped
);
if(Result) {
Result = GetOverlappedResult(
AdapterObject->hFile,
&lpPacket->OverLapped,
&lpPacket->BytesReceived,
TRUE
);
} else {
// don't care about the result
Result = WriteFileEx(
AdapterObject->hFile,
lpPacket->Buffer,
lpPacket->Length,
&lpPacket->OverLapped,
PacketSendCompletionRoutine
);
#if DEBUG_PACKETS
D(bug("Packet32: PacketSendPacket result=%d\n",(int)Result));
#endif
if(!Result && RecyclingAllowed) {
recycle_write_packet(lpPacket);
}
D(bug("Packet32: PacketSendPacket WriteFile failed, err=%d\n",(int)GetLastError()));
}
lpPacket->bIoComplete = TRUE;
if(RecyclingAllowed) PacketFreePacket(lpPacket);
#if DEBUG_PACKETS
D(bug("Packet32: PacketSendPacket result=%d, bytes=%d\n",(int)Result,(int)lpPacket->BytesReceived));
#endif
} else {
// Now: make writes always synchronous under Win9x
Sync = TRUE;
Result = PacketDeviceIoControl( AdapterObject,
lpPacket,
IOCTL_PROTOCOL_WRITE,
Sync );
if(RecyclingAllowed) recycle_write_packet(lpPacket);
// don't care about the result
Result = WriteFileEx(
AdapterObject->hFile,
lpPacket->Buffer,
lpPacket->Length,
&lpPacket->OverLapped,
PacketSendCompletionRoutine
);
#if DEBUG_PACKETS
D(bug("Packet32: PacketSendPacket result=%d\n",(int)Result));
#endif
if(!Result && RecyclingAllowed) {
recycle_write_packet(lpPacket);
}
}
return Result;
@ -347,58 +323,46 @@ BOOLEAN PacketReceivePacket(
{
BOOLEAN Result;
if(os == VER_PLATFORM_WIN32_NT) {
lpPacket->OverLapped.Offset=0;
lpPacket->OverLapped.OffsetHigh=0;
lpPacket->bIoComplete = FALSE;
lpPacket->OverLapped.Offset=0;
lpPacket->OverLapped.OffsetHigh=0;
lpPacket->bIoComplete = FALSE;
#if DEBUG_PACKETS
D(bug("Packet32: PacketReceivePacket\n"));
D(bug("Packet32: PacketReceivePacket\n"));
#endif
if (Sync) {
Result = ReadFile(
AdapterObject->hFile,
lpPacket->Buffer,
lpPacket->Length,
&lpPacket->BytesReceived,
&lpPacket->OverLapped
);
if(Result) {
Result = GetOverlappedResult(
AdapterObject->hFile,
&lpPacket->OverLapped,
&lpPacket->BytesReceived,
TRUE
);
if(Result)
lpPacket->bIoComplete = TRUE;
else
lpPacket->free = TRUE;
}
} else {
Result = ReadFileEx(
AdapterObject->hFile,
lpPacket->Buffer,
lpPacket->Length,
&lpPacket->OverLapped,
packet_read_completion
);
if (Sync) {
Result = ReadFile(
AdapterObject->hFile,
lpPacket->Buffer,
lpPacket->Length,
&lpPacket->BytesReceived,
&lpPacket->OverLapped
);
if(Result) {
Result = GetOverlappedResult(
AdapterObject->hFile,
&lpPacket->OverLapped,
&lpPacket->BytesReceived,
TRUE
);
if(Result)
lpPacket->bIoComplete = TRUE;
else
lpPacket->free = TRUE;
}
if(!Result) lpPacket->BytesReceived = 0;
} else {
Result = PacketDeviceIoControl( AdapterObject,
lpPacket,
IOCTL_PROTOCOL_READ,
Sync );
if( !Result && !Sync ) {
if (GetLastError() == ERROR_IO_PENDING) {
Result = TRUE;
}
}
Result = ReadFileEx(
AdapterObject->hFile,
lpPacket->Buffer,
lpPacket->Length,
&lpPacket->OverLapped,
packet_read_completion
);
}
if(!Result) lpPacket->BytesReceived = 0;
#if DEBUG_PACKETS
D(bug("Packet32: PacketReceivePacket got %d bytes, result=%d\n",lpPacket->BytesReceived,(int)Result));
#endif
@ -641,7 +605,7 @@ BOOLEAN PacketSetFilter( LPADAPTER AdapterObject, ULONG Filter )
return Status;
}
BOOLEAN StartPacketDriver( LPTSTR ServiceName )
BOOLEAN StartPacketDriver( LPCTSTR ServiceName )
{
BOOLEAN Status = FALSE;
@ -658,7 +622,7 @@ BOOLEAN StartPacketDriver( LPTSTR ServiceName )
} else {
SCServiceHandle = OpenService(SCManagerHandle,ServiceName,SERVICE_START);
if (SCServiceHandle == NULL) {
D(bug("Could not open service %s\r\n",ServiceName));
D(bug(TEXT("Could not open service %s\r\n"),ServiceName));
} else {
Status = StartService( SCServiceHandle, 0, NULL );
if(!Status) {
@ -686,7 +650,7 @@ BOOLEAN StartPacketDriver( LPTSTR ServiceName )
} else {
waiting = FALSE;
}
}
}
CloseServiceHandle(SCServiceHandle);
}
CloseServiceHandle(SCManagerHandle);
@ -694,91 +658,33 @@ BOOLEAN StartPacketDriver( LPTSTR ServiceName )
return Status;
}
ULONG PacketGetAdapterNames( LPADAPTER lpAdapter, PTSTR pStr, PULONG BufferSize )
ULONG PacketGetAdapterNames( LPADAPTER lpAdapter, LPTSTR pStr, PULONG BufferSize )
{
LONG Status;
if(os == VER_PLATFORM_WIN32_NT) {
HKEY hKey;
DWORD RegType;
HKEY hKey;
DWORD RegType;
Status = RegOpenKey(
HKEY_LOCAL_MACHINE,
"SYSTEM\\CurrentControlSet\\Services\\B2Ether\\Linkage",
&hKey
);
if( Status == ERROR_SUCCESS ) {
Status = RegQueryValueEx(
hKey,
"Export",
NULL,
&RegType,
(LPBYTE)pStr,
BufferSize
);
RegCloseKey(hKey);
}
} else {
if (lpAdapter && lpAdapter->hFile != INVALID_HANDLE_VALUE) {
LPPACKET Packet = PacketAllocatePacket( lpAdapter, *BufferSize );
if(Packet) {
memset( pStr, 0, *BufferSize );
Packet->Buffer = (PVOID)pStr;
Packet->Length = *BufferSize;
Status = PacketDeviceIoControl(
lpAdapter,
Packet,
(ULONG)IOCTL_PROTOCOL_MACNAME,
TRUE
);
if(Status) {
while(*pStr) {
if(*pStr == '|' || *pStr == ' ') *pStr = 0;
pStr++;
}
*(++pStr) = 0;
Status = ERROR_SUCCESS;
} else {
Status = ERROR_ACCESS_DENIED;
}
*BufferSize = Packet->BytesReceived;
PacketFreePacket(Packet);
}
}
Status = RegOpenKey(
HKEY_LOCAL_MACHINE,
TEXT("SYSTEM\\CurrentControlSet\\Services\\B2Ether\\Linkage"),
&hKey
);
if( Status == ERROR_SUCCESS ) {
Status = RegQueryValueEx(
hKey,
TEXT("Export"),
NULL,
&RegType,
(LPBYTE)pStr,
BufferSize
);
RegCloseKey(hKey);
}
return Status;
}
ULONG PacketSelectAdapterByName( LPADAPTER lpAdapter, LPCSTR name )
{
ULONG Status = 0;
if(os == VER_PLATFORM_WIN32_WINDOWS) {
int len = strlen(name) + 1;
LPPACKET Packet = PacketAllocatePacket( lpAdapter, len );
if(Packet) {
Packet->Buffer = (PVOID)name;
Packet->Length = len;
Status = PacketDeviceIoControl(
lpAdapter,
Packet,
(ULONG)IOCTL_PROTOCOL_SELECT_BY_NAME,
TRUE
);
if(Status) {
Status = ERROR_SUCCESS;
} else {
Status = ERROR_ACCESS_DENIED;
}
PacketFreePacket(Packet);
}
}
return Status;
}
#ifdef __cplusplus
}
#endif

View File

@ -29,9 +29,9 @@ extern "C" {
#include "ntcd.h"
#include "cdenable.h"
static char *sDriverShort = "cdenable";
static char *sDriverLong = "System32\\Drivers\\cdenable.sys";
static char *sCompleteName = "\\\\.\\cdenable";
static LPCTSTR sDriverShort = TEXT("cdenable");
static LPCTSTR sDriverLong = TEXT("System32\\Drivers\\cdenable.sys");
static LPCTSTR sCompleteName = TEXT("\\\\.\\cdenable");
#ifdef _DEBUG
#define new DEBUG_NEW

View File

@ -168,7 +168,7 @@ static HANDLE int_sig2 = 0;
static HANDLE int_send_now = 0;
// Prototypes
static LPADAPTER tap_open_adapter(const char *dev_name);
static LPADAPTER tap_open_adapter(LPCTSTR dev_name);
static void tap_close_adapter(LPADAPTER fd);
static bool tap_check_version(LPADAPTER fd);
static bool tap_set_status(LPADAPTER fd, ULONG status);
@ -218,7 +218,7 @@ static NetProtocol *find_protocol(uint16 type)
bool ether_init(void)
{
char str[256];
TCHAR buf[256];
// Do nothing if no Ethernet device specified
const char *name = PrefsFindString("ether");
@ -248,22 +248,21 @@ bool ether_init(void)
// Initialize slirp library
if (net_if_type == NET_IF_SLIRP) {
if (slirp_init() < 0) {
sprintf(str, GetString(STR_SLIRP_NO_DNS_FOUND_WARN));
WarningAlert(str);
WarningAlert(GetString(STR_SLIRP_NO_DNS_FOUND_WARN));
return false;
}
}
// Open ethernet device
const char *dev_name;
decltype(tstr(std::declval<const char*>())) dev_name;
switch (net_if_type) {
case NET_IF_B2ETHER:
dev_name = PrefsFindString("etherguid");
dev_name = tstr(PrefsFindString("etherguid"));
if (dev_name == NULL || strcmp(name, "b2ether") != 0)
dev_name = name;
dev_name = tstr(name);
break;
case NET_IF_TAP:
dev_name = PrefsFindString("etherguid");
dev_name = tstr(PrefsFindString("etherguid"));
break;
}
if (net_if_type == NET_IF_B2ETHER) {
@ -272,17 +271,17 @@ bool ether_init(void)
goto open_error;
}
fd = PacketOpenAdapter( dev_name, ether_multi_mode );
fd = PacketOpenAdapter( dev_name.get(), ether_multi_mode );
if (!fd) {
sprintf(str, "Could not open ethernet adapter %s.", dev_name);
WarningAlert(str);
_sntprintf(buf, lengthof(buf), TEXT("Could not open ethernet adapter %s."), dev_name.get());
WarningAlert(buf);
goto open_error;
}
// Get Ethernet address
if(!PacketGetMAC(fd,ether_addr,ether_use_permanent)) {
sprintf(str, "Could not get hardware address of device %s. Ethernet is not available.", dev_name);
WarningAlert(str);
_sntprintf(buf, lengthof(buf), TEXT("Could not get hardware address of device %s. Ethernet is not available."), dev_name.get());
WarningAlert(buf);
goto open_error;
}
D(bug("Real ethernet address %02x %02x %02x %02x %02x %02x\n", ether_addr[0], ether_addr[1], ether_addr[2], ether_addr[3], ether_addr[4], ether_addr[5]));
@ -306,28 +305,27 @@ bool ether_init(void)
goto open_error;
}
fd = tap_open_adapter(dev_name);
fd = tap_open_adapter(dev_name.get());
if (!fd) {
sprintf(str, "Could not open ethernet adapter %s.", dev_name);
WarningAlert(str);
_sntprintf(buf, lengthof(buf), TEXT("Could not open ethernet adapter %s."), dev_name.get());
WarningAlert(buf);
goto open_error;
}
if (!tap_check_version(fd)) {
sprintf(str, "Minimal TAP-Win32 version supported is %d.%d.", TAP_VERSION_MIN_MAJOR, TAP_VERSION_MIN_MINOR);
WarningAlert(str);
_sntprintf(buf, lengthof(buf), TEXT("Minimal TAP-Win32 version supported is %d.%d."), TAP_VERSION_MIN_MAJOR, TAP_VERSION_MIN_MINOR);
WarningAlert(buf);
goto open_error;
}
if (!tap_set_status(fd, true)) {
sprintf(str, "Could not set media status to connected.");
WarningAlert(str);
WarningAlert("Could not set media status to connected.");
goto open_error;
}
if (!tap_get_mac(fd, ether_addr)) {
sprintf(str, "Could not get hardware address of device %s. Ethernet is not available.", dev_name);
WarningAlert(str);
_sntprintf(buf, lengthof(buf), TEXT("Could not get hardware address of device %s. Ethernet is not available."), dev_name.get());
WarningAlert(buf);
goto open_error;
}
D(bug("Real ethernet address %02x %02x %02x %02x %02x %02x\n", ether_addr[0], ether_addr[1], ether_addr[2], ether_addr[3], ether_addr[4], ether_addr[5]));
@ -1168,15 +1166,15 @@ static bool set_wait_request(void)
* TAP-Win32 glue
*/
static LPADAPTER tap_open_adapter(const char *dev_name)
static LPADAPTER tap_open_adapter(LPCTSTR dev_name)
{
fd = (LPADAPTER)GlobalAllocPtr(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(*fd));
if (fd == NULL)
return NULL;
char dev_path[MAX_PATH];
snprintf(dev_path, sizeof(dev_path),
"\\\\.\\Global\\%s.tap", dev_name);
TCHAR dev_path[MAX_PATH];
_sntprintf(dev_path, lengthof(dev_path),
TEXT("\\\\.\\Global\\%s.tap"), dev_name);
HANDLE handle = CreateFile(
dev_path,

View File

@ -18,17 +18,18 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "sysdeps.h"
#include "main.h"
#include "extfs.h"
#include "extfs_defs.h"
#include "posix_emu.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include "sysdeps.h"
#include "extfs.h"
#include "extfs_defs.h"
#include "posix_emu.h"
#define DEBUG 0
#include "debug.h"
@ -127,8 +128,13 @@ static int open_helper(const char *path, const char *add, int flag)
char helper_path[MAX_PATH_LENGTH];
make_helper_path(path, helper_path, add);
if ((flag & O_ACCMODE) == O_RDWR || (flag & O_ACCMODE) == O_WRONLY)
switch (flag & (_O_RDONLY | _O_WRONLY | _O_RDWR)) {
case _O_WRONLY:
case _O_RDWR:
flag |= O_CREAT;
break;
}
int fd = open(helper_path, flag, 0666);
if (fd < 0) {
if (/*errno == ENOENT &&*/ (flag & O_CREAT)) {

View File

@ -30,7 +30,7 @@
#include <SDL_thread.h>
#include <string>
using std::string;
typedef std::basic_string<TCHAR> tstring;
#include "cpu_emulation.h"
#include "sys.h"
@ -63,7 +63,7 @@ extern void flush_icache_range(uint8 *start, uint32 size); // from compemu_suppo
// Constants
const char ROM_FILE_NAME[] = "ROM";
const TCHAR ROM_FILE_NAME[] = TEXT("ROM");
const int SCRATCH_MEM_SIZE = 0x10000; // Size of scratch memory area
@ -235,8 +235,8 @@ int main(int argc, char **argv)
} else if (strcmp(argv[i], "--config") == 0) {
argv[i++] = NULL;
if (i < argc) {
extern string UserPrefsPath; // from prefs_windows.cpp
UserPrefsPath = argv[i];
extern tstring UserPrefsPath; // from prefs_windows.cpp
UserPrefsPath = to_tstring(argv[i]);
argv[i] = NULL;
}
} else if (strcmp(argv[i], "--rominfo") == 0) {
@ -277,9 +277,11 @@ int main(int argc, char **argv)
}
}
#if 0
// Check that drivers are installed
if (!check_drivers())
QuitEmulator();
#endif
// FIXME: default to DIB driver
if (getenv("SDL_VIDEODRIVER") == NULL)
@ -359,10 +361,10 @@ int main(int argc, char **argv)
D(bug("Mac ROM starts at %p (%08x)\n", ROMBaseHost, ROMBaseMac));
// Get rom file path from preferences
const char *rom_path = PrefsFindString("rom");
auto rom_path = tstr(PrefsFindString("rom"));
// Load Mac ROM
HANDLE rom_fh = CreateFile(rom_path ? rom_path : ROM_FILE_NAME,
HANDLE rom_fh = CreateFile(rom_path ? rom_path.get() : ROM_FILE_NAME,
GENERIC_READ,
FILE_SHARE_READ, NULL,
OPEN_EXISTING,
@ -639,7 +641,12 @@ HWND GetMainWindowHandle(void)
static void display_alert(int title_id, const char *text, int flags)
{
HWND hMainWnd = GetMainWindowHandle();
MessageBox(hMainWnd, text, GetString(title_id), MB_OK | flags);
MessageBoxA(hMainWnd, text, GetString(title_id), MB_OK | flags);
}
static void display_alert(int title_id, const wchar_t *text, int flags)
{
HWND hMainWnd = GetMainWindowHandle();
MessageBoxW(hMainWnd, text, GetStringW(title_id).get(), MB_OK | flags);
}
@ -655,6 +662,14 @@ void ErrorAlert(const char *text)
VideoQuitFullScreen();
display_alert(STR_ERROR_ALERT_TITLE, text, MB_ICONSTOP);
}
void ErrorAlert(const wchar_t *text)
{
if (PrefsFindBool("nogui"))
return;
VideoQuitFullScreen();
display_alert(STR_ERROR_ALERT_TITLE, text, MB_ICONSTOP);
}
/*
@ -668,6 +683,13 @@ void WarningAlert(const char *text)
display_alert(STR_WARNING_ALERT_TITLE, text, MB_ICONINFORMATION);
}
void WarningAlert(const wchar_t *text)
{
if (PrefsFindBool("nogui"))
return;
display_alert(STR_WARNING_ALERT_TITLE, text, MB_ICONINFORMATION);
}
/*

View File

@ -114,21 +114,21 @@ int my_errno = 0;
#define VIRTUAL_ROOT_ID ((HANDLE)0xFFFFFFFE)
static const char *desktop_name = "Virtual Desktop";
static LPCTSTR desktop_name = TEXT("Virtual Desktop");
static const char *custom_icon_name = "Icon\r";
#define my_computer GetString(STR_EXTFS_VOLUME_NAME)
static char lb1[MAX_PATH_LENGTH];
static char lb2[MAX_PATH_LENGTH];
static TCHAR lb1[MAX_PATH_LENGTH];
static TCHAR lb2[MAX_PATH_LENGTH];
#define MRP(path) translate(path,lb1)
#define MRP(path) translate(path,lb1)
#define MRP2(path) translate(path,lb2)
#define DISABLE_ERRORS UINT prevmode = SetErrorMode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS)
#define RESTORE_ERRORS SetErrorMode(prevmode);
static char host_drive_list[512];
static char virtual_root[248]; // Not _MAX_PATH
static TCHAR host_drive_list[512];
static TCHAR virtual_root[248]; // Not _MAX_PATH
const uint8 my_comp_icon[2670] = {
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x09, 0xD8, 0x00, 0x00, 0x08, 0xD8, 0x00, 0x00, 0x00, 0x96,
@ -302,12 +302,12 @@ const uint8 my_comp_icon[2670] = {
static bool use_streams[ 'Z'-'A'+1 ];
static bool is_ntfs_volume( char *rootdir )
static bool is_ntfs_volume(LPCTSTR rootdir)
{
bool ret = false;
char tst_file[_MAX_PATH], tst_stream[_MAX_PATH];
sprintf( tst_file, "%sb2query.tmp", rootdir );
sprintf( tst_stream, "%s:AFP_AfpInfo", tst_file );
TCHAR tst_file[_MAX_PATH], tst_stream[_MAX_PATH];
_sntprintf( tst_file, lengthof(tst_file), TEXT("%sb2query.tmp"), rootdir );
_sntprintf( tst_stream, lengthof(tst_stream), TEXT("%s:AFP_AfpInfo"), tst_file );
if(!exists(tst_file)) {
if(create_file( tst_file, 0 )) {
if(create_file( tst_stream, 0 )) {
@ -353,12 +353,11 @@ void init_posix_emu(void)
const char *extdrives = PrefsFindString("extdrives");
// Set up drive list.
int outinx = 0;
for( char letter = 'A'; letter <= 'Z'; letter++ ) {
size_t outinx = 0;
for( TCHAR letter = TEXT('A'); letter <= TEXT('Z'); letter++ ) {
if(extdrives && !strchr(extdrives,letter)) continue;
int i = (int)( letter - 'A' );
char rootdir[20];
wsprintf( rootdir, "%c:\\", letter );
TCHAR rootdir[20];
_sntprintf( rootdir, lengthof(rootdir), TEXT("%c:\\"), letter );
use_streams[ letter - 'A' ] = false;
switch(GetDriveType(rootdir)) {
case DRIVE_FIXED:
@ -368,7 +367,7 @@ void init_posix_emu(void)
// fall
case DRIVE_REMOVABLE:
case DRIVE_CDROM:
if(outinx < sizeof(host_drive_list)) {
if(outinx < lengthof(host_drive_list)) {
host_drive_list[outinx] = letter;
outinx += 2;
}
@ -377,14 +376,13 @@ void init_posix_emu(void)
// Set up virtual desktop root.
// TODO: this should be customizable.
GetModuleFileName( NULL, virtual_root, sizeof(virtual_root) );
char *p = strrchr( virtual_root, '\\' );
GetModuleFileName( NULL, virtual_root, lengthof(virtual_root) );
TCHAR *p = _tcsrchr( virtual_root, TEXT('\\') );
if(p) {
*(++p) = 0;
strcat( virtual_root, desktop_name );
_tcscpy( ++p, desktop_name );
} else {
// should never happen
sprintf( virtual_root, "C:\\%s", desktop_name );
_sntprintf( virtual_root, lengthof(virtual_root), TEXT("C:\\%s"), desktop_name );
}
CreateDirectory( virtual_root, 0 );
@ -433,14 +431,14 @@ static void charset_host2mac( char *s )
}
}
static void charset_mac2host( char *s )
static void charset_mac2host( LPTSTR s )
{
int i, convert, len = strlen(s);
size_t len = _tcslen(s);
D(bug("charset_mac2host(%s)...\n", s));
D(bug(TEXT("charset_mac2host(%s)...\n"), s));
for( i=len-1; i>=0; i-- ) {
convert = 0;
for( size_t i=len; i-->0; ) {
bool convert = false;
switch( (unsigned char)s[i] ) {
// case '\r': // handled by "default"
// case '\n':
@ -455,61 +453,61 @@ static void charset_mac2host( char *s )
case '>':
case '|':
case '%':
convert = 1;
convert = true;
break;
default:
if((unsigned char)s[i] < ' ') convert = 1;
if((unsigned char)s[i] < ' ') convert = true;
break;
}
if(convert) {
char sml[10];
sprintf( sml, "%%%02X", s[i] );
memmove( &s[i+2], &s[i], strlen(&s[i])+1 );
memmove( &s[i], sml, 3 );
TCHAR sml[10];
_sntprintf( sml, lengthof(sml), TEXT("%%%02X"), s[i] );
memmove( &s[i+2], &s[i], (_tcslen(&s[i])+1) * sizeof(TCHAR) );
memmove( &s[i], sml, 3 * sizeof(TCHAR) );
}
}
D(bug("charset_mac2host = %s\n", s));
D(bug(TEXT("charset_mac2host = %s\n"), s));
}
static void make_mask(
char *mask,
const char *dir,
const char *a1,
const char *a2
TCHAR *mask,
LPCTSTR dir,
LPCTSTR a1,
LPCTSTR a2
)
{
strcpy( mask, dir );
_tcscpy( mask, dir );
int len = strlen(mask);
if( len && mask[len-1] != '\\' ) strcat( mask, "\\" );
size_t len = _tcslen(mask);
if( len && mask[len-1] != '\\' ) _tcscat( mask, TEXT("\\") );
if( a1 ) strcat( mask, a1 );
if( a2 ) strcat( mask, a2 );
if( a1 ) _tcscat( mask, a1 );
if( a2 ) _tcscat( mask, a2 );
}
// !!UNC
static char *translate( const char *path, char *buffer )
static LPTSTR translate( LPCTSTR path, TCHAR *buffer )
{
char *l = host_drive_list;
char *p = (char *)path;
TCHAR *l = host_drive_list;
const TCHAR *p = path;
while(*l) {
if(toupper(p[1]) == toupper(*l)) break;
l += strlen(l) + 1;
if(_totupper(p[1]) == _totupper(*l)) break;
l += _tcslen(l) + 1;
}
if(p[0] == '\\' && *l && (p[2] == 0 || p[2] == ':' || p[2] == '\\')) {
if(p[0] == TEXT('\\') && *l && (p[2] == 0 || p[2] == TEXT(':') || p[2] == TEXT('\\'))) {
p += 2;
if(*p == ':') p++;
if(*p == '\\') p++;
sprintf( buffer, "%c:\\%s", *l, p );
if(*p == TEXT(':')) p++;
if(*p == TEXT('\\')) p++;
_sntprintf( buffer, MAX_PATH_LENGTH, TEXT("%c:\\%s"), *l, p );
} else {
if(*path == '\\') {
sprintf( buffer, "%s%s", virtual_root, path );
if(*path == TEXT('\\')) {
_sntprintf( buffer, MAX_PATH_LENGTH, TEXT("%s%s"), virtual_root, path );
} else {
int len = strlen(path);
if(len == 0 || path[len-1] == '\\') {
make_mask( buffer, virtual_root, path, my_computer );
int len = _tcslen(path);
if(len == 0 || path[len-1] == TEXT('\\')) {
make_mask( buffer, virtual_root, path, tstr(my_computer).get() );
} else {
make_mask( buffer, virtual_root, path, 0 );
}
@ -521,10 +519,10 @@ static char *translate( const char *path, char *buffer )
}
// helpers
static void strip_trailing_bs( char *path )
static void strip_trailing_bs( LPTSTR path )
{
int len = strlen(path);
if(len > 0 && path[len-1] == '\\') path[len-1] = 0;
size_t len = _tcslen(path);
if(len > 0 && path[len-1] == TEXT('\\')) path[len-1] = 0;
}
#if 0 /* defined is util_windows.cpp */
@ -546,7 +544,7 @@ static int exists( const char *p )
}
#endif
static int is_dir( char *p )
static int is_dir( LPCTSTR p )
{
WIN32_FIND_DATA fdata;
@ -560,31 +558,31 @@ static int is_dir( char *p )
return result;
}
static int myRemoveDirectory( const char *source )
static int myRemoveDirectory( LPCTSTR source )
{
HANDLE fh;
WIN32_FIND_DATA FindFileData;
int ok, result = 1;
char mask[_MAX_PATH];
TCHAR mask[_MAX_PATH];
D(bug("removing folder %s\n", source));
D(bug(TEXT("removing folder %s\n"), source));
make_mask( mask, source, "*.*", 0 );
make_mask( mask, source, TEXT("*.*"), 0 );
fh = FindFirstFile( mask, &FindFileData );
ok = fh != INVALID_HANDLE_VALUE;
while(ok) {
make_mask( mask, source, FindFileData.cFileName, 0 );
D(bug("removing item %s\n", mask));
D(bug(TEXT("removing item %s\n"), mask));
int isdir = (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
if(isdir) {
// must delete ".finf", ".rsrc" but not ".", ".."
if(strcmp(FindFileData.cFileName,".") && strcmp(FindFileData.cFileName,"..")) {
if(_tcscmp(FindFileData.cFileName,TEXT(".")) && _tcscmp(FindFileData.cFileName,TEXT(".."))) {
result = myRemoveDirectory( mask );
if(!result) break;
}
} else {
D(bug("DeleteFile %s\n", mask));
D(bug(TEXT("DeleteFile %s\n"), mask));
result = DeleteFile( mask );
if(!result) break;
}
@ -592,41 +590,41 @@ static int myRemoveDirectory( const char *source )
}
if(fh != INVALID_HANDLE_VALUE) FindClose( fh );
if(result) {
D(bug("RemoveDirectory %s\n", source));
D(bug(TEXT("RemoveDirectory %s\n"), source));
result = RemoveDirectory( source );
}
return result;
}
static void make_folders( char *path )
static void make_folders( LPCTSTR path )
{
char local_path[_MAX_PATH], *p;
strcpy( local_path, path );
p = strrchr( local_path, '\\' );
TCHAR local_path[_MAX_PATH], *p;
_tcscpy( local_path, path );
p = _tcsrchr( local_path, TEXT('\\') );
if(p) {
*p = 0;
if(strlen(local_path) > 3) {
if(_tcslen(local_path) > 3) {
make_folders(local_path);
mkdir(local_path);
_tmkdir(local_path);
}
}
}
// !!UNC
static bool is_same_drive( char *p1, char *p2 )
static bool is_same_drive( LPCTSTR p1, LPCTSTR p2 )
{
return toupper(*p1) == toupper(*p2);
return _totupper(*p1) == _totupper(*p2);
}
// Used when the drives are known to be different.
// Can't use MoveFileEx() etc because of the Win9x limitations.
// It would simulate CopyFile*() -- DeleteFile*() anyway
int file_move_copy( char *src, char *dst, bool delete_old )
static int file_move_copy( LPCTSTR src, LPCTSTR dst, bool delete_old )
{
int result = 0;
my_errno = 0;
D(bug("file_copy %s -> %s\n", src, dst));
D(bug(TEXT("file_copy %s -> %s\n"), src, dst));
// Fail if exists -- it's up to MacOS to move things to Trash
if(CopyFile(src,dst,TRUE)) {
@ -644,24 +642,24 @@ int file_move_copy( char *src, char *dst, bool delete_old )
return result;
}
int file_move( char *src, char *dst )
static int file_move( LPCTSTR src, LPCTSTR dst )
{
return file_move_copy( src, dst, true );
}
int file_copy( char *src, char *dst )
static int file_copy( LPCTSTR src, LPCTSTR dst )
{
return file_move_copy( src, dst, false );
}
int folder_copy( char *folder_src, char *folder_dst )
static int folder_copy( LPCTSTR folder_src, LPCTSTR folder_dst )
{
HANDLE fh;
WIN32_FIND_DATA FindFileData;
int ok, result = 0;
char mask[_MAX_PATH];
TCHAR mask[_MAX_PATH];
D(bug("copying folder %s -> \n", folder_src, folder_dst));
D(bug(TEXT("copying folder %s -> \n"), folder_src, folder_dst));
my_errno = 0;
@ -670,18 +668,18 @@ int folder_copy( char *folder_src, char *folder_dst )
return -1;
}
make_mask( mask, folder_src, "*.*", 0 );
make_mask( mask, folder_src, TEXT("*.*"), 0 );
fh = FindFirstFile( mask, &FindFileData );
ok = fh != INVALID_HANDLE_VALUE;
while(ok) {
make_mask( mask, folder_src, FindFileData.cFileName, 0 );
int isdir = (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
char target[_MAX_PATH];
TCHAR target[_MAX_PATH];
make_mask( target, folder_dst, FindFileData.cFileName, 0 );
D(bug("copying item %s -> %s\n", mask, target));
D(bug(TEXT("copying item %s -> %s\n"), mask, target));
if(isdir) {
if(strcmp(FindFileData.cFileName,".") && strcmp(FindFileData.cFileName,"..")) {
if(_tcscmp(FindFileData.cFileName,TEXT(".")) && _tcscmp(FindFileData.cFileName,TEXT(".."))) {
result = folder_copy( mask, target );
if(result < 0) break;
}
@ -715,12 +713,11 @@ static int make_dentry( struct DIR *d )
memset( &d->de, 0, sizeof(d->de) );
if(d->h != INVALID_HANDLE_VALUE) {
if( (d->FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 &&
*d->FindFileData.cFileName == '.')
*d->FindFileData.cFileName == TEXT('.'))
{
ok = 0;
} else {
strncpy( d->de.d_name, d->FindFileData.cFileName, sizeof(d->de.d_name)-1 );
d->de.d_name[sizeof(d->de.d_name)-1] = 0;
strlcpy( d->de.d_name, d->FindFileData.cFileName, lengthof(d->de.d_name) );
charset_host2mac( d->de.d_name );
ok = 1;
}
@ -739,14 +736,14 @@ struct dirent *readdir( struct DIR *d )
if(d->h == VIRTUAL_ROOT_ID) {
make_dentry(d);
de = &d->de;
d->vname_list += strlen(d->vname_list) + 1;
d->vname_list += _tcslen(d->vname_list) + 1;
if(*d->vname_list) {
strcpy( d->FindFileData.cFileName, d->vname_list );
_tcscpy( d->FindFileData.cFileName, d->vname_list );
d->FindFileData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
} else {
// Out of static drive entries. Continue with other stuff.
char mask[MAX_PATH_LENGTH];
make_mask( mask, virtual_root, "*.*", 0 );
TCHAR mask[MAX_PATH_LENGTH];
make_mask( mask, virtual_root, TEXT("*.*"), 0 );
d->h = FindFirstFile( mask, &d->FindFileData );
}
} else {
@ -778,23 +775,24 @@ struct dirent *readdir( struct DIR *d )
struct DIR *opendir( const char *path )
{
DISABLE_ERRORS;
auto tpath = tstr(path);
DIR *d = new DIR;
if(d) {
memset( d, 0, sizeof(DIR) );
if(*path == 0) {
if(*tpath.get() == 0) {
d->vname_list = host_drive_list;
if(d->vname_list) {
d->h = VIRTUAL_ROOT_ID;
strcpy( d->FindFileData.cFileName, d->vname_list );
_tcscpy( d->FindFileData.cFileName, d->vname_list );
d->FindFileData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
} else {
d->h = INVALID_HANDLE_VALUE;
}
} else {
char mask[MAX_PATH_LENGTH];
make_mask( mask, MRP(path), "*.*", 0 );
TCHAR mask[MAX_PATH_LENGTH];
make_mask( mask, MRP(tpath.get()), TEXT("*.*"), 0 );
D(bug("opendir path=%s, mask=%s\n", path, mask));
D(bug(TEXT("opendir path=%s, mask=%s\n"), tpath.get(), mask));
d->h = FindFirstFile( mask, &d->FindFileData );
if(d->h == INVALID_HANDLE_VALUE) {
@ -804,7 +802,7 @@ struct DIR *opendir( const char *path )
}
}
D(bug("opendir(%s,%s) = %08x\n", path, MRP(path), d));
D(bug(TEXT("opendir(%s,%s) = %08x\n"), tpath.get(), MRP(tpath.get()), d));
RESTORE_ERRORS;
@ -823,16 +821,17 @@ int my_stat( const char *path, struct my_stat *st )
{
DISABLE_ERRORS;
auto tpath = tstr(path);
int result;
if(*path == 0) {
if(*tpath.get() == 0) {
/// virtual root
memset( st, 0, sizeof(struct my_stat) );
st->st_mode = _S_IFDIR;
result = 0;
my_errno = 0;
} else {
result = stat( MRP(path), (struct stat *)st );
result = _tstat( MRP(tpath.get()), (struct _stat *)st );
if(result < 0) {
my_errno = errno;
} else {
@ -840,7 +839,7 @@ int my_stat( const char *path, struct my_stat *st )
}
}
D(bug("stat(%s,%s) = %d\n", path, MRP(path), result));
D(bug(TEXT("stat(%s,%s) = %d\n"), tpath.get(), MRP(tpath.get()), result));
if(result >= 0) dump_stat( st );
RESTORE_ERRORS;
return result;
@ -849,7 +848,7 @@ int my_stat( const char *path, struct my_stat *st )
int my_fstat( int fd, struct my_stat *st )
{
DISABLE_ERRORS;
int result = fstat( fd, (struct stat *)st );
int result = _fstat( fd, (struct _stat *)st );
if(result < 0) {
my_errno = errno;
} else {
@ -865,24 +864,25 @@ int my_open( const char *path, int mode, ... )
{
DISABLE_ERRORS;
int result;
char *p = MRP(path);
auto tpath = tstr(path);
LPCTSTR p = MRP(tpath.get());
// Windows "open" does not handle _O_CREAT and _O_BINARY as it should
if(mode & _O_CREAT) {
if(exists(p)) {
result = open( p, mode & ~_O_CREAT );
D(bug("open-nocreat(%s,%s,%d) = %d\n", path, p, mode, result));
result = _topen( p, mode & ~_O_CREAT );
D(bug(TEXT("open-nocreat(%s,%s,%d) = %d\n"), tpath.get(), p, mode, result));
} else {
result = creat( p, _S_IWRITE|_S_IREAD );
result = _tcreat( p, _S_IWRITE|_S_IREAD );
if(result < 0) {
make_folders(p);
result = creat( p, _S_IWRITE|_S_IREAD );
result = _tcreat( p, _S_IWRITE|_S_IREAD );
}
D(bug("open-creat(%s,%s,%d) = %d\n", path, p, mode, result));
D(bug(TEXT("open-creat(%s,%s,%d) = %d\n"), tpath.get(), p, mode, result));
}
} else {
result = open( p, mode );
D(bug("open(%s,%s,%d) = %d\n", path, p, mode, result));
result = _topen( p, mode );
D(bug(TEXT("open(%s,%s,%d) = %d\n"), tpath.get(), p, mode, result));
}
if(result < 0) {
my_errno = errno;
@ -898,15 +898,17 @@ int my_rename( const char *old_path, const char *new_path )
{
DISABLE_ERRORS;
int result = -1;
char *p_old = MRP(old_path);
char *p_new = MRP2(new_path);
auto told_path = tstr(old_path);
auto tnew_path = tstr(new_path);
LPCTSTR p_old = MRP(told_path.get());
LPCTSTR p_new = MRP2(tnew_path.get());
result = my_access(old_path,0);
if(result < 0) {
// my_errno already set
} else {
if(is_same_drive(p_old,p_new)) {
result = rename( p_old, p_new );
result = _trename( p_old, p_new );
if(result != 0) { // by definition, rename may also return a positive value to indicate an error
my_errno = errno;
} else {
@ -932,7 +934,7 @@ int my_rename( const char *old_path, const char *new_path )
}
}
}
D(bug("rename(%s,%s,%s,%s) = %d\n", old_path, p_old, new_path, p_new, result));
D(bug(TEXT("rename(%s,%s,%s,%s) = %d\n"), told_path.get(), p_old, tnew_path.get(), p_new, result));
RESTORE_ERRORS;
return result;
}
@ -940,7 +942,8 @@ int my_rename( const char *old_path, const char *new_path )
int my_access( const char *path, int mode )
{
DISABLE_ERRORS;
char *p = MRP(path);
auto tpath = tstr(path);
LPCTSTR p = MRP(tpath.get());
WIN32_FIND_DATA fdata;
int result;
@ -968,7 +971,7 @@ int my_access( const char *path, int mode )
}
} else {
// W_OK, F_OK are ok.
result = access(p,mode);
result = _taccess(p,mode);
if(result < 0) {
my_errno = errno;
} else {
@ -976,7 +979,7 @@ int my_access( const char *path, int mode )
}
}
D(bug("access(%s,%s,%d) = %d\n", path, MRP(path), mode, result));
D(bug(TEXT("access(%s,%s,%d) = %d\n"), tpath.get(), p, mode, result));
RESTORE_ERRORS;
return result;
}
@ -984,19 +987,20 @@ int my_access( const char *path, int mode )
int my_mkdir( const char *path, int mode )
{
DISABLE_ERRORS;
char *p = MRP(path);
auto tpath = tstr(path);
LPTSTR p = MRP(tpath.get());
strip_trailing_bs(p);
int result = mkdir( p );
int result = _tmkdir( p );
if(result < 0) {
make_folders(p);
result = mkdir( p );
result = _tmkdir( p );
}
if(result < 0) {
my_errno = errno;
} else {
my_errno = 0;
}
D(bug("mkdir(%s,%s,%d) = %d\n", path, p, mode, result));
D(bug(TEXT("mkdir(%s,%s,%d) = %d\n"), tpath.get(), p, mode, result));
RESTORE_ERRORS;
return result;
}
@ -1004,13 +1008,14 @@ int my_mkdir( const char *path, int mode )
int my_remove( const char *path )
{
DISABLE_ERRORS;
char *p = MRP(path);
auto tpath = tstr(path);
LPTSTR p = MRP(tpath.get());
strip_trailing_bs(p);
int result;
if(is_dir(p)) {
result = myRemoveDirectory( p );
} else {
D(bug("DeleteFile %s\n", p));
D(bug(TEXT("DeleteFile %s\n"), p));
result = DeleteFile( p );
}
if(result) {
@ -1024,7 +1029,7 @@ int my_remove( const char *path )
my_errno = ENOENT;
}
}
D(bug("remove(%s,%s) = %d\n", path, p, result));
D(bug(TEXT("remove(%s,%s) = %d\n"), tpath.get(), p, result));
RESTORE_ERRORS;
return result;
}
@ -1032,11 +1037,12 @@ int my_remove( const char *path )
int my_creat( const char *path, int mode )
{
DISABLE_ERRORS;
char *p = MRP(path);
int result = creat( p, _S_IWRITE|_S_IREAD ); // note mode
auto tpath = tstr(path);
LPCTSTR p = MRP(tpath.get());
int result = _tcreat( p, _S_IWRITE|_S_IREAD ); // note mode
if(result < 0) {
make_folders(p);
result = creat( p, _S_IWRITE|_S_IREAD ); // note mode
result = _tcreat( p, _S_IWRITE|_S_IREAD ); // note mode
}
if(result < 0) {
my_errno = errno;
@ -1044,7 +1050,7 @@ int my_creat( const char *path, int mode )
setmode(result, _O_BINARY);
my_errno = 0;
}
D(bug("creat(%s,%s,%d) = %d\n", path, p, mode,result));
D(bug(TEXT("creat(%s,%s,%d) = %d\n"), tpath.get(), p, mode,result));
RESTORE_ERRORS;
return result;
}

View File

@ -39,7 +39,7 @@ typedef struct DIR {
HANDLE h;
WIN32_FIND_DATA FindFileData;
dirent de;
char *vname_list;
TCHAR *vname_list;
} DIR;
// emulated

View File

@ -24,7 +24,7 @@
#include <stdlib.h>
#include <string>
using std::string;
typedef std::basic_string<TCHAR> tstring;
#include "prefs.h"
@ -58,9 +58,9 @@ prefs_desc platform_prefs_items[] = {
// Prefs file name and path
const char PREFS_FILE_NAME[] = "BasiliskII_prefs";
string UserPrefsPath;
static string prefs_path;
const TCHAR PREFS_FILE_NAME[] = TEXT("BasiliskII_prefs");
tstring UserPrefsPath;
static tstring prefs_path;
/*
@ -72,16 +72,15 @@ void LoadPrefs(const char *vmdir)
// Construct prefs path
if (UserPrefsPath.empty()) {
int pwd_len = GetCurrentDirectory(0, NULL);
char *pwd = new char[pwd_len];
if (GetCurrentDirectory(pwd_len, pwd) == pwd_len - 1)
prefs_path = string(pwd) + '\\';
delete[] pwd;
prefs_path.resize(pwd_len);
pwd_len = GetCurrentDirectory(pwd_len, &prefs_path.front());
prefs_path[pwd_len] = TEXT('\\');
prefs_path += PREFS_FILE_NAME;
} else
prefs_path = UserPrefsPath;
// Read preferences from settings file
FILE *f = fopen(prefs_path.c_str(), "r");
FILE *f = _tfopen(prefs_path.c_str(), TEXT("r"));
if (f != NULL) {
// Prefs file found, load settings
@ -103,7 +102,7 @@ void LoadPrefs(const char *vmdir)
void SavePrefs(void)
{
FILE *f;
if ((f = fopen(prefs_path.c_str(), "w")) != NULL) {
if ((f = _tfopen(prefs_path.c_str(), TEXT("w"))) != NULL) {
SavePrefsToStream(f);
fclose(f);
}

View File

@ -21,6 +21,7 @@
*/
#include "sysdeps.h"
#include "main.h"
#include "cpu_emulation.h"
#include "prefs.h"
#include "ether_windows.h"

View File

@ -21,6 +21,7 @@
*/
#include "sysdeps.h"
#include "main.h"
#include "dump.h"
#if DEBUG

View File

@ -21,6 +21,7 @@
*/
#include "sysdeps.h"
#include "main.h"
#include "dynsockets.h"
#include "dump.h"
#include "main.h"
@ -40,7 +41,7 @@
Win95 b2 users who can't (or won't) upgrade.
*/
static const char *wslib = "WS2_32.DLL";
static LPCTSTR wslib = TEXT("WS2_32.DLL");
static HMODULE hWinsock32 = 0;
static WSADATA WSAData;

View File

@ -21,6 +21,7 @@
*/
#include "sysdeps.h"
#include "main.h"
#include <ctype.h>
#include "dump.h"
#include "prefs.h"

View File

@ -21,6 +21,7 @@
*/
#include "sysdeps.h"
#include "main.h"
#include "cpu_emulation.h"
#include "ws2tcpip.h"
#include "prefs.h"

View File

@ -21,6 +21,7 @@
*/
#include "sysdeps.h"
#include "main.h"
#include "cpu_emulation.h"
#include "ether_windows.h"
#include "ether.h"

View File

@ -21,6 +21,7 @@
*/
#include "sysdeps.h"
#include "main.h"
#include "cpu_emulation.h"
#include "ws2tcpip.h"
#include "prefs.h"

View File

@ -21,6 +21,7 @@
*/
#include "sysdeps.h"
#include "main.h"
#include "interfaces.h"
#include "../dump.h"
#include "mibaccess.h"

View File

@ -61,6 +61,7 @@
#include "sysdeps.h"
#include "main.h"
#include "mibaccess.h"
#include "../dynsockets.h"
#include "../dump.h"
@ -71,9 +72,8 @@
#include "debug.h"
MibExtLoad::MibExtLoad( LPSTR MibDllName, LPSTR SnmpDllName )
MibExtLoad::MibExtLoad( LPCTSTR MibDllName, LPCTSTR SnmpDllName )
{
m_Init = NULL;
m_InitEx = NULL;
@ -88,10 +88,10 @@ MibExtLoad::MibExtLoad( LPSTR MibDllName, LPSTR SnmpDllName )
m_hInst = LoadLibrary( MibDllName );
if(!m_hInst) {
D(bug("MIB: library %s could not be loaded.\r\n", MibDllName));
D(bug(TEXT("MIB: library %s could not be loaded.\r\n"), MibDllName));
return;
}
D(bug("MIB: library %s loaded ok.\r\n", MibDllName));
D(bug(TEXT("MIB: library %s loaded ok.\r\n"), MibDllName));
m_Init = (pSnmpExtensionInit)GetProcAddress(m_hInst ,"SnmpExtensionInit");
m_InitEx= (pSnmpExtensionInitEx)GetProcAddress(m_hInst ,"SnmpExtensionInitEx");
@ -100,19 +100,19 @@ MibExtLoad::MibExtLoad( LPSTR MibDllName, LPSTR SnmpDllName )
if( !m_Init || !m_InitEx || !m_Query || !m_Trap )
{
D(bug("MIB: required entry points not found in library %s.\r\n", MibDllName));
D(bug(TEXT("MIB: required entry points not found in library %s.\r\n"), MibDllName));
FreeLibrary( m_hInst );
m_hInst = NULL;
}
m_hInst_snmputil = LoadLibrary( SnmpDllName );
if(!m_hInst_snmputil){
D(bug("MIB: library %s could not be loaded.\r\n", SnmpDllName));
D(bug(TEXT("MIB: library %s could not be loaded.\r\n"), SnmpDllName));
FreeLibrary( m_hInst );
m_hInst = NULL;
return;
}
D(bug("MIB: library %s loaded ok.\r\n", SnmpDllName));
D(bug(TEXT("MIB: library %s loaded ok.\r\n"), SnmpDllName));
m_SnmpUtilVarBindFree = (VOID (SNMP_FUNC_TYPE *)(SnmpVarBind *))GetProcAddress( m_hInst_snmputil, "SnmpUtilVarBindFree" );
m_SnmpUtilOidNCmp = (SNMPAPI (SNMP_FUNC_TYPE *)(AsnObjectIdentifier *, AsnObjectIdentifier *, UINT))GetProcAddress( m_hInst_snmputil, "SnmpUtilOidNCmp" );
@ -120,7 +120,7 @@ MibExtLoad::MibExtLoad( LPSTR MibDllName, LPSTR SnmpDllName )
if( !m_SnmpUtilVarBindFree || !m_SnmpUtilOidNCmp || !m_SnmpUtilOidCpy )
{
D(bug("MIB: required entry points not found in library %s.\r\n", SnmpDllName));
D(bug(TEXT("MIB: required entry points not found in library %s.\r\n"), SnmpDllName));
FreeLibrary( m_hInst );
FreeLibrary( m_hInst_snmputil );
m_hInst = NULL;
@ -181,7 +181,7 @@ BOOL MibExtLoad::Trap(AsnObjectIdentifier *enterprise, AsnInteger *genericTrap,
return FALSE;
}
MibII::MibII( bool load_winsock ):MibExtLoad("inetmib1.dll","snmpapi.dll")
MibII::MibII(bool load_winsock) : MibExtLoad(TEXT("inetmib1.dll"), TEXT("snmpapi.dll"))
{
WSADATA wsa;
m_load_winsock = load_winsock;

View File

@ -38,7 +38,7 @@ typedef BOOL (WINAPI *pSnmpExtensionInitEx)(OUT AsnObjectIdentifier *supportedVi
class MibExtLoad
{
public:
MibExtLoad( LPSTR MibDllName, LPSTR SnmpDllName );
MibExtLoad( LPCTSTR MibDllName, LPCTSTR SnmpDllName );
~MibExtLoad();
BOOL Init(DWORD dwTimeZeroReference,HANDLE *hPollForTrapEvent,AsnObjectIdentifier *supportedView);
BOOL InitEx(AsnObjectIdentifier *supportedView);

View File

@ -27,6 +27,7 @@
*/
#include "sysdeps.h"
#include "main.h"
#include <process.h>

View File

@ -66,6 +66,7 @@
*/
#include "sysdeps.h"
#include "main.h"
#include <process.h>

View File

@ -21,6 +21,7 @@
*/
#include "sysdeps.h"
#include "main.h"
#include "cpu_emulation.h"
#include "prefs.h"
#include "ether_windows.h"

View File

@ -27,6 +27,7 @@
#include <process.h>
#include "main.h"
#include "util_windows.h"
#include "macos_util.h"
#include "prefs.h"
#include "serial.h"
@ -38,7 +39,7 @@
#undef OutputDebugString
#define OutputDebugString serial_log_write
static void serial_log_write( char *s );
#define SERIAL_LOG_FILE_NAME "serial.log"
#define SERIAL_LOG_FILE_NAME TEXT("serial.log")
#include "debug.h"
#undef D
#define D(x) if(debug_serial != DB_SERIAL_NONE) (x);
@ -54,7 +55,7 @@ static int16 debug_serial = DB_SERIAL_NONE;
static HANDLE serial_log_file = INVALID_HANDLE_VALUE;
static void serial_log_open( char *path )
static void serial_log_open( LPCTSTR path )
{
if(debug_serial == DB_SERIAL_NONE) return;
@ -108,28 +109,27 @@ static void serial_log_write( char *s )
// Driver private variables
class XSERDPort : public SERDPort {
public:
XSERDPort(const char *dev, const char *suffix)
XSERDPort(LPCTSTR dev, LPCTSTR suffix)
{
D(bug("XSERDPort constructor %s\r\n", dev));
// device_name = (char *)dev;
D(bug(TEXT("XSERDPort constructor %s\r\n"), dev));
read_pending = write_pending = false;
if(dev)
strcpy( device_name, (char *)dev );
_tcscpy( device_name, dev );
else
*device_name = 0;
strupr(device_name);
is_parallel = (strncmp(device_name,"LPT",3) == 0);
is_file = (strncmp(device_name,"FILE",4) == 0);
_tcsupr(device_name);
is_parallel = (_tcsncmp(device_name, TEXT("LPT"), 3) == 0);
is_file = (_tcsncmp(device_name, TEXT("FILE"), 4) == 0);
if(is_file) {
char entry_name[20];
wsprintf( entry_name, "portfile%s", suffix );
_snprintf( entry_name, lengthof(entry_name), "portfile%s", str(suffix).get() );
const char *path = PrefsFindString(entry_name);
if(path) {
strcpy( output_file_name, path );
_tcscpy( output_file_name, tstr(path).get() );
} else {
strcpy( output_file_name, "C:\\B2TEMP.OUT" );
_tcscpy( output_file_name, TEXT("C:\\B2TEMP.OUT") );
}
}
@ -171,7 +171,7 @@ private:
static int acknowledge_error(HANDLE h, bool is_read);
bool set_timeouts(int bauds, int parity_bits, int stop_bits);
char device_name[256];
TCHAR device_name[256];
HANDLE fd;
bool io_killed; // Flag: KillIO called, I/O threads must not call deferred tasks
@ -193,7 +193,7 @@ private:
bool is_parallel; // true if LPTx
bool is_file; // true if FILE
char output_file_name[256];
TCHAR output_file_name[256];
};
/*
@ -214,13 +214,13 @@ void SerialInit(void)
if(port) {
D(bug("SerialInit seriala=%s\r\n",port));
}
the_serd_port[0] = new XSERDPort(port,"0");
the_serd_port[0] = new XSERDPort(tstr(port).get(), TEXT("0"));
port = PrefsFindString("serialb");
if(port) {
D(bug("SerialInit serialb=%s\r\n",port));
}
the_serd_port[1] = new XSERDPort(port,"1");
the_serd_port[1] = new XSERDPort(tstr(port).get(), TEXT("1"));
}
@ -249,7 +249,7 @@ int16 XSERDPort::open(uint16 config)
if (!device_name || !*device_name)
return openErr;
D(bug("XSERDPort::open device=%s,config=0x%X\r\n",device_name,(int)config));
D(bug(TEXT("XSERDPort::open device=%s,config=0x%X\r\n"),device_name,(int)config));
// Init variables
io_killed = false;
@ -268,7 +268,7 @@ int16 XSERDPort::open(uint16 config)
}
if(fd == INVALID_HANDLE_VALUE) {
goto open_error;
D(bug("XSERDPort::open failed to open port %s\r\n",device_name));
D(bug(TEXT("XSERDPort::open failed to open port %s\r\n"),device_name));
}
if(is_serial) {
@ -1046,7 +1046,7 @@ unsigned int XSERDPort::input_func(void *arg)
set_desktop();
#endif
D(bug("XSERDPort::input_func started for device %s\r\n",s->device_name));
D(bug(TEXT("XSERDPort::input_func started for device %s\r\n"),s->device_name));
for (;;) {
@ -1131,7 +1131,7 @@ unsigned int XSERDPort::output_func(void *arg)
set_desktop();
#endif
D(bug("XSERDPort::output_func started for device %s\r\n",s->device_name));
D(bug(TEXT("XSERDPort::output_func started for device %s\r\n"),s->device_name));
for (;;) {

View File

@ -23,12 +23,13 @@
#include <winioctl.h>
#include <string>
using std::string;
typedef std::basic_string<TCHAR> tstring;
#include <algorithm>
using std::min;
#include "main.h"
#include "util_windows.h"
#include "macos_util.h"
#include "prefs.h"
#include "user_strings.h"
@ -45,7 +46,7 @@ using std::min;
// File handles are pointers to these structures
struct file_handle {
char *name; // Copy of device/file name
TCHAR *name; // Copy of device/file name
HANDLE fh;
bool is_file; // Flag: plain file or physical device?
bool is_floppy; // Flag: floppy device
@ -149,8 +150,8 @@ void mount_removable_media(int media)
CloseHandle(fh->fh);
// Re-open device
char device_name[MAX_PATH];
sprintf(device_name, "\\\\.\\%c:", fh->name[0]);
TCHAR device_name[MAX_PATH];
_sntprintf(device_name, lengthof(device_name), TEXT("\\\\.\\%c:"), fh->name[0]);
fh->fh = CreateFile(
device_name,
GENERIC_READ,
@ -230,11 +231,10 @@ void SysAddCDROMPrefs(void)
if (PrefsFindBool("nocdrom"))
return;
for (char letter = 'C'; letter <= 'Z'; letter++) {
int i = (int)(letter - 'A');
string rootdir = letter + ":\\";
if (GetDriveType(rootdir.c_str()) == DRIVE_CDROM)
PrefsAddString("cdrom", rootdir.c_str());
char rootdir[] = "C:\\";
for (; rootdir[0] <= 'Z'; rootdir[0]++) {
if (GetDriveTypeA(rootdir) == DRIVE_CDROM)
PrefsAddString("cdrom", rootdir);
}
}
@ -395,9 +395,9 @@ static bool is_cdrom_readable(file_handle *fh)
* Check if NAME represents a read-only file
*/
static bool is_read_only_path(const char *name)
static bool is_read_only_path(const TCHAR *name)
{
DWORD attrib = GetFileAttributes((char *)name);
DWORD attrib = GetFileAttributes(name);
return (attrib != INVALID_FILE_ATTRIBUTES && ((attrib & FILE_ATTRIBUTE_READONLY) != 0));
}
@ -411,25 +411,25 @@ void *Sys_open(const char *path_name, bool read_only)
file_handle * fh = NULL;
// Parse path name and options
char name[MAX_PATH];
strcpy(name, path_name);
TCHAR name[MAX_PATH];
tcslcpy(name, path_name, lengthof(name));
// Normalize floppy / cd path
int name_len = strlen(name);
if (name_len == 1 && isalpha(name[0]))
strcat(name, ":\\");
if (name_len > 0 && name[name_len - 1] == ':')
strcat(name, "\\");
name_len = strlen(name);
int name_len = _tcslen(name);
if (name_len == 1 && _istalpha(name[0]))
_tcscat(name, TEXT(":\\"));
if (name_len > 0 && name[name_len - 1] == TEXT(':'))
_tcscat(name, TEXT("\\"));
name_len = _tcslen(name);
D(bug("Sys_open(%s, %s)\n", name, read_only ? "read-only" : "read/write"));
if (name_len > 0 && name[name_len - 1] == '\\') {
D(bug(TEXT("Sys_open(%s, %s)\n"), name, read_only ? TEXT("read-only") : TEXT("read/write")));
if (name_len > 0 && name[name_len - 1] == TEXT('\\')) {
int type = GetDriveType(name);
if (type == DRIVE_CDROM) {
read_only = true;
char device_name[MAX_PATH];
sprintf(device_name, "\\\\.\\%c:", name[0]);
TCHAR device_name[MAX_PATH];
_sntprintf(device_name, lengthof(device_name), TEXT("\\\\.\\%c:"), name[0]);
// Open device
HANDLE h = CreateFile(
@ -439,7 +439,7 @@ void *Sys_open(const char *path_name, bool read_only)
if (h != INVALID_HANDLE_VALUE) {
fh = new file_handle;
fh->name = strdup(name);
fh->name = _tcsdup(name);
fh->fh = h;
fh->is_file = false;
fh->read_only = read_only;
@ -478,7 +478,7 @@ void *Sys_open(const char *path_name, bool read_only)
if (h != INVALID_HANDLE_VALUE) {
fh = new file_handle;
fh->name = strdup(name);
fh->name = _tcsdup(name);
fh->fh = h;
fh->is_file = true;
fh->read_only = read_only;

View File

@ -40,6 +40,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
#include <time.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

View File

@ -88,7 +88,7 @@ static const char *get_volume_name(void)
// Try Windows 2000 key first
if (ERROR_SUCCESS == RegOpenKey(
HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CLSID\\{20D04FE0-3AEA-1069-A2D8-08002B30309D}",
TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CLSID\\{20D04FE0-3AEA-1069-A2D8-08002B30309D}"),
&hHelpKey))
{
cbData = sizeof(volume);
@ -99,7 +99,7 @@ static const char *get_volume_name(void)
if (volume[0] == 0 &&
ERROR_SUCCESS == RegOpenKey(
HKEY_CURRENT_USER,
"Software\\Classes\\CLSID\\{20D04FE0-3AEA-1069-A2D8-08002B30309D}",
TEXT("Software\\Classes\\CLSID\\{20D04FE0-3AEA-1069-A2D8-08002B30309D}"),
&hHelpKey))
{
cbData = sizeof(volume);
@ -110,7 +110,7 @@ static const char *get_volume_name(void)
if (volume[0] == 0 &&
ERROR_SUCCESS == RegOpenKey(
HKEY_CLASSES_ROOT,
"CLSID\\{20D04FE0-3AEA-1069-A2D8-08002B30309D}",
TEXT("CLSID\\{20D04FE0-3AEA-1069-A2D8-08002B30309D}"),
&hHelpKey))
{
cbData = sizeof(volume);
@ -119,7 +119,7 @@ static const char *get_volume_name(void)
}
// Fix the error that some "tweak" apps do.
if (stricmp(volume, "%USERNAME% on %COMPUTER%") == 0)
if (_stricmp(volume, "%USERNAME% on %COMPUTER%") == 0)
volume[0] = '\0';
// No volume name found, default to "My Computer"
@ -159,3 +159,21 @@ const char *GetString(int num)
}
return NULL;
}
/*
* Convert text to wide string, given the string number
*/
std::unique_ptr<wchar_t[]> GetStringW(int num)
{
auto str = GetString(num);
if (str == nullptr)
return nullptr;
auto length = MultiByteToWideChar(CP_ACP, 0, str, -1, nullptr, 0);
if (length == 0)
return nullptr;
auto p = std::unique_ptr<wchar_t[]>(new wchar_t[length]);
MultiByteToWideChar(CP_ACP, 0, str, -1, p.get(), length);
return p;
}

View File

@ -1,5 +1,5 @@
/*
* user_strings_unix.h - Unix-specific localizable strings
* user_strings_windows.h - Windows-specific localizable strings
*
* Basilisk II (C) 1997-2008 Christian Bauer
*
@ -18,8 +18,17 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef USER_STRINGS_UNIX_H
#define USER_STRINGS_UNIX_H
#ifndef USER_STRINGS_WINDOWS_H
#define USER_STRINGS_WINDOWS_H
#ifdef __cplusplus
#if __cplusplus >= 201103L || _MSC_VER >= 1600
#include <memory>
// Convert text to wide string, given the string number
extern std::unique_ptr<wchar_t[]> GetStringW(int num);
#endif
#endif
enum {
STR_NO_XVISUAL_ERR = 10000,

View File

@ -31,13 +31,143 @@ using std::list;
#include <string>
using std::string;
using std::wstring;
typedef std::basic_string<TCHAR> tstring;
BOOL exists( const char *path )
std::unique_ptr<char[]> str(const wchar_t* s)
{
auto length = WideCharToMultiByte(CP_ACP, 0, s, -1, nullptr, 0, nullptr, nullptr);
if (length == -1)
return nullptr;
std::unique_ptr<char[]> p(new char[length]);
WideCharToMultiByte(CP_ACP, 0, s, -1, p.get(), length, nullptr, nullptr);
return p;
}
std::unique_ptr<wchar_t[]> wstr(const char* s)
{
auto length = MultiByteToWideChar(CP_ACP, 0, s, -1, nullptr, 0);
if (length == -1)
return nullptr;
std::unique_ptr<wchar_t[]> p(new wchar_t[length]);
MultiByteToWideChar(CP_ACP, 0, s, -1, p.get(), length);
return p;
}
string to_string(const wchar_t* s)
{
auto wlen = wcslen(s); // length without null terminator
auto len = WideCharToMultiByte(CP_ACP, 0, s, wlen, nullptr, 0, nullptr, nullptr);
if (len == -1)
return string();
string str(len, '\0');
WideCharToMultiByte(CP_ACP, 0, s, wlen, &str.front(), len, nullptr, nullptr);
return str;
}
wstring to_wstring(const char* s)
{
auto len = strlen(s); // length without null terminator
auto wlen = MultiByteToWideChar(CP_ACP, 0, s, len, nullptr, 0);
if (len == -1)
return wstring();
wstring str(wlen, L'\0');
MultiByteToWideChar(CP_ACP, 0, s, len, &str.front(), wlen);
return str;
}
size_t strlcpy(char* dst, const char* src, size_t size)
{
size_t length = strlen(src);
if (size-- > 0) {
if (length < size)
size = length;
memcpy(dst, src, size);
dst[size] = '\0';
}
return length;
}
size_t strlcpy(char* dst, const wchar_t* src, size_t size)
{
size_t length = WideCharToMultiByte(CP_ACP, 0, src, -1, dst, size, nullptr, nullptr);
if (size > 0) {
if (length == 0)
return strlcpy(dst, str(src).get(), size);
--length;
}
return length;
}
size_t strlcat(char* dst, const char* src, size_t size)
{
char* end = static_cast<char*>(memchr(dst, '\0', size));
if (end == nullptr)
return size;
size_t length = end - dst;
return length + strlcpy(end, src, size - length);
}
size_t strlcat(char* dst, const wchar_t* src, size_t size)
{
char* end = static_cast<char*>(memchr(dst, '\0', size));
if (end == nullptr)
return size;
size_t length = end - dst;
return length + strlcpy(end, src, size - length);
}
size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t size)
{
size_t length = wcslen(src);
if (size-- > 0) {
if (length < size)
size = length;
wmemcpy(dst, src, size);
dst[size] = '\0';
}
return length;
}
size_t wcslcpy(wchar_t* dst, const char* src, size_t size)
{
size_t length = MultiByteToWideChar(CP_ACP, 0, src, -1, dst, size);
if (size > 0) {
if (length == 0)
return wcslcpy(dst, wstr(src).get(), size);
--length;
}
return length;
}
size_t wcslcat(wchar_t* dst, const wchar_t* src, size_t size)
{
wchar_t* end = wmemchr(dst, L'\0', size);
if (end == nullptr)
return size;
size_t length = end - dst;
return length + wcslcpy(end, src, size - length);
}
size_t wcslcat(wchar_t* dst, const char* src, size_t size)
{
wchar_t* end = wmemchr(dst, L'\0', size);
if (end == nullptr)
return size;
size_t length = end - dst;
return length + wcslcpy(end, src, size - length);
}
BOOL exists( const TCHAR *path )
{
HFILE h;
bool ret = false;
h = _open( path, _O_RDONLY | _O_BINARY );
h = _topen( path, _O_RDONLY | _O_BINARY );
if(h != -1) {
ret = true;
_close(h);
@ -45,7 +175,7 @@ BOOL exists( const char *path )
return(ret);
}
BOOL create_file( const char *path, DWORD size )
BOOL create_file( const TCHAR *path, DWORD size )
{
HANDLE h;
bool ok = false;
@ -80,7 +210,7 @@ BOOL create_file( const char *path, DWORD size )
return(ok);
}
int32 get_file_size( const char *path )
int32 get_file_size( const TCHAR *path )
{
HANDLE h;
DWORD size = 0;
@ -125,22 +255,22 @@ void kill_thread(HANDLE thread)
bool check_drivers(void)
{
char path[_MAX_PATH];
GetSystemDirectory(path, sizeof(path));
strcat(path, "\\drivers\\cdenable.sys");
TCHAR path[_MAX_PATH];
GetSystemDirectory(path, lengthof(path));
_tcscat(path, TEXT("\\drivers\\cdenable.sys"));
if (exists(path)) {
int32 size = get_file_size(path);
if (size != 6112) {
char str[256];
sprintf(str, "The CD-ROM driver file \"%s\" is too old or corrupted.", path);
TCHAR str[256];
_sntprintf(str, lengthof(str), TEXT("The CD-ROM driver file \"%s\" is too old or corrupted."), path);
ErrorAlert(str);
return false;
}
}
else {
char str[256];
sprintf(str, "The CD-ROM driver file \"%s\" is missing.", path);
TCHAR str[256];
_sntprintf(str, lengthof(str), TEXT("The CD-ROM driver file \"%s\" is missing."), path);
WarningAlert(str);
}
@ -153,15 +283,15 @@ bool check_drivers(void)
*/
struct panel_reg {
string name;
string guid;
tstring name;
tstring guid;
};
static list<panel_reg> network_registry;
typedef list<panel_reg>::const_iterator network_registry_iterator;
#define NETWORK_CONNECTIONS_KEY \
"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
TEXT("SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}")
static void get_network_registry(void)
{
@ -184,14 +314,14 @@ static void get_network_registry(void)
return;
while (true) {
char enum_name[256];
char connection_string[256];
TCHAR enum_name[256];
TCHAR connection_string[256];
HKEY connection_key;
char name_data[256];
TCHAR name_data[256];
DWORD name_type;
const char name_string[] = "Name";
const TCHAR name_string[] = TEXT("Name");
len = sizeof (enum_name);
len = lengthof(enum_name);
status = RegEnumKeyEx(
network_connections_key,
i,
@ -204,8 +334,8 @@ static void get_network_registry(void)
if (status != ERROR_SUCCESS)
break;
snprintf (connection_string, sizeof(connection_string),
"%s\\%s\\Connection",
_sntprintf (connection_string, lengthof(connection_string),
TEXT("%s\\%s\\Connection"),
NETWORK_CONNECTIONS_KEY, enum_name);
status = RegOpenKeyEx(
@ -216,7 +346,7 @@ static void get_network_registry(void)
&connection_key);
if (status == ERROR_SUCCESS) {
len = sizeof (name_data);
len = lengthof(name_data);
status = RegQueryValueEx(
connection_key,
name_string,
@ -239,24 +369,24 @@ static void get_network_registry(void)
RegCloseKey (network_connections_key);
}
const char *ether_name_to_guid(const char *name)
const TCHAR *ether_name_to_guid(const TCHAR *name)
{
get_network_registry();
for (network_registry_iterator it = network_registry.begin(); it != network_registry.end(); it++) {
if (strcmp((*it).name.c_str(), name) == 0)
if (_tcscmp((*it).name.c_str(), name) == 0)
return (*it).guid.c_str();
}
return NULL;
}
const char *ether_guid_to_name(const char *guid)
const TCHAR *ether_guid_to_name(const TCHAR *guid)
{
get_network_registry();
for (network_registry_iterator it = network_registry.begin(); it != network_registry.end(); it++) {
if (strcmp((*it).guid.c_str(), guid) == 0)
if (_tcscmp((*it).guid.c_str(), guid) == 0)
return (*it).name.c_str();
}
@ -268,11 +398,11 @@ const char *ether_guid_to_name(const char *guid)
* Get TAP-Win32 adapters
*/
#define ADAPTER_KEY "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
#define ADAPTER_KEY TEXT("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}")
#define TAP_COMPONENT_ID "tap0801"
#define TAP_COMPONENT_ID TEXT("tap0801")
const char *ether_tap_devices(void)
const TCHAR *ether_tap_devices(void)
{
HKEY adapter_key;
LONG status;
@ -289,19 +419,19 @@ const char *ether_tap_devices(void)
if (status != ERROR_SUCCESS)
return NULL;
list<string> devices;
list<tstring> devices;
while (true) {
char enum_name[256];
char unit_string[256];
TCHAR enum_name[256];
TCHAR unit_string[256];
HKEY unit_key;
char component_id_string[] = "ComponentId";
char component_id[256];
char net_cfg_instance_id_string[] = "NetCfgInstanceId";
char net_cfg_instance_id[256];
TCHAR component_id_string[] = TEXT("ComponentId");
TCHAR component_id[256];
TCHAR net_cfg_instance_id_string[] = TEXT("NetCfgInstanceId");
TCHAR net_cfg_instance_id[256];
DWORD data_type;
len = sizeof (enum_name);
len = lengthof(enum_name);
status = RegEnumKeyEx(
adapter_key,
i,
@ -314,7 +444,7 @@ const char *ether_tap_devices(void)
if (status != ERROR_SUCCESS)
break;
snprintf (unit_string, sizeof(unit_string), "%s\\%s",
_sntprintf (unit_string, lengthof(unit_string), TEXT("%s\\%s"),
ADAPTER_KEY, enum_name);
status = RegOpenKeyEx(
@ -325,7 +455,7 @@ const char *ether_tap_devices(void)
&unit_key);
if (status == ERROR_SUCCESS) {
len = sizeof (component_id);
len = lengthof(component_id);
status = RegQueryValueEx(
unit_key,
component_id_string,
@ -335,7 +465,7 @@ const char *ether_tap_devices(void)
&len);
if (status == ERROR_SUCCESS && data_type == REG_SZ) {
len = sizeof (net_cfg_instance_id);
len = lengthof(net_cfg_instance_id);
status = RegQueryValueEx(
unit_key,
net_cfg_instance_id_string,
@ -345,7 +475,7 @@ const char *ether_tap_devices(void)
&len);
if (status == ERROR_SUCCESS && data_type == REG_SZ) {
if (!strcmp (component_id, TAP_COMPONENT_ID))
if (!_tcscmp (component_id, TAP_COMPONENT_ID))
devices.push_back(net_cfg_instance_id);
}
}
@ -360,17 +490,17 @@ const char *ether_tap_devices(void)
return NULL;
// The result is a '\0' separated list of strings
list<string>::const_iterator it;
list<tstring>::const_iterator it;
len = 0;
for (it = devices.begin(); it != devices.end(); it++)
len += (*it).length() + 1;
char *names = (char *)malloc(len);
TCHAR *names = (TCHAR *)malloc(len * sizeof(TCHAR));
if (names) {
char *p = names;
TCHAR *p = names;
for (it = devices.begin(); it != devices.end(); it++) {
len = (*it).length();
strcpy(p, (*it).c_str());
_tcscpy(p, (*it).c_str());
p[len] = '\0';
p += len + 1;
}

View File

@ -23,9 +23,12 @@
#ifndef _UTIL_WINDOWS_H
#define _UTIL_WINDOWS_H
BOOL exists( const char *path );
int32 get_file_size( const char *path );
BOOL create_file( const char *path, DWORD size );
#include <memory>
#include <string>
BOOL exists( const TCHAR *path );
int32 get_file_size( const TCHAR *path );
BOOL create_file( const TCHAR *path, DWORD size );
bool check_drivers(void);
// Thread wrappers
@ -44,10 +47,79 @@ class mutex_t {
};
// Network control panel helpers
extern const char *ether_name_to_guid(const char *name);
extern const char *ether_guid_to_name(const char *guid);
extern const TCHAR *ether_name_to_guid(const TCHAR *name);
extern const TCHAR *ether_guid_to_name(const TCHAR *guid);
// Get TAP-Win32 devices (caller free()s returned buffer)
extern const char *ether_tap_devices(void);
extern const TCHAR *ether_tap_devices(void);
// Wide string versions of commonly used functions
extern void ErrorAlert(const wchar_t *text);
extern void WarningAlert(const wchar_t *text);
// ----------------- String conversion functions -----------------
// Null deleter -- does nothing. Allows returning a non-owning
// unique_ptr. This should go away if observer_ptr makes it into
// the standard.
template <class T> struct null_delete {
constexpr null_delete() noexcept = default;
template <class U> null_delete(const null_delete<U>&) noexcept { }
void operator ()(T*) const noexcept { }
};
template <class T> struct null_delete<T[]> {
constexpr null_delete() noexcept = default;
void operator ()(T*) const noexcept { }
template <class U> void operator ()(U*) const = delete;
};
// Functions returning null-terminated C strings
std::unique_ptr<char[]> str(const wchar_t* s);
std::unique_ptr<wchar_t[]> wstr(const char* s);
inline std::unique_ptr<const char[], null_delete<const char[]>> str(const char* s)
{
return std::unique_ptr<const char[], null_delete<const char[]>>(s);
}
inline std::unique_ptr<const wchar_t[], null_delete<const wchar_t[]>> wstr(const wchar_t* s)
{
return std::unique_ptr<const wchar_t[], null_delete<const wchar_t[]>>(s);
}
#ifdef _UNICODE
#define tstr wstr
#else
#define tstr str
#endif
// Functions returning std::strings
std::string to_string(const wchar_t* s);
std::wstring to_wstring(const char* s);
inline std::string to_string(const char* s) { return std::string(s); }
inline std::wstring to_wstring(const wchar_t* s) { return std::wstring(s); }
#ifdef _UNICODE
#define to_tstring to_wstring
#else
#define to_tstring to_string
#endif
// BSD strlcpy/strlcat with overloads for converting between wide and narrow strings
size_t strlcpy(char* dst, const char* src, size_t size);
size_t strlcpy(char* dst, const wchar_t* src, size_t size);
size_t strlcat(char* dst, const char* src, size_t size);
size_t strlcat(char* dst, const wchar_t* src, size_t size);
size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t size);
size_t wcslcpy(wchar_t* dst, const char* src, size_t size);
size_t wcslcat(wchar_t* dst, const wchar_t* src, size_t size);
size_t wcslcat(wchar_t* dst, const char* src, size_t size);
#ifdef _UNICODE
#define tcslcpy wcslcpy
#define tcslcat wcslcat
#else
#define tcslcpy strlcpy
#define tcslcat strlcat
#endif
#endif // _UTIL_WINDOWS_H

View File

@ -21,18 +21,18 @@
#include "sysdeps.h"
#include <string>
using std::string;
typedef std::basic_string<TCHAR> tstring;
#include "xpram.h"
// XPRAM file name and path
#if POWERPC_ROM
const char XPRAM_FILE_NAME[] = "SheepShaver_nvram.dat";
const TCHAR XPRAM_FILE_NAME[] = TEXT("SheepShaver_nvram.dat");
#else
const char XPRAM_FILE_NAME[] = "BasiliskII_xpram.dat";
const TCHAR XPRAM_FILE_NAME[] = TEXT("BasiliskII_xpram.dat");
#endif
static string xpram_path;
static tstring xpram_path;
/*
@ -43,9 +43,9 @@ static void build_xpram_path(void)
{
xpram_path.clear();
int pwd_len = GetCurrentDirectory(0, NULL);
char *pwd = new char[pwd_len];
TCHAR *pwd = new TCHAR[pwd_len];
if (GetCurrentDirectory(pwd_len, pwd) == pwd_len - 1)
xpram_path = string(pwd) + '\\';
xpram_path = tstring(pwd) + TEXT('\\');
delete[] pwd;
xpram_path += XPRAM_FILE_NAME;
}

View File

@ -19,6 +19,7 @@
*/
#include "sysdeps.h"
#include "main.h"
#include "scsi.h"
#define DEBUG 0

View File

@ -30,24 +30,62 @@
#include <sys/types.h>
#include <sys/timeb.h>
static void _cdecl inline winbug( char *s, ...)
static inline void _cdecl vwinbug(const char *s, va_list vargs)
{
va_list vargs;
char msg[1024], date[50], hours[50];
struct _timeb tstruct;
_ftime( &tstruct );
_strtime( hours );
_strdate( date );
sprintf( msg, "B2: %s %s:%03u ", date, hours, tstruct.millitm );
va_start( vargs, s );
vsprintf( &msg[strlen(msg)], s, vargs );
va_end( vargs );
_snprintf( msg, lengthof(msg), "B2: %s %s:%03u ", date, hours, tstruct.millitm );
OutputDebugString(msg);
char *rest = &msg[strlen(msg)];
_vsnprintf( rest, lengthof(msg) - (rest - msg), s, vargs );
OutputDebugStringA(msg);
}
static inline void _cdecl vwwinbug( const wchar_t *s, va_list vargs)
{
wchar_t msg[1024], date[50], hours[50];
struct _timeb tstruct;
_ftime( &tstruct );
_wstrtime( hours );
_wstrdate( date );
_snwprintf( msg, lengthof(msg), L"B2: %s %s:%03u ", date, hours, tstruct.millitm );
wchar_t *rest = &msg[wcslen(msg)];
_vsnwprintf( rest, lengthof(msg) - (rest - msg), s, vargs );
OutputDebugStringW(msg);
}
static inline void _cdecl winbug( const char *s, ...)
{
va_list vargs;
va_start(vargs, s);
vwinbug(s, vargs);
va_end(vargs);
}
static inline void _cdecl wwinbug(const wchar_t *s, ...)
{
va_list vargs;
va_start(vargs, s);
vwwinbug(s, vargs);
va_end(vargs);
}
#ifdef __cplusplus
static inline void _cdecl winbug(wchar_t *s, ...)
{
va_list vargs;
va_start(vargs, s);
vwwinbug(s, vargs);
va_end(vargs);
}
#endif
#define bug winbug
#define wbug wwinbug
#elif defined(AMIGA)