flevel.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. -----------------------------------------------------------------------------
  3. The MIT License (MIT)
  4. Copyright (c) 2013-07-31 Tobias Peters <tobias.peters@kreativeffekt.at>
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. -----------------------------------------------------------------------------
  21. */
  22. #include <cstdio>
  23. #include <iostream>
  24. #include <boost/filesystem.hpp>
  25. #include <boost/program_options.hpp>
  26. #include "common/FileSystem.h"
  27. #include "common/Logger.h"
  28. //#include "common/VGearsFLevelFile.h"
  29. using std::cout;
  30. using std::endl;
  31. namespace bfs = boost::filesystem;
  32. namespace bpo = boost::program_options;
  33. void extractSections( const bfs::path &file_in, const bfs::path &path_out )
  34. {
  35. /*
  36. File f( file_in.string() );
  37. // TODO alternative implementation adapted to FLevel Resource
  38. VGears::FLevelFile flevel( &f );
  39. File** sections( flevel.getSections() );
  40. bfs::path file_out;
  41. file_out = path_out / ( file_in.stem().string() + ".script" );
  42. sections[0]->WriteFile( file_out.string() );
  43. file_out = path_out / ( file_in.stem().string() + ".cam_matrix" );
  44. sections[1]->WriteFile( file_out.string() );
  45. file_out = path_out / ( file_in.stem().string() + ".model_loader" );
  46. sections[2]->WriteFile( file_out.string() );
  47. file_out = path_out / ( file_in.stem().string() + ".palette" );
  48. sections[3]->WriteFile( file_out.string() );
  49. file_out = path_out / ( file_in.stem().string() + ".walkmesh" );
  50. sections[4]->WriteFile( file_out.string() );
  51. file_out = path_out / ( file_in.stem().string() + ".tilemap" );
  52. sections[5]->WriteFile( file_out.string() );
  53. file_out = path_out / ( file_in.stem().string() + ".encounter" );
  54. sections[6]->WriteFile( file_out.string() );
  55. file_out = path_out / ( file_in.stem().string() + ".trigger" );
  56. sections[7]->WriteFile( file_out.string() );
  57. file_out = path_out / ( file_in.stem().string() + ".background.ppm" );
  58. sections[8]->WriteFile( file_out.string() );
  59. file_out = path_out / ( file_in.stem().string() + ".background" );
  60. sections[9]->WriteFile( file_out.string() );
  61. */
  62. }
  63. int
  64. main(int ac, char *av[])
  65. {
  66. const char* PO_HELP( "help" );
  67. const char* PO_INPUT_FILE( "input-file" );
  68. const char* PO_OUTPUT_PATH( "output-path" );
  69. try {
  70. bpo::options_description generic("Generic options");
  71. generic.add_options()
  72. ( PO_HELP, "produce help message" )
  73. ;
  74. // Hidden options, will be allowed both on command line and
  75. // in config file, but will not be shown to the user.
  76. bpo::options_description hidden("Hidden options");
  77. hidden.add_options()
  78. ( PO_INPUT_FILE , bpo::value< bfs::path >()->required(), "lzs compressed file" )
  79. ( PO_OUTPUT_PATH
  80. , bpo::value< bfs::path >()->default_value( "." )
  81. , "path to output section files"
  82. )
  83. ;
  84. bpo::positional_options_description p;
  85. p.add( PO_INPUT_FILE , 1 )
  86. .add( PO_OUTPUT_PATH, 1 );
  87. bpo::options_description cmdline_options;
  88. cmdline_options.add( generic ).add( hidden );
  89. bpo::variables_map vm;
  90. bpo::store( bpo::command_line_parser( ac, av ).options( cmdline_options ).positional( p ).run(), vm );
  91. bfs::path self( av[0] );
  92. if ( vm.count( PO_HELP ) )
  93. {
  94. cout << "Usage: " << self.stem().string()
  95. << " [options]"
  96. << " " << PO_INPUT_FILE
  97. << " " << PO_OUTPUT_PATH
  98. << endl
  99. << generic << "\n";
  100. return 0;
  101. }
  102. bpo::notify( vm );
  103. // TODO implement compression?
  104. LOGGER = new Logger( self.stem().string() + ".log" );
  105. extractSections( vm[ PO_INPUT_FILE ].as< bfs::path >(), vm[ PO_OUTPUT_PATH ].as< bfs::path >() );
  106. }
  107. catch( std::exception& e )
  108. {
  109. cout << e.what() << endl;
  110. return 1;
  111. }
  112. return 0;
  113. }