]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/config.rb
Reset configuration changed status after saving successfully
[user/henk/code/ruby/rbot.git] / lib / rbot / config.rb
index e8cea284ab136d80cb06b763fa884a3ad00b56e4..2495a307331432faef7f28645c45727fb52b06f0 100644 (file)
@@ -25,6 +25,7 @@ module Irc
     attr_reader :requires_rescan
     attr_reader :order
     attr_reader :manager
+    attr_reader :auth_path
     def initialize(key, params)
       @manager = BotConfig::configmanager
       # Keys must be in the form 'module.name'.
@@ -48,6 +49,7 @@ module Irc
       @wizard = params[:wizard]
       @requires_restart = params[:requires_restart]
       @requires_rescan = params[:requires_rescan]
+      @auth_path = "config::key::#{key.sub('.','::')}"
     end
     def default
       if @default.instance_of?(Proc)
@@ -63,6 +65,7 @@ module Irc
     alias :value :get
     def set(value, on_change = true)
       @manager.config[@key] = value
+      @manager.changed = true
       @on_change.call(@manager.bot, value) if on_change && @on_change
     end
     def unset
@@ -176,6 +179,7 @@ module Irc
     attr_reader :bot
     attr_reader :items
     attr_reader :config
+    attr_accessor :changed
 
     def initialize
       bot_associate(nil,true)
@@ -192,6 +196,7 @@ module Irc
       @bot = bot
       return unless @bot
 
+      @changed = false
       if(File.exist?("#{@bot.botclass}/conf.yaml"))
         begin
           newconfig = YAML::load_file("#{@bot.botclass}/conf.yaml")
@@ -206,6 +211,7 @@ module Irc
       # if we got here, we need to run the first-run wizard
       BotConfigWizard.new(@bot).run
       # save newly created config
+      @changed = true
       save
     end
 
@@ -247,6 +253,10 @@ module Irc
 
     # write current configuration to #{botclass}/conf.yaml
     def save
+      if not @changed
+        debug "Not writing conf.yaml (unchanged)"
+        return
+      end
       begin
         debug "Writing new conf.yaml ..."
         File.open("#{@bot.botclass}/conf.yaml.new", "w") do |file|
@@ -259,6 +269,7 @@ module Irc
         debug "Officializing conf.yaml ..."
         File.rename("#{@bot.botclass}/conf.yaml.new",
                     "#{@bot.botclass}/conf.yaml")
+        @changed = false
       rescue => e
         error "failed to write configuration file conf.yaml! #{$!}"
         error "#{e.class}: #{e}"