Skip to content

Commit d986668

Browse files
committed
Add ability to specify a directory to extract files to
1 parent 6c74090 commit d986668

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

README.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@ directory as the NUS content, and can be compiled for Linux or macOS.
2121
### Usage
2222

2323
```
24-
cdecrypt <NUS file or directory>
24+
cdecrypt <NUS file or directory> [<target directory or existing file>]
2525
```
2626

27-
The content is extracted into the same directory where the NUS files reside.
28-
On Windows, you can also drag and drop a directory/file directly onto `cdecrypt.exe`.
27+
If only one parameter is specified, the content is extracted into the same
28+
directory where the NUS files reside. If an existing file is provided as the
29+
second parameter, it is ignored (to preserve compatibility with the previous
30+
versions of CDecrypt). If the second parameter is not an existing file, then
31+
it is used as the target directory to extract files in, with any intermediate
32+
directories created if needed.
33+
34+
Note that on Windows, you can drag and drop a directory/file directly onto
35+
`cdecrypt.exe`.

cdecrypt.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,9 @@ int main_utf8(int argc, char** argv)
497497

498498
printf("FST entries: %u\n", entries);
499499

500+
char* dst_dir = ((argc <= 2) || is_file(argv[2])) ? argv[1] : argv[2];
501+
printf("Extracting to directory: '%s'\n", dst_dir);
502+
create_path(dst_dir);
500503
char path[PATH_MAX] = { 0 };
501504
uint32_t entry[16];
502505
uint32_t l_entry[16];
@@ -519,7 +522,7 @@ int main_utf8(int argc, char** argv)
519522
} else {
520523
uint32_t offset;
521524
memset(path, 0, sizeof(path));
522-
strcpy(path, argv[1]);
525+
strcpy(path, dst_dir);
523526

524527
size_t short_path = strlen(path) + 1;
525528
for (uint32_t j = 0; j < level; j++) {

util.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ bool is_directory(const char* path)
7575

7676
char* change_extension(const char* path, const char* extension)
7777
{
78-
static char new_path[256];
78+
static char new_path[PATH_MAX];
7979
strncpy(new_path, basename((char*)path), sizeof(new_path) - 1);
8080
for (size_t i = 0; i < sizeof(new_path); i++) {
8181
if (new_path[i] == '.')

0 commit comments

Comments
 (0)