loader.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <vector>
  6. #include "common/common.h"
  7. ////////////////////////////////////////////////////////////////////////////////////////////////////
  8. // Loader namespace
  9. namespace Loader {
  10. /// File types supported by CTR
  11. enum class FileType {
  12. Error,
  13. Unknown,
  14. CCI,
  15. CXI,
  16. CIA,
  17. ELF,
  18. BIN,
  19. THREEDSX, //3DSX
  20. };
  21. /// Return type for functions in Loader namespace
  22. enum class ResultStatus {
  23. Success,
  24. Error,
  25. ErrorInvalidFormat,
  26. ErrorNotImplemented,
  27. ErrorNotLoaded,
  28. ErrorNotUsed,
  29. ErrorAlreadyLoaded,
  30. ErrorMemoryAllocationFailed,
  31. };
  32. /// Interface for loading an application
  33. class AppLoader : NonCopyable {
  34. public:
  35. AppLoader() { }
  36. virtual ~AppLoader() { }
  37. /**
  38. * Load the application
  39. * @return ResultStatus result of function
  40. */
  41. virtual ResultStatus Load() = 0;
  42. /**
  43. * Get the code (typically .code section) of the application
  44. * @param buffer Reference to buffer to store data
  45. * @return ResultStatus result of function
  46. */
  47. virtual ResultStatus ReadCode(std::vector<u8>& buffer) const {
  48. return ResultStatus::ErrorNotImplemented;
  49. }
  50. /**
  51. * Get the icon (typically icon section) of the application
  52. * @param buffer Reference to buffer to store data
  53. * @return ResultStatus result of function
  54. */
  55. virtual ResultStatus ReadIcon(std::vector<u8>& buffer) const {
  56. return ResultStatus::ErrorNotImplemented;
  57. }
  58. /**
  59. * Get the banner (typically banner section) of the application
  60. * @param buffer Reference to buffer to store data
  61. * @return ResultStatus result of function
  62. */
  63. virtual ResultStatus ReadBanner(std::vector<u8>& buffer) const {
  64. return ResultStatus::ErrorNotImplemented;
  65. }
  66. /**
  67. * Get the logo (typically logo section) of the application
  68. * @param buffer Reference to buffer to store data
  69. * @return ResultStatus result of function
  70. */
  71. virtual ResultStatus ReadLogo(std::vector<u8>& buffer) const {
  72. return ResultStatus::ErrorNotImplemented;
  73. }
  74. /**
  75. * Get the RomFS of the application
  76. * @param buffer Reference to buffer to store data
  77. * @return ResultStatus result of function
  78. */
  79. virtual ResultStatus ReadRomFS(std::vector<u8>& buffer) const {
  80. return ResultStatus::ErrorNotImplemented;
  81. }
  82. };
  83. /**
  84. * Identifies the type of a bootable file
  85. * @param filename String filename of bootable file
  86. * @return FileType of file
  87. */
  88. FileType IdentifyFile(const std::string &filename);
  89. /**
  90. * Identifies and loads a bootable file
  91. * @param filename String filename of bootable file
  92. * @return ResultStatus result of function
  93. */
  94. ResultStatus LoadFile(const std::string& filename);
  95. } // namespace