mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-30 00:41:09 +02:00
COPKGManager: add members to get package infos and optmize update check
Origin commit data
------------------
Commit: b3afd24260
Author: Thilo Graf <dbt@novatux.de>
Date: 2014-12-19 (Fri, 19 Dec 2014)
This commit is contained in:
@@ -1867,6 +1867,7 @@ opkg.failure.upgrade Upgrade fehlgeschlagen
|
||||
opkg.install.local.package Installiere lokales Paket
|
||||
opkg.messagebox.reinstall %s erneut installieren?
|
||||
opkg.messagebox.remove %s entfernen?
|
||||
opkg.messagebox.updates.available Aktualisierungen verfügbar!
|
||||
opkg.success.install Installation erfolgreich, Neustart von Neutrino kann erforderlich sein.
|
||||
opkg.title Paketverwaltung
|
||||
opkg.upgrade Installierte Pakete aktualisieren
|
||||
|
@@ -1867,6 +1867,7 @@ opkg.failure.upgrade Upgrade failed
|
||||
opkg.install.local.package Install local package
|
||||
opkg.messagebox.reinstall Re-install %s?
|
||||
opkg.messagebox.remove Remove %s?
|
||||
opkg.messagebox.updates.available Updates available!
|
||||
opkg.success.install Install successful, restart of Neutrino might be required.
|
||||
opkg.title Package Management
|
||||
opkg.upgrade Upgrade installed packages
|
||||
|
@@ -1758,6 +1758,7 @@ opkg.failure.upgrade Upgrade mislukt
|
||||
opkg.install.local.package Installeer lokale pakket
|
||||
opkg.messagebox.reinstall Herinstalleer %s?
|
||||
opkg.messagebox.remove Wissen%s?
|
||||
opkg.messagebox.updates.available Updates beschikbare!
|
||||
opkg.success.install installatie succesvol, herstart van Neutrino mogelijk vereist.
|
||||
opkg.title Pakket management
|
||||
opkg.upgrade Upgrade geïnstalleerd pakketten
|
||||
|
@@ -1848,6 +1848,7 @@ opkg.failure.upgrade Upgrade zlyhalo
|
||||
opkg.install.local.package Nainštalujte miestne balíček
|
||||
opkg.messagebox.reinstall Preinštalovať %s?
|
||||
opkg.messagebox.remove Odstrániť %s?
|
||||
opkg.messagebox.updates.available Aktualizácia k dispozícii!
|
||||
opkg.success.install Inštalácia v poriadku, reštart Neutrina bude žiadúci.
|
||||
opkg.title Správa balíčkov
|
||||
opkg.upgrade Aktualizovanie inštalovaných balíčkov
|
||||
|
@@ -42,6 +42,7 @@
|
||||
#include <gui/widget/icons.h>
|
||||
#include <gui/widget/messagebox.h>
|
||||
#include <gui/widget/shellwindow.h>
|
||||
#include <gui/widget/progresswindow.h>
|
||||
#include <driver/screen_max.h>
|
||||
#include <gui/filebrowser.h>
|
||||
#include <system/debug.h>
|
||||
@@ -68,6 +69,7 @@ enum
|
||||
OM_REMOVE,
|
||||
OM_INFO,
|
||||
OM_INSTALL,
|
||||
OM_STATUS,
|
||||
OM_MAX
|
||||
};
|
||||
|
||||
@@ -80,7 +82,8 @@ static const string pkg_types[OM_MAX] =
|
||||
OPKG_CL OPKG_CL_CONFIG_OPTIONS " upgrade ",
|
||||
OPKG_CL OPKG_CL_CONFIG_OPTIONS " remove ",
|
||||
OPKG_CL " info ",
|
||||
OPKG_CL OPKG_CL_CONFIG_OPTIONS " install "
|
||||
OPKG_CL OPKG_CL_CONFIG_OPTIONS " install ",
|
||||
OPKG_CL " status ",
|
||||
};
|
||||
|
||||
COPKGManager::COPKGManager()
|
||||
@@ -188,6 +191,7 @@ int COPKGManager::exec(CMenuTarget* parent, const string &actionKey)
|
||||
force = "--force-reinstall ";
|
||||
}
|
||||
int r = execCmd(pkg_types[OM_INSTALL] + force + actionKey, true, true);
|
||||
DisplayInfoMessage(actionKey.c_str());
|
||||
if (r) {
|
||||
showError(g_Locale->getText(LOCALE_OPKG_FAILURE_INSTALL), strerror(errno), pkg_types[OM_INSTALL] + force + actionKey);
|
||||
} else
|
||||
@@ -279,24 +283,53 @@ void COPKGManager::updateMenu()
|
||||
}
|
||||
}
|
||||
|
||||
bool COPKGManager::hasUpdates()
|
||||
bool COPKGManager::checkUpdates(const std::string & package_name, bool show_progress)
|
||||
{
|
||||
if (!hasOpkgSupport())
|
||||
return false;
|
||||
|
||||
doUpdate();
|
||||
|
||||
bool ret = false;
|
||||
|
||||
getPkgData(OM_LIST);
|
||||
getPkgData(OM_LIST_UPGRADEABLE);
|
||||
|
||||
size_t i = 0;
|
||||
CProgressWindow status;
|
||||
status.showHeader(false);
|
||||
|
||||
if (show_progress){
|
||||
status.paint();
|
||||
status.showStatus(i);
|
||||
}
|
||||
|
||||
for (map<string, struct pkg>::iterator it = pkg_map.begin(); it != pkg_map.end(); it++){
|
||||
dprintf(DEBUG_INFO, "[COPKGManager] [%s - %d] Update check for...%s\n", __func__, __LINE__, it->second.name.c_str());
|
||||
if (show_progress){
|
||||
status.showStatusMessageUTF(it->second.name);
|
||||
status.showStatus(100*i / pkg_map.size());
|
||||
}
|
||||
|
||||
if (it->second.upgradable){
|
||||
dprintf(DEBUG_INFO, "[COPKGManager] [%s - %d] Update packages available...\n", __func__, __LINE__);
|
||||
dprintf(DEBUG_INFO, "[COPKGManager] [%s - %d] Update packages available for...%s\n", __func__, __LINE__, it->second.name.c_str());
|
||||
if (!package_name.empty() && package_name == it->second.name){
|
||||
ret = true;
|
||||
break;
|
||||
}else
|
||||
ret = true;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (show_progress){
|
||||
status.showGlobalStatus(100);
|
||||
status.showStatusMessageUTF(g_Locale->getText(LOCALE_FLASHUPDATE_READY)); // UTF-8
|
||||
status.hide();
|
||||
}
|
||||
|
||||
pkg_map.clear();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -305,10 +338,10 @@ int COPKGManager::doUpdate()
|
||||
int r = execCmd(pkg_types[OM_UPDATE]);
|
||||
if (r == -1) {
|
||||
DisplayErrorMessage(g_Locale->getText(LOCALE_OPKG_FAILURE_UPDATE));
|
||||
// showError(g_Locale->getText(LOCALE_OPKG_FAILURE_UPDATE), strerror(errno), pkg_types[OM_UPDATE]);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void COPKGManager::refreshMenu() {
|
||||
list_installed_done = false,
|
||||
@@ -319,7 +352,8 @@ void COPKGManager::refreshMenu() {
|
||||
int COPKGManager::showMenu()
|
||||
{
|
||||
installed = false;
|
||||
doUpdate();
|
||||
if (checkUpdates())
|
||||
DisplayInfoMessage(g_Locale->getText(LOCALE_OPKG_MESSAGEBOX_UPDATES_AVAILABLE));
|
||||
|
||||
getPkgData(OM_LIST);
|
||||
getPkgData(OM_LIST_UPGRADEABLE);
|
||||
@@ -351,6 +385,7 @@ int COPKGManager::showMenu()
|
||||
if (badpackage(it->second.name))
|
||||
continue;
|
||||
it->second.forwarder = new CMenuForwarder(it->second.desc, true, NULL , this, it->second.name.c_str());
|
||||
getPkgInfo(it->second.name, "Size");
|
||||
it->second.forwarder->setHint("", it->second.desc);
|
||||
menu->addItem(it->second.forwarder);
|
||||
pkg_vec.push_back(&it->second);
|
||||
@@ -429,10 +464,12 @@ void COPKGManager::getPkgData(const int pkg_content_id)
|
||||
trim(line);
|
||||
|
||||
string name = getBlankPkgName(line);
|
||||
if (name.empty())
|
||||
continue;
|
||||
|
||||
switch (pkg_content_id) {
|
||||
case OM_LIST: {
|
||||
pkg_map[name] = pkg(name, line);
|
||||
pkg_map[name] = pkg(name, line, line);
|
||||
break;
|
||||
}
|
||||
case OM_LIST_INSTALLED: {
|
||||
@@ -458,10 +495,48 @@ void COPKGManager::getPkgData(const int pkg_content_id)
|
||||
|
||||
string COPKGManager::getBlankPkgName(const string& line)
|
||||
{
|
||||
size_t l_pos = line.find(" ");
|
||||
if (l_pos != string::npos)
|
||||
return line.substr(0, l_pos);
|
||||
return line;
|
||||
dprintf(DEBUG_INFO, "[COPKGManager] [%s - %d] line: %s\n", __func__, __LINE__, line.c_str());
|
||||
|
||||
//check for error relevant contents and return an empty string if found
|
||||
size_t pos0 = line.find("Collected errors:");
|
||||
size_t pos01 = line.find(" * ");
|
||||
if (pos0 != string::npos || pos01 != string::npos)
|
||||
return "";
|
||||
|
||||
//split line and use name as return value
|
||||
size_t pos1 = line.find(" ");
|
||||
if (pos1 != string::npos)
|
||||
return line.substr(0, pos1);
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
string COPKGManager::getPkgInfo(const string& pkg_name, const string& pkg_key)
|
||||
{
|
||||
tmp_str.clear();
|
||||
execCmd(pkg_types[OM_INFO] + pkg_name, false, true);
|
||||
dprintf(DEBUG_INFO, "[COPKGManager] [%s - %d] [data: %s]\n", __func__, __LINE__, tmp_str.c_str());
|
||||
|
||||
return getKeyInfo(tmp_str, pkg_key, ":");
|
||||
}
|
||||
|
||||
string COPKGManager::getKeyInfo(const string& input, const std::string& key, const string& delimiters)
|
||||
{
|
||||
string s = input;
|
||||
size_t pos1 = s.find(key);
|
||||
if (pos1 != string::npos){
|
||||
size_t pos2 = s.find(delimiters, pos1)+ delimiters.length();
|
||||
if (pos2 != string::npos){
|
||||
size_t pos3 = s.find("\n", pos2);
|
||||
if (pos3 != string::npos){
|
||||
string ret = s.substr(pos2, pos3-pos2);
|
||||
return trim(ret, " ");
|
||||
}
|
||||
else
|
||||
dprintf(DEBUG_INFO, "[COPKGManager] [%s - %d] Error: [key: %s] missing end of line...\n", __func__, __LINE__, key.c_str());
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
int COPKGManager::execCmd(const char *cmdstr, bool verbose, bool acknowledge)
|
||||
@@ -470,6 +545,7 @@ int COPKGManager::execCmd(const char *cmdstr, bool verbose, bool acknowledge)
|
||||
string cmd = string(cmdstr);
|
||||
int res = 0;
|
||||
bool has_err = false;
|
||||
tmp_str.clear();
|
||||
string err_msg = "";
|
||||
if (verbose) {
|
||||
// cmd += " 2>&1";
|
||||
@@ -491,15 +567,23 @@ int COPKGManager::execCmd(const char *cmdstr, bool verbose, bool acknowledge)
|
||||
|
||||
//check for collected errors and build a message for screen if errors available
|
||||
if (has_err){
|
||||
dprintf(DEBUG_NORMAL, "[COPKGManager] [%s - %d] %s \n", __func__, __LINE__, line.c_str());
|
||||
size_t pos1 = line.find(" * opkg_");
|
||||
dprintf(DEBUG_NORMAL, "[COPKGManager] [%s - %d] cmd: %s\nresult: %s\n", __func__, __LINE__, cmd.c_str(), line.c_str());
|
||||
size_t pos1 = line.find(" * ");
|
||||
if (pos1 != string::npos){
|
||||
string str = line.substr(pos1, line.length()-pos1);
|
||||
err_msg += str.replace(pos1, 8,"") + "\n";
|
||||
err_msg += str.replace(pos1, 3,"") + "\n";
|
||||
}
|
||||
size_t pos01 = line.find("wget returned 4");
|
||||
//find obvious errors
|
||||
if (pos01 != string::npos)
|
||||
err_msg = "Network error! Online update not possible.";
|
||||
}else{
|
||||
size_t pos2 = line.find("Collected errors:");
|
||||
if (pos2 != string::npos)
|
||||
has_err = true;
|
||||
}
|
||||
if (!has_err)
|
||||
tmp_str += line + "\n";
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
|
@@ -42,7 +42,7 @@ class COPKGManager : public CMenuTarget
|
||||
{
|
||||
private:
|
||||
int width;
|
||||
|
||||
std::string tmp_str;
|
||||
CFrameBuffer *frameBuffer;
|
||||
|
||||
struct pkg;
|
||||
@@ -64,7 +64,9 @@ class COPKGManager : public CMenuTarget
|
||||
return execCmd(cmdstr.c_str(), verbose, acknowledge);
|
||||
};
|
||||
void getPkgData(const int pkg_content_id);
|
||||
static std::string getBlankPkgName(const std::string& line);
|
||||
std::string getBlankPkgName(const std::string& line);
|
||||
std::string getPkgInfo(const std::string& pkg_name, const std::string& pkg_key);
|
||||
std::string getKeyInfo(const std::string& input, const std::string& pkg_info_key, const std::string& delimiters);
|
||||
int showMenu();
|
||||
void updateMenu();
|
||||
void refreshMenu();
|
||||
@@ -74,13 +76,14 @@ class COPKGManager : public CMenuTarget
|
||||
|
||||
struct pkg {
|
||||
std::string name;
|
||||
std::string version;
|
||||
std::string desc;
|
||||
bool installed;
|
||||
bool upgradable;
|
||||
CMenuForwarder *forwarder;
|
||||
pkg() { }
|
||||
pkg(std::string &_name, std::string &_desc)
|
||||
: name(_name), desc(_desc), installed(false), upgradable(false) { }
|
||||
pkg(std::string &_name, std::string &_version, std::string &_desc)
|
||||
: name(_name), version(_version), desc(_desc), installed(false), upgradable(false) { }
|
||||
};
|
||||
public:
|
||||
COPKGManager();
|
||||
@@ -88,6 +91,6 @@ class COPKGManager : public CMenuTarget
|
||||
|
||||
int exec(CMenuTarget* parent, const std::string & actionKey);
|
||||
static bool hasOpkgSupport();
|
||||
bool hasUpdates();
|
||||
bool checkUpdates(const std::string & package_name = std::string(), bool show_progress = true);
|
||||
};
|
||||
#endif
|
||||
|
@@ -1894,6 +1894,7 @@ typedef enum
|
||||
LOCALE_OPKG_INSTALL_LOCAL_PACKAGE,
|
||||
LOCALE_OPKG_MESSAGEBOX_REINSTALL,
|
||||
LOCALE_OPKG_MESSAGEBOX_REMOVE,
|
||||
LOCALE_OPKG_MESSAGEBOX_UPDATES_AVAILABLE,
|
||||
LOCALE_OPKG_SUCCESS_INSTALL,
|
||||
LOCALE_OPKG_TITLE,
|
||||
LOCALE_OPKG_UPGRADE,
|
||||
|
@@ -1894,6 +1894,7 @@ const char * locale_real_names[] =
|
||||
"opkg.install.local.package",
|
||||
"opkg.messagebox.reinstall",
|
||||
"opkg.messagebox.remove",
|
||||
"opkg.messagebox.updates.available",
|
||||
"opkg.success.install",
|
||||
"opkg.title",
|
||||
"opkg.upgrade",
|
||||
|
Reference in New Issue
Block a user