|
@@ -0,0 +1,69 @@
|
|
1
|
+#include "olcPGE_ResourcePack.h"
|
|
2
|
+#include <iostream>
|
|
3
|
+#include <string>
|
|
4
|
+
|
|
5
|
+void PrintUsage() {
|
|
6
|
+ std::cout << "Usage: packer --list PACK_FILE" << std::endl;
|
|
7
|
+ std::cout << " packer --add PACK_FILE FILE" << std::endl;
|
|
8
|
+ std::cout << " packer --remove PACK_FILE FILE" << std::endl;
|
|
9
|
+ // std::cout << " packer --convert PNG_FILE SPR_FILE" << std::endl;
|
|
10
|
+}
|
|
11
|
+
|
|
12
|
+void ListEntries(olc::ResourcePack& pack) {
|
|
13
|
+ auto entries = pack.GetEntries();
|
|
14
|
+ std::cout << "Total entries: " << entries.size() << std::endl;
|
|
15
|
+ for (auto entry: entries) {
|
|
16
|
+ std::cout << entry << std::endl;
|
|
17
|
+ }
|
|
18
|
+}
|
|
19
|
+
|
|
20
|
+int main(int argc, char *argv[])
|
|
21
|
+{
|
|
22
|
+ std::string packFile;
|
|
23
|
+ std::string action;
|
|
24
|
+
|
|
25
|
+ if (argc < 3) {
|
|
26
|
+ PrintUsage();
|
|
27
|
+ return -1;
|
|
28
|
+ }
|
|
29
|
+
|
|
30
|
+ action = argv[1];
|
|
31
|
+ packFile = argv[2];
|
|
32
|
+
|
|
33
|
+ olc::ResourcePack pack;
|
|
34
|
+ pack.LoadPack(packFile);
|
|
35
|
+
|
|
36
|
+ if (action == "--list") {
|
|
37
|
+ ListEntries(pack);
|
|
38
|
+ } else if (action == "--add" || action == "--remove") {
|
|
39
|
+ if (argc < 4) {
|
|
40
|
+ PrintUsage();
|
|
41
|
+ return -1;
|
|
42
|
+ }
|
|
43
|
+ for (int i = 3; i < argc; i++) {
|
|
44
|
+ std::string fileName = argv[i];
|
|
45
|
+ if (action == "--add") {
|
|
46
|
+ if (!pack.AddToPack(fileName)) {
|
|
47
|
+ std::cerr << "Could not open file " << fileName << std::endl;
|
|
48
|
+ return -3;
|
|
49
|
+ }
|
|
50
|
+ std::cout << "+ " << fileName << std::endl;
|
|
51
|
+ } else if (action == "--remove") {
|
|
52
|
+ if (!pack.RemoveFromPack(fileName)) {
|
|
53
|
+ std::cerr << "Could not open file " << fileName << std::endl;
|
|
54
|
+ return -3;
|
|
55
|
+ }
|
|
56
|
+ std::cout << "- " << fileName << std::endl;
|
|
57
|
+ }
|
|
58
|
+ }
|
|
59
|
+ std::cout << std::endl;
|
|
60
|
+ ListEntries(pack);
|
|
61
|
+ } else {
|
|
62
|
+ PrintUsage();
|
|
63
|
+ return -1;
|
|
64
|
+ }
|
|
65
|
+
|
|
66
|
+ pack.SavePack(packFile);
|
|
67
|
+
|
|
68
|
+ return 0;
|
|
69
|
+}
|