/[svn]/libgig/trunk/src/tools/akaidump.cpp
ViewVC logotype

Annotation of /libgig/trunk/src/tools/akaidump.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3983 - (hide annotations) (download)
Tue Aug 3 16:05:32 2021 UTC (2 years, 8 months ago) by schoenebeck
File size: 6214 byte(s)
Drop "svn:executable" property from all source files.

1 schoenebeck 2572 /*
2     libakai - C++ cross-platform akai sample disk reader
3     Copyright (C) 2002-2003 Sébastien Métrot
4    
5 persson 2836 Linux port by Christian Schoenebeck <cuse@users.sourceforge.net> 2003-2015
6 schoenebeck 2572
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 schoenebeck 2574 #ifdef WIN32
29 schoenebeck 2572 #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 schoenebeck 2574 #ifdef WIN32
41 schoenebeck 2572 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 schoenebeck 2574 #ifdef WIN32
68 persson 2836 const wchar_t* msg =
69     L"akaidump <source-drive-letter>: <destination-filename>\n"
70     "by S\351bastien M\351trot (meeloo@meeloo.net)\n\n"
71 schoenebeck 2572 "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 persson 2836 "Available types of your drives:\n";
75     DWORD n = wcslen(msg);
76     WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), msg, n, &n, NULL);
77 schoenebeck 2572 char rootpath[4]="a:\\";
78     for (char drive ='a'; drive <= 'z'; drive++) {
79     rootpath[0] = drive;
80     int type = GetDriveType(rootpath);
81     if (type != DRIVE_NO_ROOT_DIR) {
82     printf("Drive %s is a ", rootpath);
83     switch(type) {
84     case DRIVE_UNKNOWN: printf("Unknown\n"); break;
85     case DRIVE_NO_ROOT_DIR: printf("Unavailable\n");
86     case DRIVE_REMOVABLE: printf("removable disk\n"); break;
87     case DRIVE_FIXED: printf("fixed disk\n"); break;
88     case DRIVE_REMOTE: printf("remote (network) drive\n"); break;
89     case DRIVE_CDROM: printf("CD-ROM drive\n"); break;
90     case DRIVE_RAMDISK: printf("RAM disk\n"); break;
91     }
92     }
93     }
94     printf("\n");
95     #elif defined _CARBON_
96 persson 2836 setlocale(LC_CTYPE, "");
97     printf("%ls",
98     L"akaidump [<source-path>] <destination-filename>\n"
99     "by S\351bastien M\351trot (meeloo@meeloo.net)\n\n"
100 schoenebeck 2572 "Reads an AKAI media (i.e. CDROM, ZIP disk) and writes it as AKAI\n"
101     "disk image file to your hard disk drive for more convenient and\n"
102     "faster further usage.\n\n"
103     "<source-path> - path of the source AKAI image file, if omitted CDROM\n"
104     " drive ('/dev/rdisk1s0') will be accessed\n\n"
105     "<destination-filename> - target filename to write the AKAI disk image to\n\n"
106     );
107     #else
108 persson 2836 setlocale(LC_CTYPE, "");
109     printf("%ls",
110     L"akaidump <source-path> <destination-filename>\n"
111     "by S\351bastien M\351trot (meeloo@meeloo.net)\n"
112 schoenebeck 2572 "Linux port by Christian Schoenebeck\n\n"
113     "Reads an AKAI media (i.e. CDROM, ZIP disk) and writes it as AKAI\n"
114     "disk image file to your hard disk drive for more convenient and\n"
115     "faster further usage.\n\n"
116     "<source-path> - path of the source drive, i.e. /dev/cdrom\n\n"
117     "<destination-filename> - target filename to write the AKAI disk image to\n\n"
118     );
119     #endif
120     }
121    
122     int main(int argc, char** argv) {
123     #if defined _CARBON_
124     if (argc < 2) {
125     printUsage();
126     return -1;
127     }
128     #else
129     if (argc < 3) {
130     printUsage();
131     return -1;
132     }
133     #endif
134    
135     // open input source
136     DiskImage* pImage = NULL;
137 schoenebeck 2574 #ifdef WIN32
138 schoenebeck 2572 char drive = toupper(*(argv[1]))-'A';
139     printf("opening drive %c:\n",drive+'a');
140     pImage = new DiskImage(drive);
141     #elif defined _CARBON_
142     if (argc == 2) {
143     printf("Opening AKAI media at '/dev/rdisk1s0'\n");
144     pImage = new DiskImage((int)0); // arbitrary int, argument will be ignored
145     } else {
146     printf("Opening source AKAI image file at '%s'\n", argv[1]);
147     pImage = new DiskImage(argv[1]);
148     }
149     #else
150     printf("Opening AKAI media or image file at '%s'\n", argv[1]);
151     pImage = new DiskImage(argv[1]);
152     #endif
153    
154     // open output file for writing the AKAI disk image
155     #if defined _CARBON_
156     const char* outPath = (argc == 2) ? argv[1] : argv[2];
157     #else
158     const char* outPath = argv[2];
159     #endif
160     printf("Writing AKAI image file to '%s'\n", outPath);
161     FILE* file = fopen(outPath, "wb");
162     if (!file) {
163     printf("Couldn't open output file '%s'\n", outPath);
164     return -1;
165     }
166    
167     uint i;
168     uint size = pImage->Available(1);
169     uint mbytes = 0;
170     uint writenbytes = 0;
171     printf("Dumping %d bytes (%d Mb)\n", size, size / (1024*1024));
172     for (i = 0; i < size; ) {
173     char buffer[2048];
174     uint32_t readbytes = 0;
175     readbytes = pImage->Read(buffer, 2048, 1);
176     writenbytes += fwrite(buffer, readbytes, 1, file);
177     i += readbytes;
178    
179     if (i / (1024*1024) > mbytes) {
180     mbytes = i / (1024*1024);
181     printf("\rDumped %d Mbytes.",mbytes);
182     }
183     }
184     printf("\n%d bytes read, %d bytes written\nOK\n", i, writenbytes);
185    
186     fclose(file);
187    
188     delete pImage;
189    
190     // while(!_kbhit());
191     return 0;
192     }

  ViewVC Help
Powered by ViewVC