fix all problems I could see with dirs/filenames containing spaces/accented chars...
authorgc <gc>
Fri, 6 May 2005 22:07:42 +0000 (22:07 +0000)
committergc <gc>
Fri, 6 May 2005 22:07:42 +0000 (22:07 +0000)
bin/booh
bin/booh-gui
lib/booh/booh-lib.rb

index 6d7cc315ab38e866961110753ad3532dc529c9ff..42db25d6debb8694ade924f53d96957748546c4b 100755 (executable)
--- a/bin/booh
+++ b/bin/booh
@@ -144,8 +144,8 @@ def handle_options
     end
 
     if !$source && $xmldoc
-        $source = $xmldoc.root.attributes['source']
-        $dest = $xmldoc.root.attributes['destination']
+        $source = from_utf8($xmldoc.root.attributes['source'])
+        $dest = from_utf8($xmldoc.root.attributes['destination'])
         $theme = $xmldoc.root.attributes['theme']
         $limit_sizes = $xmldoc.root.attributes['limit-sizes']
     end
@@ -339,7 +339,7 @@ end
 
 def walk_source_dir
 
-    `find #{$source} -type d`.sort.each { |dir|
+    `find '#{$source}' -type d`.sort.each { |dir|
         dir.chomp!
         if dir =~ /'/
             die _("Source directory or sub-directories can't contain a single-quote character, sorry.")
@@ -377,9 +377,13 @@ def walk_source_dir
             entries = Dir.entries(dir).sort
             #- populate config in case of gen_config, add new files in case of merge_config
             for file in entries
-                type = entry2type(file)
-                if type && !xmldir.elements["#{type}[@filename='#{utf8(file)}']"]
-                    xmldir.add_element type, { "filename" => utf8(file), "caption" => utf8(file.sub(/\.[^\.]+$/, '')[0..17]) }
+                if file =~ /['"\(\)\[\]]/
+                    msg 1, _("Ignoring %s, contains one of forbidden characters: '\"()[]") % "#{dir}/#{file}"
+                else
+                    type = entry2type(file)
+                    if type && !xmldir.elements["#{type}[@filename='#{utf8(file)}']"]
+                        xmldir.add_element type, { "filename" => utf8(file), "caption" => utf8(file.sub(/\.[^\.]+$/, '')[0..17]) }
+                    end
                 end
             end
             if $mode == 'merge_config'
@@ -632,7 +636,7 @@ def walk_source_dir
     #- second pass to create index.html files
     msg 3, _("\trescanning directories to generate all `index.html' files...")
 
-    `find #{$source} -type d`.each { |dir|
+    `find '#{$source}' -type d`.each { |dir|
         dir.chomp!
         xmldir = $xmldoc.elements["//dir[@path='#{utf8(dir)}']"]
         if !xmldir
index 81b531a5c62fbb2f2b0bd20753e2358c5b7f82d6..fc155a457bc08715a9f9f3a62bb8247aaefcb487 100755 (executable)
@@ -156,7 +156,7 @@ end
 def current_dest_dir
     source = $xmldoc.root.attributes['source']
     dest = $xmldoc.root.attributes['destination']
-    return make_dest_filename(from_utf8($current_path).sub(/^#{Regexp.quote(source)}/, dest))
+    return make_dest_filename($current_path.sub(/^#{Regexp.quote(source)}/, dest))
 end
 
 def build_full_dest_filename(filename)
@@ -170,7 +170,7 @@ end
 
 def view_element(filename)
     if entry2type(filename) == 'video'
-        system("mplayer #{$current_path + '/' + filename}")
+        system("mplayer '#{from_utf8($current_path + '/' + filename)}'")
         return
     end
 
@@ -198,7 +198,7 @@ def view_element(filename)
     evt = Gtk::EventBox.new.add(Gtk::Alignment.new(0.5, 0.5, 0, 0).add(Gtk::Frame.new.add(Gtk::Image.new(dest_img)).set_shadow_type(Gtk::SHADOW_ETCHED_OUT)))
 
     tooltips = Gtk::Tooltips.new
-    tooltips.set_tip(evt, utf8(File.basename(filename).gsub(/\.jpg/, '')), nil)
+    tooltips.set_tip(evt, File.basename(filename).gsub(/\.jpg/, ''), nil)
 
     bottom = Gtk::Alignment.new(0.5, 0.5, 0, 0).add(b = Gtk::Button.new(Gtk::Stock::CLOSE))
     b.signal_connect('clicked') { w.destroy }
@@ -447,7 +447,7 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
     evtbox = Gtk::EventBox.new.add(Gtk::Alignment.new(0.5, 0.5, 0, 0).add(frame1.set_shadow_type(Gtk::SHADOW_ETCHED_OUT)))
 
     tooltips = Gtk::Tooltips.new
-    tipname = File.basename(thumbnail_img).gsub(/-\d+x\d+\.jpg/, '')
+    tipname = from_utf8(File.basename(filename).gsub(/\.[^\.]+$/, ''))
     tooltips.set_tip(evtbox, utf8(type == 'video' ? (_("%s (video - %s KB)") % [tipname, commify(file_size(from_utf8("#{$current_path}/#{filename}"))/1024)]) : tipname), nil)
 
     frame2, textview = create_editzone($autotable_sw, 1)
@@ -1348,7 +1348,7 @@ def new_album
                     src_nb_thread = Thread.new {
                         src_nb.set_markup(utf8(_("<span size='small'><i>processing...</i></span>")))
                         total = { 'image' => 0, 'video' => 0, nil => 0 }
-                        `find #{from_utf8(src_nb_calculated_for)} -type d`.each { |dir|
+                        `find '#{from_utf8(src_nb_calculated_for)}' -type d`.each { |dir|
                             begin
                                 Dir.entries(dir.chomp).each { |file|
                                     total[entry2type(file)] += 1
@@ -1462,6 +1462,9 @@ def new_album
                 elsif conf.text == ''
                     show_popup(dialog, utf8(_("Please specify a filename to store the album's properties.")))
                     conf.grab_focus
+                elsif destdir != make_dest_filename(destdir)
+                    show_popup(dialog, utf8(_("Sorry, destination directory can't contain non simple alphanumeric characters.")))
+                    dest.grab_focus
                 elsif File.directory?(destdir)
                     keepon = !show_popup(dialog, utf8(_("The destination directory already exists. Are you sure you want to continue?")), { :okcancel => true })
                     dest.grab_focus
@@ -1496,7 +1499,7 @@ def new_album
     Gtk.timeout_remove(timeout_src_nb)
 
     if ok
-        perform_in_background("booh --source #{srcdir} --destination #{destdir} --config-skel #{configskel} --for-gui " +
+        perform_in_background("booh --source '#{srcdir}' --destination '#{destdir}' --config-skel '#{configskel}' --for-gui " +
                                   "--verbose-level #{$verbose_level} --theme #{theme} --sizes #{sizes} #{additional_booh_options}",
                               utf8(_("Please wait while scanning source directory...")),
                               { :closure_after => proc { open_file(configskel) } })
@@ -1606,7 +1609,7 @@ def properties
     dialog.destroy
 
     if ok && (save_theme != theme || save_limit_sizes != limit_sizes)
-        perform_in_background("booh --merge-config #{$filename} --for-gui " +
+        perform_in_background("booh --merge-config '#{$filename}' --for-gui " +
                                   "--verbose-level #{$verbose_level} --theme #{theme} --sizes #{save_limit_sizes.join(',')} #{additional_booh_options}",
                               utf8(_("Please wait while scanning source directory...")),
                               { :closure_after => proc { open_file($filename) } })
@@ -1621,7 +1624,7 @@ def merge
     if limit_sizes
         limit_sizes = "--sizes #{limit_sizes}"
     end
-    perform_in_background("booh --merge-config #{$filename} --for-gui " +
+    perform_in_background("booh --merge-config '#{$filename}' --for-gui " +
                               "--verbose-level #{$verbose_level} --theme #{theme} #{limit_sizes} #{additional_booh_options}",
                           utf8(_("Please wait while scanning source directory...")),
                           { :closure_after => proc { open_file($filename) } })
@@ -1725,7 +1728,7 @@ def create_menu_and_toolbar
     $merge.signal_connect('activate') { merge }
     $generate.signal_connect('activate') {
         save_current_file
-        perform_in_background("booh --config #{$filename} --verbose-level #{$verbose_level} #{additional_booh_options}",
+        perform_in_background("booh --config '#{$filename}' --verbose-level #{$verbose_level} #{additional_booh_options}",
                               utf8(_("Please wait while generating web-album...\nThis may take a while, please be patient.")),
                               { :successmsg => utf8(_("Your web-album is now ready in directory `%s'.") % $xmldoc.root.attributes['destination'] ),
                                 :failuremsg => utf8(_("There was something wrong when generating the web-album, sorry.")) })
index 8613df9e51b68d99f59d2646804eebe8f5a33318..464fe77dae1be01217613e667b7e7003d5c254ac 100644 (file)
@@ -115,9 +115,9 @@ module Booh
     end
 
     def entry2type(entry)
-        if entry =~ /\.(jpg|jpeg|jpe|gif|bmp|png)$/i
+        if entry =~ /\.(jpg|jpeg|jpe|gif|bmp|png)$/i && entry !~ /['"\(\)\[\]]/
             return 'image'
-        elsif entry =~ /\.(mov|avi|mpg|mpeg|mpe|wmv|asx)$/i
+        elsif entry =~ /\.(mov|avi|mpg|mpeg|mpe|wmv|asx)$/i && entry !~ /['"\(\)\[\]]/
             #- might consider using file magic later..
             return 'video'
         else