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 | #include <linux/input.h> |
| 20 | #include <pthread.h> |
| 21 | #include <stdarg.h> |
| 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
| 25 | #include <fcntl.h> |
| 26 | #include <sys/stat.h> |
| 27 | #include <sys/time.h> |
| 28 | #include <sys/mman.h> |
| 29 | #include <sys/types.h> |
| 30 | #include <sys/ioctl.h> |
| 31 | #include <time.h> |
| 32 | #include <unistd.h> |
| 33 | #include <stdlib.h> |
| 34 | |
| 35 | #include <string> |
| 36 | #include <utility> |
| 37 | #include <map> |
| 38 | #include <fstream> |
| 39 | #include <sstream> |
| 40 | |
| 41 | #include "variables.h" |
| 42 | #include "data.hpp" |
| 43 | #include "partitions.hpp" |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 44 | #include "twrp-functions.hpp" |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 45 | #ifndef TW_NO_SCREEN_TIMEOUT |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 46 | #include "gui/blanktimer.hpp" |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 47 | #endif |
Ethan Yonker | 00028b4 | 2014-04-09 14:29:02 -0500 | [diff] [blame] | 48 | #include "find_file.hpp" |
Ethan Yonker | 4b94cfd | 2014-12-11 10:00:45 -0600 | [diff] [blame] | 49 | #include "set_metadata.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 50 | |
Anatoly Smaznov | 10c11f6 | 2013-02-12 13:33:40 +0700 | [diff] [blame] | 51 | #ifdef TW_USE_MODEL_HARDWARE_ID_FOR_DEVICE_ID |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 52 | #include "cutils/properties.h" |
Anatoly Smaznov | 10c11f6 | 2013-02-12 13:33:40 +0700 | [diff] [blame] | 53 | #endif |
| 54 | |
Ethan Yonker | a18f108 | 2014-07-07 15:07:58 -0500 | [diff] [blame] | 55 | #ifndef TW_MAX_BRIGHTNESS |
| 56 | #define TW_MAX_BRIGHTNESS 255 |
| 57 | #endif |
| 58 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 59 | extern "C" |
| 60 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 61 | #include "twcommon.h" |
| 62 | #include "data.h" |
Dees_Troy | 7d15c25 | 2012-09-05 20:47:21 -0400 | [diff] [blame] | 63 | #include "gui/pages.h" |
Samer Diab (S.a.M.e.R_d) | 71e9b04 | 2014-01-07 20:18:47 +0000 | [diff] [blame] | 64 | #include "minuitwrp/minui.h" |
Dees_Troy | 7d15c25 | 2012-09-05 20:47:21 -0400 | [diff] [blame] | 65 | void gui_notifyVarChange(const char *name, const char* value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 66 | } |
| 67 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 68 | #define FILE_VERSION 0x00010001 |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 69 | |
| 70 | using namespace std; |
| 71 | |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 72 | map<string, DataManager::TStrIntPair> DataManager::mValues; |
| 73 | map<string, string> DataManager::mConstValues; |
| 74 | string DataManager::mBackingFile; |
| 75 | int DataManager::mInitialized = 0; |
Jenkins | 1710bf2 | 2014-10-02 20:22:21 -0400 | [diff] [blame] | 76 | |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 77 | #ifndef TW_NO_SCREEN_TIMEOUT |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 78 | extern blanktimer blankTimer; |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 79 | #endif |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 80 | extern bool datamedia; |
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 | // Device ID functions |
| 83 | void DataManager::sanitize_device_id(char* device_id) { |
| 84 | const char* whitelist ="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-._"; |
| 85 | char str[50]; |
| 86 | char* c = str; |
| 87 | |
| 88 | strcpy(str, device_id); |
| 89 | memset(device_id, 0, sizeof(device_id)); |
| 90 | while (*c) { |
| 91 | if (strchr(whitelist, *c)) |
| 92 | strncat(device_id, c, 1); |
| 93 | c++; |
| 94 | } |
| 95 | return; |
| 96 | } |
| 97 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 98 | #define CMDLINE_SERIALNO "androidboot.serialno=" |
| 99 | #define CMDLINE_SERIALNO_LEN (strlen(CMDLINE_SERIALNO)) |
| 100 | #define CPUINFO_SERIALNO "Serial" |
| 101 | #define CPUINFO_SERIALNO_LEN (strlen(CPUINFO_SERIALNO)) |
| 102 | #define CPUINFO_HARDWARE "Hardware" |
| 103 | #define CPUINFO_HARDWARE_LEN (strlen(CPUINFO_HARDWARE)) |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 104 | |
| 105 | void DataManager::get_device_id(void) { |
| 106 | FILE *fp; |
| 107 | char line[2048]; |
| 108 | char hardware_id[32], device_id[64]; |
| 109 | char* token; |
| 110 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 111 | // Assign a blank device_id to start with |
| 112 | device_id[0] = 0; |
Anatoly Smaznov | 10c11f6 | 2013-02-12 13:33:40 +0700 | [diff] [blame] | 113 | |
| 114 | #ifdef TW_USE_MODEL_HARDWARE_ID_FOR_DEVICE_ID |
| 115 | // Now we'll use product_model_hardwareid as device id |
| 116 | char model_id[PROPERTY_VALUE_MAX]; |
| 117 | property_get("ro.product.model", model_id, "error"); |
| 118 | if (strcmp(model_id,"error") != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 119 | LOGINFO("=> product model: '%s'\n", model_id); |
Anatoly Smaznov | 10c11f6 | 2013-02-12 13:33:40 +0700 | [diff] [blame] | 120 | // Replace spaces with underscores |
| 121 | for(int i = 0; i < strlen(model_id); i++) { |
| 122 | if(model_id[i] == ' ') |
| 123 | model_id[i] = '_'; |
| 124 | } |
| 125 | strcpy(device_id, model_id); |
| 126 | if (hardware_id[0] != 0) { |
| 127 | strcat(device_id, "_"); |
| 128 | strcat(device_id, hardware_id); |
| 129 | } |
| 130 | sanitize_device_id((char *)device_id); |
| 131 | mConstValues.insert(make_pair("device_id", device_id)); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 132 | LOGINFO("=> using device id: '%s'\n", device_id); |
Anatoly Smaznov | 10c11f6 | 2013-02-12 13:33:40 +0700 | [diff] [blame] | 133 | return; |
| 134 | } |
| 135 | #endif |
| 136 | |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 137 | #ifndef TW_FORCE_CPUINFO_FOR_DEVICE_ID |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 138 | // First, try the cmdline to see if the serial number was supplied |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 139 | fp = fopen("/proc/cmdline", "rt"); |
| 140 | if (fp != NULL) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 141 | { |
| 142 | // First step, read the line. For cmdline, it's one long line |
| 143 | fgets(line, sizeof(line), fp); |
| 144 | fclose(fp); |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 145 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 146 | // Now, let's tokenize the string |
| 147 | token = strtok(line, " "); |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 148 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 149 | // Let's walk through the line, looking for the CMDLINE_SERIALNO token |
| 150 | while (token) |
| 151 | { |
| 152 | // We don't need to verify the length of token, because if it's too short, it will mismatch CMDLINE_SERIALNO at the NULL |
| 153 | if (memcmp(token, CMDLINE_SERIALNO, CMDLINE_SERIALNO_LEN) == 0) |
| 154 | { |
| 155 | // We found the serial number! |
| 156 | strcpy(device_id, token + CMDLINE_SERIALNO_LEN); |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 157 | sanitize_device_id((char *)device_id); |
| 158 | mConstValues.insert(make_pair("device_id", device_id)); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 159 | return; |
| 160 | } |
| 161 | token = strtok(NULL, " "); |
| 162 | } |
| 163 | } |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 164 | #endif |
| 165 | // Now we'll try cpuinfo for a serial number |
| 166 | fp = fopen("/proc/cpuinfo", "rt"); |
| 167 | if (fp != NULL) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 168 | { |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 169 | while (fgets(line, sizeof(line), fp) != NULL) { // First step, read the line. |
| 170 | if (memcmp(line, CPUINFO_SERIALNO, CPUINFO_SERIALNO_LEN) == 0) // check the beginning of the line for "Serial" |
| 171 | { |
| 172 | // We found the serial number! |
| 173 | token = line + CPUINFO_SERIALNO_LEN; // skip past "Serial" |
| 174 | while ((*token > 0 && *token <= 32 ) || *token == ':') token++; // skip over all spaces and the colon |
| 175 | if (*token != 0) { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 176 | token[30] = 0; |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 177 | if (token[strlen(token)-1] == 10) { // checking for endline chars and dropping them from the end of the string if needed |
| 178 | memset(device_id, 0, sizeof(device_id)); |
| 179 | strncpy(device_id, token, strlen(token) - 1); |
| 180 | } else { |
| 181 | strcpy(device_id, token); |
| 182 | } |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 183 | LOGINFO("=> serial from cpuinfo: '%s'\n", device_id); |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 184 | fclose(fp); |
| 185 | sanitize_device_id((char *)device_id); |
| 186 | mConstValues.insert(make_pair("device_id", device_id)); |
| 187 | return; |
| 188 | } |
| 189 | } else if (memcmp(line, CPUINFO_HARDWARE, CPUINFO_HARDWARE_LEN) == 0) {// We're also going to look for the hardware line in cpuinfo and save it for later in case we don't find the device ID |
| 190 | // We found the hardware ID |
| 191 | token = line + CPUINFO_HARDWARE_LEN; // skip past "Hardware" |
| 192 | while ((*token > 0 && *token <= 32 ) || *token == ':') token++; // skip over all spaces and the colon |
| 193 | if (*token != 0) { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 194 | token[30] = 0; |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 195 | if (token[strlen(token)-1] == 10) { // checking for endline chars and dropping them from the end of the string if needed |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 196 | memset(hardware_id, 0, sizeof(hardware_id)); |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 197 | strncpy(hardware_id, token, strlen(token) - 1); |
| 198 | } else { |
| 199 | strcpy(hardware_id, token); |
| 200 | } |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 201 | LOGINFO("=> hardware id from cpuinfo: '%s'\n", hardware_id); |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | } |
| 205 | fclose(fp); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 206 | } |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 207 | |
| 208 | if (hardware_id[0] != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 209 | LOGINFO("\nusing hardware id for device id: '%s'\n", hardware_id); |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 210 | strcpy(device_id, hardware_id); |
| 211 | sanitize_device_id((char *)device_id); |
| 212 | mConstValues.insert(make_pair("device_id", device_id)); |
| 213 | return; |
| 214 | } |
| 215 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 216 | strcpy(device_id, "serialno"); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 217 | LOGERR("=> device id not found, using '%s'.", device_id); |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 218 | mConstValues.insert(make_pair("device_id", device_id)); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 219 | return; |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 220 | } |
| 221 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 222 | int DataManager::ResetDefaults() |
| 223 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 224 | mValues.clear(); |
| 225 | mConstValues.clear(); |
| 226 | SetDefaultValues(); |
| 227 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | int DataManager::LoadValues(const string filename) |
| 231 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 232 | string str, dev_id; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 233 | |
| 234 | if (!mInitialized) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 235 | SetDefaultValues(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 236 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 237 | GetValue("device_id", dev_id); |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 238 | // Save off the backing file for set operations |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 239 | mBackingFile = filename; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 240 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 241 | // Read in the file, if possible |
| 242 | FILE* in = fopen(filename.c_str(), "rb"); |
| 243 | if (!in) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 244 | LOGINFO("Settings file '%s' not found.\n", filename.c_str()); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 245 | return 0; |
| 246 | } else { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 247 | LOGINFO("Loading settings from '%s'.\n", filename.c_str()); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 248 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 249 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 250 | int file_version; |
| 251 | if (fread(&file_version, 1, sizeof(int), in) != sizeof(int)) goto error; |
| 252 | if (file_version != FILE_VERSION) goto error; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 253 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 254 | while (!feof(in)) |
| 255 | { |
| 256 | string Name; |
| 257 | string Value; |
| 258 | unsigned short length; |
| 259 | char array[512]; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 260 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 261 | if (fread(&length, 1, sizeof(unsigned short), in) != sizeof(unsigned short)) goto error; |
| 262 | if (length >= 512) goto error; |
| 263 | if (fread(array, 1, length, in) != length) goto error; |
| 264 | Name = array; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 265 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 266 | if (fread(&length, 1, sizeof(unsigned short), in) != sizeof(unsigned short)) goto error; |
| 267 | if (length >= 512) goto error; |
| 268 | if (fread(array, 1, length, in) != length) goto error; |
| 269 | Value = array; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 270 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 271 | map<string, TStrIntPair>::iterator pos; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 272 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 273 | pos = mValues.find(Name); |
| 274 | if (pos != mValues.end()) |
| 275 | { |
| 276 | pos->second.first = Value; |
| 277 | pos->second.second = 1; |
| 278 | } |
| 279 | else |
| 280 | mValues.insert(TNameValuePair(Name, TStrIntPair(Value, 1))); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 281 | #ifndef TW_NO_SCREEN_TIMEOUT |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 282 | if (Name == "tw_screen_timeout_secs") |
| 283 | blankTimer.setTime(atoi(Value.c_str())); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 284 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 285 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 286 | error: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 287 | fclose(in); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 288 | string current = GetCurrentStoragePath(); |
Ethan Yonker | eeed3c5 | 2014-04-16 11:49:02 -0500 | [diff] [blame] | 289 | TWPartition* Part = PartitionManager.Find_Partition_By_Path(current); |
Vojtech Bocek | 93cb1ef | 2014-05-12 15:41:52 +0200 | [diff] [blame] | 290 | if(!Part) |
| 291 | Part = PartitionManager.Get_Default_Storage_Partition(); |
| 292 | if (Part && current != Part->Storage_Path && Part->Mount(false)) { |
Ethan Yonker | eeed3c5 | 2014-04-16 11:49:02 -0500 | [diff] [blame] | 293 | LOGINFO("LoadValues setting storage path to '%s'\n", Part->Storage_Path.c_str()); |
| 294 | SetValue("tw_storage_path", Part->Storage_Path); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 295 | } else { |
| 296 | SetBackupFolder(); |
| 297 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 298 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | int DataManager::Flush() |
| 302 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 303 | return SaveValues(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | int DataManager::SaveValues() |
| 307 | { |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 308 | #ifndef TW_OEM_BUILD |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 309 | if (mBackingFile.empty()) |
| 310 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 311 | |
| 312 | string mount_path = GetSettingsStoragePath(); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 313 | PartitionManager.Mount_By_Path(mount_path.c_str(), 1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 314 | |
| 315 | FILE* out = fopen(mBackingFile.c_str(), "wb"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 316 | if (!out) |
| 317 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 318 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 319 | int file_version = FILE_VERSION; |
| 320 | fwrite(&file_version, 1, sizeof(int), out); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 321 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 322 | map<string, TStrIntPair>::iterator iter; |
| 323 | for (iter = mValues.begin(); iter != mValues.end(); ++iter) |
| 324 | { |
| 325 | // Save only the persisted data |
| 326 | if (iter->second.second != 0) |
| 327 | { |
| 328 | unsigned short length = (unsigned short) iter->first.length() + 1; |
| 329 | fwrite(&length, 1, sizeof(unsigned short), out); |
| 330 | fwrite(iter->first.c_str(), 1, length, out); |
| 331 | length = (unsigned short) iter->second.first.length() + 1; |
| 332 | fwrite(&length, 1, sizeof(unsigned short), out); |
| 333 | fwrite(iter->second.first.c_str(), 1, length, out); |
| 334 | } |
| 335 | } |
| 336 | fclose(out); |
Ethan Yonker | 4b94cfd | 2014-12-11 10:00:45 -0600 | [diff] [blame] | 337 | tw_set_default_metadata(mBackingFile.c_str()); |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 338 | #endif // ifdef TW_OEM_BUILD |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 339 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | int DataManager::GetValue(const string varName, string& value) |
| 343 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 344 | string localStr = varName; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 345 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 346 | if (!mInitialized) |
| 347 | SetDefaultValues(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 348 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 349 | // Strip off leading and trailing '%' if provided |
| 350 | if (localStr.length() > 2 && localStr[0] == '%' && localStr[localStr.length()-1] == '%') |
| 351 | { |
| 352 | localStr.erase(0, 1); |
| 353 | localStr.erase(localStr.length() - 1, 1); |
| 354 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 355 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 356 | // Handle magic values |
| 357 | if (GetMagicValue(localStr, value) == 0) |
| 358 | return 0; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 359 | map<string, string>::iterator constPos; |
| 360 | constPos = mConstValues.find(localStr); |
| 361 | if (constPos != mConstValues.end()) |
| 362 | { |
| 363 | value = constPos->second; |
| 364 | return 0; |
| 365 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 366 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 367 | map<string, TStrIntPair>::iterator pos; |
| 368 | pos = mValues.find(localStr); |
| 369 | if (pos == mValues.end()) |
| 370 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 371 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 372 | value = pos->second.first; |
| 373 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | int DataManager::GetValue(const string varName, int& value) |
| 377 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 378 | string data; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 379 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 380 | if (GetValue(varName,data) != 0) |
| 381 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 382 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 383 | value = atoi(data.c_str()); |
| 384 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 385 | } |
| 386 | |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 387 | int DataManager::GetValue(const string varName, float& value) |
| 388 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 389 | string data; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 390 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 391 | if (GetValue(varName,data) != 0) |
| 392 | return -1; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 393 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 394 | value = atof(data.c_str()); |
| 395 | return 0; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 396 | } |
| 397 | |
bigbiff bigbiff | 2c57d78 | 2013-02-19 10:09:21 -0500 | [diff] [blame] | 398 | unsigned long long DataManager::GetValue(const string varName, unsigned long long& value) |
| 399 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 400 | string data; |
bigbiff bigbiff | 2c57d78 | 2013-02-19 10:09:21 -0500 | [diff] [blame] | 401 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 402 | if (GetValue(varName,data) != 0) |
| 403 | return -1; |
bigbiff bigbiff | 2c57d78 | 2013-02-19 10:09:21 -0500 | [diff] [blame] | 404 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 405 | value = strtoull(data.c_str(), NULL, 10); |
| 406 | return 0; |
bigbiff bigbiff | 2c57d78 | 2013-02-19 10:09:21 -0500 | [diff] [blame] | 407 | } |
| 408 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 409 | // This is a dangerous function. It will create the value if it doesn't exist so it has a valid c_str |
| 410 | string& DataManager::GetValueRef(const string varName) |
| 411 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 412 | if (!mInitialized) |
| 413 | SetDefaultValues(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 414 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 415 | map<string, string>::iterator constPos; |
| 416 | constPos = mConstValues.find(varName); |
| 417 | if (constPos != mConstValues.end()) |
| 418 | return constPos->second; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 419 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 420 | map<string, TStrIntPair>::iterator pos; |
| 421 | pos = mValues.find(varName); |
| 422 | if (pos == mValues.end()) |
| 423 | pos = (mValues.insert(TNameValuePair(varName, TStrIntPair("", 0)))).first; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 424 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 425 | return pos->second.first; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | // This function will return an empty string if the value doesn't exist |
| 429 | string DataManager::GetStrValue(const string varName) |
| 430 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 431 | string retVal; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 432 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 433 | GetValue(varName, retVal); |
| 434 | return retVal; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | // This function will return 0 if the value doesn't exist |
| 438 | int DataManager::GetIntValue(const string varName) |
| 439 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 440 | string retVal; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 441 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 442 | GetValue(varName, retVal); |
| 443 | return atoi(retVal.c_str()); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | int DataManager::SetValue(const string varName, string value, int persist /* = 0 */) |
| 447 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 448 | if (!mInitialized) |
| 449 | SetDefaultValues(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 450 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 451 | // Don't allow empty values or numerical starting values |
| 452 | if (varName.empty() || (varName[0] >= '0' && varName[0] <= '9')) |
| 453 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 454 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 455 | map<string, string>::iterator constChk; |
| 456 | constChk = mConstValues.find(varName); |
| 457 | if (constChk != mConstValues.end()) |
| 458 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 459 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 460 | map<string, TStrIntPair>::iterator pos; |
| 461 | pos = mValues.find(varName); |
| 462 | if (pos == mValues.end()) |
| 463 | pos = (mValues.insert(TNameValuePair(varName, TStrIntPair(value, persist)))).first; |
| 464 | else |
| 465 | pos->second.first = value; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 466 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 467 | if (pos->second.second != 0) |
| 468 | SaveValues(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 469 | |
| 470 | #ifndef TW_NO_SCREEN_TIMEOUT |
bigbiff bigbiff | f8e2f37 | 2013-02-27 20:50:43 -0500 | [diff] [blame] | 471 | if (varName == "tw_screen_timeout_secs") { |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 472 | blankTimer.setTime(atoi(value.c_str())); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 473 | } else |
| 474 | #endif |
| 475 | if (varName == "tw_storage_path") { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 476 | SetBackupFolder(); |
bigbiff bigbiff | f8e2f37 | 2013-02-27 20:50:43 -0500 | [diff] [blame] | 477 | } |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 478 | gui_notifyVarChange(varName.c_str(), value.c_str()); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 479 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | int DataManager::SetValue(const string varName, int value, int persist /* = 0 */) |
| 483 | { |
| 484 | ostringstream valStr; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 485 | valStr << value; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 486 | if (varName == "tw_use_external_storage") { |
| 487 | string str; |
| 488 | |
| 489 | if (GetIntValue(TW_HAS_DUAL_STORAGE) == 1) { |
| 490 | if (value == 0) { |
| 491 | str = GetStrValue(TW_INTERNAL_PATH); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 492 | } else { |
| 493 | str = GetStrValue(TW_EXTERNAL_PATH); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 494 | } |
| 495 | } else if (GetIntValue(TW_HAS_INTERNAL) == 1) |
| 496 | str = GetStrValue(TW_INTERNAL_PATH); |
| 497 | else |
| 498 | str = GetStrValue(TW_EXTERNAL_PATH); |
| 499 | |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 500 | SetValue("tw_storage_path", str); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 501 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 502 | return SetValue(varName, valStr.str(), persist); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | int DataManager::SetValue(const string varName, float value, int persist /* = 0 */) |
| 506 | { |
| 507 | ostringstream valStr; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 508 | valStr << value; |
| 509 | return SetValue(varName, valStr.str(), persist);; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 510 | } |
| 511 | |
bigbiff bigbiff | 2c57d78 | 2013-02-19 10:09:21 -0500 | [diff] [blame] | 512 | int DataManager::SetValue(const string varName, unsigned long long value, int persist /* = 0 */) |
| 513 | { |
| 514 | ostringstream valStr; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 515 | valStr << value; |
| 516 | return SetValue(varName, valStr.str(), persist); |
bigbiff bigbiff | 2c57d78 | 2013-02-19 10:09:21 -0500 | [diff] [blame] | 517 | } |
| 518 | |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 519 | int DataManager::SetProgress(float Fraction) { |
| 520 | return SetValue("ui_progress", (float) (Fraction * 100.0)); |
| 521 | } |
| 522 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 523 | int DataManager::ShowProgress(float Portion, float Seconds) |
| 524 | { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 525 | float Starting_Portion; |
| 526 | GetValue("ui_progress_portion", Starting_Portion); |
| 527 | if (SetValue("ui_progress_portion", (float)(Portion * 100.0) + Starting_Portion) != 0) |
| 528 | return -1; |
| 529 | if (SetValue("ui_progress_frames", Seconds * 30) != 0) |
| 530 | return -1; |
| 531 | return 0; |
| 532 | } |
| 533 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 534 | void DataManager::DumpValues() |
| 535 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 536 | map<string, TStrIntPair>::iterator iter; |
| 537 | gui_print("Data Manager dump - Values with leading X are persisted.\n"); |
| 538 | for (iter = mValues.begin(); iter != mValues.end(); ++iter) |
| 539 | gui_print("%c %s=%s\n", iter->second.second ? 'X' : ' ', iter->first.c_str(), iter->second.first.c_str()); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 540 | } |
| 541 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 542 | void DataManager::update_tz_environment_variables(void) |
| 543 | { |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 544 | setenv("TZ", DataManager_GetStrValue(TW_TIME_ZONE_VAR), 1); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 545 | tzset(); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 546 | } |
| 547 | |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 548 | void DataManager::SetBackupFolder() |
| 549 | { |
| 550 | string str = GetCurrentStoragePath(); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 551 | TWPartition* partition = PartitionManager.Find_Partition_By_Path(str); |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 552 | str += "/TWRP/BACKUPS/"; |
| 553 | |
| 554 | string dev_id; |
| 555 | GetValue("device_id", dev_id); |
| 556 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 557 | str += dev_id; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 558 | LOGINFO("Backup folder set to '%s'\n", str.c_str()); |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 559 | SetValue(TW_BACKUPS_FOLDER_VAR, str, 0); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 560 | if (partition != NULL) { |
| 561 | SetValue("tw_storage_display_name", partition->Storage_Name); |
| 562 | char free_space[255]; |
| 563 | sprintf(free_space, "%llu", partition->Free / 1024 / 1024); |
| 564 | SetValue("tw_storage_free_size", free_space); |
| 565 | string zip_path, zip_root, storage_path; |
| 566 | GetValue(TW_ZIP_LOCATION_VAR, zip_path); |
| 567 | if (partition->Has_Data_Media) |
| 568 | storage_path = partition->Symlink_Mount_Point; |
| 569 | else |
| 570 | storage_path = partition->Storage_Path; |
| 571 | if (zip_path.size() < storage_path.size()) { |
| 572 | SetValue(TW_ZIP_LOCATION_VAR, storage_path); |
| 573 | } else { |
Dees Troy | c2e9bc7 | 2013-09-10 00:16:24 +0000 | [diff] [blame] | 574 | zip_root = TWFunc::Get_Root_Path(zip_path); |
Dees_Troy | 1872795 | 2013-06-20 15:24:48 -0500 | [diff] [blame] | 575 | if (zip_root != storage_path) { |
| 576 | LOGINFO("DataManager::SetBackupFolder zip path was %s changing to %s, %s\n", zip_path.c_str(), storage_path.c_str(), zip_root.c_str()); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 577 | SetValue(TW_ZIP_LOCATION_VAR, storage_path); |
Dees_Troy | 1872795 | 2013-06-20 15:24:48 -0500 | [diff] [blame] | 578 | } |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 579 | } |
| 580 | } else { |
| 581 | if (PartitionManager.Fstab_Processed() != 0) |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 582 | LOGERR("Storage partition '%s' not found\n", str.c_str()); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 583 | } |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 584 | } |
| 585 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 586 | void DataManager::SetDefaultValues() |
| 587 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 588 | string str, path; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 589 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 590 | get_device_id(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 591 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 592 | mInitialized = 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 593 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 594 | mConstValues.insert(make_pair("true", "1")); |
| 595 | mConstValues.insert(make_pair("false", "0")); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 596 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 597 | mConstValues.insert(make_pair(TW_VERSION_VAR, TW_VERSION_STR)); |
Ethan Yonker | 03db326 | 2014-02-05 08:02:06 -0600 | [diff] [blame] | 598 | mValues.insert(make_pair("tw_button_vibrate", make_pair("80", 1))); |
| 599 | mValues.insert(make_pair("tw_keyboard_vibrate", make_pair("40", 1))); |
| 600 | mValues.insert(make_pair("tw_action_vibrate", make_pair("160", 1))); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 601 | |
Vojtech Bocek | 93cb1ef | 2014-05-12 15:41:52 +0200 | [diff] [blame] | 602 | TWPartition *store = PartitionManager.Get_Default_Storage_Partition(); |
| 603 | if(store) |
| 604 | mValues.insert(make_pair("tw_storage_path", make_pair(store->Storage_Path.c_str(), 1))); |
| 605 | else |
| 606 | mValues.insert(make_pair("tw_storage_path", make_pair("/", 1))); |
| 607 | |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 608 | #ifdef TW_FORCE_CPUINFO_FOR_DEVICE_ID |
| 609 | printf("TW_FORCE_CPUINFO_FOR_DEVICE_ID := true\n"); |
| 610 | #endif |
| 611 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 612 | #ifdef BOARD_HAS_NO_REAL_SDCARD |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 613 | printf("BOARD_HAS_NO_REAL_SDCARD := true\n"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 614 | mConstValues.insert(make_pair(TW_ALLOW_PARTITION_SDCARD, "0")); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 615 | #else |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 616 | mConstValues.insert(make_pair(TW_ALLOW_PARTITION_SDCARD, "1")); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 617 | #endif |
| 618 | |
| 619 | #ifdef TW_INCLUDE_DUMLOCK |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 620 | printf("TW_INCLUDE_DUMLOCK := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 621 | mConstValues.insert(make_pair(TW_SHOW_DUMLOCK, "1")); |
| 622 | #else |
| 623 | mConstValues.insert(make_pair(TW_SHOW_DUMLOCK, "0")); |
| 624 | #endif |
| 625 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 626 | str = GetCurrentStoragePath(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 627 | SetValue(TW_ZIP_LOCATION_VAR, str.c_str(), 1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 628 | str += "/TWRP/BACKUPS/"; |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 629 | |
| 630 | string dev_id; |
| 631 | GetValue("device_id", dev_id); |
| 632 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 633 | str += dev_id; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 634 | SetValue(TW_BACKUPS_FOLDER_VAR, str, 0); |
| 635 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 636 | mConstValues.insert(make_pair(TW_REBOOT_SYSTEM, "1")); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 637 | #ifdef TW_NO_REBOOT_RECOVERY |
Talustus | 33ebf93 | 2013-02-02 14:11:14 +0100 | [diff] [blame] | 638 | printf("TW_NO_REBOOT_RECOVERY := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 639 | mConstValues.insert(make_pair(TW_REBOOT_RECOVERY, "0")); |
| 640 | #else |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 641 | mConstValues.insert(make_pair(TW_REBOOT_RECOVERY, "1")); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 642 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 643 | mConstValues.insert(make_pair(TW_REBOOT_POWEROFF, "1")); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 644 | #ifdef TW_NO_REBOOT_BOOTLOADER |
Talustus | 33ebf93 | 2013-02-02 14:11:14 +0100 | [diff] [blame] | 645 | printf("TW_NO_REBOOT_BOOTLOADER := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 646 | mConstValues.insert(make_pair(TW_REBOOT_BOOTLOADER, "0")); |
| 647 | #else |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 648 | mConstValues.insert(make_pair(TW_REBOOT_BOOTLOADER, "1")); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 649 | #endif |
| 650 | #ifdef RECOVERY_SDCARD_ON_DATA |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 651 | printf("RECOVERY_SDCARD_ON_DATA := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 652 | mConstValues.insert(make_pair(TW_HAS_DATA_MEDIA, "1")); |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 653 | mConstValues.insert(make_pair("tw_has_internal", "1")); |
| 654 | datamedia = true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 655 | #else |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 656 | mValues.insert(make_pair(TW_HAS_DATA_MEDIA, make_pair("0", 0))); |
| 657 | mValues.insert(make_pair("tw_has_internal", make_pair("0", 0))); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 658 | #endif |
| 659 | #ifdef TW_NO_BATT_PERCENT |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 660 | printf("TW_NO_BATT_PERCENT := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 661 | mConstValues.insert(make_pair(TW_NO_BATTERY_PERCENT, "1")); |
| 662 | #else |
| 663 | mConstValues.insert(make_pair(TW_NO_BATTERY_PERCENT, "0")); |
| 664 | #endif |
Jenkins | 1710bf2 | 2014-10-02 20:22:21 -0400 | [diff] [blame] | 665 | #ifdef TW_NO_CPU_TEMP |
| 666 | printf("TW_NO_CPU_TEMP := true\n"); |
| 667 | mConstValues.insert(make_pair("tw_no_cpu_temp", "1")); |
| 668 | #else |
| 669 | string cpu_temp_file; |
| 670 | #ifdef TW_CUSTOM_CPU_TEMP_PATH |
| 671 | cpu_temp_file = EXPAND(TW_CUSTOM_CPU_TEMP_PATH); |
| 672 | #else |
| 673 | cpu_temp_file = "/sys/class/thermal/thermal_zone0/temp"; |
| 674 | #endif |
| 675 | if (TWFunc::Path_Exists(cpu_temp_file)) { |
| 676 | mConstValues.insert(make_pair("tw_no_cpu_temp", "0")); |
| 677 | } else { |
| 678 | LOGINFO("CPU temperature file '%s' not found, disabling CPU temp.\n", cpu_temp_file.c_str()); |
| 679 | mConstValues.insert(make_pair("tw_no_cpu_temp", "1")); |
| 680 | } |
| 681 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 682 | #ifdef TW_CUSTOM_POWER_BUTTON |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 683 | printf("TW_POWER_BUTTON := %s\n", EXPAND(TW_CUSTOM_POWER_BUTTON)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 684 | mConstValues.insert(make_pair(TW_POWER_BUTTON, EXPAND(TW_CUSTOM_POWER_BUTTON))); |
| 685 | #else |
| 686 | mConstValues.insert(make_pair(TW_POWER_BUTTON, "0")); |
| 687 | #endif |
| 688 | #ifdef TW_ALWAYS_RMRF |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 689 | printf("TW_ALWAYS_RMRF := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 690 | mConstValues.insert(make_pair(TW_RM_RF_VAR, "1")); |
| 691 | #endif |
| 692 | #ifdef TW_NEVER_UNMOUNT_SYSTEM |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 693 | printf("TW_NEVER_UNMOUNT_SYSTEM := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 694 | mConstValues.insert(make_pair(TW_DONT_UNMOUNT_SYSTEM, "1")); |
| 695 | #else |
| 696 | mConstValues.insert(make_pair(TW_DONT_UNMOUNT_SYSTEM, "0")); |
| 697 | #endif |
| 698 | #ifdef TW_NO_USB_STORAGE |
Dees_Troy | 6a042c8 | 2013-01-23 18:50:52 +0000 | [diff] [blame] | 699 | printf("TW_NO_USB_STORAGE := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 700 | mConstValues.insert(make_pair(TW_HAS_USB_STORAGE, "0")); |
| 701 | #else |
Dees_Troy | 6a042c8 | 2013-01-23 18:50:52 +0000 | [diff] [blame] | 702 | char lun_file[255]; |
| 703 | string Lun_File_str = CUSTOM_LUN_FILE; |
| 704 | size_t found = Lun_File_str.find("%"); |
| 705 | if (found != string::npos) { |
| 706 | sprintf(lun_file, CUSTOM_LUN_FILE, 0); |
| 707 | Lun_File_str = lun_file; |
| 708 | } |
| 709 | if (!TWFunc::Path_Exists(Lun_File_str)) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 710 | LOGINFO("Lun file '%s' does not exist, USB storage mode disabled\n", Lun_File_str.c_str()); |
Dees_Troy | 6a042c8 | 2013-01-23 18:50:52 +0000 | [diff] [blame] | 711 | mConstValues.insert(make_pair(TW_HAS_USB_STORAGE, "0")); |
| 712 | } else { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 713 | LOGINFO("Lun file '%s'\n", Lun_File_str.c_str()); |
Dees_Troy | 6a042c8 | 2013-01-23 18:50:52 +0000 | [diff] [blame] | 714 | mConstValues.insert(make_pair(TW_HAS_USB_STORAGE, "1")); |
| 715 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 716 | #endif |
| 717 | #ifdef TW_INCLUDE_INJECTTWRP |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 718 | printf("TW_INCLUDE_INJECTTWRP := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 719 | mConstValues.insert(make_pair(TW_HAS_INJECTTWRP, "1")); |
| 720 | mValues.insert(make_pair(TW_INJECT_AFTER_ZIP, make_pair("1", 1))); |
| 721 | #else |
| 722 | mConstValues.insert(make_pair(TW_HAS_INJECTTWRP, "0")); |
| 723 | mValues.insert(make_pair(TW_INJECT_AFTER_ZIP, make_pair("0", 1))); |
| 724 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 725 | #ifdef TW_HAS_DOWNLOAD_MODE |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 726 | printf("TW_HAS_DOWNLOAD_MODE := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 727 | mConstValues.insert(make_pair(TW_DOWNLOAD_MODE, "1")); |
| 728 | #endif |
| 729 | #ifdef TW_INCLUDE_CRYPTO |
| 730 | mConstValues.insert(make_pair(TW_HAS_CRYPTO, "1")); |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 731 | printf("TW_INCLUDE_CRYPTO := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 732 | #endif |
| 733 | #ifdef TW_SDEXT_NO_EXT4 |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 734 | printf("TW_SDEXT_NO_EXT4 := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 735 | mConstValues.insert(make_pair(TW_SDEXT_DISABLE_EXT4, "1")); |
| 736 | #else |
| 737 | mConstValues.insert(make_pair(TW_SDEXT_DISABLE_EXT4, "0")); |
| 738 | #endif |
| 739 | |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 740 | #ifdef TW_HAS_NO_BOOT_PARTITION |
Dees_Troy | f100c94 | 2013-06-21 08:15:31 -0500 | [diff] [blame] | 741 | mValues.insert(make_pair("tw_backup_list", make_pair("/system;/data;", 1))); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 742 | #else |
Dees_Troy | f100c94 | 2013-06-21 08:15:31 -0500 | [diff] [blame] | 743 | mValues.insert(make_pair("tw_backup_list", make_pair("/system;/data;/boot;", 1))); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 744 | #endif |
| 745 | mConstValues.insert(make_pair(TW_MIN_SYSTEM_VAR, TW_MIN_SYSTEM_SIZE)); |
Dees Troy | b21cc64 | 2013-09-10 17:36:41 +0000 | [diff] [blame] | 746 | mValues.insert(make_pair(TW_BACKUP_NAME, make_pair("(Auto Generate)", 0))); |
bigbiff bigbiff | 7ce7f0c | 2013-01-25 09:54:04 -0500 | [diff] [blame] | 747 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 748 | mValues.insert(make_pair(TW_REBOOT_AFTER_FLASH_VAR, make_pair("0", 1))); |
| 749 | mValues.insert(make_pair(TW_SIGNED_ZIP_VERIFY_VAR, make_pair("0", 1))); |
| 750 | mValues.insert(make_pair(TW_FORCE_MD5_CHECK_VAR, make_pair("0", 1))); |
| 751 | mValues.insert(make_pair(TW_COLOR_THEME_VAR, make_pair("0", 1))); |
| 752 | mValues.insert(make_pair(TW_USE_COMPRESSION_VAR, make_pair("0", 1))); |
| 753 | mValues.insert(make_pair(TW_SHOW_SPAM_VAR, make_pair("0", 1))); |
| 754 | mValues.insert(make_pair(TW_TIME_ZONE_VAR, make_pair("CST6CDT", 1))); |
| 755 | mValues.insert(make_pair(TW_SORT_FILES_BY_DATE_VAR, make_pair("0", 1))); |
| 756 | mValues.insert(make_pair(TW_GUI_SORT_ORDER, make_pair("1", 1))); |
| 757 | mValues.insert(make_pair(TW_RM_RF_VAR, make_pair("0", 1))); |
| 758 | mValues.insert(make_pair(TW_SKIP_MD5_CHECK_VAR, make_pair("0", 1))); |
| 759 | mValues.insert(make_pair(TW_SKIP_MD5_GENERATE_VAR, make_pair("0", 1))); |
| 760 | mValues.insert(make_pair(TW_SDEXT_SIZE, make_pair("512", 1))); |
| 761 | mValues.insert(make_pair(TW_SWAP_SIZE, make_pair("32", 1))); |
| 762 | mValues.insert(make_pair(TW_SDPART_FILE_SYSTEM, make_pair("ext3", 1))); |
| 763 | mValues.insert(make_pair(TW_TIME_ZONE_GUISEL, make_pair("CST6;CDT", 1))); |
| 764 | mValues.insert(make_pair(TW_TIME_ZONE_GUIOFFSET, make_pair("0", 1))); |
| 765 | mValues.insert(make_pair(TW_TIME_ZONE_GUIDST, make_pair("1", 1))); |
| 766 | mValues.insert(make_pair(TW_ACTION_BUSY, make_pair("0", 0))); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 767 | mValues.insert(make_pair("tw_wipe_cache", make_pair("0", 0))); |
| 768 | mValues.insert(make_pair("tw_wipe_dalvik", make_pair("0", 0))); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 769 | if (GetIntValue(TW_HAS_INTERNAL) == 1 && GetIntValue(TW_HAS_DATA_MEDIA) == 1 && GetIntValue(TW_HAS_EXTERNAL) == 0) |
| 770 | SetValue(TW_HAS_USB_STORAGE, 0, 0); |
| 771 | else |
| 772 | SetValue(TW_HAS_USB_STORAGE, 1, 0); |
| 773 | mValues.insert(make_pair(TW_ZIP_INDEX, make_pair("0", 0))); |
| 774 | mValues.insert(make_pair(TW_ZIP_QUEUE_COUNT, make_pair("0", 0))); |
| 775 | mValues.insert(make_pair(TW_FILENAME, make_pair("/sdcard", 0))); |
| 776 | mValues.insert(make_pair(TW_SIMULATE_ACTIONS, make_pair("0", 1))); |
| 777 | mValues.insert(make_pair(TW_SIMULATE_FAIL, make_pair("0", 1))); |
| 778 | mValues.insert(make_pair(TW_IS_ENCRYPTED, make_pair("0", 0))); |
| 779 | mValues.insert(make_pair(TW_IS_DECRYPTED, make_pair("0", 0))); |
| 780 | mValues.insert(make_pair(TW_CRYPTO_PASSWORD, make_pair("0", 0))); |
| 781 | mValues.insert(make_pair(TW_DATA_BLK_DEVICE, make_pair("0", 0))); |
| 782 | mValues.insert(make_pair("tw_terminal_state", make_pair("0", 0))); |
| 783 | mValues.insert(make_pair("tw_background_thread_running", make_pair("0", 0))); |
| 784 | mValues.insert(make_pair(TW_RESTORE_FILE_DATE, make_pair("0", 0))); |
bigbiff bigbiff | f8e2f37 | 2013-02-27 20:50:43 -0500 | [diff] [blame] | 785 | mValues.insert(make_pair("tw_military_time", make_pair("0", 1))); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 786 | #ifdef TW_NO_SCREEN_TIMEOUT |
| 787 | mValues.insert(make_pair("tw_screen_timeout_secs", make_pair("0", 1))); |
| 788 | mValues.insert(make_pair("tw_no_screen_timeout", make_pair("1", 1))); |
| 789 | #else |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 790 | mValues.insert(make_pair("tw_screen_timeout_secs", make_pair("60", 1))); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 791 | mValues.insert(make_pair("tw_no_screen_timeout", make_pair("0", 1))); |
| 792 | #endif |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 793 | mValues.insert(make_pair("tw_gui_done", make_pair("0", 0))); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 794 | mValues.insert(make_pair("tw_encrypt_backup", make_pair("0", 0))); |
Vojtech Bocek | 8593234 | 2013-04-01 22:11:33 +0200 | [diff] [blame] | 795 | #ifdef TW_BRIGHTNESS_PATH |
Ethan Yonker | 00028b4 | 2014-04-09 14:29:02 -0500 | [diff] [blame] | 796 | string findbright; |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 797 | if (strcmp(EXPAND(TW_BRIGHTNESS_PATH), "/nobrightness") != 0) { |
Ethan Yonker | 00028b4 | 2014-04-09 14:29:02 -0500 | [diff] [blame] | 798 | findbright = EXPAND(TW_BRIGHTNESS_PATH); |
| 799 | LOGINFO("TW_BRIGHTNESS_PATH := %s\n", findbright.c_str()); |
| 800 | if (!TWFunc::Path_Exists(findbright)) { |
| 801 | LOGINFO("Specified brightness file '%s' not found.\n", findbright.c_str()); |
| 802 | findbright = ""; |
| 803 | } |
| 804 | } |
| 805 | if (findbright.empty()) { |
| 806 | // Attempt to locate the brightness file |
| 807 | findbright = Find_File::Find("brightness", "/sys/class/backlight"); |
Ethan Yonker | 9c102b5 | 2014-04-15 11:06:18 -0500 | [diff] [blame] | 808 | if (findbright.empty()) findbright = Find_File::Find("brightness", "/sys/class/leds/lcd-backlight"); |
Ethan Yonker | 00028b4 | 2014-04-09 14:29:02 -0500 | [diff] [blame] | 809 | } |
| 810 | if (findbright.empty()) { |
| 811 | LOGINFO("Unable to locate brightness file\n"); |
| 812 | mConstValues.insert(make_pair("tw_has_brightnesss_file", "0")); |
| 813 | } else { |
| 814 | LOGINFO("Found brightness file at '%s'\n", findbright.c_str()); |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 815 | mConstValues.insert(make_pair("tw_has_brightnesss_file", "1")); |
Ethan Yonker | 00028b4 | 2014-04-09 14:29:02 -0500 | [diff] [blame] | 816 | mConstValues.insert(make_pair("tw_brightness_file", findbright)); |
Vojtech Bocek | 8593234 | 2013-04-01 22:11:33 +0200 | [diff] [blame] | 817 | ostringstream maxVal; |
| 818 | maxVal << TW_MAX_BRIGHTNESS; |
| 819 | mConstValues.insert(make_pair("tw_brightness_max", maxVal.str())); |
| 820 | mValues.insert(make_pair("tw_brightness", make_pair(maxVal.str(), 1))); |
| 821 | mValues.insert(make_pair("tw_brightness_pct", make_pair("100", 1))); |
xNUTx | e85f02d | 2014-07-18 01:30:58 +0200 | [diff] [blame] | 822 | #ifdef TW_SECONDARY_BRIGHTNESS_PATH |
| 823 | string secondfindbright = EXPAND(TW_SECONDARY_BRIGHTNESS_PATH); |
| 824 | if (secondfindbright != "" && TWFunc::Path_Exists(secondfindbright)) { |
| 825 | LOGINFO("Will use a second brightness file at '%s'\n", secondfindbright.c_str()); |
| 826 | mConstValues.insert(make_pair("tw_secondary_brightness_file", secondfindbright)); |
| 827 | } else { |
| 828 | LOGINFO("Specified secondary brightness file '%s' not found.\n", secondfindbright.c_str()); |
| 829 | } |
| 830 | #endif |
Ethan Yonker | a18f108 | 2014-07-07 15:07:58 -0500 | [diff] [blame] | 831 | string max_bright = maxVal.str(); |
xNUTx | e85f02d | 2014-07-18 01:30:58 +0200 | [diff] [blame] | 832 | TWFunc::Set_Brightness(max_bright); |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 833 | } |
| 834 | #endif |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 835 | mValues.insert(make_pair(TW_MILITARY_TIME, make_pair("0", 1))); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 836 | #ifndef TW_EXCLUDE_ENCRYPTED_BACKUPS |
| 837 | mValues.insert(make_pair("tw_include_encrypted_backup", make_pair("1", 0))); |
| 838 | #else |
| 839 | LOGINFO("TW_EXCLUDE_ENCRYPTED_BACKUPS := true\n"); |
| 840 | mValues.insert(make_pair("tw_include_encrypted_backup", make_pair("0", 0))); |
| 841 | #endif |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 842 | #ifdef TW_HAS_MTP |
| 843 | mConstValues.insert(make_pair("tw_has_mtp", "1")); |
| 844 | mValues.insert(make_pair("tw_mtp_enabled", make_pair("1", 1))); |
Ethan Yonker | c8743cf | 2014-09-03 21:16:40 -0500 | [diff] [blame] | 845 | mValues.insert(make_pair("tw_mtp_debug", make_pair("0", 1))); |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 846 | #else |
| 847 | LOGINFO("TW_EXCLUDE_MTP := true\n"); |
| 848 | mConstValues.insert(make_pair("tw_has_mtp", "0")); |
| 849 | mConstValues.insert(make_pair("tw_mtp_enabled", "0")); |
| 850 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | // Magic Values |
| 854 | int DataManager::GetMagicValue(const string varName, string& value) |
| 855 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 856 | // Handle special dynamic cases |
| 857 | if (varName == "tw_time") |
| 858 | { |
| 859 | char tmp[32]; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 860 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 861 | struct tm *current; |
| 862 | time_t now; |
| 863 | int tw_military_time; |
| 864 | now = time(0); |
| 865 | current = localtime(&now); |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 866 | GetValue(TW_MILITARY_TIME, tw_military_time); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 867 | if (current->tm_hour >= 12) |
| 868 | { |
| 869 | if (tw_military_time == 1) |
| 870 | sprintf(tmp, "%d:%02d", current->tm_hour, current->tm_min); |
| 871 | else |
| 872 | sprintf(tmp, "%d:%02d PM", current->tm_hour == 12 ? 12 : current->tm_hour - 12, current->tm_min); |
bigbiff bigbiff | 4efe9c3 | 2013-02-20 18:58:11 -0500 | [diff] [blame] | 873 | } |
bigbiff bigbiff | 4efe9c3 | 2013-02-20 18:58:11 -0500 | [diff] [blame] | 874 | else |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 875 | { |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 876 | if (tw_military_time == 1) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 877 | sprintf(tmp, "%d:%02d", current->tm_hour, current->tm_min); |
| 878 | else |
| 879 | sprintf(tmp, "%d:%02d AM", current->tm_hour == 0 ? 12 : current->tm_hour, current->tm_min); |
| 880 | } |
| 881 | value = tmp; |
| 882 | return 0; |
bigbiff bigbiff | 4efe9c3 | 2013-02-20 18:58:11 -0500 | [diff] [blame] | 883 | } |
Jenkins | 1710bf2 | 2014-10-02 20:22:21 -0400 | [diff] [blame] | 884 | else if (varName == "tw_cpu_temp") |
| 885 | { |
| 886 | string cpu_temp_file; |
| 887 | static unsigned long convert_temp = 0; |
| 888 | static time_t cpuSecCheck = 0; |
| 889 | int divisor = 0; |
| 890 | struct timeval curTime; |
| 891 | string results; |
| 892 | |
| 893 | gettimeofday(&curTime, NULL); |
| 894 | if (curTime.tv_sec > cpuSecCheck) |
| 895 | { |
| 896 | #ifdef TW_CUSTOM_CPU_TEMP_PATH |
| 897 | cpu_temp_file = EXPAND(TW_CUSTOM_CPU_TEMP_PATH); |
| 898 | if (TWFunc::read_file(cpu_temp_file, results) != 0) |
| 899 | return -1; |
| 900 | #else |
| 901 | cpu_temp_file = "/sys/class/thermal/thermal_zone0/temp"; |
| 902 | if (TWFunc::read_file(cpu_temp_file, results) != 0) |
| 903 | return -1; |
| 904 | #endif |
| 905 | convert_temp = strtoul(results.c_str(), NULL, 0) / 1000; |
| 906 | if (convert_temp <= 0) |
| 907 | convert_temp = strtoul(results.c_str(), NULL, 0); |
HandyMenny | b603345 | 2014-10-15 21:39:12 +0200 | [diff] [blame] | 908 | if (convert_temp >= 150) |
| 909 | convert_temp = strtoul(results.c_str(), NULL, 0) / 10; |
| 910 | cpuSecCheck = curTime.tv_sec + 5; |
Jenkins | 1710bf2 | 2014-10-02 20:22:21 -0400 | [diff] [blame] | 911 | } |
| 912 | value = TWFunc::to_string(convert_temp); |
| 913 | return 0; |
| 914 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 915 | else if (varName == "tw_battery") |
| 916 | { |
| 917 | char tmp[16]; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 918 | static char charging = ' '; |
| 919 | static int lastVal = -1; |
| 920 | static time_t nextSecCheck = 0; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 921 | struct timeval curTime; |
| 922 | gettimeofday(&curTime, NULL); |
| 923 | if (curTime.tv_sec > nextSecCheck) |
| 924 | { |
| 925 | char cap_s[4]; |
Dees_Troy | f33b490 | 2013-03-01 00:51:39 +0000 | [diff] [blame] | 926 | #ifdef TW_CUSTOM_BATTERY_PATH |
| 927 | string capacity_file = EXPAND(TW_CUSTOM_BATTERY_PATH); |
| 928 | capacity_file += "/capacity"; |
| 929 | FILE * cap = fopen(capacity_file.c_str(),"rt"); |
| 930 | #else |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 931 | FILE * cap = fopen("/sys/class/power_supply/battery/capacity","rt"); |
Dees_Troy | f33b490 | 2013-03-01 00:51:39 +0000 | [diff] [blame] | 932 | #endif |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 933 | if (cap){ |
| 934 | fgets(cap_s, 4, cap); |
| 935 | fclose(cap); |
| 936 | lastVal = atoi(cap_s); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 937 | if (lastVal > 100) lastVal = 101; |
| 938 | if (lastVal < 0) lastVal = 0; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 939 | } |
Dees_Troy | f33b490 | 2013-03-01 00:51:39 +0000 | [diff] [blame] | 940 | #ifdef TW_CUSTOM_BATTERY_PATH |
| 941 | string status_file = EXPAND(TW_CUSTOM_BATTERY_PATH); |
| 942 | status_file += "/status"; |
| 943 | cap = fopen(status_file.c_str(),"rt"); |
| 944 | #else |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 945 | cap = fopen("/sys/class/power_supply/battery/status","rt"); |
Dees_Troy | f33b490 | 2013-03-01 00:51:39 +0000 | [diff] [blame] | 946 | #endif |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 947 | if (cap) { |
| 948 | fgets(cap_s, 2, cap); |
| 949 | fclose(cap); |
| 950 | if (cap_s[0] == 'C') |
| 951 | charging = '+'; |
| 952 | else |
| 953 | charging = ' '; |
| 954 | } |
| 955 | nextSecCheck = curTime.tv_sec + 60; |
| 956 | } |
| 957 | |
| 958 | sprintf(tmp, "%i%%%c", lastVal, charging); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 959 | value = tmp; |
| 960 | return 0; |
| 961 | } |
| 962 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 963 | } |
| 964 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 965 | void DataManager::Output_Version(void) |
| 966 | { |
Dees_Troy | 1c1ac44 | 2013-01-17 21:42:14 +0000 | [diff] [blame] | 967 | string Path; |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 968 | char version[255]; |
| 969 | |
Dees_Troy | 1c1ac44 | 2013-01-17 21:42:14 +0000 | [diff] [blame] | 970 | if (!PartitionManager.Mount_By_Path("/cache", false)) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 971 | LOGINFO("Unable to mount '%s' to write version number.\n", Path.c_str()); |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 972 | return; |
| 973 | } |
Dees_Troy | 1c1ac44 | 2013-01-17 21:42:14 +0000 | [diff] [blame] | 974 | if (!TWFunc::Path_Exists("/cache/recovery/.")) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 975 | LOGINFO("Recreating /cache/recovery folder.\n"); |
Dees_Troy | 1c1ac44 | 2013-01-17 21:42:14 +0000 | [diff] [blame] | 976 | if (mkdir("/cache/recovery", S_IRWXU | S_IRWXG | S_IWGRP | S_IXGRP) != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 977 | LOGERR("DataManager::Output_Version -- Unable to make /cache/recovery\n"); |
Dees_Troy | 1c1ac44 | 2013-01-17 21:42:14 +0000 | [diff] [blame] | 978 | return; |
| 979 | } |
| 980 | } |
| 981 | Path = "/cache/recovery/.version"; |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 982 | if (TWFunc::Path_Exists(Path)) { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 983 | unlink(Path.c_str()); |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 984 | } |
| 985 | FILE *fp = fopen(Path.c_str(), "w"); |
| 986 | if (fp == NULL) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 987 | LOGERR("Unable to open '%s'.\n", Path.c_str()); |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 988 | return; |
| 989 | } |
| 990 | strcpy(version, TW_VERSION_STR); |
| 991 | fwrite(version, sizeof(version[0]), strlen(version) / sizeof(version[0]), fp); |
| 992 | fclose(fp); |
Dees_Troy | d93bda5 | 2013-07-03 19:55:19 +0000 | [diff] [blame] | 993 | TWFunc::copy_file("/etc/recovery.fstab", "/cache/recovery/recovery.fstab", 0644); |
| 994 | PartitionManager.Output_Storage_Fstab(); |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 995 | sync(); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 996 | LOGINFO("Version number saved to '%s'\n", Path.c_str()); |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 997 | } |
| 998 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 999 | void DataManager::ReadSettingsFile(void) |
| 1000 | { |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 1001 | #ifndef TW_OEM_BUILD |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1002 | // Load up the values for TWRP - Sleep to let the card be ready |
| 1003 | char mkdir_path[255], settings_file[255]; |
| 1004 | int is_enc, has_dual, use_ext, has_data_media, has_ext; |
| 1005 | |
| 1006 | GetValue(TW_IS_ENCRYPTED, is_enc); |
| 1007 | GetValue(TW_HAS_DATA_MEDIA, has_data_media); |
| 1008 | if (is_enc == 1 && has_data_media == 1) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1009 | LOGINFO("Cannot load settings -- encrypted.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1010 | return; |
| 1011 | } |
| 1012 | |
| 1013 | memset(mkdir_path, 0, sizeof(mkdir_path)); |
| 1014 | memset(settings_file, 0, sizeof(settings_file)); |
| 1015 | sprintf(mkdir_path, "%s/TWRP", DataManager_GetSettingsStoragePath()); |
| 1016 | sprintf(settings_file, "%s/.twrps", mkdir_path); |
| 1017 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1018 | if (!PartitionManager.Mount_Settings_Storage(false)) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1019 | { |
| 1020 | usleep(500000); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1021 | if (!PartitionManager.Mount_Settings_Storage(false)) |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1022 | LOGERR("Unable to mount %s when trying to read settings file.\n", settings_file); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | mkdir(mkdir_path, 0777); |
| 1026 | |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1027 | LOGINFO("Attempt to load settings from settings file...\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1028 | LoadValues(settings_file); |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1029 | Output_Version(); |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 1030 | #endif // ifdef TW_OEM_BUILD |
Ethan Yonker | 7af51ce | 2014-04-04 13:33:30 -0500 | [diff] [blame] | 1031 | PartitionManager.Mount_All_Storage(); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 1032 | update_tz_environment_variables(); |
xNUTx | e85f02d | 2014-07-18 01:30:58 +0200 | [diff] [blame] | 1033 | #ifdef TW_MAX_BRIGHTNESS |
| 1034 | if (GetStrValue("tw_brightness_path") != "/nobrightness") { |
| 1035 | TWFunc::Set_Brightness(GetStrValue("tw_brightness")); |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 1036 | } |
xNUTx | e85f02d | 2014-07-18 01:30:58 +0200 | [diff] [blame] | 1037 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | string DataManager::GetCurrentStoragePath(void) |
| 1041 | { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 1042 | return GetStrValue("tw_storage_path"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | string& DataManager::CGetCurrentStoragePath() |
| 1046 | { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 1047 | return GetValueRef("tw_storage_path"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | string DataManager::GetSettingsStoragePath(void) |
| 1051 | { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 1052 | return GetStrValue("tw_settings_path"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | string& DataManager::CGetSettingsStoragePath() |
| 1056 | { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 1057 | return GetValueRef("tw_settings_path"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1058 | } |
| 1059 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1060 | extern "C" int DataManager_ResetDefaults(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1061 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1062 | return DataManager::ResetDefaults(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1063 | } |
| 1064 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1065 | extern "C" void DataManager_LoadDefaults(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1066 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1067 | return DataManager::SetDefaultValues(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | extern "C" int DataManager_LoadValues(const char* filename) |
| 1071 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1072 | return DataManager::LoadValues(filename); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1073 | } |
| 1074 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1075 | extern "C" int DataManager_Flush(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1076 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1077 | return DataManager::Flush(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | extern "C" int DataManager_GetValue(const char* varName, char* value) |
| 1081 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1082 | int ret; |
| 1083 | string str; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1084 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1085 | ret = DataManager::GetValue(varName, str); |
| 1086 | if (ret == 0) |
| 1087 | strcpy(value, str.c_str()); |
| 1088 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | extern "C" const char* DataManager_GetStrValue(const char* varName) |
| 1092 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1093 | string& str = DataManager::GetValueRef(varName); |
| 1094 | return str.c_str(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | extern "C" const char* DataManager_GetCurrentStoragePath(void) |
| 1098 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1099 | string& str = DataManager::CGetCurrentStoragePath(); |
| 1100 | return str.c_str(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | extern "C" const char* DataManager_GetSettingsStoragePath(void) |
| 1104 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1105 | string& str = DataManager::CGetSettingsStoragePath(); |
| 1106 | return str.c_str(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1107 | } |
| 1108 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1109 | extern "C" int DataManager_GetIntValue(const char* varName) |
| 1110 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1111 | return DataManager::GetIntValue(varName); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | extern "C" int DataManager_SetStrValue(const char* varName, char* value) |
| 1115 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1116 | return DataManager::SetValue(varName, value, 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | extern "C" int DataManager_SetIntValue(const char* varName, int value) |
| 1120 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1121 | return DataManager::SetValue(varName, value, 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | extern "C" int DataManager_SetFloatValue(const char* varName, float value) |
| 1125 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1126 | return DataManager::SetValue(varName, value, 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | extern "C" int DataManager_ToggleIntValue(const char* varName) |
| 1130 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1131 | if (DataManager::GetIntValue(varName)) |
| 1132 | return DataManager::SetValue(varName, 0); |
| 1133 | else |
| 1134 | return DataManager::SetValue(varName, 1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1135 | } |
| 1136 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1137 | extern "C" void DataManager_DumpValues(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1138 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1139 | return DataManager::DumpValues(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1140 | } |
| 1141 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1142 | extern "C" void DataManager_ReadSettingsFile(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1143 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1144 | return DataManager::ReadSettingsFile(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1145 | } |
Samer Diab (S.a.M.e.R_d) | 71e9b04 | 2014-01-07 20:18:47 +0000 | [diff] [blame] | 1146 | void DataManager::Vibrate(const string varName) |
| 1147 | { |
| 1148 | int vib_value = 0; |
| 1149 | GetValue(varName, vib_value); |
| 1150 | if (vib_value) { |
| 1151 | vibrate(vib_value); |
| 1152 | } |
| 1153 | } |