lzs.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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/LzsFile.h"
  29. using std::cout;
  30. using std::endl;
  31. namespace bfs = boost::filesystem;
  32. namespace bpo = boost::program_options;
  33. void decompress( const bfs::path &file_in, const bfs::path &file_out )
  34. {
  35. LzsFile lzs( file_in.string() );
  36. lzs.WriteFile( file_out.string() );
  37. }
  38. int
  39. main(int ac, char *av[])
  40. {
  41. const char* PO_HELP( "help" );
  42. const char* PO_INPUT_FILE( "input-file" );
  43. const char* PO_OUTPUT_FILE( "output-file" );
  44. try {
  45. bpo::options_description generic("Generic options");
  46. generic.add_options()
  47. ( PO_HELP, "produce help message" )
  48. ;
  49. // Hidden options, will be allowed both on command line and
  50. // in config file, but will not be shown to the user.
  51. bpo::options_description hidden("Hidden options");
  52. hidden.add_options()
  53. ( PO_INPUT_FILE , bpo::value< bfs::path >()->required(), "lzs compressed file" )
  54. ( PO_OUTPUT_FILE, bpo::value< bfs::path >()->required(), "output file" )
  55. ;
  56. bpo::positional_options_description p;
  57. p.add( PO_INPUT_FILE , 1 )
  58. .add( PO_OUTPUT_FILE, 1 );
  59. bpo::options_description cmdline_options;
  60. cmdline_options.add( generic ).add( hidden );
  61. bpo::variables_map vm;
  62. bpo::store( bpo::command_line_parser( ac, av ).options( cmdline_options ).positional( p ).run(), vm );
  63. bfs::path self( av[0] );
  64. if ( vm.count( PO_HELP ) )
  65. {
  66. cout << "Usage: " << self.stem().string()
  67. << " [options]"
  68. << " " << PO_INPUT_FILE
  69. << " " << PO_OUTPUT_FILE
  70. << endl
  71. << generic << "\n";
  72. return 0;
  73. }
  74. bpo::notify( vm );
  75. // TODO implement compression?
  76. LOGGER = new Logger( self.stem().string() + ".log" );
  77. decompress( vm[ PO_INPUT_FILE ].as< bfs::path >(), vm[ PO_OUTPUT_FILE ].as< bfs::path >() );
  78. }
  79. catch( std::exception& e )
  80. {
  81. cout << e.what() << endl;
  82. return 1;
  83. }
  84. return 0;
  85. }