duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

psf_loader.h (1476B)


      1 // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
      2 // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
      3 
      4 #pragma once
      5 
      6 #include "types.h"
      7 
      8 #include <map>
      9 #include <optional>
     10 #include <string>
     11 #include <vector>
     12 
     13 class Error;
     14 
     15 namespace PSFLoader {
     16 
     17 #pragma pack(push, 1)
     18 struct PSFHeader
     19 {
     20   u8 id[3];
     21   u8 version;
     22   u32 reserved_area_size;
     23   u32 compressed_program_size;
     24   u32 program_crc32;
     25 };
     26 #pragma pack(pop)
     27 
     28 class File
     29 {
     30 public:
     31   using TagMap = std::map<std::string, std::string>;
     32   using ProgramData = std::vector<u8>;
     33 
     34   ALWAYS_INLINE const ProgramData& GetProgramData() const { return m_program_data; }
     35   ALWAYS_INLINE const TagMap& GetTagMap() const { return m_tags; }
     36   ALWAYS_INLINE DiscRegion GetRegion() const { return m_region; }
     37 
     38   std::optional<std::string> GetTagString(const char* tag_name) const;
     39   std::optional<int> GetTagInt(const char* tag_name) const;
     40   std::optional<float> GetTagFloat(const char* tag_name) const;
     41 
     42   std::string GetTagString(const char* tag_name, const char* default_value) const;
     43   int GetTagInt(const char* tag_name, int default_value) const;
     44   float GetTagFloat(const char* tag_name, float default_value) const;
     45 
     46   bool Load(const char* path, Error* error);
     47 
     48 private:
     49   enum : u32
     50   {
     51     MAX_PROGRAM_SIZE = 2 * 1024 * 1024
     52   };
     53 
     54   ProgramData m_program_data;
     55   TagMap m_tags;
     56   DiscRegion m_region = DiscRegion::Other;
     57 };
     58 
     59 bool Load(const std::string& path, Error* error);
     60 
     61 } // namespace PSFLoader