From 34692ab826abc8f8faa61bdb2280b742424528f1 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 7 Dec 2013 15:14:29 -0500 Subject: Remove unnecessary Src/ folders --- Source/Core/Common/SettingsHandler.cpp | 126 +++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 Source/Core/Common/SettingsHandler.cpp (limited to 'Source/Core/Common/SettingsHandler.cpp') diff --git a/Source/Core/Common/SettingsHandler.cpp b/Source/Core/Common/SettingsHandler.cpp new file mode 100644 index 0000000000..555cf0eae9 --- /dev/null +++ b/Source/Core/Common/SettingsHandler.cpp @@ -0,0 +1,126 @@ +// Copyright 2013 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +// Thanks to Treeki for writing the original class - 29/01/2012 + +#include "CommonPaths.h" +#include "Timer.h" +#include "SettingsHandler.h" + +#include + +#ifdef _WIN32 +#include +#include +#include +#else +#include +#endif + +SettingsHandler::SettingsHandler() +{ + Reset(); +} + +const u8* SettingsHandler::GetData() const +{ + return m_buffer; +} + +const std::string SettingsHandler::GetValue(const std::string key) +{ + std::string delim = std::string("\r\n"); + std::string toFind = delim + key + "="; + size_t found = decoded.find(toFind); + + if (found != decoded.npos) + { + size_t delimFound = decoded.find(delim, found + toFind.length()); + if (delimFound == decoded.npos) + delimFound = decoded.length() - 1; + return decoded.substr(found + toFind.length(), delimFound - (found + toFind.length())); + } + else + { + toFind = key + "="; + found = decoded.find(toFind); + if (found == 0) + { + size_t delimFound = decoded.find(delim, found + toFind.length()); + if (delimFound == decoded.npos) + delimFound = decoded.length() - 1; + return decoded.substr(found + toFind.length(), delimFound - (found + toFind.length())); + } + } + + return ""; +} + +void SettingsHandler::Decrypt() +{ + const u8 *str = m_buffer; + while (*str != 0) + { + if (m_position >= SETTINGS_SIZE) + return; + decoded.push_back((u8)(m_buffer[m_position] ^ m_key)); + m_position++; + str++; + m_key = (m_key >> 31) | (m_key << 1); + } +} + +void SettingsHandler::Reset() +{ + decoded = ""; + m_position = 0; + m_key = INITIAL_SEED; + memset(m_buffer, 0, SETTINGS_SIZE); +} + +void SettingsHandler::AddSetting(const char *key, const char *value) +{ + while (*key != 0) + { + WriteByte(*key); + key++; + } + + WriteByte('='); + + while (*value != 0) + { + WriteByte(*value); + value++; + } + + WriteByte(13); + WriteByte(10); +} + +void SettingsHandler::WriteByte(u8 b) +{ + if (m_position >= SETTINGS_SIZE) + return; + + m_buffer[m_position] = b ^ m_key; + m_position++; + m_key = (m_key >> 31) | (m_key << 1); +} + +const std::string SettingsHandler::generateSerialNumber() +{ + time_t rawtime; + tm *timeinfo; + char buffer[12]; + char serialNumber[12]; + + time(&rawtime); + timeinfo = localtime(&rawtime); + strftime(buffer, 11, "%j%H%M%S", timeinfo); + + snprintf(serialNumber, 11, "%s%i", buffer, (Common::Timer::GetTimeMs() >> 1) & 0xF); + serialNumber[10] = 0; + return std::string(serialNumber); +} -- cgit v1.2.3 From 3fe05e0a9f6908c1cf9a3caad6bff1d8decf04a3 Mon Sep 17 00:00:00 2001 From: Matthew Parlane Date: Sat, 8 Feb 2014 18:50:37 +1300 Subject: Fix IniFile to use string& instead of char* Also removes .c_str() usages where found. --- Source/Core/Common/SettingsHandler.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'Source/Core/Common/SettingsHandler.cpp') diff --git a/Source/Core/Common/SettingsHandler.cpp b/Source/Core/Common/SettingsHandler.cpp index 555cf0eae9..b368a7171a 100644 --- a/Source/Core/Common/SettingsHandler.cpp +++ b/Source/Core/Common/SettingsHandler.cpp @@ -28,7 +28,7 @@ const u8* SettingsHandler::GetData() const return m_buffer; } -const std::string SettingsHandler::GetValue(const std::string key) +const std::string SettingsHandler::GetValue(const std::string& key) { std::string delim = std::string("\r\n"); std::string toFind = delim + key + "="; @@ -79,20 +79,16 @@ void SettingsHandler::Reset() memset(m_buffer, 0, SETTINGS_SIZE); } -void SettingsHandler::AddSetting(const char *key, const char *value) +void SettingsHandler::AddSetting(const std::string& key, const std::string& value) { - while (*key != 0) - { - WriteByte(*key); - key++; + for(const char& c : key) { + WriteByte(c); } WriteByte('='); - while (*value != 0) - { - WriteByte(*value); - value++; + for(const char& c : value) { + WriteByte(c); } WriteByte(13); -- cgit v1.2.3 From 2afe2152712981e21d6bda6f029292ed2b1cf91e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 17 Feb 2014 05:18:15 -0500 Subject: Convert all includes to relative paths. --- Source/Core/Common/SettingsHandler.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/Core/Common/SettingsHandler.cpp') diff --git a/Source/Core/Common/SettingsHandler.cpp b/Source/Core/Common/SettingsHandler.cpp index b368a7171a..beeaa82da9 100644 --- a/Source/Core/Common/SettingsHandler.cpp +++ b/Source/Core/Common/SettingsHandler.cpp @@ -4,9 +4,9 @@ // Thanks to Treeki for writing the original class - 29/01/2012 -#include "CommonPaths.h" -#include "Timer.h" -#include "SettingsHandler.h" +#include "Common/CommonPaths.h" +#include "Common/SettingsHandler.h" +#include "Common/Timer.h" #include -- cgit v1.2.3 From 3f9c38d2314a259a9c34dd89bcdfab3af00a02f5 Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Wed, 19 Feb 2014 01:54:11 +0100 Subject: Fix more header sorting issues in Common/ (now check-includes clean). --- Source/Core/Common/SettingsHandler.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Source/Core/Common/SettingsHandler.cpp') diff --git a/Source/Core/Common/SettingsHandler.cpp b/Source/Core/Common/SettingsHandler.cpp index beeaa82da9..b7a7aeedbd 100644 --- a/Source/Core/Common/SettingsHandler.cpp +++ b/Source/Core/Common/SettingsHandler.cpp @@ -4,20 +4,20 @@ // Thanks to Treeki for writing the original class - 29/01/2012 -#include "Common/CommonPaths.h" -#include "Common/SettingsHandler.h" -#include "Common/Timer.h" - -#include +#include #ifdef _WIN32 -#include #include #include +#include #else #include #endif +#include "Common/CommonPaths.h" +#include "Common/SettingsHandler.h" +#include "Common/Timer.h" + SettingsHandler::SettingsHandler() { Reset(); -- cgit v1.2.3 From 83b7bb64aa5e1ee6b18eaa5d08c17bb5b6c57048 Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Thu, 20 Feb 2014 04:11:52 +0100 Subject: Make Common/ mostly IWYU clean (and fix errors in rest of the project detected by this change). --- Source/Core/Common/SettingsHandler.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'Source/Core/Common/SettingsHandler.cpp') diff --git a/Source/Core/Common/SettingsHandler.cpp b/Source/Core/Common/SettingsHandler.cpp index b7a7aeedbd..21cabaf4b4 100644 --- a/Source/Core/Common/SettingsHandler.cpp +++ b/Source/Core/Common/SettingsHandler.cpp @@ -4,17 +4,20 @@ // Thanks to Treeki for writing the original class - 29/01/2012 +#include +#include +#include #include +#include #ifdef _WIN32 #include #include #include -#else -#include +#include "Common/CommonFuncs.h" // snprintf #endif -#include "Common/CommonPaths.h" +#include "Common/CommonTypes.h" #include "Common/SettingsHandler.h" #include "Common/Timer.h" -- cgit v1.2.3 From 31cfc73a09a8685cbab20502b4bc132e98e2feb5 Mon Sep 17 00:00:00 2001 From: Matthew Parlane Date: Tue, 11 Mar 2014 00:30:55 +1300 Subject: Fixes spacing for "for", "while", "switch" and "if" Also moved && and || to ends of lines instead of start. Fixed misc vertical alignments and some { needed newlining. --- Source/Core/Common/SettingsHandler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Core/Common/SettingsHandler.cpp') diff --git a/Source/Core/Common/SettingsHandler.cpp b/Source/Core/Common/SettingsHandler.cpp index 21cabaf4b4..46acff321d 100644 --- a/Source/Core/Common/SettingsHandler.cpp +++ b/Source/Core/Common/SettingsHandler.cpp @@ -84,13 +84,13 @@ void SettingsHandler::Reset() void SettingsHandler::AddSetting(const std::string& key, const std::string& value) { - for(const char& c : key) { + for (const char& c : key) { WriteByte(c); } WriteByte('='); - for(const char& c : value) { + for (const char& c : value) { WriteByte(c); } -- cgit v1.2.3 From ba4934b75eb13cc04a54efd54a9d6f286d255083 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 30 Aug 2014 16:14:56 -0400 Subject: Common: Clean up brace placements --- Source/Core/Common/SettingsHandler.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Source/Core/Common/SettingsHandler.cpp') diff --git a/Source/Core/Common/SettingsHandler.cpp b/Source/Core/Common/SettingsHandler.cpp index 46acff321d..4a6897153c 100644 --- a/Source/Core/Common/SettingsHandler.cpp +++ b/Source/Core/Common/SettingsHandler.cpp @@ -84,13 +84,15 @@ void SettingsHandler::Reset() void SettingsHandler::AddSetting(const std::string& key, const std::string& value) { - for (const char& c : key) { + for (const char& c : key) + { WriteByte(c); } WriteByte('='); - for (const char& c : value) { + for (const char& c : value) + { WriteByte(c); } -- cgit v1.2.3 From cefcb0ace9d363b3679b4e93bcc9ec05f1e5f4f8 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Mon, 18 May 2015 01:08:10 +0200 Subject: Update license headers to GPLv2+ --- Source/Core/Common/SettingsHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/Common/SettingsHandler.cpp') diff --git a/Source/Core/Common/SettingsHandler.cpp b/Source/Core/Common/SettingsHandler.cpp index 4a6897153c..5ae43c10fe 100644 --- a/Source/Core/Common/SettingsHandler.cpp +++ b/Source/Core/Common/SettingsHandler.cpp @@ -1,5 +1,5 @@ // Copyright 2013 Dolphin Emulator Project -// Licensed under GPLv2 +// Licensed under GPLv2+ // Refer to the license.txt file included. // Thanks to Treeki for writing the original class - 29/01/2012 -- cgit v1.2.3 From 30ebb2459eb97ba544547183854775df8460b475 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 24 May 2015 06:55:12 +0200 Subject: Set copyright year to when a file was created --- Source/Core/Common/SettingsHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/Common/SettingsHandler.cpp') diff --git a/Source/Core/Common/SettingsHandler.cpp b/Source/Core/Common/SettingsHandler.cpp index 5ae43c10fe..cfbda9795e 100644 --- a/Source/Core/Common/SettingsHandler.cpp +++ b/Source/Core/Common/SettingsHandler.cpp @@ -1,4 +1,4 @@ -// Copyright 2013 Dolphin Emulator Project +// Copyright 2012 Dolphin Emulator Project // Licensed under GPLv2+ // Refer to the license.txt file included. -- cgit v1.2.3