opkg_manager: vizualize available package updates

This commit is contained in:
2021-04-10 15:51:30 +02:00
parent ff4e114876
commit 7289bcfd67
4 changed files with 83 additions and 38 deletions

View File

@@ -2253,7 +2253,7 @@ opkg.install.local.package Installiere lokales Paket
opkg.messagebox.reinstall %s erneut installieren? opkg.messagebox.reinstall %s erneut installieren?
opkg.messagebox.remove %s entfernen? opkg.messagebox.remove %s entfernen?
opkg.messagebox.size.error Nicht genügend freier Speicher für Paketinstallation verfügbar! opkg.messagebox.size.error Nicht genügend freier Speicher für Paketinstallation verfügbar!
opkg.messagebox.updates.available Aktualisierung(en) verfügbar! opkg.messagebox.updates.available Paket-Aktualisierung(en) verfügbar!
opkg.success.install Installation erfolgreich!\nNeustart von Neutrino kann erforderlich sein. Jetzt neu starten? opkg.success.install Installation erfolgreich!\nNeustart von Neutrino kann erforderlich sein. Jetzt neu starten?
opkg.title Paketverwaltung opkg.title Paketverwaltung
opkg.update.check Prüfe auf Updates ... opkg.update.check Prüfe auf Updates ...

View File

@@ -2253,7 +2253,7 @@ opkg.install.local.package Install local package
opkg.messagebox.reinstall Re-install %s? opkg.messagebox.reinstall Re-install %s?
opkg.messagebox.remove Remove %s? opkg.messagebox.remove Remove %s?
opkg.messagebox.size.error Not enough free memory available for this package! opkg.messagebox.size.error Not enough free memory available for this package!
opkg.messagebox.updates.available Update(s) available! opkg.messagebox.updates.available Package update(s) available!
opkg.success.install Install successful!\n restart of Neutrino might be required. Restart now? opkg.success.install Install successful!\n restart of Neutrino might be required. Restart now?
opkg.title Package Management opkg.title Package Management
opkg.update.check Checking for updates ... opkg.update.check Checking for updates ...

View File

@@ -1,11 +1,11 @@
/* /*
Based up Neutrino-GUI - Tuxbox-Project Based up Neutrino-GUI - Tuxbox-Project
Copyright (C) 2001 by Steffen Hehn 'McClean' Copyright (C) 2001 by Steffen Hehn 'McClean'
OPKG-Manager Class for Neutrino-GUI OPKG-Manager Class for Neutrino-GUI
Implementation: Implementation:
Copyright (C) 2012-2018 T. Graf 'dbt' Copyright (C) 2012-2020 T. Graf 'dbt'
www.dbox2-tuning.net www.dbox2-tuning.net
Adaptions: Adaptions:
@@ -34,7 +34,7 @@
#endif #endif
#include "opkg_manager.h" #include "opkg_manager.h"
#include <gui/widget/termwindow.h> #include "widget/termwindow.h"
/* hack, so we don't have to change all code below */ /* hack, so we don't have to change all code below */
#define CShellWindow CTermWindow #define CShellWindow CTermWindow
@@ -42,14 +42,14 @@
#include <neutrino.h> #include <neutrino.h>
#include <neutrino_menue.h> #include <neutrino_menue.h>
#include <gui/widget/icons.h> #include "widget/icons.h"
#include <gui/widget/msgbox.h> #include "widget/msgbox.h"
#include <gui/widget/progresswindow.h> #include "widget/progresswindow.h"
#include <gui/widget/hintbox.h> #include "widget/hintbox.h"
#include <gui/widget/keyboard_input.h> #include "widget/keyboard_input.h"
#include <driver/screen_max.h> #include <driver/screen_max.h>
#include <gui/filebrowser.h> #include "filebrowser.h"
#include <system/debug.h> #include <system/debug.h>
#include <system/helpers.h> #include <system/helpers.h>
#include <unistd.h> #include <unistd.h>
@@ -87,6 +87,8 @@
*/ */
#define SYSTEM_UPDATE "system-update" #define SYSTEM_UPDATE "system-update"
#define INFOBAR_TXT_FILE "/tmp/infobar.txt"
using namespace std; using namespace std;
enum enum
@@ -169,6 +171,10 @@ int COPKGManager::exec(CMenuTarget* parent, const string &actionKey)
int ret = showMenu(); int ret = showMenu();
saveConfig(); saveConfig();
CFileHelpers::removeDir(OPKG_TMP_DIR); CFileHelpers::removeDir(OPKG_TMP_DIR);
if (!num_updates)
removeInfoBarTxt();
return ret; return ret;
} }
int selected = menu->getSelected() - menu_offset; int selected = menu->getSelected() - menu_offset;
@@ -457,9 +463,55 @@ void COPKGManager::updateMenu()
} }
} }
bool COPKGManager::removeInfoBarTxt()
{
if (file_exists(INFOBAR_TXT_FILE))
{
//ensure remove infobar.txt with relevant content.
std::string txt = readFile(INFOBAR_TXT_FILE);
std::string update_text = g_Locale->getText(LOCALE_OPKG_MESSAGEBOX_UPDATES_AVAILABLE);
std::size_t found = txt.find(update_text);
if (found != std::string::npos)
{
unlink(INFOBAR_TXT_FILE);
return true;
}
}
return false;
}
void COPKGManager::initUpdateMessage(bool enable_message)
{
std::string update_count = to_string(num_updates) + " ";
std::string update_text = g_Locale->getText(LOCALE_OPKG_MESSAGEBOX_UPDATES_AVAILABLE);
std::string update_msg = update_count + update_text;
dprintf(DEBUG_NORMAL,"\033[32m[COPKGManager] [%s - %d] %s...\033[0m\n", __func__, __LINE__, update_msg.c_str());
if (enable_message && !removeInfoBarTxt())
DisplayInfoMessage(update_msg.c_str());
fstream f;
f.open(INFOBAR_TXT_FILE, ios::out);
f << update_msg << endl;
f.close();
}
void COPKGManager::setUpdateCheckResult(bool enable_message)
{
std::lock_guard<std::mutex> g(opk_mutex);
checkUpdates(std::string(), enable_message);
if (num_updates)
initUpdateMessage(enable_message);
else
removeInfoBarTxt();
}
bool COPKGManager::checkUpdates(const std::string & package_name, bool show_progress) bool COPKGManager::checkUpdates(const std::string & package_name, bool show_progress)
{ {
if (!hasOpkgSupport()) if (!hasOpkgSupport() || file_exists("/run/opkg.lock"))
return false; return false;
silent = !show_progress; silent = !show_progress;
@@ -497,11 +549,11 @@ bool COPKGManager::checkUpdates(const std::string & package_name, bool show_prog
if (it->second.upgradable){ if (it->second.upgradable){
dprintf(DEBUG_INFO, "[COPKGManager] [%s - %d] Update packages available for...%s\n", __func__, __LINE__, it->second.name.c_str()); 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){ if (!package_name.empty() && package_name == it->second.name)
ret = true; num_updates = 1;
}else else
ret = true;
num_updates++; num_updates++;
ret = true;
} }
i++; i++;
} }
@@ -544,6 +596,7 @@ int COPKGManager::doUpdate()
DisplayErrorMessage(msg.c_str()); DisplayErrorMessage(msg.c_str());
return r; return r;
} }
return 0; return 0;
} }
@@ -553,23 +606,10 @@ void COPKGManager::refreshMenu() {
updateMenu(); updateMenu();
} }
void COPKGManager::showUpdateCheckResult()
{
checkUpdates();
if (num_updates)
{
std::string update_msg = to_string(num_updates) + " ";
update_msg += g_Locale->getText(LOCALE_OPKG_MESSAGEBOX_UPDATES_AVAILABLE);
DisplayInfoMessage(update_msg.c_str());
}
}
int COPKGManager::showMenu() int COPKGManager::showMenu()
{ {
installed = false; installed = false;
showUpdateCheckResult(); setUpdateCheckResult(true);
#if 0 #if 0
getPkgData(OM_LIST); getPkgData(OM_LIST);
getPkgData(OM_LIST_UPGRADEABLE); getPkgData(OM_LIST_UPGRADEABLE);
@@ -625,7 +665,7 @@ int COPKGManager::showMenu()
//handling after successful installation //handling after successful installation
string exit_action = ""; string exit_action = "";
if (!has_err && installed){ if (!has_err && installed){
/*! /*
Show a success message only if restart/reboot is required and user should decide what to do or not. Show a success message only if restart/reboot is required and user should decide what to do or not.
NOTE: marker file should be generated by opkg package itself (eg. with preinstall scripts), NOTE: marker file should be generated by opkg package itself (eg. with preinstall scripts),
so it's controlled by the package maintainer! so it's controlled by the package maintainer!

View File

@@ -5,7 +5,7 @@
OPKG-Manager Class for Neutrino-GUI OPKG-Manager Class for Neutrino-GUI
Implementation: Implementation:
Copyright (C) 2012-2015 T. Graf 'dbt' Copyright (C) 2012-2020 T. Graf 'dbt'
www.dbox2-tuning.net www.dbox2-tuning.net
Adaptions: Adaptions:
@@ -36,6 +36,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <map> #include <map>
#include <mutex>
#define OPKG_MAX_FEEDS 10 #define OPKG_MAX_FEEDS 10
@@ -107,7 +108,10 @@ class COPKGManager : public CMenuTarget
std::string getBlankPkgName(const std::string& line); std::string getBlankPkgName(const std::string& line);
bool isInstalled(const std::string& pkg_name); bool isInstalled(const std::string& pkg_name);
bool isUpgradable(const std::string& pkg_name); bool isUpgradable(const std::string& pkg_name);
void showUpdateCheckResult();
void initUpdateMessage(bool enable_message = true);
bool removeInfoBarTxt();
std::mutex opk_mutex;
/*! /*!
* Gets an info from opkg command info or status from a package via keywords as std::string * Gets an info from opkg command info or status from a package via keywords as std::string
@@ -172,7 +176,8 @@ class COPKGManager : public CMenuTarget
int exec(CMenuTarget* parent, const std::string & actionKey); int exec(CMenuTarget* parent, const std::string & actionKey);
static bool hasOpkgSupport(); static bool hasOpkgSupport();
bool checkUpdates(const std::string & package_name = std::string(), bool show_progress = true); bool checkUpdates(const std::string & package_name = std::string(), bool show_progress = false);
void setUpdateCheckResult(bool enable_message = true);
bool installPackage(const std::string& pkg_name, std::string options = std::string(), bool force_configure = false); bool installPackage(const std::string& pkg_name, std::string options = std::string(), bool force_configure = false);
bool checkSize(const std::string& pkg_name); bool checkSize(const std::string& pkg_name);
}; };