Add Fastboot/EDL reboot modes and SIM contact import/export
This commit is contained in:
1 parent
a1e4f6ef8c
commit
a117e74452
17 files changed
+864
-37
No files matched your search
@@ -809,6 +809,78 @@ class ContactBook {
|
||||
return true;
|
||||
}
|
||||
|
||||
int importContactsBatch(
|
||||
const std::vector<std::pair<std::string, std::string>>& items) {
|
||||
if (items.empty()) {
|
||||
return 0;
|
||||
}
|
||||
std::string path = getContactsFilePath();
|
||||
ensureParentDir(path);
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> rows;
|
||||
{
|
||||
std::ifstream in(path);
|
||||
std::string line;
|
||||
while (std::getline(in, line)) {
|
||||
if (line.empty()) continue;
|
||||
size_t tab = line.find('\t');
|
||||
if (tab == std::string::npos) continue;
|
||||
std::string num = trimStr(line.substr(0, tab));
|
||||
std::string name = trimStr(line.substr(tab + 1));
|
||||
if (!num.empty() && !name.empty()) {
|
||||
rows.push_back({num, name});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for (const auto& item : items) {
|
||||
std::string newNumber = trimStr(item.first);
|
||||
std::string newName = trimStr(item.second);
|
||||
for (char& ch : newName) {
|
||||
if (ch == '\t' || ch == '\r' || ch == '\n') {
|
||||
ch = ' ';
|
||||
}
|
||||
}
|
||||
std::string newNorm = normalizePhone(newNumber);
|
||||
if (newNorm.empty()) {
|
||||
continue;
|
||||
}
|
||||
if (newName.empty()) {
|
||||
newName = newNumber;
|
||||
}
|
||||
bool replaced = false;
|
||||
for (auto& r : rows) {
|
||||
if (r.first == newNumber ||
|
||||
(!newNorm.empty() && normalizePhone(r.first) == newNorm)) {
|
||||
r.first = newNumber;
|
||||
r.second = newName;
|
||||
replaced = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!replaced) {
|
||||
rows.push_back({newNumber, newName});
|
||||
}
|
||||
++count;
|
||||
}
|
||||
|
||||
if (count <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::ofstream out(path, std::ios::trunc);
|
||||
if (!out.is_open()) {
|
||||
return -1;
|
||||
}
|
||||
for (const auto& r : rows) {
|
||||
out << r.first << "\t" << r.second << "\n";
|
||||
}
|
||||
out.close();
|
||||
load();
|
||||
return count;
|
||||
}
|
||||
|
||||
bool deleteContact(const std::string& number, const std::string& name) {
|
||||
std::string path = getContactsFilePath();
|
||||
std::vector<std::pair<std::string, std::string>> rows;
|
||||
|
||||
Reference in new issue
Block a user