summaryrefslogtreecommitdiffstats
path: root/infomanager.cpp
diff options
context:
space:
mode:
authorEthan Yonker <dees_troy@teamw.in>2016-03-14 20:54:37 +0100
committerDees Troy <dees_troy@teamw.in>2016-03-31 16:43:53 +0200
commitfe91611cb1c484429f2fdc958732337a5fc38fa8 (patch)
treee91133c9a9dff6f1dbba46c5110cd203dc0ddc55 /infomanager.cpp
parentlanguages: fix and improve german translation (diff)
downloadandroid_bootable_recovery-fe91611cb1c484429f2fdc958732337a5fc38fa8.tar
android_bootable_recovery-fe91611cb1c484429f2fdc958732337a5fc38fa8.tar.gz
android_bootable_recovery-fe91611cb1c484429f2fdc958732337a5fc38fa8.tar.bz2
android_bootable_recovery-fe91611cb1c484429f2fdc958732337a5fc38fa8.tar.lz
android_bootable_recovery-fe91611cb1c484429f2fdc958732337a5fc38fa8.tar.xz
android_bootable_recovery-fe91611cb1c484429f2fdc958732337a5fc38fa8.tar.zst
android_bootable_recovery-fe91611cb1c484429f2fdc958732337a5fc38fa8.zip
Diffstat (limited to '')
-rw-r--r--infomanager.cpp80
1 files changed, 51 insertions, 29 deletions
diff --git a/infomanager.cpp b/infomanager.cpp
index 2a4c3c892..275c70c6e 100644
--- a/infomanager.cpp
+++ b/infomanager.cpp
@@ -16,22 +16,7 @@
along with TWRP. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <linux/input.h>
-#include <pthread.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <unistd.h>
-#include <stdlib.h>
-
#include <string>
-#include <utility>
#include <map>
#include <fstream>
#include <sstream>
@@ -43,11 +28,34 @@
using namespace std;
-InfoManager::InfoManager(const string filename) {
- File = filename;
+InfoManager::InfoManager() {
+ file_version = 0;
+ is_const = false;
+}
+
+InfoManager::InfoManager(const string& filename) {
+ file_version = 0;
+ is_const = false;
+ SetFile(filename);
}
InfoManager::~InfoManager(void) {
+ Clear();
+}
+
+void InfoManager::SetFile(const string& filename) {
+ File = filename;
+}
+
+void InfoManager::SetFileVersion(int version) {
+ file_version = version;
+}
+
+void InfoManager::SetConst(void) {
+ is_const = true;
+}
+
+void InfoManager::Clear(void) {
mValues.clear();
}
@@ -63,6 +71,16 @@ int InfoManager::LoadValues(void) {
LOGINFO("InfoManager loading from '%s'.\n", File.c_str());
}
+ if (file_version) {
+ int read_file_version;
+ if (fread(&read_file_version, 1, sizeof(int), in) != sizeof(int))
+ goto error;
+ if (read_file_version != file_version) {
+ LOGINFO("InfoManager file version has changed, not reading file\n");
+ goto error;
+ }
+ }
+
while (!feof(in)) {
string Name;
string Value;
@@ -105,6 +123,10 @@ int InfoManager::SaveValues(void) {
if (!out)
return -1;
+ if (file_version) {
+ fwrite(&file_version, 1, sizeof(int), out);
+ }
+
map<string, string>::iterator iter;
for (iter = mValues.begin(); iter != mValues.end(); ++iter) {
unsigned short length = (unsigned short) iter->first.length() + 1;
@@ -119,7 +141,7 @@ int InfoManager::SaveValues(void) {
return 0;
}
-int InfoManager::GetValue(const string varName, string& value) {
+int InfoManager::GetValue(const string& varName, string& value) {
string localStr = varName;
map<string, string>::iterator pos;
@@ -131,7 +153,7 @@ int InfoManager::GetValue(const string varName, string& value) {
return 0;
}
-int InfoManager::GetValue(const string varName, int& value) {
+int InfoManager::GetValue(const string& varName, int& value) {
string data;
if (GetValue(varName,data) != 0)
@@ -141,7 +163,7 @@ int InfoManager::GetValue(const string varName, int& value) {
return 0;
}
-int InfoManager::GetValue(const string varName, float& value) {
+int InfoManager::GetValue(const string& varName, float& value) {
string data;
if (GetValue(varName,data) != 0)
@@ -151,7 +173,7 @@ int InfoManager::GetValue(const string varName, float& value) {
return 0;
}
-unsigned long long InfoManager::GetValue(const string varName, unsigned long long& value) {
+unsigned long long InfoManager::GetValue(const string& varName, unsigned long long& value) {
string data;
if (GetValue(varName,data) != 0)
@@ -162,7 +184,7 @@ unsigned long long InfoManager::GetValue(const string varName, unsigned long lon
}
// This function will return an empty string if the value doesn't exist
-string InfoManager::GetStrValue(const string varName) {
+string InfoManager::GetStrValue(const string& varName) {
string retVal;
GetValue(varName, retVal);
@@ -170,14 +192,14 @@ string InfoManager::GetStrValue(const string varName) {
}
// This function will return 0 if the value doesn't exist
-int InfoManager::GetIntValue(const string varName) {
+int InfoManager::GetIntValue(const string& varName) {
string retVal;
GetValue(varName, retVal);
return atoi(retVal.c_str());
}
-int InfoManager::SetValue(const string varName, string value) {
- // Don't allow empty values or numerical starting values
+int InfoManager::SetValue(const string& varName, const string& value) {
+ // Don't allow empty names or numerical starting values
if (varName.empty() || (varName[0] >= '0' && varName[0] <= '9'))
return -1;
@@ -185,25 +207,25 @@ int InfoManager::SetValue(const string varName, string value) {
pos = mValues.find(varName);
if (pos == mValues.end())
mValues.insert(make_pair(varName, value));
- else
+ else if (!is_const)
pos->second = value;
return 0;
}
-int InfoManager::SetValue(const string varName, int value) {
+int InfoManager::SetValue(const string& varName, const int value) {
ostringstream valStr;
valStr << value;
return SetValue(varName, valStr.str());
}
-int InfoManager::SetValue(const string varName, float value) {
+int InfoManager::SetValue(const string& varName, const float value) {
ostringstream valStr;
valStr << value;
return SetValue(varName, valStr.str());
}
-int InfoManager::SetValue(const string varName, unsigned long long value) {
+int InfoManager::SetValue(const string& varName, const unsigned long long& value) {
ostringstream valStr;
valStr << value;
return SetValue(varName, valStr.str());