when save fail, rescue errors; try to save in UTF8 if user entered chars which defaul...
[booh] / bin / booh
index f59d3da5b8ab1fd02097ab5ad0b528df1bd09ca7..c9f9a9235d7c2d7675281440682e9c9ec2f79f17 100755 (executable)
--- a/bin/booh
+++ b/bin/booh
@@ -1549,16 +1549,36 @@ def save_current_file
     save_changes
 
     if $filename
-        ios = File.open($filename, "w")
-        $xmldoc.write(ios, 0)
-        ios.close
+        begin
+            begin
+                ios = File.open($filename, "w")
+                $xmldoc.write(ios, 0)
+                ios.close
+            rescue Iconv::IllegalSequence
+                #- user might have entered text which cannot be encoded in his default encoding. retry in UTF-8.
+                if ! ios.nil? && ! ios.closed?
+                    ios.close
+                end
+                $xmldoc.xml_decl.encoding = 'UTF-8'
+                ios = File.open($filename, "w")
+                $xmldoc.write(ios, 0)
+                ios.close
+            end
+            return true
+        rescue Exception
+            return false
+        end
     end
 end
 
 def save_current_file_user
     save_tempfilename = $filename
     $filename = $orig_filename
-    save_current_file
+    if ! save_current_file
+        show_popup($main_window, utf8(_("Save failed! Try another location/name.")))
+        $filename = save_tempfilename
+        return
+    end
     $modified = false
     $generated_outofline = false
     $filename = save_tempfilename
@@ -1602,7 +1622,9 @@ def ask_save_modifications(msg1, msg2, *options)
         dialog.run { |response|
             dialog.destroy
             if response == Gtk::Dialog::RESPONSE_YES
-                save_current_file_user
+                if ! save_current_file_user
+                    return ask_save_modifications(msg1, msg2, options)
+                end
             else
                 #- if we have generated an album but won't save modifications, we must remove 
                 #- already-generated markers in original file
@@ -3090,7 +3112,10 @@ def save_as_do
     fc.filename = $orig_filename
     if fc.run == Gtk::Dialog::RESPONSE_ACCEPT
         $orig_filename = fc.filename
-        save_current_file_user
+        if ! save_current_file_user
+            fc.destroy
+            return save_as_do
+        end
         $config['last-opens'] ||= []
         $config['last-opens'] << $orig_filename
     end