Skip to content

Commit 59b39a1

Browse files
authored
Merge pull request #19436 from hrydgard/save-data-install
Implement save data install from ZIP
2 parents 4250bdc + 514f29d commit 59b39a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+662
-248
lines changed

Common/File/FileUtil.cpp

+45-19
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#ifndef UNICODE
2121
#error Win32 build requires a unicode build
2222
#endif
23+
#else
24+
#define _POSIX_SOURCE
25+
#define _LARGE_TIME_API
2326
#endif
2427

2528
#include "ppsspp_config.h"
@@ -37,6 +40,8 @@
3740
#include <ctime>
3841
#include <memory>
3942

43+
#include <sys/types.h>
44+
4045
#include "Common/Log.h"
4146
#include "Common/LogReporting.h"
4247
#include "Common/File/AndroidContentURI.h"
@@ -46,6 +51,7 @@
4651

4752
#ifdef _WIN32
4853
#include "Common/CommonWindows.h"
54+
#include <sys/utime.h>
4955
#include <Windows.h>
5056
#include <shlobj.h> // for SHGetFolderPath
5157
#include <shellapi.h>
@@ -63,6 +69,7 @@
6369
#include <errno.h>
6470
#include <stdlib.h>
6571
#include <unistd.h>
72+
#include <utime.h>
6673
#endif
6774

6875
#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
@@ -167,7 +174,7 @@ FILE *OpenCFile(const Path &path, const char *mode) {
167174

168175
#if defined(_WIN32) && defined(UNICODE)
169176
#if PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__)
170-
// We shouldn't use _wfopen here,
177+
// We shouldn't use _wfopen here,
171178
// this function is not allowed to read outside Local and Installation folders
172179
// FileSystem (broadFileSystemAccess) doesn't apply on _wfopen
173180
// if we have custom memory stick location _wfopen will return null
@@ -471,7 +478,7 @@ bool Delete(const Path &filename) {
471478

472479
INFO_LOG(Log::Common, "Delete: file %s", filename.c_str());
473480

474-
// Return true because we care about the file no
481+
// Return true because we care about the file no
475482
// being there, not the actual delete.
476483
if (!Exists(filename)) {
477484
WARN_LOG(Log::Common, "Delete: '%s' already does not exist", filename.c_str());
@@ -498,7 +505,7 @@ bool Delete(const Path &filename) {
498505
#endif
499506
#else
500507
if (unlink(filename.c_str()) == -1) {
501-
WARN_LOG(Log::Common, "Delete: unlink failed on %s: %s",
508+
WARN_LOG(Log::Common, "Delete: unlink failed on %s: %s",
502509
filename.c_str(), GetLastErrorMsg().c_str());
503510
return false;
504511
}
@@ -547,7 +554,7 @@ bool CreateDir(const Path &path) {
547554
if (::CreateDirectory(path.ToWString().c_str(), NULL))
548555
return true;
549556
#endif
550-
557+
551558
DWORD error = GetLastError();
552559
if (error == ERROR_ALREADY_EXISTS) {
553560
WARN_LOG(Log::Common, "CreateDir: CreateDirectory failed on %s: already exists", path.c_str());
@@ -616,7 +623,7 @@ bool CreateFullPath(const Path &path) {
616623
return true;
617624
}
618625

619-
// renames file srcFilename to destFilename, returns true on success
626+
// renames file srcFilename to destFilename, returns true on success
620627
bool Rename(const Path &srcFilename, const Path &destFilename) {
621628
if (srcFilename.Type() != destFilename.Type()) {
622629
// Impossible. You're gonna need to make a copy, and delete the original. Not the responsibility
@@ -659,12 +666,12 @@ bool Rename(const Path &srcFilename, const Path &destFilename) {
659666
return true;
660667
#endif
661668

662-
ERROR_LOG(Log::Common, "Rename: failed %s --> %s: %s",
669+
ERROR_LOG(Log::Common, "Rename: failed %s --> %s: %s",
663670
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg().c_str());
664671
return false;
665672
}
666673

667-
// copies file srcFilename to destFilename, returns true on success
674+
// copies file srcFilename to destFilename, returns true on success
668675
bool Copy(const Path &srcFilename, const Path &destFilename) {
669676
switch (srcFilename.Type()) {
670677
case PathType::NATIVE:
@@ -692,7 +699,7 @@ bool Copy(const Path &srcFilename, const Path &destFilename) {
692699
if (CopyFile(srcFilename.ToWString().c_str(), destFilename.ToWString().c_str(), FALSE))
693700
return true;
694701
#endif
695-
ERROR_LOG(Log::Common, "Copy: failed %s --> %s: %s",
702+
ERROR_LOG(Log::Common, "Copy: failed %s --> %s: %s",
696703
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg().c_str());
697704
return false;
698705
#else
@@ -705,7 +712,7 @@ bool Copy(const Path &srcFilename, const Path &destFilename) {
705712
// Open input file
706713
FILE *input = OpenCFile(srcFilename, "rb");
707714
if (!input) {
708-
ERROR_LOG(Log::Common, "Copy: input failed %s --> %s: %s",
715+
ERROR_LOG(Log::Common, "Copy: input failed %s --> %s: %s",
709716
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg().c_str());
710717
return false;
711718
}
@@ -714,7 +721,7 @@ bool Copy(const Path &srcFilename, const Path &destFilename) {
714721
FILE *output = OpenCFile(destFilename, "wb");
715722
if (!output) {
716723
fclose(input);
717-
ERROR_LOG(Log::Common, "Copy: output failed %s --> %s: %s",
724+
ERROR_LOG(Log::Common, "Copy: output failed %s --> %s: %s",
718725
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg().c_str());
719726
return false;
720727
}
@@ -725,23 +732,23 @@ bool Copy(const Path &srcFilename, const Path &destFilename) {
725732
int rnum = fread(buffer, sizeof(char), BSIZE, input);
726733
if (rnum != BSIZE) {
727734
if (ferror(input) != 0) {
728-
ERROR_LOG(Log::Common,
729-
"Copy: failed reading from source, %s --> %s: %s",
735+
ERROR_LOG(Log::Common,
736+
"Copy: failed reading from source, %s --> %s: %s",
730737
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg().c_str());
731738
fclose(input);
732-
fclose(output);
739+
fclose(output);
733740
return false;
734741
}
735742
}
736743

737744
// write output
738745
int wnum = fwrite(buffer, sizeof(char), rnum, output);
739746
if (wnum != rnum) {
740-
ERROR_LOG(Log::Common,
741-
"Copy: failed writing to output, %s --> %s: %s",
747+
ERROR_LOG(Log::Common,
748+
"Copy: failed writing to output, %s --> %s: %s",
742749
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg().c_str());
743750
fclose(input);
744-
fclose(output);
751+
fclose(output);
745752
return false;
746753
}
747754
}
@@ -883,9 +890,9 @@ uint64_t GetFileSize(FILE *f) {
883890
#endif
884891
}
885892

886-
// creates an empty file filename, returns true on success
893+
// creates an empty file filename, returns true on success
887894
bool CreateEmptyFile(const Path &filename) {
888-
INFO_LOG(Log::Common, "CreateEmptyFile: %s", filename.c_str());
895+
INFO_LOG(Log::Common, "CreateEmptyFile: %s", filename.c_str());
889896
FILE *pFile = OpenCFile(filename, "wb");
890897
if (!pFile) {
891898
ERROR_LOG(Log::Common, "CreateEmptyFile: failed to create '%s': %s", filename.c_str(), GetLastErrorMsg().c_str());
@@ -1118,7 +1125,7 @@ bool IOFile::Seek(int64_t off, int origin)
11181125
}
11191126

11201127
uint64_t IOFile::Tell()
1121-
{
1128+
{
11221129
if (IsOpen())
11231130
return ftello(m_file);
11241131
else
@@ -1240,4 +1247,23 @@ bool WriteDataToFile(bool text_file, const void* data, size_t size, const Path &
12401247
return true;
12411248
}
12421249

1250+
void ChangeMTime(const Path &path, time_t mtime) {
1251+
if (path.Type() == PathType::CONTENT_URI) {
1252+
// No clue what to do here.
1253+
return;
1254+
}
1255+
1256+
#ifdef _WIN32
1257+
_utimbuf buf{};
1258+
buf.actime = mtime;
1259+
buf.modtime = mtime;
1260+
_utime(path.c_str(), &buf);
1261+
#else
1262+
utimbuf buf{};
1263+
buf.actime = mtime;
1264+
buf.modtime = mtime;
1265+
utime(path.c_str(), &buf);
1266+
#endif
1267+
}
1268+
12431269
} // namespace File

Common/File/FileUtil.h

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ uint64_t ComputeRecursiveDirectorySize(const Path &path);
8383
// Returns true if successful, or path already exists.
8484
bool CreateDir(const Path &filename);
8585

86+
void ChangeMTime(const Path &path, time_t mtime);
87+
8688
// Creates the full path of fullPath returns true on success
8789
bool CreateFullPath(const Path &fullPath);
8890

Core/ELF/ParamSFO.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,28 @@ void ParamSFOData::SetValue(const std::string &key, const u8 *value, unsigned in
6262

6363
int ParamSFOData::GetValueInt(const std::string &key) const {
6464
std::map<std::string,ValueData>::const_iterator it = values.find(key);
65-
if(it == values.end() || it->second.type != VT_INT)
65+
if (it == values.end() || it->second.type != VT_INT)
6666
return 0;
6767
return it->second.i_value;
6868
}
6969

7070
std::string ParamSFOData::GetValueString(const std::string &key) const {
7171
std::map<std::string,ValueData>::const_iterator it = values.find(key);
72-
if(it == values.end() || (it->second.type != VT_UTF8))
72+
if (it == values.end() || (it->second.type != VT_UTF8))
7373
return "";
7474
return it->second.s_value;
7575
}
7676

77+
bool ParamSFOData::HasKey(const std::string &key) const {
78+
return values.find(key) != values.end();
79+
}
80+
7781
const u8 *ParamSFOData::GetValueData(const std::string &key, unsigned int *size) const {
7882
std::map<std::string,ValueData>::const_iterator it = values.find(key);
79-
if(it == values.end() || (it->second.type != VT_UTF8_SPE))
83+
if (it == values.end() || (it->second.type != VT_UTF8_SPE)) {
8084
return 0;
81-
if(size)
82-
{
85+
}
86+
if (size) {
8387
*size = it->second.u_size;
8488
}
8589
return it->second.u_value;

Core/ELF/ParamSFO.h

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class ParamSFOData
3535

3636
int GetValueInt(const std::string &key) const;
3737
std::string GetValueString(const std::string &key) const;
38+
bool HasKey(const std::string &key) const;
3839
const u8 *GetValueData(const std::string &key, unsigned int *size) const;
3940

4041
std::vector<std::string> GetKeys() const;

0 commit comments

Comments
 (0)