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.
92 lines
2.7 KiB
C++
92 lines
2.7 KiB
C++
/*
|
|
Copyright 2014 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 <string>
|
|
#include <vector>
|
|
#include <dirent.h>
|
|
#include <stdlib.h>
|
|
#include "find_file.hpp"
|
|
#include "twrp-functions.hpp"
|
|
#include "twcommon.h"
|
|
|
|
using namespace std;
|
|
|
|
string Find_File::Find(const string& file_name, const string& start_path) {
|
|
return Find_File().Find_Internal(file_name, start_path);
|
|
}
|
|
|
|
Find_File::Find_File() {
|
|
}
|
|
|
|
string Find_File::Find_Internal(const string& filename, const string& starting_path) {
|
|
DIR *d;
|
|
string new_path, return_path;
|
|
vector<string> dirs;
|
|
vector<string> symlinks;
|
|
unsigned index;
|
|
|
|
// Check to see if we have already searched this directory to prevent infinite loops
|
|
if (std::find(searched_dirs.begin(), searched_dirs.end(), starting_path) != searched_dirs.end()) {
|
|
return "";
|
|
}
|
|
searched_dirs.push_back(starting_path);
|
|
|
|
d = opendir(starting_path.c_str());
|
|
if (d == NULL) {
|
|
LOGINFO("Find_File: Error opening '%s'\n", starting_path.c_str());
|
|
return "";
|
|
}
|
|
|
|
struct dirent *p;
|
|
while ((p = readdir(d))) {
|
|
if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, ".."))
|
|
continue;
|
|
new_path = starting_path + "/";
|
|
new_path.append(p->d_name);
|
|
if (p->d_type == DT_DIR) {
|
|
// Add dir to search list for later
|
|
dirs.push_back(new_path);
|
|
} else if (p->d_type == DT_LNK) {
|
|
// Add symlink to search list for later
|
|
symlinks.push_back(new_path);
|
|
} else if (p->d_type == DT_REG && filename == p->d_name) {
|
|
// We found a match!
|
|
closedir(d);
|
|
return new_path;
|
|
}
|
|
}
|
|
closedir(d);
|
|
|
|
// Scan real directories first if no match found in this path
|
|
for (index = 0; index < dirs.size(); index++) {
|
|
return_path = Find_Internal(filename, dirs.at(index));
|
|
if (!return_path.empty()) return return_path;
|
|
}
|
|
// Scan symlinks after scanning real directories
|
|
for (index = 0; index < symlinks.size(); index++) {
|
|
char buf[PATH_MAX];
|
|
// Resolve symlink to a real path
|
|
char* ret = realpath(symlinks.at(index).c_str(), buf);
|
|
if (ret) {
|
|
return_path = Find_Internal(filename, buf);
|
|
if (!return_path.empty()) return return_path;
|
|
}
|
|
}
|
|
return "";
|
|
}
|