-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed 'use cue name' behavior and used smarter naming
- Loading branch information
Showing
8 changed files
with
142 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,139 +1,91 @@ | ||
#include <cstdio> | ||
#include <cstdint> | ||
#include <cstring> | ||
#include <cinttypes> | ||
|
||
#if defined(_WIN32) || defined(WIN32) | ||
|
||
#define WIN32_LEAN_AND_MEAN | ||
|
||
#include <windows.h> | ||
|
||
#else | ||
#include <sys/stat.h> | ||
#include <unistd.h> | ||
#endif | ||
#include <string> | ||
|
||
#include "../../lib/cgss_api.h" | ||
#include "../common/common.h" | ||
#include "../common/acbextract.h" | ||
|
||
using namespace std; | ||
using namespace cgss; | ||
|
||
static void print_help(); | ||
struct AcbUnpackOptions { | ||
bool_t useCueName; | ||
}; | ||
|
||
static void MakeDirectories(const std::string &s); | ||
static void PrintHelp(); | ||
|
||
static std::string GetDirectoryFromPath(const std::string &s); | ||
static int ParseArgs(int argc, const char *argv[], string &inputFile, AcbUnpackOptions &options); | ||
|
||
static std::string GetFileNameFromPath(const std::string &s); | ||
static int DoWork(const string &inputFile, const AcbUnpackOptions &options); | ||
|
||
static int ExtractFile(AcbWalkCallbackParams *params); | ||
|
||
int main(int argc, const char *argv[]) { | ||
if (argc == 1) { | ||
print_help(); | ||
string inputFile; | ||
AcbUnpackOptions options = {0}; | ||
|
||
const auto parsed = ParseArgs(argc, argv, inputFile, options); | ||
|
||
if (parsed < 0) { | ||
return 0; | ||
} else if (parsed > 0) { | ||
return parsed; | ||
} | ||
|
||
const char *filePath = argv[1]; | ||
|
||
if (!cgssHelperFileExists(filePath)) { | ||
fprintf(stderr, "File '%s' does not exist or cannot be opened.\n", filePath); | ||
if (!cgssHelperFileExists(inputFile.c_str())) { | ||
fprintf(stderr, "File '%s' does not exist or cannot be opened.\n", inputFile.c_str()); | ||
return -1; | ||
} | ||
|
||
AcbWalkOptions options; | ||
options.useCueName = true; | ||
options.callback = ExtractFile; | ||
return DoWork(inputFile, options); | ||
} | ||
|
||
const auto r = AcbWalk(filePath, &options); | ||
static int DoWork(const string &inputFile, const AcbUnpackOptions &options) { | ||
AcbWalkOptions o; | ||
o.useCueName = options.useCueName; | ||
o.callback = ExtractFile; | ||
|
||
return r; | ||
return AcbWalk(inputFile, &o); | ||
} | ||
|
||
static int ExtractFile(AcbWalkCallbackParams *params) { | ||
fprintf(stdout, "Unpacking: %s\n", params->extractPathHint.c_str()); | ||
|
||
CFileStream fs(params->extractPathHint.c_str(), FileMode::Create, FileAccess::Write); | ||
common_utils::CopyStream(params->entryDataStream, &fs); | ||
|
||
return 0; | ||
} | ||
|
||
static void print_help() { | ||
fprintf(stderr, "Usage:\n\n\tacbunpack <file>\n"); | ||
} | ||
|
||
static std::string GetDirectoryFromPath(const std::string &s) { | ||
const char sep1 = '/', sep2 = '\\'; | ||
|
||
size_t i1 = s.rfind(sep1, s.length()); | ||
size_t i2 = s.rfind(sep2, s.length()); | ||
|
||
if (i1 != std::string::npos) { | ||
if (i2 != std::string::npos) { | ||
auto i = i1 > i2 ? i1 : i2; | ||
return (s.substr(0, i)); | ||
} else { | ||
return (s.substr(0, i1)); | ||
} | ||
} else { | ||
if (i2 != std::string::npos) { | ||
return (s.substr(0, i2)); | ||
} else { | ||
return std::string(""); | ||
} | ||
} | ||
static void PrintHelp() { | ||
static const char *helpMessage = "Usage:\n" | ||
"\n" | ||
"\tacbunpack <file> [-n]\n" | ||
"\n" | ||
"\t-n Use cue names for output waveforms\n"; | ||
fprintf(stderr, "%s", helpMessage); | ||
} | ||
|
||
static std::string GetFileNameFromPath(const std::string &s) { | ||
const char sep1 = '/', sep2 = '\\'; | ||
|
||
size_t i1 = s.rfind(sep1, s.length()); | ||
size_t i2 = s.rfind(sep2, s.length()); | ||
|
||
if (i1 != std::string::npos) { | ||
if (i2 != std::string::npos) { | ||
auto i = i1 > i2 ? i1 : i2; | ||
return (s.substr(i + 1)); | ||
} else { | ||
return (s.substr(i1 + 1)); | ||
} | ||
} else { | ||
if (i2 != std::string::npos) { | ||
return (s.substr(i2 + 1)); | ||
} else { | ||
return std::string(""); | ||
} | ||
static int ParseArgs(int argc, const char *argv[], string &inputFile, AcbUnpackOptions &options) { | ||
if (argc < 2) { | ||
PrintHelp(); | ||
return -1; | ||
} | ||
} | ||
|
||
#if defined(WIN32) || defined(_WIN32) | ||
|
||
static void MakeDirectories(const std::string &s) { | ||
CreateDirectory(s.c_str(), nullptr); | ||
} | ||
|
||
#else | ||
|
||
static void MakeDirectories(const std::string &s) { | ||
char str[512] = {0}; | ||
|
||
strncpy(str, s.c_str(), 512); | ||
auto len = strlen(str); | ||
|
||
for (auto i = 0; i < len; i++) { | ||
if (str[i] == '/') { | ||
str[i] = '\0'; | ||
if (access(str, 0) != 0) { | ||
mkdir(str, 0777); | ||
inputFile = argv[1]; | ||
|
||
for (int i = 2; i < argc; ++i) { | ||
if (argv[i][0] == '-' || argv[i][0] == '/') { | ||
switch (argv[i][1]) { | ||
case 'n': | ||
options.useCueName = TRUE; | ||
break; | ||
default: | ||
fprintf(stderr, "Unknown option: %s\n", argv[i]); | ||
return 2; | ||
} | ||
str[i] = '/'; | ||
} | ||
} | ||
|
||
if (len > 0 && access(str, 0) != 0) { | ||
mkdir(str, 0777); | ||
} | ||
return 0; | ||
} | ||
|
||
#endif |
Oops, something went wrong.