f6176009b1
Stages TWRP's GUI engine and standalone tooling as PawletOS-owned modules instead of a bootable/recovery fork, per the plugin-architecture finding in NOTES-ota-recovery-ab.md: stock recovery_main.cpp already dlopen()s librecovery_ui_ext.so and dlsym()s make_device() from it at runtime, so the UI layer doesn't require touching stock bootable/recovery at all. Confirmed via source grep that recovery.cpp/install.cpp have zero references into the partition manager/backup engine/GUI code and vice versa. recovery_ui/: TWRP's gui/, minuitwrp/, libpixelflinger/ (copied verbatim, GPL-3.0), plus a new device/ providing PawletTwrpUI (a ScreenRecoveryUI subclass) and make_device() — written from scratch against stock's RecoveryUI/ScreenRecoveryUI virtual-method contract, since TWRP's own fork never ships a make_device() (every real TWRP device provides its own, and no reference device tree was available to copy from). Top-level Android.bp defines librecovery_ui_pawlet_twrp, the module TARGET_RECOVERY_UI_LIB should point at. gui/Android.bp and minuitwrp/Android.bp had their include_dirs rewritten for the new paths. recovery_toolkit/: partition manager, backup engine (tar/digest/adbbu/apex), filesystem/format support (exfat/dosfstools/gpt/fuse/mtp/crypto), scripting (openrecoveryscript/orscmd/twrpinstall), shared helpers. Source only, no Android.bp yet for any of it. Known gap blocking recovery_ui from actually linking: gui/'s libguitwrp depends on libaosprecovery, built from recovery_toolkit/helpers/twrp.cpp via a Go Soong plugin (libaosprecovery_defaults.go) not yet ported. Neither repo has been build-tested — no local AOSP build environment available in this workspace. See each directory's README.md for a precise done/not-done breakdown.
140 lines
3.3 KiB
C++
140 lines
3.3 KiB
C++
/*
|
|
Copyright 2015 _that/TeamWin
|
|
This file is part of TWRP/TeamWin Recovery Project.
|
|
|
|
TWRP is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
TWRP is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with TWRP. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "../data.hpp"
|
|
#include "pages.hpp"
|
|
#include "resources.hpp"
|
|
|
|
#include "twmsg.h"
|
|
#include <cctype>
|
|
|
|
std::string Message::GetFormatString(const std::string& name) const
|
|
{
|
|
return resourceLookup(name);
|
|
}
|
|
|
|
// Look up in local replacement vars first, if not found then use outer lookup object
|
|
class LocalLookup : public StringLookup
|
|
{
|
|
const std::vector<std::string>& vars;
|
|
const StringLookup& next;
|
|
public:
|
|
LocalLookup(const std::vector<std::string>& vars, const StringLookup& next) : vars(vars), next(next) {}
|
|
virtual std::string operator()(const std::string& name) const
|
|
{
|
|
if (!name.empty() && isdigit(name[0])) { // {1}..{9}
|
|
int i = atoi(name.c_str());
|
|
if (i > 0 && i <= (int)vars.size())
|
|
return vars[i - 1];
|
|
}
|
|
return next(name);
|
|
}
|
|
};
|
|
|
|
// conversion to final string
|
|
Message::operator std::string() const
|
|
{
|
|
// do resource lookup
|
|
std::string str = GetFormatString(name);
|
|
|
|
LocalLookup lookup(variables, varLookup);
|
|
|
|
// now insert stuff into curly braces
|
|
|
|
size_t pos = 0;
|
|
while ((pos = str.find('{', pos)) < std::string::npos) {
|
|
size_t end = str.find('}', pos);
|
|
if (end == std::string::npos)
|
|
break;
|
|
|
|
std::string varname = str.substr(pos + 1, end - pos - 1);
|
|
std::string vartext = lookup(varname);
|
|
|
|
str.replace(pos, end - pos + 1, vartext);
|
|
}
|
|
// TODO: complain about too many or too few numbered replacement variables
|
|
return str;
|
|
}
|
|
|
|
/*
|
|
Resource manager lookup
|
|
*/
|
|
class ResourceLookup : public StringLookup
|
|
{
|
|
public:
|
|
virtual std::string operator()(const std::string& name) const
|
|
{
|
|
std::string resname;
|
|
std::string default_value;
|
|
|
|
size_t pos = name.find('=');
|
|
if (pos == std::string::npos) {
|
|
resname = name;
|
|
} else {
|
|
resname = name.substr(0, pos);
|
|
default_value = name.substr(pos + 1);
|
|
}
|
|
#ifndef BUILD_TWRPTAR_MAIN
|
|
const ResourceManager* res = PageManager::GetResources();
|
|
if (res) {
|
|
if (default_value.empty())
|
|
return res->FindString(resname);
|
|
else
|
|
return res->FindString(resname, default_value);
|
|
}
|
|
#endif
|
|
if (!default_value.empty()) {
|
|
return default_value;
|
|
}
|
|
return name;
|
|
}
|
|
};
|
|
ResourceLookup resourceLookup;
|
|
|
|
|
|
/*
|
|
DataManager lookup
|
|
*/
|
|
class DataLookup : public StringLookup
|
|
{
|
|
public:
|
|
virtual std::string operator()(const std::string& name) const
|
|
{
|
|
#ifndef BUILD_TWRPTAR_MAIN
|
|
std::string value;
|
|
if (DataManager::GetValue(name, value) == 0)
|
|
return value;
|
|
else
|
|
#endif
|
|
return "";
|
|
}
|
|
};
|
|
DataLookup dataLookup;
|
|
|
|
|
|
// Utility functions to create messages. Short names to make usage convenient.
|
|
Message Msg(const char* name)
|
|
{
|
|
return Message(msg::kNormal, name, resourceLookup, dataLookup);
|
|
}
|
|
|
|
Message Msg(msg::Kind kind, const char* name)
|
|
{
|
|
return Message(kind, name, resourceLookup, dataLookup);
|
|
}
|