Permalink
Browse files

Replacement: Refactor ini template generation.

  • Loading branch information...
unknownbrackets committed Oct 1, 2018
1 parent f90439a commit 13375e2b953d273e9919200291c130deb08baf97
Showing with 44 additions and 32 deletions.
  1. +38 −0 Core/TextureReplacer.cpp
  2. +2 −0 Core/TextureReplacer.h
  3. +4 −32 UI/GameSettingsScreen.cpp
View
@@ -613,3 +613,41 @@ void ReplacedTexture::Load(int level, void *out, int rowPitch) {
png_image_free(&png);
#endif
}
bool TextureReplacer::GenerateIni(const std::string &gameID, std::string *generatedFilename) {
if (gameID.empty())
return false;
std::string texturesDirectory = GetSysDirectory(DIRECTORY_TEXTURES) + gameID + "/";
if (!File::Exists(texturesDirectory)) {
File::CreateFullPath(texturesDirectory);
}
if (generatedFilename)
*generatedFilename = texturesDirectory + INI_FILENAME;
if (File::Exists(texturesDirectory + INI_FILENAME))
return true;
FILE *f = File::OpenCFile(texturesDirectory + INI_FILENAME, "wb");
if (f) {
fwrite("\xEF\xBB\xBF", 0, 3, f);
fclose(f);
// Let's also write some defaults.
std::fstream fs;
File::OpenCPPFile(fs, texturesDirectory + INI_FILENAME, std::ios::out | std::ios::ate);
fs << "# This file is optional\n";
fs << "# for syntax explanation check:\n";
fs << "# - https://github.com/hrydgard/ppsspp/pull/8715 \n";
fs << "# - https://github.com/hrydgard/ppsspp/pull/8792 \n";
fs << "[options]\n";
fs << "version = 1\n";
fs << "hash = quick\n";
fs << "\n";
fs << "[hashes]\n";
fs << "\n";
fs << "[hashranges]\n";
fs.close();
}
return File::Exists(texturesDirectory + INI_FILENAME);
}
View
@@ -186,6 +186,8 @@ class TextureReplacer {
void NotifyTextureDecoded(const ReplacedTextureDecodeInfo &replacedInfo, const void *data, int pitch, int level, int w, int h);
static bool GenerateIni(const std::string &gameID, std::string *generatedFilename);
protected:
bool LoadIni();
void ParseHashRange(const std::string &key, const std::string &value);
View
@@ -53,6 +53,7 @@
#include "Core/Host.h"
#include "Core/System.h"
#include "Core/Reporting.h"
#include "Core/TextureReplacer.h"
#include "Core/WebServer.h"
#include "GPU/Common/PostShader.h"
#include "android/jni/TestRunner.h"
@@ -1345,38 +1346,9 @@ UI::EventReturn DeveloperToolsScreen::OnLoadLanguageIni(UI::EventParams &e) {
UI::EventReturn DeveloperToolsScreen::OnOpenTexturesIniFile(UI::EventParams &e) {
std::string gameID = g_paramSFO.GetDiscID();
std::string texturesDirectory = GetSysDirectory(DIRECTORY_TEXTURES) + gameID + "/";
bool enabled_ = !gameID.empty();
if (enabled_) {
if (!File::Exists(texturesDirectory)) {
File::CreateFullPath(texturesDirectory);
}
if (!File::Exists(texturesDirectory + "textures.ini")) {
FILE *f = File::OpenCFile(texturesDirectory + "textures.ini", "wb");
if (f) {
fwrite("\xEF\xBB\xBF", 0, 3, f);
fclose(f);
// Let's also write some defaults
std::fstream fs;
File::OpenCPPFile(fs, texturesDirectory + "textures.ini", std::ios::out | std::ios::ate);
fs << "# This file is optional\n";
fs << "# for syntax explanation check:\n";
fs << "# - https://github.com/hrydgard/ppsspp/pull/8715 \n";
fs << "# - https://github.com/hrydgard/ppsspp/pull/8792 \n";
fs << "[options]\n";
fs << "version = 1\n";
fs << "hash = quick\n";
fs << "\n";
fs << "[hashes]\n";
fs << "\n";
fs << "[hashranges]\n";
fs.close();
}
}
enabled_ = File::Exists(texturesDirectory + "textures.ini");
}
if (enabled_) {
File::openIniFile(texturesDirectory + "textures.ini");
std::string generatedFilename;
if (TextureReplacer::GenerateIni(gameID, &generatedFilename)) {
File::openIniFile(generatedFilename);
}
return UI::EVENT_DONE;
}

0 comments on commit 13375e2

Please sign in to comment.