videosite-irssi: fix init logic
[videosite.git] / videosite-irssi.pl
index f20e3a1..f9d7828 100644 (file)
@@ -778,9 +778,13 @@ sub config_init {
     my $conf;
 
     # Check for irssi internal config. If not found...
+    if (config_has(['config-version'])) {
+        # Configuration in irssi config file. We're done.
+        return;
+    }
 
+    # Try to find old config files and load them.
     if (-r $conffile) {
-        write_debug("Attempting JSON config load from %s", $conffile);
         eval {
             local $/;
             open(CONF, '<', $conffile);
@@ -788,7 +792,6 @@ sub config_init {
             close(CONF);
         };
     } elsif (-r $xmlconffile) {
-        write_debug("Attempting XML config load from %s", $xmlconffile);
         $conf = XML::Simple::XMLin($xmlconffile, ForceArray => ['config', 'option', 'connectorlist'], KeepRoot => 1, KeyAttr => {'connector' => '+name', 'config' => 'module', 'option' => 'key'});
     }
 
@@ -800,7 +803,7 @@ sub config_init {
     #   content => value
     # }
     #
-    # by this structure
+    # with this structure
     #
     # key => value
     #
@@ -855,6 +858,7 @@ sub config_init {
     }
     config_set(['active-connectors'], join(",", @{$conf->{connectorlist}}));
     config_set(['defined-connectors'], join(",", @connectors));
+    config_set(['config-version'], '2');
 }
 
 #
@@ -862,7 +866,7 @@ sub config_init {
 #
 sub config_get {
     my $path = shift;
-    my $item = join('.', @{$path});
+    my $item = join('.', 'videosite', @{$path});
     my $val;
 
 
@@ -877,7 +881,7 @@ sub config_get {
 #
 sub config_has {
     my $path = shift;
-    my $item = join('.', @{$path});
+    my $item = join('.', 'videosite', @{$path});
 
     Irssi::settings_add_str('videosite', $item, "\0");
     return Irssi::settings_get_str ne "\0";
@@ -889,7 +893,7 @@ sub config_has {
 sub config_set {
     my $path = shift;
     my $value = shift;
-    my $item = join('.', @{$path});
+    my $item = join('.', 'videosite', @{$path});
 
     Irssi::settings_add_str('videosite', $item, "\0");
     Irssi::settings_set_str($item, $value);
@@ -900,7 +904,7 @@ sub config_set {
 #
 sub config_del {
     my $path = shift;
-    my $item = join('.', @{$path});
+    my $item = join('.', 'videosite', @{$path});
 
     Irssi::settings_remove($item);
 }
@@ -977,7 +981,7 @@ sub videosite_init {
     push(@INC, File::Spec->catfile(Irssi::get_irssi_dir(), 'scripts'));
     load 'libvideosite';
 
-    unless (videosite_reset()) {
+    if (videosite_reset()) {
         signal_add_last("message public", sub { message_hook(@_) });
         signal_add_last("message own_public", sub { message_hook($_[0], $_[1], undef, undef, $_[2]) });
         signal_add_last("message private", sub { message_hooK($_[0], $_[1], $_[2], $_[3], $_[2]) });