Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1 | /* |
Dees Troy | 3be70a8 | 2013-10-22 14:25:12 +0000 | [diff] [blame] | 2 | 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 18 | |
| 19 | #ifndef _DATAMANAGER_HPP_HEADER |
| 20 | #define _DATAMANAGER_HPP_HEADER |
| 21 | |
| 22 | #include <string> |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 23 | #include <pthread.h> |
Ethan Yonker | fe91611 | 2016-03-14 14:54:37 -0500 | [diff] [blame] | 24 | #include "infomanager.hpp" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 25 | |
| 26 | using namespace std; |
| 27 | |
| 28 | class DataManager |
| 29 | { |
| 30 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 31 | static int ResetDefaults(); |
Ethan Yonker | fe91611 | 2016-03-14 14:54:37 -0500 | [diff] [blame] | 32 | static int LoadValues(const string& filename); |
nkk71 | 98fc399 | 2017-12-16 16:26:42 +0200 | [diff] [blame] | 33 | static int LoadPersistValues(void); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 34 | static int Flush(); |
epicX | a721f95 | 2021-01-04 13:01:31 +0530 | [diff] [blame] | 35 | static void LoadTWRPFolderInfo(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 36 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 37 | // Core get routines |
Ethan Yonker | fe91611 | 2016-03-14 14:54:37 -0500 | [diff] [blame] | 38 | static int GetValue(const string& varName, string& value); |
| 39 | static int GetValue(const string& varName, int& value); |
| 40 | static int GetValue(const string& varName, float& value); |
nkk71 | 98fc399 | 2017-12-16 16:26:42 +0200 | [diff] [blame] | 41 | static int GetValue(const string& varName, unsigned long long& value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 42 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 43 | // Helper functions |
Ethan Yonker | fe91611 | 2016-03-14 14:54:37 -0500 | [diff] [blame] | 44 | static string GetStrValue(const string& varName); |
| 45 | static int GetIntValue(const string& varName); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 46 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 47 | // Core set routines |
Ethan Yonker | fe91611 | 2016-03-14 14:54:37 -0500 | [diff] [blame] | 48 | static int SetValue(const string& varName, const string& value, const int persist = 0); |
| 49 | static int SetValue(const string& varName, const int value, const int persist = 0); |
| 50 | static int SetValue(const string& varName, const float value, const int persist = 0); |
| 51 | static int SetValue(const string& varName, const unsigned long long& value, const int persist = 0); |
| 52 | static int SetProgress(const float Fraction); |
Chaosmaster | d5364a0 | 2020-02-03 15:38:02 +0100 | [diff] [blame] | 53 | static int _SetProgress(float Fraction); |
| 54 | static int ShowProgress(float Portion, const float Seconds); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 55 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 56 | static void DumpValues(); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 57 | static void update_tz_environment_variables(); |
Ethan Yonker | fe91611 | 2016-03-14 14:54:37 -0500 | [diff] [blame] | 58 | static void Vibrate(const string& varName); |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 59 | static void SetBackupFolder(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 60 | static void SetDefaultValues(); |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 61 | 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] | 62 | static void ReadSettingsFile(void); |
bigbiff bigbiff | 2c57d78 | 2013-02-19 10:09:21 -0500 | [diff] [blame] | 63 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 64 | static string GetCurrentStoragePath(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 65 | static string GetSettingsStoragePath(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 66 | |
epicX | a721f95 | 2021-01-04 13:01:31 +0530 | [diff] [blame] | 67 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 68 | static string mBackingFile; |
epicX | a721f95 | 2021-01-04 13:01:31 +0530 | [diff] [blame] | 69 | |
| 70 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 71 | static int mInitialized; |
Ethan Yonker | fe91611 | 2016-03-14 14:54:37 -0500 | [diff] [blame] | 72 | static InfoManager mPersist; |
| 73 | static InfoManager mData; |
| 74 | static InfoManager mConst; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 75 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 76 | static map<string, string> mConstValues; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 77 | |
| 78 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 79 | static int SaveValues(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 80 | |
Ethan Yonker | fe91611 | 2016-03-14 14:54:37 -0500 | [diff] [blame] | 81 | static int GetMagicValue(const string& varName, string& value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 82 | |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 83 | private: |
| 84 | static void sanitize_device_id(char* device_id); |
| 85 | static void get_device_id(void); |
| 86 | |
Vojtech Bocek | fda239b | 2015-01-07 22:55:13 +0100 | [diff] [blame] | 87 | static pthread_mutex_t m_valuesLock; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | #endif // _DATAMANAGER_HPP_HEADER |
| 91 | |