2
* util_windows.cpp - Miscellaneous utilities for Win32
4
* Basilisk II (C) 1997-2005 Christian Bauer
6
* Windows platform specific code copyright (C) Lauri Pesonen
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
#include "util_windows.h"
27
BOOL exists( const char *path )
32
h = _lopen( path, OF_READ );
33
if(h != HFILE_ERROR) {
40
BOOL create_file( const char *path, DWORD size )
46
GENERIC_READ | GENERIC_WRITE,
47
0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL
49
if(h != INVALID_HANDLE_VALUE) {
52
} else if(SetFilePointer( h, size, NULL, FILE_BEGIN) != 0xFFFFFFFF) {
55
if(SetFilePointer( h, 0, NULL, FILE_BEGIN) != 0xFFFFFFFF) {
56
DWORD written, zeroed_size = min(1024*1024,size);
57
char *b = (char *)malloc(zeroed_size);
59
memset( b, 0, zeroed_size );
60
WriteFile( h, b, zeroed_size, &written, NULL );
68
if(!ok) DeleteFile(path);
72
int32 get_file_size( const char *path )
79
0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
81
if(h != INVALID_HANDLE_VALUE) {
82
size = GetFileSize( h, NULL );
93
HANDLE create_thread(LPTHREAD_START_ROUTINE start_routine, void *arg)
96
return CreateThread(NULL, 0, start_routine, arg, 0, &dwThreadId);
99
void wait_thread(HANDLE thread)
101
WaitForSingleObject(thread, INFINITE);
105
void kill_thread(HANDLE thread)
107
TerminateThread(thread, 0);
112
* Check that drivers are installed
115
bool check_drivers(void)
117
char path[_MAX_PATH];
118
GetSystemDirectory(path, sizeof(path));
119
strcat(path, "\\drivers\\cdenable.sys");
122
int32 size = get_file_size(path);
125
sprintf(str, "The CD-ROM driver file \"%s\" is too old or corrupted.", path);
132
sprintf(str, "The CD-ROM driver file \"%s\" is missing.", path);