mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Core: Remove some uses of OpenCPPFile.
This commit is contained in:
parent
96c109e6ce
commit
2999e1cb86
4 changed files with 42 additions and 54 deletions
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "Common/Data/Format/IniFile.h"
|
||||
#include "Common/File/VFS/VFS.h"
|
||||
#include "Common/File/FileUtil.h"
|
||||
#include "Common/Data/Text/Parsers.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -597,32 +598,26 @@ bool IniFile::Load(std::istream &in) {
|
|||
|
||||
bool IniFile::Save(const char* filename)
|
||||
{
|
||||
std::ofstream out;
|
||||
#if defined(_WIN32) && !defined(__MINGW32__)
|
||||
out.open(ConvertUTF8ToWString(filename), std::ios::out);
|
||||
#else
|
||||
out.open(filename, std::ios::out);
|
||||
#endif
|
||||
|
||||
if (out.fail())
|
||||
{
|
||||
FILE *file = File::OpenCFile(filename, "w");
|
||||
if (!file) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// UTF-8 byte order mark. To make sure notepad doesn't go nuts.
|
||||
out << "\xEF\xBB\xBF";
|
||||
// TODO: Do we still need this? It's annoying.
|
||||
fprintf(file, "\xEF\xBB\xBF");
|
||||
|
||||
for (const Section §ion : sections) {
|
||||
if (!section.name().empty() && (!section.lines.empty() || !section.comment.empty())) {
|
||||
out << "[" << section.name() << "]" << section.comment << std::endl;
|
||||
fprintf(file, "[%s]%s\n", section.name().c_str(), section.comment.c_str());
|
||||
}
|
||||
|
||||
for (const std::string &s : section.lines) {
|
||||
out << s << std::endl;
|
||||
fprintf(file, "%s\n", s.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
out.close();
|
||||
fclose(file);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -82,19 +82,16 @@ void VirtualDiscFileSystem::LoadFileListIndex() {
|
|||
return;
|
||||
}
|
||||
|
||||
std::ifstream in;
|
||||
in.open(filename.c_str(), std::ios::in);
|
||||
if (in.fail()) {
|
||||
FILE *f = File::OpenCFile(filename, "r");
|
||||
if (!f) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string buf;
|
||||
static const int MAX_LINE_SIZE = 1024;
|
||||
while (!in.eof()) {
|
||||
buf.resize(MAX_LINE_SIZE, '\0');
|
||||
in.getline(&buf[0], MAX_LINE_SIZE);
|
||||
|
||||
std::string line = buf.data();
|
||||
static const int MAX_LINE_SIZE = 2048;
|
||||
char linebuf[MAX_LINE_SIZE]{};
|
||||
while (fgets(linebuf, MAX_LINE_SIZE, f)) {
|
||||
std::string line = linebuf;
|
||||
|
||||
// Ignore any UTF-8 BOM.
|
||||
if (line.substr(0, 3) == "\xEF\xBB\xBF") {
|
||||
|
@ -163,7 +160,7 @@ void VirtualDiscFileSystem::LoadFileListIndex() {
|
|||
fileList.push_back(entry);
|
||||
}
|
||||
|
||||
in.close();
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
void VirtualDiscFileSystem::DoState(PointerWrap &p)
|
||||
|
|
|
@ -743,35 +743,32 @@ bool TextureReplacer::GenerateIni(const std::string &gameID, std::string *genera
|
|||
|
||||
FILE *f = File::OpenCFile(texturesDirectory + INI_FILENAME, "wb");
|
||||
if (f) {
|
||||
fwrite("\xEF\xBB\xBF", 0, 3, f);
|
||||
fclose(f);
|
||||
fwrite("\xEF\xBB\xBF", 1, 3, 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 and describes your textures.\n";
|
||||
fs << "# Some information on syntax available here:\n";
|
||||
fs << "# https://github.com/hrydgard/ppsspp/wiki/Texture-replacement-ini-syntax\n";
|
||||
fs << "[options]\n";
|
||||
fs << "version = 1\n";
|
||||
fs << "hash = quick\n";
|
||||
fs << "ignoreMipmap = false\n";
|
||||
fs << "\n";
|
||||
fs << "[games]\n";
|
||||
fs << "# Used to make it easier to install, and override settings for other regions.\n";
|
||||
fs << "# Files still have to be copied to each TEXTURES folder.";
|
||||
fs << gameID << " = " << INI_FILENAME << "\n";
|
||||
fs << "\n";
|
||||
fs << "[hashes]\n";
|
||||
fs << "# Use / for folders not \\, avoid special characters, and stick to lowercase.\n";
|
||||
fs << "# See wiki for more info.\n";
|
||||
fs << "\n";
|
||||
fs << "[hashranges]\n";
|
||||
fs << "\n";
|
||||
fs << "[filtering]\n";
|
||||
fs << "\n";
|
||||
fs << "[reducehashranges]\n";
|
||||
fs.close();
|
||||
fprintf(f, "# This file is optional and describes your textures.\n");
|
||||
fprintf(f, "# Some information on syntax available here:\n");
|
||||
fprintf(f, "# https://github.com/hrydgard/ppsspp/wiki/Texture-replacement-ini-syntax \n");
|
||||
fprintf(f, "[options]\n");
|
||||
fprintf(f, "version = 1\n");
|
||||
fprintf(f, "hash = quick\n");
|
||||
fprintf(f, "ignoreMipmap = false\n");
|
||||
fprintf(f, "\n");
|
||||
fprintf(f, "[games]\n");
|
||||
fprintf(f, "# Used to make it easier to install, and override settings for other regions.\n");
|
||||
fprintf(f, "# Files still have to be copied to each TEXTURES folder.");
|
||||
fprintf(f, "%s = %s\n", gameID.c_str(), INI_FILENAME.c_str());
|
||||
fprintf(f, "\n");
|
||||
fprintf(f, "[hashes]\n");
|
||||
fprintf(f, "# Use / for folders not \\, avoid special characters, and stick to lowercase.\n");
|
||||
fprintf(f, "# See wiki for more info.\n");
|
||||
fprintf(f, "\n");
|
||||
fprintf(f, "[hashranges]\n");
|
||||
fprintf(f, "\n");
|
||||
fprintf(f, "[filtering]\n");
|
||||
fprintf(f, "\n");
|
||||
fprintf(f, "[reducehashranges]\n");
|
||||
fclose(f);
|
||||
}
|
||||
return File::Exists(texturesDirectory + INI_FILENAME);
|
||||
}
|
||||
|
|
|
@ -1150,10 +1150,9 @@ UI::EventReturn GameSettingsScreen::OnSavePathMydoc(UI::EventParams &e) {
|
|||
installed_ = false;
|
||||
g_Config.memStickDirectory = PPSSPPpath + "memstick/";
|
||||
} else {
|
||||
std::ofstream myfile;
|
||||
myfile.open(PPSSPPpath + "installed.txt");
|
||||
if (myfile.is_open()){
|
||||
myfile.close();
|
||||
FILE *f = File::OpenCFile(PPSSPPpath + "installed.txt", "wb");
|
||||
if (f) {
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
const std::string myDocsPath = W32Util::UserDocumentsPath() + "/PPSSPP/";
|
||||
|
|
Loading…
Add table
Reference in a new issue