Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef _DATAMANAGER_HPP_HEADER |
| 18 | #define _DATAMANAGER_HPP_HEADER |
| 19 | |
| 20 | #include <string> |
| 21 | #include <utility> |
| 22 | #include <map> |
| 23 | |
| 24 | using namespace std; |
| 25 | |
| 26 | class DataManager |
| 27 | { |
| 28 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 29 | static int ResetDefaults(); |
| 30 | static int LoadValues(const string filename); |
| 31 | static int Flush(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 32 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 33 | // Core get routines |
| 34 | static int GetValue(const string varName, string& value); |
| 35 | static int GetValue(const string varName, int& value); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 36 | static int GetValue(const string varName, float& value); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 37 | static unsigned long long GetValue(const string varName, unsigned long long& value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 38 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 39 | // This is a dangerous function. It will create the value if it doesn't exist so it has a valid c_str |
| 40 | static string& GetValueRef(const string varName); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 41 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 42 | // Helper functions |
| 43 | static string GetStrValue(const string varName); |
| 44 | static int GetIntValue(const string varName); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 45 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 46 | // Core set routines |
| 47 | static int SetValue(const string varName, string value, int persist = 0); |
| 48 | static int SetValue(const string varName, int value, int persist = 0); |
| 49 | static int SetValue(const string varName, float value, int persist = 0); |
| 50 | static int SetValue(const string varName, unsigned long long value, int persist = 0); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 51 | static int SetProgress(float Fraction); |
| 52 | static int ShowProgress(float Portion, float Seconds); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 53 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 54 | static void DumpValues(); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 55 | static void update_tz_environment_variables(); |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 56 | static void SetBackupFolder(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 57 | static void SetDefaultValues(); |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 58 | static void Output_Version(void); // Outputs the version to a file in the TWRP folder |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 59 | static void ReadSettingsFile(void); |
bigbiff bigbiff | 2c57d78 | 2013-02-19 10:09:21 -0500 | [diff] [blame] | 60 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 61 | static string GetCurrentStoragePath(void); |
| 62 | static string& CGetCurrentStoragePath(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 63 | static string GetSettingsStoragePath(void); |
| 64 | static string& CGetSettingsStoragePath(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 65 | |
| 66 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 67 | typedef pair<string, int> TStrIntPair; |
| 68 | typedef pair<string, unsigned long long> TStrULLPair; |
| 69 | typedef pair<string, TStrIntPair> TNameValuePair; |
| 70 | static map<string, TStrIntPair> mValues; |
| 71 | static map<string, TStrULLPair> mULLValues; |
| 72 | static string mBackingFile; |
| 73 | static int mInitialized; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 74 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 75 | static map<string, string> mConstValues; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 76 | |
| 77 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 78 | static int SaveValues(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 79 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 80 | static int GetMagicValue(string varName, string& value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 81 | |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 82 | private: |
| 83 | static void sanitize_device_id(char* device_id); |
| 84 | static void get_device_id(void); |
| 85 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | #endif // _DATAMANAGER_HPP_HEADER |
| 89 | |