-
Notifications
You must be signed in to change notification settings - Fork 25
/
filereq_win32.c
180 lines (154 loc) · 4.08 KB
/
filereq_win32.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
** Oricutron
** Copyright (C) 2009-2014 Peter Gordon
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation, version 2
** of the License.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
** Windows file dialog
*/
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#define WANT_WMINFO
#include "system.h"
#include "6502.h"
#include "via.h"
#include "8912.h"
#include "disk.h"
#include "gui.h"
#include "monitor.h"
#include "6551.h"
#include "machine.h"
#include "filereq.h"
SDL_bool init_filerequester( struct machine *oric )
{
return SDL_TRUE;
}
void shut_filerequester( struct machine *oric )
{
}
SDL_bool filerequester( struct machine *oric, char *title, char *path, char *fname, int type )
{
SDL_SysWMinfo wmi;
OPENFILENAME ofn;
HWND hwnd;
char tmp[4096];
int i;
char *odir;
strcpy( tmp, fname );
hwnd = NULL;
SDL_VERSION(&wmi.version);
if (SDL_COMPAT_GetWMInfo(&wmi))
#if SDL_MAJOR_VERSION == 1
hwnd = (HWND)wmi.window;
#else
hwnd = (HWND)wmi.info.win.window;
#endif
ZeroMemory( &ofn, sizeof( ofn ) );
ofn.lStructSize = sizeof( ofn );
ofn.hwndOwner = hwnd;
ofn.lpstrFile = fname;
ofn.nMaxFile = 4096;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
switch( type )
{
case FR_DISKSAVE:
ofn.Flags = OFN_PATHMUSTEXIST;
case FR_DISKLOAD:
ofn.lpstrFilter = "All Files\0*.*\0Disk Images (*.dsk)\0*.DSK\0";
ofn.nFilterIndex = 2;
break;
case FR_TAPESAVETAP:
ofn.Flags = OFN_PATHMUSTEXIST;
ofn.lpstrFilter = "All Files\0*.*\0Tape Images (*.tap)\0*.TAP\0";
ofn.nFilterIndex = 2;
break;
case FR_TAPESAVEORT:
ofn.Flags = OFN_PATHMUSTEXIST;
ofn.lpstrFilter = "All Files\0*.*\0Raw Tape Images (*.ort)\0*.ORT\0";
ofn.nFilterIndex = 2;
break;
case FR_TAPELOAD:
ofn.lpstrFilter = "All Files\0*.*\0Tape Images (*.tap, *.ort, *.wav)\0*.TAP;*.ORT;*.WAV\0";
ofn.nFilterIndex = 2;
break;
case FR_ROMS:
ofn.lpstrFilter = "All Files\0*.*\0Rom Images (*.rom)\0*.ROM\0";
ofn.nFilterIndex = 2;
break;
case FR_SNAPSHOTSAVE:
ofn.Flags = OFN_PATHMUSTEXIST;
case FR_SNAPSHOTLOAD:
ofn.lpstrFilter = "All Files\0*.*\0Snapshot files (*.sna)\0*.SNA\0";
ofn.nFilterIndex = 2;
break;
case FR_KEYMAPPINGSAVE:
ofn.Flags = OFN_PATHMUSTEXIST;
case FR_KEYMAPPINGLOAD:
ofn.lpstrFilter = "All Files\0*.*\0Keyboard Mapping files (*.kma)\0*.KMA\0";
ofn.nFilterIndex = 2;
break;
default:
ofn.lpstrFilter = "All Files\0*.*";
ofn.nFilterIndex = 1;
break;
}
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = path;
odir = getcwd( NULL, 0 );
switch( type )
{
case FR_SNAPSHOTSAVE:
case FR_DISKSAVE:
if( !GetSaveFileName( &ofn ) )
{
chdir( odir );
free( odir );
return SDL_FALSE;
}
break;
default:
if( !GetOpenFileName( &ofn ) )
{
chdir( odir );
free( odir );
return SDL_FALSE;
}
break;
}
chdir( odir );
free( odir );
i = strlen( ofn.lpstrFile );
if( !i ) return SDL_FALSE;
i--;
while( ofn.lpstrFile[i] != PATHSEP )
{
if( i == 0 ) break;
i--;
}
if( ( ofn.lpstrFile[i] == PATHSEP ) && ( i < (strlen(ofn.lpstrFile)-1) ) )
{
ofn.lpstrFile[i] = 0;
strcpy( path, ofn.lpstrFile );
strncpy( fname, &ofn.lpstrFile[i+1], 512 );
fname[511] = 0;
} else {
path[0] = 0;
strncpy( fname, ofn.lpstrFile, 512 );
fname[511] = 0;
}
return SDL_TRUE;
}