settings_manager: remember last used directory

Origin commit data
------------------
Commit: 864907a95f
Author: vanhofen <vanhofen@gmx.de>
Date: 2017-12-15 (Fri, 15 Dec 2017)

Origin message was:
------------------
- settings_manager: remember last used directory
This commit is contained in:
vanhofen
2017-12-15 23:20:55 +01:00
parent ed99ad9639
commit fc0c1ac32d
7 changed files with 61 additions and 28 deletions

View File

@@ -2523,6 +2523,7 @@ servicemenu.restarting_tuner Tuner wird neu gestartet
servicemenu.scants Kanalsuche
servicemenu.update Software-Aktualisierung
settings.backup NI-Backup sichern
settings.backup_dir Nach %s sichern?\n"Nein" wählt ein anderes Verzeichnis
settings.backup_failed Sicherung fehlgeschlagen!
settings.help Hilfe
settings.menu_hints Hinweise anzeigen

View File

@@ -2522,6 +2522,7 @@ servicemenu.restarting_tuner Restarting tuner
servicemenu.scants Servicescan
servicemenu.update Software Update
settings.backup Save NI-Backup
settings.backup_dir Save to %s?\n"No" chooses another directory.
settings.backup_failed Backup failed!
settings.help Help
settings.menu_hints Show menu hints

View File

@@ -77,8 +77,9 @@ int CSettingsManager::exec(CMenuTarget* parent, const std::string &actionKey)
{
fileFilter.addFilter("conf");
fileBrowser.Filter = &fileFilter;
if (fileBrowser.exec(CONFIGDIR) == true)
if (fileBrowser.exec(g_settings.backup_dir.c_str()) == true)
{
g_settings.backup_dir = fileBrowser.getCurrentDir();
CNeutrinoApp::getInstance()->loadSetup(fileBrowser.getSelectedFile()->Name.c_str());
CColorSetupNotifier *colorSetupNotifier = new CColorSetupNotifier;
colorSetupNotifier->changeNotify(NONEXISTANT_LOCALE, NULL);
@@ -91,41 +92,62 @@ int CSettingsManager::exec(CMenuTarget* parent, const std::string &actionKey)
}
else if(actionKey == "saveconfig")
{
fileBrowser.Dir_Mode = true;
if (fileBrowser.exec("/media") == true)
{
std::string fname = "neutrino.conf";
CKeyboardInput * sms = new CKeyboardInput(LOCALE_EXTRA_SAVECONFIG, &fname);
sms->exec(NULL, "");
char msgtxt[1024];
snprintf(msgtxt, sizeof(msgtxt), g_Locale->getText(LOCALE_SETTINGS_BACKUP_DIR), g_settings.backup_dir.c_str());
std::string sname = fileBrowser.getSelectedFile()->Name + "/" + fname;
printf("[neutrino] save settings: %s\n", sname.c_str());
CNeutrinoApp::getInstance()->saveSetup(sname.c_str());
delete sms;
int result = ShowMsg(LOCALE_EXTRA_SAVECONFIG, msgtxt, CMsgBox::mbrYes, CMsgBox::mbYes | CMsgBox::mbNo);
if (result == CMsgBox::mbrNo)
{
fileBrowser.Dir_Mode = true;
if (fileBrowser.exec(g_settings.backup_dir.c_str()) == true)
g_settings.backup_dir = fileBrowser.getSelectedFile()->Name;
else
return res;
}
std::string fname = "neutrino.conf";
CKeyboardInput * sms = new CKeyboardInput(LOCALE_EXTRA_SAVECONFIG, &fname);
sms->exec(NULL, "");
delete sms;
std::string sname = g_settings.backup_dir + "/" + fname;
printf("[neutrino] save settings: %s\n", sname.c_str());
CNeutrinoApp::getInstance()->saveSetup(sname.c_str());
return res;
}
else if(actionKey == "backup")
{
fileBrowser.Dir_Mode = true;
if (fileBrowser.exec("/media") == true)
char msgtxt[1024];
snprintf(msgtxt, sizeof(msgtxt), g_Locale->getText(LOCALE_SETTINGS_BACKUP_DIR), g_settings.backup_dir.c_str());
int result = ShowMsg(LOCALE_SETTINGS_BACKUP, msgtxt, CMsgBox::mbrYes, CMsgBox::mbYes | CMsgBox::mbNo);
if (result == CMsgBox::mbrNo)
{
struct statfs s;
int ret = ::statfs(fileBrowser.getSelectedFile()->Name.c_str(), &s);
if(ret == 0 && s.f_type != 0x72b6L) /*jffs2*/
{
//NI
CHintBox * hintBox = new CHintBox(LOCALE_MESSAGEBOX_INFO, g_Locale->getText(LOCALE_SETTINGS_BACKUP));
hintBox->paint();
const char backup_sh[] = TARGET_PREFIX "/bin/backup.sh";
printf("backup: executing [%s %s]\n", backup_sh, fileBrowser.getSelectedFile()->Name.c_str());
my_system(2, backup_sh, fileBrowser.getSelectedFile()->Name.c_str());
hintBox->hide();
delete hintBox;
}
fileBrowser.Dir_Mode = true;
if (fileBrowser.exec(g_settings.backup_dir.c_str()) == true)
g_settings.backup_dir = fileBrowser.getSelectedFile()->Name;
else
ShowMsg(LOCALE_MESSAGEBOX_ERROR, g_Locale->getText(LOCALE_SETTINGS_BACKUP_FAILED),CMsgBox::mbrBack, CMsgBox::mbBack, NEUTRINO_ICON_ERROR);
return res;
}
struct statfs s;
int ret = ::statfs(g_settings.backup_dir.c_str(), &s);
if (ret == 0 && s.f_type != 0x72b6L) /*jffs2*/
{
CHintBox * hintBox = new CHintBox(LOCALE_MESSAGEBOX_INFO, g_Locale->getText(LOCALE_SETTINGS_BACKUP));
hintBox->paint();
const char backup_sh[] = TARGET_PREFIX "/bin/backup.sh";
printf("backup: executing [%s %s]\n", backup_sh, g_settings.backup_dir.c_str());
my_system(2, backup_sh, g_settings.backup_dir.c_str());
hintBox->hide();
delete hintBox;
}
else
ShowMsg(LOCALE_MESSAGEBOX_ERROR, g_Locale->getText(LOCALE_SETTINGS_BACKUP_FAILED),CMsgBox::mbrBack, CMsgBox::mbBack, NEUTRINO_ICON_ERROR);
return res;
}
else if(actionKey == "restore")
@@ -133,8 +155,9 @@ int CSettingsManager::exec(CMenuTarget* parent, const std::string &actionKey)
fileFilter.addFilter("tar");
fileFilter.addFilter("gz"); //NI
fileBrowser.Filter = &fileFilter;
if (fileBrowser.exec("/media") == true)
if (fileBrowser.exec(g_settings.backup_dir.c_str()) == true)
{
g_settings.backup_dir = fileBrowser.getCurrentDir();
int result = ShowMsg(LOCALE_SETTINGS_RESTORE, g_Locale->getText(LOCALE_SETTINGS_RESTORE_WARN), CMsgBox::mbrNo, CMsgBox::mbYes | CMsgBox::mbNo);
if(result == CMsgBox::mbrYes)
{

View File

@@ -891,6 +891,8 @@ int CNeutrinoApp::loadSetup(const char * fname)
g_settings.font_scaling_x = configfile.getInt32("font_scaling_x", 105); //NI
g_settings.font_scaling_y = configfile.getInt32("font_scaling_y", 105); //NI
g_settings.backup_dir = configfile.getString("backup_dir", "/media");
g_settings.update_dir = configfile.getString("update_dir", "/tmp");
g_settings.update_dir_opkg = configfile.getString("update_dir_opkg", g_settings.update_dir);
@@ -1587,6 +1589,8 @@ void CNeutrinoApp::saveSetup(const char * fname)
configfile.setString("softupdate_proxyusername" , g_settings.softupdate_proxyusername );
configfile.setString("softupdate_proxypassword" , g_settings.softupdate_proxypassword );
configfile.setString("backup_dir", g_settings.backup_dir);
configfile.setString("update_dir", g_settings.update_dir);
configfile.setString("update_dir_opkg", g_settings.update_dir_opkg);

View File

@@ -2549,6 +2549,7 @@ typedef enum
LOCALE_SERVICEMENU_SCANTS,
LOCALE_SERVICEMENU_UPDATE,
LOCALE_SETTINGS_BACKUP,
LOCALE_SETTINGS_BACKUP_DIR,
LOCALE_SETTINGS_BACKUP_FAILED,
LOCALE_SETTINGS_HELP,
LOCALE_SETTINGS_MENU_HINTS,

View File

@@ -2549,6 +2549,7 @@ const char * locale_real_names[] =
"servicemenu.scants",
"servicemenu.update",
"settings.backup",
"settings.backup_dir",
"settings.backup_failed",
"settings.help",
"settings.menu_hints",

View File

@@ -689,6 +689,8 @@ struct SNeutrinoSettings
int flashupdate_createimage_add_spare;
int flashupdate_createimage_add_kernel;
std::string backup_dir;
std::string update_dir;
std::string update_dir_opkg;