mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-27 23:42:58 +02:00
gui/update.cpp: add function to check first url for image update;
check update version and timestamp to notify user about updates
This commit is contained in:
@@ -95,6 +95,7 @@ extern int allow_flash;
|
|||||||
#else
|
#else
|
||||||
#define MTD_DEVICE_OF_UPDATE_PART "/dev/mtd3"
|
#define MTD_DEVICE_OF_UPDATE_PART "/dev/mtd3"
|
||||||
#endif
|
#endif
|
||||||
|
int pinghost (const std::string &hostname, std::string *ip = NULL);
|
||||||
|
|
||||||
CFlashUpdate::CFlashUpdate()
|
CFlashUpdate::CFlashUpdate()
|
||||||
:CProgressWindow()
|
:CProgressWindow()
|
||||||
@@ -105,6 +106,7 @@ CFlashUpdate::CFlashUpdate()
|
|||||||
if (sysfs.empty())
|
if (sysfs.empty())
|
||||||
sysfs = MTD_DEVICE_OF_UPDATE_PART;
|
sysfs = MTD_DEVICE_OF_UPDATE_PART;
|
||||||
printf("Mtd partition to update: %s\n", sysfs.c_str());
|
printf("Mtd partition to update: %s\n", sysfs.c_str());
|
||||||
|
notify = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -128,6 +130,61 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool CFlashUpdate::checkOnlineVersion()
|
||||||
|
{
|
||||||
|
CHTTPTool httpTool;
|
||||||
|
std::string url;
|
||||||
|
std::string name;
|
||||||
|
std::string version;
|
||||||
|
std::string md5;
|
||||||
|
std::vector<std::string> updates_lists, urls, names, versions, descriptions, md5s;
|
||||||
|
int curVer, newVer;
|
||||||
|
bool newfound = false;
|
||||||
|
|
||||||
|
std::vector<CUpdateMenuTarget*> update_t_list;
|
||||||
|
|
||||||
|
CConfigFile _configfile('\t');
|
||||||
|
const char * versionString = (_configfile.loadConfig("/.version")) ? (_configfile.getString( "version", "????????????????").c_str()) : "????????????????";
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf("[update] file %s\n", g_settings.softupdate_url_file.c_str());
|
||||||
|
#endif
|
||||||
|
CFlashVersionInfo curInfo(versionString);
|
||||||
|
curVer = curInfo.getVersion();
|
||||||
|
printf("current flash-version: %s (%d) date %s (%ld)\n", versionString, curInfo.getVersion(), curInfo.getDate(), curInfo.getDateTime());
|
||||||
|
|
||||||
|
std::ifstream urlFile(g_settings.softupdate_url_file.c_str());
|
||||||
|
if (urlFile >> url) {
|
||||||
|
/* extract domain name */
|
||||||
|
std::string::size_type startpos, endpos;
|
||||||
|
std::string host;
|
||||||
|
startpos = url.find("//");
|
||||||
|
if (startpos != std::string::npos) {
|
||||||
|
startpos += 2;
|
||||||
|
endpos = url.find('/', startpos);
|
||||||
|
host = url.substr(startpos, endpos - startpos);
|
||||||
|
}
|
||||||
|
printf("[update] host %s\n", host.c_str());
|
||||||
|
if (host.empty() || (pinghost(host) != 1))
|
||||||
|
return false;
|
||||||
|
if (httpTool.downloadFile(url, gTmpPath LIST_OF_UPDATES_LOCAL_FILENAME, 20)) {
|
||||||
|
std::ifstream in(gTmpPath LIST_OF_UPDATES_LOCAL_FILENAME);
|
||||||
|
while (in >> url >> version >> md5 >> std::ws) {
|
||||||
|
CFlashVersionInfo versionInfo(version);
|
||||||
|
newVer = versionInfo.getVersion();
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf("[update] url %s version %s (%d) timestamp %s (%ld) md5 %s name %s\n", url.c_str(), version.c_str(), newVer, versionInfo.getDate(), versionInfo.getDateTime(), md5.c_str(), name.c_str());
|
||||||
|
#endif
|
||||||
|
if(versionInfo.snapshot < '3' && (newVer > curVer || versionInfo.getDateTime() > curInfo.getDateTime())) {
|
||||||
|
newfound = true;
|
||||||
|
printf("[update] found new image\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newfound;
|
||||||
|
}
|
||||||
|
|
||||||
//#define DEBUG
|
//#define DEBUG
|
||||||
bool CFlashUpdate::selectHttpImage(void)
|
bool CFlashUpdate::selectHttpImage(void)
|
||||||
{
|
{
|
||||||
@@ -141,14 +198,11 @@ bool CFlashUpdate::selectHttpImage(void)
|
|||||||
int selected = -1, listWidth = w_max (80, 10);
|
int selected = -1, listWidth = w_max (80, 10);
|
||||||
int curVer, newVer, newfound = 0;
|
int curVer, newVer, newfound = 0;
|
||||||
|
|
||||||
std::vector<CUpdateMenuTarget*> update_t_list;
|
|
||||||
|
|
||||||
CConfigFile _configfile('\t');
|
CConfigFile _configfile('\t');
|
||||||
const char * versionString = (_configfile.loadConfig("/.version")) ? (_configfile.getString( "version", "????????????????").c_str()) : "????????????????";
|
const char * versionString = (_configfile.loadConfig("/.version")) ? (_configfile.getString( "version", "????????????????").c_str()) : "????????????????";
|
||||||
installedVersion = versionString;
|
|
||||||
|
|
||||||
CFlashVersionInfo curInfo(versionString);
|
CFlashVersionInfo curInfo(versionString);
|
||||||
printf("current flash-version: %s (%d)\n", installedVersion.c_str(), curInfo.getVersion());
|
printf("current flash-version: %s (%d) date %s (%ld)\n", versionString, curInfo.getVersion(), curInfo.getDate(), curInfo.getDateTime());
|
||||||
curVer = curInfo.getVersion();
|
curVer = curInfo.getVersion();
|
||||||
|
|
||||||
httpTool.setStatusViewer(this);
|
httpTool.setStatusViewer(this);
|
||||||
@@ -215,9 +269,9 @@ bool CFlashUpdate::selectHttpImage(void)
|
|||||||
CFlashVersionInfo versionInfo(versions[i]);
|
CFlashVersionInfo versionInfo(versions[i]);
|
||||||
newVer = versionInfo.getVersion();
|
newVer = versionInfo.getVersion();
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("[update] url %s version %s (%d) md5 %s name %s\n", url.c_str(), version.c_str(), newVer, md5.c_str(), name.c_str());
|
printf("[update] url %s version %s (%d) timestamp %s (%ld) md5 %s name %s\n", url.c_str(), version.c_str(), newVer, versionInfo.getDate(), versionInfo.getDateTime(), md5.c_str(), name.c_str());
|
||||||
#endif
|
#endif
|
||||||
if(newVer > curVer)
|
if(versionInfo.snapshot < '3' && (newVer > curVer || versionInfo.getDateTime() > curInfo.getDateTime()))
|
||||||
newfound = 1;
|
newfound = 1;
|
||||||
if(!allow_flash && (versionInfo.snapshot < '3'))
|
if(!allow_flash && (versionInfo.snapshot < '3'))
|
||||||
enabled = false;
|
enabled = false;
|
||||||
@@ -235,8 +289,7 @@ bool CFlashUpdate::selectHttpImage(void)
|
|||||||
|
|
||||||
//SelectionWidget.addItem(new CMenuForwarder(names[i].c_str(), enabled, descriptions[i].c_str(), new CUpdateMenuTarget(i, &selected)));
|
//SelectionWidget.addItem(new CMenuForwarder(names[i].c_str(), enabled, descriptions[i].c_str(), new CUpdateMenuTarget(i, &selected)));
|
||||||
CUpdateMenuTarget * up = new CUpdateMenuTarget(i, &selected);
|
CUpdateMenuTarget * up = new CUpdateMenuTarget(i, &selected);
|
||||||
update_t_list.push_back(up);
|
SelectionWidget.addItem(new CMenuDForwarder(descriptions[i].c_str(), enabled, names[i].c_str(), up));
|
||||||
SelectionWidget.addItem(new CMenuForwarder(descriptions[i].c_str(), enabled, names[i].c_str(), up));
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -249,16 +302,15 @@ bool CFlashUpdate::selectHttpImage(void)
|
|||||||
ShowMsg(LOCALE_MESSAGEBOX_ERROR, g_Locale->getText(LOCALE_FLASHUPDATE_GETINFOFILEERROR), CMessageBox::mbrOk, CMessageBox::mbOk); // UTF-8
|
ShowMsg(LOCALE_MESSAGEBOX_ERROR, g_Locale->getText(LOCALE_FLASHUPDATE_GETINFOFILEERROR), CMessageBox::mbrOk, CMessageBox::mbOk); // UTF-8
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(newfound)
|
if (notify) {
|
||||||
ShowMsg(LOCALE_MESSAGEBOX_INFO, g_Locale->getText(LOCALE_FLASHUPDATE_NEW_FOUND), CMessageBox::mbrOk, CMessageBox::mbOk, NEUTRINO_ICON_INFO);
|
if(newfound)
|
||||||
else
|
ShowMsg(LOCALE_MESSAGEBOX_INFO, g_Locale->getText(LOCALE_FLASHUPDATE_NEW_FOUND), CMessageBox::mbrOk, CMessageBox::mbOk, NEUTRINO_ICON_INFO);
|
||||||
ShowMsg(LOCALE_MESSAGEBOX_INFO, g_Locale->getText(LOCALE_FLASHUPDATE_NEW_NOTFOUND), CMessageBox::mbrOk, CMessageBox::mbOk, NEUTRINO_ICON_INFO);
|
else
|
||||||
|
ShowMsg(LOCALE_MESSAGEBOX_INFO, g_Locale->getText(LOCALE_FLASHUPDATE_NEW_NOTFOUND), CMessageBox::mbrOk, CMessageBox::mbOk, NEUTRINO_ICON_INFO);
|
||||||
|
}
|
||||||
|
|
||||||
menu_ret = SelectionWidget.exec(NULL, "");
|
menu_ret = SelectionWidget.exec(NULL, "");
|
||||||
|
|
||||||
for (std::vector<CUpdateMenuTarget*>::iterator it = update_t_list.begin(); it != update_t_list.end(); ++it)
|
|
||||||
delete (*it);
|
|
||||||
|
|
||||||
if (selected == -1)
|
if (selected == -1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@@ -53,8 +53,8 @@ class CFlashUpdate : public CProgressWindow
|
|||||||
std::string sysfs;
|
std::string sysfs;
|
||||||
char fileType;
|
char fileType;
|
||||||
int width;
|
int width;
|
||||||
|
bool notify;
|
||||||
|
|
||||||
std::string installedVersion;
|
|
||||||
std::string newVersion;
|
std::string newVersion;
|
||||||
int menu_ret;
|
int menu_ret;
|
||||||
int softupdate_mode;
|
int softupdate_mode;
|
||||||
@@ -66,6 +66,8 @@ class CFlashUpdate : public CProgressWindow
|
|||||||
public:
|
public:
|
||||||
CFlashUpdate();
|
CFlashUpdate();
|
||||||
int exec( CMenuTarget* parent, const std::string & actionKey );
|
int exec( CMenuTarget* parent, const std::string & actionKey );
|
||||||
|
bool checkOnlineVersion();
|
||||||
|
void enableNotify(bool enable) { notify = enable; }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user