From d2be5becccb403d2128157ee91bfc71c9176d467 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 2 Dec 2017 08:17:50 -0800 Subject: [PATCH] Savedata: Show icon for new saves more often. In fact, it may even be wrong to show the new data icon in this case... Also fixes crashes when save title is 128 characters long. Should improve #9632. --- Core/Dialog/PSPSaveDialog.cpp | 120 +++++++++++++++++++--------------- Core/Dialog/PSPSaveDialog.h | 2 +- Core/Dialog/SavedataParam.cpp | 12 ++-- Core/Dialog/SavedataParam.h | 2 +- 4 files changed, 74 insertions(+), 62 deletions(-) diff --git a/Core/Dialog/PSPSaveDialog.cpp b/Core/Dialog/PSPSaveDialog.cpp index 0236519962..c9dc744843 100755 --- a/Core/Dialog/PSPSaveDialog.cpp +++ b/Core/Dialog/PSPSaveDialog.cpp @@ -459,59 +459,71 @@ void PSPSaveDialog::DisplaySaveDataInfo1() } } -void PSPSaveDialog::DisplaySaveDataInfo2() -{ +void PSPSaveDialog::DisplaySaveDataInfo2(bool showNewData) { std::lock_guard guard(paramLock); - if (param.GetFileInfo(currentSelectedSave).size == 0) { - } else { - char txt[1024]; - char date[256]; - char am_pm[] = "AM"; - char hour_time[10] ; - int hour = param.GetFileInfo(currentSelectedSave).modif_time.tm_hour; - int min = param.GetFileInfo(currentSelectedSave).modif_time.tm_min; - switch (g_Config.iTimeFormat) { - case 1: - if (hour > 12) { - strcpy(am_pm, "PM"); - hour -= 12; - } - snprintf(hour_time,10,"%02d:%02d %s", hour, min, am_pm); - break; - case 2: - snprintf(hour_time,10,"%02d:%02d", hour, min); - break; - default: - if (hour > 12) { - strcpy(am_pm, "PM"); - hour -= 12; - } - snprintf(hour_time,10,"%02d:%02d %s", hour, min, am_pm); - } - const char *saveTitle = param.GetFileInfo(currentSelectedSave).saveTitle; - int day = param.GetFileInfo(currentSelectedSave).modif_time.tm_mday; - int month = param.GetFileInfo(currentSelectedSave).modif_time.tm_mon + 1; - int year = param.GetFileInfo(currentSelectedSave).modif_time.tm_year + 1900; - s64 sizeK = param.GetFileInfo(currentSelectedSave).size / 1024; - switch (g_Config.iDateFormat) { - case 1: - snprintf(date, 256, "%d/%02d/%02d", year, month, day); - break; - case 2: - snprintf(date, 256, "%02d/%02d/%d", month, day, year); - break; - case 3: - snprintf(date, 256, "%02d/%02d/%d", day, month, year); - break; - default: - snprintf(date, 256, "%d/%02d/%02d", year, month, day); - } - snprintf(txt, 1024, "%s\n%s %s\n%lld KB", saveTitle, date, hour_time, sizeK); - std::string saveinfoTxt = txt; - PPGeDrawText(saveinfoTxt.c_str(), 9, 202, PPGE_ALIGN_LEFT, 0.5f, CalcFadedColor(0x80000000)); - PPGeDrawText(saveinfoTxt.c_str(), 8, 200, PPGE_ALIGN_LEFT, 0.5f, CalcFadedColor(0xFFFFFFFF)); + tm modif_time; + const char *save_title; + u32 data_size; + + if (showNewData || param.GetFileInfo(currentSelectedSave).size == 0) { + time_t t; + time(&t); + localtime_r(&t, &modif_time); + save_title = param.GetPspParam()->sfoParam.savedataTitle; + // TODO: Account for icon, etc., etc. + data_size = param.GetPspParam()->dataSize; + } else { + modif_time = param.GetFileInfo(currentSelectedSave).modif_time; + save_title = param.GetFileInfo(currentSelectedSave).saveTitle; + data_size = param.GetFileInfo(currentSelectedSave).size; } + + char date[256]; + char am_pm[] = "AM"; + char hour_time[10] ; + int hour = modif_time.tm_hour; + int min = modif_time.tm_min; + switch (g_Config.iTimeFormat) { + case 1: + if (hour > 12) { + strcpy(am_pm, "PM"); + hour -= 12; + } + snprintf(hour_time, 10, "%02d:%02d %s", hour, min, am_pm); + break; + case 2: + snprintf(hour_time, 10, "%02d:%02d", hour, min); + break; + default: + if (hour > 12) { + strcpy(am_pm, "PM"); + hour -= 12; + } + snprintf(hour_time, 10, "%02d:%02d %s", hour, min, am_pm); + } + + int day = modif_time.tm_mday; + int month = modif_time.tm_mon + 1; + int year = modif_time.tm_year + 1900; + s64 sizeK = data_size / 1024; + switch (g_Config.iDateFormat) { + case 1: + snprintf(date, 256, "%d/%02d/%02d", year, month, day); + break; + case 2: + snprintf(date, 256, "%02d/%02d/%d", month, day, year); + break; + case 3: + snprintf(date, 256, "%02d/%02d/%d", day, month, year); + break; + default: + snprintf(date, 256, "%d/%02d/%02d", year, month, day); + } + + std::string saveinfoTxt = StringFromFormat("%.128s\n%s %s\n%lld KB", save_title, date, hour_time, sizeK); + PPGeDrawText(saveinfoTxt.c_str(), 9, 202, PPGE_ALIGN_LEFT, 0.5f, CalcFadedColor(0x80000000)); + PPGeDrawText(saveinfoTxt.c_str(), 8, 200, PPGE_ALIGN_LEFT, 0.5f, CalcFadedColor(0xFFFFFFFF)); } void PSPSaveDialog::DisplayMessage(std::string text, bool hasYesNo) @@ -637,7 +649,7 @@ int PSPSaveDialog::Update(int animSpeed) StartDraw(); DisplaySaveIcon(); - DisplaySaveDataInfo2(); + DisplaySaveDataInfo2(true); DisplayMessage(di->T("Confirm Save", "Do you want to save this data?"), true); @@ -687,7 +699,7 @@ int PSPSaveDialog::Update(int animSpeed) StartDraw(); DisplaySaveIcon(); - DisplaySaveDataInfo2(); + DisplaySaveDataInfo2(true); DisplayMessage(di->T("Saving","Saving\nPlease Wait...")); @@ -700,7 +712,7 @@ int PSPSaveDialog::Update(int animSpeed) StartDraw(); DisplaySaveIcon(); - DisplaySaveDataInfo2(); + DisplaySaveDataInfo2(true); DisplayMessage(di->T("SavingFailed", "Unable to save data.")); @@ -727,7 +739,7 @@ int PSPSaveDialog::Update(int animSpeed) StartDraw(); DisplaySaveIcon(); - DisplaySaveDataInfo2(); + DisplaySaveDataInfo2(true); DisplayMessage(di->T("Save completed")); diff --git a/Core/Dialog/PSPSaveDialog.h b/Core/Dialog/PSPSaveDialog.h index 128616f520..c0d42e4955 100644 --- a/Core/Dialog/PSPSaveDialog.h +++ b/Core/Dialog/PSPSaveDialog.h @@ -92,7 +92,7 @@ private: void DisplaySaveList(bool canMove = true); void DisplaySaveIcon(); void DisplaySaveDataInfo1(); - void DisplaySaveDataInfo2(); + void DisplaySaveDataInfo2(bool showNewData = false); void DisplayMessage(std::string text, bool hasYesNo = false); const std::string GetSelectedSaveDirName() const; diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index ac506478bc..ff5a6d964a 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -1456,8 +1456,7 @@ void SavedataParam::SetFileInfo(int idx, PSPFileInfo &info, std::string saveName saveDataList[idx].idx = idx; } -void SavedataParam::ClearFileInfo(SaveFileInfo &saveInfo, std::string saveName) -{ +void SavedataParam::ClearFileInfo(SaveFileInfo &saveInfo, const std::string &saveName) { saveInfo.size = 0; saveInfo.saveName = saveName; saveInfo.idx = 0; @@ -1468,16 +1467,17 @@ void SavedataParam::ClearFileInfo(SaveFileInfo &saveInfo, std::string saveName) saveInfo.texture = NULL; } - if (GetPspParam()->newData.IsValid() && GetPspParam()->newData->buf.IsValid()) - { + if (GetPspParam()->newData.IsValid() && GetPspParam()->newData->buf.IsValid()) { // We have a png to show - if (!noSaveIcon) - { + if (!noSaveIcon) { noSaveIcon = new SaveFileInfo(); PspUtilitySavedataFileData *newData = GetPspParam()->newData; noSaveIcon->texture = new PPGeImage(newData->buf.ptr, (SceSize)newData->size); } saveInfo.texture = noSaveIcon->texture; + } else if ((u32)GetPspParam()->mode == SCE_UTILITY_SAVEDATA_TYPE_SAVE && GetPspParam()->icon0FileData.buf.IsValid()) { + const PspUtilitySavedataFileData &icon0FileData = GetPspParam()->icon0FileData; + saveInfo.texture = new PPGeImage(icon0FileData.buf.ptr, (SceSize)icon0FileData.size); } } diff --git a/Core/Dialog/SavedataParam.h b/Core/Dialog/SavedataParam.h index cccfbfc108..0ea0e4ae61 100644 --- a/Core/Dialog/SavedataParam.h +++ b/Core/Dialog/SavedataParam.h @@ -352,7 +352,7 @@ private: void Clear(); void SetFileInfo(int idx, PSPFileInfo &info, std::string saveName); void SetFileInfo(SaveFileInfo &saveInfo, PSPFileInfo &info, std::string saveName); - void ClearFileInfo(SaveFileInfo &saveInfo, std::string saveName); + void ClearFileInfo(SaveFileInfo &saveInfo, const std::string &saveName); bool LoadSaveData(SceUtilitySavedataParam *param, const std::string &saveDirName, const std::string& dirPath, bool secureMode); void LoadCryptedSave(SceUtilitySavedataParam *param, u8 *data, u8 *saveData, int &saveSize, int prevCryptMode, bool &saveDone);