Skip to content

Commit cbac839

Browse files
committed
Add secure value import upon restore from folder.
1 parent 24f9699 commit cbac839

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

JKSM/source/AppStates/BackupMenuState.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ typedef struct
2424
Data::SaveDataType SaveType;
2525
const Data::TitleData *TargetTitle;
2626
BackupMenuState *CallingState = nullptr;
27-
uint32_t UniqueID = 0;
2827
} TargetStruct;
2928

3029
// Declarations. Definitions after class members.
@@ -124,8 +123,8 @@ void BackupMenuState::Update(void)
124123
// Create confirmation struct.
125124
std::shared_ptr<TargetStruct> ConfirmStruct(new TargetStruct);
126125
ConfirmStruct->TargetPath = m_DirectoryPath / m_DirectoryListing[m_BackupMenu.GetSelected() - 1];
127-
ConfirmStruct->UniqueID = m_Data->GetUniqueID();
128126
ConfirmStruct->SaveType = m_SaveType;
127+
ConfirmStruct->TargetTitle = m_Data;
129128

130129
// Query string
131130
char TargetName[FsLib::MAX_PATH] = {0};
@@ -204,7 +203,8 @@ static void CreateNewBackup(System::ProgressTask *Task,
204203
BackupMenuState *CreatingState)
205204
{
206205
// Make sure destination exists.
207-
if (!Config::GetByKey(Config::Keys::ExportToZip) && (FsLib::DirectoryExists(BackupPath) || FsLib::CreateDirectory(BackupPath)))
206+
if (!Config::GetByKey(Config::Keys::ExportToZip) && BackupPath.GetExtension() != u"zip" &&
207+
(FsLib::DirectoryExists(BackupPath) || FsLib::CreateDirectory(BackupPath)))
208208
{
209209
// Copy save as-is to target directory.
210210
FS::CopyDirectoryToDirectory(Task, FS::SAVE_ROOT, BackupPath, false);
@@ -275,10 +275,25 @@ static void RestoreBackup(System::ProgressTask *Task, std::shared_ptr<TargetStru
275275
return;
276276
}
277277

278-
if (!Config::GetByKey(Config::Keys::PreserveSecureValues) && !FS::DeleteSecureValue(DataStruct->UniqueID))
278+
// Secure value check. Scoped so path gets freed immediately after check is finished.
279279
{
280-
Task->Finish();
281-
return;
280+
// This is the path the secure value if it exits.
281+
FsLib::Path SecureValuePath = DataStruct->TargetPath / u"._secure_value";
282+
if (Config::GetByKey(Config::Keys::PreserveSecureValues) && FsLib::FileExists(SecureValuePath))
283+
{
284+
// Try to open file and read secure value.
285+
uint64_t SecureValue = 0;
286+
FsLib::File SecureValueFile(SecureValuePath, FS_OPEN_READ);
287+
if (!SecureValueFile.IsOpen() || SecureValueFile.Read(&SecureValue, sizeof(uint64_t)) != sizeof(uint64_t) ||
288+
!FsLib::SetSecureValueForTitle(DataStruct->TargetTitle->GetUniqueID(), SecureValue))
289+
{
290+
Logger::Log("Error occurred while attempting to set and preserve secure value for game.");
291+
}
292+
}
293+
else if (!Config::GetByKey(Config::Keys::PreserveSecureValues) && !FS::DeleteSecureValue(DataStruct->TargetTitle->GetUniqueID()))
294+
{
295+
Logger::Log("Error occurred while trying to delete secure value for game.");
296+
}
282297
}
283298

284299
// Whether or not committing data is needed.

JKSM/source/FS/IO.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ void FS::CopyDirectoryToDirectory(System::ProgressTask *Task, const FsLib::Path
6868

6969
for (uint32_t i = 0; i < SourceDir.GetEntryCount(); i++)
7070
{
71+
// Test to make sure JKSM doesn't copy the ._secure_value file to the save if it exists. This might be a little unsafe.
72+
if (std::char_traits<char16_t>::compare(u"._secure_value", SourceDir[i], 14) == 0)
73+
{
74+
continue;
75+
}
76+
7177
if (SourceDir.EntryAtIsDirectory(i))
7278
{
7379
FsLib::Path NewSource = Source / SourceDir[i];

0 commit comments

Comments
 (0)