Geen omschrijving
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

packer.cpp 1.9KB

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