-
Notifications
You must be signed in to change notification settings - Fork 1
/
unsfark-win32.c
148 lines (114 loc) · 3.26 KB
/
unsfark-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
#include "unsfark.h"
#include <windows.h>
#include <tchar.h>
static HWND MainWindow;
static const TCHAR Extensions[] = {'s','f','A','r','k',' ','f','i','l','e','s',' ','(','*','.','s','f','a','r','k',')',0,
'*','.','s','f','a','r','k',0,
'A','l','l',' ','f','i','l','e','s',' ','(','*','.','*',')',0,
'*','.','*',0,0};
static const TCHAR Extensions2[] = {'s','f','2',' ','f','i','l','e','s',' ','(','*','.','s','f','2',')',0,
'*','.','s','f','2',0,
'A','l','l',' ','f','i','l','e','s',' ','(','*','.','*',')',0,
'*','.','*',0,0};
static const TCHAR ErrorStr[] = _T("sfArk Error");
static const TCHAR WindowName[] = _T("sfArk Extractor");
static const TCHAR Load[] = _T("sfArk file to convert to soundfont:");
static const TCHAR Save[] = _T("Name of saved soundfont file:");
/***************** init_ofn() ******************
* Initializes the OPENFILENAME struct.
*/
static void init_ofn(OPENFILENAME *ofn, TCHAR * buffer, const TCHAR * extension)
{
// Clear out fields
ZeroMemory(ofn, sizeof(OPENFILENAME));
// Set size
ofn->lStructSize = sizeof(OPENFILENAME);
// Store passed buffer for filename
ofn->lpstrFile = buffer;
ofn->nMaxFile = MAX_PATH;
// Set owner
ofn->hwndOwner = MainWindow;
// Set extensions
ofn->lpstrDefExt = ofn->lpstrFilter = extension;
while (*ofn->lpstrDefExt++);
ofn->lpstrDefExt += 2;
}
/****************** getLoadName() *****************
* Get the user's choice of filename to load,
* and copies it to specified buffer.
*/
static TCHAR * getLoadName(TCHAR * buffer)
{
OPENFILENAME ofn;
// Init OPENFILENAME
init_ofn(&ofn, buffer, &Extensions[0]);
ofn.lpstrFile[0] = 0;
// Set title
ofn.lpstrTitle = &Load[0];
// Set flags
ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_LONGNAMES;
// Present the dialog and get user's selection
return (GetOpenFileName(&ofn) ? buffer : 0);
}
/****************** getSaveName() *****************
* Get the user's choice of filename to save,
* and copies it to specified buffer.
*/
static TCHAR * getSaveName(TCHAR * buffer)
{
OPENFILENAME ofn;
// Init OPENFILENAME
init_ofn(&ofn, buffer, &Extensions2[0]);
// Set title
ofn.lpstrTitle = &Save[0];
// Set flags
ofn.Flags = OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|OFN_LONGNAMES;
// Present the dialog and get user's selection
return (GetOpenFileName(&ofn) ? buffer : 0);
}
int main(int argc, char * argv[])
{
register char * str;
SFARKHANDLE sfark;
MainWindow = 0;
if (!(sfark = SfarkAllocA()))
printf("Not enough RAM!\r\n");
else
{
int errCode;
errCode = 0;
if (argc > 1)
str = argv[1];
else
str = getLoadName(SfarkGetBuffer(sfark));
if (str && !(errCode = SfarkOpen(sfark, str)))
{
if (argc > 2)
str = argv[2];
else
str = getSaveName(SfarkGetBuffer(sfark));
if (str && !(errCode = SfarkBeginExtract(sfark, str)))
{
unsigned char dots;
dots = 0;
do
{
if (dots != SfarkPercent(sfark))
{
printf("*");
++dots;
}
} while (!(errCode = SfarkExtract(sfark)));
if (errCode > 0) errCode = 0;
printf("\r\n");
}
}
str = (char *)SfarkErrMsg(sfark, errCode);
if (errCode)
MessageBoxA(MainWindow, str, &ErrorStr[0], MB_OK|MB_ICONEXCLAMATION);
else
printf("\r\n%s\n", str);
SfarkFree(sfark);
}
return 0;
}