mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 05:19:56 +00:00
Use ReadEntireFile() a few more places.
This fixes one or two minor memory leaks.
This commit is contained in:
parent
2d3f0758c1
commit
0636a65ad9
@ -323,15 +323,11 @@ bool SavedataParam::Save(SceUtilitySavedataParam* param, const std::string &save
|
||||
ParamSFOData sfoFile;
|
||||
std::string sfopath = dirPath+"/" + SFO_FILENAME;
|
||||
PSPFileInfo sfoInfo = pspFileSystem.GetFileInfo(sfopath);
|
||||
if(sfoInfo.exists) // Read old sfo if exist
|
||||
if (sfoInfo.exists) // Read old sfo if exist
|
||||
{
|
||||
u8 *sfoData = new u8[(size_t)sfoInfo.size];
|
||||
size_t sfoSize = (size_t)sfoInfo.size;
|
||||
if(ReadPSPFile(sfopath,&sfoData,sfoSize, NULL))
|
||||
{
|
||||
sfoFile.ReadSFO(sfoData,sfoSize);
|
||||
delete[] sfoData;
|
||||
}
|
||||
std::vector<u8> sfoData;
|
||||
if (pspFileSystem.ReadEntireFile(sfopath, sfoData) >= 0)
|
||||
sfoFile.ReadSFO(sfoData);
|
||||
}
|
||||
|
||||
// Update values
|
||||
@ -566,12 +562,11 @@ void SavedataParam::LoadSFO(SceUtilitySavedataParam *param, const std::string di
|
||||
ParamSFOData sfoFile;
|
||||
std::string sfopath = dirPath+"/" + SFO_FILENAME;
|
||||
PSPFileInfo sfoInfo = pspFileSystem.GetFileInfo(sfopath);
|
||||
if(sfoInfo.exists) {
|
||||
// Read sfo
|
||||
u8 *sfoData = new u8[(size_t)sfoInfo.size];
|
||||
size_t sfoSize = (size_t)sfoInfo.size;
|
||||
if(ReadPSPFile(sfopath,&sfoData,sfoSize, NULL)) {
|
||||
sfoFile.ReadSFO(sfoData,sfoSize);
|
||||
if (sfoInfo.exists) {
|
||||
// Read sfo
|
||||
std::vector<u8> sfoData;
|
||||
if (pspFileSystem.ReadEntireFile(sfopath, sfoData) >= 0) {
|
||||
sfoFile.ReadSFO(sfoData);
|
||||
|
||||
// copy back info in request
|
||||
strncpy(param->sfoParam.title,sfoFile.GetValueString("TITLE").c_str(),128);
|
||||
@ -579,43 +574,40 @@ void SavedataParam::LoadSFO(SceUtilitySavedataParam *param, const std::string di
|
||||
strncpy(param->sfoParam.detail,sfoFile.GetValueString("SAVEDATA_DETAIL").c_str(),1024);
|
||||
param->sfoParam.parentalLevel = sfoFile.GetValueInt("PARENTAL_LEVEL");
|
||||
}
|
||||
delete[] sfoData;
|
||||
}
|
||||
}
|
||||
|
||||
std::set<std::string> SavedataParam::getSecureFileNames(std::string dirPath) {
|
||||
PSPFileInfo sfoFileInfo = pspFileSystem.GetFileInfo(dirPath + "/" + SFO_FILENAME);
|
||||
std::set<std::string> secureFileNames;
|
||||
if(!sfoFileInfo.exists)
|
||||
return secureFileNames;
|
||||
|
||||
ParamSFOData sfoFile;
|
||||
size_t sfoSize = (size_t)sfoFileInfo.size;
|
||||
u8 *sfoData = new u8[sfoSize];
|
||||
if (ReadPSPFile(dirPath + "/" + SFO_FILENAME, &sfoData, sfoSize, NULL)){
|
||||
sfoFile.ReadSFO(sfoData, sfoSize);
|
||||
}
|
||||
delete[] sfoData;
|
||||
|
||||
u32 sfoFileListSize = 0;
|
||||
char *sfoFileList = (char *)sfoFile.GetValueData("SAVEDATA_FILE_LIST", &sfoFileListSize);
|
||||
const int FILE_LIST_ITEM_SIZE = 13 + 16 + 3;
|
||||
const u32 FILE_LIST_COUNT_MAX = 99;
|
||||
|
||||
// Filenames are 13 bytes long at most. Add a NULL so there's no surprises.
|
||||
char temp[14];
|
||||
temp[13] = '\0';
|
||||
|
||||
for (u32 i = 0; i < FILE_LIST_COUNT_MAX; ++i) {
|
||||
// Ends at a NULL filename.
|
||||
if (i * FILE_LIST_ITEM_SIZE >= sfoFileListSize || sfoFileList[i * FILE_LIST_ITEM_SIZE] == '\0') {
|
||||
break;
|
||||
}
|
||||
|
||||
strncpy(temp, &sfoFileList[i * FILE_LIST_ITEM_SIZE], 13);
|
||||
secureFileNames.insert(temp);
|
||||
}
|
||||
PSPFileInfo sfoFileInfo = pspFileSystem.GetFileInfo(dirPath + "/" + SFO_FILENAME);
|
||||
std::set<std::string> secureFileNames;
|
||||
if (!sfoFileInfo.exists)
|
||||
return secureFileNames;
|
||||
|
||||
ParamSFOData sfoFile;
|
||||
std::vector<u8> sfoData;
|
||||
if (pspFileSystem.ReadEntireFile(dirPath + "/" + SFO_FILENAME, sfoData) >= 0) {
|
||||
sfoFile.ReadSFO(sfoData);
|
||||
}
|
||||
|
||||
u32 sfoFileListSize = 0;
|
||||
char *sfoFileList = (char *)sfoFile.GetValueData("SAVEDATA_FILE_LIST", &sfoFileListSize);
|
||||
const int FILE_LIST_ITEM_SIZE = 13 + 16 + 3;
|
||||
const u32 FILE_LIST_COUNT_MAX = 99;
|
||||
|
||||
// Filenames are 13 bytes long at most. Add a NULL so there's no surprises.
|
||||
char temp[14];
|
||||
temp[13] = '\0';
|
||||
|
||||
for (u32 i = 0; i < FILE_LIST_COUNT_MAX; ++i) {
|
||||
// Ends at a NULL filename.
|
||||
if (i * FILE_LIST_ITEM_SIZE >= sfoFileListSize || sfoFileList[i * FILE_LIST_ITEM_SIZE] == '\0') {
|
||||
break;
|
||||
}
|
||||
|
||||
strncpy(temp, &sfoFileList[i * FILE_LIST_ITEM_SIZE], 13);
|
||||
secureFileNames.insert(temp);
|
||||
}
|
||||
return secureFileNames;
|
||||
}
|
||||
|
||||
void SavedataParam::LoadFile(const std::string dirPath, const std::string filename, PspUtilitySavedataFileData *fileData) {
|
||||
@ -1272,16 +1264,15 @@ void SavedataParam::SetFileInfo(SaveFileInfo &saveInfo, PSPFileInfo &info, std::
|
||||
info2 = pspFileSystem.GetFileInfo(fileDataPath2);
|
||||
if (info2.exists)
|
||||
{
|
||||
u8 *sfoParam = new u8[(size_t)info2.size];
|
||||
ReadPSPFile(fileDataPath2, &sfoParam, info2.size, NULL);
|
||||
std::vector<u8> sfoData;
|
||||
pspFileSystem.ReadEntireFile(fileDataPath2, sfoData);
|
||||
ParamSFOData sfoFile;
|
||||
if (sfoFile.ReadSFO(sfoParam,(size_t)info2.size))
|
||||
if (sfoFile.ReadSFO(sfoData))
|
||||
{
|
||||
SetStringFromSFO(sfoFile, "TITLE", saveInfo.title, sizeof(saveInfo.title));
|
||||
SetStringFromSFO(sfoFile, "SAVEDATA_TITLE", saveInfo.saveTitle, sizeof(saveInfo.saveTitle));
|
||||
SetStringFromSFO(sfoFile, "SAVEDATA_DETAIL", saveInfo.saveDetail, sizeof(saveInfo.saveDetail));
|
||||
}
|
||||
delete [] sfoParam;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1501,11 +1492,10 @@ bool SavedataParam::IsSaveEncrypted(SceUtilitySavedataParam* param, const std::s
|
||||
PSPFileInfo sfoInfo = pspFileSystem.GetFileInfo(sfopath);
|
||||
if(sfoInfo.exists) // Read sfo
|
||||
{
|
||||
u8 *sfoData = new u8[(size_t)sfoInfo.size];
|
||||
size_t sfoSize = (size_t)sfoInfo.size;
|
||||
if(ReadPSPFile(sfopath,&sfoData,sfoSize, NULL))
|
||||
std::vector<u8> sfoData;
|
||||
if (pspFileSystem.ReadEntireFile(sfopath, sfoData) >= 0)
|
||||
{
|
||||
sfoFile.ReadSFO(sfoData,sfoSize);
|
||||
sfoFile.ReadSFO(sfoData);
|
||||
|
||||
// save created in PPSSPP and not encrypted has '0' in SAVEDATA_PARAMS
|
||||
u32 tmpDataSize = 0;
|
||||
@ -1519,7 +1509,6 @@ bool SavedataParam::IsSaveEncrypted(SceUtilitySavedataParam* param, const std::s
|
||||
}
|
||||
}
|
||||
}
|
||||
delete[] sfoData;
|
||||
}
|
||||
return isCrypted;
|
||||
}
|
||||
|
@ -37,6 +37,10 @@ public:
|
||||
bool ReadSFO(const u8 *paramsfo, size_t size);
|
||||
bool WriteSFO(u8 **paramsfo, size_t *size);
|
||||
|
||||
bool ReadSFO(const std::vector<u8> ¶msfo) {
|
||||
return ReadSFO(¶msfo[0], paramsfo.size());
|
||||
}
|
||||
|
||||
int GetDataOffset(const u8 *paramsfo, std::string dataName);
|
||||
|
||||
private:
|
||||
|
@ -517,7 +517,7 @@ size_t MetaFileSystem::SeekFile(u32 handle, s32 position, FileMove type)
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 MetaFileSystem::ReadEntireFile(const std::string &filename, std::string &data) {
|
||||
u32 MetaFileSystem::ReadEntireFile(const std::string &filename, std::vector<u8> &data) {
|
||||
int error = 0;
|
||||
u32 handle = pspFileSystem.OpenWithError(error, filename, FILEACCESS_READ);
|
||||
if (handle == 0)
|
||||
|
@ -106,7 +106,7 @@ public:
|
||||
// TODO: void IoCtl(...)
|
||||
|
||||
// Convenience helper - returns < 0 on failure.
|
||||
u32 ReadEntireFile(const std::string &filename, std::string &data);
|
||||
u32 ReadEntireFile(const std::string &filename, std::vector<u8> &data);
|
||||
|
||||
void SetStartingDirectory(const std::string &dir) {
|
||||
lock_guard guard(lock);
|
||||
|
@ -130,30 +130,19 @@ public:
|
||||
}
|
||||
|
||||
Font(const u8 *data, size_t dataSize) {
|
||||
pgf_.ReadPtr(data, dataSize);
|
||||
style_.fontH = (float)pgf_.header.hSize / 64.0f;
|
||||
style_.fontV = (float)pgf_.header.vSize / 64.0f;
|
||||
style_.fontHRes = (float)pgf_.header.hResolution / 64.0f;
|
||||
style_.fontVRes = (float)pgf_.header.vResolution / 64.0f;
|
||||
Init(data, dataSize);
|
||||
}
|
||||
|
||||
Font(const u8 *data, size_t dataSize, const FontRegistryEntry &entry) {
|
||||
pgf_.ReadPtr(data, dataSize);
|
||||
style_.fontH = entry.hSize / 64.f;
|
||||
style_.fontV = entry.vSize / 64.f;
|
||||
style_.fontHRes = entry.hResolution / 64.f;
|
||||
style_.fontVRes = entry.vResolution / 64.f;
|
||||
style_.fontWeight = (float)entry.weight;
|
||||
style_.fontFamily = (u16)entry.familyCode;
|
||||
style_.fontStyle = (u16)entry.style;
|
||||
style_.fontStyleSub = (u16)entry.styleSub;
|
||||
style_.fontLanguage = (u16)entry.languageCode;
|
||||
style_.fontRegion = (u16)entry.regionCode;
|
||||
style_.fontCountry = (u16)entry.countryCode;
|
||||
strncpy(style_.fontName, entry.fontName, sizeof(style_.fontName));
|
||||
strncpy(style_.fontFileName, entry.fileName, sizeof(style_.fontFileName));
|
||||
style_.fontAttributes = entry.extraAttributes;
|
||||
style_.fontExpire = entry.expireDate;
|
||||
Init(data, dataSize, entry);
|
||||
}
|
||||
|
||||
Font (const std::vector<u8> &data) {
|
||||
Init(&data[0], data.size());
|
||||
}
|
||||
|
||||
Font (const std::vector<u8> &data, const FontRegistryEntry &entry) {
|
||||
Init(&data[0], data.size(), entry);
|
||||
}
|
||||
|
||||
const PGFFontStyle &GetFontStyle() const { return style_; }
|
||||
@ -210,6 +199,33 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
void Init(const u8 *data, size_t dataSize) {
|
||||
pgf_.ReadPtr(data, dataSize);
|
||||
style_.fontH = (float)pgf_.header.hSize / 64.0f;
|
||||
style_.fontV = (float)pgf_.header.vSize / 64.0f;
|
||||
style_.fontHRes = (float)pgf_.header.hResolution / 64.0f;
|
||||
style_.fontVRes = (float)pgf_.header.vResolution / 64.0f;
|
||||
}
|
||||
|
||||
void Init(const u8 *data, size_t dataSize, const FontRegistryEntry &entry) {
|
||||
pgf_.ReadPtr(data, dataSize);
|
||||
style_.fontH = entry.hSize / 64.f;
|
||||
style_.fontV = entry.vSize / 64.f;
|
||||
style_.fontHRes = entry.hResolution / 64.f;
|
||||
style_.fontVRes = entry.vResolution / 64.f;
|
||||
style_.fontWeight = (float)entry.weight;
|
||||
style_.fontFamily = (u16)entry.familyCode;
|
||||
style_.fontStyle = (u16)entry.style;
|
||||
style_.fontStyleSub = (u16)entry.styleSub;
|
||||
style_.fontLanguage = (u16)entry.languageCode;
|
||||
style_.fontRegion = (u16)entry.regionCode;
|
||||
style_.fontCountry = (u16)entry.countryCode;
|
||||
strncpy(style_.fontName, entry.fontName, sizeof(style_.fontName));
|
||||
strncpy(style_.fontFileName, entry.fileName, sizeof(style_.fontFileName));
|
||||
style_.fontAttributes = entry.extraAttributes;
|
||||
style_.fontExpire = entry.expireDate;
|
||||
}
|
||||
|
||||
PGF pgf_;
|
||||
PGFFontStyle style_;
|
||||
DISALLOW_COPY_AND_ASSIGN(Font);
|
||||
@ -499,11 +515,9 @@ void __LoadInternalFonts() {
|
||||
|
||||
if (info.exists) {
|
||||
INFO_LOG(SCEFONT, "Loading font %s (%i bytes)", fontFilename.c_str(), (int)info.size);
|
||||
u8 *buffer = new u8[(size_t)info.size];
|
||||
u32 handle = pspFileSystem.OpenFile(fontFilename, FILEACCESS_READ);
|
||||
if (!handle) {
|
||||
std::vector<u8> buffer;
|
||||
if (pspFileSystem.ReadEntireFile(fontFilename, buffer) < 0) {
|
||||
ERROR_LOG(SCEFONT, "Failed opening font");
|
||||
delete [] buffer;
|
||||
continue;
|
||||
}
|
||||
// Our provided font of jpn0.pgf has size 4367080 bytes
|
||||
@ -511,16 +525,12 @@ void __LoadInternalFonts() {
|
||||
if (std::string(entry.fileName) == "jpn0.pgf" && (int)info.size == 4367080) {
|
||||
packagedFont = true;
|
||||
}
|
||||
|
||||
pspFileSystem.ReadFile(handle, buffer, info.size);
|
||||
pspFileSystem.CloseFile(handle);
|
||||
|
||||
internalFonts.push_back(new Font(buffer, (size_t)info.size, entry));
|
||||
internalFonts.push_back(new Font(buffer, entry));
|
||||
|
||||
delete [] buffer;
|
||||
INFO_LOG(SCEFONT, "Loaded font %s", fontFilename.c_str());
|
||||
DEBUG_LOG(SCEFONT, "Loaded font %s", fontFilename.c_str());
|
||||
} else {
|
||||
INFO_LOG(SCEFONT, "Font file not found: %s", fontFilename.c_str());
|
||||
WARN_LOG(SCEFONT, "Font file not found: %s", fontFilename.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -707,13 +717,9 @@ u32 sceFontOpenUserFile(u32 libHandle, const char *fileName, u32 mode, u32 error
|
||||
return 0;
|
||||
}
|
||||
|
||||
u8 *buffer = new u8[(size_t)info.size];
|
||||
|
||||
u32 fileHandle = pspFileSystem.OpenFile(fileName, FILEACCESS_READ);
|
||||
pspFileSystem.ReadFile(fileHandle, buffer, info.size);
|
||||
pspFileSystem.CloseFile(fileHandle);
|
||||
|
||||
LoadedFont *font = fontLib->OpenFont(new Font(buffer, (size_t)info.size));
|
||||
std::vector<u8> buffer;
|
||||
pspFileSystem.ReadEntireFile(fileName, buffer);
|
||||
LoadedFont *font = fontLib->OpenFont(new Font(buffer));
|
||||
if (font) {
|
||||
fontMap[font->Handle()] = font;
|
||||
Memory::Write_U32(0, errorCodePtr);
|
||||
|
@ -488,7 +488,7 @@ namespace MIPSAnalyst {
|
||||
|
||||
// Yay, found a function.
|
||||
Function &f = *(iter->second);
|
||||
if (f.hash = mf->hash && f.size == mf->size) {
|
||||
if (f.hash == mf->hash && f.size == mf->size) {
|
||||
strncpy(f.name, mf->name, sizeof(mf->name) - 1);
|
||||
|
||||
const char *existingLabel = symbolMap.GetLabelName(f.start);
|
||||
|
@ -81,11 +81,9 @@ void InitMemoryForGameISO(std::string fileToStart) {
|
||||
|
||||
if (fileInfo.exists)
|
||||
{
|
||||
u8 *paramsfo = new u8[(size_t)fileInfo.size];
|
||||
u32 fd = pspFileSystem.OpenFile(sfoPath, FILEACCESS_READ);
|
||||
pspFileSystem.ReadFile(fd, paramsfo, fileInfo.size);
|
||||
pspFileSystem.CloseFile(fd);
|
||||
if (g_paramSFO.ReadSFO(paramsfo, (size_t)fileInfo.size))
|
||||
std::vector<u8> paramsfo;
|
||||
pspFileSystem.ReadEntireFile(sfoPath, paramsfo);
|
||||
if (g_paramSFO.ReadSFO(paramsfo))
|
||||
{
|
||||
gameID = g_paramSFO.GetValueString("DISC_ID");
|
||||
|
||||
@ -100,7 +98,6 @@ void InitMemoryForGameISO(std::string fileToStart) {
|
||||
}
|
||||
DEBUG_LOG(LOADER, "HDRemaster mode is %s", g_RemasterMode? "true": "false");
|
||||
}
|
||||
delete [] paramsfo;
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,18 +109,15 @@ bool Load_PSP_ISO(const char *filename, std::string *error_string)
|
||||
PSPFileInfo fileInfo = pspFileSystem.GetFileInfo(sfoPath.c_str());
|
||||
if (fileInfo.exists)
|
||||
{
|
||||
u8 *paramsfo = new u8[(size_t)fileInfo.size];
|
||||
u32 fd = pspFileSystem.OpenFile(sfoPath, FILEACCESS_READ);
|
||||
pspFileSystem.ReadFile(fd, paramsfo, fileInfo.size);
|
||||
pspFileSystem.CloseFile(fd);
|
||||
if (g_paramSFO.ReadSFO(paramsfo, (size_t)fileInfo.size))
|
||||
std::vector<u8> paramsfo;
|
||||
pspFileSystem.ReadEntireFile(sfoPath, paramsfo);
|
||||
if (g_paramSFO.ReadSFO(paramsfo))
|
||||
{
|
||||
char title[1024];
|
||||
sprintf(title, "%s : %s", g_paramSFO.GetValueString("DISC_ID").c_str(), g_paramSFO.GetValueString("TITLE").c_str());
|
||||
INFO_LOG(LOADER, "%s", title);
|
||||
host->SetWindowTitle(title);
|
||||
}
|
||||
delete [] paramsfo;
|
||||
}
|
||||
|
||||
|
||||
|
@ -158,7 +158,7 @@ bool GameManager::InstallGame(std::string zipfile, bool deleteAfter) {
|
||||
if (zippedName[i] == '/') {
|
||||
slashCount++;
|
||||
slashLocation = lastSlashLocation;
|
||||
lastSlashLocation = i;
|
||||
lastSlashLocation = (int)i;
|
||||
}
|
||||
}
|
||||
if (slashCount >= 1 && (!isPSP || slashLocation < stripChars + 1)) {
|
||||
|
@ -830,7 +830,7 @@ bool PPGeImage::Load() {
|
||||
if (filename_.empty()) {
|
||||
success = pngLoadPtr(Memory::GetPointer(png_), size_, &width_, &height_, &textureData, false);
|
||||
} else {
|
||||
std::string pngData;
|
||||
std::vector<u8> pngData;
|
||||
if (pspFileSystem.ReadEntireFile(filename_, pngData) < 0) {
|
||||
WARN_LOG(SCEGE, "Bad PPGeImage - cannot load file");
|
||||
return false;
|
||||
|
@ -571,7 +571,7 @@ void DrawDownloadsOverlay(UIContext &ctx) {
|
||||
|
||||
ctx.Begin();
|
||||
int h = 5;
|
||||
for (int i = 0; i < progress.size(); i++) {
|
||||
for (size_t i = 0; i < progress.size(); i++) {
|
||||
float barWidth = 10 + (dp_xres - 10) * progress[i];
|
||||
Bounds bounds(0, h * i, barWidth, h);
|
||||
UI::Drawable solid(colors[i & 3]);
|
||||
|
Loading…
Reference in New Issue
Block a user