CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/ELF/ParamSFO.h
Views: 1401
1
// Copyright (c) 2012- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#pragma once
19
20
#include <string>
21
#include <map>
22
#include <vector>
23
24
#include "Common/CommonTypes.h"
25
#include "Common/Log.h"
26
27
class Path;
28
29
class ParamSFOData
30
{
31
public:
32
void SetValue(const std::string &key, unsigned int value, int max_size);
33
void SetValue(const std::string &key, const std::string &value, int max_size);
34
void SetValue(const std::string &key, const u8 *value, unsigned int size, int max_size);
35
36
int GetValueInt(const std::string &key) const;
37
std::string GetValueString(const std::string &key) const;
38
bool HasKey(const std::string &key) const;
39
const u8 *GetValueData(const std::string &key, unsigned int *size) const;
40
41
std::vector<std::string> GetKeys() const;
42
std::string GenerateFakeID(const Path &filename) const;
43
44
std::string GetDiscID();
45
46
// This allocates a buffer (*paramsfo) using new[], whose size is zero-filled up to a multiple of 16 bytes.
47
// This is required for SavedataParam::BuildHash.
48
void WriteSFO(u8 **paramsfo, size_t *size) const;
49
50
bool ReadSFO(const u8 *paramsfo, size_t size);
51
bool ReadSFO(const std::vector<u8> &paramsfo) {
52
if (!paramsfo.empty()) {
53
return ReadSFO(&paramsfo[0], paramsfo.size());
54
} else {
55
return false;
56
}
57
}
58
59
// If not found, returns a negative value.
60
int GetDataOffset(const u8 *paramsfo, const char *dataName);
61
62
void Clear();
63
64
private:
65
enum ValueType
66
{
67
VT_INT,
68
VT_UTF8,
69
VT_UTF8_SPE // raw data in u8
70
};
71
72
class ValueData
73
{
74
public:
75
ValueType type = VT_INT;
76
int max_size = 0;
77
std::string s_value;
78
int i_value = 0;
79
80
u8* u_value = nullptr;
81
unsigned int u_size = 0;
82
83
void SetData(const u8* data, int size);
84
85
~ValueData() {
86
delete[] u_value;
87
}
88
};
89
90
std::map<std::string,ValueData> values;
91
};
92
93
94