innoextract.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * innoextract.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "innoextract.h"
  12. #ifdef ENABLE_INNOEXTRACT
  13. #include "cli/extract.hpp"
  14. #include "setup/version.hpp"
  15. #endif
  16. QString Innoextract::extract(QString installer, QString outDir, std::function<void (float percent)> cb)
  17. {
  18. QString errorText{};
  19. #ifdef ENABLE_INNOEXTRACT
  20. ::extract_options o;
  21. o.extract = true;
  22. // standard settings
  23. o.gog_galaxy = true;
  24. o.codepage = 0U;
  25. o.output_dir = outDir.toStdString();
  26. o.extract_temp = true;
  27. o.extract_unknown = true;
  28. o.filenames.set_expand(true);
  29. o.preserve_file_times = true; // also correctly closes file -> without it: on Windows the files are not written completely
  30. try
  31. {
  32. process_file(installer.toStdString(), o, cb);
  33. }
  34. catch(const std::ios_base::failure & e)
  35. {
  36. errorText = tr("Stream error while extracting files!\nerror reason: ");
  37. errorText += e.what();
  38. }
  39. catch(const format_error & e)
  40. {
  41. errorText = e.what();
  42. }
  43. catch(const std::runtime_error & e)
  44. {
  45. errorText = e.what();
  46. }
  47. catch(const setup::version_error &)
  48. {
  49. errorText = tr("Not a supported Inno Setup installer!");
  50. }
  51. #else
  52. errorText = tr("VCMI was compiled without innoextract support, which is needed to extract exe files!");
  53. #endif
  54. return errorText;
  55. }