blob: 723cf9b12a514ed22e95a6b9c0d8fb85d7cb1497 [file] [log] [blame]
Dees_Troy51a0e822012-09-05 15:24:24 -04001/*
Dees Troy3be70a82013-10-22 14:25:12 +00002 Copyright 2012 bigbiff/Dees_Troy TeamWin
3 This file is part of TWRP/TeamWin Recovery Project.
4
5 TWRP is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 TWRP is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with TWRP. If not, see <http://www.gnu.org/licenses/>.
17*/
Dees_Troy51a0e822012-09-05 15:24:24 -040018
19#ifndef _DATAMANAGER_HPP_HEADER
20#define _DATAMANAGER_HPP_HEADER
21
22#include <string>
23#include <utility>
24#include <map>
25
26using namespace std;
27
28class DataManager
29{
30public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020031 static int ResetDefaults();
32 static int LoadValues(const string filename);
33 static int Flush();
Dees_Troy51a0e822012-09-05 15:24:24 -040034
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020035 // Core get routines
36 static int GetValue(const string varName, string& value);
37 static int GetValue(const string varName, int& value);
Dees_Troy2673cec2013-04-02 20:22:16 +000038 static int GetValue(const string varName, float& value);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020039 static unsigned long long GetValue(const string varName, unsigned long long& value);
Dees_Troy51a0e822012-09-05 15:24:24 -040040
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020041 // This is a dangerous function. It will create the value if it doesn't exist so it has a valid c_str
42 static string& GetValueRef(const string varName);
Dees_Troy51a0e822012-09-05 15:24:24 -040043
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020044 // Helper functions
45 static string GetStrValue(const string varName);
46 static int GetIntValue(const string varName);
Dees_Troy51a0e822012-09-05 15:24:24 -040047
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020048 // Core set routines
49 static int SetValue(const string varName, string value, int persist = 0);
50 static int SetValue(const string varName, int value, int persist = 0);
51 static int SetValue(const string varName, float value, int persist = 0);
52 static int SetValue(const string varName, unsigned long long value, int persist = 0);
Dees_Troy2673cec2013-04-02 20:22:16 +000053 static int SetProgress(float Fraction);
54 static int ShowProgress(float Portion, float Seconds);
Dees_Troy51a0e822012-09-05 15:24:24 -040055
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020056 static void DumpValues();
Dees_Troy8170a922012-09-18 15:40:25 -040057 static void update_tz_environment_variables();
Dees_Troy16b74352012-11-14 22:27:31 +000058 static void SetBackupFolder();
Dees_Troy51a0e822012-09-05 15:24:24 -040059 static void SetDefaultValues();
Dees_Troy01a9b7a2012-10-01 09:01:03 -040060 static void Output_Version(void); // Outputs the version to a file in the TWRP folder
Dees_Troy51a0e822012-09-05 15:24:24 -040061 static void ReadSettingsFile(void);
bigbiff bigbiff2c57d782013-02-19 10:09:21 -050062
Dees_Troy51a0e822012-09-05 15:24:24 -040063 static string GetCurrentStoragePath(void);
64 static string& CGetCurrentStoragePath();
Dees_Troy51a0e822012-09-05 15:24:24 -040065 static string GetSettingsStoragePath(void);
66 static string& CGetSettingsStoragePath();
Dees_Troy51a0e822012-09-05 15:24:24 -040067
68protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020069 typedef pair<string, int> TStrIntPair;
70 typedef pair<string, unsigned long long> TStrULLPair;
71 typedef pair<string, TStrIntPair> TNameValuePair;
72 static map<string, TStrIntPair> mValues;
73 static map<string, TStrULLPair> mULLValues;
74 static string mBackingFile;
75 static int mInitialized;
Dees_Troy51a0e822012-09-05 15:24:24 -040076
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020077 static map<string, string> mConstValues;
Dees_Troy51a0e822012-09-05 15:24:24 -040078
79protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020080 static int SaveValues();
Dees_Troy51a0e822012-09-05 15:24:24 -040081
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020082 static int GetMagicValue(string varName, string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -040083
Dees_Troyfdf5fcc2012-09-11 10:27:01 -040084private:
85 static void sanitize_device_id(char* device_id);
86 static void get_device_id(void);
87
Dees_Troy51a0e822012-09-05 15:24:24 -040088};
89
90#endif // _DATAMANAGER_HPP_HEADER
91