make_android_mono_config.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. def generate_compressed_config(config_src, output_dir):
  2. import os.path
  3. # Source file
  4. with open(os.path.join(output_dir, "android_mono_config.gen.cpp"), "w") as cpp:
  5. with open(config_src, "rb") as f:
  6. buf = f.read()
  7. decompr_size = len(buf)
  8. import zlib
  9. buf = zlib.compress(buf)
  10. compr_size = len(buf)
  11. bytes_seq_str = ""
  12. for i, buf_idx in enumerate(range(compr_size)):
  13. if i > 0:
  14. bytes_seq_str += ", "
  15. bytes_seq_str += str(buf[buf_idx])
  16. cpp.write(
  17. """/* THIS FILE IS GENERATED DO NOT EDIT */
  18. #include "android_mono_config.h"
  19. #ifdef ANDROID_ENABLED
  20. #include "core/io/compression.h"
  21. namespace {
  22. // config
  23. static const int config_compressed_size = %d;
  24. static const int config_uncompressed_size = %d;
  25. static const unsigned char config_compressed_data[] = { %s };
  26. } // namespace
  27. String get_godot_android_mono_config() {
  28. Vector<uint8_t> data;
  29. data.resize(config_uncompressed_size);
  30. uint8_t* w = data.ptrw();
  31. Compression::decompress(w, config_uncompressed_size, config_compressed_data,
  32. config_compressed_size, Compression::MODE_DEFLATE);
  33. String s;
  34. if (s.parse_utf8((const char *)w, data.size())) {
  35. ERR_FAIL_V(String());
  36. }
  37. return s;
  38. }
  39. #endif // ANDROID_ENABLED
  40. """
  41. % (compr_size, decompr_size, bytes_seq_str)
  42. )