forked from gildor2/UEViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
139 lines (114 loc) · 2.71 KB
/
Copy pathMain.cpp
File metadata and controls
139 lines (114 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "Core.h"
#include "UnrealClasses.h"
#include "UnPackage.h"
#include "UnUbisoft.h"
#define DEF_UNP_DIR "unpacked"
#define HOMEPAGE "http://www.gildor.org/"
/*-----------------------------------------------------------------------------
Main function
-----------------------------------------------------------------------------*/
static char BaseDir[256];
static bool GUnpackUmd = false;
static bool ScanFile(const CGameFileInfo *file)
{
guard(ScanFile);
FArchive *Ar = appCreateFileReader(file);
// setup NotifyInfo to describe package only
appSetNotifyHeader(file->RelativeName);
FArchive *TmpAr = CreateUMDReader(Ar);
if (!TmpAr)
{
// not UMD file
delete Ar;
return true;
}
printf("Processing: %s\n", file->RelativeName);
Ar = TmpAr; // original reader will be destroyed automatically with this reader
if (!GUnpackUmd)
{
ExtractUMDArchive(Ar, BaseDir);
}
else
{
char FileName[512];
appSprintf(ARRAY_ARG(FileName), "%s/%s", BaseDir, file->ShortFilename);
SaveUMDArchive(Ar, FileName);
}
delete Ar;
return true;
unguardf("%s", file->RelativeName);
}
int main(int argc, char **argv)
{
#if DO_GUARD
TRY {
#endif
guard(Main);
// display usage
if (argc < 2)
{
help:
printf( "Ubisoft Unreal Engine UMD Unpacker\n"
"Usage: unumd [options]\n"
"\n"
"Options:\n"
" -path=PATH set directory with UMD files\n"
" -out=PATH extract everything into PATH, default is \"" DEF_UNP_DIR "\"\n"
" -unpack unpack UMD file instead of extraction\n"
"\n"
"For details and updates please visit " HOMEPAGE "\n"
);
exit(0);
}
// parse command line
strcpy(BaseDir, DEF_UNP_DIR);
bool hasRootDir = false;
int arg;
for (arg = 1; arg < argc; arg++)
{
if (argv[arg][0] == '-')
{
const char *opt = argv[arg]+1;
if (!strnicmp(opt, "path=", 5))
{
appSetRootDirectory(opt+5);
hasRootDir = true;
}
else if (!strnicmp(opt, "out=", 4))
{
strcpy(BaseDir, opt+4);
}
else if (!stricmp(opt, "unpack"))
GUnpackUmd = true;
else
goto help;
}
else
{
break;
}
}
if (!hasRootDir) appSetRootDirectory("."); // scan for packages from the current directory
if (arg < argc) goto help;
guard(ProcessFiles);
// scan packages
appEnumGameFiles(ScanFile, "umd");
unguard; // ProcessFiles
unguard; // Main
#if DO_GUARD
} CATCH {
if (GErrorHistory[0])
{
// printf("ERROR: %s\n", GErrorHistory);
appNotify("ERROR: %s\n", GErrorHistory);
}
else
{
// printf("Unknown error\n");
appNotify("Unknown error\n");
}
exit(1);
}
#endif
return 0;
}