1 |
/* |
2 |
libakai - C++ cross-platform akai sample disk reader |
3 |
Copyright (C) 2002-2003 Sébastien Métrot |
4 |
|
5 |
Linux port by Christian Schoenebeck <cuse@users.sourceforge.net> 2003-2014 |
6 |
|
7 |
This library is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU Lesser General Public |
9 |
License as published by the Free Software Foundation; either |
10 |
version 2.1 of the License, or (at your option) any later version. |
11 |
|
12 |
This library is distributed in the hope that it will be useful, |
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 |
Lesser General Public License for more details. |
16 |
|
17 |
You should have received a copy of the GNU Lesser General Public |
18 |
License along with this library; if not, write to the Free Software |
19 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
*/ |
21 |
// akaidump.cpp : Defines the entry point for the console application. |
22 |
// |
23 |
|
24 |
#ifdef HAVE_CONFIG_H |
25 |
#include <config.h> |
26 |
#endif |
27 |
|
28 |
#ifdef _WIN32_ |
29 |
#define _WIN32_WINNT 0x0500 |
30 |
|
31 |
#include <windows.h> |
32 |
#include <conio.h> |
33 |
#endif |
34 |
|
35 |
#include <stdio.h> |
36 |
#include "../Akai.h" |
37 |
|
38 |
static void PrintLastError(char* file, int line) |
39 |
{ |
40 |
#ifdef _WIN32_ |
41 |
LPVOID lpMsgBuf; |
42 |
FormatMessage( |
43 |
FORMAT_MESSAGE_ALLOCATE_BUFFER | |
44 |
FORMAT_MESSAGE_FROM_SYSTEM | |
45 |
FORMAT_MESSAGE_IGNORE_INSERTS, |
46 |
NULL, |
47 |
GetLastError(), |
48 |
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language |
49 |
(LPTSTR) &lpMsgBuf, |
50 |
0, |
51 |
NULL |
52 |
); |
53 |
|
54 |
// Display the string. |
55 |
char buf[2048]; |
56 |
sprintf(buf,"%s(%d): %s",file, line, (LPCTSTR)lpMsgBuf); |
57 |
printf("%s",buf); |
58 |
OutputDebugString(buf); |
59 |
// Free the buffer. |
60 |
LocalFree( lpMsgBuf ); |
61 |
#endif |
62 |
} |
63 |
|
64 |
#define SHOWERROR PrintLastError(__FILE__,__LINE__) |
65 |
|
66 |
static void printUsage() { |
67 |
#ifdef _WIN32_ |
68 |
printf( |
69 |
"akaidump <source-drive-letter>: <destination-filename>\n" |
70 |
"by Sebastien Métrot (meeloo@meeloo.net)\n\n" |
71 |
"Reads an AKAI media (i.e. CDROM, ZIP disk) and writes it as AKAI\n" |
72 |
"disk image file to your hard disk drive for more convenient and\n" |
73 |
"faster further usage.\n\n" |
74 |
"Available types of your drives:\n" |
75 |
); |
76 |
char rootpath[4]="a:\\"; |
77 |
for (char drive ='a'; drive <= 'z'; drive++) { |
78 |
rootpath[0] = drive; |
79 |
int type = GetDriveType(rootpath); |
80 |
if (type != DRIVE_NO_ROOT_DIR) { |
81 |
printf("Drive %s is a ", rootpath); |
82 |
switch(type) { |
83 |
case DRIVE_UNKNOWN: printf("Unknown\n"); break; |
84 |
case DRIVE_NO_ROOT_DIR: printf("Unavailable\n"); |
85 |
case DRIVE_REMOVABLE: printf("removable disk\n"); break; |
86 |
case DRIVE_FIXED: printf("fixed disk\n"); break; |
87 |
case DRIVE_REMOTE: printf("remote (network) drive\n"); break; |
88 |
case DRIVE_CDROM: printf("CD-ROM drive\n"); break; |
89 |
case DRIVE_RAMDISK: printf("RAM disk\n"); break; |
90 |
} |
91 |
} |
92 |
} |
93 |
printf("\n"); |
94 |
#elif defined _CARBON_ |
95 |
printf( |
96 |
"akaidump [<source-path>] <destination-filename>\n" |
97 |
"by Sebastien Métrot (meeloo@meeloo.net)\n\n" |
98 |
"Reads an AKAI media (i.e. CDROM, ZIP disk) and writes it as AKAI\n" |
99 |
"disk image file to your hard disk drive for more convenient and\n" |
100 |
"faster further usage.\n\n" |
101 |
"<source-path> - path of the source AKAI image file, if omitted CDROM\n" |
102 |
" drive ('/dev/rdisk1s0') will be accessed\n\n" |
103 |
"<destination-filename> - target filename to write the AKAI disk image to\n\n" |
104 |
); |
105 |
#else |
106 |
printf( |
107 |
"akaidump <source-path> <destination-filename>\n" |
108 |
"by Sebastien Métrot (meeloo@meeloo.net)\n" |
109 |
"Linux port by Christian Schoenebeck\n\n" |
110 |
"Reads an AKAI media (i.e. CDROM, ZIP disk) and writes it as AKAI\n" |
111 |
"disk image file to your hard disk drive for more convenient and\n" |
112 |
"faster further usage.\n\n" |
113 |
"<source-path> - path of the source drive, i.e. /dev/cdrom\n\n" |
114 |
"<destination-filename> - target filename to write the AKAI disk image to\n\n" |
115 |
); |
116 |
#endif |
117 |
} |
118 |
|
119 |
int main(int argc, char** argv) { |
120 |
#if defined _CARBON_ |
121 |
if (argc < 2) { |
122 |
printUsage(); |
123 |
return -1; |
124 |
} |
125 |
#else |
126 |
if (argc < 3) { |
127 |
printUsage(); |
128 |
return -1; |
129 |
} |
130 |
#endif |
131 |
|
132 |
// open input source |
133 |
DiskImage* pImage = NULL; |
134 |
#ifdef _WIN32_ |
135 |
char drive = toupper(*(argv[1]))-'A'; |
136 |
printf("opening drive %c:\n",drive+'a'); |
137 |
pImage = new DiskImage(drive); |
138 |
#elif defined _CARBON_ |
139 |
if (argc == 2) { |
140 |
printf("Opening AKAI media at '/dev/rdisk1s0'\n"); |
141 |
pImage = new DiskImage((int)0); // arbitrary int, argument will be ignored |
142 |
} else { |
143 |
printf("Opening source AKAI image file at '%s'\n", argv[1]); |
144 |
pImage = new DiskImage(argv[1]); |
145 |
} |
146 |
#else |
147 |
printf("Opening AKAI media or image file at '%s'\n", argv[1]); |
148 |
pImage = new DiskImage(argv[1]); |
149 |
#endif |
150 |
|
151 |
// open output file for writing the AKAI disk image |
152 |
#if defined _CARBON_ |
153 |
const char* outPath = (argc == 2) ? argv[1] : argv[2]; |
154 |
#else |
155 |
const char* outPath = argv[2]; |
156 |
#endif |
157 |
printf("Writing AKAI image file to '%s'\n", outPath); |
158 |
FILE* file = fopen(outPath, "wb"); |
159 |
if (!file) { |
160 |
printf("Couldn't open output file '%s'\n", outPath); |
161 |
return -1; |
162 |
} |
163 |
|
164 |
uint i; |
165 |
uint size = pImage->Available(1); |
166 |
uint mbytes = 0; |
167 |
uint writenbytes = 0; |
168 |
printf("Dumping %d bytes (%d Mb)\n", size, size / (1024*1024)); |
169 |
for (i = 0; i < size; ) { |
170 |
char buffer[2048]; |
171 |
uint32_t readbytes = 0; |
172 |
readbytes = pImage->Read(buffer, 2048, 1); |
173 |
writenbytes += fwrite(buffer, readbytes, 1, file); |
174 |
i += readbytes; |
175 |
|
176 |
if (i / (1024*1024) > mbytes) { |
177 |
mbytes = i / (1024*1024); |
178 |
printf("\rDumped %d Mbytes.",mbytes); |
179 |
} |
180 |
} |
181 |
printf("\n%d bytes read, %d bytes written\nOK\n", i, writenbytes); |
182 |
|
183 |
fclose(file); |
184 |
|
185 |
delete pImage; |
186 |
|
187 |
// while(!_kbhit()); |
188 |
return 0; |
189 |
} |