From a897844ea1cfa6303112fd3f0d472d3e135bdc6d Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Mon, 15 Aug 2011 14:07:53 +0200 Subject: More preparation for automatic updating of config files --- src/FbTk/LResource.cc | 34 ++++---- src/FbTk/LResource.hh | 8 +- src/FbTk/Resource.hh | 41 ++++++---- src/Slit.cc | 2 +- src/Slit.hh | 14 +++- util/fluxbox-update_configs.cc | 182 +++++++++++++++++++++++++++-------------- 6 files changed, 182 insertions(+), 99 deletions(-) diff --git a/src/FbTk/LResource.cc b/src/FbTk/LResource.cc index 18209cb..589e52f 100644 --- a/src/FbTk/LResource.cc +++ b/src/FbTk/LResource.cc @@ -89,21 +89,6 @@ namespace { } // anonymous namespace -void LResourceManager::convert(ResourceManager &old, const std::string &new_file) { - Lua l; - - LResourceManager new_rm(old.root(), l); - for(ResourceList::const_iterator i = old.begin(); i != old.end(); ++i) { - // adding the resource to new_rm will set it to default value - // we save the value to a temp variable so we can restore it later - const std::string &t = (*i)->getString(); - new_rm.addResource(**i); - (*i)->setFromString(t.c_str()); - } - - new_rm.save(new_file.c_str(), NULL); -} - LResourceManager::LResourceManager(const std::string &root, Lua &l, unsigned int autosave) : ResourceManager_base(root), m_l(&l) { @@ -116,6 +101,25 @@ LResourceManager::LResourceManager(const std::string &root, Lua &l, unsigned int setLua(l); } +LResourceManager::LResourceManager(ResourceManager &old, Lua &l) + : ResourceManager_base(old.root()), m_l(&l) { + + // We create a copy of the list so we can safely traverse it while the resources disassociate + // themselves from the old resource manager + ResourceList list; + for(ResourceList::const_iterator i = old.begin(); i != old.end(); ++i) { + list.push_back(*i); + } + + for(ResourceList::const_iterator i = list.begin(); i != list.end(); ++i) { + // adding the resource to this resource manager will set it to default value + // we save the value to a temp variable so we can restore it later + const std::string &t = (*i)->getString(); + (*i)->setResourceManager(*this); + (*i)->setFromString(t.c_str()); + } +} + void LResourceManager::doLoad(const std::string &filename) { m_l->checkstack(1); lua::stack_sentry s(*m_l); diff --git a/src/FbTk/LResource.hh b/src/FbTk/LResource.hh index a198197..022e6f5 100644 --- a/src/FbTk/LResource.hh +++ b/src/FbTk/LResource.hh @@ -36,7 +36,6 @@ class Lua; class LResourceManager: public ResourceManager_base { public: - static void convert(ResourceManager &old, const std::string &new_file); /** * @param root the name of the table where settings will reside @@ -45,16 +44,21 @@ public: * starts a timer. If another resource is modified, the timer is restarted. 0 = disabled */ LResourceManager(const std::string &root, Lua &l, unsigned int autosave = 0); + /** + * Take over resources from the old resource manager. Used in fluxbox-update_configs. + * Resource managers created via this constructor don't support automatic saving. + */ + explicit LResourceManager(ResourceManager &old, Lua &l); virtual bool save(const char *filename, const char *); virtual void addResource(Resource_base &r); virtual void removeResource(Resource_base &r); virtual void resourceChanged(Resource_base &r); + virtual void doLoad(const std::string &filename); void setLua(Lua &l); private: void doAddResource(Resource_base &r); void doRemoveResource(Resource_base &r); - virtual void doLoad(const std::string &filename); Lua *m_l; Timer m_savetimer; diff --git a/src/FbTk/Resource.hh b/src/FbTk/Resource.hh index 700fe70..b729ad4 100644 --- a/src/FbTk/Resource.hh +++ b/src/FbTk/Resource.hh @@ -47,12 +47,19 @@ private: std::string m_str; }; +// forward declarations +template +class Resource; +class ResourceManager_base; + /// Base class for resources, this is only used in ResourceManager class Resource_base:private FbTk::NotCopyable { public: virtual ~Resource_base() { }; + virtual void setResourceManager(ResourceManager_base &rm) = 0; + /// set from string value virtual void setFromString(char const *strval) = 0; /// set default value @@ -80,9 +87,6 @@ private: std::string m_altname; ///< alternative name }; -template -class Resource; - class ResourceManager_base { public: @@ -134,10 +138,10 @@ public: ResourceList::const_iterator begin() { return m_resourcelist.begin(); } ResourceList::const_iterator end() { return m_resourcelist.end(); } -protected: /// does the actual loading virtual void doLoad(const std::string &filename) = 0; +protected: ResourceList m_resourcelist; const std::string m_root; std::string m_filename; @@ -177,9 +181,10 @@ public: std::cerr<<(*it)->name()<addResource(*this); // add this to resource handler } // LResourceManager does not use altname, so we provide a constructor which initializes // altname to name Resource(ResourceManager_base &rm, T val, const std::string &name, const Traits &traits = Traits() ): - Resource_base(name, name), Traits(traits), m_value(val), m_defaultval(val), m_rm(rm) { - m_rm.addResource(*this); // add this to resource handler + Resource_base(name, name), Traits(traits), m_value(val), m_defaultval(val), m_rm(&rm) { + m_rm->addResource(*this); // add this to resource handler } virtual ~Resource() { - m_rm.removeResource(*this); // remove this from resource handler + m_rm->removeResource(*this); // remove this from resource handler + } + + virtual void setResourceManager(ResourceManager_base &rm) { + m_rm->removeResource(*this); + m_rm = &rm; + m_rm->addResource(*this); } void setDefaultValue() { m_value = m_defaultval; - m_rm.resourceChanged(*this); + m_rm->resourceChanged(*this); m_modified_sig.emit(m_value); } /// sets resource from string, specialized, must be implemented void setFromString(const char *strval) { try { m_value = Traits::fromString(strval); - m_rm.resourceChanged(*this); + m_rm->resourceChanged(*this); m_modified_sig.emit(m_value); } catch(ConversionError &e) { @@ -236,7 +247,7 @@ public: } Accessor &operator =(const T& newvalue) { m_value = newvalue; - m_rm.resourceChanged(*this); + m_rm->resourceChanged(*this); m_modified_sig.emit(m_value); return *this; } @@ -247,7 +258,7 @@ public: virtual void setFromLua(lua::state &l) { try { m_value = Traits::fromLua(l); - m_rm.resourceChanged(*this); + m_rm->resourceChanged(*this); m_modified_sig.emit(m_value); } catch(ConversionError &e) { @@ -268,7 +279,7 @@ public: private: T m_value, m_defaultval; - ResourceManager_base &m_rm; + ResourceManager_base *m_rm; Signal m_modified_sig; }; diff --git a/src/Slit.cc b/src/Slit.cc index 4d9a0df..3937653 100644 --- a/src/Slit.cc +++ b/src/Slit.cc @@ -211,7 +211,7 @@ void Slit::SlitClientsRes::setFromLua(lua::state &l) { l.pop(); - m_rm.resourceChanged(*this); + m_rm->resourceChanged(*this); } void Slit::SlitClientsRes::pushToLua(lua::state &l) const { diff --git a/src/Slit.hh b/src/Slit.hh index 77ce6f5..d6ba08f 100644 --- a/src/Slit.hh +++ b/src/Slit.hh @@ -180,12 +180,18 @@ private: class SlitClientsRes: public FbTk::Resource_base, public SlitClients { public: SlitClientsRes(FbTk::ResourceManager_base &rm, const std::string &name) - : FbTk::Resource_base(name, name), m_rm(rm) { - m_rm.addResource(*this); + : FbTk::Resource_base(name, name), m_rm(&rm) { + m_rm->addResource(*this); } ~SlitClientsRes() { - m_rm.removeResource(*this); + m_rm->removeResource(*this); + } + + virtual void setResourceManager(FbTk::ResourceManager_base &rm) { + m_rm->removeResource(*this); + m_rm = &rm; + m_rm->addResource(*this); } virtual void setDefaultValue() {} @@ -195,7 +201,7 @@ private: virtual void pushToLua(lua::state &l) const; private: - FbTk::ResourceManager_base &m_rm; + FbTk::ResourceManager_base *m_rm; }; SlitClientsRes m_client_list; diff --git a/util/fluxbox-update_configs.cc b/util/fluxbox-update_configs.cc index cbc0d73..a6cbce5 100644 --- a/util/fluxbox-update_configs.cc +++ b/util/fluxbox-update_configs.cc @@ -20,7 +20,8 @@ // DEALINGS IN THE SOFTWARE. #include "../src/FbTk/I18n.hh" -#include "../src/FbTk/Resource.hh" +#include "../src/FbTk/LResource.hh" +#include "../src/FbTk/LuaUtil.hh" #include "../src/FbTk/StringUtil.hh" #include "../src/FbTk/FileUtil.hh" @@ -74,8 +75,8 @@ void save_all_files(); /*------------------------------------------------------------------*\ \*------------------------------------------------------------------*/ -void update_add_mouse_evens_to_keys(FbTk::ResourceManager_base& rm, - const FbTk::FbString& keyfilename, const FbTk::FbString& appsfilename) { +void update_add_mouse_evens_to_keys(std::auto_ptr& rm) { + string keyfilename = FbTk::StringUtil::expandFilename(rm->resourceValue("keyFile")); string whole_keyfile = read_file(keyfilename); string new_keyfile = ""; @@ -89,10 +90,10 @@ void update_add_mouse_evens_to_keys(FbTk::ResourceManager_base& rm, // hmmm, what are the odds that somebody wants this to be different on // different screens? the ability is going away until we make per-screen // keys files, anyway, so let's just use the first screen's setting - FbTk::BoolResource rc_wheeling(rm, true, + FbTk::BoolResource rc_wheeling(*rm, true, "screen0.desktopwheeling", "Screen0.DesktopWheeling"); - FbTk::BoolResource rc_reverse(rm, false, + FbTk::BoolResource rc_reverse(*rm, false, "screen0.reversewheeling", "Screen0.ReverseWheeling"); if (*rc_wheeling) { @@ -111,10 +112,10 @@ void update_add_mouse_evens_to_keys(FbTk::ResourceManager_base& rm, } -void update_move_groups_entries_to_apps_file(FbTk::ResourceManager_base& rm, - const FbTk::FbString& keyfilename, const FbTk::FbString& appsfilename) { +void update_move_groups_entries_to_apps_file(std::auto_ptr& rm) { - FbTk::StringResource rc_groupfile(rm, "~/.fluxbox/groups", + string appsfilename = FbTk::StringUtil::expandFilename(rm->resourceValue("appsFile")); + FbTk::StringResource rc_groupfile(*rm, "~/.fluxbox/groups", "groupFile", "GroupFile"); string groupfilename = FbTk::StringUtil::expandFilename(*rc_groupfile); string whole_groupfile = read_file(groupfilename); @@ -148,9 +149,9 @@ void update_move_groups_entries_to_apps_file(FbTk::ResourceManager_base& rm, } -void update_move_toolbar_wheeling_to_keys_file(FbTk::ResourceManager_base& rm, - const FbTk::FbString& keyfilename, const FbTk::FbString& appsfilename) { +void update_move_toolbar_wheeling_to_keys_file(std::auto_ptr& rm) { + string keyfilename = FbTk::StringUtil::expandFilename(rm->resourceValue("keyFile")); string whole_keyfile = read_file(keyfilename); string new_keyfile = ""; // let's put our new keybindings first, so they're easy to find @@ -158,13 +159,13 @@ void update_move_toolbar_wheeling_to_keys_file(FbTk::ResourceManager_base& rm, bool keep_changes = false; // scrolling on toolbar needs to match user's toolbar wheeling settings - FbTk::StringResource rc_wheeling(rm, "Off", + FbTk::StringResource rc_wheeling(*rm, "Off", "screen0.iconbar.wheelMode", "Screen0.Iconbar.WheelMode"); - FbTk::BoolResource rc_screen(rm, true, + FbTk::BoolResource rc_screen(*rm, true, "screen0.desktopwheeling", "Screen0.DesktopWheeling"); - FbTk::BoolResource rc_reverse(rm, false, + FbTk::BoolResource rc_reverse(*rm, false, "screen0.reversewheeling", "Screen0.ReverseWheeling"); if (strcasecmp(rc_wheeling->c_str(), "On") == 0 || @@ -187,18 +188,18 @@ void update_move_toolbar_wheeling_to_keys_file(FbTk::ResourceManager_base& rm, -void update_move_modkey_to_keys_file(FbTk::ResourceManager_base& rm, - const FbTk::FbString& keyfilename, const FbTk::FbString& appsfilename) { +void update_move_modkey_to_keys_file(std::auto_ptr& rm) { + string keyfilename = FbTk::StringUtil::expandFilename(rm->resourceValue("keyFile")); string whole_keyfile = read_file(keyfilename); string new_keyfile = ""; // let's put our new keybindings first, so they're easy to find new_keyfile += "!mouse actions added by fluxbox-update_configs\n"; // need to match user's resize model - FbTk::StringResource rc_mode(rm, "Bottom", + FbTk::StringResource rc_mode(*rm, "Bottom", "screen0.resizeMode", "Screen0.ResizeMode"); - FbTk::StringResource rc_modkey(rm, "Mod1", + FbTk::StringResource rc_modkey(*rm, "Mod1", "modKey", "ModKey"); @@ -222,13 +223,12 @@ void update_move_modkey_to_keys_file(FbTk::ResourceManager_base& rm, -void update_window_patterns_for_iconbar(FbTk::ResourceManager_base& rm, - const FbTk::FbString& keyfilename, const FbTk::FbString& appsfilename) { +void update_window_patterns_for_iconbar(std::auto_ptr& rm) { // this needs to survive after going out of scope // it won't get freed, but that's ok FbTk::StringResource *rc_mode = - new FbTk::StringResource(rm, "Workspace", + new FbTk::StringResource(*rm, "Workspace", "screen0.iconbar.mode", "Screen0.Iconbar.Mode"); @@ -251,8 +251,8 @@ void update_window_patterns_for_iconbar(FbTk::ResourceManager_base& rm, } -void update_move_titlebar_actions_to_keys_file(FbTk::ResourceManager_base& rm, - const FbTk::FbString& keyfilename, const FbTk::FbString& appsfilename) { +void update_move_titlebar_actions_to_keys_file(std::auto_ptr& rm) { + string keyfilename = FbTk::StringUtil::expandFilename(rm->resourceValue("keyFile")); string whole_keyfile = read_file(keyfilename); string new_keyfile = ""; // let's put our new keybindings first, so they're easy to find @@ -260,8 +260,8 @@ void update_move_titlebar_actions_to_keys_file(FbTk::ResourceManager_base& rm, new_keyfile += "OnTitlebar Double Mouse1 :Shade\n"; new_keyfile += "OnTitlebar Mouse3 :WindowMenu\n"; - FbTk::BoolResource rc_reverse(rm, false,"screen0.reversewheeling", "Screen0.ReverseWheeling"); - FbTk::StringResource scroll_action(rm, "", "screen0.windowScrollAction", "Screen0.WindowScrollAction"); + FbTk::BoolResource rc_reverse(*rm, false,"screen0.reversewheeling", "Screen0.ReverseWheeling"); + FbTk::StringResource scroll_action(*rm, "", "screen0.windowScrollAction", "Screen0.WindowScrollAction"); if (strcasecmp(scroll_action->c_str(), "shade") == 0) { if (*rc_reverse) { new_keyfile += "OnTitlebar Mouse5 :ShadeOn\n"; @@ -288,8 +288,8 @@ void update_move_titlebar_actions_to_keys_file(FbTk::ResourceManager_base& rm, } -void update_added_starttabbing_command(FbTk::ResourceManager_base& rm, - const FbTk::FbString& keyfilename, const FbTk::FbString& appsfilename) { +void update_added_starttabbing_command(std::auto_ptr& rm) { + string keyfilename = FbTk::StringUtil::expandFilename(rm->resourceValue("keyFile")); string whole_keyfile = read_file(keyfilename); string new_keyfile = ""; // let's put our new keybindings first, so they're easy to find @@ -302,11 +302,10 @@ void update_added_starttabbing_command(FbTk::ResourceManager_base& rm, -void update_disable_icons_in_tabs_for_backwards_compatibility(FbTk::ResourceManager_base& rm, - const FbTk::FbString& keyfilename, const FbTk::FbString& appsfilename) { +void update_disable_icons_in_tabs_for_backwards_compatibility(std::auto_ptr& rm) { FbTk::BoolResource *show = - new FbTk::BoolResource(rm, false, + new FbTk::BoolResource(*rm, false, "screen0.tabs.usePixmap", "Screen0.Tabs.UsePixmap"); if (!*show) // only change if the setting didn't already exist @@ -316,16 +315,15 @@ void update_disable_icons_in_tabs_for_backwards_compatibility(FbTk::ResourceMana -void update_change_format_of_split_placement_menu(FbTk::ResourceManager_base& rm, - const FbTk::FbString& keyfilename, const FbTk::FbString& appsfilename) { +void update_change_format_of_split_placement_menu(std::auto_ptr& rm) { FbTk::StringResource *placement = - new FbTk::StringResource(rm, "BottomRight", + new FbTk::StringResource(*rm, "BottomRight", "screen0.slit.placement", "Screen0.Slit.Placement"); FbTk::StringResource *direction = - new FbTk::StringResource(rm, "Vertical", + new FbTk::StringResource(*rm, "Vertical", "screen0.slit.direction", "Screen0.Slit.Direction"); @@ -344,9 +342,9 @@ void update_change_format_of_split_placement_menu(FbTk::ResourceManager_base& rm -void update_update_keys_file_for_nextwindow_syntax_changes(FbTk::ResourceManager_base& rm, - const FbTk::FbString& keyfilename, const FbTk::FbString& appsfilename) { +void update_update_keys_file_for_nextwindow_syntax_changes(std::auto_ptr& rm) { + string keyfilename = FbTk::StringUtil::expandFilename(rm->resourceValue("keyFile")); string whole_keyfile = read_file(keyfilename); size_t pos = 0; @@ -401,9 +399,9 @@ void update_update_keys_file_for_nextwindow_syntax_changes(FbTk::ResourceManager -void update_keys_for_ongrip_onwindowborder(FbTk::ResourceManager_base& rm, - const FbTk::FbString& keyfilename, const FbTk::FbString& appsfilename) { +void update_keys_for_ongrip_onwindowborder(std::auto_ptr& rm) { + string keyfilename = FbTk::StringUtil::expandFilename(rm->resourceValue("keyFile")); string whole_keyfile = read_file(keyfilename); string new_keyfile = ""; // let's put our new keybindings first, so they're easy to find @@ -421,9 +419,9 @@ void update_keys_for_ongrip_onwindowborder(FbTk::ResourceManager_base& rm, -void update_keys_for_activetab(FbTk::ResourceManager_base& rm, - const FbTk::FbString& keyfilename, const FbTk::FbString& appsfilename) { +void update_keys_for_activetab(std::auto_ptr& rm) { + string keyfilename = FbTk::StringUtil::expandFilename(rm->resourceValue("keyFile")); string whole_file = read_file(keyfilename); string new_keyfile = ""; @@ -439,9 +437,9 @@ void update_keys_for_activetab(FbTk::ResourceManager_base& rm, // NextWindow {static groups} => NextWindow {static groups} (workspace=[current]) -void update_limit_nextwindow_to_current_workspace(FbTk::ResourceManager_base& rm, - const FbTk::FbString& keyfilename, const FbTk::FbString& appsfilename) { +void update_limit_nextwindow_to_current_workspace(std::auto_ptr& rm) { + string keyfilename = FbTk::StringUtil::expandFilename(rm->resourceValue("keyFile")); string whole_file = read_file(keyfilename); string new_keyfile = ""; @@ -525,12 +523,22 @@ void update_limit_nextwindow_to_current_workspace(FbTk::ResourceManager_base& rm write_file(keyfilename, new_keyfile); } +void update_lua_resource_manager(std::auto_ptr& rm) { + if( dynamic_cast(rm.get()) ) { + // there's nothing to do, we already have a lua resource manager + // this shouldn't happen, since all lua init files should have versions >= 14 + return; + } + + +} + /*------------------------------------------------------------------*\ \*------------------------------------------------------------------*/ struct Update { int version; - void (*update)(FbTk::ResourceManager_base& rm, const FbTk::FbString&, const FbTk::FbString&); + void (*update)(std::auto_ptr& rm); }; const Update UPDATES[] = { @@ -546,26 +554,24 @@ const Update UPDATES[] = { { 10, update_update_keys_file_for_nextwindow_syntax_changes }, { 11, update_keys_for_ongrip_onwindowborder }, { 12, update_keys_for_activetab }, - { 13, update_limit_nextwindow_to_current_workspace } + { 13, update_limit_nextwindow_to_current_workspace }, + { 14, update_lua_resource_manager } }; /*------------------------------------------------------------------*\ \*------------------------------------------------------------------*/ -int run_updates(int old_version, FbTk::ResourceManager &rm) { +int run_updates(int old_version, std::auto_ptr &rm, FbTk::Lua &l) { int new_version = old_version; - FbTk::StringResource rc_keyfile(rm, "~/.fluxbox/keys", + FbTk::StringResource rc_keyfile(*rm, "~/.fluxbox/keys", "keyFile", "KeyFile"); - FbTk::StringResource rc_appsfile(rm, "~/.fluxbox/apps", + FbTk::StringResource rc_appsfile(*rm, "~/.fluxbox/apps", "appsFile", "AppsFile"); - string appsfilename = FbTk::StringUtil::expandFilename(*rc_appsfile); - string keyfilename = FbTk::StringUtil::expandFilename(*rc_keyfile); - for (size_t i = 0; i < sizeof(UPDATES) / sizeof(Update); ++i) { if (old_version < UPDATES[i].version) { - UPDATES[i].update(rm, keyfilename, appsfilename); + UPDATES[i].update(rm); new_version = UPDATES[i].version; } } @@ -573,8 +579,32 @@ int run_updates(int old_version, FbTk::ResourceManager &rm) { return new_version; } +std::auto_ptr try_load(const std::string &filename, FbTk::Lua &l) { + _FB_USES_NLS; + std::auto_ptr r; + try { + r.reset(new FbTk::LResourceManager("session", l)); + r->doLoad(filename); + } + catch(std::runtime_error &) { + try { + r.reset(new FbTk::ResourceManager("session", "Session", filename.c_str(), false)); + r->doLoad(filename); + } + catch(std::runtime_error &) { + r.reset(); + } + } + if(r.get()) { + cerr << _FB_CONSOLETEXT(Update, Loading, "Loading resources from: ", "filename follows") + << filename << endl; + } + return r; +} + int main(int argc, char **argv) { string rc_filename; + string oldrc_filename; set style_filenames; int i = 1; bool check = 0; @@ -595,6 +625,14 @@ int main(int argc, char **argv) { } rc_filename = argv[i]; + } else if (arg == "-oldrc") { + if ((++i) >= argc) { + cerr<<_FB_CONSOLETEXT(main, RCRequiresArg, + "error: '-oldrc' requires an argument", "the -oldrc option requires a file argument")<= argc) { // need translations for this, too @@ -605,7 +643,8 @@ int main(int argc, char **argv) { check = true; } else if (arg == "-help" || arg == "-h") { // no NLS translations yet -- we'll just have to use English for now - cout << " -rc \t\t\tuse alternate resource file.\n" + cout << " -rc \t\t\twhere to save the new resource file.\n" + << " -oldrc \t\t\tfile from which to load old resources (default = same as -rc).\n" << " -pid \t\t\ttell fluxbox to reload configuration.\n" << " -check\t\t\tcheck version of this tool and the fluxbox config.\n" << " -help\t\t\t\tdisplay this help text and exit.\n\n" @@ -614,14 +653,33 @@ int main(int argc, char **argv) { } } - if (rc_filename.empty()) - rc_filename = getenv("HOME") + string("/.fluxbox/init"); + string filenames[4]; + if(!oldrc_filename.empty()) + filenames[0] = oldrc_filename; + else if(!rc_filename.empty()) + filenames[0] = rc_filename; + else { + filenames[0] = getenv("HOME") + string("/.fluxbox/init.lua"); + filenames[1] = getenv("HOME") + string("/.fluxbox/init"); + filenames[2] = DEFAULT_INITFILE; + filenames[3] = string(DEFAULT_INITFILE, string(DEFAULT_INITFILE).rfind(".lua")); + } - FbTk::ResourceManager resource_manager("session", "Session", rc_filename.c_str(),false); - try { - resource_manager.load(rc_filename, DEFAULT_INITFILE); + if (rc_filename.empty()) + rc_filename = getenv("HOME") + string("/.fluxbox/init.lua"); + + FbTk::Lua l; + std::auto_ptr resource_manager; + for(size_t i = 0; i < sizeof filenames / sizeof filenames[0]; ++i) { + if(!filenames[i].empty()) { + resource_manager = try_load(filenames[i], l); + if(resource_manager.get()) { + oldrc_filename = filenames[i]; + break; + } + } } - catch(std::runtime_error &) { + if(!resource_manager.get()) { // This should only happen if system-wide init file is broken. // this is a fatal error for us return 1; @@ -630,22 +688,22 @@ int main(int argc, char **argv) { // run updates here // I feel like putting this in a separate function for no apparent reason - FbTk::IntResource config_version(resource_manager, 0, + FbTk::IntResource config_version(*resource_manager, 0, "configVersion", "ConfigVersion"); if (check) { - cout << rc_filename << ": " << *config_version << endl + cout << oldrc_filename << ": " << *config_version << endl << "fluxbox-update_configs: " << UPDATES[sizeof(UPDATES)/sizeof(Update) - 1].version << endl; - exit(0); + return 0; } int old_version = *config_version; - int new_version = run_updates(old_version, resource_manager); + int new_version = run_updates(old_version, resource_manager, l); if (new_version > old_version) { // configs were updated -- let's save our changes config_version = new_version; - resource_manager.save(rc_filename.c_str(), rc_filename.c_str()); + resource_manager->save(rc_filename.c_str()); save_all_files(); #if defined(HAVE_SIGNAL_H) && !defined(_WIN32) -- cgit v0.11.2