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