- update: formatting code using astyle; some manual code nicenings

Conflicts:
	src/gui/update.cpp
	src/gui/update.h

Signed-off-by: Thilo Graf <dbt@novatux.de>
This commit is contained in:
svenhoefer
2021-12-06 05:18:19 +01:00
committed by Thilo Graf
parent 863dac9275
commit 389772e1a8
2 changed files with 323 additions and 250 deletions

View File

@@ -86,9 +86,8 @@
extern cVideo *videoDecoder; extern cVideo *videoDecoder;
#endif #endif
#if 0 //softupdate
#include <sys/stat.h> #include <sys/stat.h>
#endif
extern int allow_flash; extern int allow_flash;
//#define DRYRUN //#define DRYRUN
@@ -116,8 +115,7 @@ extern int allow_flash;
int pinghost(const std::string &hostname, std::string *ip = NULL); int pinghost(const std::string &hostname, std::string *ip = NULL);
CFlashUpdate::CFlashUpdate() CFlashUpdate::CFlashUpdate() : CProgressWindow()
:CProgressWindow()
{ {
width = 40; width = 40;
setTitle(LOCALE_FLASHUPDATE_HEAD); setTitle(LOCALE_FLASHUPDATE_HEAD);
@@ -129,8 +127,6 @@ CFlashUpdate::CFlashUpdate()
gotImage = false; // NOTE: local update can't set gotImage variable! gotImage = false; // NOTE: local update can't set gotImage variable!
} }
class CUpdateMenuTarget : public CMenuTarget class CUpdateMenuTarget : public CMenuTarget
{ {
int myID; int myID;
@@ -150,7 +146,6 @@ public:
} }
}; };
#if 0
void CFlashUpdate::update_php(std::string &url, const char *type) void CFlashUpdate::update_php(std::string &url, const char *type)
{ {
if (url.find("update.php") != std::string::npos) if (url.find("update.php") != std::string::npos)
@@ -165,7 +160,7 @@ void CFlashUpdate::update_php(std::string &url, const char* type)
printf("[update_php] url %s\n", url.c_str()); printf("[update_php] url %s\n", url.c_str());
} }
} }
#endif
bool CFlashUpdate::checkOnlineVersion() bool CFlashUpdate::checkOnlineVersion()
{ {
CHTTPTool httpTool; CHTTPTool httpTool;
@@ -189,13 +184,15 @@ bool CFlashUpdate::checkOnlineVersion()
dprintf(DEBUG_NORMAL, "[update] current flash-version: %s (%d) date %s (%ld)\n", versionString.c_str(), curInfo.getVersion(), curInfo.getDate(), curInfo.getDateTime()); dprintf(DEBUG_NORMAL, "[update] current flash-version: %s (%d) date %s (%ld)\n", versionString.c_str(), curInfo.getVersion(), curInfo.getDate(), curInfo.getDateTime());
std::ifstream urlFile(g_settings.softupdate_url_file.c_str()); std::ifstream urlFile(g_settings.softupdate_url_file.c_str());
if (urlFile >> url) { if (urlFile >> url)
/* extract domain name */ {
// extract domain name
std::string::size_type startpos, endpos; std::string::size_type startpos, endpos;
std::string host; std::string host;
startpos = url.find("//"); startpos = url.find("//");
if (startpos != std::string::npos) { if (startpos != std::string::npos)
//update_php(url, curInfo.getType()); //NI {
update_php(url, curInfo.getType());
startpos += 2; startpos += 2;
endpos = url.find('/', startpos); endpos = url.find('/', startpos);
host = url.substr(startpos, endpos - startpos); host = url.substr(startpos, endpos - startpos);
@@ -203,14 +200,17 @@ bool CFlashUpdate::checkOnlineVersion()
dprintf(DEBUG_NORMAL, "[update] host %s\n", host.c_str()); dprintf(DEBUG_NORMAL, "[update] host %s\n", host.c_str());
if (host.empty() || (pinghost(host) != 1)) if (host.empty() || (pinghost(host) != 1))
return false; return false;
if (httpTool.downloadFile(url, gTmpPath LIST_OF_UPDATES_LOCAL_FILENAME, 20)) { if (httpTool.downloadFile(url, gTmpPath LIST_OF_UPDATES_LOCAL_FILENAME, 20))
{
std::ifstream in(gTmpPath LIST_OF_UPDATES_LOCAL_FILENAME); std::ifstream in(gTmpPath LIST_OF_UPDATES_LOCAL_FILENAME);
while (in >> url >> version >> md5 >> std::ws) { while (in >> url >> version >> md5 >> std::ws)
{
std::getline(in, name); std::getline(in, name);
CFlashVersionInfo versionInfo(version); CFlashVersionInfo versionInfo(version);
newVer = versionInfo.getVersion(); newVer = versionInfo.getVersion();
dprintf(DEBUG_NORMAL, "[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()); dprintf(DEBUG_NORMAL, "[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());
if(versionInfo.snapshot <= '2' && (newVer > curVer || versionInfo.getDateTime() > curInfo.getDateTime())) { if (versionInfo.snapshot <= '2' && (newVer > curVer || versionInfo.getDateTime() > curInfo.getDateTime()))
{
newfound = true; newfound = true;
dprintf(DEBUG_NORMAL, "[update] found new image\n"); dprintf(DEBUG_NORMAL, "[update] found new image\n");
break; break;
@@ -272,7 +272,7 @@ bool CFlashUpdate::selectHttpImage(void)
std::string::size_type startpos, endpos; std::string::size_type startpos, endpos;
dprintf(DEBUG_NORMAL, "[update] url %s\n", url.c_str()); dprintf(DEBUG_NORMAL, "[update] url %s\n", url.c_str());
/* extract domain name */ // extract domain name
startpos = url.find("//"); startpos = url.find("//");
if (startpos == std::string::npos) if (startpos == std::string::npos)
{ {
@@ -280,14 +280,12 @@ bool CFlashUpdate::selectHttpImage(void)
} }
else else
{ {
// update_php(url, curInfo.getType()); update_php(url, curInfo.getType());
startpos = url.find('/', startpos + 2) + 1; startpos = url.find('/', startpos + 2) + 1;
} }
endpos = std::string::npos; endpos = std::string::npos;
updates_lists.push_back(url.substr(startpos, endpos - startpos)); updates_lists.push_back(url.substr(startpos, endpos - startpos));
// don't paint separator for lists with no entry
// SelectionWidget.addItem(new CMenuSeparator(CMenuSeparator::STRING | CMenuSeparator::LINE, updates_lists.rbegin()->c_str()));
bool separator = false; bool separator = false;
if (httpTool.downloadFile(url, gTmpPath LIST_OF_UPDATES_LOCAL_FILENAME, 20)) if (httpTool.downloadFile(url, gTmpPath LIST_OF_UPDATES_LOCAL_FILENAME, 20))
@@ -321,7 +319,7 @@ bool CFlashUpdate::selectHttpImage(void)
description += ", "; description += ", ";
description += versionInfo.getTime(); description += versionInfo.getTime();
descriptions.push_back(description); /* workaround since CMenuForwarder does not store the Option String itself */ descriptions.push_back(description); // workaround since CMenuForwarder does not store the Option String itself
if (!separator) if (!separator)
{ {
@@ -332,7 +330,7 @@ bool CFlashUpdate::selectHttpImage(void)
} }
CUpdateMenuTarget *up = new CUpdateMenuTarget(i, &selected); CUpdateMenuTarget *up = new CUpdateMenuTarget(i, &selected);
mf = new CMenuDForwarder(descriptions[i].c_str(), enabled, names[i].c_str(), up); mf = new CMenuDForwarder(descriptions[i].c_str(), enabled, names[i].c_str(), up);
//TODO mf->setHint(NEUTRINO_ICON_HINT_SW_UPDATE, ""); //mf->setHint(NEUTRINO_ICON_HINT_SW_UPDATE, "");
SelectionWidget.addItem(mf, i == 0); // first entry is preselected SelectionWidget.addItem(mf, i == 0); // first entry is preselected
i++; i++;
} }
@@ -346,7 +344,8 @@ bool CFlashUpdate::selectHttpImage(void)
DisplayErrorMessage(g_Locale->getText(LOCALE_FLASHUPDATE_GETINFOFILEERROR)); DisplayErrorMessage(g_Locale->getText(LOCALE_FLASHUPDATE_GETINFOFILEERROR));
return false; return false;
} }
if (notify) { if (notify)
{
if (newfound) if (newfound)
ShowMsg(LOCALE_MESSAGEBOX_INFO, LOCALE_FLASHUPDATE_NEW_FOUND, CMsgBox::mbrOk, CMsgBox::mbOk, NEUTRINO_ICON_INFO, MSGBOX_MIN_WIDTH, 6); ShowMsg(LOCALE_MESSAGEBOX_INFO, LOCALE_FLASHUPDATE_NEW_FOUND, CMsgBox::mbrOk, CMsgBox::mbOk, NEUTRINO_ICON_INFO, MSGBOX_MIN_WIDTH, 6);
#if 0 #if 0
@@ -371,7 +370,8 @@ bool CFlashUpdate::selectHttpImage(void)
{ {
int esize = CMTDInfo::getInstance()->getMTDEraseSize(sysfs); int esize = CMTDInfo::getInstance()->getMTDEraseSize(sysfs);
dprintf(DEBUG_NORMAL, "[update] erase size is %x\n", esize); dprintf(DEBUG_NORMAL, "[update] erase size is %x\n", esize);
if (esize == 0x40000) { if (esize == 0x40000)
{
filename += ".256k"; filename += ".256k";
} }
} }
@@ -396,8 +396,10 @@ bool CFlashUpdate::getUpdateImage(const std::string & version)
httpTool.setStatusViewer(this); httpTool.setStatusViewer(this);
fname = rindex(filename.c_str(), '/'); fname = rindex(filename.c_str(), '/');
if(fname != NULL) fname++; if (fname != NULL)
else return false; fname++;
else
return false;
sprintf(dest_name, "%s/%s", g_settings.update_dir.c_str(), fname); sprintf(dest_name, "%s/%s", g_settings.update_dir.c_str(), fname);
showStatusMessageUTF(std::string(g_Locale->getText(LOCALE_FLASHUPDATE_GETUPDATEFILE)) + ' ' + version); showStatusMessageUTF(std::string(g_Locale->getText(LOCALE_FLASHUPDATE_GETUPDATEFILE)) + ' ' + version);
@@ -474,7 +476,8 @@ bool CFlashUpdate::checkVersion4Update()
UpdatesBrowser.Filter = &UpdatesFilter; UpdatesBrowser.Filter = &UpdatesFilter;
CFile *file_selected = NULL; CFile *file_selected = NULL;
if (!(UpdatesBrowser.exec(g_settings.update_dir.c_str()))) { if (!(UpdatesBrowser.exec(g_settings.update_dir.c_str())))
{
menu_ret = UpdatesBrowser.getMenuRet(); menu_ret = UpdatesBrowser.getMenuRet();
return false; return false;
} }
@@ -489,7 +492,8 @@ bool CFlashUpdate::checkVersion4Update()
FILE *fd = fopen(filename.c_str(), "r"); FILE *fd = fopen(filename.c_str(), "r");
if (fd) if (fd)
fclose(fd); fclose(fd);
else { else
{
hide(); hide();
dprintf(DEBUG_NORMAL, "[update] flash/package-file not found: %s\n", filename.c_str()); dprintf(DEBUG_NORMAL, "[update] flash/package-file not found: %s\n", filename.c_str());
DisplayErrorMessage(g_Locale->getText(LOCALE_FLASHUPDATE_CANTOPENFILE)); DisplayErrorMessage(g_Locale->getText(LOCALE_FLASHUPDATE_CANTOPENFILE));
@@ -499,11 +503,14 @@ bool CFlashUpdate::checkVersion4Update()
#if ENABLE_PKG_MANAGEMENT #if ENABLE_PKG_MANAGEMENT
// package install: // package install:
if (file_selected->getType() == CFile::FILE_PKG_PACKAGE){ if (file_selected->getType() == CFile::FILE_PKG_PACKAGE)
{
COPKGManager opkg; COPKGManager opkg;
if (opkg.hasOpkgSupport()){ if (opkg.hasOpkgSupport())
{
int msgres = ShowMsg(LOCALE_MESSAGEBOX_INFO, LOCALE_OPKG_WARNING_3RDPARTY_PACKAGES, CMsgBox::mbrNo, CMsgBox::mbYes | CMsgBox::mbNo, NEUTRINO_ICON_UPDATE, 700); int msgres = ShowMsg(LOCALE_MESSAGEBOX_INFO, LOCALE_OPKG_WARNING_3RDPARTY_PACKAGES, CMsgBox::mbrNo, CMsgBox::mbYes | CMsgBox::mbNo, NEUTRINO_ICON_UPDATE, 700);
if (msgres == CMsgBox::mbrYes){ if (msgres == CMsgBox::mbrYes)
{
if (!opkg.installPackage(UpdatesBrowser.getSelectedFile()->Name)) if (!opkg.installPackage(UpdatesBrowser.getSelectedFile()->Name))
DisplayErrorMessage(g_Locale->getText(LOCALE_OPKG_FAILURE_INSTALL)); DisplayErrorMessage(g_Locale->getText(LOCALE_OPKG_FAILURE_INSTALL));
} }
@@ -517,7 +524,8 @@ bool CFlashUpdate::checkVersion4Update()
// set internal filetype // set internal filetype
char const *ptr = rindex(filename.c_str(), '.'); char const *ptr = rindex(filename.c_str(), '.');
if(ptr) { if (ptr)
{
ptr++; ptr++;
if (!strcmp(ptr, "bin")) if (!strcmp(ptr, "bin"))
fileType = 'A'; fileType = 'A';
@@ -553,12 +561,14 @@ int CFlashUpdate::exec(CMenuTarget* parent, const std::string &actionKey)
menu_ret = menu_return::RETURN_REPAINT; menu_ret = menu_return::RETURN_REPAINT;
paint(); paint();
if(sysfs.size() < 8) { if (sysfs.size() < 8)
{
DisplayErrorMessage(g_Locale->getText(LOCALE_FLASHUPDATE_CANTOPENMTD)); DisplayErrorMessage(g_Locale->getText(LOCALE_FLASHUPDATE_CANTOPENMTD));
hide(); hide();
return menu_return::RETURN_REPAINT; return menu_return::RETURN_REPAINT;
} }
if(!checkVersion4Update()) { if (!checkVersion4Update())
{
hide(); hide();
return menu_ret; return menu_ret;
} }
@@ -568,7 +578,6 @@ int CFlashUpdate::exec(CMenuTarget* parent, const std::string &actionKey)
CVFD::getInstance()->setMode(CLCD::MODE_PROGRESSBAR2); CVFD::getInstance()->setMode(CLCD::MODE_PROGRESSBAR2);
#endif // VFD_UPDATE #endif // VFD_UPDATE
paint(); paint();
showGlobalStatus(20); showGlobalStatus(20);
@@ -577,7 +586,8 @@ int CFlashUpdate::exec(CMenuTarget* parent, const std::string &actionKey)
char const *fname = rindex(filename.c_str(), '/') + 1; char const *fname = rindex(filename.c_str(), '/') + 1;
char fullname[255]; char fullname[255];
if(!getUpdateImage(newVersion)) { if (!getUpdateImage(newVersion))
{
hide(); hide();
DisplayErrorMessage(g_Locale->getText(LOCALE_FLASHUPDATE_GETUPDATEFILEERROR)); DisplayErrorMessage(g_Locale->getText(LOCALE_FLASHUPDATE_GETUPDATEFILEERROR));
return menu_return::RETURN_REPAINT; return menu_return::RETURN_REPAINT;
@@ -593,12 +603,14 @@ int CFlashUpdate::exec(CMenuTarget* parent, const std::string &actionKey)
ft.setStatusViewer(this); ft.setStatusViewer(this);
showStatusMessageUTF(g_Locale->getText(LOCALE_FLASHUPDATE_MD5CHECK)); showStatusMessageUTF(g_Locale->getText(LOCALE_FLASHUPDATE_MD5CHECK));
if((softupdate_mode==1) && !ft.check_md5(filename, file_md5)) { if ((softupdate_mode == 1) && !ft.check_md5(filename, file_md5))
{
hide(); hide();
DisplayErrorMessage(g_Locale->getText(LOCALE_FLASHUPDATE_MD5SUMERROR)); DisplayErrorMessage(g_Locale->getText(LOCALE_FLASHUPDATE_MD5SUMERROR));
return menu_return::RETURN_REPAINT; return menu_return::RETURN_REPAINT;
} }
if(softupdate_mode==1) { //internet-update if (softupdate_mode == 1) // internet-update
{
if (ShowMsg(LOCALE_MESSAGEBOX_INFO, gotImage ? LOCALE_FLASHUPDATE_INSTALL_IMAGE : LOCALE_FLASHUPDATE_INSTALL_PACKAGE, CMsgBox::mbrYes, CMsgBox::mbYes | CMsgBox::mbNo, NEUTRINO_ICON_UPDATE) != CMsgBox::mbrYes) if (ShowMsg(LOCALE_MESSAGEBOX_INFO, gotImage ? LOCALE_FLASHUPDATE_INSTALL_IMAGE : LOCALE_FLASHUPDATE_INSTALL_PACKAGE, CMsgBox::mbrYes, CMsgBox::mbYes | CMsgBox::mbNo, NEUTRINO_ICON_UPDATE) != CMsgBox::mbrYes)
{ {
hide(); hide();
@@ -614,9 +626,11 @@ int CFlashUpdate::exec(CMenuTarget* parent, const std::string &actionKey)
{ {
#if ENABLE_EXTUPDATE #if ENABLE_EXTUPDATE
#ifndef BOXMODEL_CST_HD2 #ifndef BOXMODEL_CST_HD2
if (g_settings.apply_settings) { if (g_settings.apply_settings)
{
if (ShowMsg(LOCALE_MESSAGEBOX_INFO, LOCALE_FLASHUPDATE_APPLY_SETTINGS, CMsgBox::mbrYes, CMsgBox::mbYes | CMsgBox::mbNo, NEUTRINO_ICON_UPDATE) == CMsgBox::mbrYes) if (ShowMsg(LOCALE_MESSAGEBOX_INFO, LOCALE_FLASHUPDATE_APPLY_SETTINGS, CMsgBox::mbrYes, CMsgBox::mbYes | CMsgBox::mbNo, NEUTRINO_ICON_UPDATE) == CMsgBox::mbrYes)
if (!CExtUpdate::getInstance()->applySettings(filename, CExtUpdate::MODE_SOFTUPDATE)) { if (!CExtUpdate::getInstance()->applySettings(filename, CExtUpdate::MODE_SOFTUPDATE))
{
hide(); hide();
return menu_return::RETURN_REPAINT; return menu_return::RETURN_REPAINT;
} }
@@ -713,7 +727,8 @@ int CFlashUpdate::exec(CMenuTarget* parent, const std::string &actionKey)
restart = ShowMsg(LOCALE_MESSAGEBOX_INFO, LOCALE_FLASHUPDATE_START_SELECTED_PARTITION, CMsgBox::mbrYes, CMsgBox::mbYes | CMsgBox::mbNo, NEUTRINO_ICON_UPDATE); restart = ShowMsg(LOCALE_MESSAGEBOX_INFO, LOCALE_FLASHUPDATE_START_SELECTED_PARTITION, CMsgBox::mbrYes, CMsgBox::mbYes | CMsgBox::mbNo, NEUTRINO_ICON_UPDATE);
if (restart == CMsgBox::mbrYes) if (restart == CMsgBox::mbrYes)
{ {
if(g_settings.hdmi_cec_standby){ if (g_settings.hdmi_cec_standby)
{
videoDecoder->SetCECMode((VIDEO_HDMI_CEC_MODE)0); videoDecoder->SetCECMode((VIDEO_HDMI_CEC_MODE)0);
} }
std::string startup_new("/boot/"); std::string startup_new("/boot/");
@@ -725,7 +740,9 @@ int CFlashUpdate::exec(CMenuTarget* parent, const std::string &actionKey)
fh.copyFile(startup_new.c_str(), "/boot/STARTUP"); fh.copyFile(startup_new.c_str(), "/boot/STARTUP");
#endif #endif
} }
} else if (selected > 0 && strcmp(c, to_string(selected).c_str()) == 0) { }
else if (selected > 0 && strcmp(c, to_string(selected).c_str()) == 0)
{
flashing = true; flashing = true;
ofgwrite_options = "-m" + to_string(selected); ofgwrite_options = "-m" + to_string(selected);
} }
@@ -738,6 +755,9 @@ int CFlashUpdate::exec(CMenuTarget* parent, const std::string &actionKey)
#ifndef DRYRUN #ifndef DRYRUN
if (flashing) if (flashing)
{ {
if (FILE *f = fopen("/tmp/.flash.start", "w"))
fclose(f);
CVFD::getInstance()->setMode(CVFD::MODE_MENU_UTF8); CVFD::getInstance()->setMode(CVFD::MODE_MENU_UTF8);
CVFD::getInstance()->showMenuText(0, "ofgwrite Flashing Tool", -1, true); CVFD::getInstance()->showMenuText(0, "ofgwrite Flashing Tool", -1, true);
my_system(4, ofgwrite_caller.c_str(), g_settings.update_dir.c_str(), filename.c_str(), ofgwrite_options.c_str()); my_system(4, ofgwrite_caller.c_str(), g_settings.update_dir.c_str(), filename.c_str(), ofgwrite_options.c_str());
@@ -759,7 +779,8 @@ int CFlashUpdate::exec(CMenuTarget* parent, const std::string &actionKey)
else if (fileType == 'T') // not image, display file contents else if (fileType == 'T') // not image, display file contents
{ {
FILE *fd = fopen(filename.c_str(), "r"); FILE *fd = fopen(filename.c_str(), "r");
if(fd) { if (fd)
{
char *buffer; char *buffer;
off_t filesize = lseek(fileno(fd), 0, SEEK_END); off_t filesize = lseek(fileno(fd), 0, SEEK_END);
lseek(fileno(fd), 0, SEEK_SET); lseek(fileno(fd), 0, SEEK_SET);
@@ -808,11 +829,13 @@ CFlashExpert* CFlashExpert::getInstance()
bool CFlashExpert::checkSize(int mtd, std::string &backupFile) bool CFlashExpert::checkSize(int mtd, std::string &backupFile)
{ {
#ifndef BOXMODEL_CST_HD2 #ifndef BOXMODEL_CST_HD2
if (mtd < 0) return false; if (mtd < 0)
return false;
#endif #endif
char errMsg[1024] = {0}; char errMsg[1024] = {0};
std::string path = getPathName(backupFile); std::string path = getPathName(backupFile);
if (!file_exists(path.c_str())) { if (!file_exists(path.c_str()))
{
snprintf(errMsg, sizeof(errMsg) - 1, g_Locale->getText(LOCALE_FLASHUPDATE_READ_DIRECTORY_NOT_EXIST), path.c_str()); snprintf(errMsg, sizeof(errMsg) - 1, g_Locale->getText(LOCALE_FLASHUPDATE_READ_DIRECTORY_NOT_EXIST), path.c_str());
DisplayErrorMessage(errMsg); DisplayErrorMessage(errMsg);
return false; return false;
@@ -822,8 +845,10 @@ bool CFlashExpert::checkSize(int mtd, std::string &backupFile)
long bsize = 0; long bsize = 0;
uint64_t backupRequiredSize = 0; uint64_t backupRequiredSize = 0;
#ifdef BOXMODEL_CST_HD2 #ifdef BOXMODEL_CST_HD2
if (mtd == -1) { // check disk space for image creation if (mtd == -1) // check disk space for image creation
if (!get_fs_usage("/", btotal, bused, &bsize)) { {
if (!get_fs_usage("/", btotal, bused, &bsize))
{
snprintf(errMsg, sizeof(errMsg) - 1, g_Locale->getText(LOCALE_FLASHUPDATE_READ_VOLUME_ERROR), "root0"); snprintf(errMsg, sizeof(errMsg) - 1, g_Locale->getText(LOCALE_FLASHUPDATE_READ_VOLUME_ERROR), "root0");
DisplayErrorMessage(errMsg); DisplayErrorMessage(errMsg);
return false; return false;
@@ -837,7 +862,8 @@ bool CFlashExpert::checkSize(int mtd, std::string &backupFile)
backupRequiredSize = CMTDInfo::getInstance()->getMTDSize(mtd) / 1024ULL; backupRequiredSize = CMTDInfo::getInstance()->getMTDSize(mtd) / 1024ULL;
btotal = 0; bused = 0; bsize = 0; btotal = 0; bused = 0; bsize = 0;
if (!get_fs_usage(path.c_str(), btotal, bused, &bsize)) { if (!get_fs_usage(path.c_str(), btotal, bused, &bsize))
{
snprintf(errMsg, sizeof(errMsg) - 1, g_Locale->getText(LOCALE_FLASHUPDATE_READ_VOLUME_ERROR), path.c_str()); snprintf(errMsg, sizeof(errMsg) - 1, g_Locale->getText(LOCALE_FLASHUPDATE_READ_VOLUME_ERROR), path.c_str());
DisplayErrorMessage(errMsg); DisplayErrorMessage(errMsg);
return false; return false;
@@ -848,7 +874,8 @@ bool CFlashExpert::checkSize(int mtd, std::string &backupFile)
dprintf(DEBUG_INFO, "##### [%s] backupMaxSize: %" PRIu64 ", btotal: %" PRIu64 ", bused: %" PRIu64 ", bsize: %ld\n", dprintf(DEBUG_INFO, "##### [%s] backupMaxSize: %" PRIu64 ", btotal: %" PRIu64 ", bused: %" PRIu64 ", bsize: %ld\n",
__func__, backupMaxSize, btotal, bused, bsize); __func__, backupMaxSize, btotal, bused, bsize);
if (backupMaxSize < backupRequiredSize) { if (backupMaxSize < backupRequiredSize)
{
snprintf(errMsg, sizeof(errMsg) - 1, g_Locale->getText(LOCALE_FLASHUPDATE_READ_NO_AVAILABLE_SPACE), path.c_str(), to_string(backupMaxSize).c_str(), to_string(backupRequiredSize).c_str()); snprintf(errMsg, sizeof(errMsg) - 1, g_Locale->getText(LOCALE_FLASHUPDATE_READ_NO_AVAILABLE_SPACE), path.c_str(), to_string(backupMaxSize).c_str(), to_string(backupRequiredSize).c_str());
DisplayErrorMessage(errMsg); DisplayErrorMessage(errMsg);
return false; return false;
@@ -861,33 +888,39 @@ bool CFlashExpert::checkSize(int mtd, std::string &backupFile)
bool CFlashExpert::readDevtableFile(std::string &devtableFile, CMkfsJFFS2::v_devtable_t &v_devtable) bool CFlashExpert::readDevtableFile(std::string &devtableFile, CMkfsJFFS2::v_devtable_t &v_devtable)
{ {
FILE *fd = fopen(devtableFile.c_str(), "r"); FILE *fd = fopen(devtableFile.c_str(), "r");
if (!fd) return false; if (!fd)
return false;
char lineRead[1024]; char lineRead[1024];
memset(lineRead, 0, sizeof(lineRead)); memset(lineRead, 0, sizeof(lineRead));
bool status = false; bool status = false;
while (fgets(lineRead, sizeof(lineRead)-1, fd)) { while (fgets(lineRead, sizeof(lineRead) - 1, fd))
{
std::string line = lineRead; std::string line = lineRead;
line = trim(line); line = trim(line);
// ignore comments // ignore comments
if (line.find_first_of("#") == 0) { if (line.find_first_of("#") == 0)
{
continue; continue;
} }
// ignore comments after the entry // ignore comments after the entry
size_t pos = line.find_first_of("#"); size_t pos = line.find_first_of("#");
if (pos != std::string::npos) { if (pos != std::string::npos)
{
line = line.substr(0, pos); line = line.substr(0, pos);
line = trim(line); line = trim(line);
} }
// minimal entry: "/dev/x x 0000" // minimal entry: "/dev/x x 0000"
// length = 13 // length = 13
if (line.length() > 12) { if (line.length() > 12)
{
v_devtable.push_back(line); v_devtable.push_back(line);
status = true; status = true;
} }
memset(lineRead, 0, sizeof(lineRead)); memset(lineRead, 0, sizeof(lineRead));
} }
fclose(fd); fclose(fd);
if (!status) return false; if (!status)
return false;
return true; return true;
} }
@@ -903,20 +936,26 @@ void CFlashExpert::readmtdJFFS2(std::string &filename, std::string title/*=""*/,
progress.paint(); progress.paint();
int eSize = CMTDInfo::getInstance()->getMTDEraseSize(CMTDInfo::getInstance()->findMTDsystem()); int eSize = CMTDInfo::getInstance()->getMTDEraseSize(CMTDInfo::getInstance()->findMTDsystem());
if (createimage_other == 1) { if (createimage_other == 1)
if (eSize == 0x40000) eSize = 0x20000; {
else if (eSize == 0x20000) eSize = 0x40000; if (eSize == 0x40000)
eSize = 0x20000;
else if (eSize == 0x20000)
eSize = 0x40000;
} }
CMkfsJFFS2 mkfs; CMkfsJFFS2 mkfs;
if (makeDevTable) { if (makeDevTable)
{
CMkfsJFFS2::v_devtable_t v_devtable; CMkfsJFFS2::v_devtable_t v_devtable;
bool devtableFileIO = false; bool devtableFileIO = false;
std::string devtableFile = (std::string)CONFIGDIR + "/devtable.txt"; std::string devtableFile = (std::string)CONFIGDIR + "/devtable.txt";
if (file_exists(devtableFile.c_str())) { if (file_exists(devtableFile.c_str()))
{
if (readDevtableFile(devtableFile, v_devtable)) if (readDevtableFile(devtableFile, v_devtable))
devtableFileIO = true; devtableFileIO = true;
} }
if (!devtableFileIO || v_devtable.empty()) { if (!devtableFileIO || v_devtable.empty())
{
v_devtable.push_back("/dev/console c 0600 0 0 5 1 0 0 0"); v_devtable.push_back("/dev/console c 0600 0 0 5 1 0 0 0");
v_devtable.push_back("/dev/null c 0666 0 0 1 3 0 0 0"); v_devtable.push_back("/dev/null c 0666 0 0 1 3 0 0 0");
} }
@@ -945,14 +984,21 @@ void CFlashExpert::readmtd(int preadmtd)
#if ENABLE_EXTUPDATE #if ENABLE_EXTUPDATE
#ifdef BOXMODEL_CST_HD2 #ifdef BOXMODEL_CST_HD2
int eSize = CMTDInfo::getInstance()->getMTDEraseSize(CMTDInfo::getInstance()->findMTDsystem()); int eSize = CMTDInfo::getInstance()->getMTDEraseSize(CMTDInfo::getInstance()->findMTDsystem());
if (preadmtd == 0) { if (preadmtd == 0)
if (createimage_other == 0) { {
if (eSize == 0x40000) tankStr = ".256k"; if (createimage_other == 0)
if (eSize == 0x20000) tankStr = ""; {
if (eSize == 0x40000)
tankStr = ".256k";
if (eSize == 0x20000)
tankStr = "";
} }
else if (createimage_other == 1) { else if (createimage_other == 1)
if (eSize == 0x40000) tankStr = ""; {
if (eSize == 0x20000) tankStr = ".256k"; if (eSize == 0x40000)
tankStr = "";
if (eSize == 0x20000)
tankStr = ".256k";
} }
} }
#endif #endif
@@ -965,22 +1011,26 @@ void CFlashExpert::readmtd(int preadmtd)
#ifdef BOXMODEL_CST_HD2 #ifdef BOXMODEL_CST_HD2
std::string title = " (" + CMTDInfo::getInstance()->getMTDName(preadmtd) + ")"; std::string title = " (" + CMTDInfo::getInstance()->getMTDName(preadmtd) + ")";
std::string mountp = getJFFS2MountPoint(preadmtd); std::string mountp = getJFFS2MountPoint(preadmtd);
if (preadmtd == 0) { if (preadmtd == 0)
{
readmtdJFFS2(filename, title); readmtdJFFS2(filename, title);
return; return;
} }
if (preadmtd == 1) { if (preadmtd == 1)
{
if (mountp != "") if (mountp != "")
readmtdJFFS2(filename, title, mountp.c_str(), false); readmtdJFFS2(filename, title, mountp.c_str(), false);
return; return;
} }
if (preadmtd == 2) { if (preadmtd == 2)
{
if (mountp != "") if (mountp != "")
readmtdJFFS2(filename, title, mountp.c_str(), false); readmtdJFFS2(filename, title, mountp.c_str(), false);
return; return;
} }
#endif #endif
if (preadmtd == -1) { if (preadmtd == -1)
{
filename = (std::string)g_settings.update_dir + "/flashimage.img"; // US-ASCII (subset of UTF-8 and ISO8859-1) filename = (std::string)g_settings.update_dir + "/flashimage.img"; // US-ASCII (subset of UTF-8 and ISO8859-1)
preadmtd = MTD_OF_WHOLE_IMAGE; preadmtd = MTD_OF_WHOLE_IMAGE;
} }
@@ -1004,10 +1054,13 @@ void CFlashExpert::readmtd(int preadmtd)
ft.setStatusViewer(this); ft.setStatusViewer(this);
ft.setMTDDevice(mtdInfo->getMTDFileName(preadmtd)); ft.setMTDDevice(mtdInfo->getMTDFileName(preadmtd));
if(!ft.readFromMTD(filename, 100)) { if (!ft.readFromMTD(filename, 100))
{
showStatusMessageUTF(ft.getErrorMessage()); showStatusMessageUTF(ft.getErrorMessage());
sleep(10); sleep(10);
} else { }
else
{
showGlobalStatus(100); showGlobalStatus(100);
showStatusMessageUTF(g_Locale->getText(LOCALE_FLASHUPDATE_READY)); showStatusMessageUTF(g_Locale->getText(LOCALE_FLASHUPDATE_READY));
char message[500]; char message[500];
@@ -1045,10 +1098,13 @@ void CFlashExpert::writemtd(const std::string & filename, int mtdNumber)
CFlashTool ft; CFlashTool ft;
ft.setStatusViewer(this); ft.setStatusViewer(this);
ft.setMTDDevice(CMTDInfo::getInstance()->getMTDFileName(mtdNumber)); ft.setMTDDevice(CMTDInfo::getInstance()->getMTDFileName(mtdNumber));
if(!ft.program( (std::string)g_settings.update_dir + "/" + filename, 50, 100)) { if (!ft.program((std::string)g_settings.update_dir + "/" + filename, 50, 100))
{
showStatusMessageUTF(ft.getErrorMessage()); showStatusMessageUTF(ft.getErrorMessage());
sleep(10); sleep(10);
} else { }
else
{
showGlobalStatus(100); showGlobalStatus(100);
showStatusMessageUTF(g_Locale->getText(LOCALE_FLASHUPDATE_READY)); showStatusMessageUTF(g_Locale->getText(LOCALE_FLASHUPDATE_READY));
sleep(2); sleep(2);
@@ -1073,7 +1129,8 @@ int CFlashExpert::showMTDSelector(const std::string & actionkey)
mtdselector->addIntroItems(LOCALE_FLASHUPDATE_MTDSELECTOR, NONEXISTANT_LOCALE, CMenuWidget::BTN_TYPE_CANCEL); mtdselector->addIntroItems(LOCALE_FLASHUPDATE_MTDSELECTOR, NONEXISTANT_LOCALE, CMenuWidget::BTN_TYPE_CANCEL);
CMTDInfo *mtdInfo = CMTDInfo::getInstance(); CMTDInfo *mtdInfo = CMTDInfo::getInstance();
for(int lx=0;lx<mtdInfo->getMTDCount();lx++) { for (int lx = 0; lx < mtdInfo->getMTDCount(); lx++)
{
char sActionKey[20]; char sActionKey[20];
bool enabled = true; bool enabled = true;
#ifdef BOXMODEL_CST_HD2 #ifdef BOXMODEL_CST_HD2
@@ -1082,7 +1139,8 @@ int CFlashExpert::showMTDSelector(const std::string & actionkey)
lx == mtdInfo->findMTDNumberFromName("uldr") || lx == mtdInfo->findMTDNumberFromName("uldr") ||
lx == mtdInfo->findMTDNumberFromName("env"))) lx == mtdInfo->findMTDNumberFromName("env")))
enabled = false; enabled = false;
if (actionkey == "readmtd") { if (actionkey == "readmtd")
{
// Enabled when file system is mounted // Enabled when file system is mounted
if (lx == mtdInfo->findMTDNumberFromName("var")) if (lx == mtdInfo->findMTDNumberFromName("var"))
enabled = (getJFFS2MountPoint(lx) == "") ? false : true; enabled = (getJFFS2MountPoint(lx) == "") ? false : true;
@@ -1131,7 +1189,7 @@ int CFlashExpert::showFileSelector(const std::string & actionkey)
if (pos != -1) if (pos != -1)
{ {
fileselector->addItem(new CMenuForwarder(filen.c_str(), true, NULL, this, (actionkey + filen).c_str())); fileselector->addItem(new CMenuForwarder(filen.c_str(), true, NULL, this, (actionkey + filen).c_str()));
//TODO make sure filen is UTF-8 encoded // TODO: make sure filen is UTF-8 encoded
} }
free(namelist[count]); free(namelist[count]);
} }
@@ -1148,41 +1206,54 @@ int CFlashExpert::exec(CMenuTarget* parent, const std::string & actionKey)
if (parent) if (parent)
parent->hide(); parent->hide();
if(actionKey=="readflash") { if (actionKey == "readflash")
{
readmtd(-1); readmtd(-1);
} }
else if(actionKey=="writeflash") { else if (actionKey == "writeflash")
{
res = showFileSelector(""); res = showFileSelector("");
} }
else if(actionKey=="readflashmtd") { else if (actionKey == "readflashmtd")
{
res = showMTDSelector("readmtd"); res = showMTDSelector("readmtd");
} }
else if(actionKey=="writeflashmtd") { else if (actionKey == "writeflashmtd")
{
res = showMTDSelector("writemtd"); res = showMTDSelector("writemtd");
} }
else { else
{
int iReadmtd = -1; int iReadmtd = -1;
int iWritemtd = -1; int iWritemtd = -1;
sscanf(actionKey.c_str(), "readmtd%d", &iReadmtd); sscanf(actionKey.c_str(), "readmtd%d", &iReadmtd);
sscanf(actionKey.c_str(), "writemtd%d", &iWritemtd); sscanf(actionKey.c_str(), "writemtd%d", &iWritemtd);
if(iReadmtd!=-1) { if (iReadmtd != -1)
{
readmtd(iReadmtd); readmtd(iReadmtd);
} }
else if(iWritemtd!=-1) { else if (iWritemtd != -1)
{
dprintf(DEBUG_NORMAL, "[update] mtd-write\n\n"); dprintf(DEBUG_NORMAL, "[update] mtd-write\n\n");
selectedMTD = iWritemtd; selectedMTD = iWritemtd;
showFileSelector(""); showFileSelector("");
} else { }
else
{
#if ENABLE_EXTUPDATE #if ENABLE_EXTUPDATE
if(selectedMTD == 10) { if (selectedMTD == 10)
{
std::string aK = actionKey; std::string aK = actionKey;
CExtUpdate::getInstance()->applySettings(aK, CExtUpdate::MODE_EXPERT); CExtUpdate::getInstance()->applySettings(aK, CExtUpdate::MODE_EXPERT);
} }
else else
#endif #endif
if (selectedMTD == -1) { if (selectedMTD == -1)
{
writemtd(actionKey, MTD_OF_WHOLE_IMAGE); writemtd(actionKey, MTD_OF_WHOLE_IMAGE);
} else { }
else
{
writemtd(actionKey, selectedMTD); writemtd(actionKey, selectedMTD);
selectedMTD = -1; selectedMTD = -1;
} }
@@ -1218,11 +1289,13 @@ int CFlashExpertSetup::exec(CMenuTarget* parent, const std::string &actionKey)
if (parent) if (parent)
parent->hide(); parent->hide();
if (actionKey == "readmtd0") { if (actionKey == "readmtd0")
{
CFlashExpert *cfe = CFlashExpert::getInstance(); CFlashExpert *cfe = CFlashExpert::getInstance();
CMTDInfo *mtdInfo = CMTDInfo::getInstance(); CMTDInfo *mtdInfo = CMTDInfo::getInstance();
bool skipImage = false; bool skipImage = false;
if (cfe->createimage_other == 1) { if (cfe->createimage_other == 1)
{
char message[512] = {0}; char message[512] = {0};
// create image warning // create image warning
const char *box = (mtdInfo->getMTDEraseSize(mtdInfo->findMTDsystem()) == 0x40000) ? "Trinity" : "Tank"; const char *box = (mtdInfo->getMTDEraseSize(mtdInfo->findMTDsystem()) == 0x40000) ? "Trinity" : "Tank";
@@ -1230,7 +1303,8 @@ int CFlashExpertSetup::exec(CMenuTarget* parent, const std::string &actionKey)
if (ShowMsg(LOCALE_MESSAGEBOX_INFO, message, CMsgBox::mbrNo, CMsgBox::mbYes | CMsgBox::mbNo, NEUTRINO_ICON_UPDATE, 600) != CMsgBox::mbrYes) if (ShowMsg(LOCALE_MESSAGEBOX_INFO, message, CMsgBox::mbrNo, CMsgBox::mbYes | CMsgBox::mbNo, NEUTRINO_ICON_UPDATE, 600) != CMsgBox::mbrYes)
skipImage = true; skipImage = true;
} }
if (!skipImage) { if (!skipImage)
{
std::string uldrName = (std::string)UPDATEDIR + "/uldr.bin"; std::string uldrName = (std::string)UPDATEDIR + "/uldr.bin";
cfe->forceOtherFilename = true; cfe->forceOtherFilename = true;
if (g_settings.flashupdate_createimage_add_uldr == 1) if (g_settings.flashupdate_createimage_add_uldr == 1)
@@ -1341,7 +1415,8 @@ int CFlashExpertSetup::showMenu()
#endif #endif
rootfsSetup->addItem(m6); // include kernel rootfsSetup->addItem(m6); // include kernel
if (cs_get_revision() != 12) { // not kronos if (cs_get_revision() != 12) // not kronos
{
CMTDInfo *mtdInfo = CMTDInfo::getInstance(); CMTDInfo *mtdInfo = CMTDInfo::getInstance();
const char *box = (mtdInfo->getMTDEraseSize(mtdInfo->findMTDsystem()) == 0x40000) ? "Trinity" : "Tank"; const char *box = (mtdInfo->getMTDEraseSize(mtdInfo->findMTDsystem()) == 0x40000) ? "Trinity" : "Tank";
char mText[512] = {0}; char mText[512] = {0};
@@ -1350,7 +1425,8 @@ int CFlashExpertSetup::showMenu()
rootfsSetup->addItem(GenericMenuSeparatorLine); rootfsSetup->addItem(GenericMenuSeparatorLine);
rootfsSetup->addItem(m7); // create image for other STB rootfsSetup->addItem(m7); // create image for other STB
} else }
else
cfe->createimage_other = 0; cfe->createimage_other = 0;
int res = rootfsSetup->exec(NULL, ""); int res = rootfsSetup->exec(NULL, "");

View File

@@ -30,7 +30,6 @@
Boston, MA 02110-1301, USA. Boston, MA 02110-1301, USA.
*/ */
#ifndef __update__ #ifndef __update__
#define __update__ #define __update__
@@ -60,7 +59,7 @@ class CFlashUpdate : public CProgressWindow
int menu_ret; int menu_ret;
int softupdate_mode; int softupdate_mode;
// void update_php(std::string &url, const char* type); void update_php(std::string &url, const char *type);
bool selectHttpImage(void); bool selectHttpImage(void);
bool getUpdateImage(const std::string &version); bool getUpdateImage(const std::string &version);
bool checkVersion4Update(); bool checkVersion4Update();
@@ -70,7 +69,6 @@ class CFlashUpdate : public CProgressWindow
int exec(CMenuTarget *parent, const std::string &actionKey); int exec(CMenuTarget *parent, const std::string &actionKey);
bool checkOnlineVersion(); bool checkOnlineVersion();
void enableNotify(bool enable) { notify = enable; } void enableNotify(bool enable) { notify = enable; }
}; };
class CFlashExpert : public CProgressWindow class CFlashExpert : public CProgressWindow
@@ -99,7 +97,6 @@ class CFlashExpert : public CProgressWindow
int exec(CMenuTarget *parent, const std::string &actionKey); int exec(CMenuTarget *parent, const std::string &actionKey);
void writemtd(const std::string &filename, int mtdNumber); void writemtd(const std::string &filename, int mtdNumber);
void readmtd(int readmtd); void readmtd(int readmtd);
}; };
#ifdef BOXMODEL_CST_HD2 #ifdef BOXMODEL_CST_HD2