});
}
+bool StartsWith(const std::string& str, const std::string& substr) {
+ return str.length() >= substr.length() &&
+ std::equal(substr.begin(), substr.end(), str.begin());
+}
+
+constexpr const char kThemeFilesPrefix[] = "/theme/files/";
+
} // namespace
namespace ttm {
}
std::string ThemeInfo::GetPath(const std::string& key) const {
+ std::string key_to_get;
+ if (StartsWith(key, kThemeFilesPrefix)) {
+ auto pos = key.rfind("/");
+ key_to_get = key.substr(0, pos);
+ } else {
+ key_to_get = key;
+ }
+
bool is_overlayed = false;
std::vector<std::string> selected_keys =
bundle_.GetStringArray("selected_keys");
- auto it = std::find(selected_keys.begin(), selected_keys.end(), key);
- if (it != selected_keys.end())
+ auto it = std::find(selected_keys.begin(), selected_keys.end(), key_to_get);
+ if (it != selected_keys.end() || selected_keys.empty())
is_overlayed = true;
std::string pkgid;
uid = GetUid();
} else {
pkgid = bundle_.GetString("default_pkgid");
- uid = std::stoi(bundle_.GetString("default_uid"));
+ if (pkgid.empty()) {
+ LOG(WARNING) << "Default Theme may not installed";
+ return {};
+ }
+ std::string uid_str = bundle_.GetString("default_uid");
+ if (uid_str.empty()) {
+ LOG(WARNING) << "Default Theme may not installed";
+ return {};
+ }
+ try {
+ uid = std::stoi(uid_str);
+ } catch (const std::invalid_argument& e) {
+ LOG(ERROR) << "Exception occurred while getting default theme uid: "
+ << e.what();
+ return {};
+ } catch (const std::out_of_range& e) {
+ LOG(ERROR) << "Exception occurred while getting default theme uid: "
+ << e.what();
+ return {};
+ }
}
std::string root_path = GetPkgRootPath(pkgid, uid);
return {};
}
- std::string val = bundle_.GetString(key);
+ std::string val = bundle_.GetString(key_to_get);
+ if (val.empty()) {
+ LOG(ERROR) << "Failed to get path for key: " << key;
+ return {};
+ }
return root_path + "/" + val;
}