2 |
* * |
* * |
3 |
* libgig - C++ cross-platform Gigasampler format file access library * |
* libgig - C++ cross-platform Gigasampler format file access library * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003-2014 by Christian Schoenebeck * |
* Copyright (C) 2003-2016 by Christian Schoenebeck * |
6 |
* <cuse@users.sourceforge.net> * |
* <cuse@users.sourceforge.net> * |
7 |
* * |
* * |
8 |
* This program is part of libgig. * |
* This program is part of libgig. * |
45 |
void PrintRegions(gig::Instrument* instr); |
void PrintRegions(gig::Instrument* instr); |
46 |
void PrintUsage(); |
void PrintUsage(); |
47 |
void PrintDimensionRegions(gig::Region* rgn); |
void PrintDimensionRegions(gig::Region* rgn); |
48 |
|
bool VerifyFile(gig::File* gig); |
49 |
|
void RebuildChecksumTable(gig::File* gig); |
50 |
|
|
51 |
class PubSample : public gig::Sample { |
class PubSample : public gig::Sample { |
52 |
public: |
public: |
53 |
using DLS::Sample::pCkData; |
using DLS::Sample::pCkData; |
54 |
}; |
}; |
55 |
|
|
56 |
|
class PubFile : public gig::File { |
57 |
|
public: |
58 |
|
using gig::File::VerifySampleChecksumTable; |
59 |
|
using gig::File::RebuildSampleChecksumTable; |
60 |
|
}; |
61 |
|
|
62 |
|
|
63 |
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) |
64 |
{ |
{ |
65 |
|
bool bVerify = false; |
66 |
|
bool bRebuildChecksums = false; |
67 |
|
|
68 |
if (argc <= 1) { |
if (argc <= 1) { |
69 |
PrintUsage(); |
PrintUsage(); |
70 |
return EXIT_FAILURE; |
return EXIT_FAILURE; |
71 |
} |
} |
72 |
if (argv[1][0] == '-') { |
|
73 |
switch (argv[1][1]) { |
int iArg; |
74 |
case 'v': |
for (iArg = 1; iArg < argc; ++iArg) { |
75 |
PrintVersion(); |
const string opt = argv[iArg]; |
76 |
return EXIT_SUCCESS; |
if (opt == "--") { // common for all command line tools: separator between initial option arguments and i.e. subsequent file arguments |
77 |
|
iArg++; |
78 |
|
break; |
79 |
|
} |
80 |
|
if (opt.substr(0, 1) != "-") break; |
81 |
|
|
82 |
|
if (opt == "-v") { |
83 |
|
PrintVersion(); |
84 |
|
return EXIT_SUCCESS; |
85 |
|
} else if (opt == "--verify") { |
86 |
|
bVerify = true; |
87 |
|
} else if (opt == "--rebuild-checksums") { |
88 |
|
bRebuildChecksums = true; |
89 |
|
} else { |
90 |
|
cerr << "Unknown option '" << opt << "'" << endl; |
91 |
|
cerr << endl; |
92 |
|
PrintUsage(); |
93 |
|
return EXIT_FAILURE; |
94 |
} |
} |
95 |
} |
} |
96 |
FILE* hFile = fopen(argv[1], "r"); |
if (iArg >= argc) { |
97 |
|
cout << "No file name provided!" << endl; |
98 |
|
return EXIT_FAILURE; |
99 |
|
} |
100 |
|
const char* filename = argv[iArg]; |
101 |
|
|
102 |
|
FILE* hFile = fopen(filename, "r"); |
103 |
if (!hFile) { |
if (!hFile) { |
104 |
cout << "Invalid file argument!" << endl; |
cout << "Invalid file argument!" << endl; |
105 |
return EXIT_FAILURE; |
return EXIT_FAILURE; |
106 |
} |
} |
107 |
fclose(hFile); |
fclose(hFile); |
108 |
try { |
try { |
109 |
RIFF::File* riff = new RIFF::File(argv[1]); |
RIFF::File* riff = new RIFF::File(filename); |
110 |
gig::File* gig = new gig::File(riff); |
gig::File* gig = new gig::File(riff); |
111 |
PrintFileInformations(gig); |
|
112 |
cout << endl; |
if (bRebuildChecksums) { |
113 |
PrintGroups(gig); |
RebuildChecksumTable(gig); |
114 |
cout << endl; |
} else if (bVerify) { |
115 |
PrintSamples(gig); |
bool OK = VerifyFile(gig); |
116 |
cout << endl; |
if (OK) cout << "All checks passed successfully! :-)\n"; |
117 |
PrintScripts(gig); |
return (OK) ? EXIT_SUCCESS : EXIT_FAILURE; |
118 |
cout << endl; |
} else { |
119 |
PrintInstruments(gig); |
PrintFileInformations(gig); |
120 |
|
cout << endl; |
121 |
|
PrintGroups(gig); |
122 |
|
cout << endl; |
123 |
|
PrintSamples(gig); |
124 |
|
cout << endl; |
125 |
|
PrintScripts(gig); |
126 |
|
cout << endl; |
127 |
|
PrintInstruments(gig); |
128 |
|
} |
129 |
delete gig; |
delete gig; |
130 |
delete riff; |
delete riff; |
131 |
} |
} |
511 |
} |
} |
512 |
} |
} |
513 |
|
|
514 |
|
bool VerifyFile(gig::File* _gig) { |
515 |
|
PubFile* gig = (PubFile*) _gig; |
516 |
|
|
517 |
|
cout << "Verifying sample checksum table ... " << flush; |
518 |
|
if (!gig->VerifySampleChecksumTable()) { |
519 |
|
cout << "DAMAGED\n"; |
520 |
|
cout << "You may use --rebuild-checksums to repair the sample checksum table.\n"; |
521 |
|
return false; |
522 |
|
} |
523 |
|
cout << "OK\n" << flush; |
524 |
|
|
525 |
|
cout << "Verifying samples ... " << flush; |
526 |
|
std::map<int,gig::Sample*> failedSamples; |
527 |
|
int iTotal = 0; |
528 |
|
for (gig::Sample* pSample = gig->GetFirstSample(); pSample; pSample = gig->GetNextSample(), ++iTotal) { |
529 |
|
if (!pSample->VerifyWaveData()) |
530 |
|
failedSamples[iTotal] = pSample; |
531 |
|
} |
532 |
|
if (failedSamples.empty()) { |
533 |
|
cout << "ALL OK\n"; |
534 |
|
return true; |
535 |
|
} else { |
536 |
|
cout << failedSamples.size() << " of " << iTotal << " Samples DAMAGED:\n"; |
537 |
|
for (std::map<int,gig::Sample*>::iterator it = failedSamples.begin(); it != failedSamples.end(); ++it) { |
538 |
|
const int i = it->first; |
539 |
|
gig::Sample* pSample = it->second; |
540 |
|
|
541 |
|
string name = pSample->pInfo->Name; |
542 |
|
if (name == "") name = "<NO NAME>"; |
543 |
|
else name = '\"' + name + '\"'; |
544 |
|
|
545 |
|
cout << "Damaged Sample " << (i+1) << ") " << name << endl; |
546 |
|
} |
547 |
|
return false; |
548 |
|
} |
549 |
|
} |
550 |
|
|
551 |
|
void RebuildChecksumTable(gig::File* _gig) { |
552 |
|
PubFile* gig = (PubFile*) _gig; |
553 |
|
|
554 |
|
cout << "Recalculating checksums of all samples ... " << flush; |
555 |
|
bool bSaveRequired = gig->RebuildSampleChecksumTable(); |
556 |
|
cout << "OK\n"; |
557 |
|
if (bSaveRequired) { |
558 |
|
cout << "WARNING: File structure change required, rebuilding entire file now ..." << endl; |
559 |
|
gig->Save(); |
560 |
|
cout << "DONE\n"; |
561 |
|
cout << "NOTE: Since the entire file was rebuilt, you may need to manually check all samples in this particular case now!\n"; |
562 |
|
} |
563 |
|
} |
564 |
|
|
565 |
string Revision() { |
string Revision() { |
566 |
string s = "$Revision$"; |
string s = "$Revision$"; |
567 |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
575 |
void PrintUsage() { |
void PrintUsage() { |
576 |
cout << "gigdump - parses Gigasampler files and prints out the content." << endl; |
cout << "gigdump - parses Gigasampler files and prints out the content." << endl; |
577 |
cout << endl; |
cout << endl; |
578 |
cout << "Usage: gigdump [-v] FILE" << endl; |
cout << "Usage: gigdump [-v | --verify | --rebuild-checksums] FILE" << endl; |
579 |
|
cout << endl; |
580 |
|
cout << " --rebuild-checksums Rebuild checksum table for all samples." << endl; |
581 |
|
cout << endl; |
582 |
|
cout << " -v Print version and exit." << endl; |
583 |
cout << endl; |
cout << endl; |
584 |
cout << " -v Print version and exit." << endl; |
cout << " --verify Checks raw wave data integrity of all samples." << endl; |
585 |
cout << endl; |
cout << endl; |
586 |
} |
} |