Subversion Repositories ipe_artfile_utils

Rev

Blame | Last modification | View Log | RSS feed

  1. /**
  2.  * ART file unpacker by Daniel Marschall, ViaThinkSoft (C) 2014-2018
  3.  * Supports:
  4.  * - Blown Away - The Interactive Game by Imagination Pilots
  5.  * - Panic in the Park - The Interactive Game by Imagination Pilots
  6.  * - Where's Waldo? At the Circus (Waldo1)
  7.  * - Where's Waldo? Exploring Geography
  8.  * - Eraser Turnabout by Imagination Pilots
  9.  * - Virtual K'Nex by Imagination Pilots
  10.  * Revision: 2018-02-15
  11.  **/
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <assert.h>
  16. #include <string.h>
  17. #include <getopt.h>
  18.  
  19. #include "ipe16_artfile.h"
  20. #include "ipe32_artfile.h"
  21.  
  22. #include "ipe_artfile_unpacker_ipe16.h"
  23. #include "ipe_artfile_unpacker_ipe32.h"
  24.  
  25. #define VERSION "2018-02-15"
  26.  
  27. void print_syntax() {
  28.         fprintf(stderr, "Syntax: -v [-o <outputdir>] -i <artfile>\n");
  29.         fprintf(stderr, "   -v : verbose output\n");
  30.         fprintf(stderr, "Runs in simulation mode if no output directory is defined.\n");
  31. }
  32.  
  33. int main(int argc, char *argv[]) {
  34.         int verbosity = 0;
  35.         char* szOutputDir = "";
  36.         char* szArtFile = "";
  37.         int c;
  38.  
  39.         #define PRINT_SYNTAX { print_syntax(); return 0; }
  40.  
  41.         while ((c = getopt(argc, argv, "Vvi:o:")) != -1) {
  42.                 switch (c) {
  43.                         case 'v':
  44.                                 verbosity++;
  45.                                 break;
  46.                         case 'V':
  47.                                 fprintf(stdout, "IPE Artfile unpacker, revision %s\n", VERSION);
  48.                                 return 0;
  49.                         case 'i':
  50.                                 szArtFile = optarg;
  51.                                 break;
  52.                         case 'o':
  53.                                 szOutputDir = optarg;
  54.                                 break;
  55.                         case '?':
  56.                                 PRINT_SYNTAX;
  57.                                 break;
  58.                 }
  59.         }
  60.         if (optind < argc) PRINT_SYNTAX;
  61.  
  62.         if (strlen(szArtFile) == 0) PRINT_SYNTAX;
  63.  
  64.         FILE* fibArt = fopen(szArtFile, "rb");
  65.         if (!fibArt) {
  66.                 fprintf(stderr, "FATAL: Cannot open %s\n", szArtFile);
  67.                 return 1;
  68.         }
  69.  
  70.         char signature[9]={0};
  71.         if (fread(&signature, 8, 1, fibArt) != 1) {
  72.                 fprintf(stderr, "FATAL: Cannot read signature of %s\n", szArtFile);
  73.                 return 1;
  74.         }
  75.         if (strcmp(signature, IPE32_MAGIC_ART) == 0) {
  76.                 if (verbosity >= 1) fprintf(stdout, "%s: Detected file as IPE32 (Waldo2/Eraser/K'Nex) art file\n", szArtFile);
  77.                 return ipe32_extract_art_to_folder(fibArt, szOutputDir, verbosity) ? 0 : 1;
  78.         } else if (strcmp(signature, IPE16_MAGIC_ART) == 0) {
  79.                 if (verbosity >= 1) fprintf(stdout, "%s: Detected file as IPE16 (BA/PiP/Waldo1) art file\n", szArtFile);
  80.                 return ipe16_extract_art_to_folder(fibArt, szOutputDir, verbosity) ? 0 : 1;
  81.         } else {
  82.                 fprintf(stderr, "FATAL: %s is not a valid ART file of Imagination Pilots!\n", szArtFile);
  83.                 return 1;
  84.         }
  85.  
  86.         fclose(fibArt);
  87. }
  88.