blob: 9c53c46f126659b987ed1c8dbe3ce0d90c34417b [file] [log] [blame]
Dees_Troy51a0e822012-09-05 15:24:24 -04001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <linux/input.h>
18#include <pthread.h>
19#include <stdarg.h>
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23#include <fcntl.h>
24#include <sys/stat.h>
25#include <sys/time.h>
26#include <sys/mman.h>
27#include <sys/types.h>
28#include <sys/ioctl.h>
29#include <time.h>
30#include <unistd.h>
31#include <stdlib.h>
32
33#include <string>
34#include <utility>
35#include <map>
36#include <fstream>
37#include <sstream>
38
39#include "variables.h"
40#include "data.hpp"
41#include "partitions.hpp"
42
43extern "C"
44{
45 #include "common.h"
46 #include "data.h"
47 #include "tw_reboot.h"
48 #include "roots.h"
Dees_Troy7d15c252012-09-05 20:47:21 -040049 #include "gui/pages.h"
50
51 void gui_notifyVarChange(const char *name, const char* value);
Dees_Troy51a0e822012-09-05 15:24:24 -040052
Dees_Troy51a0e822012-09-05 15:24:24 -040053 int __system(const char *command);
54}
55
56#define FILE_VERSION 0x00010001
57
58using namespace std;
59
60map<string, DataManager::TStrIntPair> DataManager::mValues;
61map<string, string> DataManager::mConstValues;
62string DataManager::mBackingFile;
63int DataManager::mInitialized = 0;
64
Dees_Troyfdf5fcc2012-09-11 10:27:01 -040065// Device ID functions
66void DataManager::sanitize_device_id(char* device_id) {
67 const char* whitelist ="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-._";
68 char str[50];
69 char* c = str;
70
71 strcpy(str, device_id);
72 memset(device_id, 0, sizeof(device_id));
73 while (*c) {
74 if (strchr(whitelist, *c))
75 strncat(device_id, c, 1);
76 c++;
77 }
78 return;
79}
80
81#define CMDLINE_SERIALNO "androidboot.serialno="
82#define CMDLINE_SERIALNO_LEN (strlen(CMDLINE_SERIALNO))
83#define CPUINFO_SERIALNO "Serial"
84#define CPUINFO_SERIALNO_LEN (strlen(CPUINFO_SERIALNO))
85#define CPUINFO_HARDWARE "Hardware"
86#define CPUINFO_HARDWARE_LEN (strlen(CPUINFO_HARDWARE))
87
88void DataManager::get_device_id(void) {
89 FILE *fp;
90 char line[2048];
91 char hardware_id[32], device_id[64];
92 char* token;
93
94 // Assign a blank device_id to start with
95 device_id[0] = 0;
96#ifndef TW_FORCE_CPUINFO_FOR_DEVICE_ID
97 // First, try the cmdline to see if the serial number was supplied
98 fp = fopen("/proc/cmdline", "rt");
99 if (fp != NULL)
100 {
101 // First step, read the line. For cmdline, it's one long line
102 fgets(line, sizeof(line), fp);
103 fclose(fp);
104
105 // Now, let's tokenize the string
106 token = strtok(line, " ");
107
108 // Let's walk through the line, looking for the CMDLINE_SERIALNO token
109 while (token)
110 {
111 // We don't need to verify the length of token, because if it's too short, it will mismatch CMDLINE_SERIALNO at the NULL
112 if (memcmp(token, CMDLINE_SERIALNO, CMDLINE_SERIALNO_LEN) == 0)
113 {
114 // We found the serial number!
115 strcpy(device_id, token + CMDLINE_SERIALNO_LEN);
116 sanitize_device_id((char *)device_id);
117 mConstValues.insert(make_pair("device_id", device_id));
118 return;
119 }
120 token = strtok(NULL, " ");
121 }
122 }
123#endif
124 // Now we'll try cpuinfo for a serial number
125 fp = fopen("/proc/cpuinfo", "rt");
126 if (fp != NULL)
127 {
128 while (fgets(line, sizeof(line), fp) != NULL) { // First step, read the line.
129 if (memcmp(line, CPUINFO_SERIALNO, CPUINFO_SERIALNO_LEN) == 0) // check the beginning of the line for "Serial"
130 {
131 // We found the serial number!
132 token = line + CPUINFO_SERIALNO_LEN; // skip past "Serial"
133 while ((*token > 0 && *token <= 32 ) || *token == ':') token++; // skip over all spaces and the colon
134 if (*token != 0) {
135 token[30] = 0;
136 if (token[strlen(token)-1] == 10) { // checking for endline chars and dropping them from the end of the string if needed
137 memset(device_id, 0, sizeof(device_id));
138 strncpy(device_id, token, strlen(token) - 1);
139 } else {
140 strcpy(device_id, token);
141 }
142 LOGI("=> serial from cpuinfo: '%s'\n", device_id);
143 fclose(fp);
144 sanitize_device_id((char *)device_id);
145 mConstValues.insert(make_pair("device_id", device_id));
146 return;
147 }
148 } 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
149 // We found the hardware ID
150 token = line + CPUINFO_HARDWARE_LEN; // skip past "Hardware"
151 while ((*token > 0 && *token <= 32 ) || *token == ':') token++; // skip over all spaces and the colon
152 if (*token != 0) {
153 token[30] = 0;
154 if (token[strlen(token)-1] == 10) { // checking for endline chars and dropping them from the end of the string if needed
155 memset(hardware_id, 0, sizeof(hardware_id));
156 strncpy(hardware_id, token, strlen(token) - 1);
157 } else {
158 strcpy(hardware_id, token);
159 }
160 LOGI("=> hardware id from cpuinfo: '%s'\n", hardware_id);
161 }
162 }
163 }
164 fclose(fp);
165 }
166
167 if (hardware_id[0] != 0) {
168 LOGW("\nusing hardware id for device id: '%s'\n", hardware_id);
169 strcpy(device_id, hardware_id);
170 sanitize_device_id((char *)device_id);
171 mConstValues.insert(make_pair("device_id", device_id));
172 return;
173 }
174
175 strcpy(device_id, "serialno");
176 LOGE("=> device id not found, using '%s'.", device_id);
177 mConstValues.insert(make_pair("device_id", device_id));
178 return;
179}
180
Dees_Troy51a0e822012-09-05 15:24:24 -0400181int DataManager::ResetDefaults()
182{
183 mValues.clear();
184 mConstValues.clear();
185 SetDefaultValues();
186 return 0;
187}
188
189int DataManager::LoadValues(const string filename)
190{
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400191 string str, dev_id;
Dees_Troy51a0e822012-09-05 15:24:24 -0400192
193 if (!mInitialized)
194 SetDefaultValues();
195
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400196 GetValue("device_id", dev_id);
197 // Save off the backing file for set operations
Dees_Troy51a0e822012-09-05 15:24:24 -0400198 mBackingFile = filename;
199
200 // Read in the file, if possible
201 FILE* in = fopen(filename.c_str(), "rb");
202 if (!in) return 0;
203
204 int file_version;
205 if (fread(&file_version, 1, sizeof(int), in) != sizeof(int)) goto error;
206 if (file_version != FILE_VERSION) goto error;
207
208 while (!feof(in))
209 {
210 string Name;
211 string Value;
212 unsigned short length;
213 char array[512];
214
215 if (fread(&length, 1, sizeof(unsigned short), in) != sizeof(unsigned short)) goto error;
216 if (length >= 512) goto error;
217 if (fread(array, 1, length, in) != length) goto error;
218 Name = array;
219
220 if (fread(&length, 1, sizeof(unsigned short), in) != sizeof(unsigned short)) goto error;
221 if (length >= 512) goto error;
222 if (fread(array, 1, length, in) != length) goto error;
223 Value = array;
224
225 map<string, TStrIntPair>::iterator pos;
226
227 pos = mValues.find(Name);
228 if (pos != mValues.end())
229 {
230 pos->second.first = Value;
231 pos->second.second = 1;
232 }
233 else
234 mValues.insert(TNameValuePair(Name, TStrIntPair(Value, 1)));
235 }
236 fclose(in);
237
238 str = GetCurrentStoragePath();
239 str += "/TWRP/BACKUPS/";
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400240 str += dev_id;
Dees_Troy51a0e822012-09-05 15:24:24 -0400241 SetValue(TW_BACKUPS_FOLDER_VAR, str, 0);
242
243 return 0;
244
245error:
246 // File version mismatch. Use defaults.
247 fclose(in);
248 str = GetCurrentStoragePath();
249 str += "/TWRP/BACKUPS/";
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400250 str += dev_id;
Dees_Troy51a0e822012-09-05 15:24:24 -0400251 SetValue(TW_BACKUPS_FOLDER_VAR, str, 0);
252 return -1;
253}
254
255int DataManager::Flush()
256{
257 return SaveValues();
258}
259
260int DataManager::SaveValues()
261{
262 if (mBackingFile.empty()) return -1;
263
264 string mount_path = GetSettingsStoragePath();
Dees_Troy5bf43922012-09-07 16:07:55 -0400265 PartitionManager.Mount_By_Path(mount_path.c_str(), 1);
Dees_Troy51a0e822012-09-05 15:24:24 -0400266
267 FILE* out = fopen(mBackingFile.c_str(), "wb");
268 if (!out) return -1;
269
270 int file_version = FILE_VERSION;
271 fwrite(&file_version, 1, sizeof(int), out);
272
273 map<string, TStrIntPair>::iterator iter;
274 for (iter = mValues.begin(); iter != mValues.end(); ++iter)
275 {
276 // Save only the persisted data
277 if (iter->second.second != 0)
278 {
279 unsigned short length = (unsigned short) iter->first.length() + 1;
280 fwrite(&length, 1, sizeof(unsigned short), out);
281 fwrite(iter->first.c_str(), 1, length, out);
282 length = (unsigned short) iter->second.first.length() + 1;
283 fwrite(&length, 1, sizeof(unsigned short), out);
284 fwrite(iter->second.first.c_str(), 1, length, out);
285 }
286 }
287 fclose(out);
288 return 0;
289}
290
291int DataManager::GetValue(const string varName, string& value)
292{
293 string localStr = varName;
294
295 if (!mInitialized)
296 SetDefaultValues();
297
298 // Strip off leading and trailing '%' if provided
299 if (localStr.length() > 2 && localStr[0] == '%' && localStr[localStr.length()-1] == '%')
300 {
301 localStr.erase(0, 1);
302 localStr.erase(localStr.length() - 1, 1);
303 }
304
305 // Handle magic values
306 if (GetMagicValue(localStr, value) == 0) return 0;
307
308 map<string, string>::iterator constPos;
309 constPos = mConstValues.find(localStr);
310 if (constPos != mConstValues.end())
311 {
312 value = constPos->second;
313 return 0;
314 }
315
316 map<string, TStrIntPair>::iterator pos;
317 pos = mValues.find(localStr);
318 if (pos == mValues.end())
319 return -1;
320
321 value = pos->second.first;
322 return 0;
323}
324
325int DataManager::GetValue(const string varName, int& value)
326{
327 string data;
328
329 if (GetValue(varName,data) != 0)
330 return -1;
331
332 value = atoi(data.c_str());
333 return 0;
334}
335
336// This is a dangerous function. It will create the value if it doesn't exist so it has a valid c_str
337string& DataManager::GetValueRef(const string varName)
338{
339 if (!mInitialized)
340 SetDefaultValues();
341
342 map<string, string>::iterator constPos;
343 constPos = mConstValues.find(varName);
344 if (constPos != mConstValues.end())
345 return constPos->second;
346
347 map<string, TStrIntPair>::iterator pos;
348 pos = mValues.find(varName);
349 if (pos == mValues.end())
350 pos = (mValues.insert(TNameValuePair(varName, TStrIntPair("", 0)))).first;
351
352 return pos->second.first;
353}
354
355// This function will return an empty string if the value doesn't exist
356string DataManager::GetStrValue(const string varName)
357{
358 string retVal;
359
360 GetValue(varName, retVal);
361 return retVal;
362}
363
364// This function will return 0 if the value doesn't exist
365int DataManager::GetIntValue(const string varName)
366{
367 string retVal;
368
369 GetValue(varName, retVal);
370 return atoi(retVal.c_str());
371}
372
373int DataManager::SetValue(const string varName, string value, int persist /* = 0 */)
374{
375 if (!mInitialized)
376 SetDefaultValues();
377
378 // Don't allow empty values or numerical starting values
379 if (varName.empty() || (varName[0] >= '0' && varName[0] <= '9'))
380 return -1;
381
382 map<string, string>::iterator constChk;
383 constChk = mConstValues.find(varName);
384 if (constChk != mConstValues.end())
385 return -1;
386
387 map<string, TStrIntPair>::iterator pos;
388 pos = mValues.find(varName);
389 if (pos == mValues.end())
390 pos = (mValues.insert(TNameValuePair(varName, TStrIntPair(value, persist)))).first;
391 else
392 pos->second.first = value;
393
394 if (pos->second.second != 0)
395 SaveValues();
396
397 gui_notifyVarChange(varName.c_str(), value.c_str());
398 return 0;
399}
400
401int DataManager::SetValue(const string varName, int value, int persist /* = 0 */)
402{
403 ostringstream valStr;
404 valStr << value;
405 if (varName == "tw_use_external_storage") {
406 string str;
407
408 if (GetIntValue(TW_HAS_DUAL_STORAGE) == 1) {
409 if (value == 0) {
410 str = GetStrValue(TW_INTERNAL_PATH);
Dees_Troy51a0e822012-09-05 15:24:24 -0400411 } else {
412 str = GetStrValue(TW_EXTERNAL_PATH);
Dees_Troy51a0e822012-09-05 15:24:24 -0400413 }
414 } else if (GetIntValue(TW_HAS_INTERNAL) == 1)
415 str = GetStrValue(TW_INTERNAL_PATH);
416 else
417 str = GetStrValue(TW_EXTERNAL_PATH);
418
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400419 string dev_id;
420
421 GetValue("device_id", dev_id);
Dees_Troy51a0e822012-09-05 15:24:24 -0400422 str += "/TWRP/BACKUPS/";
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400423 str += dev_id;
Dees_Troy51a0e822012-09-05 15:24:24 -0400424
425 SetValue(TW_BACKUPS_FOLDER_VAR, str);
426 }
427 return SetValue(varName, valStr.str(), persist);;
428}
429
430int DataManager::SetValue(const string varName, float value, int persist /* = 0 */)
431{
432 ostringstream valStr;
433 valStr << value;
434 return SetValue(varName, valStr.str(), persist);;
435}
436
437void DataManager::DumpValues()
438{
439 map<string, TStrIntPair>::iterator iter;
440 ui_print("Data Manager dump - Values with leading X are persisted.\n");
441 for (iter = mValues.begin(); iter != mValues.end(); ++iter)
442 {
443 ui_print("%c %s=%s\n", iter->second.second ? 'X' : ' ', iter->first.c_str(), iter->second.first.c_str());
444 }
445}
446
Dees_Troy8170a922012-09-18 15:40:25 -0400447void DataManager::update_tz_environment_variables(void) {
448 setenv("TZ", DataManager_GetStrValue(TW_TIME_ZONE_VAR), 1);
449 tzset();
450}
451
Dees_Troy51a0e822012-09-05 15:24:24 -0400452void DataManager::SetDefaultValues()
453{
454 string str, path;
455
456 get_device_id();
457
458 mInitialized = 1;
459
460 mConstValues.insert(make_pair("true", "1"));
461 mConstValues.insert(make_pair("false", "0"));
462
463 mConstValues.insert(make_pair(TW_VERSION_VAR, TW_VERSION_STR));
464
465#ifdef BOARD_HAS_NO_REAL_SDCARD
466 mConstValues.insert(make_pair(TW_ALLOW_PARTITION_SDCARD, "0"));
467#else
468 mConstValues.insert(make_pair(TW_ALLOW_PARTITION_SDCARD, "1"));
469#endif
470
471#ifdef TW_INCLUDE_DUMLOCK
472 mConstValues.insert(make_pair(TW_SHOW_DUMLOCK, "1"));
473#else
474 mConstValues.insert(make_pair(TW_SHOW_DUMLOCK, "0"));
475#endif
476
477#ifdef TW_INTERNAL_STORAGE_PATH
478 LOGI("Internal path defined: '%s'\n", EXPAND(TW_INTERNAL_STORAGE_PATH));
479 mValues.insert(make_pair(TW_USE_EXTERNAL_STORAGE, make_pair("0", 1)));
480 mConstValues.insert(make_pair(TW_HAS_INTERNAL, "1"));
481 mConstValues.insert(make_pair(TW_INTERNAL_PATH, EXPAND(TW_INTERNAL_STORAGE_PATH)));
482 mConstValues.insert(make_pair(TW_INTERNAL_LABEL, EXPAND(TW_INTERNAL_STORAGE_MOUNT_POINT)));
483 path.clear();
484 path = "/";
485 path += EXPAND(TW_INTERNAL_STORAGE_MOUNT_POINT);
486 mConstValues.insert(make_pair(TW_INTERNAL_MOUNT, path));
487 #ifdef TW_EXTERNAL_STORAGE_PATH
488 LOGI("External path defined: '%s'\n", EXPAND(TW_EXTERNAL_STORAGE_PATH));
489 // Device has dual storage
490 mConstValues.insert(make_pair(TW_HAS_DUAL_STORAGE, "1"));
491 mConstValues.insert(make_pair(TW_HAS_EXTERNAL, "1"));
492 mConstValues.insert(make_pair(TW_EXTERNAL_PATH, EXPAND(TW_EXTERNAL_STORAGE_PATH)));
493 mConstValues.insert(make_pair(TW_EXTERNAL_LABEL, EXPAND(TW_EXTERNAL_STORAGE_MOUNT_POINT)));
494 mValues.insert(make_pair(TW_ZIP_EXTERNAL_VAR, make_pair(EXPAND(TW_EXTERNAL_STORAGE_PATH), 1)));
495 path.clear();
496 path = "/";
497 path += EXPAND(TW_EXTERNAL_STORAGE_MOUNT_POINT);
498 mConstValues.insert(make_pair(TW_EXTERNAL_MOUNT, path));
499 if (strcmp(EXPAND(TW_EXTERNAL_STORAGE_PATH), "/sdcard") == 0) {
500 mValues.insert(make_pair(TW_ZIP_INTERNAL_VAR, make_pair("/emmc", 1)));
501 } else {
502 mValues.insert(make_pair(TW_ZIP_INTERNAL_VAR, make_pair("/sdcard", 1)));
503 }
504 #else
505 LOGI("Just has internal storage.\n");
506 // Just has internal storage
507 mValues.insert(make_pair(TW_ZIP_INTERNAL_VAR, make_pair("/sdcard", 1)));
508 mConstValues.insert(make_pair(TW_HAS_DUAL_STORAGE, "0"));
509 mConstValues.insert(make_pair(TW_HAS_EXTERNAL, "0"));
510 mConstValues.insert(make_pair(TW_EXTERNAL_PATH, "0"));
511 mConstValues.insert(make_pair(TW_EXTERNAL_MOUNT, "0"));
512 mConstValues.insert(make_pair(TW_EXTERNAL_LABEL, "0"));
513 #endif
514#else
515 #ifdef RECOVERY_SDCARD_ON_DATA
516 #ifdef TW_EXTERNAL_STORAGE_PATH
517 LOGI("Has /data/media + external storage in '%s'\n", EXPAND(TW_EXTERNAL_STORAGE_PATH));
518 // Device has /data/media + external storage
519 mConstValues.insert(make_pair(TW_HAS_DUAL_STORAGE, "1"));
520 #else
521 LOGI("Single storage only -- data/media.\n");
522 // Device just has external storage
523 mConstValues.insert(make_pair(TW_HAS_DUAL_STORAGE, "0"));
524 mConstValues.insert(make_pair(TW_HAS_EXTERNAL, "0"));
525 #endif
526 #else
527 LOGI("Single storage only.\n");
528 // Device just has external storage
529 mConstValues.insert(make_pair(TW_HAS_DUAL_STORAGE, "0"));
530 #endif
531 #ifdef RECOVERY_SDCARD_ON_DATA
532 LOGI("Device has /data/media defined.\n");
533 // Device has /data/media
534 mConstValues.insert(make_pair(TW_USE_EXTERNAL_STORAGE, "0"));
535 mConstValues.insert(make_pair(TW_HAS_INTERNAL, "1"));
536 mConstValues.insert(make_pair(TW_INTERNAL_PATH, "/data/media"));
537 mConstValues.insert(make_pair(TW_INTERNAL_MOUNT, "/data"));
538 mConstValues.insert(make_pair(TW_INTERNAL_LABEL, "data"));
539 #ifdef TW_EXTERNAL_STORAGE_PATH
540 if (strcmp(EXPAND(TW_EXTERNAL_STORAGE_PATH), "/sdcard") == 0) {
541 mValues.insert(make_pair(TW_ZIP_INTERNAL_VAR, make_pair("/emmc", 1)));
542 } else {
543 mValues.insert(make_pair(TW_ZIP_INTERNAL_VAR, make_pair("/sdcard", 1)));
544 }
545 #else
546 mValues.insert(make_pair(TW_ZIP_INTERNAL_VAR, make_pair("/sdcard", 1)));
547 #endif
548 #else
549 LOGI("No internal storage defined.\n");
550 // Device has no internal storage
551 mConstValues.insert(make_pair(TW_USE_EXTERNAL_STORAGE, "1"));
552 mConstValues.insert(make_pair(TW_HAS_INTERNAL, "0"));
553 mConstValues.insert(make_pair(TW_INTERNAL_PATH, "0"));
554 mConstValues.insert(make_pair(TW_INTERNAL_MOUNT, "0"));
555 mConstValues.insert(make_pair(TW_INTERNAL_LABEL, "0"));
556 #endif
557 #ifdef TW_EXTERNAL_STORAGE_PATH
558 LOGI("Only external path defined: '%s'\n", EXPAND(TW_EXTERNAL_STORAGE_PATH));
559 // External has custom definition
560 mConstValues.insert(make_pair(TW_HAS_EXTERNAL, "1"));
561 mConstValues.insert(make_pair(TW_EXTERNAL_PATH, EXPAND(TW_EXTERNAL_STORAGE_PATH)));
562 mConstValues.insert(make_pair(TW_EXTERNAL_LABEL, EXPAND(TW_EXTERNAL_STORAGE_MOUNT_POINT)));
563 mValues.insert(make_pair(TW_ZIP_EXTERNAL_VAR, make_pair(EXPAND(TW_EXTERNAL_STORAGE_PATH), 1)));
564 path.clear();
565 path = "/";
566 path += EXPAND(TW_EXTERNAL_STORAGE_MOUNT_POINT);
567 mConstValues.insert(make_pair(TW_EXTERNAL_MOUNT, path));
568 #else
569 #ifndef RECOVERY_SDCARD_ON_DATA
570 LOGI("No storage defined, defaulting to /sdcard.\n");
571 // Standard external definition
572 mConstValues.insert(make_pair(TW_HAS_EXTERNAL, "1"));
573 mConstValues.insert(make_pair(TW_EXTERNAL_PATH, "/sdcard"));
574 mConstValues.insert(make_pair(TW_EXTERNAL_MOUNT, "/sdcard"));
575 mConstValues.insert(make_pair(TW_EXTERNAL_LABEL, "sdcard"));
576 mValues.insert(make_pair(TW_ZIP_EXTERNAL_VAR, make_pair("/sdcard", 1)));
577 #endif
578 #endif
579#endif
580
581#ifdef TW_DEFAULT_EXTERNAL_STORAGE
582 SetValue(TW_USE_EXTERNAL_STORAGE, 1);
583 LOGI("Defaulting to external storage.\n");
584#endif
585
586 str = GetCurrentStoragePath();
587#ifdef RECOVERY_SDCARD_ON_DATA
588 #ifndef TW_EXTERNAL_STORAGE_PATH
589 SetValue(TW_ZIP_LOCATION_VAR, "/sdcard", 1);
590 #else
591 if (strcmp(EXPAND(TW_EXTERNAL_STORAGE_PATH), "/sdcard") == 0) {
592 SetValue(TW_ZIP_LOCATION_VAR, "/emmc", 1);
593 } else {
594 SetValue(TW_ZIP_LOCATION_VAR, "/sdcard", 1);
595 }
596 #endif
597#else
598 SetValue(TW_ZIP_LOCATION_VAR, str.c_str(), 1);
599#endif
600 str += "/TWRP/BACKUPS/";
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400601
602 string dev_id;
603 GetValue("device_id", dev_id);
604
605 str += dev_id;
Dees_Troy51a0e822012-09-05 15:24:24 -0400606 SetValue(TW_BACKUPS_FOLDER_VAR, str, 0);
607
Dees_Troy8170a922012-09-18 15:40:25 -0400608#ifdef SP1_DISPLAY_NAME
Dees_Troy51a0e822012-09-05 15:24:24 -0400609 if (strlen(EXPAND(SP1_DISPLAY_NAME))) mConstValues.insert(make_pair(TW_SP1_PARTITION_NAME_VAR, EXPAND(SP1_DISPLAY_NAME)));
Dees_Troyb46a6842012-09-25 11:06:46 -0400610#else
611 #ifdef SP1_NAME
612 if (strlen(EXPAND(SP1_NAME))) mConstValues.insert(make_pair(TW_SP1_PARTITION_NAME_VAR, EXPAND(SP1_NAME)));
613 #endif
Dees_Troy8170a922012-09-18 15:40:25 -0400614#endif
615#ifdef SP2_DISPLAY_NAME
Dees_Troy51a0e822012-09-05 15:24:24 -0400616 if (strlen(EXPAND(SP2_DISPLAY_NAME))) mConstValues.insert(make_pair(TW_SP2_PARTITION_NAME_VAR, EXPAND(SP2_DISPLAY_NAME)));
Dees_Troyb46a6842012-09-25 11:06:46 -0400617#else
618 #ifdef SP2_NAME
619 if (strlen(EXPAND(SP2_NAME))) mConstValues.insert(make_pair(TW_SP1_PARTITION_NAME_VAR, EXPAND(SP2_NAME)));
620 #endif
Dees_Troy8170a922012-09-18 15:40:25 -0400621#endif
622#ifdef SP3_DISPLAY_NAME
Dees_Troy51a0e822012-09-05 15:24:24 -0400623 if (strlen(EXPAND(SP3_DISPLAY_NAME))) mConstValues.insert(make_pair(TW_SP3_PARTITION_NAME_VAR, EXPAND(SP3_DISPLAY_NAME)));
Dees_Troyb46a6842012-09-25 11:06:46 -0400624#else
625 #ifdef SP3_NAME
626 if (strlen(EXPAND(SP3_NAME))) mConstValues.insert(make_pair(TW_SP1_PARTITION_NAME_VAR, EXPAND(SP3_NAME)));
627 #endif
Dees_Troy8170a922012-09-18 15:40:25 -0400628#endif
Dees_Troy51a0e822012-09-05 15:24:24 -0400629
630 mConstValues.insert(make_pair(TW_REBOOT_SYSTEM, tw_isRebootCommandSupported(rb_system) ? "1" : "0"));
631#ifdef TW_NO_REBOOT_RECOVERY
632 mConstValues.insert(make_pair(TW_REBOOT_RECOVERY, "0"));
633#else
634 mConstValues.insert(make_pair(TW_REBOOT_RECOVERY, tw_isRebootCommandSupported(rb_recovery) ? "1" : "0"));
635#endif
636 mConstValues.insert(make_pair(TW_REBOOT_POWEROFF, tw_isRebootCommandSupported(rb_poweroff) ? "1" : "0"));
637#ifdef TW_NO_REBOOT_BOOTLOADER
638 mConstValues.insert(make_pair(TW_REBOOT_BOOTLOADER, "0"));
639#else
640 mConstValues.insert(make_pair(TW_REBOOT_BOOTLOADER, tw_isRebootCommandSupported(rb_bootloader) ? "1" : "0"));
641#endif
642#ifdef RECOVERY_SDCARD_ON_DATA
643 mConstValues.insert(make_pair(TW_HAS_DATA_MEDIA, "1"));
644#else
645 mConstValues.insert(make_pair(TW_HAS_DATA_MEDIA, "0"));
646#endif
647#ifdef TW_NO_BATT_PERCENT
648 mConstValues.insert(make_pair(TW_NO_BATTERY_PERCENT, "1"));
649#else
650 mConstValues.insert(make_pair(TW_NO_BATTERY_PERCENT, "0"));
651#endif
652#ifdef TW_CUSTOM_POWER_BUTTON
653 mConstValues.insert(make_pair(TW_POWER_BUTTON, EXPAND(TW_CUSTOM_POWER_BUTTON)));
654#else
655 mConstValues.insert(make_pair(TW_POWER_BUTTON, "0"));
656#endif
657#ifdef TW_ALWAYS_RMRF
658 mConstValues.insert(make_pair(TW_RM_RF_VAR, "1"));
659#endif
660#ifdef TW_NEVER_UNMOUNT_SYSTEM
661 mConstValues.insert(make_pair(TW_DONT_UNMOUNT_SYSTEM, "1"));
662#else
663 mConstValues.insert(make_pair(TW_DONT_UNMOUNT_SYSTEM, "0"));
664#endif
665#ifdef TW_NO_USB_STORAGE
666 mConstValues.insert(make_pair(TW_HAS_USB_STORAGE, "0"));
667#else
668 mConstValues.insert(make_pair(TW_HAS_USB_STORAGE, "1"));
669#endif
670#ifdef TW_INCLUDE_INJECTTWRP
671 mConstValues.insert(make_pair(TW_HAS_INJECTTWRP, "1"));
672 mValues.insert(make_pair(TW_INJECT_AFTER_ZIP, make_pair("1", 1)));
673#else
674 mConstValues.insert(make_pair(TW_HAS_INJECTTWRP, "0"));
675 mValues.insert(make_pair(TW_INJECT_AFTER_ZIP, make_pair("0", 1)));
676#endif
677#ifdef TW_FLASH_FROM_STORAGE
678 mConstValues.insert(make_pair(TW_FLASH_ZIP_IN_PLACE, "1"));
679#endif
680#ifdef TW_HAS_DOWNLOAD_MODE
681 mConstValues.insert(make_pair(TW_DOWNLOAD_MODE, "1"));
682#endif
683#ifdef TW_INCLUDE_CRYPTO
684 mConstValues.insert(make_pair(TW_HAS_CRYPTO, "1"));
685 LOGI("Device has crypto support compiled into recovery.\n");
686#endif
687#ifdef TW_SDEXT_NO_EXT4
688 mConstValues.insert(make_pair(TW_SDEXT_DISABLE_EXT4, "1"));
689#else
690 mConstValues.insert(make_pair(TW_SDEXT_DISABLE_EXT4, "0"));
691#endif
692
693 mConstValues.insert(make_pair(TW_MIN_SYSTEM_VAR, TW_MIN_SYSTEM_SIZE));
694 mValues.insert(make_pair(TW_BACKUP_NAME, make_pair("(Current Date)", 0)));
695 mValues.insert(make_pair(TW_BACKUP_SYSTEM_VAR, make_pair("1", 1)));
696 mValues.insert(make_pair(TW_BACKUP_DATA_VAR, make_pair("1", 1)));
697 mValues.insert(make_pair(TW_BACKUP_BOOT_VAR, make_pair("1", 1)));
698 mValues.insert(make_pair(TW_BACKUP_RECOVERY_VAR, make_pair("0", 1)));
699 mValues.insert(make_pair(TW_BACKUP_CACHE_VAR, make_pair("0", 1)));
700 mValues.insert(make_pair(TW_BACKUP_SP1_VAR, make_pair("0", 1)));
701 mValues.insert(make_pair(TW_BACKUP_SP2_VAR, make_pair("0", 1)));
702 mValues.insert(make_pair(TW_BACKUP_SP3_VAR, make_pair("0", 1)));
703 mValues.insert(make_pair(TW_BACKUP_ANDSEC_VAR, make_pair("0", 1)));
704 mValues.insert(make_pair(TW_BACKUP_SDEXT_VAR, make_pair("0", 1)));
705 mValues.insert(make_pair(TW_BACKUP_SYSTEM_SIZE, make_pair("0", 0)));
706 mValues.insert(make_pair(TW_BACKUP_DATA_SIZE, make_pair("0", 0)));
707 mValues.insert(make_pair(TW_BACKUP_BOOT_SIZE, make_pair("0", 0)));
708 mValues.insert(make_pair(TW_BACKUP_RECOVERY_SIZE, make_pair("0", 0)));
709 mValues.insert(make_pair(TW_BACKUP_CACHE_SIZE, make_pair("0", 0)));
710 mValues.insert(make_pair(TW_BACKUP_ANDSEC_SIZE, make_pair("0", 0)));
711 mValues.insert(make_pair(TW_BACKUP_SDEXT_SIZE, make_pair("0", 0)));
712 mValues.insert(make_pair(TW_BACKUP_SP1_SIZE, make_pair("0", 0)));
713 mValues.insert(make_pair(TW_BACKUP_SP2_SIZE, make_pair("0", 0)));
714 mValues.insert(make_pair(TW_BACKUP_SP3_SIZE, make_pair("0", 0)));
715 mValues.insert(make_pair(TW_STORAGE_FREE_SIZE, make_pair("0", 0)));
716
717 mValues.insert(make_pair(TW_REBOOT_AFTER_FLASH_VAR, make_pair("0", 1)));
718 mValues.insert(make_pair(TW_SIGNED_ZIP_VERIFY_VAR, make_pair("0", 1)));
719 mValues.insert(make_pair(TW_FORCE_MD5_CHECK_VAR, make_pair("0", 1)));
720 mValues.insert(make_pair(TW_COLOR_THEME_VAR, make_pair("0", 1)));
721 mValues.insert(make_pair(TW_USE_COMPRESSION_VAR, make_pair("0", 1)));
722 mValues.insert(make_pair(TW_IGNORE_IMAGE_SIZE, make_pair("0", 1)));
723 mValues.insert(make_pair(TW_SHOW_SPAM_VAR, make_pair("0", 1)));
724 mValues.insert(make_pair(TW_TIME_ZONE_VAR, make_pair("CST6CDT", 1)));
725 mValues.insert(make_pair(TW_SORT_FILES_BY_DATE_VAR, make_pair("0", 1)));
726 mValues.insert(make_pair(TW_GUI_SORT_ORDER, make_pair("1", 1)));
727 mValues.insert(make_pair(TW_RM_RF_VAR, make_pair("0", 1)));
728 mValues.insert(make_pair(TW_SKIP_MD5_CHECK_VAR, make_pair("0", 1)));
729 mValues.insert(make_pair(TW_SKIP_MD5_GENERATE_VAR, make_pair("0", 1)));
730 mValues.insert(make_pair(TW_SDEXT_SIZE, make_pair("512", 1)));
731 mValues.insert(make_pair(TW_SWAP_SIZE, make_pair("32", 1)));
732 mValues.insert(make_pair(TW_SDPART_FILE_SYSTEM, make_pair("ext3", 1)));
733 mValues.insert(make_pair(TW_TIME_ZONE_GUISEL, make_pair("CST6;CDT", 1)));
734 mValues.insert(make_pair(TW_TIME_ZONE_GUIOFFSET, make_pair("0", 1)));
735 mValues.insert(make_pair(TW_TIME_ZONE_GUIDST, make_pair("1", 1)));
736 mValues.insert(make_pair(TW_ACTION_BUSY, make_pair("0", 0)));
737 mValues.insert(make_pair(TW_BACKUP_AVG_IMG_RATE, make_pair("15000000", 1)));
738 mValues.insert(make_pair(TW_BACKUP_AVG_FILE_RATE, make_pair("3000000", 1)));
739 mValues.insert(make_pair(TW_BACKUP_AVG_FILE_COMP_RATE, make_pair("2000000", 1)));
740 mValues.insert(make_pair(TW_RESTORE_AVG_IMG_RATE, make_pair("15000000", 1)));
741 mValues.insert(make_pair(TW_RESTORE_AVG_FILE_RATE, make_pair("3000000", 1)));
742 mValues.insert(make_pair(TW_RESTORE_AVG_FILE_COMP_RATE, make_pair("2000000", 1)));
743 if (GetIntValue(TW_HAS_INTERNAL) == 1 && GetIntValue(TW_HAS_DATA_MEDIA) == 1 && GetIntValue(TW_HAS_EXTERNAL) == 0)
744 SetValue(TW_HAS_USB_STORAGE, 0, 0);
745 else
746 SetValue(TW_HAS_USB_STORAGE, 1, 0);
747 mValues.insert(make_pair(TW_ZIP_INDEX, make_pair("0", 0)));
748 mValues.insert(make_pair(TW_ZIP_QUEUE_COUNT, make_pair("0", 0)));
749 mValues.insert(make_pair(TW_FILENAME, make_pair("/sdcard", 0)));
750 mValues.insert(make_pair(TW_SIMULATE_ACTIONS, make_pair("0", 1)));
751 mValues.insert(make_pair(TW_SIMULATE_FAIL, make_pair("0", 1)));
752 mValues.insert(make_pair(TW_IS_ENCRYPTED, make_pair("0", 0)));
753 mValues.insert(make_pair(TW_IS_DECRYPTED, make_pair("0", 0)));
754 mValues.insert(make_pair(TW_CRYPTO_PASSWORD, make_pair("0", 0)));
755 mValues.insert(make_pair(TW_DATA_BLK_DEVICE, make_pair("0", 0)));
756 mValues.insert(make_pair("tw_terminal_state", make_pair("0", 0)));
757 mValues.insert(make_pair("tw_background_thread_running", make_pair("0", 0)));
758 mValues.insert(make_pair(TW_RESTORE_FILE_DATE, make_pair("0", 0)));
759}
760
761// Magic Values
762int DataManager::GetMagicValue(const string varName, string& value)
763{
764 // Handle special dynamic cases
765 if (varName == "tw_time")
766 {
767 char tmp[32];
768
769 struct tm *current;
770 time_t now;
771 now = time(0);
772 current = localtime(&now);
773
774 if (current->tm_hour >= 12)
775 sprintf(tmp, "%d:%02d PM", current->tm_hour == 12 ? 12 : current->tm_hour - 12, current->tm_min);
776 else
777 sprintf(tmp, "%d:%02d AM", current->tm_hour == 0 ? 12 : current->tm_hour, current->tm_min);
778
779 value = tmp;
780 return 0;
781 }
782 if (varName == "tw_battery")
783 {
784 char tmp[16];
Dees_Troy38bd7602012-09-14 13:33:53 -0400785 static char charging = ' ';
786 static int lastVal = -1;
787 static time_t nextSecCheck = 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400788
Dees_Troy38bd7602012-09-14 13:33:53 -0400789 struct timeval curTime;
790 gettimeofday(&curTime, NULL);
791 if (curTime.tv_sec > nextSecCheck)
792 {
793 char cap_s[4];
794 FILE * cap = fopen("/sys/class/power_supply/battery/capacity","rt");
795 if (cap){
796 fgets(cap_s, 4, cap);
797 fclose(cap);
798 lastVal = atoi(cap_s);
799 if (lastVal > 100) lastVal = 101;
800 if (lastVal < 0) lastVal = 0;
801 }
802 cap = fopen("/sys/class/power_supply/battery/status","rt");
803 if (cap) {
804 fgets(cap_s, 2, cap);
805 fclose(cap);
806 if (cap_s[0] == 'C')
807 charging = '+';
808 else
809 charging = ' ';
810 }
811 nextSecCheck = curTime.tv_sec + 60;
812 }
813
814 sprintf(tmp, "%i%%%c", lastVal, charging);
Dees_Troy51a0e822012-09-05 15:24:24 -0400815 value = tmp;
816 return 0;
817 }
818 return -1;
819}
820
821void DataManager::ReadSettingsFile(void)
822{
823 // Load up the values for TWRP - Sleep to let the card be ready
824 char mkdir_path[255], settings_file[255];
825 int is_enc, has_dual, use_ext, has_data_media, has_ext;
826
827 GetValue(TW_IS_ENCRYPTED, is_enc);
828 GetValue(TW_HAS_DATA_MEDIA, has_data_media);
829 if (is_enc == 1 && has_data_media == 1) {
830 LOGI("Cannot load settings -- encrypted.\n");
831 return;
832 }
833
834 memset(mkdir_path, 0, sizeof(mkdir_path));
835 memset(settings_file, 0, sizeof(settings_file));
836 sprintf(mkdir_path, "%s/TWRP", DataManager_GetSettingsStoragePath());
837 sprintf(settings_file, "%s/.twrps", mkdir_path);
838
Dees_Troy5bf43922012-09-07 16:07:55 -0400839 if (!PartitionManager.Mount_Settings_Storage(false))
Dees_Troy51a0e822012-09-05 15:24:24 -0400840 {
841 usleep(500000);
Dees_Troy5bf43922012-09-07 16:07:55 -0400842 if (!PartitionManager.Mount_Settings_Storage(false))
Dees_Troy51a0e822012-09-05 15:24:24 -0400843 LOGE("Unable to mount %s when trying to read settings file.\n", DataManager_GetSettingsStorageMount());
844 }
845
846 mkdir(mkdir_path, 0777);
847
848 LOGI("Attempt to load settings from settings file...\n");
849 LoadValues(settings_file);
850 GetValue(TW_HAS_DUAL_STORAGE, has_dual);
851 GetValue(TW_USE_EXTERNAL_STORAGE, use_ext);
852 GetValue(TW_HAS_EXTERNAL, has_ext);
853 if (has_dual != 0 && use_ext == 1) {
854 // Attempt to sdcard using external storage
Dees_Troye2920fa2012-09-19 16:18:00 -0400855 if (!PartitionManager.Mount_Current_Storage(false)) {
Dees_Troy51a0e822012-09-05 15:24:24 -0400856 LOGE("Failed to mount external storage, using internal storage.\n");
857 // Remount failed, default back to internal storage
858 SetValue(TW_USE_EXTERNAL_STORAGE, 0);
Dees_Troy5bf43922012-09-07 16:07:55 -0400859 PartitionManager.Mount_Current_Storage(true);
Dees_Troye2920fa2012-09-19 16:18:00 -0400860 string int_zip_path;
861 GetValue(TW_ZIP_INTERNAL_VAR, int_zip_path);
862 SetValue(TW_USE_EXTERNAL_STORAGE, 0);
863 SetValue(TW_ZIP_LOCATION_VAR, int_zip_path);
Dees_Troy51a0e822012-09-05 15:24:24 -0400864 }
865 } else {
Dees_Troy5bf43922012-09-07 16:07:55 -0400866 PartitionManager.Mount_Current_Storage(true);
Dees_Troy51a0e822012-09-05 15:24:24 -0400867 }
868 if (has_data_media == 1) {
869 if (has_dual == 0) {
870 LOGI("Mounting /data/media to /sdcard\n");
871 system("umount /sdcard");
872 system("mount /data/media /sdcard");
873 } else {
874 string ext_path;
875
876 GetValue(TW_EXTERNAL_PATH, ext_path);
877 if (ext_path == "/sdcard") {
878 LOGI("Mounting /data/media to /emmc\n");
879 system("cd / && mkdir emmc");
880 system("umount /emmc");
881 system("mount /data/media /emmc");
882 } else {
883 LOGI("Mounting /data/media to /sdcard\n");
884 system("umount /sdcard");
885 system("mount /data/media /sdcard");
886 }
887 }
888 }
889
Dees_Troy51a0e822012-09-05 15:24:24 -0400890 if (has_ext) {
891 string ext_path;
892
893 GetValue(TW_EXTERNAL_PATH, ext_path);
Dees_Troy5bf43922012-09-07 16:07:55 -0400894 PartitionManager.Mount_By_Path(ext_path, 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400895 }
Dees_Troy8170a922012-09-18 15:40:25 -0400896 update_tz_environment_variables();
Dees_Troy51a0e822012-09-05 15:24:24 -0400897}
898
899string DataManager::GetCurrentStoragePath(void)
900{
901 if (GetIntValue(TW_HAS_DUAL_STORAGE) == 1) {
902 if (GetIntValue(TW_USE_EXTERNAL_STORAGE) == 0)
903 return GetStrValue(TW_INTERNAL_PATH);
904 else
905 return GetStrValue(TW_EXTERNAL_PATH);
906 } else if (GetIntValue(TW_HAS_INTERNAL) == 1)
907 return GetStrValue(TW_INTERNAL_PATH);
908 else
909 return GetStrValue(TW_EXTERNAL_PATH);
910}
911
912string& DataManager::CGetCurrentStoragePath()
913{
914 if (GetIntValue(TW_HAS_DUAL_STORAGE) == 1) {
915 if (GetIntValue(TW_USE_EXTERNAL_STORAGE) == 0)
916 return GetValueRef(TW_INTERNAL_PATH);
917 else
918 return GetValueRef(TW_EXTERNAL_PATH);
919 } else if (GetIntValue(TW_HAS_INTERNAL) == 1)
920 return GetValueRef(TW_INTERNAL_PATH);
921 else
922 return GetValueRef(TW_EXTERNAL_PATH);
923}
924
925string DataManager::GetCurrentStorageMount(void)
926{
927 if (GetIntValue(TW_HAS_DUAL_STORAGE) == 1) {
928 if (GetIntValue(TW_USE_EXTERNAL_STORAGE) == 0)
929 return GetStrValue(TW_INTERNAL_MOUNT);
930 else
931 return GetStrValue(TW_EXTERNAL_MOUNT);
932 } else if (GetIntValue(TW_HAS_INTERNAL) == 1)
933 return GetStrValue(TW_INTERNAL_MOUNT);
934 else
935 return GetStrValue(TW_EXTERNAL_MOUNT);
936}
937
938string& DataManager::CGetCurrentStorageMount()
939{
940 if (GetIntValue(TW_HAS_DUAL_STORAGE) == 1) {
941 if (GetIntValue(TW_USE_EXTERNAL_STORAGE) == 0)
942 return GetValueRef(TW_INTERNAL_MOUNT);
943 else
944 return GetValueRef(TW_EXTERNAL_MOUNT);
945 } else if (GetIntValue(TW_HAS_INTERNAL) == 1)
946 return GetValueRef(TW_INTERNAL_MOUNT);
947 else
948 return GetValueRef(TW_EXTERNAL_MOUNT);
949}
950
951string DataManager::GetSettingsStoragePath(void)
952{
953 if (GetIntValue(TW_HAS_INTERNAL) == 1)
954 return GetStrValue(TW_INTERNAL_PATH);
955 else
956 return GetStrValue(TW_EXTERNAL_PATH);
957}
958
959string& DataManager::CGetSettingsStoragePath()
960{
961 if (GetIntValue(TW_HAS_INTERNAL) == 1)
962 return GetValueRef(TW_INTERNAL_PATH);
963 else
964 return GetValueRef(TW_EXTERNAL_PATH);
965}
966
967string DataManager::GetSettingsStorageMount(void)
968{
969 if (GetIntValue(TW_HAS_INTERNAL) == 1)
970 return GetStrValue(TW_INTERNAL_MOUNT);
971 else
972 return GetStrValue(TW_EXTERNAL_MOUNT);
973}
974
975string& DataManager::CGetSettingsStorageMount()
976{
977 if (GetIntValue(TW_HAS_INTERNAL) == 1)
978 return GetValueRef(TW_INTERNAL_MOUNT);
979 else
980 return GetValueRef(TW_EXTERNAL_MOUNT);
981}
982
983extern "C" int DataManager_ResetDefaults()
984{
985 return DataManager::ResetDefaults();
986}
987
988extern "C" void DataManager_LoadDefaults()
989{
990 return DataManager::SetDefaultValues();
991}
992
993extern "C" int DataManager_LoadValues(const char* filename)
994{
995 return DataManager::LoadValues(filename);
996}
997
998extern "C" int DataManager_Flush()
999{
1000 return DataManager::Flush();
1001}
1002
1003extern "C" int DataManager_GetValue(const char* varName, char* value)
1004{
1005 int ret;
1006 string str;
1007
1008 ret = DataManager::GetValue(varName, str);
1009 if (ret == 0)
1010 strcpy(value, str.c_str());
1011 return ret;
1012}
1013
1014extern "C" const char* DataManager_GetStrValue(const char* varName)
1015{
1016 string& str = DataManager::GetValueRef(varName);
1017 return str.c_str();
1018}
1019
1020extern "C" const char* DataManager_GetCurrentStoragePath(void)
1021{
1022 string& str = DataManager::CGetCurrentStoragePath();
1023 return str.c_str();
1024}
1025
1026extern "C" const char* DataManager_GetSettingsStoragePath(void)
1027{
1028 string& str = DataManager::CGetSettingsStoragePath();
1029 return str.c_str();
1030}
1031
1032extern "C" const char* DataManager_GetCurrentStorageMount(void)
1033{
1034 string& str = DataManager::CGetCurrentStorageMount();
1035 return str.c_str();
1036}
1037
1038extern "C" const char* DataManager_GetSettingsStorageMount(void)
1039{
1040 string& str = DataManager::CGetSettingsStorageMount();
1041 return str.c_str();
1042}
1043
1044extern "C" int DataManager_GetIntValue(const char* varName)
1045{
1046 return DataManager::GetIntValue(varName);
1047}
1048
1049extern "C" int DataManager_SetStrValue(const char* varName, char* value)
1050{
1051 return DataManager::SetValue(varName, value, 0);
1052}
1053
1054extern "C" int DataManager_SetIntValue(const char* varName, int value)
1055{
1056 return DataManager::SetValue(varName, value, 0);
1057}
1058
1059extern "C" int DataManager_SetFloatValue(const char* varName, float value)
1060{
1061 return DataManager::SetValue(varName, value, 0);
1062}
1063
1064extern "C" int DataManager_ToggleIntValue(const char* varName)
1065{
1066 if (DataManager::GetIntValue(varName))
1067 return DataManager::SetValue(varName, 0);
1068 else
1069 return DataManager::SetValue(varName, 1);
1070}
1071
1072extern "C" void DataManager_DumpValues()
1073{
1074 return DataManager::DumpValues();
1075}
1076
1077extern "C" void DataManager_ReadSettingsFile()
1078{
1079 return DataManager::ReadSettingsFile();
1080}