From a3762416af63bb3a7934c7c6e67d2d5fb87629e2 Mon Sep 17 00:00:00 2001 From: Michael Liebmann Date: Tue, 20 Aug 2013 02:23:10 +0200 Subject: [PATCH] Softupdate: Check the available disk space when reading the flash --- data/locale/deutsch.locale | 3 +++ data/locale/english.locale | 3 +++ src/gui/update.cpp | 34 ++++++++++++++++++++++++++++++++++ src/gui/update.h | 1 + src/system/locals.h | 3 +++ src/system/locals_intern.h | 3 +++ 6 files changed, 47 insertions(+) diff --git a/data/locale/deutsch.locale b/data/locale/deutsch.locale index 7715bcfc5..725e58fbb 100644 --- a/data/locale/deutsch.locale +++ b/data/locale/deutsch.locale @@ -509,6 +509,9 @@ flashupdate.proxyserver_sep Proxyserver flashupdate.proxyusername Benutzername flashupdate.proxyusername_hint1 Geben Sie den Proxy-Benutzernamen ein flashupdate.proxyusername_hint2 Ein leerer Eintrag bedeutet keine Authentifizierung +flashupdate.read_directory_not_exist Das Backupverzeichnis %s \nexistiert nicht! +flashupdate.read_no_available_space Der maximal verfügbare Platz in %s \nbeträgt %d KB, es werden aber %d KB benötigt.\n \nDer Vorgang wird abgebrochen, wählen sie bitte einen anderen Datenträger! +flashupdate.read_volume_error Die Größe des Datenträgers %s \nkann nicht ermittelt werden! flashupdate.readflash ganzes Flashimage auslesen flashupdate.readflashmtd einzelne Partition auslesen flashupdate.ready fertig diff --git a/data/locale/english.locale b/data/locale/english.locale index d96bf036b..45f1a519d 100644 --- a/data/locale/english.locale +++ b/data/locale/english.locale @@ -509,6 +509,9 @@ flashupdate.proxyserver_sep Proxyserver flashupdate.proxyusername Username flashupdate.proxyusername_hint1 enter the proxyserver username flashupdate.proxyusername_hint2 a empty entry means no proxy-auth +flashupdate.read_directory_not_exist The backup directory %s \ndoes not exist! +flashupdate.read_no_available_space The maximum available space in %s \nis %d KB, but there are %d KB required.\n \nThe operation is canceled, please choose another medium! +flashupdate.read_volume_error The size of the volume %s \ncan not be determined! flashupdate.readflash Read whole image flashupdate.readflashmtd Read one partition flashupdate.ready ready diff --git a/src/gui/update.cpp b/src/gui/update.cpp index e85a9efb7..b48f13325 100644 --- a/src/gui/update.cpp +++ b/src/gui/update.cpp @@ -550,6 +550,36 @@ CFlashExpert* CFlashExpert::getInstance() return FlashExpert; } +bool CFlashExpert::checkSize(int mtd, std::string &backupFile) +{ + char errMsg[1024] = {0}; + std::string path = getPathName(backupFile); + if (!file_exists(path.c_str())) { + snprintf(errMsg, sizeof(errMsg)-1, g_Locale->getText(LOCALE_FLASHUPDATE_READ_DIRECTORY_NOT_EXIST), path.c_str()); + ShowHintUTF(LOCALE_MESSAGEBOX_ERROR, errMsg); + return false; + } + + int mtdSize = CMTDInfo::getInstance()->getMTDSize(mtd) / 1024; + + long btotal = 0, bused = 0, bsize = 0; + 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()); + ShowHintUTF(LOCALE_MESSAGEBOX_ERROR, errMsg); + return false; + } + int backupMaxSize = (int)((btotal - bused) * bsize); + int res = 10; // Reserved 10% of available space + backupMaxSize = (backupMaxSize - ((backupMaxSize * res) / 100)) / 1024; + if (backupMaxSize < mtdSize) { + snprintf(errMsg, sizeof(errMsg)-1, g_Locale->getText(LOCALE_FLASHUPDATE_READ_NO_AVAILABLE_SPACE), path.c_str(), backupMaxSize, mtdSize); + ShowHintUTF(LOCALE_MESSAGEBOX_ERROR, errMsg); + return false; + } + + return true; +} + void CFlashExpert::readmtd(int preadmtd) { std::string filename; @@ -566,6 +596,10 @@ void CFlashExpert::readmtd(int preadmtd) filename = (std::string)g_settings.update_dir + "/flashimage.img"; // US-ASCII (subset of UTF-8 and ISO8859-1) preadmtd = MTD_OF_WHOLE_IMAGE; } + + if (!checkSize(preadmtd, filename)) + return; + setTitle(LOCALE_FLASHUPDATE_TITLEREADFLASH); paint(); showGlobalStatus(0); diff --git a/src/gui/update.h b/src/gui/update.h index 8d9a30266..ae9e436d5 100644 --- a/src/gui/update.h +++ b/src/gui/update.h @@ -75,6 +75,7 @@ class CFlashExpert : public CProgressWindow void showMTDSelector(const std::string & actionkey); void showFileSelector(const std::string & actionkey); + bool checkSize(int mtd, std::string &backupFile); void readmtd(int readmtd); public: diff --git a/src/system/locals.h b/src/system/locals.h index d4550706c..743fadee5 100644 --- a/src/system/locals.h +++ b/src/system/locals.h @@ -536,6 +536,9 @@ typedef enum LOCALE_FLASHUPDATE_PROXYUSERNAME, LOCALE_FLASHUPDATE_PROXYUSERNAME_HINT1, LOCALE_FLASHUPDATE_PROXYUSERNAME_HINT2, + LOCALE_FLASHUPDATE_READ_DIRECTORY_NOT_EXIST, + LOCALE_FLASHUPDATE_READ_NO_AVAILABLE_SPACE, + LOCALE_FLASHUPDATE_READ_VOLUME_ERROR, LOCALE_FLASHUPDATE_READFLASH, LOCALE_FLASHUPDATE_READFLASHMTD, LOCALE_FLASHUPDATE_READY, diff --git a/src/system/locals_intern.h b/src/system/locals_intern.h index 6782964b0..305b8ed6b 100644 --- a/src/system/locals_intern.h +++ b/src/system/locals_intern.h @@ -536,6 +536,9 @@ const char * locale_real_names[] = "flashupdate.proxyusername", "flashupdate.proxyusername_hint1", "flashupdate.proxyusername_hint2", + "flashupdate.read_directory_not_exist", + "flashupdate.read_no_available_space", + "flashupdate.read_volume_error", "flashupdate.readflash", "flashupdate.readflashmtd", "flashupdate.ready",