Index: /extensions/BatchDownloader/include/BatchDownloader.class.php
===================================================================
--- /extensions/BatchDownloader/include/BatchDownloader.class.php	(revision 17655)
+++ /extensions/BatchDownloader/include/BatchDownloader.class.php	(revision 17656)
@@ -325,5 +325,5 @@
       foreach ($images_to_add as $row)
       {        
-        $zip->addFile(PHPWG_ROOT_PATH . $row['path'], $row['id'].'_'.str2url($row['name']).'.'.get_extension($row['file']));
+        $zip->addFile(PHPWG_ROOT_PATH . $row['path'], $row['id'].'_'.get_filename_wo_extension($row['file']).'.'.get_extension($row['path']));
         
         array_push($images_added, $row['id']);
Index: /extensions/BatchDownloader/include/events.inc.php
===================================================================
--- /extensions/BatchDownloader/include/events.inc.php	(revision 17655)
+++ /extensions/BatchDownloader/include/events.inc.php	(revision 17656)
@@ -3,14 +3,4 @@
 
 # this file contains all functions directly called by the triggers #
-
-/* unserialize conf and load language */
-function batch_download_init()
-{
-  global $conf;
-  
-  $conf['batch_download'] = unserialize($conf['batch_download']);
-  load_language('plugin.lang', BATCH_DOWNLOAD_PATH);
-}
-
 
 /* define page section from url */
Index: /extensions/BatchDownloader/include/install.inc.php
===================================================================
--- /extensions/BatchDownloader/include/install.inc.php	(revision 17656)
+++ /extensions/BatchDownloader/include/install.inc.php	(revision 17656)
@@ -0,0 +1,64 @@
+<?php
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+function batch_download_install() 
+{
+  global $conf, $prefixeTable;
+  
+  // configuration
+  if (empty($conf['batch_download']))
+  {
+    $batch_download_default_config = serialize(array(
+      'groups'          => array(),
+      'level'           => 0,
+      'photo_size'      => 'original',
+      'archive_prefix'  => 'piwigo',
+      'archive_timeout' => 48, /* hours */
+      'max_elements'    => 500,
+      'max_size'        => 100, /* MB */
+      'last_clean'      => time(),
+      ));
+    
+    conf_update_param('batch_download', $batch_download_default_config);
+    conf_update_param('batch_download_comment', null);
+    
+    $conf['batch_download'] = $batch_download_default_config;
+    $conf['batch_download_comment'] = null;
+  }
+
+  // archives directory
+  if (!file_exists($conf['data_location'] . 'download_archives/'))
+  {
+    mkdir($conf['data_location'] . 'download_archives/', 0755);
+  }
+
+  // create tables
+  $query = '
+CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'download_sets` (
+  `id` mediumint(8) NOT NULL AUTO_INCREMENT,
+  `user_id` smallint(5) NOT NULL,
+  `date_creation` datetime NOT NULL,
+  `type` varchar(16) CHARACTER SET utf8 NOT NULL,
+  `type_id` varchar(64) CHARACTER SET utf8 NOT NULL,
+  `nb_zip` smallint(3) NOT NULL DEFAULT 0,
+  `last_zip` smallint(3) NOT NULL DEFAULT 0,
+  `nb_images` mediumint(8) NOT NULL DEFAULT 0,
+  `total_size` int(10) NOT NULL DEFAULT 0,
+  `status` enum("new","download","done") CHARACTER SET utf8 NOT NULL DEFAULT "new",
+  PRIMARY KEY (`id`)
+) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1
+;';
+  pwg_query($query);
+  
+  $query = '
+CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'download_sets_images` (
+  `set_id` mediumint(8) NOT NULL,
+  `image_id` mediumint(8) NOT NULL,
+  `zip` smallint(5) NOT NULL DEFAULT 0,
+  UNIQUE KEY `UNIQUE` (`set_id`,`image_id`)
+) DEFAULT CHARSET=utf8
+;';
+  pwg_query($query);
+}
+
+?>
Index: /extensions/BatchDownloader/main.inc.php
===================================================================
--- /extensions/BatchDownloader/main.inc.php	(revision 17655)
+++ /extensions/BatchDownloader/main.inc.php	(revision 17656)
@@ -13,16 +13,17 @@
 global $conf, $prefixeTable;
 
-define('BATCH_DOWNLOAD_PATH',    PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
+define('BATCH_DOWNLOAD_PATH',    PHPWG_PLUGINS_PATH . 'BatchDownloader/');
 define('BATCH_DOWNLOAD_TSETS',   $prefixeTable . 'download_sets');
 define('BATCH_DOWNLOAD_TIMAGES', $prefixeTable . 'download_sets_images');
 define('BATCH_DOWNLOAD_LOCAL',   PHPWG_ROOT_PATH . $conf['data_location'] . 'download_archives/');
-define('BATCH_DOWNLOAD_ADMIN',   get_root_url() . 'admin.php?page=plugin-' . basename(dirname(__FILE__)));
+define('BATCH_DOWNLOAD_ADMIN',   get_root_url() . 'admin.php?page=plugin-BatchDownloader');
 define('BATCH_DOWNLOAD_PUBLIC',  get_absolute_root_url() . make_index_url(array('section' => 'download')) . '/');
+define('BATCH_DOWNLOAD_VERSION', '1.0.3');
 
+
+add_event_handler('init', 'batch_download_init');
 
 if (class_exists('ZipArchive'))
 {
-  add_event_handler('init', 'batch_download_init');
-
   add_event_handler('loc_end_section_init', 'batch_download_section_init');
   add_event_handler('loc_end_index', 'batch_download_page');
@@ -35,13 +36,55 @@
   add_event_handler('blockmanager_apply', 'batch_download_applymenu');
   
-  require(BATCH_DOWNLOAD_PATH . 'include/functions.inc.php');
-  require(BATCH_DOWNLOAD_PATH . 'include/BatchDownloader.class.php');
-  require(BATCH_DOWNLOAD_PATH . 'include/events.inc.php');
+  include_once(BATCH_DOWNLOAD_PATH . 'include/BatchDownloader.class.php');
+  include_once(BATCH_DOWNLOAD_PATH . 'include/functions.inc.php');
+  include_once(BATCH_DOWNLOAD_PATH . 'include/events.inc.php');
+}
+
+if (defined('IN_ADMIN'))
+{
+  add_event_handler('get_admin_plugin_menu_links', 'batch_download_admin_menu');
 }
 
 
-add_event_handler('get_admin_plugin_menu_links', 'batch_download_admin_menu');
 
-/* admin plugins menu */
+/**
+ * unserialize conf and load language
+ */
+function batch_download_init()
+{
+  global $conf, $pwg_loaded_plugins;
+  
+  if (
+    $pwg_loaded_plugins['BatchDownloader']['version'] == 'auto' or
+    version_compare($pwg_loaded_plugins['BatchDownloader']['version'], BATCH_DOWNLOAD_VERSION, '<')
+  )
+  {
+    include_once(BATCH_DOWNLOAD_PATH . 'include/install.inc.php');
+    batch_download_install();
+    
+    if ($pwg_loaded_plugins['BatchDownloader']['version'] != 'auto')
+    {
+      $query = '
+UPDATE '. PLUGINS_TABLE .'
+SET version = "'. BATCH_DOWNLOAD_VERSION .'"
+WHERE id = "BatchDownloader"';
+      pwg_query($query);
+      
+      $pwg_loaded_plugins['BatchDownloader']['version'] = BATCH_DOWNLOAD_VERSION;
+      
+      if (defined('IN_ADMIN'))
+      {
+        $_SESSION['page_infos'][] = 'BatchDownloader updated to version '. BATCH_DOWNLOAD_VERSION;
+      }
+    }
+  }
+  
+  $conf['batch_download'] = unserialize($conf['batch_download']);
+  load_language('plugin.lang', BATCH_DOWNLOAD_PATH);
+}
+
+/**
+ * admin plugins menu
+ */
 function batch_download_admin_menu($menu) 
 {
Index: /extensions/BatchDownloader/maintain.inc.php
===================================================================
--- /extensions/BatchDownloader/maintain.inc.php	(revision 17655)
+++ /extensions/BatchDownloader/maintain.inc.php	(revision 17656)
@@ -2,70 +2,18 @@
 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
 
-define(
-  'batch_download_default_config', 
-  serialize(array(
-    'groups'          => array(),
-    'level'           => 0,
-    'photo_size'      => 'original',
-    'archive_prefix'  => 'piwigo',
-    'archive_timeout' => 48, /* hours */
-    'max_elements'    => 500,
-    'max_size'        => 100, /* MB */
-    'last_clean'      => time(),
-    ))
-  );
+include_once(PHPWG_PLUGINS_PATH . 'BatchDownloader/include/install.inc.php');
 
 function plugin_install() 
 {
-  global $conf, $prefixeTable;
+  batch_download_install();
   
-  $query = '
-CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'download_sets` (
-  `id` mediumint(8) NOT NULL AUTO_INCREMENT,
-  `user_id` smallint(5) NOT NULL,
-  `date_creation` datetime NOT NULL,
-  `type` varchar(16) CHARACTER SET utf8 NOT NULL,
-  `type_id` varchar(64) CHARACTER SET utf8 NOT NULL,
-  `nb_zip` smallint(3) NOT NULL DEFAULT 0,
-  `last_zip` smallint(3) NOT NULL DEFAULT 0,
-  `nb_images` mediumint(8) NOT NULL DEFAULT 0,
-  `total_size` int(10) NOT NULL DEFAULT 0,
-  `status` enum("new","download","done") CHARACTER SET utf8 NOT NULL DEFAULT "new",
-  PRIMARY KEY (`id`)
-) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1
-;';
-  pwg_query($query);
-  
-  $query = '
-CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'download_sets_images` (
-  `set_id` mediumint(8) NOT NULL,
-  `image_id` mediumint(8) NOT NULL,
-  `zip` smallint(5) NOT NULL DEFAULT 0,
-  UNIQUE KEY `UNIQUE` (`set_id`,`image_id`)
-) DEFAULT CHARSET=utf8
-;';
-  pwg_query($query);
-
-  conf_update_param('batch_download', batch_download_default_config);
-  conf_update_param('batch_download_comment', null);
-  
-  mkdir($conf['data_location'] . 'download_archives/', 0755);
+  define('batch_download_installed', true);
 }
 
 function plugin_activate()
 {
-  global $conf;
-
-  if (empty($conf['batch_download_comment']))
+  if (!defined('batch_download_installed'))
   {
-    $new_conf = unserialize($conf['batch_download']);
-    unset($new_conf['archive_comment']);
-    conf_update_param('batch_download', serialize($new_conf));
-    conf_update_param('batch_download_comment', null);
-  }
-  
-  if (!file_exists($conf['data_location'] . 'download_archives/'))
-  {
-    mkdir($conf['data_location'] . 'download_archives/', 0755);
+    batch_download_install();
   }
 }
@@ -82,32 +30,36 @@
 }
 
-function rrmdir($dir)
+
+if (!function_exists('rrmdir'))
 {
-  if (!is_dir($dir))
+  function rrmdir($dir)
   {
-    return false;
-  }
-  $dir = rtrim($dir, '/');
-  $objects = scandir($dir);
-  $return = true;
-  
-  foreach ($objects as $object)
-  {
-    if ($object !== '.' && $object !== '..')
+    if (!is_dir($dir))
     {
-      $path = $dir.'/'.$object;
-      if (filetype($path) == 'dir') 
+      return false;
+    }
+    $dir = rtrim($dir, '/');
+    $objects = scandir($dir);
+    $return = true;
+    
+    foreach ($objects as $object)
+    {
+      if ($object !== '.' && $object !== '..')
       {
-        $return = $return && rrmdir($path); 
-      }
-      else 
-      {
-        $return = $return && @unlink($path);
+        $path = $dir.'/'.$object;
+        if (filetype($path) == 'dir') 
+        {
+          $return = $return && rrmdir($path); 
+        }
+        else 
+        {
+          $return = $return && @unlink($path);
+        }
       }
     }
+    
+    return $return && @rmdir($dir);
   }
-  
-  return $return && @rmdir($dir);
-} 
+}
 
 ?>
