From 7b3115e4de8efdcb9b7d6a25f6ca2fdf22bd155c Mon Sep 17 00:00:00 2001 From: sum2012 Date: Tue, 27 Jan 2015 19:54:22 +0800 Subject: [PATCH 1/5] Create as UTF-8 format of new cwcheat file Fix #4300 --- Core/CwCheat.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Core/CwCheat.cpp b/Core/CwCheat.cpp index 77e8c8bf42..c7c6bed167 100644 --- a/Core/CwCheat.cpp +++ b/Core/CwCheat.cpp @@ -13,6 +13,8 @@ #include "util/text/utf8.h" #endif +using namespace std; + static int CheatEvent = -1; std::string gameTitle; std::string activeCheatFile; @@ -39,7 +41,11 @@ static void __CheatStart() { File::CreateFullPath(GetSysDirectory(DIRECTORY_CHEATS)); if (!File::Exists(activeCheatFile)) { - File::CreateEmptyFile(activeCheatFile); + ofstream myCheatFile; + myCheatFile.open(activeCheatFile); + myCheatFile << "\xEF\xBB\xBF"; + myCheatFile.close(); + } cheatEngine = new CWCheatEngine(); From 12e1cdbbaecc2149a3f1ece06d7db509ecef9311 Mon Sep 17 00:00:00 2001 From: sum2012 Date: Tue, 27 Jan 2015 21:11:07 +0800 Subject: [PATCH 2/5] Attempt to fix Symbian build --- Core/CwCheat.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Core/CwCheat.cpp b/Core/CwCheat.cpp index c7c6bed167..b8484062ca 100644 --- a/Core/CwCheat.cpp +++ b/Core/CwCheat.cpp @@ -41,10 +41,14 @@ static void __CheatStart() { File::CreateFullPath(GetSysDirectory(DIRECTORY_CHEATS)); if (!File::Exists(activeCheatFile)) { +#ifndef Symbian ofstream myCheatFile; myCheatFile.open(activeCheatFile); myCheatFile << "\xEF\xBB\xBF"; myCheatFile.close(); +#else + File::CreateEmptyFile(activeCheatFile); +#endif } From dff76dec566d97642ba2162ab14869bc28ed7f7a Mon Sep 17 00:00:00 2001 From: sum2012 Date: Tue, 27 Jan 2015 21:17:07 +0800 Subject: [PATCH 3/5] Fix as @Bigpet suggestion --- Core/CwCheat.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Core/CwCheat.cpp b/Core/CwCheat.cpp index b8484062ca..612e13587c 100644 --- a/Core/CwCheat.cpp +++ b/Core/CwCheat.cpp @@ -41,14 +41,10 @@ static void __CheatStart() { File::CreateFullPath(GetSysDirectory(DIRECTORY_CHEATS)); if (!File::Exists(activeCheatFile)) { -#ifndef Symbian ofstream myCheatFile; - myCheatFile.open(activeCheatFile); + myCheatFile.open(activeCheatFile.c_str()); myCheatFile << "\xEF\xBB\xBF"; myCheatFile.close(); -#else - File::CreateEmptyFile(activeCheatFile); -#endif } From 008806c27556d114f1973f55b970794fac12e224 Mon Sep 17 00:00:00 2001 From: sum2012 Date: Wed, 28 Jan 2015 06:15:05 +0800 Subject: [PATCH 4/5] Fix as @hrydgard suggest --- Core/CwCheat.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Core/CwCheat.cpp b/Core/CwCheat.cpp index 612e13587c..722af616af 100644 --- a/Core/CwCheat.cpp +++ b/Core/CwCheat.cpp @@ -1,3 +1,5 @@ +#include "i18n/i18n.h" +#include "UI/OnScreenDisplay.h" #include "Common/StringUtils.h" #include "Common/ChunkFile.h" #include "Common/FileUtil.h" @@ -13,7 +15,7 @@ #include "util/text/utf8.h" #endif -using namespace std; + static int CheatEvent = -1; std::string gameTitle; @@ -41,10 +43,15 @@ static void __CheatStart() { File::CreateFullPath(GetSysDirectory(DIRECTORY_CHEATS)); if (!File::Exists(activeCheatFile)) { - ofstream myCheatFile; - myCheatFile.open(activeCheatFile.c_str()); - myCheatFile << "\xEF\xBB\xBF"; - myCheatFile.close(); + FILE *f = File::OpenCFile(activeCheatFile, "wb"); + if (f) { + fwrite("\xEF\xBB\xBF", 1, 3, f); + fclose(f); + } + if (!File::Exists(activeCheatFile)) { + I18NCategory *err = GetI18NCategory("Error"); + osm.Show(err->T("Unable to create cheat file, disk may be full")); + } } From f172bd78b7a5808590670e93233d4eac5704ccb1 Mon Sep 17 00:00:00 2001 From: sum2012 Date: Wed, 28 Jan 2015 06:17:27 +0800 Subject: [PATCH 5/5] Remove unused line --- Core/CwCheat.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/Core/CwCheat.cpp b/Core/CwCheat.cpp index 722af616af..ff0d888248 100644 --- a/Core/CwCheat.cpp +++ b/Core/CwCheat.cpp @@ -15,8 +15,6 @@ #include "util/text/utf8.h" #endif - - static int CheatEvent = -1; std::string gameTitle; std::string activeCheatFile;