Unify indentation and little clean-up in TWRP files
Signed-off-by: Vojtech Bocek <vbocek@gmail.com>
This commit is contained in:
committed by
Gerrit Code Review
parent
8b44bbda25
commit
fafb0c541b
@@ -43,26 +43,26 @@
|
||||
#include "gui/blanktimer.hpp"
|
||||
|
||||
#ifdef TW_USE_MODEL_HARDWARE_ID_FOR_DEVICE_ID
|
||||
#include "cutils/properties.h"
|
||||
#include "cutils/properties.h"
|
||||
#endif
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "twcommon.h"
|
||||
#include "data.h"
|
||||
#include "twcommon.h"
|
||||
#include "data.h"
|
||||
#include "gui/pages.h"
|
||||
|
||||
void gui_notifyVarChange(const char *name, const char* value);
|
||||
}
|
||||
|
||||
#define FILE_VERSION 0x00010001
|
||||
#define FILE_VERSION 0x00010001
|
||||
|
||||
using namespace std;
|
||||
|
||||
map<string, DataManager::TStrIntPair> DataManager::mValues;
|
||||
map<string, string> DataManager::mConstValues;
|
||||
string DataManager::mBackingFile;
|
||||
int DataManager::mInitialized = 0;
|
||||
map<string, DataManager::TStrIntPair> DataManager::mValues;
|
||||
map<string, string> DataManager::mConstValues;
|
||||
string DataManager::mBackingFile;
|
||||
int DataManager::mInitialized = 0;
|
||||
extern blanktimer blankTimer;
|
||||
|
||||
// Device ID functions
|
||||
@@ -81,12 +81,12 @@ void DataManager::sanitize_device_id(char* device_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
#define CMDLINE_SERIALNO "androidboot.serialno="
|
||||
#define CMDLINE_SERIALNO_LEN (strlen(CMDLINE_SERIALNO))
|
||||
#define CPUINFO_SERIALNO "Serial"
|
||||
#define CPUINFO_SERIALNO_LEN (strlen(CPUINFO_SERIALNO))
|
||||
#define CPUINFO_HARDWARE "Hardware"
|
||||
#define CPUINFO_HARDWARE_LEN (strlen(CPUINFO_HARDWARE))
|
||||
#define CMDLINE_SERIALNO "androidboot.serialno="
|
||||
#define CMDLINE_SERIALNO_LEN (strlen(CMDLINE_SERIALNO))
|
||||
#define CPUINFO_SERIALNO "Serial"
|
||||
#define CPUINFO_SERIALNO_LEN (strlen(CPUINFO_SERIALNO))
|
||||
#define CPUINFO_HARDWARE "Hardware"
|
||||
#define CPUINFO_HARDWARE_LEN (strlen(CPUINFO_HARDWARE))
|
||||
|
||||
void DataManager::get_device_id(void) {
|
||||
FILE *fp;
|
||||
@@ -94,8 +94,8 @@ void DataManager::get_device_id(void) {
|
||||
char hardware_id[32], device_id[64];
|
||||
char* token;
|
||||
|
||||
// Assign a blank device_id to start with
|
||||
device_id[0] = 0;
|
||||
// Assign a blank device_id to start with
|
||||
device_id[0] = 0;
|
||||
|
||||
#ifdef TW_USE_MODEL_HARDWARE_ID_FOR_DEVICE_ID
|
||||
// Now we'll use product_model_hardwareid as device id
|
||||
@@ -121,37 +121,37 @@ void DataManager::get_device_id(void) {
|
||||
#endif
|
||||
|
||||
#ifndef TW_FORCE_CPUINFO_FOR_DEVICE_ID
|
||||
// First, try the cmdline to see if the serial number was supplied
|
||||
// First, try the cmdline to see if the serial number was supplied
|
||||
fp = fopen("/proc/cmdline", "rt");
|
||||
if (fp != NULL)
|
||||
{
|
||||
// First step, read the line. For cmdline, it's one long line
|
||||
fgets(line, sizeof(line), fp);
|
||||
fclose(fp);
|
||||
{
|
||||
// First step, read the line. For cmdline, it's one long line
|
||||
fgets(line, sizeof(line), fp);
|
||||
fclose(fp);
|
||||
|
||||
// Now, let's tokenize the string
|
||||
token = strtok(line, " ");
|
||||
// Now, let's tokenize the string
|
||||
token = strtok(line, " ");
|
||||
|
||||
// Let's walk through the line, looking for the CMDLINE_SERIALNO token
|
||||
while (token)
|
||||
{
|
||||
// We don't need to verify the length of token, because if it's too short, it will mismatch CMDLINE_SERIALNO at the NULL
|
||||
if (memcmp(token, CMDLINE_SERIALNO, CMDLINE_SERIALNO_LEN) == 0)
|
||||
{
|
||||
// We found the serial number!
|
||||
strcpy(device_id, token + CMDLINE_SERIALNO_LEN);
|
||||
// Let's walk through the line, looking for the CMDLINE_SERIALNO token
|
||||
while (token)
|
||||
{
|
||||
// We don't need to verify the length of token, because if it's too short, it will mismatch CMDLINE_SERIALNO at the NULL
|
||||
if (memcmp(token, CMDLINE_SERIALNO, CMDLINE_SERIALNO_LEN) == 0)
|
||||
{
|
||||
// We found the serial number!
|
||||
strcpy(device_id, token + CMDLINE_SERIALNO_LEN);
|
||||
sanitize_device_id((char *)device_id);
|
||||
mConstValues.insert(make_pair("device_id", device_id));
|
||||
return;
|
||||
}
|
||||
token = strtok(NULL, " ");
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
token = strtok(NULL, " ");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// Now we'll try cpuinfo for a serial number
|
||||
fp = fopen("/proc/cpuinfo", "rt");
|
||||
if (fp != NULL)
|
||||
{
|
||||
{
|
||||
while (fgets(line, sizeof(line), fp) != NULL) { // First step, read the line.
|
||||
if (memcmp(line, CPUINFO_SERIALNO, CPUINFO_SERIALNO_LEN) == 0) // check the beginning of the line for "Serial"
|
||||
{
|
||||
@@ -159,7 +159,7 @@ void DataManager::get_device_id(void) {
|
||||
token = line + CPUINFO_SERIALNO_LEN; // skip past "Serial"
|
||||
while ((*token > 0 && *token <= 32 ) || *token == ':') token++; // skip over all spaces and the colon
|
||||
if (*token != 0) {
|
||||
token[30] = 0;
|
||||
token[30] = 0;
|
||||
if (token[strlen(token)-1] == 10) { // checking for endline chars and dropping them from the end of the string if needed
|
||||
memset(device_id, 0, sizeof(device_id));
|
||||
strncpy(device_id, token, strlen(token) - 1);
|
||||
@@ -177,9 +177,9 @@ void DataManager::get_device_id(void) {
|
||||
token = line + CPUINFO_HARDWARE_LEN; // skip past "Hardware"
|
||||
while ((*token > 0 && *token <= 32 ) || *token == ':') token++; // skip over all spaces and the colon
|
||||
if (*token != 0) {
|
||||
token[30] = 0;
|
||||
token[30] = 0;
|
||||
if (token[strlen(token)-1] == 10) { // checking for endline chars and dropping them from the end of the string if needed
|
||||
memset(hardware_id, 0, sizeof(hardware_id));
|
||||
memset(hardware_id, 0, sizeof(hardware_id));
|
||||
strncpy(hardware_id, token, strlen(token) - 1);
|
||||
} else {
|
||||
strcpy(hardware_id, token);
|
||||
@@ -189,7 +189,7 @@ void DataManager::get_device_id(void) {
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
if (hardware_id[0] != 0) {
|
||||
LOGINFO("\nusing hardware id for device id: '%s'\n", hardware_id);
|
||||
@@ -199,76 +199,76 @@ void DataManager::get_device_id(void) {
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy(device_id, "serialno");
|
||||
strcpy(device_id, "serialno");
|
||||
LOGERR("=> device id not found, using '%s'.", device_id);
|
||||
mConstValues.insert(make_pair("device_id", device_id));
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
int DataManager::ResetDefaults()
|
||||
{
|
||||
mValues.clear();
|
||||
mConstValues.clear();
|
||||
SetDefaultValues();
|
||||
return 0;
|
||||
mValues.clear();
|
||||
mConstValues.clear();
|
||||
SetDefaultValues();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DataManager::LoadValues(const string filename)
|
||||
{
|
||||
string str, dev_id;
|
||||
string str, dev_id;
|
||||
|
||||
if (!mInitialized)
|
||||
SetDefaultValues();
|
||||
SetDefaultValues();
|
||||
|
||||
GetValue("device_id", dev_id);
|
||||
GetValue("device_id", dev_id);
|
||||
// Save off the backing file for set operations
|
||||
mBackingFile = filename;
|
||||
mBackingFile = filename;
|
||||
|
||||
// Read in the file, if possible
|
||||
FILE* in = fopen(filename.c_str(), "rb");
|
||||
if (!in) {
|
||||
// Read in the file, if possible
|
||||
FILE* in = fopen(filename.c_str(), "rb");
|
||||
if (!in) {
|
||||
LOGINFO("Settings file '%s' not found.\n", filename.c_str());
|
||||
return 0;
|
||||
} else {
|
||||
LOGINFO("Loading settings from '%s'.\n", filename.c_str());
|
||||
}
|
||||
|
||||
int file_version;
|
||||
if (fread(&file_version, 1, sizeof(int), in) != sizeof(int)) goto error;
|
||||
if (file_version != FILE_VERSION) goto error;
|
||||
int file_version;
|
||||
if (fread(&file_version, 1, sizeof(int), in) != sizeof(int)) goto error;
|
||||
if (file_version != FILE_VERSION) goto error;
|
||||
|
||||
while (!feof(in))
|
||||
{
|
||||
string Name;
|
||||
string Value;
|
||||
unsigned short length;
|
||||
char array[512];
|
||||
while (!feof(in))
|
||||
{
|
||||
string Name;
|
||||
string Value;
|
||||
unsigned short length;
|
||||
char array[512];
|
||||
|
||||
if (fread(&length, 1, sizeof(unsigned short), in) != sizeof(unsigned short)) goto error;
|
||||
if (length >= 512) goto error;
|
||||
if (fread(array, 1, length, in) != length) goto error;
|
||||
Name = array;
|
||||
if (fread(&length, 1, sizeof(unsigned short), in) != sizeof(unsigned short)) goto error;
|
||||
if (length >= 512) goto error;
|
||||
if (fread(array, 1, length, in) != length) goto error;
|
||||
Name = array;
|
||||
|
||||
if (fread(&length, 1, sizeof(unsigned short), in) != sizeof(unsigned short)) goto error;
|
||||
if (length >= 512) goto error;
|
||||
if (fread(array, 1, length, in) != length) goto error;
|
||||
Value = array;
|
||||
if (fread(&length, 1, sizeof(unsigned short), in) != sizeof(unsigned short)) goto error;
|
||||
if (length >= 512) goto error;
|
||||
if (fread(array, 1, length, in) != length) goto error;
|
||||
Value = array;
|
||||
|
||||
map<string, TStrIntPair>::iterator pos;
|
||||
map<string, TStrIntPair>::iterator pos;
|
||||
|
||||
pos = mValues.find(Name);
|
||||
if (pos != mValues.end())
|
||||
{
|
||||
pos->second.first = Value;
|
||||
pos->second.second = 1;
|
||||
}
|
||||
else
|
||||
mValues.insert(TNameValuePair(Name, TStrIntPair(Value, 1)));
|
||||
pos = mValues.find(Name);
|
||||
if (pos != mValues.end())
|
||||
{
|
||||
pos->second.first = Value;
|
||||
pos->second.second = 1;
|
||||
}
|
||||
else
|
||||
mValues.insert(TNameValuePair(Name, TStrIntPair(Value, 1)));
|
||||
if (Name == "tw_screen_timeout_secs")
|
||||
blankTimer.setTime(atoi(Value.c_str()));
|
||||
}
|
||||
}
|
||||
error:
|
||||
fclose(in);
|
||||
fclose(in);
|
||||
string current = GetCurrentStoragePath();
|
||||
string settings = GetSettingsStoragePath();
|
||||
if (current != settings && !PartitionManager.Mount_By_Path(current, false)) {
|
||||
@@ -276,185 +276,188 @@ error:
|
||||
} else {
|
||||
SetBackupFolder();
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DataManager::Flush()
|
||||
{
|
||||
return SaveValues();
|
||||
return SaveValues();
|
||||
}
|
||||
|
||||
int DataManager::SaveValues()
|
||||
{
|
||||
if (mBackingFile.empty()) return -1;
|
||||
if (mBackingFile.empty())
|
||||
return -1;
|
||||
|
||||
string mount_path = GetSettingsStoragePath();
|
||||
PartitionManager.Mount_By_Path(mount_path.c_str(), 1);
|
||||
|
||||
FILE* out = fopen(mBackingFile.c_str(), "wb");
|
||||
if (!out) return -1;
|
||||
if (!out)
|
||||
return -1;
|
||||
|
||||
int file_version = FILE_VERSION;
|
||||
fwrite(&file_version, 1, sizeof(int), out);
|
||||
int file_version = FILE_VERSION;
|
||||
fwrite(&file_version, 1, sizeof(int), out);
|
||||
|
||||
map<string, TStrIntPair>::iterator iter;
|
||||
for (iter = mValues.begin(); iter != mValues.end(); ++iter)
|
||||
{
|
||||
// Save only the persisted data
|
||||
if (iter->second.second != 0)
|
||||
{
|
||||
unsigned short length = (unsigned short) iter->first.length() + 1;
|
||||
fwrite(&length, 1, sizeof(unsigned short), out);
|
||||
fwrite(iter->first.c_str(), 1, length, out);
|
||||
length = (unsigned short) iter->second.first.length() + 1;
|
||||
fwrite(&length, 1, sizeof(unsigned short), out);
|
||||
fwrite(iter->second.first.c_str(), 1, length, out);
|
||||
}
|
||||
}
|
||||
fclose(out);
|
||||
return 0;
|
||||
map<string, TStrIntPair>::iterator iter;
|
||||
for (iter = mValues.begin(); iter != mValues.end(); ++iter)
|
||||
{
|
||||
// Save only the persisted data
|
||||
if (iter->second.second != 0)
|
||||
{
|
||||
unsigned short length = (unsigned short) iter->first.length() + 1;
|
||||
fwrite(&length, 1, sizeof(unsigned short), out);
|
||||
fwrite(iter->first.c_str(), 1, length, out);
|
||||
length = (unsigned short) iter->second.first.length() + 1;
|
||||
fwrite(&length, 1, sizeof(unsigned short), out);
|
||||
fwrite(iter->second.first.c_str(), 1, length, out);
|
||||
}
|
||||
}
|
||||
fclose(out);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DataManager::GetValue(const string varName, string& value)
|
||||
{
|
||||
string localStr = varName;
|
||||
string localStr = varName;
|
||||
|
||||
if (!mInitialized)
|
||||
SetDefaultValues();
|
||||
if (!mInitialized)
|
||||
SetDefaultValues();
|
||||
|
||||
// Strip off leading and trailing '%' if provided
|
||||
if (localStr.length() > 2 && localStr[0] == '%' && localStr[localStr.length()-1] == '%')
|
||||
{
|
||||
localStr.erase(0, 1);
|
||||
localStr.erase(localStr.length() - 1, 1);
|
||||
}
|
||||
// Strip off leading and trailing '%' if provided
|
||||
if (localStr.length() > 2 && localStr[0] == '%' && localStr[localStr.length()-1] == '%')
|
||||
{
|
||||
localStr.erase(0, 1);
|
||||
localStr.erase(localStr.length() - 1, 1);
|
||||
}
|
||||
|
||||
// Handle magic values
|
||||
if (GetMagicValue(localStr, value) == 0) return 0;
|
||||
// Handle magic values
|
||||
if (GetMagicValue(localStr, value) == 0)
|
||||
return 0;
|
||||
|
||||
map<string, string>::iterator constPos;
|
||||
constPos = mConstValues.find(localStr);
|
||||
if (constPos != mConstValues.end())
|
||||
{
|
||||
value = constPos->second;
|
||||
return 0;
|
||||
}
|
||||
map<string, string>::iterator constPos;
|
||||
constPos = mConstValues.find(localStr);
|
||||
if (constPos != mConstValues.end())
|
||||
{
|
||||
value = constPos->second;
|
||||
return 0;
|
||||
}
|
||||
|
||||
map<string, TStrIntPair>::iterator pos;
|
||||
pos = mValues.find(localStr);
|
||||
if (pos == mValues.end())
|
||||
return -1;
|
||||
map<string, TStrIntPair>::iterator pos;
|
||||
pos = mValues.find(localStr);
|
||||
if (pos == mValues.end())
|
||||
return -1;
|
||||
|
||||
value = pos->second.first;
|
||||
return 0;
|
||||
value = pos->second.first;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DataManager::GetValue(const string varName, int& value)
|
||||
{
|
||||
string data;
|
||||
string data;
|
||||
|
||||
if (GetValue(varName,data) != 0)
|
||||
return -1;
|
||||
if (GetValue(varName,data) != 0)
|
||||
return -1;
|
||||
|
||||
value = atoi(data.c_str());
|
||||
return 0;
|
||||
value = atoi(data.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DataManager::GetValue(const string varName, float& value)
|
||||
{
|
||||
string data;
|
||||
string data;
|
||||
|
||||
if (GetValue(varName,data) != 0)
|
||||
return -1;
|
||||
if (GetValue(varName,data) != 0)
|
||||
return -1;
|
||||
|
||||
value = atof(data.c_str());
|
||||
return 0;
|
||||
value = atof(data.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned long long DataManager::GetValue(const string varName, unsigned long long& value)
|
||||
{
|
||||
string data;
|
||||
string data;
|
||||
|
||||
if (GetValue(varName,data) != 0)
|
||||
return -1;
|
||||
if (GetValue(varName,data) != 0)
|
||||
return -1;
|
||||
|
||||
value = strtoull(data.c_str(), NULL, 10);
|
||||
return 0;
|
||||
value = strtoull(data.c_str(), NULL, 10);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// This is a dangerous function. It will create the value if it doesn't exist so it has a valid c_str
|
||||
string& DataManager::GetValueRef(const string varName)
|
||||
{
|
||||
if (!mInitialized)
|
||||
SetDefaultValues();
|
||||
if (!mInitialized)
|
||||
SetDefaultValues();
|
||||
|
||||
map<string, string>::iterator constPos;
|
||||
constPos = mConstValues.find(varName);
|
||||
if (constPos != mConstValues.end())
|
||||
return constPos->second;
|
||||
map<string, string>::iterator constPos;
|
||||
constPos = mConstValues.find(varName);
|
||||
if (constPos != mConstValues.end())
|
||||
return constPos->second;
|
||||
|
||||
map<string, TStrIntPair>::iterator pos;
|
||||
pos = mValues.find(varName);
|
||||
if (pos == mValues.end())
|
||||
pos = (mValues.insert(TNameValuePair(varName, TStrIntPair("", 0)))).first;
|
||||
map<string, TStrIntPair>::iterator pos;
|
||||
pos = mValues.find(varName);
|
||||
if (pos == mValues.end())
|
||||
pos = (mValues.insert(TNameValuePair(varName, TStrIntPair("", 0)))).first;
|
||||
|
||||
return pos->second.first;
|
||||
return pos->second.first;
|
||||
}
|
||||
|
||||
// This function will return an empty string if the value doesn't exist
|
||||
string DataManager::GetStrValue(const string varName)
|
||||
{
|
||||
string retVal;
|
||||
string retVal;
|
||||
|
||||
GetValue(varName, retVal);
|
||||
return retVal;
|
||||
GetValue(varName, retVal);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
// This function will return 0 if the value doesn't exist
|
||||
int DataManager::GetIntValue(const string varName)
|
||||
{
|
||||
string retVal;
|
||||
string retVal;
|
||||
|
||||
GetValue(varName, retVal);
|
||||
return atoi(retVal.c_str());
|
||||
GetValue(varName, retVal);
|
||||
return atoi(retVal.c_str());
|
||||
}
|
||||
|
||||
int DataManager::SetValue(const string varName, string value, int persist /* = 0 */)
|
||||
{
|
||||
if (!mInitialized)
|
||||
SetDefaultValues();
|
||||
if (!mInitialized)
|
||||
SetDefaultValues();
|
||||
|
||||
// Don't allow empty values or numerical starting values
|
||||
if (varName.empty() || (varName[0] >= '0' && varName[0] <= '9'))
|
||||
return -1;
|
||||
// Don't allow empty values or numerical starting values
|
||||
if (varName.empty() || (varName[0] >= '0' && varName[0] <= '9'))
|
||||
return -1;
|
||||
|
||||
map<string, string>::iterator constChk;
|
||||
constChk = mConstValues.find(varName);
|
||||
if (constChk != mConstValues.end())
|
||||
return -1;
|
||||
map<string, string>::iterator constChk;
|
||||
constChk = mConstValues.find(varName);
|
||||
if (constChk != mConstValues.end())
|
||||
return -1;
|
||||
|
||||
map<string, TStrIntPair>::iterator pos;
|
||||
pos = mValues.find(varName);
|
||||
if (pos == mValues.end())
|
||||
pos = (mValues.insert(TNameValuePair(varName, TStrIntPair(value, persist)))).first;
|
||||
else
|
||||
pos->second.first = value;
|
||||
map<string, TStrIntPair>::iterator pos;
|
||||
pos = mValues.find(varName);
|
||||
if (pos == mValues.end())
|
||||
pos = (mValues.insert(TNameValuePair(varName, TStrIntPair(value, persist)))).first;
|
||||
else
|
||||
pos->second.first = value;
|
||||
|
||||
if (pos->second.second != 0)
|
||||
SaveValues();
|
||||
if (pos->second.second != 0)
|
||||
SaveValues();
|
||||
if (varName == "tw_screen_timeout_secs") {
|
||||
blankTimer.setTime(atoi(value.c_str()));
|
||||
} else if (varName == "tw_storage_path") {
|
||||
SetBackupFolder();
|
||||
}
|
||||
gui_notifyVarChange(varName.c_str(), value.c_str());
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DataManager::SetValue(const string varName, int value, int persist /* = 0 */)
|
||||
{
|
||||
ostringstream valStr;
|
||||
valStr << value;
|
||||
valStr << value;
|
||||
if (varName == "tw_use_external_storage") {
|
||||
string str;
|
||||
|
||||
@@ -471,28 +474,29 @@ int DataManager::SetValue(const string varName, int value, int persist /* = 0 */
|
||||
|
||||
SetValue("tw_storage_path", str);
|
||||
}
|
||||
return SetValue(varName, valStr.str(), persist);
|
||||
return SetValue(varName, valStr.str(), persist);
|
||||
}
|
||||
|
||||
int DataManager::SetValue(const string varName, float value, int persist /* = 0 */)
|
||||
{
|
||||
ostringstream valStr;
|
||||
valStr << value;
|
||||
return SetValue(varName, valStr.str(), persist);;
|
||||
valStr << value;
|
||||
return SetValue(varName, valStr.str(), persist);;
|
||||
}
|
||||
|
||||
int DataManager::SetValue(const string varName, unsigned long long value, int persist /* = 0 */)
|
||||
{
|
||||
ostringstream valStr;
|
||||
valStr << value;
|
||||
return SetValue(varName, valStr.str(), persist);;
|
||||
valStr << value;
|
||||
return SetValue(varName, valStr.str(), persist);
|
||||
}
|
||||
|
||||
int DataManager::SetProgress(float Fraction) {
|
||||
return SetValue("ui_progress", (float) (Fraction * 100.0));
|
||||
}
|
||||
|
||||
int DataManager::ShowProgress(float Portion, float Seconds) {
|
||||
int DataManager::ShowProgress(float Portion, float Seconds)
|
||||
{
|
||||
float Starting_Portion;
|
||||
GetValue("ui_progress_portion", Starting_Portion);
|
||||
if (SetValue("ui_progress_portion", (float)(Portion * 100.0) + Starting_Portion) != 0)
|
||||
@@ -504,17 +508,16 @@ int DataManager::ShowProgress(float Portion, float Seconds) {
|
||||
|
||||
void DataManager::DumpValues()
|
||||
{
|
||||
map<string, TStrIntPair>::iterator iter;
|
||||
gui_print("Data Manager dump - Values with leading X are persisted.\n");
|
||||
for (iter = mValues.begin(); iter != mValues.end(); ++iter)
|
||||
{
|
||||
gui_print("%c %s=%s\n", iter->second.second ? 'X' : ' ', iter->first.c_str(), iter->second.first.c_str());
|
||||
}
|
||||
map<string, TStrIntPair>::iterator iter;
|
||||
gui_print("Data Manager dump - Values with leading X are persisted.\n");
|
||||
for (iter = mValues.begin(); iter != mValues.end(); ++iter)
|
||||
gui_print("%c %s=%s\n", iter->second.second ? 'X' : ' ', iter->first.c_str(), iter->second.first.c_str());
|
||||
}
|
||||
|
||||
void DataManager::update_tz_environment_variables(void) {
|
||||
void DataManager::update_tz_environment_variables(void)
|
||||
{
|
||||
setenv("TZ", DataManager_GetStrValue(TW_TIME_ZONE_VAR), 1);
|
||||
tzset();
|
||||
tzset();
|
||||
}
|
||||
|
||||
void DataManager::SetBackupFolder()
|
||||
@@ -526,7 +529,7 @@ void DataManager::SetBackupFolder()
|
||||
string dev_id;
|
||||
GetValue("device_id", dev_id);
|
||||
|
||||
str += dev_id;
|
||||
str += dev_id;
|
||||
LOGINFO("Backup folder set to '%s'\n", str.c_str());
|
||||
SetValue(TW_BACKUPS_FOLDER_VAR, str, 0);
|
||||
if (partition != NULL) {
|
||||
@@ -558,16 +561,16 @@ void DataManager::SetBackupFolder()
|
||||
|
||||
void DataManager::SetDefaultValues()
|
||||
{
|
||||
string str, path;
|
||||
string str, path;
|
||||
|
||||
get_device_id();
|
||||
get_device_id();
|
||||
|
||||
mInitialized = 1;
|
||||
mInitialized = 1;
|
||||
|
||||
mConstValues.insert(make_pair("true", "1"));
|
||||
mConstValues.insert(make_pair("false", "0"));
|
||||
mConstValues.insert(make_pair("true", "1"));
|
||||
mConstValues.insert(make_pair("false", "0"));
|
||||
|
||||
mConstValues.insert(make_pair(TW_VERSION_VAR, TW_VERSION_STR));
|
||||
mConstValues.insert(make_pair(TW_VERSION_VAR, TW_VERSION_STR));
|
||||
mValues.insert(make_pair("tw_storage_path", make_pair("/", 1)));
|
||||
|
||||
#ifdef TW_FORCE_CPUINFO_FOR_DEVICE_ID
|
||||
@@ -576,9 +579,9 @@ void DataManager::SetDefaultValues()
|
||||
|
||||
#ifdef BOARD_HAS_NO_REAL_SDCARD
|
||||
printf("BOARD_HAS_NO_REAL_SDCARD := true\n");
|
||||
mConstValues.insert(make_pair(TW_ALLOW_PARTITION_SDCARD, "0"));
|
||||
mConstValues.insert(make_pair(TW_ALLOW_PARTITION_SDCARD, "0"));
|
||||
#else
|
||||
mConstValues.insert(make_pair(TW_ALLOW_PARTITION_SDCARD, "1"));
|
||||
mConstValues.insert(make_pair(TW_ALLOW_PARTITION_SDCARD, "1"));
|
||||
#endif
|
||||
|
||||
#ifdef TW_INCLUDE_DUMLOCK
|
||||
@@ -720,45 +723,45 @@ void DataManager::SetDefaultValues()
|
||||
string dev_id;
|
||||
GetValue("device_id", dev_id);
|
||||
|
||||
str += dev_id;
|
||||
str += dev_id;
|
||||
SetValue(TW_BACKUPS_FOLDER_VAR, str, 0);
|
||||
|
||||
#ifdef SP1_DISPLAY_NAME
|
||||
printf("SP1_DISPLAY_NAME := %s\n", EXPAND(SP1_DISPLAY_NAME));
|
||||
if (strlen(EXPAND(SP1_DISPLAY_NAME))) mConstValues.insert(make_pair(TW_SP1_PARTITION_NAME_VAR, EXPAND(SP1_DISPLAY_NAME)));
|
||||
if (strlen(EXPAND(SP1_DISPLAY_NAME))) mConstValues.insert(make_pair(TW_SP1_PARTITION_NAME_VAR, EXPAND(SP1_DISPLAY_NAME)));
|
||||
#else
|
||||
#ifdef SP1_NAME
|
||||
printf("SP1_NAME := %s\n", EXPAND(SP1_NAME));
|
||||
if (strlen(EXPAND(SP1_NAME))) mConstValues.insert(make_pair(TW_SP1_PARTITION_NAME_VAR, EXPAND(SP1_NAME)));
|
||||
if (strlen(EXPAND(SP1_NAME))) mConstValues.insert(make_pair(TW_SP1_PARTITION_NAME_VAR, EXPAND(SP1_NAME)));
|
||||
#endif
|
||||
#endif
|
||||
#ifdef SP2_DISPLAY_NAME
|
||||
printf("SP2_DISPLAY_NAME := %s\n", EXPAND(SP2_DISPLAY_NAME));
|
||||
if (strlen(EXPAND(SP2_DISPLAY_NAME))) mConstValues.insert(make_pair(TW_SP2_PARTITION_NAME_VAR, EXPAND(SP2_DISPLAY_NAME)));
|
||||
if (strlen(EXPAND(SP2_DISPLAY_NAME))) mConstValues.insert(make_pair(TW_SP2_PARTITION_NAME_VAR, EXPAND(SP2_DISPLAY_NAME)));
|
||||
#else
|
||||
#ifdef SP2_NAME
|
||||
printf("SP2_NAME := %s\n", EXPAND(SP2_NAME));
|
||||
if (strlen(EXPAND(SP2_NAME))) mConstValues.insert(make_pair(TW_SP2_PARTITION_NAME_VAR, EXPAND(SP2_NAME)));
|
||||
if (strlen(EXPAND(SP2_NAME))) mConstValues.insert(make_pair(TW_SP2_PARTITION_NAME_VAR, EXPAND(SP2_NAME)));
|
||||
#endif
|
||||
#endif
|
||||
#ifdef SP3_DISPLAY_NAME
|
||||
printf("SP3_DISPLAY_NAME := %s\n", EXPAND(SP3_DISPLAY_NAME));
|
||||
if (strlen(EXPAND(SP3_DISPLAY_NAME))) mConstValues.insert(make_pair(TW_SP3_PARTITION_NAME_VAR, EXPAND(SP3_DISPLAY_NAME)));
|
||||
if (strlen(EXPAND(SP3_DISPLAY_NAME))) mConstValues.insert(make_pair(TW_SP3_PARTITION_NAME_VAR, EXPAND(SP3_DISPLAY_NAME)));
|
||||
#else
|
||||
#ifdef SP3_NAME
|
||||
printf("SP3_NAME := %s\n", EXPAND(SP3_NAME));
|
||||
if (strlen(EXPAND(SP3_NAME))) mConstValues.insert(make_pair(TW_SP3_PARTITION_NAME_VAR, EXPAND(SP3_NAME)));
|
||||
if (strlen(EXPAND(SP3_NAME))) mConstValues.insert(make_pair(TW_SP3_PARTITION_NAME_VAR, EXPAND(SP3_NAME)));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
mConstValues.insert(make_pair(TW_REBOOT_SYSTEM, "1"));
|
||||
mConstValues.insert(make_pair(TW_REBOOT_SYSTEM, "1"));
|
||||
#ifdef TW_NO_REBOOT_RECOVERY
|
||||
printf("TW_NO_REBOOT_RECOVERY := true\n");
|
||||
mConstValues.insert(make_pair(TW_REBOOT_RECOVERY, "0"));
|
||||
#else
|
||||
mConstValues.insert(make_pair(TW_REBOOT_RECOVERY, "1"));
|
||||
#endif
|
||||
mConstValues.insert(make_pair(TW_REBOOT_POWEROFF, "1"));
|
||||
mConstValues.insert(make_pair(TW_REBOOT_POWEROFF, "1"));
|
||||
#ifdef TW_NO_REBOOT_BOOTLOADER
|
||||
printf("TW_NO_REBOOT_BOOTLOADER := true\n");
|
||||
mConstValues.insert(make_pair(TW_REBOOT_BOOTLOADER, "0"));
|
||||
@@ -843,15 +846,15 @@ void DataManager::SetDefaultValues()
|
||||
mConstValues.insert(make_pair(TW_MIN_SYSTEM_VAR, TW_MIN_SYSTEM_SIZE));
|
||||
mValues.insert(make_pair(TW_BACKUP_NAME, make_pair("(Current Date)", 0)));
|
||||
mValues.insert(make_pair(TW_BACKUP_SYSTEM_VAR, make_pair("1", 1)));
|
||||
mValues.insert(make_pair(TW_BACKUP_DATA_VAR, make_pair("1", 1)));
|
||||
mValues.insert(make_pair(TW_BACKUP_BOOT_VAR, make_pair("1", 1)));
|
||||
mValues.insert(make_pair(TW_BACKUP_RECOVERY_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_BACKUP_CACHE_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_BACKUP_SP1_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_BACKUP_SP2_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_BACKUP_SP3_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_BACKUP_ANDSEC_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_BACKUP_SDEXT_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_BACKUP_DATA_VAR, make_pair("1", 1)));
|
||||
mValues.insert(make_pair(TW_BACKUP_BOOT_VAR, make_pair("1", 1)));
|
||||
mValues.insert(make_pair(TW_BACKUP_RECOVERY_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_BACKUP_CACHE_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_BACKUP_SP1_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_BACKUP_SP2_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_BACKUP_SP3_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_BACKUP_ANDSEC_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_BACKUP_SDEXT_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_BACKUP_SYSTEM_SIZE, make_pair("0", 0)));
|
||||
mValues.insert(make_pair(TW_BACKUP_DATA_SIZE, make_pair("0", 0)));
|
||||
mValues.insert(make_pair(TW_BACKUP_BOOT_SIZE, make_pair("0", 0)));
|
||||
@@ -864,33 +867,33 @@ void DataManager::SetDefaultValues()
|
||||
mValues.insert(make_pair(TW_BACKUP_SP3_SIZE, make_pair("0", 0)));
|
||||
mValues.insert(make_pair(TW_STORAGE_FREE_SIZE, make_pair("0", 0)));
|
||||
|
||||
mValues.insert(make_pair(TW_REBOOT_AFTER_FLASH_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_SIGNED_ZIP_VERIFY_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_FORCE_MD5_CHECK_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_COLOR_THEME_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_USE_COMPRESSION_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_SHOW_SPAM_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_TIME_ZONE_VAR, make_pair("CST6CDT", 1)));
|
||||
mValues.insert(make_pair(TW_SORT_FILES_BY_DATE_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_GUI_SORT_ORDER, make_pair("1", 1)));
|
||||
mValues.insert(make_pair(TW_RM_RF_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_SKIP_MD5_CHECK_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_SKIP_MD5_GENERATE_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_SDEXT_SIZE, make_pair("512", 1)));
|
||||
mValues.insert(make_pair(TW_SWAP_SIZE, make_pair("32", 1)));
|
||||
mValues.insert(make_pair(TW_SDPART_FILE_SYSTEM, make_pair("ext3", 1)));
|
||||
mValues.insert(make_pair(TW_TIME_ZONE_GUISEL, make_pair("CST6;CDT", 1)));
|
||||
mValues.insert(make_pair(TW_TIME_ZONE_GUIOFFSET, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_TIME_ZONE_GUIDST, make_pair("1", 1)));
|
||||
mValues.insert(make_pair(TW_ACTION_BUSY, make_pair("0", 0)));
|
||||
mValues.insert(make_pair(TW_BACKUP_AVG_IMG_RATE, make_pair("15000000", 1)));
|
||||
mValues.insert(make_pair(TW_BACKUP_AVG_FILE_RATE, make_pair("3000000", 1)));
|
||||
mValues.insert(make_pair(TW_BACKUP_AVG_FILE_COMP_RATE, make_pair("2000000", 1)));
|
||||
mValues.insert(make_pair(TW_RESTORE_AVG_IMG_RATE, make_pair("15000000", 1)));
|
||||
mValues.insert(make_pair(TW_RESTORE_AVG_FILE_RATE, make_pair("3000000", 1)));
|
||||
mValues.insert(make_pair(TW_RESTORE_AVG_FILE_COMP_RATE, make_pair("2000000", 1)));
|
||||
mValues.insert(make_pair("tw_wipe_cache", make_pair("0", 0)));
|
||||
mValues.insert(make_pair("tw_wipe_dalvik", make_pair("0", 0)));
|
||||
mValues.insert(make_pair(TW_REBOOT_AFTER_FLASH_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_SIGNED_ZIP_VERIFY_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_FORCE_MD5_CHECK_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_COLOR_THEME_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_USE_COMPRESSION_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_SHOW_SPAM_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_TIME_ZONE_VAR, make_pair("CST6CDT", 1)));
|
||||
mValues.insert(make_pair(TW_SORT_FILES_BY_DATE_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_GUI_SORT_ORDER, make_pair("1", 1)));
|
||||
mValues.insert(make_pair(TW_RM_RF_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_SKIP_MD5_CHECK_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_SKIP_MD5_GENERATE_VAR, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_SDEXT_SIZE, make_pair("512", 1)));
|
||||
mValues.insert(make_pair(TW_SWAP_SIZE, make_pair("32", 1)));
|
||||
mValues.insert(make_pair(TW_SDPART_FILE_SYSTEM, make_pair("ext3", 1)));
|
||||
mValues.insert(make_pair(TW_TIME_ZONE_GUISEL, make_pair("CST6;CDT", 1)));
|
||||
mValues.insert(make_pair(TW_TIME_ZONE_GUIOFFSET, make_pair("0", 1)));
|
||||
mValues.insert(make_pair(TW_TIME_ZONE_GUIDST, make_pair("1", 1)));
|
||||
mValues.insert(make_pair(TW_ACTION_BUSY, make_pair("0", 0)));
|
||||
mValues.insert(make_pair(TW_BACKUP_AVG_IMG_RATE, make_pair("15000000", 1)));
|
||||
mValues.insert(make_pair(TW_BACKUP_AVG_FILE_RATE, make_pair("3000000", 1)));
|
||||
mValues.insert(make_pair(TW_BACKUP_AVG_FILE_COMP_RATE, make_pair("2000000", 1)));
|
||||
mValues.insert(make_pair(TW_RESTORE_AVG_IMG_RATE, make_pair("15000000", 1)));
|
||||
mValues.insert(make_pair(TW_RESTORE_AVG_FILE_RATE, make_pair("3000000", 1)));
|
||||
mValues.insert(make_pair(TW_RESTORE_AVG_FILE_COMP_RATE, make_pair("2000000", 1)));
|
||||
mValues.insert(make_pair("tw_wipe_cache", make_pair("0", 0)));
|
||||
mValues.insert(make_pair("tw_wipe_dalvik", make_pair("0", 0)));
|
||||
if (GetIntValue(TW_HAS_INTERNAL) == 1 && GetIntValue(TW_HAS_DATA_MEDIA) == 1 && GetIntValue(TW_HAS_EXTERNAL) == 0)
|
||||
SetValue(TW_HAS_USB_STORAGE, 0, 0);
|
||||
else
|
||||
@@ -940,35 +943,37 @@ void DataManager::SetDefaultValues()
|
||||
// Magic Values
|
||||
int DataManager::GetMagicValue(const string varName, string& value)
|
||||
{
|
||||
// Handle special dynamic cases
|
||||
if (varName == "tw_time")
|
||||
{
|
||||
char tmp[32];
|
||||
// Handle special dynamic cases
|
||||
if (varName == "tw_time")
|
||||
{
|
||||
char tmp[32];
|
||||
|
||||
struct tm *current;
|
||||
time_t now;
|
||||
int tw_military_time;
|
||||
now = time(0);
|
||||
current = localtime(&now);
|
||||
GetValue(TW_MILITARY_TIME, tw_military_time);
|
||||
if (current->tm_hour >= 12) {
|
||||
if (tw_military_time == 1)
|
||||
sprintf(tmp, "%d:%02d", current->tm_hour, current->tm_min);
|
||||
else
|
||||
sprintf(tmp, "%d:%02d PM", current->tm_hour == 12 ? 12 : current->tm_hour - 12, current->tm_min);
|
||||
struct tm *current;
|
||||
time_t now;
|
||||
int tw_military_time;
|
||||
now = time(0);
|
||||
current = localtime(&now);
|
||||
GetValue(TW_MILITARY_TIME, tw_military_time);
|
||||
if (current->tm_hour >= 12)
|
||||
{
|
||||
if (tw_military_time == 1)
|
||||
sprintf(tmp, "%d:%02d", current->tm_hour, current->tm_min);
|
||||
else
|
||||
sprintf(tmp, "%d:%02d PM", current->tm_hour == 12 ? 12 : current->tm_hour - 12, current->tm_min);
|
||||
}
|
||||
else {
|
||||
if (tw_military_time == 1)
|
||||
sprintf(tmp, "%d:%02d", current->tm_hour, current->tm_min);
|
||||
else
|
||||
sprintf(tmp, "%d:%02d AM", current->tm_hour == 0 ? 12 : current->tm_hour, current->tm_min);
|
||||
{
|
||||
if (tw_military_time == 1)
|
||||
sprintf(tmp, "%d:%02d", current->tm_hour, current->tm_min);
|
||||
else
|
||||
sprintf(tmp, "%d:%02d AM", current->tm_hour == 0 ? 12 : current->tm_hour, current->tm_min);
|
||||
}
|
||||
value = tmp;
|
||||
return 0;
|
||||
}
|
||||
value = tmp;
|
||||
return 0;
|
||||
}
|
||||
if (varName == "tw_battery")
|
||||
{
|
||||
char tmp[16];
|
||||
else if (varName == "tw_battery")
|
||||
{
|
||||
char tmp[16];
|
||||
static char charging = ' ';
|
||||
static int lastVal = -1;
|
||||
static time_t nextSecCheck = 0;
|
||||
@@ -989,8 +994,8 @@ int DataManager::GetMagicValue(const string varName, string& value)
|
||||
fgets(cap_s, 4, cap);
|
||||
fclose(cap);
|
||||
lastVal = atoi(cap_s);
|
||||
if (lastVal > 100) lastVal = 101;
|
||||
if (lastVal < 0) lastVal = 0;
|
||||
if (lastVal > 100) lastVal = 101;
|
||||
if (lastVal < 0) lastVal = 0;
|
||||
}
|
||||
#ifdef TW_CUSTOM_BATTERY_PATH
|
||||
string status_file = EXPAND(TW_CUSTOM_BATTERY_PATH);
|
||||
@@ -1011,13 +1016,14 @@ int DataManager::GetMagicValue(const string varName, string& value)
|
||||
}
|
||||
|
||||
sprintf(tmp, "%i%%%c", lastVal, charging);
|
||||
value = tmp;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
value = tmp;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void DataManager::Output_Version(void) {
|
||||
void DataManager::Output_Version(void)
|
||||
{
|
||||
string Path;
|
||||
char version[255];
|
||||
|
||||
@@ -1131,89 +1137,89 @@ string& DataManager::CGetSettingsStoragePath()
|
||||
return GetValueRef("tw_settings_path");
|
||||
}
|
||||
|
||||
extern "C" int DataManager_ResetDefaults()
|
||||
extern "C" int DataManager_ResetDefaults(void)
|
||||
{
|
||||
return DataManager::ResetDefaults();
|
||||
return DataManager::ResetDefaults();
|
||||
}
|
||||
|
||||
extern "C" void DataManager_LoadDefaults()
|
||||
extern "C" void DataManager_LoadDefaults(void)
|
||||
{
|
||||
return DataManager::SetDefaultValues();
|
||||
return DataManager::SetDefaultValues();
|
||||
}
|
||||
|
||||
extern "C" int DataManager_LoadValues(const char* filename)
|
||||
{
|
||||
return DataManager::LoadValues(filename);
|
||||
return DataManager::LoadValues(filename);
|
||||
}
|
||||
|
||||
extern "C" int DataManager_Flush()
|
||||
extern "C" int DataManager_Flush(void)
|
||||
{
|
||||
return DataManager::Flush();
|
||||
return DataManager::Flush();
|
||||
}
|
||||
|
||||
extern "C" int DataManager_GetValue(const char* varName, char* value)
|
||||
{
|
||||
int ret;
|
||||
string str;
|
||||
int ret;
|
||||
string str;
|
||||
|
||||
ret = DataManager::GetValue(varName, str);
|
||||
if (ret == 0)
|
||||
strcpy(value, str.c_str());
|
||||
return ret;
|
||||
ret = DataManager::GetValue(varName, str);
|
||||
if (ret == 0)
|
||||
strcpy(value, str.c_str());
|
||||
return ret;
|
||||
}
|
||||
|
||||
extern "C" const char* DataManager_GetStrValue(const char* varName)
|
||||
{
|
||||
string& str = DataManager::GetValueRef(varName);
|
||||
return str.c_str();
|
||||
string& str = DataManager::GetValueRef(varName);
|
||||
return str.c_str();
|
||||
}
|
||||
|
||||
extern "C" const char* DataManager_GetCurrentStoragePath(void)
|
||||
{
|
||||
string& str = DataManager::CGetCurrentStoragePath();
|
||||
return str.c_str();
|
||||
string& str = DataManager::CGetCurrentStoragePath();
|
||||
return str.c_str();
|
||||
}
|
||||
|
||||
extern "C" const char* DataManager_GetSettingsStoragePath(void)
|
||||
{
|
||||
string& str = DataManager::CGetSettingsStoragePath();
|
||||
return str.c_str();
|
||||
string& str = DataManager::CGetSettingsStoragePath();
|
||||
return str.c_str();
|
||||
}
|
||||
|
||||
extern "C" int DataManager_GetIntValue(const char* varName)
|
||||
{
|
||||
return DataManager::GetIntValue(varName);
|
||||
return DataManager::GetIntValue(varName);
|
||||
}
|
||||
|
||||
extern "C" int DataManager_SetStrValue(const char* varName, char* value)
|
||||
{
|
||||
return DataManager::SetValue(varName, value, 0);
|
||||
return DataManager::SetValue(varName, value, 0);
|
||||
}
|
||||
|
||||
extern "C" int DataManager_SetIntValue(const char* varName, int value)
|
||||
{
|
||||
return DataManager::SetValue(varName, value, 0);
|
||||
return DataManager::SetValue(varName, value, 0);
|
||||
}
|
||||
|
||||
extern "C" int DataManager_SetFloatValue(const char* varName, float value)
|
||||
{
|
||||
return DataManager::SetValue(varName, value, 0);
|
||||
return DataManager::SetValue(varName, value, 0);
|
||||
}
|
||||
|
||||
extern "C" int DataManager_ToggleIntValue(const char* varName)
|
||||
{
|
||||
if (DataManager::GetIntValue(varName))
|
||||
return DataManager::SetValue(varName, 0);
|
||||
else
|
||||
return DataManager::SetValue(varName, 1);
|
||||
if (DataManager::GetIntValue(varName))
|
||||
return DataManager::SetValue(varName, 0);
|
||||
else
|
||||
return DataManager::SetValue(varName, 1);
|
||||
}
|
||||
|
||||
extern "C" void DataManager_DumpValues()
|
||||
extern "C" void DataManager_DumpValues(void)
|
||||
{
|
||||
return DataManager::DumpValues();
|
||||
return DataManager::DumpValues();
|
||||
}
|
||||
|
||||
extern "C" void DataManager_ReadSettingsFile()
|
||||
extern "C" void DataManager_ReadSettingsFile(void)
|
||||
{
|
||||
return DataManager::ReadSettingsFile();
|
||||
return DataManager::ReadSettingsFile();
|
||||
}
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
#ifndef _DATA_HEADER
|
||||
#define _DATA_HEADER
|
||||
|
||||
int DataManager_ResetDefaults();
|
||||
void DataManager_LoadDefaults();
|
||||
int DataManager_ResetDefaults(void);
|
||||
void DataManager_LoadDefaults(void);
|
||||
int DataManager_LoadValues(const char* filename);
|
||||
int DataManager_Flush();
|
||||
int DataManager_Flush(void);
|
||||
const char* DataManager_GetStrValue(const char* varName);
|
||||
const char* DataManager_GetCurrentStoragePath();
|
||||
const char* DataManager_GetSettingsStoragePath();
|
||||
const char* DataManager_GetCurrentStoragePath(void);
|
||||
const char* DataManager_GetSettingsStoragePath(void);
|
||||
int DataManager_GetIntValue(const char* varName);
|
||||
|
||||
int DataManager_SetStrValue(const char* varName, char* value);
|
||||
@@ -32,8 +32,8 @@ int DataManager_SetFloatValue(const char* varName, float value);
|
||||
|
||||
int DataManager_ToggleIntValue(const char* varName);
|
||||
|
||||
void DataManager_DumpValues();
|
||||
void DataManager_ReadSettingsFile();
|
||||
void DataManager_DumpValues(void);
|
||||
void DataManager_ReadSettingsFile(void);
|
||||
|
||||
#endif // _DATA_HEADER
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -26,32 +26,32 @@ using namespace std;
|
||||
class DataManager
|
||||
{
|
||||
public:
|
||||
static int ResetDefaults();
|
||||
static int LoadValues(const string filename);
|
||||
static int Flush();
|
||||
static int ResetDefaults();
|
||||
static int LoadValues(const string filename);
|
||||
static int Flush();
|
||||
|
||||
// Core get routines
|
||||
static int GetValue(const string varName, string& value);
|
||||
static int GetValue(const string varName, int& value);
|
||||
// Core get routines
|
||||
static int GetValue(const string varName, string& value);
|
||||
static int GetValue(const string varName, int& value);
|
||||
static int GetValue(const string varName, float& value);
|
||||
static unsigned long long GetValue(const string varName, unsigned long long& value);
|
||||
static unsigned long long GetValue(const string varName, unsigned long long& value);
|
||||
|
||||
// This is a dangerous function. It will create the value if it doesn't exist so it has a valid c_str
|
||||
static string& GetValueRef(const string varName);
|
||||
// This is a dangerous function. It will create the value if it doesn't exist so it has a valid c_str
|
||||
static string& GetValueRef(const string varName);
|
||||
|
||||
// Helper functions
|
||||
static string GetStrValue(const string varName);
|
||||
static int GetIntValue(const string varName);
|
||||
// Helper functions
|
||||
static string GetStrValue(const string varName);
|
||||
static int GetIntValue(const string varName);
|
||||
|
||||
// Core set routines
|
||||
static int SetValue(const string varName, string value, int persist = 0);
|
||||
static int SetValue(const string varName, int value, int persist = 0);
|
||||
static int SetValue(const string varName, float value, int persist = 0);
|
||||
static int SetValue(const string varName, unsigned long long value, int persist = 0);
|
||||
// Core set routines
|
||||
static int SetValue(const string varName, string value, int persist = 0);
|
||||
static int SetValue(const string varName, int value, int persist = 0);
|
||||
static int SetValue(const string varName, float value, int persist = 0);
|
||||
static int SetValue(const string varName, unsigned long long value, int persist = 0);
|
||||
static int SetProgress(float Fraction);
|
||||
static int ShowProgress(float Portion, float Seconds);
|
||||
|
||||
static void DumpValues();
|
||||
static void DumpValues();
|
||||
static void update_tz_environment_variables();
|
||||
static void SetBackupFolder();
|
||||
static void SetDefaultValues();
|
||||
@@ -64,20 +64,20 @@ public:
|
||||
static string& CGetSettingsStoragePath();
|
||||
|
||||
protected:
|
||||
typedef pair<string, int> TStrIntPair;
|
||||
typedef pair<string, unsigned long long> TStrULLPair;
|
||||
typedef pair<string, TStrIntPair> TNameValuePair;
|
||||
static map<string, TStrIntPair> mValues;
|
||||
static map<string, TStrULLPair> mULLValues;
|
||||
static string mBackingFile;
|
||||
static int mInitialized;
|
||||
typedef pair<string, int> TStrIntPair;
|
||||
typedef pair<string, unsigned long long> TStrULLPair;
|
||||
typedef pair<string, TStrIntPair> TNameValuePair;
|
||||
static map<string, TStrIntPair> mValues;
|
||||
static map<string, TStrULLPair> mULLValues;
|
||||
static string mBackingFile;
|
||||
static int mInitialized;
|
||||
|
||||
static map<string, string> mConstValues;
|
||||
static map<string, string> mConstValues;
|
||||
|
||||
protected:
|
||||
static int SaveValues();
|
||||
static int SaveValues();
|
||||
|
||||
static int GetMagicValue(string varName, string& value);
|
||||
static int GetMagicValue(string varName, string& value);
|
||||
|
||||
private:
|
||||
static void sanitize_device_id(char* device_id);
|
||||
|
||||
+238
-238
@@ -64,72 +64,72 @@ extern blanktimer blankTimer;
|
||||
void curtainClose(void);
|
||||
|
||||
GUIAction::GUIAction(xml_node<>* node)
|
||||
: Conditional(node)
|
||||
: Conditional(node)
|
||||
{
|
||||
xml_node<>* child;
|
||||
xml_node<>* actions;
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
xml_node<>* actions;
|
||||
xml_attribute<>* attr;
|
||||
|
||||
mKey = 0;
|
||||
mKey = 0;
|
||||
|
||||
if (!node) return;
|
||||
if (!node) return;
|
||||
|
||||
// First, get the action
|
||||
actions = node->first_node("actions");
|
||||
if (actions) child = actions->first_node("action");
|
||||
else child = node->first_node("action");
|
||||
// First, get the action
|
||||
actions = node->first_node("actions");
|
||||
if (actions) child = actions->first_node("action");
|
||||
else child = node->first_node("action");
|
||||
|
||||
if (!child) return;
|
||||
if (!child) return;
|
||||
|
||||
while (child)
|
||||
{
|
||||
Action action;
|
||||
while (child)
|
||||
{
|
||||
Action action;
|
||||
|
||||
attr = child->first_attribute("function");
|
||||
if (!attr) return;
|
||||
|
||||
action.mFunction = attr->value();
|
||||
action.mArg = child->value();
|
||||
mActions.push_back(action);
|
||||
attr = child->first_attribute("function");
|
||||
if (!attr) return;
|
||||
|
||||
action.mFunction = attr->value();
|
||||
action.mArg = child->value();
|
||||
mActions.push_back(action);
|
||||
|
||||
child = child->next_sibling("action");
|
||||
}
|
||||
child = child->next_sibling("action");
|
||||
}
|
||||
|
||||
// Now, let's get either the key or region
|
||||
child = node->first_node("touch");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("key");
|
||||
if (attr)
|
||||
{
|
||||
std::string key = attr->value();
|
||||
|
||||
mKey = getKeyByName(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
attr = child->first_attribute("x");
|
||||
if (!attr) return;
|
||||
mActionX = atol(attr->value());
|
||||
attr = child->first_attribute("y");
|
||||
if (!attr) return;
|
||||
mActionY = atol(attr->value());
|
||||
attr = child->first_attribute("w");
|
||||
if (!attr) return;
|
||||
mActionW = atol(attr->value());
|
||||
attr = child->first_attribute("h");
|
||||
if (!attr) return;
|
||||
mActionH = atol(attr->value());
|
||||
}
|
||||
}
|
||||
// Now, let's get either the key or region
|
||||
child = node->first_node("touch");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("key");
|
||||
if (attr)
|
||||
{
|
||||
std::string key = attr->value();
|
||||
|
||||
mKey = getKeyByName(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
attr = child->first_attribute("x");
|
||||
if (!attr) return;
|
||||
mActionX = atol(attr->value());
|
||||
attr = child->first_attribute("y");
|
||||
if (!attr) return;
|
||||
mActionY = atol(attr->value());
|
||||
attr = child->first_attribute("w");
|
||||
if (!attr) return;
|
||||
mActionW = atol(attr->value());
|
||||
attr = child->first_attribute("h");
|
||||
if (!attr) return;
|
||||
mActionH = atol(attr->value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int GUIAction::NotifyTouch(TOUCH_STATE state, int x, int y)
|
||||
{
|
||||
if (state == TOUCH_RELEASE)
|
||||
doActions();
|
||||
if (state == TOUCH_RELEASE)
|
||||
doActions();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GUIAction::NotifyKey(int key)
|
||||
@@ -143,17 +143,17 @@ int GUIAction::NotifyKey(int key)
|
||||
|
||||
int GUIAction::NotifyVarChange(std::string varName, std::string value)
|
||||
{
|
||||
if (varName.empty() && !isConditionValid() && !mKey && !mActionW)
|
||||
doActions();
|
||||
if (varName.empty() && !isConditionValid() && !mKey && !mActionW)
|
||||
doActions();
|
||||
|
||||
// This handles notifying the condition system of page start
|
||||
if (varName.empty() && isConditionValid())
|
||||
NotifyPageSet();
|
||||
// This handles notifying the condition system of page start
|
||||
if (varName.empty() && isConditionValid())
|
||||
NotifyPageSet();
|
||||
|
||||
if ((varName.empty() || IsConditionVariable(varName)) && isConditionValid() && isConditionTrue())
|
||||
doActions();
|
||||
if ((varName.empty() || IsConditionVariable(varName)) && isConditionValid() && isConditionTrue())
|
||||
doActions();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void GUIAction::simulate_progress_bar(void)
|
||||
@@ -168,54 +168,54 @@ void GUIAction::simulate_progress_bar(void)
|
||||
|
||||
int GUIAction::flash_zip(std::string filename, std::string pageName, const int simulate, int* wipe_cache)
|
||||
{
|
||||
int ret_val = 0;
|
||||
int ret_val = 0;
|
||||
|
||||
DataManager::SetValue("ui_progress", 0);
|
||||
|
||||
if (filename.empty())
|
||||
{
|
||||
LOGERR("No file specified.\n");
|
||||
return -1;
|
||||
}
|
||||
if (filename.empty())
|
||||
{
|
||||
LOGERR("No file specified.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// We're going to jump to this page first, like a loading page
|
||||
gui_changePage(pageName);
|
||||
// We're going to jump to this page first, like a loading page
|
||||
gui_changePage(pageName);
|
||||
|
||||
int fd = -1;
|
||||
ZipArchive zip;
|
||||
int fd = -1;
|
||||
ZipArchive zip;
|
||||
|
||||
if (!PartitionManager.Mount_By_Path(filename, true))
|
||||
if (!PartitionManager.Mount_By_Path(filename, true))
|
||||
return -1;
|
||||
|
||||
if (mzOpenZipArchive(filename.c_str(), &zip))
|
||||
{
|
||||
LOGERR("Unable to open zip file.\n");
|
||||
return -1;
|
||||
}
|
||||
{
|
||||
LOGERR("Unable to open zip file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check the zip to see if it has a custom installer theme
|
||||
// Check the zip to see if it has a custom installer theme
|
||||
const ZipEntry* twrp = mzFindZipEntry(&zip, "META-INF/teamwin/twrp.zip");
|
||||
if (twrp != NULL)
|
||||
{
|
||||
unlink("/tmp/twrp.zip");
|
||||
fd = creat("/tmp/twrp.zip", 0666);
|
||||
}
|
||||
if (fd >= 0 && twrp != NULL &&
|
||||
mzExtractZipEntryToFile(&zip, twrp, fd) &&
|
||||
!PageManager::LoadPackage("install", "/tmp/twrp.zip", "main"))
|
||||
{
|
||||
mzCloseZipArchive(&zip);
|
||||
if (twrp != NULL)
|
||||
{
|
||||
unlink("/tmp/twrp.zip");
|
||||
fd = creat("/tmp/twrp.zip", 0666);
|
||||
}
|
||||
if (fd >= 0 && twrp != NULL &&
|
||||
mzExtractZipEntryToFile(&zip, twrp, fd) &&
|
||||
!PageManager::LoadPackage("install", "/tmp/twrp.zip", "main"))
|
||||
{
|
||||
mzCloseZipArchive(&zip);
|
||||
PageManager::SelectPackage("install");
|
||||
gui_changePage("main");
|
||||
}
|
||||
else
|
||||
{
|
||||
// In this case, we just use the default page
|
||||
mzCloseZipArchive(&zip);
|
||||
gui_changePage("main");
|
||||
}
|
||||
else
|
||||
{
|
||||
// In this case, we just use the default page
|
||||
mzCloseZipArchive(&zip);
|
||||
gui_changePage(pageName);
|
||||
}
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
}
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
|
||||
if (simulate) {
|
||||
simulate_progress_bar();
|
||||
@@ -237,20 +237,20 @@ int GUIAction::flash_zip(std::string filename, std::string pageName, const int s
|
||||
}
|
||||
}
|
||||
|
||||
// Done
|
||||
DataManager::SetValue("ui_progress", 100);
|
||||
DataManager::SetValue("ui_progress", 0);
|
||||
return ret_val;
|
||||
// Done
|
||||
DataManager::SetValue("ui_progress", 100);
|
||||
DataManager::SetValue("ui_progress", 0);
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
int GUIAction::doActions()
|
||||
{
|
||||
if (mActions.size() < 1) return -1;
|
||||
if (mActions.size() == 1)
|
||||
if (mActions.size() < 1) return -1;
|
||||
if (mActions.size() == 1)
|
||||
return doAction(mActions.at(0), 0);
|
||||
|
||||
// For multi-action, we always use a thread
|
||||
pthread_t t;
|
||||
// For multi-action, we always use a thread
|
||||
pthread_t t;
|
||||
pthread_attr_t tattr;
|
||||
|
||||
if (pthread_attr_init(&tattr)) {
|
||||
@@ -271,7 +271,7 @@ int GUIAction::doActions()
|
||||
}
|
||||
*/
|
||||
int ret = pthread_create(&t, &tattr, thread_start, this);
|
||||
if (ret) {
|
||||
if (ret) {
|
||||
LOGERR("Unable to create more threads for actions... continuing in same thread! %i\n", ret);
|
||||
thread_start(this);
|
||||
} else {
|
||||
@@ -284,30 +284,30 @@ int GUIAction::doActions()
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* GUIAction::thread_start(void *cookie)
|
||||
{
|
||||
GUIAction* ourThis = (GUIAction*) cookie;
|
||||
GUIAction* ourThis = (GUIAction*) cookie;
|
||||
|
||||
DataManager::SetValue(TW_ACTION_BUSY, 1);
|
||||
|
||||
if (ourThis->mActions.size() > 1)
|
||||
{
|
||||
std::vector<Action>::iterator iter;
|
||||
for (iter = ourThis->mActions.begin(); iter != ourThis->mActions.end(); iter++)
|
||||
ourThis->doAction(*iter, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ourThis->doAction(ourThis->mActions.at(0), 1);
|
||||
}
|
||||
if (ourThis->mActions.size() > 1)
|
||||
{
|
||||
std::vector<Action>::iterator iter;
|
||||
for (iter = ourThis->mActions.begin(); iter != ourThis->mActions.end(); iter++)
|
||||
ourThis->doAction(*iter, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ourThis->doAction(ourThis->mActions.at(0), 1);
|
||||
}
|
||||
int check = 0;
|
||||
DataManager::GetValue("tw_background_thread_running", check);
|
||||
if (check == 0)
|
||||
DataManager::SetValue(TW_ACTION_BUSY, 0);
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void GUIAction::operation_start(const string operation_name)
|
||||
@@ -357,7 +357,7 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
|
||||
|
||||
if (function == "reboot")
|
||||
{
|
||||
//curtainClose(); this sometimes causes a crash
|
||||
//curtainClose(); this sometimes causes a crash
|
||||
|
||||
sync();
|
||||
DataManager::SetValue("tw_gui_done", 1);
|
||||
@@ -365,25 +365,25 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
|
||||
|
||||
return 0;
|
||||
}
|
||||
if (function == "home")
|
||||
{
|
||||
PageManager::SelectPackage("TWRP");
|
||||
gui_changePage("main");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (function == "key")
|
||||
{
|
||||
PageManager::NotifyKey(getKeyByName(arg));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (function == "page") {
|
||||
std::string page_name = gui_parse_text(arg);
|
||||
return gui_changePage(page_name);
|
||||
if (function == "home")
|
||||
{
|
||||
PageManager::SelectPackage("TWRP");
|
||||
gui_changePage("main");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (function == "reload") {
|
||||
if (function == "key")
|
||||
{
|
||||
PageManager::NotifyKey(getKeyByName(arg));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (function == "page") {
|
||||
std::string page_name = gui_parse_text(arg);
|
||||
return gui_changePage(page_name);
|
||||
}
|
||||
|
||||
if (function == "reload") {
|
||||
int check = 0, ret_val = 0;
|
||||
std::string theme_path;
|
||||
|
||||
@@ -405,85 +405,85 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
|
||||
ret_val = 1;
|
||||
}
|
||||
}
|
||||
operation_end(ret_val, simulate);
|
||||
operation_end(ret_val, simulate);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (function == "readBackup")
|
||||
{
|
||||
if (function == "readBackup")
|
||||
{
|
||||
string Restore_Name;
|
||||
DataManager::GetValue("tw_restore", Restore_Name);
|
||||
PartitionManager.Set_Restore_Files(Restore_Name);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (function == "set")
|
||||
{
|
||||
if (arg.find('=') != string::npos)
|
||||
{
|
||||
string varName = arg.substr(0, arg.find('='));
|
||||
string value = arg.substr(arg.find('=') + 1, string::npos);
|
||||
if (function == "set")
|
||||
{
|
||||
if (arg.find('=') != string::npos)
|
||||
{
|
||||
string varName = arg.substr(0, arg.find('='));
|
||||
string value = arg.substr(arg.find('=') + 1, string::npos);
|
||||
|
||||
DataManager::GetValue(value, value);
|
||||
DataManager::SetValue(varName, value);
|
||||
}
|
||||
else
|
||||
DataManager::SetValue(arg, "1");
|
||||
return 0;
|
||||
}
|
||||
if (function == "clear")
|
||||
{
|
||||
DataManager::SetValue(arg, "0");
|
||||
return 0;
|
||||
}
|
||||
DataManager::GetValue(value, value);
|
||||
DataManager::SetValue(varName, value);
|
||||
}
|
||||
else
|
||||
DataManager::SetValue(arg, "1");
|
||||
return 0;
|
||||
}
|
||||
if (function == "clear")
|
||||
{
|
||||
DataManager::SetValue(arg, "0");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (function == "mount")
|
||||
{
|
||||
if (arg == "usb")
|
||||
{
|
||||
DataManager::SetValue(TW_ACTION_BUSY, 1);
|
||||
if (function == "mount")
|
||||
{
|
||||
if (arg == "usb")
|
||||
{
|
||||
DataManager::SetValue(TW_ACTION_BUSY, 1);
|
||||
if (!simulate)
|
||||
PartitionManager.usb_storage_enable();
|
||||
else
|
||||
gui_print("Simulating actions...\n");
|
||||
}
|
||||
else if (!simulate)
|
||||
{
|
||||
string cmd;
|
||||
}
|
||||
else if (!simulate)
|
||||
{
|
||||
string cmd;
|
||||
if (arg == "EXTERNAL")
|
||||
PartitionManager.Mount_By_Path(DataManager::GetStrValue(TW_EXTERNAL_MOUNT), true);
|
||||
else if (arg == "INTERNAL")
|
||||
PartitionManager.Mount_By_Path(DataManager::GetStrValue(TW_INTERNAL_MOUNT), true);
|
||||
else
|
||||
PartitionManager.Mount_By_Path(arg, true);
|
||||
} else
|
||||
} else
|
||||
gui_print("Simulating actions...\n");
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (function == "umount" || function == "unmount")
|
||||
{
|
||||
if (arg == "usb")
|
||||
{
|
||||
if (!simulate)
|
||||
if (function == "umount" || function == "unmount")
|
||||
{
|
||||
if (arg == "usb")
|
||||
{
|
||||
if (!simulate)
|
||||
PartitionManager.usb_storage_disable();
|
||||
else
|
||||
gui_print("Simulating actions...\n");
|
||||
DataManager::SetValue(TW_ACTION_BUSY, 0);
|
||||
}
|
||||
else if (!simulate)
|
||||
{
|
||||
string cmd;
|
||||
}
|
||||
else if (!simulate)
|
||||
{
|
||||
string cmd;
|
||||
if (arg == "EXTERNAL")
|
||||
PartitionManager.UnMount_By_Path(DataManager::GetStrValue(TW_EXTERNAL_MOUNT), true);
|
||||
else if (arg == "INTERNAL")
|
||||
PartitionManager.UnMount_By_Path(DataManager::GetStrValue(TW_INTERNAL_MOUNT), true);
|
||||
else
|
||||
PartitionManager.UnMount_By_Path(arg, true);
|
||||
} else
|
||||
} else
|
||||
gui_print("Simulating actions...\n");
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (function == "restoredefaultsettings")
|
||||
{
|
||||
@@ -519,20 +519,20 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
|
||||
if (function == "compute" || function == "addsubtract")
|
||||
{
|
||||
if (arg.find("+") != string::npos)
|
||||
{
|
||||
string varName = arg.substr(0, arg.find('+'));
|
||||
string string_to_add = arg.substr(arg.find('+') + 1, string::npos);
|
||||
{
|
||||
string varName = arg.substr(0, arg.find('+'));
|
||||
string string_to_add = arg.substr(arg.find('+') + 1, string::npos);
|
||||
int amount_to_add = atoi(string_to_add.c_str());
|
||||
int value;
|
||||
|
||||
DataManager::GetValue(varName, value);
|
||||
DataManager::SetValue(varName, value + amount_to_add);
|
||||
DataManager::SetValue(varName, value + amount_to_add);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (arg.find("-") != string::npos)
|
||||
{
|
||||
string varName = arg.substr(0, arg.find('-'));
|
||||
string string_to_subtract = arg.substr(arg.find('-') + 1, string::npos);
|
||||
{
|
||||
string varName = arg.substr(0, arg.find('-'));
|
||||
string string_to_subtract = arg.substr(arg.find('-') + 1, string::npos);
|
||||
int amount_to_subtract = atoi(string_to_subtract.c_str());
|
||||
int value;
|
||||
|
||||
@@ -540,9 +540,9 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
|
||||
value -= amount_to_subtract;
|
||||
if (value <= 0)
|
||||
value = 0;
|
||||
DataManager::SetValue(varName, value);
|
||||
DataManager::SetValue(varName, value);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (arg.find("*") != string::npos)
|
||||
{
|
||||
string varName = arg.substr(0, arg.find('*'));
|
||||
@@ -653,11 +653,11 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
|
||||
}
|
||||
|
||||
if (function == "overlay")
|
||||
return gui_changeOverlay(arg);
|
||||
return gui_changeOverlay(arg);
|
||||
|
||||
if (function == "queuezip")
|
||||
{
|
||||
if (zip_queue_index >= 10) {
|
||||
{
|
||||
if (zip_queue_index >= 10) {
|
||||
gui_print("Maximum zip queue reached!\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -670,8 +670,8 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
|
||||
}
|
||||
|
||||
if (function == "cancelzip")
|
||||
{
|
||||
if (zip_queue_index <= 0) {
|
||||
{
|
||||
if (zip_queue_index <= 0) {
|
||||
gui_print("Minimum zip queue reached!\n");
|
||||
return 0;
|
||||
} else {
|
||||
@@ -696,9 +696,9 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (isThreaded)
|
||||
{
|
||||
if (function == "fileexists")
|
||||
if (isThreaded)
|
||||
{
|
||||
if (function == "fileexists")
|
||||
{
|
||||
struct stat st;
|
||||
string newpath = arg + "/.";
|
||||
@@ -712,13 +712,13 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
|
||||
}
|
||||
|
||||
if (function == "flash")
|
||||
{
|
||||
{
|
||||
int i, ret_val = 0, wipe_cache = 0;
|
||||
|
||||
for (i=0; i<zip_queue_index; i++) {
|
||||
operation_start("Flashing");
|
||||
DataManager::SetValue("tw_filename", zip_queue[i]);
|
||||
DataManager::SetValue(TW_ZIP_INDEX, (i + 1));
|
||||
DataManager::SetValue("tw_filename", zip_queue[i]);
|
||||
DataManager::SetValue(TW_ZIP_INDEX, (i + 1));
|
||||
|
||||
ret_val = flash_zip(zip_queue[i], arg, simulate, &wipe_cache);
|
||||
if (ret_val != 0) {
|
||||
@@ -751,12 +751,12 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
|
||||
}
|
||||
PartitionManager.Update_System_Details();
|
||||
operation_end(ret_val, simulate);
|
||||
return 0;
|
||||
}
|
||||
if (function == "wipe")
|
||||
{
|
||||
operation_start("Format");
|
||||
DataManager::SetValue("tw_partition", arg);
|
||||
return 0;
|
||||
}
|
||||
if (function == "wipe")
|
||||
{
|
||||
operation_start("Format");
|
||||
DataManager::SetValue("tw_partition", arg);
|
||||
|
||||
int ret_val = false;
|
||||
|
||||
@@ -863,9 +863,9 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
|
||||
ret_val = 0; // 0 is success
|
||||
else
|
||||
ret_val = 1; // 1 is failure
|
||||
operation_end(ret_val, simulate);
|
||||
return 0;
|
||||
}
|
||||
operation_end(ret_val, simulate);
|
||||
return 0;
|
||||
}
|
||||
if (function == "refreshsizes")
|
||||
{
|
||||
operation_start("Refreshing Sizes");
|
||||
@@ -876,9 +876,9 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
|
||||
operation_end(0, simulate);
|
||||
return 0;
|
||||
}
|
||||
if (function == "nandroid")
|
||||
{
|
||||
operation_start("Nandroid");
|
||||
if (function == "nandroid")
|
||||
{
|
||||
operation_start("Nandroid");
|
||||
int ret = 0;
|
||||
|
||||
if (simulate) {
|
||||
@@ -910,13 +910,13 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
|
||||
ret = 1; // 1 for failure
|
||||
else
|
||||
ret = 0; // 0 for success
|
||||
operation_end(ret, simulate);
|
||||
operation_end(ret, simulate);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (function == "fixpermissions")
|
||||
{
|
||||
operation_start("Fix Permissions");
|
||||
LOGINFO("fix permissions started!\n");
|
||||
LOGINFO("fix permissions started!\n");
|
||||
if (simulate) {
|
||||
simulate_progress_bar();
|
||||
} else {
|
||||
@@ -927,9 +927,9 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (function == "dd")
|
||||
{
|
||||
operation_start("imaging");
|
||||
if (function == "dd")
|
||||
{
|
||||
operation_start("imaging");
|
||||
|
||||
if (simulate) {
|
||||
simulate_progress_bar();
|
||||
@@ -938,9 +938,9 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
|
||||
string cmd = "dd " + arg;
|
||||
TWFunc::Exec_Cmd(cmd, result);
|
||||
}
|
||||
operation_end(0, simulate);
|
||||
return 0;
|
||||
}
|
||||
operation_end(0, simulate);
|
||||
return 0;
|
||||
}
|
||||
if (function == "partitionsd")
|
||||
{
|
||||
operation_start("Partition SD Card");
|
||||
@@ -1292,26 +1292,26 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
|
||||
operation_end(op_status, simulate);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
pthread_t t;
|
||||
pthread_create(&t, NULL, thread_start, this);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
LOGERR("Unknown action '%s'\n", function.c_str());
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int GUIAction::getKeyByName(std::string key)
|
||||
{
|
||||
if (key == "home") return KEY_HOME;
|
||||
else if (key == "menu") return KEY_MENU;
|
||||
else if (key == "back") return KEY_BACK;
|
||||
else if (key == "search") return KEY_SEARCH;
|
||||
else if (key == "voldown") return KEY_VOLUMEDOWN;
|
||||
else if (key == "volup") return KEY_VOLUMEUP;
|
||||
else if (key == "power") {
|
||||
if (key == "home") return KEY_HOME;
|
||||
else if (key == "menu") return KEY_MENU;
|
||||
else if (key == "back") return KEY_BACK;
|
||||
else if (key == "search") return KEY_SEARCH;
|
||||
else if (key == "voldown") return KEY_VOLUMEDOWN;
|
||||
else if (key == "volup") return KEY_VOLUMEUP;
|
||||
else if (key == "power") {
|
||||
int ret_val;
|
||||
DataManager::GetValue(TW_POWER_BUTTON, ret_val);
|
||||
if (!ret_val)
|
||||
@@ -1320,7 +1320,7 @@ int GUIAction::getKeyByName(std::string key)
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
return atol(key.c_str());
|
||||
return atol(key.c_str());
|
||||
}
|
||||
|
||||
void* GUIAction::command_thread(void *cookie)
|
||||
|
||||
+85
-85
@@ -28,109 +28,109 @@ extern "C" {
|
||||
|
||||
GUIAnimation::GUIAnimation(xml_node<>* node)
|
||||
{
|
||||
xml_node<>* child;
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
xml_attribute<>* attr;
|
||||
|
||||
mAnimation = NULL;
|
||||
mFrame = 1;
|
||||
mFPS = 1;
|
||||
mLoop = -1;
|
||||
mRender = 1;
|
||||
mUpdateCount = 0;
|
||||
mAnimation = NULL;
|
||||
mFrame = 1;
|
||||
mFPS = 1;
|
||||
mLoop = -1;
|
||||
mRender = 1;
|
||||
mUpdateCount = 0;
|
||||
|
||||
if (!node) return;
|
||||
if (!node) return;
|
||||
|
||||
child = node->first_node("resource");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("name");
|
||||
if (attr)
|
||||
mAnimation = (AnimationResource*) PageManager::FindResource(attr->value());
|
||||
}
|
||||
child = node->first_node("resource");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("name");
|
||||
if (attr)
|
||||
mAnimation = (AnimationResource*) PageManager::FindResource(attr->value());
|
||||
}
|
||||
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement);
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement);
|
||||
|
||||
child = node->first_node("speed");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("fps");
|
||||
if (attr)
|
||||
mFPS = atoi(attr->value());
|
||||
attr = child->first_attribute("render");
|
||||
if (attr)
|
||||
mRender = atoi(attr->value());
|
||||
}
|
||||
if (mFPS > 30) mFPS = 30;
|
||||
child = node->first_node("speed");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("fps");
|
||||
if (attr)
|
||||
mFPS = atoi(attr->value());
|
||||
attr = child->first_attribute("render");
|
||||
if (attr)
|
||||
mRender = atoi(attr->value());
|
||||
}
|
||||
if (mFPS > 30) mFPS = 30;
|
||||
|
||||
child = node->first_node("loop");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("frame");
|
||||
if (attr)
|
||||
mLoop = atoi(attr->value()) - 1;
|
||||
attr = child->first_attribute("start");
|
||||
if (attr)
|
||||
mFrame = atoi(attr->value());
|
||||
}
|
||||
child = node->first_node("loop");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("frame");
|
||||
if (attr)
|
||||
mLoop = atoi(attr->value()) - 1;
|
||||
attr = child->first_attribute("start");
|
||||
if (attr)
|
||||
mFrame = atoi(attr->value());
|
||||
}
|
||||
|
||||
// Fetch the render sizes
|
||||
if (mAnimation && mAnimation->GetResource())
|
||||
{
|
||||
mRenderW = gr_get_width(mAnimation->GetResource());
|
||||
mRenderH = gr_get_height(mAnimation->GetResource());
|
||||
// Fetch the render sizes
|
||||
if (mAnimation && mAnimation->GetResource())
|
||||
{
|
||||
mRenderW = gr_get_width(mAnimation->GetResource());
|
||||
mRenderH = gr_get_height(mAnimation->GetResource());
|
||||
|
||||
// Adjust for placement
|
||||
if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT)
|
||||
{
|
||||
if (mPlacement == CENTER)
|
||||
mRenderX -= (mRenderW / 2);
|
||||
else
|
||||
mRenderX -= mRenderW;
|
||||
}
|
||||
if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT)
|
||||
{
|
||||
if (mPlacement == CENTER)
|
||||
mRenderY -= (mRenderH / 2);
|
||||
else
|
||||
mRenderY -= mRenderH;
|
||||
}
|
||||
SetPlacement(TOP_LEFT);
|
||||
}
|
||||
// Adjust for placement
|
||||
if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT)
|
||||
{
|
||||
if (mPlacement == CENTER)
|
||||
mRenderX -= (mRenderW / 2);
|
||||
else
|
||||
mRenderX -= mRenderW;
|
||||
}
|
||||
if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT)
|
||||
{
|
||||
if (mPlacement == CENTER)
|
||||
mRenderY -= (mRenderH / 2);
|
||||
else
|
||||
mRenderY -= mRenderH;
|
||||
}
|
||||
SetPlacement(TOP_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
int GUIAnimation::Render(void)
|
||||
{
|
||||
if (!mAnimation || !mAnimation->GetResource(mFrame)) return -1;
|
||||
if (!mAnimation || !mAnimation->GetResource(mFrame)) return -1;
|
||||
|
||||
gr_blit(mAnimation->GetResource(mFrame), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
|
||||
return 0;
|
||||
gr_blit(mAnimation->GetResource(mFrame), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GUIAnimation::Update(void)
|
||||
{
|
||||
if (!mAnimation) return -1;
|
||||
if (!mAnimation) return -1;
|
||||
|
||||
// Handle the "end-of-animation" state
|
||||
if (mLoop == -2) return 0;
|
||||
// Handle the "end-of-animation" state
|
||||
if (mLoop == -2) return 0;
|
||||
|
||||
// Determine if we need the next frame yet...
|
||||
if (++mUpdateCount > 30 / mFPS)
|
||||
{
|
||||
mUpdateCount = 0;
|
||||
if (++mFrame >= mAnimation->GetResourceCount())
|
||||
{
|
||||
if (mLoop < 0)
|
||||
{
|
||||
mFrame = mAnimation->GetResourceCount() - 1;
|
||||
mLoop = -2;
|
||||
}
|
||||
else
|
||||
mFrame = mLoop;
|
||||
}
|
||||
if (mRender == 2) return 2;
|
||||
return (Render() == 0 ? 1 : -1);
|
||||
}
|
||||
return 0;
|
||||
// Determine if we need the next frame yet...
|
||||
if (++mUpdateCount > 30 / mFPS)
|
||||
{
|
||||
mUpdateCount = 0;
|
||||
if (++mFrame >= mAnimation->GetResourceCount())
|
||||
{
|
||||
if (mLoop < 0)
|
||||
{
|
||||
mFrame = mAnimation->GetResourceCount() - 1;
|
||||
mLoop = -2;
|
||||
}
|
||||
else
|
||||
mFrame = mLoop;
|
||||
}
|
||||
if (mRender == 2) return 2;
|
||||
return (Render() == 0 ? 1 : -1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+28
-24
@@ -24,31 +24,35 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class blanktimer {
|
||||
public:
|
||||
blanktimer(void);
|
||||
int setTimerThread(void);
|
||||
void resetTimerAndUnblank(void);
|
||||
void setTime(int newtime);
|
||||
bool IsScreenOff();
|
||||
class blanktimer
|
||||
{
|
||||
public:
|
||||
blanktimer(void);
|
||||
|
||||
private:
|
||||
void setConBlank(int blank);
|
||||
void setTimer(void);
|
||||
timespec getTimer(void);
|
||||
int getBrightness(void);
|
||||
int setBrightness(int brightness);
|
||||
int setBlankTimer(void);
|
||||
int setClockTimer(void);
|
||||
typedef int (blanktimer::*ThreadPtr)(void);
|
||||
typedef void* (*PThreadPtr)(void*);
|
||||
pthread_mutex_t conblankmutex;
|
||||
pthread_mutex_t timermutex;
|
||||
int conblank;
|
||||
timespec btimer;
|
||||
unsigned long long sleepTimer;
|
||||
int orig_brightness;
|
||||
bool screenoff;
|
||||
int setTimerThread(void);
|
||||
void resetTimerAndUnblank(void);
|
||||
void setTime(int newtime);
|
||||
bool IsScreenOff();
|
||||
|
||||
private:
|
||||
typedef int (blanktimer::*ThreadPtr)(void);
|
||||
typedef void* (*PThreadPtr)(void*);
|
||||
|
||||
void setConBlank(int blank);
|
||||
void setTimer(void);
|
||||
timespec getTimer(void);
|
||||
int getBrightness(void);
|
||||
int setBrightness(int brightness);
|
||||
int setBlankTimer(void);
|
||||
int setClockTimer(void);
|
||||
|
||||
pthread_mutex_t conblankmutex;
|
||||
pthread_mutex_t timermutex;
|
||||
int conblank;
|
||||
timespec btimer;
|
||||
unsigned long long sleepTimer;
|
||||
int orig_brightness;
|
||||
bool screenoff;
|
||||
};
|
||||
|
||||
extern blanktimer blankTimer;
|
||||
|
||||
+127
-128
@@ -42,42 +42,42 @@ extern "C" {
|
||||
#include "objects.hpp"
|
||||
|
||||
GUIButton::GUIButton(xml_node<>* node)
|
||||
: Conditional(node)
|
||||
: Conditional(node)
|
||||
{
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
|
||||
mButtonImg = NULL;
|
||||
mButtonIcon = NULL;
|
||||
mButtonLabel = NULL;
|
||||
mAction = NULL;
|
||||
mRendered = false;
|
||||
mButtonImg = NULL;
|
||||
mButtonIcon = NULL;
|
||||
mButtonLabel = NULL;
|
||||
mAction = NULL;
|
||||
mRendered = false;
|
||||
hasHighlightColor = false;
|
||||
renderHighlight = false;
|
||||
hasFill = false;
|
||||
|
||||
if (!node) return;
|
||||
if (!node) return;
|
||||
|
||||
// Three of the four can be loaded directly from the node
|
||||
mButtonImg = new GUIImage(node);
|
||||
mButtonLabel = new GUIText(node);
|
||||
mAction = new GUIAction(node);
|
||||
// Three of the four can be loaded directly from the node
|
||||
mButtonImg = new GUIImage(node);
|
||||
mButtonLabel = new GUIText(node);
|
||||
mAction = new GUIAction(node);
|
||||
|
||||
if (mButtonImg->Render() < 0)
|
||||
{
|
||||
delete mButtonImg;
|
||||
mButtonImg = NULL;
|
||||
}
|
||||
if (mButtonLabel->Render() < 0)
|
||||
{
|
||||
delete mButtonLabel;
|
||||
mButtonLabel = NULL;
|
||||
}
|
||||
if (mButtonImg->Render() < 0)
|
||||
{
|
||||
delete mButtonImg;
|
||||
mButtonImg = NULL;
|
||||
}
|
||||
if (mButtonLabel->Render() < 0)
|
||||
{
|
||||
delete mButtonLabel;
|
||||
mButtonLabel = NULL;
|
||||
}
|
||||
// Load fill if it exists
|
||||
memset(&mFillColor, 0, sizeof(COLOR));
|
||||
child = node->first_node("fill");
|
||||
if (child)
|
||||
{
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("color");
|
||||
if (attr) {
|
||||
hasFill = true;
|
||||
@@ -89,14 +89,14 @@ GUIButton::GUIButton(xml_node<>* node)
|
||||
LOGERR("No image resource or fill specified for button.\n");
|
||||
}
|
||||
|
||||
// The icon is a special case
|
||||
child = node->first_node("icon");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("resource");
|
||||
if (attr)
|
||||
mButtonIcon = PageManager::FindResource(attr->value());
|
||||
}
|
||||
// The icon is a special case
|
||||
child = node->first_node("icon");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("resource");
|
||||
if (attr)
|
||||
mButtonIcon = PageManager::FindResource(attr->value());
|
||||
}
|
||||
|
||||
memset(&mHighlightColor, 0, sizeof(COLOR));
|
||||
child = node->first_node("highlight");
|
||||
@@ -109,43 +109,43 @@ GUIButton::GUIButton(xml_node<>* node)
|
||||
}
|
||||
}
|
||||
|
||||
int x, y, w, h;
|
||||
if (mButtonImg) {
|
||||
int x, y, w, h;
|
||||
if (mButtonImg) {
|
||||
mButtonImg->GetRenderPos(x, y, w, h);
|
||||
} else if (hasFill) {
|
||||
LoadPlacement(node->first_node("placement"), &x, &y, &w, &h);
|
||||
}
|
||||
SetRenderPos(x, y, w, h);
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
GUIButton::~GUIButton()
|
||||
{
|
||||
if (mButtonImg) delete mButtonImg;
|
||||
if (mButtonLabel) delete mButtonLabel;
|
||||
if (mAction) delete mAction;
|
||||
if (mButtonIcon) delete mButtonIcon;
|
||||
if (mButtonImg) delete mButtonImg;
|
||||
if (mButtonLabel) delete mButtonLabel;
|
||||
if (mAction) delete mAction;
|
||||
if (mButtonIcon) delete mButtonIcon;
|
||||
}
|
||||
|
||||
int GUIButton::Render(void)
|
||||
{
|
||||
if (!isConditionTrue())
|
||||
{
|
||||
mRendered = false;
|
||||
return 0;
|
||||
}
|
||||
if (!isConditionTrue())
|
||||
{
|
||||
mRendered = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
int ret = 0;
|
||||
|
||||
if (mButtonImg) ret = mButtonImg->Render();
|
||||
if (ret < 0) return ret;
|
||||
if (mButtonImg) ret = mButtonImg->Render();
|
||||
if (ret < 0) return ret;
|
||||
if (hasFill) {
|
||||
gr_color(mFillColor.red, mFillColor.green, mFillColor.blue, mFillColor.alpha);
|
||||
gr_fill(mRenderX, mRenderY, mRenderW, mRenderH);
|
||||
}
|
||||
if (mButtonIcon && mButtonIcon->GetResource())
|
||||
gr_blit(mButtonIcon->GetResource(), 0, 0, mIconW, mIconH, mIconX, mIconY);
|
||||
if (mButtonLabel) {
|
||||
if (mButtonIcon && mButtonIcon->GetResource())
|
||||
gr_blit(mButtonIcon->GetResource(), 0, 0, mIconW, mIconH, mIconX, mIconY);
|
||||
if (mButtonLabel) {
|
||||
int w, h;
|
||||
mButtonLabel->GetCurrentBounds(w, h);
|
||||
if (w != mTextW) {
|
||||
@@ -163,109 +163,109 @@ int GUIButton::Render(void)
|
||||
mButtonLabel->SetRenderPos(mTextX, mTextY);
|
||||
}
|
||||
ret = mButtonLabel->Render();
|
||||
if (ret < 0) return ret;
|
||||
if (ret < 0) return ret;
|
||||
}
|
||||
if (renderHighlight && hasHighlightColor) {
|
||||
gr_color(mHighlightColor.red, mHighlightColor.green, mHighlightColor.blue, mHighlightColor.alpha);
|
||||
gr_fill(mRenderX, mRenderY, mRenderW, mRenderH);
|
||||
}
|
||||
mRendered = true;
|
||||
return ret;
|
||||
mRendered = true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int GUIButton::Update(void)
|
||||
{
|
||||
if (!isConditionTrue()) return (mRendered ? 2 : 0);
|
||||
if (!mRendered) return 2;
|
||||
if (!isConditionTrue()) return (mRendered ? 2 : 0);
|
||||
if (!mRendered) return 2;
|
||||
|
||||
int ret = 0, ret2 = 0;
|
||||
int ret = 0, ret2 = 0;
|
||||
|
||||
if (mButtonImg) ret = mButtonImg->Update();
|
||||
if (ret < 0) return ret;
|
||||
if (mButtonImg) ret = mButtonImg->Update();
|
||||
if (ret < 0) return ret;
|
||||
|
||||
if (ret == 0)
|
||||
{
|
||||
if (mButtonLabel) {
|
||||
if (ret == 0)
|
||||
{
|
||||
if (mButtonLabel) {
|
||||
ret2 = mButtonLabel->Update();
|
||||
if (ret2 < 0) return ret2;
|
||||
if (ret2 > ret) ret = ret2;
|
||||
if (ret2 < 0) return ret2;
|
||||
if (ret2 > ret) ret = ret2;
|
||||
}
|
||||
}
|
||||
else if (ret == 1)
|
||||
{
|
||||
// The button re-rendered, so everyone else is a render
|
||||
if (mButtonIcon && mButtonIcon->GetResource())
|
||||
gr_blit(mButtonIcon->GetResource(), 0, 0, mIconW, mIconH, mIconX, mIconY);
|
||||
if (mButtonLabel) ret = mButtonLabel->Render();
|
||||
if (ret < 0) return ret;
|
||||
ret = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Aparently, the button needs a background update
|
||||
ret = 2;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
else if (ret == 1)
|
||||
{
|
||||
// The button re-rendered, so everyone else is a render
|
||||
if (mButtonIcon && mButtonIcon->GetResource())
|
||||
gr_blit(mButtonIcon->GetResource(), 0, 0, mIconW, mIconH, mIconX, mIconY);
|
||||
if (mButtonLabel) ret = mButtonLabel->Render();
|
||||
if (ret < 0) return ret;
|
||||
ret = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Aparently, the button needs a background update
|
||||
ret = 2;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int GUIButton::SetRenderPos(int x, int y, int w, int h)
|
||||
{
|
||||
mRenderX = x;
|
||||
mRenderY = y;
|
||||
if (w || h)
|
||||
{
|
||||
mRenderW = w;
|
||||
mRenderH = h;
|
||||
}
|
||||
mRenderX = x;
|
||||
mRenderY = y;
|
||||
if (w || h)
|
||||
{
|
||||
mRenderW = w;
|
||||
mRenderH = h;
|
||||
}
|
||||
|
||||
mIconW = 0; mIconH = 0;
|
||||
if (mButtonIcon && mButtonIcon->GetResource())
|
||||
{
|
||||
mIconW = gr_get_width(mButtonIcon->GetResource());
|
||||
mIconH = gr_get_height(mButtonIcon->GetResource());
|
||||
}
|
||||
mIconW = 0; mIconH = 0;
|
||||
if (mButtonIcon && mButtonIcon->GetResource())
|
||||
{
|
||||
mIconW = gr_get_width(mButtonIcon->GetResource());
|
||||
mIconH = gr_get_height(mButtonIcon->GetResource());
|
||||
}
|
||||
|
||||
mTextH = 0;
|
||||
mTextW = 0;
|
||||
mIconX = mRenderX + ((mRenderW - mIconW) / 2);
|
||||
if (mButtonLabel) mButtonLabel->GetCurrentBounds(mTextW, mTextH);
|
||||
if (mTextW)
|
||||
{
|
||||
// As a special case, we'll allow large text which automatically moves it to the right.
|
||||
if (mTextW > mRenderW)
|
||||
{
|
||||
mTextX = mRenderW + mRenderX + 5;
|
||||
mRenderW += mTextW + 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
mTextX = mRenderX + ((mRenderW - mTextW) / 2);
|
||||
}
|
||||
}
|
||||
mTextH = 0;
|
||||
mTextW = 0;
|
||||
mIconX = mRenderX + ((mRenderW - mIconW) / 2);
|
||||
if (mButtonLabel) mButtonLabel->GetCurrentBounds(mTextW, mTextH);
|
||||
if (mTextW)
|
||||
{
|
||||
// As a special case, we'll allow large text which automatically moves it to the right.
|
||||
if (mTextW > mRenderW)
|
||||
{
|
||||
mTextX = mRenderW + mRenderX + 5;
|
||||
mRenderW += mTextW + 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
mTextX = mRenderX + ((mRenderW - mTextW) / 2);
|
||||
}
|
||||
}
|
||||
|
||||
if (mIconH == 0 || mTextH == 0 || mIconH + mTextH > mRenderH)
|
||||
{
|
||||
mIconY = mRenderY + (mRenderH / 2) - (mIconH / 2);
|
||||
mTextY = mRenderY + (mRenderH / 2) - (mTextH / 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
int divisor = mRenderH - (mIconH + mTextH);
|
||||
mIconY = mRenderY + (divisor / 3);
|
||||
mTextY = mRenderY + (divisor * 2 / 3) + mIconH;
|
||||
}
|
||||
if (mIconH == 0 || mTextH == 0 || mIconH + mTextH > mRenderH)
|
||||
{
|
||||
mIconY = mRenderY + (mRenderH / 2) - (mIconH / 2);
|
||||
mTextY = mRenderY + (mRenderH / 2) - (mTextH / 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
int divisor = mRenderH - (mIconH + mTextH);
|
||||
mIconY = mRenderY + (divisor / 3);
|
||||
mTextY = mRenderY + (divisor * 2 / 3) + mIconH;
|
||||
}
|
||||
|
||||
if (mButtonLabel) mButtonLabel->SetRenderPos(mTextX, mTextY);
|
||||
if (mAction) mAction->SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
|
||||
SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
|
||||
return 0;
|
||||
if (mButtonLabel) mButtonLabel->SetRenderPos(mTextX, mTextY);
|
||||
if (mAction) mAction->SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
|
||||
SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GUIButton::NotifyTouch(TOUCH_STATE state, int x, int y)
|
||||
{
|
||||
static int last_state = 0;
|
||||
|
||||
if (!isConditionTrue()) return -1;
|
||||
if (!isConditionTrue()) return -1;
|
||||
if (x < mRenderX || x - mRenderX > mRenderW || y < mRenderY || y - mRenderY > mRenderH || state == TOUCH_RELEASE) {
|
||||
if (last_state == 1) {
|
||||
last_state = 0;
|
||||
@@ -289,6 +289,5 @@ int GUIButton::NotifyTouch(TOUCH_STATE state, int x, int y)
|
||||
}
|
||||
if (x < mRenderX || x - mRenderX > mRenderW || y < mRenderY || y - mRenderY > mRenderH)
|
||||
return 0;
|
||||
return (mAction ? mAction->NotifyTouch(state, x, y) : 1);
|
||||
return (mAction ? mAction->NotifyTouch(state, x, y) : 1);
|
||||
}
|
||||
|
||||
|
||||
+103
-99
@@ -26,63 +26,64 @@ extern "C" {
|
||||
#include "objects.hpp"
|
||||
|
||||
GUICheckbox::GUICheckbox(xml_node<>* node)
|
||||
: Conditional(node)
|
||||
: Conditional(node)
|
||||
{
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
|
||||
mChecked = NULL;
|
||||
mUnchecked = NULL;
|
||||
mLabel = NULL;
|
||||
mRendered = false;
|
||||
mChecked = NULL;
|
||||
mUnchecked = NULL;
|
||||
mLabel = NULL;
|
||||
mRendered = false;
|
||||
|
||||
mLastState = 0;
|
||||
mLastState = 0;
|
||||
|
||||
if (!node) return;
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
// The label can be loaded directly
|
||||
mLabel = new GUIText(node);
|
||||
// The label can be loaded directly
|
||||
mLabel = new GUIText(node);
|
||||
|
||||
// Read the check states
|
||||
child = node->first_node("image");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("checked");
|
||||
if (attr)
|
||||
mChecked = PageManager::FindResource(attr->value());
|
||||
attr = child->first_attribute("unchecked");
|
||||
if (attr)
|
||||
mUnchecked = PageManager::FindResource(attr->value());
|
||||
}
|
||||
// Read the check states
|
||||
child = node->first_node("image");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("checked");
|
||||
if (attr)
|
||||
mChecked = PageManager::FindResource(attr->value());
|
||||
attr = child->first_attribute("unchecked");
|
||||
if (attr)
|
||||
mUnchecked = PageManager::FindResource(attr->value());
|
||||
}
|
||||
|
||||
// Get the variable data
|
||||
child = node->first_node("data");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("variable");
|
||||
if (attr)
|
||||
mVarName = attr->value();
|
||||
attr = child->first_attribute("default");
|
||||
if (attr)
|
||||
DataManager::SetValue(mVarName, attr->value());
|
||||
}
|
||||
// Get the variable data
|
||||
child = node->first_node("data");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("variable");
|
||||
if (attr)
|
||||
mVarName = attr->value();
|
||||
attr = child->first_attribute("default");
|
||||
if (attr)
|
||||
DataManager::SetValue(mVarName, attr->value());
|
||||
}
|
||||
|
||||
mCheckW = 0; mCheckH = 0;
|
||||
if (mChecked && mChecked->GetResource())
|
||||
{
|
||||
mCheckW = gr_get_width(mChecked->GetResource());
|
||||
mCheckH = gr_get_height(mChecked->GetResource());
|
||||
}
|
||||
else if (mUnchecked && mUnchecked->GetResource())
|
||||
{
|
||||
mCheckW = gr_get_width(mUnchecked->GetResource());
|
||||
mCheckH = gr_get_height(mUnchecked->GetResource());
|
||||
}
|
||||
mCheckW = 0; mCheckH = 0;
|
||||
if (mChecked && mChecked->GetResource())
|
||||
{
|
||||
mCheckW = gr_get_width(mChecked->GetResource());
|
||||
mCheckH = gr_get_height(mChecked->GetResource());
|
||||
}
|
||||
else if (mUnchecked && mUnchecked->GetResource())
|
||||
{
|
||||
mCheckW = gr_get_width(mUnchecked->GetResource());
|
||||
mCheckH = gr_get_height(mUnchecked->GetResource());
|
||||
}
|
||||
|
||||
int x, y, w, h;
|
||||
mLabel->GetRenderPos(x, y, w, h);
|
||||
SetRenderPos(x, y, 0, 0);
|
||||
return;
|
||||
int x, y, w, h;
|
||||
mLabel->GetRenderPos(x, y, w, h);
|
||||
SetRenderPos(x, y, 0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
GUICheckbox::~GUICheckbox()
|
||||
@@ -91,78 +92,81 @@ GUICheckbox::~GUICheckbox()
|
||||
|
||||
int GUICheckbox::Render(void)
|
||||
{
|
||||
if (!isConditionTrue())
|
||||
{
|
||||
mRendered = false;
|
||||
return 0;
|
||||
}
|
||||
if (!isConditionTrue())
|
||||
{
|
||||
mRendered = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
int lastState = 0;
|
||||
DataManager::GetValue(mVarName, lastState);
|
||||
int ret = 0;
|
||||
int lastState = 0;
|
||||
DataManager::GetValue(mVarName, lastState);
|
||||
|
||||
if (lastState)
|
||||
{
|
||||
if (mChecked && mChecked->GetResource())
|
||||
gr_blit(mChecked->GetResource(), 0, 0, mCheckW, mCheckH, mRenderX, mRenderY);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mUnchecked && mUnchecked->GetResource())
|
||||
gr_blit(mUnchecked->GetResource(), 0, 0, mCheckW, mCheckH, mRenderX, mRenderY);
|
||||
}
|
||||
if (mLabel) ret = mLabel->Render();
|
||||
mLastState = lastState;
|
||||
mRendered = true;
|
||||
return ret;
|
||||
if (lastState)
|
||||
{
|
||||
if (mChecked && mChecked->GetResource())
|
||||
gr_blit(mChecked->GetResource(), 0, 0, mCheckW, mCheckH, mRenderX, mRenderY);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mUnchecked && mUnchecked->GetResource())
|
||||
gr_blit(mUnchecked->GetResource(), 0, 0, mCheckW, mCheckH, mRenderX, mRenderY);
|
||||
}
|
||||
if (mLabel)
|
||||
ret = mLabel->Render();
|
||||
mLastState = lastState;
|
||||
mRendered = true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int GUICheckbox::Update(void)
|
||||
{
|
||||
if (!isConditionTrue()) return (mRendered ? 2 : 0);
|
||||
if (!mRendered) return 2;
|
||||
if (!isConditionTrue()) return (mRendered ? 2 : 0);
|
||||
if (!mRendered) return 2;
|
||||
|
||||
int lastState = 0;
|
||||
DataManager::GetValue(mVarName, lastState);
|
||||
int lastState = 0;
|
||||
DataManager::GetValue(mVarName, lastState);
|
||||
|
||||
if (lastState != mLastState)
|
||||
return 2;
|
||||
return 0;
|
||||
if (lastState != mLastState)
|
||||
return 2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GUICheckbox::SetRenderPos(int x, int y, int w, int h)
|
||||
{
|
||||
mRenderX = x;
|
||||
mRenderY = y;
|
||||
mRenderX = x;
|
||||
mRenderY = y;
|
||||
|
||||
if (w || h) return -1;
|
||||
if (w || h)
|
||||
return -1;
|
||||
|
||||
int textW, textH;
|
||||
mLabel->GetCurrentBounds(textW, textH);
|
||||
int textW, textH;
|
||||
mLabel->GetCurrentBounds(textW, textH);
|
||||
|
||||
w = textW + mCheckW + 5;
|
||||
mRenderW = w;
|
||||
mRenderH = mCheckH;
|
||||
w = textW + mCheckW + 5;
|
||||
mRenderW = w;
|
||||
mRenderH = mCheckH;
|
||||
|
||||
mTextX = mRenderX + mCheckW + 5;
|
||||
mTextY = mRenderY + ((mCheckH / 2) - (textH / 2));
|
||||
mTextX = mRenderX + mCheckW + 5;
|
||||
mTextY = mRenderY + ((mCheckH / 2) - (textH / 2));
|
||||
|
||||
mLabel->SetRenderPos(mTextX, mTextY, 0, 0);
|
||||
SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
|
||||
return 0;
|
||||
mLabel->SetRenderPos(mTextX, mTextY, 0, 0);
|
||||
SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GUICheckbox::NotifyTouch(TOUCH_STATE state, int x, int y)
|
||||
{
|
||||
if (!isConditionTrue()) return -1;
|
||||
if (!isConditionTrue())
|
||||
return -1;
|
||||
|
||||
if (state == TOUCH_RELEASE)
|
||||
{
|
||||
int lastState;
|
||||
DataManager::GetValue(mVarName, lastState);
|
||||
lastState = (lastState == 0) ? 1 : 0;
|
||||
DataManager::SetValue(mVarName, lastState);
|
||||
}
|
||||
return 0;
|
||||
if (state == TOUCH_RELEASE)
|
||||
{
|
||||
int lastState;
|
||||
DataManager::GetValue(mVarName, lastState);
|
||||
lastState = (lastState == 0) ? 1 : 0;
|
||||
DataManager::SetValue(mVarName, lastState);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+119
-117
@@ -29,153 +29,156 @@ extern "C" {
|
||||
|
||||
Conditional::Conditional(xml_node<>* node)
|
||||
{
|
||||
// Break out early, it's too hard to check if valid every step
|
||||
if (!node) return;
|
||||
// Break out early, it's too hard to check if valid every step
|
||||
if (!node) return;
|
||||
|
||||
// First, get the action
|
||||
xml_node<>* condition = node->first_node("conditions");
|
||||
if (condition) condition = condition->first_node("condition");
|
||||
else condition = node->first_node("condition");
|
||||
// First, get the action
|
||||
xml_node<>* condition = node->first_node("conditions");
|
||||
if (condition) condition = condition->first_node("condition");
|
||||
else condition = node->first_node("condition");
|
||||
|
||||
if (!condition) return;
|
||||
if (!condition) return;
|
||||
|
||||
while (condition)
|
||||
{
|
||||
Condition cond;
|
||||
while (condition)
|
||||
{
|
||||
Condition cond;
|
||||
|
||||
cond.mCompareOp = "=";
|
||||
cond.mCompareOp = "=";
|
||||
|
||||
xml_attribute<>* attr;
|
||||
attr = condition->first_attribute("var1");
|
||||
if (attr) cond.mVar1 = attr->value();
|
||||
xml_attribute<>* attr;
|
||||
attr = condition->first_attribute("var1");
|
||||
if (attr) cond.mVar1 = attr->value();
|
||||
|
||||
attr = condition->first_attribute("op");
|
||||
if (attr) cond.mCompareOp = attr->value();
|
||||
attr = condition->first_attribute("op");
|
||||
if (attr) cond.mCompareOp = attr->value();
|
||||
|
||||
attr = condition->first_attribute("var2");
|
||||
if (attr) cond.mVar2 = attr->value();
|
||||
|
||||
mConditions.push_back(cond);
|
||||
attr = condition->first_attribute("var2");
|
||||
if (attr) cond.mVar2 = attr->value();
|
||||
|
||||
mConditions.push_back(cond);
|
||||
|
||||
condition = condition->next_sibling("condition");
|
||||
}
|
||||
condition = condition->next_sibling("condition");
|
||||
}
|
||||
}
|
||||
|
||||
bool Conditional::IsConditionVariable(std::string var)
|
||||
{
|
||||
std::vector<Condition>::iterator iter;
|
||||
for (iter = mConditions.begin(); iter != mConditions.end(); iter++)
|
||||
{
|
||||
if (iter->mVar1 == var) return true;
|
||||
}
|
||||
return false;
|
||||
std::vector<Condition>::iterator iter;
|
||||
for (iter = mConditions.begin(); iter != mConditions.end(); iter++)
|
||||
{
|
||||
if (iter->mVar1 == var)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Conditional::isConditionTrue()
|
||||
{
|
||||
std::vector<Condition>::iterator iter;
|
||||
for (iter = mConditions.begin(); iter != mConditions.end(); iter++)
|
||||
{
|
||||
if (!isConditionTrue(&(*iter))) return false;
|
||||
}
|
||||
return true;
|
||||
std::vector<Condition>::iterator iter;
|
||||
for (iter = mConditions.begin(); iter != mConditions.end(); iter++)
|
||||
{
|
||||
if (!isConditionTrue(&(*iter)))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Conditional::isConditionTrue(Condition* condition)
|
||||
{
|
||||
// This is used to hold the proper value of "true" based on the '!' NOT flag
|
||||
bool bTrue = true;
|
||||
// This is used to hold the proper value of "true" based on the '!' NOT flag
|
||||
bool bTrue = true;
|
||||
|
||||
if (condition->mVar1.empty()) return bTrue;
|
||||
if (condition->mVar1.empty())
|
||||
return bTrue;
|
||||
|
||||
if (!condition->mCompareOp.empty() && condition->mCompareOp[0] == '!')
|
||||
bTrue = false;
|
||||
if (!condition->mCompareOp.empty() && condition->mCompareOp[0] == '!')
|
||||
bTrue = false;
|
||||
|
||||
if (condition->mVar2.empty() && condition->mCompareOp != "modified")
|
||||
{
|
||||
if (!DataManager::GetStrValue(condition->mVar1).empty())
|
||||
return bTrue;
|
||||
if (condition->mVar2.empty() && condition->mCompareOp != "modified")
|
||||
{
|
||||
if (!DataManager::GetStrValue(condition->mVar1).empty())
|
||||
return bTrue;
|
||||
|
||||
return !bTrue;
|
||||
}
|
||||
return !bTrue;
|
||||
}
|
||||
|
||||
string var1, var2;
|
||||
if (DataManager::GetValue(condition->mVar1, var1))
|
||||
var1 = condition->mVar1;
|
||||
if (DataManager::GetValue(condition->mVar2, var2))
|
||||
var2 = condition->mVar2;
|
||||
string var1, var2;
|
||||
if (DataManager::GetValue(condition->mVar1, var1))
|
||||
var1 = condition->mVar1;
|
||||
if (DataManager::GetValue(condition->mVar2, var2))
|
||||
var2 = condition->mVar2;
|
||||
|
||||
// This is a special case, we stat the file and that determines our result
|
||||
if (var1 == "fileexists")
|
||||
{
|
||||
struct stat st;
|
||||
if (stat(var2.c_str(), &st) == 0)
|
||||
var2 = var1;
|
||||
else
|
||||
var2 = "FAILED";
|
||||
}
|
||||
if (var1 == "mounted")
|
||||
{
|
||||
if (isMounted(condition->mVar2))
|
||||
var2 = var1;
|
||||
else
|
||||
var2 = "FAILED";
|
||||
}
|
||||
// This is a special case, we stat the file and that determines our result
|
||||
if (var1 == "fileexists")
|
||||
{
|
||||
struct stat st;
|
||||
if (stat(var2.c_str(), &st) == 0)
|
||||
var2 = var1;
|
||||
else
|
||||
var2 = "FAILED";
|
||||
}
|
||||
if (var1 == "mounted")
|
||||
{
|
||||
if (isMounted(condition->mVar2))
|
||||
var2 = var1;
|
||||
else
|
||||
var2 = "FAILED";
|
||||
}
|
||||
|
||||
if (condition->mCompareOp.find('=') != string::npos && var1 == var2)
|
||||
return bTrue;
|
||||
if (condition->mCompareOp.find('=') != string::npos && var1 == var2)
|
||||
return bTrue;
|
||||
|
||||
if (condition->mCompareOp.find('>') != string::npos && (atof(var1.c_str()) > atof(var2.c_str())))
|
||||
return bTrue;
|
||||
if (condition->mCompareOp.find('>') != string::npos && (atof(var1.c_str()) > atof(var2.c_str())))
|
||||
return bTrue;
|
||||
|
||||
if (condition->mCompareOp.find('<') != string::npos && (atof(var1.c_str()) < atof(var2.c_str())))
|
||||
return bTrue;
|
||||
if (condition->mCompareOp.find('<') != string::npos && (atof(var1.c_str()) < atof(var2.c_str())))
|
||||
return bTrue;
|
||||
|
||||
if (condition->mCompareOp == "modified")
|
||||
{
|
||||
// This is a hack to allow areas to reset the default value
|
||||
if (var1.empty())
|
||||
{
|
||||
condition->mLastVal = var1;
|
||||
return !bTrue;
|
||||
}
|
||||
if (condition->mCompareOp == "modified")
|
||||
{
|
||||
// This is a hack to allow areas to reset the default value
|
||||
if (var1.empty())
|
||||
{
|
||||
condition->mLastVal = var1;
|
||||
return !bTrue;
|
||||
}
|
||||
|
||||
if (var1 != condition->mLastVal)
|
||||
return bTrue;
|
||||
}
|
||||
if (var1 != condition->mLastVal)
|
||||
return bTrue;
|
||||
}
|
||||
|
||||
return !bTrue;
|
||||
return !bTrue;
|
||||
}
|
||||
|
||||
bool Conditional::isConditionValid()
|
||||
{
|
||||
return !mConditions.empty();
|
||||
return !mConditions.empty();
|
||||
}
|
||||
|
||||
void Conditional::NotifyPageSet()
|
||||
{
|
||||
std::vector<Condition>::iterator iter;
|
||||
for (iter = mConditions.begin(); iter != mConditions.end(); iter++)
|
||||
{
|
||||
if (iter->mCompareOp == "modified")
|
||||
{
|
||||
string val;
|
||||
|
||||
// If this fails, val will not be set, which is perfect
|
||||
if (DataManager::GetValue(iter->mVar1, val))
|
||||
{
|
||||
DataManager::SetValue(iter->mVar1, "");
|
||||
DataManager::GetValue(iter->mVar1, val);
|
||||
}
|
||||
iter->mLastVal = val;
|
||||
}
|
||||
}
|
||||
std::vector<Condition>::iterator iter;
|
||||
for (iter = mConditions.begin(); iter != mConditions.end(); iter++)
|
||||
{
|
||||
if (iter->mCompareOp == "modified")
|
||||
{
|
||||
string val;
|
||||
|
||||
// If this fails, val will not be set, which is perfect
|
||||
if (DataManager::GetValue(iter->mVar1, val))
|
||||
{
|
||||
DataManager::SetValue(iter->mVar1, "");
|
||||
DataManager::GetValue(iter->mVar1, val);
|
||||
}
|
||||
iter->mLastVal = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Conditional::isMounted(string vol)
|
||||
{
|
||||
FILE *fp;
|
||||
char tmpOutput[255];
|
||||
char tmpOutput[255];
|
||||
|
||||
if (strcmp(vol.c_str(), "EXTERNAL") == 0)
|
||||
DataManager::GetValue(TW_EXTERNAL_MOUNT, vol);
|
||||
@@ -184,19 +187,18 @@ bool Conditional::isMounted(string vol)
|
||||
fp = fopen("/proc/mounts", "rt");
|
||||
while (fgets(tmpOutput,255,fp) != NULL)
|
||||
{
|
||||
char* mnt = tmpOutput;
|
||||
while (*mnt > 32) mnt++;
|
||||
while (*mnt > 0 && *mnt <= 32) mnt++;
|
||||
char* pos = mnt;
|
||||
while (*pos > 32) pos++;
|
||||
*pos = 0;
|
||||
if (vol == mnt)
|
||||
{
|
||||
fclose(fp);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
return false;
|
||||
char* mnt = tmpOutput;
|
||||
while (*mnt > 32) mnt++;
|
||||
while (*mnt > 0 && *mnt <= 32) mnt++;
|
||||
char* pos = mnt;
|
||||
while (*pos > 32) pos++;
|
||||
*pos = 0;
|
||||
if (vol == mnt)
|
||||
{
|
||||
fclose(fp);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+275
-274
@@ -30,373 +30,374 @@ static std::vector<std::string> gConsole;
|
||||
|
||||
extern "C" void gui_print(const char *fmt, ...)
|
||||
{
|
||||
char buf[512]; // We're going to limit a single request to 512 bytes
|
||||
char buf[512]; // We're going to limit a single request to 512 bytes
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(buf, 512, fmt, ap);
|
||||
va_end(ap);
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(buf, 512, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
fputs(buf, stdout);
|
||||
|
||||
char *start, *next;
|
||||
char *start, *next;
|
||||
|
||||
if (buf[0] == '\n' && strlen(buf) < 2) {
|
||||
// This prevents the double lines bug seen in the console during zip installs
|
||||
return;
|
||||
}
|
||||
|
||||
for (start = next = buf; *next != '\0'; next++)
|
||||
{
|
||||
if (*next == '\n')
|
||||
{
|
||||
*next = '\0';
|
||||
next++;
|
||||
for (start = next = buf; *next != '\0'; next++)
|
||||
{
|
||||
if (*next == '\n')
|
||||
{
|
||||
*next = '\0';
|
||||
next++;
|
||||
|
||||
std::string line = start;
|
||||
gConsole.push_back(line);
|
||||
start = next;
|
||||
std::string line = start;
|
||||
gConsole.push_back(line);
|
||||
start = next;
|
||||
|
||||
// Handle the normal \n\0 case
|
||||
if (*next == '\0')
|
||||
if (*next == '\0')
|
||||
return;
|
||||
}
|
||||
}
|
||||
std::string line = start;
|
||||
gConsole.push_back(line);
|
||||
return;
|
||||
}
|
||||
}
|
||||
std::string line = start;
|
||||
gConsole.push_back(line);
|
||||
return;
|
||||
}
|
||||
|
||||
extern "C" void gui_print_overwrite(const char *fmt, ...)
|
||||
{
|
||||
char buf[512]; // We're going to limit a single request to 512 bytes
|
||||
char buf[512]; // We're going to limit a single request to 512 bytes
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(buf, 512, fmt, ap);
|
||||
va_end(ap);
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(buf, 512, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
fputs(buf, stdout);
|
||||
|
||||
// Pop the last line, and we can continue
|
||||
if (!gConsole.empty()) gConsole.pop_back();
|
||||
// Pop the last line, and we can continue
|
||||
if (!gConsole.empty()) gConsole.pop_back();
|
||||
|
||||
char *start, *next;
|
||||
for (start = next = buf; *next != '\0'; next++)
|
||||
{
|
||||
if (*next == '\n')
|
||||
{
|
||||
*next = '\0';
|
||||
next++;
|
||||
|
||||
std::string line = start;
|
||||
gConsole.push_back(line);
|
||||
start = next;
|
||||
char *start, *next;
|
||||
for (start = next = buf; *next != '\0'; next++)
|
||||
{
|
||||
if (*next == '\n')
|
||||
{
|
||||
*next = '\0';
|
||||
next++;
|
||||
|
||||
std::string line = start;
|
||||
gConsole.push_back(line);
|
||||
start = next;
|
||||
|
||||
// Handle the normal \n\0 case
|
||||
if (*next == '\0')
|
||||
// Handle the normal \n\0 case
|
||||
if (*next == '\0')
|
||||
return;
|
||||
}
|
||||
}
|
||||
std::string line = start;
|
||||
gConsole.push_back(line);
|
||||
return;
|
||||
}
|
||||
}
|
||||
std::string line = start;
|
||||
gConsole.push_back(line);
|
||||
return;
|
||||
}
|
||||
|
||||
GUIConsole::GUIConsole(xml_node<>* node)
|
||||
{
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
|
||||
mFont = NULL;
|
||||
mCurrentLine = -1;
|
||||
memset(&mForegroundColor, 255, sizeof(COLOR));
|
||||
memset(&mBackgroundColor, 0, sizeof(COLOR));
|
||||
mBackgroundColor.alpha = 255;
|
||||
memset(&mScrollColor, 0x08, sizeof(COLOR));
|
||||
mScrollColor.alpha = 255;
|
||||
mLastCount = 0;
|
||||
mSlideout = 0;
|
||||
mSlideoutState = hidden;
|
||||
mFont = NULL;
|
||||
mCurrentLine = -1;
|
||||
memset(&mForegroundColor, 255, sizeof(COLOR));
|
||||
memset(&mBackgroundColor, 0, sizeof(COLOR));
|
||||
mBackgroundColor.alpha = 255;
|
||||
memset(&mScrollColor, 0x08, sizeof(COLOR));
|
||||
mScrollColor.alpha = 255;
|
||||
mLastCount = 0;
|
||||
mSlideout = 0;
|
||||
mSlideoutState = hidden;
|
||||
|
||||
mRenderX = 0; mRenderY = 0; mRenderW = gr_fb_width(); mRenderH = gr_fb_height();
|
||||
mRenderX = 0; mRenderY = 0; mRenderW = gr_fb_width(); mRenderH = gr_fb_height();
|
||||
|
||||
if (!node)
|
||||
{
|
||||
mSlideoutX = 0; mSlideoutY = 0; mSlideoutW = 0; mSlideoutH = 0;
|
||||
mConsoleX = 0; mConsoleY = 0; mConsoleW = gr_fb_width(); mConsoleH = gr_fb_height();
|
||||
}
|
||||
else
|
||||
{
|
||||
child = node->first_node("font");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("resource");
|
||||
if (attr)
|
||||
mFont = PageManager::FindResource(attr->value());
|
||||
}
|
||||
if (!node)
|
||||
{
|
||||
mSlideoutX = 0; mSlideoutY = 0; mSlideoutW = 0; mSlideoutH = 0;
|
||||
mConsoleX = 0; mConsoleY = 0; mConsoleW = gr_fb_width(); mConsoleH = gr_fb_height();
|
||||
}
|
||||
else
|
||||
{
|
||||
child = node->first_node("font");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("resource");
|
||||
if (attr)
|
||||
mFont = PageManager::FindResource(attr->value());
|
||||
}
|
||||
|
||||
child = node->first_node("color");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("foreground");
|
||||
if (attr)
|
||||
{
|
||||
std::string color = attr->value();
|
||||
ConvertStrToColor(color, &mForegroundColor);
|
||||
}
|
||||
attr = child->first_attribute("background");
|
||||
if (attr)
|
||||
{
|
||||
std::string color = attr->value();
|
||||
ConvertStrToColor(color, &mBackgroundColor);
|
||||
}
|
||||
attr = child->first_attribute("scroll");
|
||||
if (attr)
|
||||
{
|
||||
std::string color = attr->value();
|
||||
ConvertStrToColor(color, &mScrollColor);
|
||||
}
|
||||
}
|
||||
child = node->first_node("color");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("foreground");
|
||||
if (attr)
|
||||
{
|
||||
std::string color = attr->value();
|
||||
ConvertStrToColor(color, &mForegroundColor);
|
||||
}
|
||||
attr = child->first_attribute("background");
|
||||
if (attr)
|
||||
{
|
||||
std::string color = attr->value();
|
||||
ConvertStrToColor(color, &mBackgroundColor);
|
||||
}
|
||||
attr = child->first_attribute("scroll");
|
||||
if (attr)
|
||||
{
|
||||
std::string color = attr->value();
|
||||
ConvertStrToColor(color, &mScrollColor);
|
||||
}
|
||||
}
|
||||
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &mConsoleX, &mConsoleY, &mConsoleW, &mConsoleH);
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &mConsoleX, &mConsoleY, &mConsoleW, &mConsoleH);
|
||||
|
||||
child = node->first_node("slideout");
|
||||
if (child)
|
||||
{
|
||||
mSlideout = 1;
|
||||
LoadPlacement(child, &mSlideoutX, &mSlideoutY);
|
||||
child = node->first_node("slideout");
|
||||
if (child)
|
||||
{
|
||||
mSlideout = 1;
|
||||
LoadPlacement(child, &mSlideoutX, &mSlideoutY);
|
||||
|
||||
attr = child->first_attribute("resource");
|
||||
if (attr) mSlideoutImage = PageManager::FindResource(attr->value());
|
||||
attr = child->first_attribute("resource");
|
||||
if (attr) mSlideoutImage = PageManager::FindResource(attr->value());
|
||||
|
||||
if (mSlideoutImage && mSlideoutImage->GetResource())
|
||||
{
|
||||
mSlideoutW = gr_get_width(mSlideoutImage->GetResource());
|
||||
mSlideoutH = gr_get_height(mSlideoutImage->GetResource());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mSlideoutImage && mSlideoutImage->GetResource())
|
||||
{
|
||||
mSlideoutW = gr_get_width(mSlideoutImage->GetResource());
|
||||
mSlideoutH = gr_get_height(mSlideoutImage->GetResource());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gr_getFontDetails(mFont, &mFontHeight, NULL);
|
||||
SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
|
||||
SetRenderPos(mConsoleX, mConsoleY);
|
||||
return;
|
||||
gr_getFontDetails(mFont, &mFontHeight, NULL);
|
||||
SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
|
||||
SetRenderPos(mConsoleX, mConsoleY);
|
||||
return;
|
||||
}
|
||||
|
||||
int GUIConsole::RenderSlideout(void)
|
||||
{
|
||||
if (!mSlideoutImage || !mSlideoutImage->GetResource()) return -1;
|
||||
if (!mSlideoutImage || !mSlideoutImage->GetResource())
|
||||
return -1;
|
||||
|
||||
gr_blit(mSlideoutImage->GetResource(), 0, 0, mSlideoutW, mSlideoutH, mSlideoutX, mSlideoutY);
|
||||
return 0;
|
||||
gr_blit(mSlideoutImage->GetResource(), 0, 0, mSlideoutW, mSlideoutH, mSlideoutX, mSlideoutY);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GUIConsole::RenderConsole(void)
|
||||
{
|
||||
void* fontResource = NULL;
|
||||
if (mFont) fontResource = mFont->GetResource();
|
||||
void* fontResource = NULL;
|
||||
if (mFont)
|
||||
fontResource = mFont->GetResource();
|
||||
|
||||
// We fill the background
|
||||
gr_color(mBackgroundColor.red, mBackgroundColor.green, mBackgroundColor.blue, 255);
|
||||
gr_fill(mConsoleX, mConsoleY, mConsoleW, mConsoleH);
|
||||
// We fill the background
|
||||
gr_color(mBackgroundColor.red, mBackgroundColor.green, mBackgroundColor.blue, 255);
|
||||
gr_fill(mConsoleX, mConsoleY, mConsoleW, mConsoleH);
|
||||
|
||||
gr_color(mScrollColor.red, mScrollColor.green, mScrollColor.blue, mScrollColor.alpha);
|
||||
gr_fill(mConsoleX + (mConsoleW * 9 / 10), mConsoleY, (mConsoleW / 10), mConsoleH);
|
||||
gr_color(mScrollColor.red, mScrollColor.green, mScrollColor.blue, mScrollColor.alpha);
|
||||
gr_fill(mConsoleX + (mConsoleW * 9 / 10), mConsoleY, (mConsoleW / 10), mConsoleH);
|
||||
|
||||
// Render the lines
|
||||
gr_color(mForegroundColor.red, mForegroundColor.green, mForegroundColor.blue, mForegroundColor.alpha);
|
||||
// Render the lines
|
||||
gr_color(mForegroundColor.red, mForegroundColor.green, mForegroundColor.blue, mForegroundColor.alpha);
|
||||
|
||||
// Don't try to continue to render without data
|
||||
mLastCount = gConsole.size();
|
||||
if (mLastCount == 0) return (mSlideout ? RenderSlideout() : 0);
|
||||
// Don't try to continue to render without data
|
||||
mLastCount = gConsole.size();
|
||||
if (mLastCount == 0)
|
||||
return (mSlideout ? RenderSlideout() : 0);
|
||||
|
||||
// Find the start point
|
||||
int start;
|
||||
int curLine = mCurrentLine; // Thread-safing (Another thread updates this value)
|
||||
if (curLine == -1)
|
||||
{
|
||||
start = mLastCount - mMaxRows;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (curLine > (int) mLastCount) curLine = (int) mLastCount;
|
||||
if ((int) mMaxRows > curLine) curLine = (int) mMaxRows;
|
||||
start = curLine - mMaxRows;
|
||||
}
|
||||
// Find the start point
|
||||
int start;
|
||||
int curLine = mCurrentLine; // Thread-safing (Another thread updates this value)
|
||||
if (curLine == -1)
|
||||
{
|
||||
start = mLastCount - mMaxRows;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (curLine > (int) mLastCount)
|
||||
curLine = (int) mLastCount;
|
||||
if ((int) mMaxRows > curLine)
|
||||
curLine = (int) mMaxRows;
|
||||
start = curLine - mMaxRows;
|
||||
}
|
||||
|
||||
unsigned int line;
|
||||
for (line = 0; line < mMaxRows; line++)
|
||||
{
|
||||
if ((start + (int) line) >= 0 && (start + (int) line) < (int) mLastCount)
|
||||
{
|
||||
gr_textExW(mConsoleX, mStartY + (line * mFontHeight), gConsole[start + line].c_str(), fontResource, mConsoleW + mConsoleX);
|
||||
}
|
||||
}
|
||||
return (mSlideout ? RenderSlideout() : 0);
|
||||
unsigned int line;
|
||||
for (line = 0; line < mMaxRows; line++)
|
||||
{
|
||||
if ((start + (int) line) >= 0 && (start + (int) line) < (int) mLastCount)
|
||||
gr_textExW(mConsoleX, mStartY + (line * mFontHeight), gConsole[start + line].c_str(), fontResource, mConsoleW + mConsoleX);
|
||||
}
|
||||
return (mSlideout ? RenderSlideout() : 0);
|
||||
}
|
||||
|
||||
int GUIConsole::Render(void)
|
||||
{
|
||||
if (mSlideout && mSlideoutState == hidden)
|
||||
{
|
||||
return RenderSlideout();
|
||||
}
|
||||
return RenderConsole();
|
||||
if (mSlideout && mSlideoutState == hidden)
|
||||
return RenderSlideout();
|
||||
|
||||
return RenderConsole();
|
||||
}
|
||||
|
||||
int GUIConsole::Update(void)
|
||||
{
|
||||
if (mSlideout && mSlideoutState != visible)
|
||||
{
|
||||
if (mSlideoutState == hidden)
|
||||
return 0;
|
||||
if (mSlideout && mSlideoutState != visible)
|
||||
{
|
||||
if (mSlideoutState == hidden)
|
||||
return 0;
|
||||
|
||||
if (mSlideoutState == request_hide)
|
||||
mSlideoutState = hidden;
|
||||
if (mSlideoutState == request_hide)
|
||||
mSlideoutState = hidden;
|
||||
|
||||
if (mSlideoutState == request_show)
|
||||
mSlideoutState = visible;
|
||||
if (mSlideoutState == request_show)
|
||||
mSlideoutState = visible;
|
||||
|
||||
// Any time we activate the slider, we reset the position
|
||||
mCurrentLine = -1;
|
||||
return 2;
|
||||
}
|
||||
// Any time we activate the slider, we reset the position
|
||||
mCurrentLine = -1;
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (mCurrentLine == -1 && mLastCount != gConsole.size())
|
||||
{
|
||||
// We can use Render, and return for just a flip
|
||||
Render();
|
||||
return 2;
|
||||
}
|
||||
else if (mLastTouchY >= 0)
|
||||
{
|
||||
// They're still touching, so re-render
|
||||
Render();
|
||||
mLastTouchY = -1;
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
if (mCurrentLine == -1 && mLastCount != gConsole.size())
|
||||
{
|
||||
// We can use Render, and return for just a flip
|
||||
Render();
|
||||
return 2;
|
||||
}
|
||||
else if (mLastTouchY >= 0)
|
||||
{
|
||||
// They're still touching, so re-render
|
||||
Render();
|
||||
mLastTouchY = -1;
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GUIConsole::SetRenderPos(int x, int y, int w, int h)
|
||||
{
|
||||
// Adjust the stub position accordingly
|
||||
mSlideoutX += (x - mConsoleX);
|
||||
mSlideoutY += (y - mConsoleY);
|
||||
// Adjust the stub position accordingly
|
||||
mSlideoutX += (x - mConsoleX);
|
||||
mSlideoutY += (y - mConsoleY);
|
||||
|
||||
mConsoleX = x;
|
||||
mConsoleY = y;
|
||||
if (w || h)
|
||||
{
|
||||
mConsoleW = w;
|
||||
mConsoleH = h;
|
||||
}
|
||||
mConsoleX = x;
|
||||
mConsoleY = y;
|
||||
if (w || h)
|
||||
{
|
||||
mConsoleW = w;
|
||||
mConsoleH = h;
|
||||
}
|
||||
|
||||
// Calculate the max rows
|
||||
mMaxRows = mConsoleH / mFontHeight;
|
||||
// Calculate the max rows
|
||||
mMaxRows = mConsoleH / mFontHeight;
|
||||
|
||||
// Adjust so we always fit to bottom
|
||||
mStartY = mConsoleY + (mConsoleH % mFontHeight);
|
||||
return 0;
|
||||
// Adjust so we always fit to bottom
|
||||
mStartY = mConsoleY + (mConsoleH % mFontHeight);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// IsInRegion - Checks if the request is handled by this object
|
||||
// Return 0 if this object handles the request, 1 if not
|
||||
int GUIConsole::IsInRegion(int x, int y)
|
||||
{
|
||||
if (mSlideout)
|
||||
{
|
||||
// Check if they tapped the slideout button
|
||||
if (x >= mSlideoutX && x <= mSlideoutX + mSlideoutW && y >= mSlideoutY && y < mSlideoutY + mSlideoutH)
|
||||
return 1;
|
||||
if (mSlideout)
|
||||
{
|
||||
// Check if they tapped the slideout button
|
||||
if (x >= mSlideoutX && x <= mSlideoutX + mSlideoutW && y >= mSlideoutY && y < mSlideoutY + mSlideoutH)
|
||||
return 1;
|
||||
|
||||
// If we're only rendering the slideout, bail now
|
||||
if (mSlideoutState == hidden)
|
||||
return 0;
|
||||
}
|
||||
// If we're only rendering the slideout, bail now
|
||||
if (mSlideoutState == hidden)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (x < mConsoleX || x > mConsoleX + mConsoleW || y < mConsoleY || y > mConsoleY + mConsoleH) ? 0 : 1;
|
||||
return (x < mConsoleX || x > mConsoleX + mConsoleW || y < mConsoleY || y > mConsoleY + mConsoleH) ? 0 : 1;
|
||||
}
|
||||
|
||||
// NotifyTouch - Notify of a touch event
|
||||
// Return 0 on success, >0 to ignore remainder of touch, and <0 on error
|
||||
int GUIConsole::NotifyTouch(TOUCH_STATE state, int x, int y)
|
||||
{
|
||||
if (mSlideout && mSlideoutState == hidden)
|
||||
{
|
||||
if (state == TOUCH_START)
|
||||
{
|
||||
mSlideoutState = request_show;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (mSlideout && mSlideoutState == visible)
|
||||
{
|
||||
// Are we sliding it back in?
|
||||
if (state == TOUCH_START && x > mSlideoutX && x < (mSlideoutX + mSlideoutW) && y > mSlideoutY && y < (mSlideoutY + mSlideoutH))
|
||||
{
|
||||
mSlideoutState = request_hide;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (mSlideout && mSlideoutState == hidden)
|
||||
{
|
||||
if (state == TOUCH_START)
|
||||
{
|
||||
mSlideoutState = request_show;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (mSlideout && mSlideoutState == visible)
|
||||
{
|
||||
// Are we sliding it back in?
|
||||
if (state == TOUCH_START && x > mSlideoutX && x < (mSlideoutX + mSlideoutW) && y > mSlideoutY && y < (mSlideoutY + mSlideoutH))
|
||||
{
|
||||
mSlideoutState = request_hide;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// If we don't have enough lines to scroll, throw this away.
|
||||
if (mLastCount < mMaxRows) return 1;
|
||||
// If we don't have enough lines to scroll, throw this away.
|
||||
if (mLastCount < mMaxRows) return 1;
|
||||
|
||||
// We are scrolling!!!
|
||||
switch (state)
|
||||
{
|
||||
case TOUCH_START:
|
||||
mLastTouchX = x;
|
||||
mLastTouchY = y;
|
||||
if ((x - mConsoleX) > ((9 * mConsoleW) / 10))
|
||||
mSlideMultiplier = 10;
|
||||
else
|
||||
mSlideMultiplier = 1;
|
||||
break;
|
||||
// We are scrolling!!!
|
||||
switch (state)
|
||||
{
|
||||
case TOUCH_START:
|
||||
mLastTouchX = x;
|
||||
mLastTouchY = y;
|
||||
if ((x - mConsoleX) > ((9 * mConsoleW) / 10))
|
||||
mSlideMultiplier = 10;
|
||||
else
|
||||
mSlideMultiplier = 1;
|
||||
break;
|
||||
|
||||
case TOUCH_DRAG:
|
||||
// This handles tapping
|
||||
if (x == mLastTouchX && y == mLastTouchY) break;
|
||||
mLastTouchX = -1;
|
||||
case TOUCH_DRAG:
|
||||
// This handles tapping
|
||||
if (x == mLastTouchX && y == mLastTouchY) break;
|
||||
mLastTouchX = -1;
|
||||
|
||||
if (y > mLastTouchY + 5)
|
||||
{
|
||||
mLastTouchY = y;
|
||||
if (mCurrentLine == -1)
|
||||
mCurrentLine = mLastCount - 1;
|
||||
else if (mCurrentLine > mSlideMultiplier)
|
||||
mCurrentLine -= mSlideMultiplier;
|
||||
else
|
||||
mCurrentLine = mMaxRows;
|
||||
if (y > mLastTouchY + 5)
|
||||
{
|
||||
mLastTouchY = y;
|
||||
if (mCurrentLine == -1)
|
||||
mCurrentLine = mLastCount - 1;
|
||||
else if (mCurrentLine > mSlideMultiplier)
|
||||
mCurrentLine -= mSlideMultiplier;
|
||||
else
|
||||
mCurrentLine = mMaxRows;
|
||||
|
||||
if (mCurrentLine < (int) mMaxRows)
|
||||
mCurrentLine = mMaxRows;
|
||||
}
|
||||
else if (y < mLastTouchY - 5)
|
||||
{
|
||||
mLastTouchY = y;
|
||||
if (mCurrentLine >= 0)
|
||||
{
|
||||
mCurrentLine += mSlideMultiplier;
|
||||
if (mCurrentLine >= (int) mLastCount)
|
||||
mCurrentLine = -1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
if (mCurrentLine < (int) mMaxRows)
|
||||
mCurrentLine = mMaxRows;
|
||||
}
|
||||
else if (y < mLastTouchY - 5)
|
||||
{
|
||||
mLastTouchY = y;
|
||||
if (mCurrentLine >= 0)
|
||||
{
|
||||
mCurrentLine += mSlideMultiplier;
|
||||
if (mCurrentLine >= (int) mLastCount)
|
||||
mCurrentLine = -1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case TOUCH_RELEASE:
|
||||
// On a tap, we jump to the tail
|
||||
if (mLastTouchX >= 0)
|
||||
mCurrentLine = -1;
|
||||
case TOUCH_RELEASE:
|
||||
// On a tap, we jump to the tail
|
||||
if (mLastTouchX >= 0)
|
||||
mCurrentLine = -1;
|
||||
|
||||
mLastTouchY = -1;
|
||||
mLastTouchY = -1;
|
||||
case TOUCH_REPEAT:
|
||||
case TOUCH_HOLD:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -198,12 +198,12 @@ GUIFileSelector::GUIFileSelector(xml_node<>* node)
|
||||
|
||||
attr = child->first_attribute("highlightcolor");
|
||||
memset(&mFontHighlightColor, 0, sizeof(COLOR));
|
||||
if (attr)
|
||||
{
|
||||
std::string color = attr->value();
|
||||
if (attr)
|
||||
{
|
||||
std::string color = attr->value();
|
||||
ConvertStrToColor(color, &mFontHighlightColor);
|
||||
hasFontHighlightColor = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load the separator if it exists
|
||||
@@ -408,11 +408,10 @@ int GUIFileSelector::Render(void)
|
||||
if (updateFileList) {
|
||||
string value;
|
||||
DataManager::GetValue(mPathVar, value);
|
||||
if (GetFileList(value) == 0) {
|
||||
if (GetFileList(value) == 0)
|
||||
updateFileList = false;
|
||||
} else {
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// This tells us how many lines we can actually render
|
||||
@@ -652,7 +651,9 @@ int GUIFileSelector::Update(void)
|
||||
int GUIFileSelector::GetSelection(int x, int y)
|
||||
{
|
||||
// We only care about y position
|
||||
if (y < mRenderY || y - mRenderY <= mHeaderH || y - mRenderY > mRenderH) return -1;
|
||||
if (y < mRenderY || y - mRenderY <= mHeaderH || y - mRenderY > mRenderH)
|
||||
return -1;
|
||||
|
||||
return (y - mRenderY - mHeaderH);
|
||||
}
|
||||
|
||||
@@ -674,7 +675,6 @@ int GUIFileSelector::NotifyTouch(TOUCH_STATE state, int x, int y)
|
||||
startY = lastY = last2Y = y;
|
||||
scrollingSpeed = 0;
|
||||
break;
|
||||
|
||||
case TOUCH_DRAG:
|
||||
// Check if we dragged out of the selection window
|
||||
if (GetSelection(x, y) == -1) {
|
||||
|
||||
+15
-15
@@ -27,31 +27,31 @@ extern "C" {
|
||||
|
||||
GUIFill::GUIFill(xml_node<>* node)
|
||||
{
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
|
||||
if (!node)
|
||||
return;
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
attr = node->first_attribute("color");
|
||||
if (!attr) {
|
||||
attr = node->first_attribute("color");
|
||||
if (!attr) {
|
||||
LOGERR("No color specified for fill\n");
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
std::string color = attr->value();
|
||||
ConvertStrToColor(color, &mColor);
|
||||
std::string color = attr->value();
|
||||
ConvertStrToColor(color, &mColor);
|
||||
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH);
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH);
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
int GUIFill::Render(void)
|
||||
{
|
||||
gr_color(mColor.red, mColor.green, mColor.blue, mColor.alpha);
|
||||
gr_fill(mRenderX, mRenderY, mRenderW, mRenderH);
|
||||
return 0;
|
||||
gr_color(mColor.red, mColor.green, mColor.blue, mColor.alpha);
|
||||
gr_fill(mRenderX, mRenderY, mRenderW, mRenderH);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+434
-460
File diff suppressed because it is too large
Load Diff
@@ -26,15 +26,18 @@ extern "C" {
|
||||
#include "rapidxml.hpp"
|
||||
#include "objects.hpp"
|
||||
|
||||
HardwareKeyboard::HardwareKeyboard(void) {
|
||||
// Do Nothing
|
||||
HardwareKeyboard::HardwareKeyboard(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
HardwareKeyboard::~HardwareKeyboard() {
|
||||
// Do Nothing
|
||||
HardwareKeyboard::~HardwareKeyboard()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int HardwareKeyboard::KeyDown(int key_code) {
|
||||
int HardwareKeyboard::KeyDown(int key_code)
|
||||
{
|
||||
#ifdef _EVENT_LOGGING
|
||||
LOGERR("HardwareKeyboard::KeyDown %i\n", key_code);
|
||||
#endif
|
||||
@@ -42,14 +45,16 @@ int HardwareKeyboard::KeyDown(int key_code) {
|
||||
return 0; // 0 = no key repeat anything else turns on key repeat
|
||||
}
|
||||
|
||||
int HardwareKeyboard::KeyUp(int key_code) {
|
||||
int HardwareKeyboard::KeyUp(int key_code)
|
||||
{
|
||||
#ifdef _EVENT_LOGGING
|
||||
LOGERR("HardwareKeyboard::KeyUp %i\n", key_code);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int HardwareKeyboard::KeyRepeat(void) {
|
||||
int HardwareKeyboard::KeyRepeat(void)
|
||||
{
|
||||
#ifdef _EVENT_LOGGING
|
||||
LOGERR("HardwareKeyboard::KeyRepeat\n");
|
||||
#endif
|
||||
|
||||
+51
-46
@@ -27,71 +27,76 @@ extern "C" {
|
||||
|
||||
GUIImage::GUIImage(xml_node<>* node)
|
||||
{
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
|
||||
mImage = NULL;
|
||||
mImage = NULL;
|
||||
mHighlightImage = NULL;
|
||||
isHighlighted = false;
|
||||
|
||||
if (!node)
|
||||
return;
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
child = node->first_node("image");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("resource");
|
||||
if (attr)
|
||||
mImage = PageManager::FindResource(attr->value());
|
||||
child = node->first_node("image");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("resource");
|
||||
if (attr)
|
||||
mImage = PageManager::FindResource(attr->value());
|
||||
attr = child->first_attribute("highlightresource");
|
||||
if (attr)
|
||||
mHighlightImage = PageManager::FindResource(attr->value());
|
||||
}
|
||||
if (attr)
|
||||
mHighlightImage = PageManager::FindResource(attr->value());
|
||||
}
|
||||
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement);
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement);
|
||||
|
||||
if (mImage && mImage->GetResource())
|
||||
{
|
||||
mRenderW = gr_get_width(mImage->GetResource());
|
||||
mRenderH = gr_get_height(mImage->GetResource());
|
||||
if (mImage && mImage->GetResource())
|
||||
{
|
||||
mRenderW = gr_get_width(mImage->GetResource());
|
||||
mRenderH = gr_get_height(mImage->GetResource());
|
||||
|
||||
// Adjust for placement
|
||||
if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT)
|
||||
{
|
||||
if (mPlacement == CENTER)
|
||||
mRenderX -= (mRenderW / 2);
|
||||
else
|
||||
mRenderX -= mRenderW;
|
||||
}
|
||||
if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT)
|
||||
{
|
||||
if (mPlacement == CENTER)
|
||||
mRenderY -= (mRenderH / 2);
|
||||
else
|
||||
mRenderY -= mRenderH;
|
||||
}
|
||||
SetPlacement(TOP_LEFT);
|
||||
}
|
||||
// Adjust for placement
|
||||
if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT)
|
||||
{
|
||||
if (mPlacement == CENTER)
|
||||
mRenderX -= (mRenderW / 2);
|
||||
else
|
||||
mRenderX -= mRenderW;
|
||||
}
|
||||
if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT)
|
||||
{
|
||||
if (mPlacement == CENTER)
|
||||
mRenderY -= (mRenderH / 2);
|
||||
else
|
||||
mRenderY -= mRenderH;
|
||||
}
|
||||
SetPlacement(TOP_LEFT);
|
||||
}
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
int GUIImage::Render(void)
|
||||
{
|
||||
if (isHighlighted && mHighlightImage && mHighlightImage->GetResource()) {
|
||||
if (isHighlighted && mHighlightImage && mHighlightImage->GetResource()) {
|
||||
gr_blit(mHighlightImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
|
||||
return 0;
|
||||
} else if (!mImage || !mImage->GetResource()) return -1;
|
||||
gr_blit(mImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
|
||||
return 0;
|
||||
}
|
||||
else if (!mImage || !mImage->GetResource())
|
||||
return -1;
|
||||
|
||||
gr_blit(mImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GUIImage::SetRenderPos(int x, int y, int w, int h)
|
||||
{
|
||||
if (w || h) return -1;
|
||||
mRenderX = x;
|
||||
mRenderY = y;
|
||||
return 0;
|
||||
if (w || h)
|
||||
return -1;
|
||||
|
||||
mRenderX = x;
|
||||
mRenderY = y;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+54
-52
@@ -29,17 +29,17 @@ extern "C" {
|
||||
#include "../data.hpp"
|
||||
|
||||
GUIInput::GUIInput(xml_node<>* node)
|
||||
: Conditional(node)
|
||||
: Conditional(node)
|
||||
{
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
|
||||
mInputText = NULL;
|
||||
mInputText = NULL;
|
||||
mAction = NULL;
|
||||
mBackground = NULL;
|
||||
mCursor = NULL;
|
||||
mFont = NULL;
|
||||
mRendered = false;
|
||||
mRendered = false;
|
||||
HasMask = false;
|
||||
DrawCursor = false;
|
||||
isLocalChange = true;
|
||||
@@ -52,18 +52,19 @@ GUIInput::GUIInput(xml_node<>* node)
|
||||
ConvertStrToColor("black", &mBackgroundColor);
|
||||
ConvertStrToColor("white", &mCursorColor);
|
||||
|
||||
if (!node) return;
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
// Load text directly from the node
|
||||
mInputText = new GUIText(node);
|
||||
// Load text directly from the node
|
||||
mInputText = new GUIText(node);
|
||||
// Load action directly from the node
|
||||
mAction = new GUIAction(node);
|
||||
|
||||
if (mInputText->Render() < 0)
|
||||
{
|
||||
delete mInputText;
|
||||
mInputText = NULL;
|
||||
}
|
||||
{
|
||||
delete mInputText;
|
||||
mInputText = NULL;
|
||||
}
|
||||
|
||||
// Load the background
|
||||
child = node->first_node("background");
|
||||
@@ -114,18 +115,18 @@ GUIInput::GUIInput(xml_node<>* node)
|
||||
DrawCursor = HasInputFocus;
|
||||
|
||||
// Load the font, and possibly override the color
|
||||
child = node->first_node("font");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("resource");
|
||||
if (attr) {
|
||||
mFont = PageManager::FindResource(attr->value());
|
||||
child = node->first_node("font");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("resource");
|
||||
if (attr) {
|
||||
mFont = PageManager::FindResource(attr->value());
|
||||
gr_getFontDetails(mFont ? mFont->GetResource() : NULL, &mFontHeight, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
child = node->first_node("text");
|
||||
if (child) mText = child->value();
|
||||
if (child) mText = child->value();
|
||||
mLastValue = gui_parse_text(mText);
|
||||
|
||||
child = node->first_node("data");
|
||||
@@ -175,7 +176,7 @@ GUIInput::GUIInput(xml_node<>* node)
|
||||
}
|
||||
}
|
||||
|
||||
// Load the placement
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH);
|
||||
SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
|
||||
|
||||
@@ -190,17 +191,15 @@ GUIInput::GUIInput(xml_node<>* node)
|
||||
|
||||
isLocalChange = false;
|
||||
HandleTextLocation(-3);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
GUIInput::~GUIInput()
|
||||
{
|
||||
if (mInputText) delete mInputText;
|
||||
if (mBackground) delete mBackground;
|
||||
if (mCursor) delete mCursor;
|
||||
if (mFont) delete mFont;
|
||||
if (mAction) delete mAction;
|
||||
if (mInputText) delete mInputText;
|
||||
if (mBackground) delete mBackground;
|
||||
if (mCursor) delete mCursor;
|
||||
if (mFont) delete mFont;
|
||||
if (mAction) delete mAction;
|
||||
}
|
||||
|
||||
int GUIInput::HandleTextLocation(int x)
|
||||
@@ -209,7 +208,8 @@ int GUIInput::HandleTextLocation(int x)
|
||||
string displayValue, originalValue, insertChar;
|
||||
void* fontResource = NULL;
|
||||
|
||||
if (mFont) fontResource = mFont->GetResource();
|
||||
if (mFont)
|
||||
fontResource = mFont->GetResource();
|
||||
|
||||
DataManager::GetValue(mVariable, originalValue);
|
||||
displayValue = originalValue;
|
||||
@@ -229,9 +229,10 @@ int GUIInput::HandleTextLocation(int x)
|
||||
mRendered = false;
|
||||
return 0;
|
||||
}
|
||||
if (skipChars && skipChars < displayValue.size()) {
|
||||
|
||||
if (skipChars && skipChars < displayValue.size())
|
||||
displayValue.erase(0, skipChars);
|
||||
}
|
||||
|
||||
textWidth = gr_measureEx(displayValue.c_str(), fontResource);
|
||||
mRendered = false;
|
||||
|
||||
@@ -239,9 +240,9 @@ int GUIInput::HandleTextLocation(int x)
|
||||
|
||||
if (x < -1000) {
|
||||
// No change in scrolling
|
||||
if (x == -1003) {
|
||||
if (x == -1003)
|
||||
mCursorLocation = -1;
|
||||
}
|
||||
|
||||
if (mCursorLocation == -1) {
|
||||
displayValue = originalValue;
|
||||
skipChars = 0;
|
||||
@@ -372,15 +373,15 @@ int GUIInput::HandleTextLocation(int x)
|
||||
int GUIInput::Render(void)
|
||||
{
|
||||
if (!isConditionTrue())
|
||||
{
|
||||
mRendered = false;
|
||||
return 0;
|
||||
}
|
||||
{
|
||||
mRendered = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* fontResource = NULL;
|
||||
if (mFont) fontResource = mFont->GetResource();
|
||||
|
||||
// First step, fill background
|
||||
// First step, fill background
|
||||
gr_color(mBackgroundColor.red, mBackgroundColor.green, mBackgroundColor.blue, 255);
|
||||
gr_fill(mRenderX, mRenderY, mRenderW, mRenderH);
|
||||
|
||||
@@ -394,11 +395,11 @@ int GUIInput::Render(void)
|
||||
|
||||
int ret = 0;
|
||||
|
||||
// Render the text
|
||||
// Render the text
|
||||
mInputText->SetRenderPos(mRenderX + scrollingX, mFontY);
|
||||
mInputText->SetMaxWidth(mRenderW - scrollingX);
|
||||
if (mInputText) ret = mInputText->Render();
|
||||
if (ret < 0) return ret;
|
||||
if (mInputText) ret = mInputText->Render();
|
||||
if (ret < 0) return ret;
|
||||
|
||||
if (HasInputFocus && DrawCursor) {
|
||||
// Render the cursor
|
||||
@@ -451,21 +452,21 @@ int GUIInput::Render(void)
|
||||
gr_fill(cursorX, mFontY, CursorWidth, mFontHeight);
|
||||
}
|
||||
|
||||
mRendered = true;
|
||||
return ret;
|
||||
mRendered = true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int GUIInput::Update(void)
|
||||
{
|
||||
if (!isConditionTrue()) return (mRendered ? 2 : 0);
|
||||
if (!mRendered) return 2;
|
||||
if (!isConditionTrue()) return (mRendered ? 2 : 0);
|
||||
if (!mRendered) return 2;
|
||||
|
||||
int ret = 0;
|
||||
int ret = 0;
|
||||
|
||||
if (mInputText) ret = mInputText->Update();
|
||||
if (ret < 0) return ret;
|
||||
if (mInputText) ret = mInputText->Update();
|
||||
if (ret < 0) return ret;
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int GUIInput::GetSelection(int x, int y)
|
||||
@@ -476,14 +477,15 @@ int GUIInput::GetSelection(int x, int y)
|
||||
|
||||
int GUIInput::NotifyTouch(TOUCH_STATE state, int x, int y)
|
||||
{
|
||||
static int startSelection = -1;
|
||||
static int startSelection = -1;
|
||||
int textWidth;
|
||||
string displayValue, originalValue;
|
||||
void* fontResource = NULL;
|
||||
|
||||
if (mFont) fontResource = mFont->GetResource();
|
||||
|
||||
if (!isConditionTrue()) return -1;
|
||||
if (!isConditionTrue())
|
||||
return -1;
|
||||
|
||||
if (!HasInputFocus) {
|
||||
if (state != TOUCH_RELEASE)
|
||||
@@ -569,7 +571,7 @@ int GUIInput::NotifyTouch(TOUCH_STATE state, int x, int y)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GUIInput::NotifyVarChange(std::string varName, std::string value)
|
||||
|
||||
+23
-23
@@ -191,12 +191,12 @@ GUIListBox::GUIListBox(xml_node<>* node)
|
||||
|
||||
attr = child->first_attribute("highlightcolor");
|
||||
memset(&mFontHighlightColor, 0, sizeof(COLOR));
|
||||
if (attr)
|
||||
{
|
||||
std::string color = attr->value();
|
||||
if (attr)
|
||||
{
|
||||
std::string color = attr->value();
|
||||
ConvertStrToColor(color, &mFontHighlightColor);
|
||||
hasFontHighlightColor = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load the separator if it exists
|
||||
@@ -323,15 +323,15 @@ GUIListBox::GUIListBox(xml_node<>* node)
|
||||
|
||||
// Get the data for the list
|
||||
child = node->first_node("listitem");
|
||||
if (!child) return;
|
||||
if (!child) return;
|
||||
|
||||
while (child)
|
||||
{
|
||||
ListData data;
|
||||
{
|
||||
ListData data;
|
||||
|
||||
attr = child->first_attribute("name");
|
||||
if (!attr) return;
|
||||
data.displayName = attr->value();
|
||||
if (!attr) return;
|
||||
data.displayName = attr->value();
|
||||
|
||||
data.variableValue = child->value();
|
||||
if (child->value() == currentValue) {
|
||||
@@ -340,10 +340,10 @@ GUIListBox::GUIListBox(xml_node<>* node)
|
||||
data.selected = 0;
|
||||
}
|
||||
|
||||
mList.push_back(data);
|
||||
mList.push_back(data);
|
||||
|
||||
child = child->next_sibling("listitem");
|
||||
}
|
||||
child = child->next_sibling("listitem");
|
||||
}
|
||||
}
|
||||
|
||||
GUIListBox::~GUIListBox()
|
||||
@@ -430,21 +430,21 @@ int GUIListBox::Render(void)
|
||||
}
|
||||
|
||||
if (mList.at(line + mStart).selected != 0)
|
||||
{
|
||||
icon = mIconSelected;
|
||||
{
|
||||
icon = mIconSelected;
|
||||
currentIconHeight = mSelectedIconHeight;
|
||||
currentIconWidth = mSelectedIconWidth;
|
||||
currentIconOffsetY = SelectedIconOffsetY;
|
||||
currentIconOffsetX = SelectedIconOffsetX;
|
||||
}
|
||||
else
|
||||
{
|
||||
icon = mIconUnselected;
|
||||
}
|
||||
else
|
||||
{
|
||||
icon = mIconUnselected;
|
||||
currentIconHeight = mSelectedIconHeight;
|
||||
currentIconWidth = mSelectedIconWidth;
|
||||
currentIconOffsetY = SelectedIconOffsetY;
|
||||
currentIconOffsetX = SelectedIconOffsetX;
|
||||
}
|
||||
}
|
||||
|
||||
if (icon && icon->GetResource())
|
||||
{
|
||||
@@ -758,8 +758,8 @@ int GUIListBox::NotifyVarChange(std::string varName, std::string value)
|
||||
}
|
||||
}
|
||||
if (varName == mVariable)
|
||||
{
|
||||
int i, listSize = mList.size(), selected_index = 0;
|
||||
{
|
||||
int i, listSize = mList.size(), selected_index = 0;
|
||||
|
||||
currentValue = value;
|
||||
|
||||
@@ -783,8 +783,8 @@ int GUIListBox::NotifyVarChange(std::string varName, std::string value)
|
||||
}
|
||||
|
||||
mUpdate = 1;
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+396
-401
File diff suppressed because it is too large
Load Diff
+588
-561
File diff suppressed because it is too large
Load Diff
+63
-63
@@ -4,10 +4,10 @@
|
||||
#define _PAGES_HEADER_HPP
|
||||
|
||||
typedef struct {
|
||||
unsigned char red;
|
||||
unsigned char green;
|
||||
unsigned char blue;
|
||||
unsigned char alpha;
|
||||
unsigned char red;
|
||||
unsigned char green;
|
||||
unsigned char blue;
|
||||
unsigned char alpha;
|
||||
} COLOR;
|
||||
|
||||
// Utility Functions
|
||||
@@ -26,110 +26,110 @@ class InputObject;
|
||||
class Page
|
||||
{
|
||||
public:
|
||||
virtual ~Page() {}
|
||||
virtual ~Page() {}
|
||||
|
||||
public:
|
||||
Page(xml_node<>* page, xml_node<>* templates = NULL);
|
||||
std::string GetName(void) { return mName; }
|
||||
Page(xml_node<>* page, xml_node<>* templates = NULL);
|
||||
std::string GetName(void) { return mName; }
|
||||
|
||||
public:
|
||||
virtual int Render(void);
|
||||
virtual int Update(void);
|
||||
virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
|
||||
virtual int NotifyKey(int key);
|
||||
virtual int Render(void);
|
||||
virtual int Update(void);
|
||||
virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
|
||||
virtual int NotifyKey(int key);
|
||||
virtual int NotifyKeyboard(int key);
|
||||
virtual int SetKeyBoardFocus(int inFocus);
|
||||
virtual int NotifyVarChange(std::string varName, std::string value);
|
||||
virtual void SetPageFocus(int inFocus);
|
||||
virtual int NotifyVarChange(std::string varName, std::string value);
|
||||
virtual void SetPageFocus(int inFocus);
|
||||
|
||||
protected:
|
||||
std::string mName;
|
||||
std::vector<RenderObject*> mRenders;
|
||||
std::vector<ActionObject*> mActions;
|
||||
std::string mName;
|
||||
std::vector<RenderObject*> mRenders;
|
||||
std::vector<ActionObject*> mActions;
|
||||
std::vector<InputObject*> mInputs;
|
||||
|
||||
ActionObject* mTouchStart;
|
||||
COLOR mBackground;
|
||||
ActionObject* mTouchStart;
|
||||
COLOR mBackground;
|
||||
|
||||
protected:
|
||||
bool ProcessNode(xml_node<>* page, xml_node<>* templates = NULL, int depth = 0);
|
||||
bool ProcessNode(xml_node<>* page, xml_node<>* templates = NULL, int depth = 0);
|
||||
};
|
||||
|
||||
class PageSet
|
||||
{
|
||||
public:
|
||||
PageSet(char* xmlFile);
|
||||
virtual ~PageSet();
|
||||
PageSet(char* xmlFile);
|
||||
virtual ~PageSet();
|
||||
|
||||
public:
|
||||
int Load(ZipArchive* package);
|
||||
int Load(ZipArchive* package);
|
||||
|
||||
Page* FindPage(std::string name);
|
||||
int SetPage(std::string page);
|
||||
Page* FindPage(std::string name);
|
||||
int SetPage(std::string page);
|
||||
int SetOverlay(Page* page);
|
||||
Resource* FindResource(std::string name);
|
||||
Resource* FindResource(std::string name);
|
||||
|
||||
// Helper routine for identifing if we're the current page
|
||||
int IsCurrentPage(Page* page);
|
||||
// Helper routine for identifing if we're the current page
|
||||
int IsCurrentPage(Page* page);
|
||||
|
||||
// These are routing routines
|
||||
int Render(void);
|
||||
int Update(void);
|
||||
int NotifyTouch(TOUCH_STATE state, int x, int y);
|
||||
int NotifyKey(int key);
|
||||
// These are routing routines
|
||||
int Render(void);
|
||||
int Update(void);
|
||||
int NotifyTouch(TOUCH_STATE state, int x, int y);
|
||||
int NotifyKey(int key);
|
||||
int NotifyKeyboard(int key);
|
||||
int SetKeyBoardFocus(int inFocus);
|
||||
int NotifyVarChange(std::string varName, std::string value);
|
||||
int NotifyVarChange(std::string varName, std::string value);
|
||||
|
||||
protected:
|
||||
int LoadPages(xml_node<>* pages, xml_node<>* templates = NULL);
|
||||
int LoadVariables(xml_node<>* vars);
|
||||
int LoadPages(xml_node<>* pages, xml_node<>* templates = NULL);
|
||||
int LoadVariables(xml_node<>* vars);
|
||||
|
||||
protected:
|
||||
char* mXmlFile;
|
||||
xml_document<> mDoc;
|
||||
ResourceManager* mResources;
|
||||
std::vector<Page*> mPages;
|
||||
Page* mCurrentPage;
|
||||
Page* mOverlayPage; // This is a special case, used for "locking" the screen
|
||||
char* mXmlFile;
|
||||
xml_document<> mDoc;
|
||||
ResourceManager* mResources;
|
||||
std::vector<Page*> mPages;
|
||||
Page* mCurrentPage;
|
||||
Page* mOverlayPage; // This is a special case, used for "locking" the screen
|
||||
};
|
||||
|
||||
class PageManager
|
||||
{
|
||||
public:
|
||||
// Used by GUI
|
||||
static int LoadPackage(std::string name, std::string package, std::string startpage);
|
||||
static PageSet* SelectPackage(std::string name);
|
||||
static int ReloadPackage(std::string name, std::string package);
|
||||
static void ReleasePackage(std::string name);
|
||||
// Used by GUI
|
||||
static int LoadPackage(std::string name, std::string package, std::string startpage);
|
||||
static PageSet* SelectPackage(std::string name);
|
||||
static int ReloadPackage(std::string name, std::string package);
|
||||
static void ReleasePackage(std::string name);
|
||||
|
||||
// Used for actions and pages
|
||||
static int ChangePage(std::string name);
|
||||
// Used for actions and pages
|
||||
static int ChangePage(std::string name);
|
||||
static int ChangeOverlay(std::string name);
|
||||
static Resource* FindResource(std::string name);
|
||||
static Resource* FindResource(std::string package, std::string name);
|
||||
static Resource* FindResource(std::string name);
|
||||
static Resource* FindResource(std::string package, std::string name);
|
||||
|
||||
// Used for console-only mode - Can be reverted via ChangePage
|
||||
static int SwitchToConsole(void);
|
||||
// Used for console-only mode - Can be reverted via ChangePage
|
||||
static int SwitchToConsole(void);
|
||||
|
||||
// Helper to identify if a particular page is the active page
|
||||
static int IsCurrentPage(Page* page);
|
||||
// Helper to identify if a particular page is the active page
|
||||
static int IsCurrentPage(Page* page);
|
||||
|
||||
// These are routing routines
|
||||
static int Render(void);
|
||||
static int Update(void);
|
||||
static int NotifyTouch(TOUCH_STATE state, int x, int y);
|
||||
static int NotifyKey(int key);
|
||||
// These are routing routines
|
||||
static int Render(void);
|
||||
static int Update(void);
|
||||
static int NotifyTouch(TOUCH_STATE state, int x, int y);
|
||||
static int NotifyKey(int key);
|
||||
static int NotifyKeyboard(int key);
|
||||
static int SetKeyBoardFocus(int inFocus);
|
||||
static int NotifyVarChange(std::string varName, std::string value);
|
||||
static int NotifyVarChange(std::string varName, std::string value);
|
||||
|
||||
protected:
|
||||
static PageSet* FindPackage(std::string name);
|
||||
static PageSet* FindPackage(std::string name);
|
||||
|
||||
protected:
|
||||
static std::map<std::string, PageSet*> mPageSets;
|
||||
static PageSet* mCurrentSet;
|
||||
static std::map<std::string, PageSet*> mPageSets;
|
||||
static PageSet* mCurrentSet;
|
||||
static PageSet* mBaseSet;
|
||||
};
|
||||
|
||||
|
||||
+15
-15
@@ -193,12 +193,12 @@ GUIPartitionList::GUIPartitionList(xml_node<>* node)
|
||||
|
||||
attr = child->first_attribute("highlightcolor");
|
||||
memset(&mFontHighlightColor, 0, sizeof(COLOR));
|
||||
if (attr)
|
||||
{
|
||||
std::string color = attr->value();
|
||||
if (attr)
|
||||
{
|
||||
std::string color = attr->value();
|
||||
ConvertStrToColor(color, &mFontHighlightColor);
|
||||
hasFontHighlightColor = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load the separator if it exists
|
||||
@@ -433,21 +433,21 @@ int GUIPartitionList::Render(void)
|
||||
}
|
||||
|
||||
if (mList.at(line + mStart).selected != 0)
|
||||
{
|
||||
icon = mIconSelected;
|
||||
{
|
||||
icon = mIconSelected;
|
||||
currentIconHeight = mSelectedIconHeight;
|
||||
currentIconWidth = mSelectedIconWidth;
|
||||
currentIconOffsetY = SelectedIconOffsetY;
|
||||
currentIconOffsetX = SelectedIconOffsetX;
|
||||
}
|
||||
else
|
||||
{
|
||||
icon = mIconUnselected;
|
||||
}
|
||||
else
|
||||
{
|
||||
icon = mIconUnselected;
|
||||
currentIconHeight = mSelectedIconHeight;
|
||||
currentIconWidth = mSelectedIconWidth;
|
||||
currentIconOffsetY = SelectedIconOffsetY;
|
||||
currentIconOffsetX = SelectedIconOffsetX;
|
||||
}
|
||||
}
|
||||
|
||||
if (icon && icon->GetResource())
|
||||
{
|
||||
@@ -827,8 +827,8 @@ int GUIPartitionList::NotifyVarChange(std::string varName, std::string value)
|
||||
}
|
||||
}
|
||||
if (varName == mVariable && !mUpdate)
|
||||
{
|
||||
if (ListType == "storage") {
|
||||
{
|
||||
if (ListType == "storage") {
|
||||
int i, listSize = mList.size(), selected_index = 0;
|
||||
|
||||
currentValue = value;
|
||||
@@ -856,8 +856,8 @@ int GUIPartitionList::NotifyVarChange(std::string varName, std::string value)
|
||||
}
|
||||
|
||||
mUpdate = 1;
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+154
-142
@@ -27,188 +27,200 @@ extern "C" {
|
||||
|
||||
GUIProgressBar::GUIProgressBar(xml_node<>* node)
|
||||
{
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
|
||||
mEmptyBar = NULL;
|
||||
mFullBar = NULL;
|
||||
mLastPos = 0;
|
||||
mSlide = 0.0;
|
||||
mSlideInc = 0.0;
|
||||
mEmptyBar = NULL;
|
||||
mFullBar = NULL;
|
||||
mLastPos = 0;
|
||||
mSlide = 0.0;
|
||||
mSlideInc = 0.0;
|
||||
|
||||
if (!node)
|
||||
{
|
||||
LOGERR("GUIProgressBar created without XML node\n");
|
||||
return;
|
||||
}
|
||||
if (!node)
|
||||
{
|
||||
LOGERR("GUIProgressBar created without XML node\n");
|
||||
return;
|
||||
}
|
||||
|
||||
child = node->first_node("resource");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("empty");
|
||||
if (attr)
|
||||
mEmptyBar = PageManager::FindResource(attr->value());
|
||||
child = node->first_node("resource");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("empty");
|
||||
if (attr)
|
||||
mEmptyBar = PageManager::FindResource(attr->value());
|
||||
|
||||
attr = child->first_attribute("full");
|
||||
if (attr)
|
||||
mFullBar = PageManager::FindResource(attr->value());
|
||||
}
|
||||
attr = child->first_attribute("full");
|
||||
if (attr)
|
||||
mFullBar = PageManager::FindResource(attr->value());
|
||||
}
|
||||
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY);
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY);
|
||||
|
||||
// Load the data
|
||||
child = node->first_node("data");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("min");
|
||||
if (attr) mMinValVar = attr->value();
|
||||
// Load the data
|
||||
child = node->first_node("data");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("min");
|
||||
if (attr) mMinValVar = attr->value();
|
||||
|
||||
attr = child->first_attribute("max");
|
||||
if (attr) mMaxValVar = attr->value();
|
||||
attr = child->first_attribute("max");
|
||||
if (attr) mMaxValVar = attr->value();
|
||||
|
||||
attr = child->first_attribute("name");
|
||||
if (attr) mCurValVar = attr->value();
|
||||
}
|
||||
attr = child->first_attribute("name");
|
||||
if (attr) mCurValVar = attr->value();
|
||||
}
|
||||
|
||||
if (mEmptyBar && mEmptyBar->GetResource())
|
||||
{
|
||||
mRenderW = gr_get_width(mEmptyBar->GetResource());
|
||||
mRenderH = gr_get_height(mEmptyBar->GetResource());
|
||||
}
|
||||
if (mEmptyBar && mEmptyBar->GetResource())
|
||||
{
|
||||
mRenderW = gr_get_width(mEmptyBar->GetResource());
|
||||
mRenderH = gr_get_height(mEmptyBar->GetResource());
|
||||
}
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
int GUIProgressBar::Render(void)
|
||||
{
|
||||
// This handles making sure timing updates occur
|
||||
Update();
|
||||
return RenderInternal();
|
||||
// This handles making sure timing updates occur
|
||||
Update();
|
||||
return RenderInternal();
|
||||
}
|
||||
|
||||
int GUIProgressBar::RenderInternal(void)
|
||||
{
|
||||
if (!mEmptyBar || !mEmptyBar->GetResource()) return -1;
|
||||
if (!mFullBar || !mFullBar->GetResource()) return -1;
|
||||
if (!mEmptyBar || !mEmptyBar->GetResource())
|
||||
return -1;
|
||||
|
||||
gr_blit(mEmptyBar->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
|
||||
gr_blit(mFullBar->GetResource(), 0, 0, mLastPos, mRenderH, mRenderX, mRenderY);
|
||||
return 0;
|
||||
if (!mFullBar || !mFullBar->GetResource())
|
||||
return -1;
|
||||
|
||||
gr_blit(mEmptyBar->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
|
||||
gr_blit(mFullBar->GetResource(), 0, 0, mLastPos, mRenderH, mRenderX, mRenderY);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GUIProgressBar::Update(void)
|
||||
{
|
||||
std::string str;
|
||||
int min, max, cur, pos;
|
||||
std::string str;
|
||||
int min, max, cur, pos;
|
||||
|
||||
if (mMinValVar.empty()) min = 0;
|
||||
else
|
||||
{
|
||||
str.clear();
|
||||
if (atoi(mMinValVar.c_str()) != 0) str = mMinValVar;
|
||||
else DataManager::GetValue(mMinValVar, str);
|
||||
min = atoi(str.c_str());
|
||||
}
|
||||
if (mMinValVar.empty())
|
||||
min = 0;
|
||||
else
|
||||
{
|
||||
str.clear();
|
||||
if (atoi(mMinValVar.c_str()) != 0)
|
||||
str = mMinValVar;
|
||||
else
|
||||
DataManager::GetValue(mMinValVar, str);
|
||||
min = atoi(str.c_str());
|
||||
}
|
||||
|
||||
if (mMaxValVar.empty()) max = 100;
|
||||
else
|
||||
{
|
||||
str.clear();
|
||||
if (atoi(mMaxValVar.c_str()) != 0) str = mMaxValVar;
|
||||
else DataManager::GetValue(mMaxValVar, str);
|
||||
max = atoi(str.c_str());
|
||||
}
|
||||
if (mMaxValVar.empty())
|
||||
max = 100;
|
||||
else
|
||||
{
|
||||
str.clear();
|
||||
if (atoi(mMaxValVar.c_str()) != 0)
|
||||
str = mMaxValVar;
|
||||
else
|
||||
DataManager::GetValue(mMaxValVar, str);
|
||||
max = atoi(str.c_str());
|
||||
}
|
||||
|
||||
str.clear();
|
||||
DataManager::GetValue(mCurValVar, str);
|
||||
cur = atoi(str.c_str());
|
||||
str.clear();
|
||||
DataManager::GetValue(mCurValVar, str);
|
||||
cur = atoi(str.c_str());
|
||||
|
||||
// Do slide, if needed
|
||||
if (mSlideFrames)
|
||||
{
|
||||
mSlide += mSlideInc;
|
||||
mSlideFrames--;
|
||||
if (cur != (int) mSlide)
|
||||
{
|
||||
cur = (int) mSlide;
|
||||
DataManager::SetValue(mCurValVar, cur);
|
||||
}
|
||||
}
|
||||
// Do slide, if needed
|
||||
if (mSlideFrames)
|
||||
{
|
||||
mSlide += mSlideInc;
|
||||
mSlideFrames--;
|
||||
if (cur != (int) mSlide)
|
||||
{
|
||||
cur = (int) mSlide;
|
||||
DataManager::SetValue(mCurValVar, cur);
|
||||
}
|
||||
}
|
||||
|
||||
// Normalize to 0
|
||||
max -= min;
|
||||
cur -= min;
|
||||
min = 0;
|
||||
// Normalize to 0
|
||||
max -= min;
|
||||
cur -= min;
|
||||
min = 0;
|
||||
|
||||
if (cur < min) cur = min;
|
||||
if (cur > max) cur = max;
|
||||
if (cur < min) cur = min;
|
||||
if (cur > max) cur = max;
|
||||
|
||||
if (max == 0) pos = 0;
|
||||
else pos = (cur * mRenderW) / max;
|
||||
if (max == 0) pos = 0;
|
||||
else pos = (cur * mRenderW) / max;
|
||||
|
||||
if (pos == mLastPos) return 0;
|
||||
mLastPos = pos;
|
||||
if (RenderInternal() != 0) return -1;
|
||||
return 2;
|
||||
if (pos == mLastPos)
|
||||
return 0;
|
||||
|
||||
mLastPos = pos;
|
||||
|
||||
if (RenderInternal() != 0)
|
||||
return -1;
|
||||
return 2;
|
||||
}
|
||||
|
||||
int GUIProgressBar::NotifyVarChange(std::string varName, std::string value)
|
||||
{
|
||||
static int nextPush = 0;
|
||||
static int nextPush = 0;
|
||||
|
||||
if (varName.empty())
|
||||
{
|
||||
nextPush = 0;
|
||||
mLastPos = 0;
|
||||
mSlide = 0.0;
|
||||
mSlideInc = 0.0;
|
||||
return 0;
|
||||
}
|
||||
if (varName.empty())
|
||||
{
|
||||
nextPush = 0;
|
||||
mLastPos = 0;
|
||||
mSlide = 0.0;
|
||||
mSlideInc = 0.0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (varName == "ui_progress_portion" || varName == "ui_progress_frames")
|
||||
{
|
||||
std::string str;
|
||||
int cur;
|
||||
if (varName == "ui_progress_portion" || varName == "ui_progress_frames")
|
||||
{
|
||||
std::string str;
|
||||
int cur;
|
||||
|
||||
if (mSlideFrames)
|
||||
{
|
||||
mSlide += (mSlideInc * mSlideFrames);
|
||||
cur = (int) mSlide;
|
||||
DataManager::SetValue(mCurValVar, cur);
|
||||
mSlideFrames = 0;
|
||||
}
|
||||
if (mSlideFrames)
|
||||
{
|
||||
mSlide += (mSlideInc * mSlideFrames);
|
||||
cur = (int) mSlide;
|
||||
DataManager::SetValue(mCurValVar, cur);
|
||||
mSlideFrames = 0;
|
||||
}
|
||||
|
||||
if (nextPush)
|
||||
{
|
||||
mSlide += nextPush;
|
||||
cur = (int) mSlide;
|
||||
DataManager::SetValue(mCurValVar, cur);
|
||||
nextPush = 0;
|
||||
}
|
||||
if (nextPush)
|
||||
{
|
||||
mSlide += nextPush;
|
||||
cur = (int) mSlide;
|
||||
DataManager::SetValue(mCurValVar, cur);
|
||||
nextPush = 0;
|
||||
}
|
||||
|
||||
if (varName == "ui_progress_portion") mSlide = atof(value.c_str());
|
||||
else
|
||||
{
|
||||
mSlideFrames = atol(value.c_str());
|
||||
if (mSlideFrames == 0)
|
||||
{
|
||||
// We're just holding this progress until the next push
|
||||
nextPush = mSlide;
|
||||
}
|
||||
}
|
||||
if (varName == "ui_progress_portion") mSlide = atof(value.c_str());
|
||||
else
|
||||
{
|
||||
mSlideFrames = atol(value.c_str());
|
||||
if (mSlideFrames == 0)
|
||||
{
|
||||
// We're just holding this progress until the next push
|
||||
nextPush = mSlide;
|
||||
}
|
||||
}
|
||||
|
||||
if (mSlide > 0 && mSlideFrames > 0)
|
||||
{
|
||||
// Get the current position
|
||||
str.clear();
|
||||
DataManager::GetValue(mCurValVar, str);
|
||||
cur = atoi(str.c_str());
|
||||
if (mSlide > 0 && mSlideFrames > 0)
|
||||
{
|
||||
// Get the current position
|
||||
str.clear();
|
||||
DataManager::GetValue(mCurValVar, str);
|
||||
cur = atoi(str.c_str());
|
||||
|
||||
mSlideInc = (float) mSlide / (float) mSlideFrames;
|
||||
mSlide = cur;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
mSlideInc = (float) mSlide / (float) mSlideFrames;
|
||||
mSlide = cur;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+156
-158
@@ -32,59 +32,56 @@ extern "C" {
|
||||
|
||||
Resource::Resource(xml_node<>* node, ZipArchive* pZip)
|
||||
{
|
||||
if (node && node->first_attribute("name"))
|
||||
mName = node->first_attribute("name")->value();
|
||||
if (node && node->first_attribute("name"))
|
||||
mName = node->first_attribute("name")->value();
|
||||
}
|
||||
|
||||
|
||||
int Resource::ExtractResource(ZipArchive* pZip,
|
||||
std::string folderName,
|
||||
std::string fileName,
|
||||
std::string fileExtn,
|
||||
std::string destFile)
|
||||
int Resource::ExtractResource(ZipArchive* pZip, std::string folderName, std::string fileName, std::string fileExtn, std::string destFile)
|
||||
{
|
||||
if (!pZip) return -1;
|
||||
if (!pZip)
|
||||
return -1;
|
||||
|
||||
std::string src = folderName + "/" + fileName + fileExtn;
|
||||
std::string src = folderName + "/" + fileName + fileExtn;
|
||||
|
||||
const ZipEntry* binary = mzFindZipEntry(pZip, src.c_str());
|
||||
if (binary == NULL) {
|
||||
return -1;
|
||||
if (binary == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
unlink(destFile.c_str());
|
||||
int fd = creat(destFile.c_str(), 0666);
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
unlink(destFile.c_str());
|
||||
int fd = creat(destFile.c_str(), 0666);
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
|
||||
int ret = 0;
|
||||
if (!mzExtractZipEntryToFile(pZip, binary, fd))
|
||||
ret = -1;
|
||||
int ret = 0;
|
||||
if (!mzExtractZipEntryToFile(pZip, binary, fd))
|
||||
ret = -1;
|
||||
|
||||
close(fd);
|
||||
return ret;
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
FontResource::FontResource(xml_node<>* node, ZipArchive* pZip)
|
||||
: Resource(node, pZip)
|
||||
{
|
||||
std::string file;
|
||||
std::string file;
|
||||
|
||||
mFont = NULL;
|
||||
if (!node) return;
|
||||
mFont = NULL;
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
if (node->first_attribute("filename"))
|
||||
file = node->first_attribute("filename")->value();
|
||||
if (node->first_attribute("filename"))
|
||||
file = node->first_attribute("filename")->value();
|
||||
|
||||
if (ExtractResource(pZip, "fonts", file, ".dat", TMP_RESOURCE_NAME) == 0)
|
||||
{
|
||||
mFont = gr_loadFont(TMP_RESOURCE_NAME);
|
||||
unlink(TMP_RESOURCE_NAME);
|
||||
}
|
||||
else
|
||||
{
|
||||
mFont = gr_loadFont(file.c_str());
|
||||
}
|
||||
if (ExtractResource(pZip, "fonts", file, ".dat", TMP_RESOURCE_NAME) == 0)
|
||||
{
|
||||
mFont = gr_loadFont(TMP_RESOURCE_NAME);
|
||||
unlink(TMP_RESOURCE_NAME);
|
||||
}
|
||||
else
|
||||
{
|
||||
mFont = gr_loadFont(file.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
FontResource::~FontResource()
|
||||
@@ -94,115 +91,118 @@ FontResource::~FontResource()
|
||||
ImageResource::ImageResource(xml_node<>* node, ZipArchive* pZip)
|
||||
: Resource(node, pZip)
|
||||
{
|
||||
std::string file;
|
||||
std::string file;
|
||||
|
||||
mSurface = NULL;
|
||||
if (!node) return;
|
||||
mSurface = NULL;
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
if (node->first_attribute("filename"))
|
||||
file = node->first_attribute("filename")->value();
|
||||
if (node->first_attribute("filename"))
|
||||
file = node->first_attribute("filename")->value();
|
||||
|
||||
if (ExtractResource(pZip, "images", file, ".png", TMP_RESOURCE_NAME) == 0)
|
||||
{
|
||||
res_create_surface(TMP_RESOURCE_NAME, &mSurface);
|
||||
unlink(TMP_RESOURCE_NAME);
|
||||
} else if (ExtractResource(pZip, "images", file, "", TMP_RESOURCE_NAME) == 0)
|
||||
{
|
||||
// JPG includes the .jpg extension in the filename so extension should be blank
|
||||
if (ExtractResource(pZip, "images", file, ".png", TMP_RESOURCE_NAME) == 0)
|
||||
{
|
||||
res_create_surface(TMP_RESOURCE_NAME, &mSurface);
|
||||
unlink(TMP_RESOURCE_NAME);
|
||||
}
|
||||
else
|
||||
unlink(TMP_RESOURCE_NAME);
|
||||
}
|
||||
else if (ExtractResource(pZip, "images", file, "", TMP_RESOURCE_NAME) == 0)
|
||||
{
|
||||
// JPG includes the .jpg extension in the filename so extension should be blank
|
||||
res_create_surface(TMP_RESOURCE_NAME, &mSurface);
|
||||
unlink(TMP_RESOURCE_NAME);
|
||||
}
|
||||
else
|
||||
res_create_surface(file.c_str(), &mSurface);
|
||||
}
|
||||
|
||||
ImageResource::~ImageResource()
|
||||
{
|
||||
if (mSurface)
|
||||
res_free_surface(mSurface);
|
||||
if (mSurface)
|
||||
res_free_surface(mSurface);
|
||||
}
|
||||
|
||||
AnimationResource::AnimationResource(xml_node<>* node, ZipArchive* pZip)
|
||||
: Resource(node, pZip)
|
||||
{
|
||||
std::string file;
|
||||
int fileNum = 1;
|
||||
std::string file;
|
||||
int fileNum = 1;
|
||||
|
||||
if (!node) return;
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
if (node->first_attribute("filename"))
|
||||
file = node->first_attribute("filename")->value();
|
||||
if (node->first_attribute("filename"))
|
||||
file = node->first_attribute("filename")->value();
|
||||
|
||||
for ( ; ; )
|
||||
{
|
||||
std::ostringstream fileName;
|
||||
fileName << file << std::setfill ('0') << std::setw (3) << fileNum;
|
||||
for (;;)
|
||||
{
|
||||
std::ostringstream fileName;
|
||||
fileName << file << std::setfill ('0') << std::setw (3) << fileNum;
|
||||
|
||||
gr_surface surface;
|
||||
if (pZip)
|
||||
{
|
||||
if (ExtractResource(pZip, "images", fileName.str(), ".png", TMP_RESOURCE_NAME) != 0)
|
||||
break;
|
||||
|
||||
if (res_create_surface(TMP_RESOURCE_NAME, &surface))
|
||||
break;
|
||||
gr_surface surface;
|
||||
if (pZip)
|
||||
{
|
||||
if (ExtractResource(pZip, "images", fileName.str(), ".png", TMP_RESOURCE_NAME) != 0)
|
||||
break;
|
||||
|
||||
if (res_create_surface(TMP_RESOURCE_NAME, &surface))
|
||||
break;
|
||||
|
||||
unlink(TMP_RESOURCE_NAME);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (res_create_surface(fileName.str().c_str(), &surface))
|
||||
break;
|
||||
}
|
||||
mSurfaces.push_back(surface);
|
||||
fileNum++;
|
||||
}
|
||||
unlink(TMP_RESOURCE_NAME);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (res_create_surface(fileName.str().c_str(), &surface))
|
||||
break;
|
||||
}
|
||||
mSurfaces.push_back(surface);
|
||||
fileNum++;
|
||||
}
|
||||
}
|
||||
|
||||
AnimationResource::~AnimationResource()
|
||||
{
|
||||
std::vector<gr_surface>::iterator it;
|
||||
std::vector<gr_surface>::iterator it;
|
||||
|
||||
for (it = mSurfaces.begin(); it != mSurfaces.end(); ++it)
|
||||
{
|
||||
res_free_surface(*it);
|
||||
}
|
||||
mSurfaces.clear();
|
||||
for (it = mSurfaces.begin(); it != mSurfaces.end(); ++it)
|
||||
res_free_surface(*it);
|
||||
|
||||
mSurfaces.clear();
|
||||
}
|
||||
|
||||
Resource* ResourceManager::FindResource(std::string name)
|
||||
{
|
||||
std::vector<Resource*>::iterator iter;
|
||||
std::vector<Resource*>::iterator iter;
|
||||
|
||||
for (iter = mResources.begin(); iter != mResources.end(); iter++)
|
||||
{
|
||||
if (name == (*iter)->GetName())
|
||||
return (*iter);
|
||||
}
|
||||
return NULL;
|
||||
for (iter = mResources.begin(); iter != mResources.end(); iter++)
|
||||
{
|
||||
if (name == (*iter)->GetName())
|
||||
return (*iter);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ResourceManager::ResourceManager(xml_node<>* resList, ZipArchive* pZip)
|
||||
{
|
||||
xml_node<>* child;
|
||||
xml_node<>* child;
|
||||
|
||||
if (!resList) return;
|
||||
if (!resList)
|
||||
return;
|
||||
|
||||
child = resList->first_node("resource");
|
||||
while (child != NULL)
|
||||
{
|
||||
xml_attribute<>* attr = child->first_attribute("type");
|
||||
if (!attr)
|
||||
break;
|
||||
child = resList->first_node("resource");
|
||||
while (child != NULL)
|
||||
{
|
||||
xml_attribute<>* attr = child->first_attribute("type");
|
||||
if (!attr)
|
||||
break;
|
||||
|
||||
std::string type = attr->value();
|
||||
|
||||
if (type == "font")
|
||||
{
|
||||
FontResource* res = new FontResource(child, pZip);
|
||||
if (res == NULL || res->GetResource() == NULL)
|
||||
{
|
||||
xml_attribute<>* attr_name = child->first_attribute("name");
|
||||
if (type == "font")
|
||||
{
|
||||
FontResource* res = new FontResource(child, pZip);
|
||||
if (res == NULL || res->GetResource() == NULL)
|
||||
{
|
||||
xml_attribute<>* attr_name = child->first_attribute("name");
|
||||
|
||||
if (!attr_name) {
|
||||
std::string res_name = attr_name->value();
|
||||
@@ -210,39 +210,19 @@ ResourceManager::ResourceManager(xml_node<>* resList, ZipArchive* pZip)
|
||||
} else
|
||||
LOGERR("Resource type (%s) failed to load\n", type.c_str());
|
||||
|
||||
delete res;
|
||||
}
|
||||
else
|
||||
{
|
||||
mResources.push_back((Resource*) res);
|
||||
}
|
||||
}
|
||||
else if (type == "image")
|
||||
{
|
||||
ImageResource* res = new ImageResource(child, pZip);
|
||||
if (res == NULL || res->GetResource() == NULL)
|
||||
{
|
||||
xml_attribute<>* attr_name = child->first_attribute("name");
|
||||
|
||||
if (!attr_name) {
|
||||
std::string res_name = attr_name->value();
|
||||
LOGERR("Resource (%s)-(%s) failed to load\n", type.c_str(), res_name.c_str());
|
||||
} else
|
||||
LOGERR("Resource type (%s) failed to load\n", type.c_str());
|
||||
|
||||
delete res;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete res;
|
||||
}
|
||||
else
|
||||
{
|
||||
mResources.push_back((Resource*) res);
|
||||
}
|
||||
}
|
||||
else if (type == "animation")
|
||||
{
|
||||
AnimationResource* res = new AnimationResource(child, pZip);
|
||||
if (res == NULL || res->GetResource() == NULL)
|
||||
{
|
||||
xml_attribute<>* attr_name = child->first_attribute("name");
|
||||
}
|
||||
}
|
||||
else if (type == "image")
|
||||
{
|
||||
ImageResource* res = new ImageResource(child, pZip);
|
||||
if (res == NULL || res->GetResource() == NULL)
|
||||
{
|
||||
xml_attribute<>* attr_name = child->first_attribute("name");
|
||||
|
||||
if (!attr_name) {
|
||||
std::string res_name = attr_name->value();
|
||||
@@ -250,30 +230,48 @@ ResourceManager::ResourceManager(xml_node<>* resList, ZipArchive* pZip)
|
||||
} else
|
||||
LOGERR("Resource type (%s) failed to load\n", type.c_str());
|
||||
|
||||
delete res;
|
||||
}
|
||||
else
|
||||
{
|
||||
mResources.push_back((Resource*) res);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGERR("Resource type (%s) not supported.\n", type.c_str());
|
||||
}
|
||||
delete res;
|
||||
}
|
||||
else
|
||||
{
|
||||
mResources.push_back((Resource*) res);
|
||||
}
|
||||
}
|
||||
else if (type == "animation")
|
||||
{
|
||||
AnimationResource* res = new AnimationResource(child, pZip);
|
||||
if (res == NULL || res->GetResource() == NULL)
|
||||
{
|
||||
xml_attribute<>* attr_name = child->first_attribute("name");
|
||||
|
||||
child = child->next_sibling("resource");
|
||||
}
|
||||
if (!attr_name) {
|
||||
std::string res_name = attr_name->value();
|
||||
LOGERR("Resource (%s)-(%s) failed to load\n", type.c_str(), res_name.c_str());
|
||||
} else
|
||||
LOGERR("Resource type (%s) failed to load\n", type.c_str());
|
||||
|
||||
delete res;
|
||||
}
|
||||
else
|
||||
{
|
||||
mResources.push_back((Resource*) res);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGERR("Resource type (%s) not supported.\n", type.c_str());
|
||||
}
|
||||
|
||||
child = child->next_sibling("resource");
|
||||
}
|
||||
}
|
||||
|
||||
ResourceManager::~ResourceManager()
|
||||
{
|
||||
std::vector<Resource*>::iterator iter;
|
||||
std::vector<Resource*>::iterator iter;
|
||||
|
||||
for (iter = mResources.begin(); iter != mResources.end(); iter++)
|
||||
{
|
||||
delete *iter;
|
||||
}
|
||||
mResources.clear();
|
||||
for (iter = mResources.begin(); iter != mResources.end(); iter++)
|
||||
delete *iter;
|
||||
|
||||
mResources.clear();
|
||||
}
|
||||
|
||||
|
||||
+27
-28
@@ -7,24 +7,24 @@
|
||||
class Resource
|
||||
{
|
||||
public:
|
||||
Resource(xml_node<>* node, ZipArchive* pZip);
|
||||
virtual ~Resource() {}
|
||||
Resource(xml_node<>* node, ZipArchive* pZip);
|
||||
virtual ~Resource() {}
|
||||
|
||||
public:
|
||||
virtual void* GetResource(void) = 0;
|
||||
std::string GetName(void) { return mName; }
|
||||
virtual void* GetResource(void) = 0;
|
||||
std::string GetName(void) { return mName; }
|
||||
|
||||
private:
|
||||
std::string mName;
|
||||
std::string mName;
|
||||
|
||||
protected:
|
||||
static int ExtractResource(ZipArchive* pZip, std::string folderName, std::string fileName, std::string fileExtn, std::string destFile);
|
||||
static int ExtractResource(ZipArchive* pZip, std::string folderName, std::string fileName, std::string fileExtn, std::string destFile);
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
TOUCH_START = 0,
|
||||
TOUCH_DRAG = 1,
|
||||
TOUCH_RELEASE = 2,
|
||||
TOUCH_START = 0,
|
||||
TOUCH_DRAG = 1,
|
||||
TOUCH_RELEASE = 2,
|
||||
TOUCH_HOLD = 3,
|
||||
TOUCH_REPEAT = 4
|
||||
} TOUCH_STATE;
|
||||
@@ -32,56 +32,55 @@ typedef enum {
|
||||
class FontResource : public Resource
|
||||
{
|
||||
public:
|
||||
FontResource(xml_node<>* node, ZipArchive* pZip);
|
||||
virtual ~FontResource();
|
||||
FontResource(xml_node<>* node, ZipArchive* pZip);
|
||||
virtual ~FontResource();
|
||||
|
||||
public:
|
||||
virtual void* GetResource(void) { return mFont; }
|
||||
virtual void* GetResource(void) { return mFont; }
|
||||
|
||||
protected:
|
||||
void* mFont;
|
||||
void* mFont;
|
||||
};
|
||||
|
||||
class ImageResource : public Resource
|
||||
{
|
||||
public:
|
||||
ImageResource(xml_node<>* node, ZipArchive* pZip);
|
||||
virtual ~ImageResource();
|
||||
ImageResource(xml_node<>* node, ZipArchive* pZip);
|
||||
virtual ~ImageResource();
|
||||
|
||||
public:
|
||||
virtual void* GetResource(void) { return mSurface; }
|
||||
virtual void* GetResource(void) { return mSurface; }
|
||||
|
||||
protected:
|
||||
gr_surface mSurface;
|
||||
gr_surface mSurface;
|
||||
};
|
||||
|
||||
class AnimationResource : public Resource
|
||||
{
|
||||
public:
|
||||
AnimationResource(xml_node<>* node, ZipArchive* pZip);
|
||||
virtual ~AnimationResource();
|
||||
AnimationResource(xml_node<>* node, ZipArchive* pZip);
|
||||
virtual ~AnimationResource();
|
||||
|
||||
public:
|
||||
virtual void* GetResource(void) { return mSurfaces.at(0); }
|
||||
virtual void* GetResource(int entry) { return mSurfaces.at(entry); }
|
||||
virtual int GetResourceCount(void) { return mSurfaces.size(); }
|
||||
virtual void* GetResource(void) { return mSurfaces.at(0); }
|
||||
virtual void* GetResource(int entry) { return mSurfaces.at(entry); }
|
||||
virtual int GetResourceCount(void) { return mSurfaces.size(); }
|
||||
|
||||
protected:
|
||||
std::vector<gr_surface> mSurfaces;
|
||||
std::vector<gr_surface> mSurfaces;
|
||||
};
|
||||
|
||||
class ResourceManager
|
||||
{
|
||||
public:
|
||||
ResourceManager(xml_node<>* resList, ZipArchive* pZip);
|
||||
virtual ~ResourceManager();
|
||||
ResourceManager(xml_node<>* resList, ZipArchive* pZip);
|
||||
virtual ~ResourceManager();
|
||||
|
||||
public:
|
||||
Resource* FindResource(std::string name);
|
||||
Resource* FindResource(std::string name);
|
||||
|
||||
private:
|
||||
std::vector<Resource*> mResources;
|
||||
std::vector<Resource*> mResources;
|
||||
};
|
||||
|
||||
#endif // _RESOURCE_HEADER
|
||||
|
||||
|
||||
+100
-100
@@ -28,143 +28,143 @@ extern "C" {
|
||||
|
||||
GUISlider::GUISlider(xml_node<>* node)
|
||||
{
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
|
||||
sAction = NULL;
|
||||
sSlider = NULL;
|
||||
sSliderUsed = NULL;
|
||||
sTouch = NULL;
|
||||
sTouchW = 20;
|
||||
sAction = NULL;
|
||||
sSlider = NULL;
|
||||
sSliderUsed = NULL;
|
||||
sTouch = NULL;
|
||||
sTouchW = 20;
|
||||
|
||||
if (!node)
|
||||
{
|
||||
LOGERR("GUISlider created without XML node\n");
|
||||
return;
|
||||
}
|
||||
if (!node)
|
||||
{
|
||||
LOGERR("GUISlider created without XML node\n");
|
||||
return;
|
||||
}
|
||||
|
||||
child = node->first_node("resource");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("base");
|
||||
if (attr)
|
||||
sSlider = PageManager::FindResource(attr->value());
|
||||
child = node->first_node("resource");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("base");
|
||||
if (attr)
|
||||
sSlider = PageManager::FindResource(attr->value());
|
||||
|
||||
attr = child->first_attribute("used");
|
||||
if (attr)
|
||||
sSliderUsed = PageManager::FindResource(attr->value());
|
||||
attr = child->first_attribute("used");
|
||||
if (attr)
|
||||
sSliderUsed = PageManager::FindResource(attr->value());
|
||||
|
||||
attr = child->first_attribute("touch");
|
||||
if (attr)
|
||||
sTouch = PageManager::FindResource(attr->value());
|
||||
}
|
||||
attr = child->first_attribute("touch");
|
||||
if (attr)
|
||||
sTouch = PageManager::FindResource(attr->value());
|
||||
}
|
||||
|
||||
// Load the placement
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY);
|
||||
|
||||
if (sSlider && sSlider->GetResource())
|
||||
{
|
||||
if (sSlider && sSlider->GetResource())
|
||||
{
|
||||
mRenderW = gr_get_width(sSlider->GetResource());
|
||||
mRenderH = gr_get_height(sSlider->GetResource());
|
||||
}
|
||||
if (sTouch && sTouch->GetResource())
|
||||
{
|
||||
sTouchW = gr_get_width(sTouch->GetResource()); // Width of the "touch image" that follows the touch (arrow)
|
||||
sTouchH = gr_get_height(sTouch->GetResource()); // Height of the "touch image" that follows the touch (arrow)
|
||||
}
|
||||
mRenderH = gr_get_height(sSlider->GetResource());
|
||||
}
|
||||
if (sTouch && sTouch->GetResource())
|
||||
{
|
||||
sTouchW = gr_get_width(sTouch->GetResource()); // Width of the "touch image" that follows the touch (arrow)
|
||||
sTouchH = gr_get_height(sTouch->GetResource()); // Height of the "touch image" that follows the touch (arrow)
|
||||
}
|
||||
|
||||
//LOGINFO("mRenderW: %i mTouchW: %i\n", mRenderW, mTouchW);
|
||||
//LOGINFO("mRenderW: %i mTouchW: %i\n", mRenderW, mTouchW);
|
||||
mActionX = mRenderX;
|
||||
mActionY = mRenderY;
|
||||
mActionW = mRenderW;
|
||||
mActionH = mRenderH;
|
||||
mActionY = mRenderY;
|
||||
mActionW = mRenderW;
|
||||
mActionH = mRenderH;
|
||||
|
||||
sAction = new GUIAction(node);
|
||||
sAction = new GUIAction(node);
|
||||
|
||||
sCurTouchX = mRenderX;
|
||||
sUpdate = 1;
|
||||
|
||||
return;
|
||||
sCurTouchX = mRenderX;
|
||||
sUpdate = 1;
|
||||
}
|
||||
|
||||
GUISlider::~GUISlider()
|
||||
{
|
||||
delete sAction;
|
||||
delete sAction;
|
||||
}
|
||||
|
||||
int GUISlider::Render(void)
|
||||
{
|
||||
if (!sSlider || !sSlider->GetResource()) return -1;
|
||||
if (!sSlider || !sSlider->GetResource())
|
||||
return -1;
|
||||
|
||||
// Draw the slider
|
||||
gr_blit(sSlider->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
|
||||
// Draw the slider
|
||||
gr_blit(sSlider->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
|
||||
|
||||
// Draw the used
|
||||
if (sSliderUsed && sSliderUsed->GetResource() && sCurTouchX > mRenderX)
|
||||
{
|
||||
gr_blit(sSliderUsed->GetResource(), 0, 0, sCurTouchX - mRenderX, mRenderH, mRenderX, mRenderY);
|
||||
}
|
||||
// Draw the used
|
||||
if (sSliderUsed && sSliderUsed->GetResource() && sCurTouchX > mRenderX)
|
||||
gr_blit(sSliderUsed->GetResource(), 0, 0, sCurTouchX - mRenderX, mRenderH, mRenderX, mRenderY);
|
||||
|
||||
// Draw the touch icon
|
||||
if (sTouch && sTouch->GetResource())
|
||||
{
|
||||
gr_blit(sTouch->GetResource(), 0, 0, sTouchW, sTouchH, sCurTouchX, (mRenderY + ((mRenderH - sTouchH) / 2)));
|
||||
}
|
||||
// Draw the touch icon
|
||||
if (sTouch && sTouch->GetResource())
|
||||
gr_blit(sTouch->GetResource(), 0, 0, sTouchW, sTouchH, sCurTouchX, (mRenderY + ((mRenderH - sTouchH) / 2)));
|
||||
|
||||
sUpdate = 0;
|
||||
return 0;
|
||||
sUpdate = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GUISlider::Update(void)
|
||||
{
|
||||
if (sUpdate) return 2;
|
||||
return 0;
|
||||
if (sUpdate)
|
||||
return 2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GUISlider::NotifyTouch(TOUCH_STATE state, int x, int y)
|
||||
{
|
||||
static bool dragging = false;
|
||||
static bool dragging = false;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case TOUCH_START:
|
||||
if (x >= mRenderX && x <= mRenderX + sTouchW &&
|
||||
y >= mRenderY && y <= mRenderY + mRenderH)
|
||||
{
|
||||
sCurTouchX = x - (sTouchW / 2);
|
||||
if (sCurTouchX < mRenderX) sCurTouchX = mRenderX;
|
||||
dragging = true;
|
||||
}
|
||||
break;
|
||||
{
|
||||
case TOUCH_START:
|
||||
if (x >= mRenderX && x <= mRenderX + sTouchW &&
|
||||
y >= mRenderY && y <= mRenderY + mRenderH)
|
||||
{
|
||||
sCurTouchX = x - (sTouchW / 2);
|
||||
if (sCurTouchX < mRenderX)
|
||||
sCurTouchX = mRenderX;
|
||||
dragging = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case TOUCH_DRAG:
|
||||
if (!dragging) return 0;
|
||||
if (y < mRenderY - sTouchH || y > mRenderY + (sTouchH * 2))
|
||||
{
|
||||
sCurTouchX = mRenderX;
|
||||
dragging = false;
|
||||
sUpdate = 1;
|
||||
break;
|
||||
}
|
||||
sCurTouchX = x - (sTouchW / 2);
|
||||
if (sCurTouchX < mRenderX) sCurTouchX = mRenderX;
|
||||
if (sCurTouchX > mRenderX + mRenderW - sTouchW) sCurTouchX = mRenderX + mRenderW - sTouchW;
|
||||
sUpdate = 1;
|
||||
break;
|
||||
case TOUCH_DRAG:
|
||||
if (!dragging)
|
||||
return 0;
|
||||
if (y < mRenderY - sTouchH || y > mRenderY + (sTouchH * 2))
|
||||
{
|
||||
sCurTouchX = mRenderX;
|
||||
dragging = false;
|
||||
sUpdate = 1;
|
||||
break;
|
||||
}
|
||||
sCurTouchX = x - (sTouchW / 2);
|
||||
if (sCurTouchX < mRenderX)
|
||||
sCurTouchX = mRenderX;
|
||||
if (sCurTouchX > mRenderX + mRenderW - sTouchW)
|
||||
sCurTouchX = mRenderX + mRenderW - sTouchW;
|
||||
sUpdate = 1;
|
||||
break;
|
||||
|
||||
case TOUCH_RELEASE:
|
||||
if (!dragging) return 0;
|
||||
if (sCurTouchX >= mRenderX + mRenderW - sTouchW)
|
||||
{
|
||||
sAction->doActions();
|
||||
}
|
||||
sCurTouchX = mRenderX;
|
||||
dragging = false;
|
||||
sUpdate = 1;
|
||||
case TOUCH_RELEASE:
|
||||
if (!dragging)
|
||||
return 0;
|
||||
|
||||
if (sCurTouchX >= mRenderX + mRenderW - sTouchW)
|
||||
sAction->doActions();
|
||||
|
||||
sCurTouchX = mRenderX;
|
||||
dragging = false;
|
||||
sUpdate = 1;
|
||||
case TOUCH_REPEAT:
|
||||
case TOUCH_HOLD:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+123
-117
@@ -26,116 +26,119 @@ extern "C" {
|
||||
#include "objects.hpp"
|
||||
|
||||
GUIText::GUIText(xml_node<>* node)
|
||||
: Conditional(node)
|
||||
: Conditional(node)
|
||||
{
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
xml_attribute<>* attr;
|
||||
xml_node<>* child;
|
||||
|
||||
mFont = NULL;
|
||||
mIsStatic = 1;
|
||||
mVarChanged = 0;
|
||||
mFontHeight = 0;
|
||||
mFont = NULL;
|
||||
mIsStatic = 1;
|
||||
mVarChanged = 0;
|
||||
mFontHeight = 0;
|
||||
maxWidth = 0;
|
||||
charSkip = 0;
|
||||
isHighlighted = false;
|
||||
hasHighlightColor = false;
|
||||
|
||||
if (!node) return;
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
// Initialize color to solid black
|
||||
memset(&mColor, 0, sizeof(COLOR));
|
||||
mColor.alpha = 255;
|
||||
// Initialize color to solid black
|
||||
memset(&mColor, 0, sizeof(COLOR));
|
||||
mColor.alpha = 255;
|
||||
memset(&mHighlightColor, 0, sizeof(COLOR));
|
||||
mHighlightColor.alpha = 255;
|
||||
mHighlightColor.alpha = 255;
|
||||
|
||||
attr = node->first_attribute("color");
|
||||
if (attr)
|
||||
{
|
||||
std::string color = attr->value();
|
||||
ConvertStrToColor(color, &mColor);
|
||||
}
|
||||
attr = node->first_attribute("color");
|
||||
if (attr)
|
||||
{
|
||||
std::string color = attr->value();
|
||||
ConvertStrToColor(color, &mColor);
|
||||
}
|
||||
attr = node->first_attribute("highlightcolor");
|
||||
if (attr)
|
||||
{
|
||||
std::string color = attr->value();
|
||||
if (attr)
|
||||
{
|
||||
std::string color = attr->value();
|
||||
ConvertStrToColor(color, &mHighlightColor);
|
||||
hasHighlightColor = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Load the font, and possibly override the color
|
||||
child = node->first_node("font");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("resource");
|
||||
if (attr)
|
||||
mFont = PageManager::FindResource(attr->value());
|
||||
// Load the font, and possibly override the color
|
||||
child = node->first_node("font");
|
||||
if (child)
|
||||
{
|
||||
attr = child->first_attribute("resource");
|
||||
if (attr)
|
||||
mFont = PageManager::FindResource(attr->value());
|
||||
|
||||
attr = child->first_attribute("color");
|
||||
if (attr)
|
||||
{
|
||||
std::string color = attr->value();
|
||||
ConvertStrToColor(color, &mColor);
|
||||
}
|
||||
attr = child->first_attribute("color");
|
||||
if (attr)
|
||||
{
|
||||
std::string color = attr->value();
|
||||
ConvertStrToColor(color, &mColor);
|
||||
}
|
||||
|
||||
attr = child->first_attribute("highlightcolor");
|
||||
if (attr)
|
||||
{
|
||||
std::string color = attr->value();
|
||||
if (attr)
|
||||
{
|
||||
std::string color = attr->value();
|
||||
ConvertStrToColor(color, &mHighlightColor);
|
||||
hasHighlightColor = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH, &mPlacement);
|
||||
// Load the placement
|
||||
LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH, &mPlacement);
|
||||
|
||||
child = node->first_node("text");
|
||||
if (child) mText = child->value();
|
||||
child = node->first_node("text");
|
||||
if (child) mText = child->value();
|
||||
|
||||
// Simple way to check for static state
|
||||
mLastValue = parseText();
|
||||
if (mLastValue != mText) mIsStatic = 0;
|
||||
// Simple way to check for static state
|
||||
mLastValue = parseText();
|
||||
if (mLastValue != mText) mIsStatic = 0;
|
||||
|
||||
gr_getFontDetails(mFont ? mFont->GetResource() : NULL, (unsigned*) &mFontHeight, NULL);
|
||||
return;
|
||||
gr_getFontDetails(mFont ? mFont->GetResource() : NULL, (unsigned*) &mFontHeight, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
int GUIText::Render(void)
|
||||
{
|
||||
if (!isConditionTrue()) return 0;
|
||||
if (!isConditionTrue())
|
||||
return 0;
|
||||
|
||||
void* fontResource = NULL;
|
||||
void* fontResource = NULL;
|
||||
string displayValue;
|
||||
|
||||
if (mFont) fontResource = mFont->GetResource();
|
||||
if (mFont)
|
||||
fontResource = mFont->GetResource();
|
||||
|
||||
mLastValue = parseText();
|
||||
mLastValue = parseText();
|
||||
displayValue = mLastValue;
|
||||
|
||||
if (charSkip)
|
||||
displayValue.erase(0, charSkip);
|
||||
|
||||
mVarChanged = 0;
|
||||
mVarChanged = 0;
|
||||
|
||||
int x = mRenderX, y = mRenderY;
|
||||
int width = gr_measureEx(displayValue.c_str(), fontResource);
|
||||
int x = mRenderX, y = mRenderY;
|
||||
int width = gr_measureEx(displayValue.c_str(), fontResource);
|
||||
|
||||
if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT)
|
||||
{
|
||||
if (mPlacement == CENTER || mPlacement == CENTER_X_ONLY)
|
||||
x -= (width / 2);
|
||||
else
|
||||
x -= width;
|
||||
}
|
||||
if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT)
|
||||
{
|
||||
if (mPlacement == CENTER)
|
||||
y -= (mFontHeight / 2);
|
||||
else if (mPlacement == BOTTOM_LEFT || mPlacement == BOTTOM_RIGHT)
|
||||
y -= mFontHeight;
|
||||
}
|
||||
if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT)
|
||||
{
|
||||
if (mPlacement == CENTER || mPlacement == CENTER_X_ONLY)
|
||||
x -= (width / 2);
|
||||
else
|
||||
x -= width;
|
||||
}
|
||||
if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT)
|
||||
{
|
||||
if (mPlacement == CENTER)
|
||||
y -= (mFontHeight / 2);
|
||||
else if (mPlacement == BOTTOM_LEFT || mPlacement == BOTTOM_RIGHT)
|
||||
y -= mFontHeight;
|
||||
}
|
||||
|
||||
if (hasHighlightColor && isHighlighted)
|
||||
if (hasHighlightColor && isHighlighted)
|
||||
gr_color(mHighlightColor.red, mHighlightColor.green, mHighlightColor.blue, mHighlightColor.alpha);
|
||||
else
|
||||
gr_color(mColor.red, mColor.green, mColor.blue, mColor.alpha);
|
||||
@@ -144,82 +147,85 @@ int GUIText::Render(void)
|
||||
gr_textExW(x, y, displayValue.c_str(), fontResource, maxWidth + x);
|
||||
else
|
||||
gr_textEx(x, y, displayValue.c_str(), fontResource);
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GUIText::Update(void)
|
||||
{
|
||||
if (!isConditionTrue()) return 0;
|
||||
if (!isConditionTrue())
|
||||
return 0;
|
||||
|
||||
static int updateCounter = 3;
|
||||
static int updateCounter = 3;
|
||||
|
||||
// This hack just makes sure we update at least once a minute for things like clock and battery
|
||||
if (updateCounter) updateCounter--;
|
||||
else
|
||||
{
|
||||
mVarChanged = 1;
|
||||
updateCounter = 3;
|
||||
}
|
||||
// This hack just makes sure we update at least once a minute for things like clock and battery
|
||||
if (updateCounter) updateCounter--;
|
||||
else
|
||||
{
|
||||
mVarChanged = 1;
|
||||
updateCounter = 3;
|
||||
}
|
||||
|
||||
if (mIsStatic || !mVarChanged) return 0;
|
||||
if (mIsStatic || !mVarChanged)
|
||||
return 0;
|
||||
|
||||
std::string newValue = parseText();
|
||||
if (mLastValue == newValue)
|
||||
std::string newValue = parseText();
|
||||
if (mLastValue == newValue)
|
||||
return 0;
|
||||
else
|
||||
mLastValue = newValue;
|
||||
return 2;
|
||||
return 2;
|
||||
}
|
||||
|
||||
int GUIText::GetCurrentBounds(int& w, int& h)
|
||||
{
|
||||
void* fontResource = NULL;
|
||||
void* fontResource = NULL;
|
||||
|
||||
if (mFont) fontResource = mFont->GetResource();
|
||||
if (mFont)
|
||||
fontResource = mFont->GetResource();
|
||||
|
||||
h = mFontHeight;
|
||||
h = mFontHeight;
|
||||
mLastValue = parseText();
|
||||
w = gr_measureEx(mLastValue.c_str(), fontResource);
|
||||
return 0;
|
||||
w = gr_measureEx(mLastValue.c_str(), fontResource);
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string GUIText::parseText(void)
|
||||
{
|
||||
static int counter = 0;
|
||||
std::string str = mText;
|
||||
size_t pos = 0;
|
||||
size_t next = 0, end = 0;
|
||||
static int counter = 0;
|
||||
std::string str = mText;
|
||||
size_t pos = 0;
|
||||
size_t next = 0, end = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
next = str.find('%', pos);
|
||||
if (next == std::string::npos) return str;
|
||||
end = str.find('%', next + 1);
|
||||
if (end == std::string::npos) return str;
|
||||
while (1)
|
||||
{
|
||||
next = str.find('%', pos);
|
||||
if (next == std::string::npos) return str;
|
||||
end = str.find('%', next + 1);
|
||||
if (end == std::string::npos) return str;
|
||||
|
||||
// We have a block of data
|
||||
std::string var = str.substr(next + 1, (end - next) - 1);
|
||||
str.erase(next, (end - next) + 1);
|
||||
// We have a block of data
|
||||
std::string var = str.substr(next + 1, (end - next) - 1);
|
||||
str.erase(next, (end - next) + 1);
|
||||
|
||||
if (next + 1 == end)
|
||||
{
|
||||
str.insert(next, 1, '%');
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string value;
|
||||
if (DataManager::GetValue(var, value) == 0)
|
||||
str.insert(next, value);
|
||||
}
|
||||
if (next + 1 == end)
|
||||
{
|
||||
str.insert(next, 1, '%');
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string value;
|
||||
if (DataManager::GetValue(var, value) == 0)
|
||||
str.insert(next, value);
|
||||
}
|
||||
|
||||
pos = next + 1;
|
||||
}
|
||||
pos = next + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int GUIText::NotifyVarChange(std::string varName, std::string value)
|
||||
{
|
||||
mVarChanged = 1;
|
||||
return 0;
|
||||
mVarChanged = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GUIText::SetMaxWidth(unsigned width)
|
||||
|
||||
+24
-24
@@ -1062,7 +1062,7 @@ bool TWPartition::Wipe_AndSec(void) {
|
||||
|
||||
gui_print("Wiping %s\n", Backup_Display_Name.c_str());
|
||||
TWFunc::removeDir(Mount_Point + "/.android_secure/", true);
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TWPartition::Backup(string backup_folder) {
|
||||
@@ -1361,31 +1361,31 @@ bool TWPartition::Wipe_MTD() {
|
||||
|
||||
gui_print("MTD Formatting \"%s\"\n", MTD_Name.c_str());
|
||||
|
||||
mtd_scan_partitions();
|
||||
const MtdPartition* mtd = mtd_find_partition_by_name(MTD_Name.c_str());
|
||||
if (mtd == NULL) {
|
||||
LOGERR("No mtd partition named '%s'", MTD_Name.c_str());
|
||||
return false;
|
||||
}
|
||||
mtd_scan_partitions();
|
||||
const MtdPartition* mtd = mtd_find_partition_by_name(MTD_Name.c_str());
|
||||
if (mtd == NULL) {
|
||||
LOGERR("No mtd partition named '%s'", MTD_Name.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
MtdWriteContext* ctx = mtd_write_partition(mtd);
|
||||
if (ctx == NULL) {
|
||||
LOGERR("Can't write '%s', failed to format.", MTD_Name.c_str());
|
||||
return false;
|
||||
}
|
||||
if (mtd_erase_blocks(ctx, -1) == -1) {
|
||||
mtd_write_close(ctx);
|
||||
LOGERR("Failed to format '%s'", MTD_Name.c_str());
|
||||
return false;
|
||||
}
|
||||
if (mtd_write_close(ctx) != 0) {
|
||||
LOGERR("Failed to close '%s'", MTD_Name.c_str());
|
||||
return false;
|
||||
}
|
||||
MtdWriteContext* ctx = mtd_write_partition(mtd);
|
||||
if (ctx == NULL) {
|
||||
LOGERR("Can't write '%s', failed to format.", MTD_Name.c_str());
|
||||
return false;
|
||||
}
|
||||
if (mtd_erase_blocks(ctx, -1) == -1) {
|
||||
mtd_write_close(ctx);
|
||||
LOGERR("Failed to format '%s'", MTD_Name.c_str());
|
||||
return false;
|
||||
}
|
||||
if (mtd_write_close(ctx) != 0) {
|
||||
LOGERR("Failed to close '%s'", MTD_Name.c_str());
|
||||
return false;
|
||||
}
|
||||
Current_File_System = "yaffs2";
|
||||
Recreate_AndSec_Folder();
|
||||
gui_print("Done.\n");
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TWPartition::Wipe_RMRF() {
|
||||
@@ -1415,7 +1415,7 @@ bool TWPartition::Wipe_Data_Without_Wiping_Media() {
|
||||
if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue;
|
||||
// The media folder is the "internal sdcard"
|
||||
// The .layout_version file is responsible for determining whether 4.2 decides up upgrade
|
||||
// the media folder for multi-user.
|
||||
// the media folder for multi-user.
|
||||
if (strcmp(de->d_name, "media") == 0 || strcmp(de->d_name, ".layout_version") == 0) continue;
|
||||
|
||||
dir = "/data/";
|
||||
@@ -1560,7 +1560,7 @@ bool TWPartition::Restore_Tar(string restore_folder, string Restore_File_System)
|
||||
} else {
|
||||
gui_print("Wiping %s...\n", Display_Name.c_str());
|
||||
if (!Wipe(Restore_File_System))
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
TWFunc::GUI_Operation_Text(TW_RESTORE_TEXT, Backup_Display_Name, "Restoring");
|
||||
gui_print("Restoring %s...\n", Backup_Display_Name.c_str());
|
||||
|
||||
@@ -1104,14 +1104,14 @@ int TWPartitionManager::Wipe_Dalvik_Cache(void) {
|
||||
}
|
||||
}
|
||||
TWPartition* sdext = Find_Partition_By_Path("/sd-ext");
|
||||
if (sdext != NULL) {
|
||||
if (sdext->Is_Present && sdext->Mount(false)) {
|
||||
if (stat("/sd-ext/dalvik-cache", &st) == 0) {
|
||||
TWFunc::removeDir("/sd-ext/dalvik-cache", false);
|
||||
gui_print("Cleaned: /sd-ext/dalvik-cache...\n");
|
||||
}
|
||||
if (sdext && sdext->Is_Present && sdext->Mount(false))
|
||||
{
|
||||
if (stat("/sd-ext/dalvik-cache", &st) == 0)
|
||||
{
|
||||
TWFunc::removeDir("/sd-ext/dalvik-cache", false);
|
||||
gui_print("Cleaned: /sd-ext/dalvik-cache...\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
gui_print("-- Dalvik Cache Directories Wipe Complete!\n\n");
|
||||
return true;
|
||||
}
|
||||
@@ -1893,4 +1893,4 @@ void TWPartitionManager::Output_Storage_Fstab(void) {
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
+137
-128
@@ -33,33 +33,35 @@ static int get_bootloader_message_block(struct bootloader_message *out, const TW
|
||||
static int set_bootloader_message_block(const struct bootloader_message *in, const TWPartition* Partition);
|
||||
|
||||
int get_bootloader_message(struct bootloader_message *out) {
|
||||
TWPartition* Part = PartitionManager.Find_Partition_By_Path("/misc");
|
||||
if (Part == NULL) {
|
||||
//LOGE("Cannot load volume /misc!\n");
|
||||
return -1;
|
||||
}
|
||||
if (Part->Current_File_System == "mtd") {
|
||||
return get_bootloader_message_mtd(out, Part);
|
||||
} else if (Part->Current_File_System == "emmc") {
|
||||
return get_bootloader_message_block(out, Part);
|
||||
}
|
||||
LOGE("unknown misc partition fs_type \"%s\"\n", Part->Current_File_System.c_str());
|
||||
return -1;
|
||||
TWPartition* Part = PartitionManager.Find_Partition_By_Path("/misc");
|
||||
if (Part == NULL) {
|
||||
//LOGE("Cannot load volume /misc!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (Part->Current_File_System == "mtd")
|
||||
return get_bootloader_message_mtd(out, Part);
|
||||
else if (Part->Current_File_System == "emmc")
|
||||
return get_bootloader_message_block(out, Part);
|
||||
|
||||
LOGE("unknown misc partition fs_type \"%s\"\n", Part->Current_File_System.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int set_bootloader_message(const struct bootloader_message *in) {
|
||||
TWPartition* Part = PartitionManager.Find_Partition_By_Path("/misc");
|
||||
if (Part == NULL) {
|
||||
//LOGE("Cannot load volume /misc!\n");
|
||||
return -1;
|
||||
}
|
||||
if (Part->Current_File_System == "mtd") {
|
||||
return set_bootloader_message_mtd(in, Part);
|
||||
} else if (Part->Current_File_System == "emmc") {
|
||||
return set_bootloader_message_block(in, Part);
|
||||
}
|
||||
LOGE("unknown misc partition fs_type \"%s\"\n", Part->Current_File_System.c_str());
|
||||
return -1;
|
||||
TWPartition* Part = PartitionManager.Find_Partition_By_Path("/misc");
|
||||
if (Part == NULL) {
|
||||
//LOGE("Cannot load volume /misc!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (Part->Current_File_System == "mtd")
|
||||
return set_bootloader_message_mtd(in, Part);
|
||||
else if (Part->Current_File_System == "emmc")
|
||||
return set_bootloader_message_block(in, Part);
|
||||
|
||||
LOGE("unknown misc partition fs_type \"%s\"\n", Part->Current_File_System.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ------------------------------
|
||||
@@ -71,134 +73,141 @@ static const int MISC_COMMAND_PAGE = 1; // bootloader command is this page
|
||||
|
||||
static int get_bootloader_message_mtd(struct bootloader_message *out,
|
||||
const TWPartition* Partition) {
|
||||
size_t write_size;
|
||||
mtd_scan_partitions();
|
||||
const MtdPartition *part = mtd_find_partition_by_name(Partition->MTD_Name.c_str());
|
||||
if (part == NULL || mtd_partition_info(part, NULL, NULL, &write_size)) {
|
||||
LOGE("Can't find %s\n", Partition->MTD_Name.c_str());
|
||||
return -1;
|
||||
}
|
||||
size_t write_size;
|
||||
mtd_scan_partitions();
|
||||
const MtdPartition *part = mtd_find_partition_by_name(Partition->MTD_Name.c_str());
|
||||
if (part == NULL || mtd_partition_info(part, NULL, NULL, &write_size)) {
|
||||
LOGE("Can't find %s\n", Partition->MTD_Name.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
MtdReadContext *read = mtd_read_partition(part);
|
||||
if (read == NULL) {
|
||||
LOGE("Can't open %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
MtdReadContext *read = mtd_read_partition(part);
|
||||
if (read == NULL) {
|
||||
LOGE("Can't open %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
const ssize_t size = write_size * MISC_PAGES;
|
||||
char data[size];
|
||||
ssize_t r = mtd_read_data(read, data, size);
|
||||
if (r != size) LOGE("Can't read %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
|
||||
mtd_read_close(read);
|
||||
if (r != size) return -1;
|
||||
const ssize_t size = write_size * MISC_PAGES;
|
||||
char data[size];
|
||||
ssize_t r = mtd_read_data(read, data, size);
|
||||
if (r != size) LOGE("Can't read %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
|
||||
mtd_read_close(read);
|
||||
if (r != size) return -1;
|
||||
|
||||
memcpy(out, &data[write_size * MISC_COMMAND_PAGE], sizeof(*out));
|
||||
return 0;
|
||||
memcpy(out, &data[write_size * MISC_COMMAND_PAGE], sizeof(*out));
|
||||
return 0;
|
||||
}
|
||||
static int set_bootloader_message_mtd(const struct bootloader_message *in,
|
||||
const TWPartition* Partition) {
|
||||
size_t write_size;
|
||||
mtd_scan_partitions();
|
||||
const MtdPartition *part = mtd_find_partition_by_name(Partition->MTD_Name.c_str());
|
||||
if (part == NULL || mtd_partition_info(part, NULL, NULL, &write_size)) {
|
||||
LOGE("Can't find %s\n", Partition->MTD_Name.c_str());
|
||||
return -1;
|
||||
}
|
||||
size_t write_size;
|
||||
mtd_scan_partitions();
|
||||
const MtdPartition *part = mtd_find_partition_by_name(Partition->MTD_Name.c_str());
|
||||
if (part == NULL || mtd_partition_info(part, NULL, NULL, &write_size)) {
|
||||
LOGE("Can't find %s\n", Partition->MTD_Name.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
MtdReadContext *read = mtd_read_partition(part);
|
||||
if (read == NULL) {
|
||||
LOGE("Can't open %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
MtdReadContext *read = mtd_read_partition(part);
|
||||
if (read == NULL) {
|
||||
LOGE("Can't open %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t size = write_size * MISC_PAGES;
|
||||
char data[size];
|
||||
ssize_t r = mtd_read_data(read, data, size);
|
||||
if (r != size) LOGE("Can't read %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
|
||||
mtd_read_close(read);
|
||||
if (r != size) return -1;
|
||||
ssize_t size = write_size * MISC_PAGES;
|
||||
char data[size];
|
||||
ssize_t r = mtd_read_data(read, data, size);
|
||||
if (r != size) LOGE("Can't read %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
|
||||
mtd_read_close(read);
|
||||
if (r != size) return -1;
|
||||
|
||||
memcpy(&data[write_size * MISC_COMMAND_PAGE], in, sizeof(*in));
|
||||
memcpy(&data[write_size * MISC_COMMAND_PAGE], in, sizeof(*in));
|
||||
|
||||
MtdWriteContext *write = mtd_write_partition(part);
|
||||
if (write == NULL) {
|
||||
LOGE("Can't open %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (mtd_write_data(write, data, size) != size) {
|
||||
LOGE("Can't write %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
|
||||
mtd_write_close(write);
|
||||
return -1;
|
||||
}
|
||||
if (mtd_write_close(write)) {
|
||||
LOGE("Can't finish %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
MtdWriteContext *write = mtd_write_partition(part);
|
||||
if (write == NULL) {
|
||||
LOGE("Can't open %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (mtd_write_data(write, data, size) != size) {
|
||||
LOGE("Can't write %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
|
||||
mtd_write_close(write);
|
||||
return -1;
|
||||
}
|
||||
if (mtd_write_close(write)) {
|
||||
LOGE("Can't finish %s\n(%s)\n", Partition->MTD_Name.c_str(), strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
LOGI("Set boot command \"%s\"\n", in->command[0] != 255 ? in->command : "");
|
||||
return 0;
|
||||
LOGI("Set boot command \"%s\"\n", in->command[0] != 255 ? in->command : "");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------
|
||||
// for misc partitions on block devices
|
||||
// ------------------------------------
|
||||
|
||||
static void wait_for_device(const char* fn) {
|
||||
int tries = 0;
|
||||
int ret;
|
||||
struct stat buf;
|
||||
do {
|
||||
++tries;
|
||||
ret = stat(fn, &buf);
|
||||
if (ret) {
|
||||
printf("stat %s try %d: %s\n", fn, tries, strerror(errno));
|
||||
sleep(1);
|
||||
}
|
||||
} while (ret && tries < 10);
|
||||
if (ret) {
|
||||
printf("failed to stat %s\n", fn);
|
||||
}
|
||||
int tries = 0;
|
||||
int ret;
|
||||
struct stat buf;
|
||||
|
||||
do {
|
||||
++tries;
|
||||
ret = stat(fn, &buf);
|
||||
if (ret) {
|
||||
printf("stat %s try %d: %s\n", fn, tries, strerror(errno));
|
||||
sleep(1);
|
||||
}
|
||||
} while (ret && tries < 10);
|
||||
|
||||
if (ret)
|
||||
printf("failed to stat %s\n", fn);
|
||||
}
|
||||
|
||||
static int get_bootloader_message_block(struct bootloader_message *out,
|
||||
const TWPartition* Partition) {
|
||||
wait_for_device(Partition->Actual_Block_Device.c_str());
|
||||
FILE* f = fopen(Partition->Actual_Block_Device.c_str(), "rb");
|
||||
if (f == NULL) {
|
||||
LOGE("Can't open %s\n(%s)\n", Partition->Actual_Block_Device.c_str(), strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
struct bootloader_message temp;
|
||||
int count = fread(&temp, sizeof(temp), 1, f);
|
||||
if (count != 1) {
|
||||
LOGE("Failed reading %s\n(%s)\n", Partition->Actual_Block_Device.c_str(), strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (fclose(f) != 0) {
|
||||
LOGE("Failed closing %s\n(%s)\n", Partition->Actual_Block_Device.c_str(), strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
memcpy(out, &temp, sizeof(temp));
|
||||
return 0;
|
||||
wait_for_device(Partition->Actual_Block_Device.c_str());
|
||||
|
||||
FILE* f = fopen(Partition->Actual_Block_Device.c_str(), "rb");
|
||||
if (f == NULL) {
|
||||
LOGE("Can't open %s\n(%s)\n", Partition->Actual_Block_Device.c_str(), strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct bootloader_message temp;
|
||||
int count = fread(&temp, sizeof(temp), 1, f);
|
||||
if (count != 1) {
|
||||
LOGE("Failed reading %s\n(%s)\n", Partition->Actual_Block_Device.c_str(), strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fclose(f) != 0) {
|
||||
LOGE("Failed closing %s\n(%s)\n", Partition->Actual_Block_Device.c_str(), strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(out, &temp, sizeof(temp));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_bootloader_message_block(const struct bootloader_message *in,
|
||||
const TWPartition* Partition) {
|
||||
wait_for_device(Partition->Actual_Block_Device.c_str());
|
||||
FILE* f = fopen(Partition->Actual_Block_Device.c_str(), "wb");
|
||||
if (f == NULL) {
|
||||
LOGE("Can't open %s\n(%s)\n", Partition->Actual_Block_Device.c_str(), strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
int count = fwrite(in, sizeof(*in), 1, f);
|
||||
if (count != 1) {
|
||||
LOGE("Failed writing %s\n(%s)\n", Partition->Actual_Block_Device.c_str(), strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (fclose(f) != 0) {
|
||||
LOGE("Failed closing %s\n(%s)\n", Partition->Actual_Block_Device.c_str(), strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
wait_for_device(Partition->Actual_Block_Device.c_str());
|
||||
|
||||
FILE* f = fopen(Partition->Actual_Block_Device.c_str(), "wb");
|
||||
if (f == NULL) {
|
||||
LOGE("Can't open %s\n(%s)\n", Partition->Actual_Block_Device.c_str(), strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
int count = fwrite(in, sizeof(*in), 1, f);
|
||||
if (count != 1) {
|
||||
LOGE("Failed writing %s\n(%s)\n", Partition->Actual_Block_Device.c_str(), strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fclose(f) != 0) {
|
||||
LOGE("Failed closing %s\n(%s)\n", Partition->Actual_Block_Device.c_str(), strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
+26
-26
@@ -87,37 +87,37 @@ static int Run_Update_Binary(const char *path, ZipArchive *Zip, int* wipe_cache)
|
||||
child_data = fdopen(pipe_fd[0], "r");
|
||||
while (fgets(buffer, sizeof(buffer), child_data) != NULL) {
|
||||
char* command = strtok(buffer, " \n");
|
||||
if (command == NULL) {
|
||||
continue;
|
||||
} else if (strcmp(command, "progress") == 0) {
|
||||
char* fraction_char = strtok(NULL, " \n");
|
||||
char* seconds_char = strtok(NULL, " \n");
|
||||
if (command == NULL) {
|
||||
continue;
|
||||
} else if (strcmp(command, "progress") == 0) {
|
||||
char* fraction_char = strtok(NULL, " \n");
|
||||
char* seconds_char = strtok(NULL, " \n");
|
||||
|
||||
float fraction_float = strtof(fraction_char, NULL);
|
||||
int seconds_float = strtol(seconds_char, NULL, 10);
|
||||
float fraction_float = strtof(fraction_char, NULL);
|
||||
int seconds_float = strtol(seconds_char, NULL, 10);
|
||||
|
||||
if (zip_verify)
|
||||
if (zip_verify)
|
||||
DataManager::ShowProgress(fraction_float * (1 - VERIFICATION_PROGRESS_FRACTION), seconds_float);
|
||||
else
|
||||
DataManager::ShowProgress(fraction_float, seconds_float);
|
||||
} else if (strcmp(command, "set_progress") == 0) {
|
||||
char* fraction_char = strtok(NULL, " \n");
|
||||
float fraction_float = strtof(fraction_char, NULL);
|
||||
DataManager::SetProgress(fraction_float);
|
||||
} else if (strcmp(command, "ui_print") == 0) {
|
||||
char* display_value = strtok(NULL, "\n");
|
||||
if (display_value) {
|
||||
gui_print("%s", display_value);
|
||||
} else {
|
||||
gui_print("\n");
|
||||
}
|
||||
} else if (strcmp(command, "wipe_cache") == 0) {
|
||||
*wipe_cache = 1;
|
||||
} else if (strcmp(command, "clear_display") == 0) {
|
||||
// Do nothing, not supported by TWRP
|
||||
} else {
|
||||
LOGERR("unknown command [%s]\n", command);
|
||||
}
|
||||
} else if (strcmp(command, "set_progress") == 0) {
|
||||
char* fraction_char = strtok(NULL, " \n");
|
||||
float fraction_float = strtof(fraction_char, NULL);
|
||||
DataManager::SetProgress(fraction_float);
|
||||
} else if (strcmp(command, "ui_print") == 0) {
|
||||
char* display_value = strtok(NULL, "\n");
|
||||
if (display_value) {
|
||||
gui_print("%s", display_value);
|
||||
} else {
|
||||
gui_print("\n");
|
||||
}
|
||||
} else if (strcmp(command, "wipe_cache") == 0) {
|
||||
*wipe_cache = 1;
|
||||
} else if (strcmp(command, "clear_display") == 0) {
|
||||
// Do nothing, not supported by TWRP
|
||||
} else {
|
||||
LOGERR("unknown command [%s]\n", command);
|
||||
}
|
||||
}
|
||||
fclose(child_data);
|
||||
|
||||
|
||||
+15
-14
@@ -424,15 +424,17 @@ unsigned int TWFunc::Get_D_Type_From_Stat(string Path) {
|
||||
}
|
||||
|
||||
int TWFunc::read_file(string fn, string& results) {
|
||||
ifstream file;
|
||||
file.open(fn.c_str(), ios::in);
|
||||
if (file.is_open()) {
|
||||
file >> results;
|
||||
file.close();
|
||||
return 0;
|
||||
ifstream file;
|
||||
file.open(fn.c_str(), ios::in);
|
||||
|
||||
if (file.is_open()) {
|
||||
file >> results;
|
||||
file.close();
|
||||
return 0;
|
||||
}
|
||||
LOGINFO("Cannot find file %s\n", fn.c_str());
|
||||
return -1;
|
||||
|
||||
LOGINFO("Cannot find file %s\n", fn.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int TWFunc::read_file(string fn, vector<string>& results) {
|
||||
@@ -498,7 +500,7 @@ timespec TWFunc::timespec_diff(timespec& start, timespec& end)
|
||||
return temp;
|
||||
}
|
||||
|
||||
int TWFunc::drop_caches(void) {
|
||||
int TWFunc::drop_caches(void) {
|
||||
string file = "/proc/sys/vm/drop_caches";
|
||||
string value = "3";
|
||||
if (write_file(file, value) != 0)
|
||||
@@ -714,7 +716,7 @@ int TWFunc::Get_File_Type(string fn) {
|
||||
string::size_type i = 0;
|
||||
int firstbyte = 0, secondbyte = 0;
|
||||
char header[3];
|
||||
|
||||
|
||||
ifstream f;
|
||||
f.open(fn.c_str(), ios::in | ios::binary);
|
||||
f.get(header, 3);
|
||||
@@ -722,13 +724,12 @@ int TWFunc::Get_File_Type(string fn) {
|
||||
firstbyte = header[i] & 0xff;
|
||||
secondbyte = header[++i] & 0xff;
|
||||
|
||||
if (firstbyte == 0x1f && secondbyte == 0x8b) {
|
||||
if (firstbyte == 0x1f && secondbyte == 0x8b)
|
||||
return 1; // Compressed
|
||||
} else if (firstbyte == 0x4f && secondbyte == 0x41) {
|
||||
else if (firstbyte == 0x4f && secondbyte == 0x41)
|
||||
return 2; // Encrypted
|
||||
} else {
|
||||
else
|
||||
return 0; // Unknown
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+6
-6
@@ -8,12 +8,12 @@ using namespace std;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
rb_current = 0,
|
||||
rb_system,
|
||||
rb_recovery,
|
||||
rb_poweroff,
|
||||
rb_bootloader, // May also be fastboot
|
||||
rb_download,
|
||||
rb_current = 0,
|
||||
rb_system,
|
||||
rb_recovery,
|
||||
rb_poweroff,
|
||||
rb_bootloader, // May also be fastboot
|
||||
rb_download,
|
||||
} RebootCommand;
|
||||
|
||||
// Partition class
|
||||
|
||||
@@ -152,7 +152,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
char twrp_booted[PROPERTY_VALUE_MAX];
|
||||
char twrp_booted[PROPERTY_VALUE_MAX];
|
||||
property_get("ro.twrp.boot", twrp_booted, "0");
|
||||
if (strcmp(twrp_booted, "0") == 0) {
|
||||
property_list(Print_Prop, NULL);
|
||||
@@ -242,10 +242,10 @@ int main(int argc, char **argv) {
|
||||
PartitionManager.UnMount_By_Path("/system", false);
|
||||
}
|
||||
|
||||
// Reboot
|
||||
// Reboot
|
||||
TWFunc::Update_Intent_File(Reboot_Value);
|
||||
TWFunc::Update_Log_File();
|
||||
gui_print("Rebooting...\n");
|
||||
TWFunc::Update_Log_File();
|
||||
gui_print("Rebooting...\n");
|
||||
string Reboot_Arg;
|
||||
DataManager::GetValue("tw_reboot_arg", Reboot_Arg);
|
||||
if (Reboot_Arg == "recovery")
|
||||
@@ -260,9 +260,9 @@ int main(int argc, char **argv) {
|
||||
TWFunc::tw_reboot(rb_system);
|
||||
|
||||
#ifdef ANDROID_RB_RESTART
|
||||
android_reboot(ANDROID_RB_RESTART, 0, 0);
|
||||
android_reboot(ANDROID_RB_RESTART, 0, 0);
|
||||
#else
|
||||
reboot(RB_AUTOBOOT);
|
||||
#endif
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
+3
-1
@@ -16,10 +16,12 @@
|
||||
along with TWRP. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#include "digest/md5.h"
|
||||
#include "libcrecovery/common.h"
|
||||
}
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
+15
-12
@@ -18,18 +18,21 @@
|
||||
extern "C" {
|
||||
#include "digest/md5.h"
|
||||
}
|
||||
|
||||
using namespace std;
|
||||
|
||||
class twrpDigest {
|
||||
public:
|
||||
void setfn(string fn);
|
||||
void setdir(string dir);
|
||||
int computeMD5(void);
|
||||
int verify_md5digest(void);
|
||||
int write_md5digest(void);
|
||||
private:
|
||||
int read_md5digest(void);
|
||||
string md5fn;
|
||||
string line;
|
||||
unsigned char md5sum[MD5LENGTH];
|
||||
class twrpDigest
|
||||
{
|
||||
public:
|
||||
void setfn(string fn);
|
||||
void setdir(string dir);
|
||||
int computeMD5(void);
|
||||
int verify_md5digest(void);
|
||||
int write_md5digest(void);
|
||||
|
||||
private:
|
||||
int read_md5digest(void);
|
||||
string md5fn;
|
||||
string line;
|
||||
unsigned char md5sum[MD5LENGTH];
|
||||
};
|
||||
|
||||
+1
-1
@@ -1297,7 +1297,7 @@ int twrpTar::entryExists(string entry) {
|
||||
|
||||
unsigned long long twrpTar::uncompressedSize() {
|
||||
int type = 0;
|
||||
unsigned long long total_size = 0;
|
||||
unsigned long long total_size = 0;
|
||||
string Tar, Command, result;
|
||||
vector<string> split;
|
||||
|
||||
|
||||
+53
-52
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
extern "C" {
|
||||
#include "libtar/libtar.h"
|
||||
#include "libtar/libtar.h"
|
||||
}
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -41,59 +41,60 @@ struct thread_data_struct {
|
||||
};
|
||||
|
||||
class twrpTar {
|
||||
public:
|
||||
twrpTar();
|
||||
virtual ~twrpTar();
|
||||
int createTarFork();
|
||||
int extractTarFork();
|
||||
int splitArchiveFork();
|
||||
void setexcl(string exclude);
|
||||
void setfn(string fn);
|
||||
void setdir(string dir);
|
||||
unsigned long long uncompressedSize();
|
||||
|
||||
public:
|
||||
int use_encryption;
|
||||
int userdata_encryption;
|
||||
int use_compression;
|
||||
int split_archives;
|
||||
int has_data_media;
|
||||
string backup_name;
|
||||
public:
|
||||
twrpTar();
|
||||
virtual ~twrpTar();
|
||||
int createTarFork();
|
||||
int extractTarFork();
|
||||
int splitArchiveFork();
|
||||
void setexcl(string exclude);
|
||||
void setfn(string fn);
|
||||
void setdir(string dir);
|
||||
unsigned long long uncompressedSize();
|
||||
|
||||
public:
|
||||
int use_encryption;
|
||||
int userdata_encryption;
|
||||
int use_compression;
|
||||
int split_archives;
|
||||
int has_data_media;
|
||||
string backup_name;
|
||||
|
||||
private:
|
||||
int extract();
|
||||
int addFilesToExistingTar(vector <string> files, string tarFile);
|
||||
int createTar();
|
||||
int addFile(string fn, bool include_root);
|
||||
int entryExists(string entry);
|
||||
int closeTar();
|
||||
int create();
|
||||
int Split_Archive();
|
||||
int removeEOT(string tarFile);
|
||||
int extractTar();
|
||||
int tarDirs(bool include_root);
|
||||
int Generate_Multiple_Archives(string Path);
|
||||
string Strip_Root_Dir(string Path);
|
||||
int openTar();
|
||||
int Archive_File_Count;
|
||||
int Archive_Current_Type;
|
||||
unsigned long long Archive_Current_Size;
|
||||
TAR *t;
|
||||
int fd;
|
||||
pid_t pigz_pid;
|
||||
pid_t oaes_pid;
|
||||
private:
|
||||
int extract();
|
||||
int addFilesToExistingTar(vector <string> files, string tarFile);
|
||||
int createTar();
|
||||
int addFile(string fn, bool include_root);
|
||||
int entryExists(string entry);
|
||||
int closeTar();
|
||||
int create();
|
||||
int Split_Archive();
|
||||
int removeEOT(string tarFile);
|
||||
int extractTar();
|
||||
int tarDirs(bool include_root);
|
||||
int Generate_Multiple_Archives(string Path);
|
||||
string Strip_Root_Dir(string Path);
|
||||
int openTar();
|
||||
int Generate_TarList(string Path, std::vector<TarListStruct> *TarList, unsigned long long *Target_Size, unsigned *thread_id);
|
||||
static void* createList(void *cookie);
|
||||
static void* extractMulti(void *cookie);
|
||||
int tarList(bool include_root, std::vector<TarListStruct> *TarList, unsigned thread_id);
|
||||
|
||||
string tardir;
|
||||
string tarfn;
|
||||
string basefn;
|
||||
string tarexclude;
|
||||
int Archive_File_Count;
|
||||
int Archive_Current_Type;
|
||||
unsigned long long Archive_Current_Size;
|
||||
TAR *t;
|
||||
int fd;
|
||||
pid_t pigz_pid;
|
||||
pid_t oaes_pid;
|
||||
|
||||
vector<string> split;
|
||||
string tardir;
|
||||
string tarfn;
|
||||
string basefn;
|
||||
string tarexclude;
|
||||
|
||||
int Generate_TarList(string Path, std::vector<TarListStruct> *TarList, unsigned long long *Target_Size, unsigned *thread_id);
|
||||
static void* createList(void *cookie);
|
||||
static void* extractMulti(void *cookie);
|
||||
int tarList(bool include_root, std::vector<TarListStruct> *TarList, unsigned thread_id);
|
||||
std::vector<TarListStruct> *ItemList;
|
||||
int thread_id;
|
||||
vector<string> split;
|
||||
|
||||
std::vector<TarListStruct> *ItemList;
|
||||
int thread_id;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user