diff --git a/Common/System/NativeApp.h b/Common/System/NativeApp.h index d1286a8d74..d33c454156 100644 --- a/Common/System/NativeApp.h +++ b/Common/System/NativeApp.h @@ -87,3 +87,6 @@ void NativeShutdownGraphics(); void NativeShutdown(); void PostLoadConfig(); + +void NativeSaveSecret(const char *nameOfSecret, const std::string &data); +std::string NativeLoadSecret(const char *nameOfSecret); diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 0099f460db..91e08ac1d3 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1419,3 +1419,23 @@ void NativeShutdown() { // Previously we did exit() here on Android but that makes it hard to do things like restart on backend change. // I think we handle most globals correctly or correct-enough now. } + +Path GetSecretPath(const char *nameOfSecret) { + return g_Config.internalDataDirectory / ("ppsspp_" + std::string(nameOfSecret) + ".dat"); +} + +// name should be simple alphanumerics to avoid problems on Windows. +void NativeSaveSecret(const char *nameOfSecret, const std::string &data) { + // We'll simply store secrets in files under g_Config.internalDataDirectory. + // On Android, that corresponds to the app private directory. On other platforms, + // the location is less secure unfortunately - to be improved. + Path path = GetSecretPath(nameOfSecret); + File::WriteDataToFile(false, data.data(), data.size(), path); +} + +std::string NativeLoadSecret(const char *nameOfSecret) { + Path path = GetSecretPath(nameOfSecret); + std::string data; + File::ReadFileToString(false, path, data); + return data; +}