Skip to content

Commit 07232f7

Browse files
feat(cli): add arguments for adding and removing directories
1 parent df22e9b commit 07232f7

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/cli/Main.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ ARG_S(COMPRESSION_METHOD, "-m", "--compression-method");
3535
ARG_S(COMPRESSION_LEVEL, "-x", "--compression-level");
3636
ARG_L(GEN_MD5_ENTRIES, "--gen-md5-entries");
3737
ARG_L(ADD_FILE, "--add-file");
38+
ARG_L(ADD_DIR, "--add-dir");
3839
ARG_L(REMOVE_FILE, "--remove-file");
40+
ARG_L(REMOVE_DIR, "--remove-dir");
3941
ARG_S(PRELOAD, "-p", "--preload");
4042
ARG_S(SINGLE_FILE, "-s", "--single-file");
4143
ARG_S(EXTRACT, "-e", "--extract");
@@ -173,6 +175,8 @@ void edit(const argparse::ArgumentParser& cli, const std::string& inputPath) {
173175
auto args = cli.get<std::vector<std::string>>(ARG_L(ADD_FILE));
174176
if (!std::filesystem::exists(args[0])) {
175177
std::cerr << "File at \"" << args[0] << "\" does not exist! Cannot add to pack file." << std::endl;
178+
} else if (!std::filesystem::is_regular_file(args[0])) {
179+
std::cerr << "Path \"" << args[0] << "\" does not point to a file! Cannot add to pack file." << std::endl;
176180
} else {
177181
packFile->addEntry(args[1], args[0], {});
178182
packFile->bake("", {
@@ -184,6 +188,23 @@ void edit(const argparse::ArgumentParser& cli, const std::string& inputPath) {
184188
}
185189
}
186190

191+
if (cli.is_used(ARG_L(ADD_DIR))) {
192+
auto args = cli.get<std::vector<std::string>>(ARG_L(ADD_DIR));
193+
if (!std::filesystem::exists(args[0])) {
194+
std::cerr << "Directory at \"" << args[0] << "\" does not exist! Cannot add to pack file." << std::endl;
195+
} else if (!std::filesystem::is_directory(args[0])) {
196+
std::cerr << "Path \"" << args[0] << "\" does not point to a directory! Cannot add to pack file." << std::endl;
197+
} else {
198+
packFile->addDirectory(args[1], args[0]);
199+
packFile->bake("", {
200+
.zip_compressionTypeOverride = compressionMethod,
201+
.zip_compressionStrength = compressionLevel,
202+
.vpk_generateMD5Entries = generateMD5Entries,
203+
}, nullptr);
204+
std::cout << "Added directory at \"" << args[0] << "\" to the pack file at path \"" << args[1] << "\"." << std::endl;
205+
}
206+
}
207+
187208
if (cli.is_used(ARG_L(REMOVE_FILE))) {
188209
auto path = cli.get(ARG_L(REMOVE_FILE));
189210
if (!packFile->removeEntry(path)) {
@@ -198,6 +219,21 @@ void edit(const argparse::ArgumentParser& cli, const std::string& inputPath) {
198219
std::cout << "Removed file at \"" << path << "\" from the pack file." << std::endl;
199220
}
200221
}
222+
223+
if (cli.is_used(ARG_L(REMOVE_DIR))) {
224+
auto path = cli.get(ARG_L(REMOVE_DIR));
225+
if (!packFile->removeDirectory(path)) {
226+
std::cerr
227+
<< "Unable to remove directory at \"" << path << "\" from the pack file!\n"
228+
<< "Check the directory exists in the pack file and the path is spelled correctly." << std::endl;
229+
} else {
230+
packFile->bake("", {
231+
.zip_compressionStrength = compressionLevel,
232+
.vpk_generateMD5Entries = generateMD5Entries,
233+
}, nullptr);
234+
std::cout << "Removed directory at \"" << path << "\" from the pack file." << std::endl;
235+
}
236+
}
201237
}
202238

203239
/// Sign an existing VPK
@@ -469,10 +505,18 @@ int main(int argc, const char* const* argv) {
469505
.help("(Modify) Add the specified file to the pack file with the given path.")
470506
.nargs(2);
471507

508+
cli.add_argument(ARG_L(ADD_DIR))
509+
.help("(Modify) Add the specified directory to the pack file with the given path.")
510+
.nargs(2);
511+
472512
cli.add_argument(ARG_L(REMOVE_FILE))
473513
.help("(Modify) Remove the specified file at the given path from the pack file.")
474514
.nargs(1);
475515

516+
cli.add_argument(ARG_L(REMOVE_DIR))
517+
.help("(Modify) Remove the specified directory at the given path from the pack file.")
518+
.nargs(1);
519+
476520
cli.add_argument(ARG_P(PRELOAD))
477521
.help("(Pack) If a file's extension is in this list, the first kilobyte will be\n"
478522
"preloaded in the directory FPX/VPK. Full file names are also supported here\n"

src/shared/thirdparty/sourcepp

Submodule sourcepp updated 55 files

0 commit comments

Comments
 (0)