ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Windows/util_windows.cpp
Revision: 1.4
Committed: 2005-03-19T19:01:49Z (19 years, 7 months ago) by gbeauche
Branch: MAIN
CVS Tags: nigel-build-17
Changes since 1.3: +30 -0 lines
Log Message:
Check that drivers are installed (e.g. CD-ROM driver)

File Contents

# User Rev Content
1 gbeauche 1.1 /*
2     * util_windows.cpp - Miscellaneous utilities for Win32
3     *
4 gbeauche 1.3 * Basilisk II (C) 1997-2005 Christian Bauer
5 gbeauche 1.1 *
6     * Windows platform specific code copyright (C) Lauri Pesonen
7     *
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.
12     *
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.
17     *
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
21     */
22    
23     #include "sysdeps.h"
24     #include "util_windows.h"
25 gbeauche 1.4 #include "main.h"
26 gbeauche 1.1
27     BOOL exists( const char *path )
28     {
29     HFILE h;
30     bool ret = false;
31    
32     h = _lopen( path, OF_READ );
33     if(h != HFILE_ERROR) {
34     ret = true;
35     _lclose(h);
36     }
37     return(ret);
38     }
39    
40     BOOL create_file( const char *path, DWORD size )
41     {
42     HANDLE h;
43     bool ok = false;
44    
45     h = CreateFile( path,
46     GENERIC_READ | GENERIC_WRITE,
47     0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL
48     );
49     if(h != INVALID_HANDLE_VALUE) {
50     if(size == 0) {
51     ok = true;
52     } else if(SetFilePointer( h, size, NULL, FILE_BEGIN) != 0xFFFFFFFF) {
53     if(SetEndOfFile(h)) {
54     ok = true;
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);
58     if(b) {
59     memset( b, 0, zeroed_size );
60     WriteFile( h, b, zeroed_size, &written, NULL );
61     free(b);
62     }
63     }
64     }
65     }
66     CloseHandle(h);
67     }
68     if(!ok) DeleteFile(path);
69     return(ok);
70     }
71    
72     int32 get_file_size( const char *path )
73     {
74     HANDLE h;
75     DWORD size = 0;
76    
77     h = CreateFile( path,
78     GENERIC_READ,
79     0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
80     );
81     if(h != INVALID_HANDLE_VALUE) {
82     size = GetFileSize( h, NULL );
83     CloseHandle(h);
84     }
85     return(size);
86     }
87 gbeauche 1.2
88    
89     /*
90     * Thread wrappers
91     */
92    
93     HANDLE create_thread(LPTHREAD_START_ROUTINE start_routine, void *arg)
94     {
95     DWORD dwThreadId;
96     return CreateThread(NULL, 0, start_routine, arg, 0, &dwThreadId);
97     }
98    
99     void wait_thread(HANDLE thread)
100     {
101     WaitForSingleObject(thread, INFINITE);
102     CloseHandle(thread);
103     }
104    
105     void kill_thread(HANDLE thread)
106     {
107     TerminateThread(thread, 0);
108     }
109 gbeauche 1.4
110    
111     /*
112     * Check that drivers are installed
113     */
114    
115     bool check_drivers(void)
116     {
117     char path[_MAX_PATH];
118     GetSystemDirectory(path, sizeof(path));
119     strcat(path, "\\drivers\\cdenable.sys");
120    
121     if (exists(path)) {
122     int32 size = get_file_size(path);
123     if (size != 6112) {
124     char str[256];
125     sprintf(str, "The CD-ROM driver file \"%s\" is too old or corrupted.", path);
126     ErrorAlert(str);
127     return false;
128     }
129     }
130     else {
131     char str[256];
132     sprintf(str, "The CD-ROM driver file \"%s\" is missing.", path);
133     WarningAlert(str);
134     }
135    
136     return true;
137     }