diff --git a/contrib/de_DE/LC_MESSAGES/gimp.po b/contrib/de_DE/LC_MESSAGES/gimp.po index f291f1b..1a16cb7 100644 --- a/contrib/de_DE/LC_MESSAGES/gimp.po +++ b/contrib/de_DE/LC_MESSAGES/gimp.po @@ -21,23 +21,23 @@ msgstr "" "dngettext:2,3\n" "X-Poedit-Basepath: .\n" -#: gimp.lua:189 +#: gimp.lua:194 #, lua-format msgid "Export Image %i/%i" msgstr "Exportiere Bild %i/%i" -#: gimp.lua:202 +#: gimp.lua:242 msgid "Unable to move edited file into collection. Leaving it as %s" msgstr "Die bearbeitete Datei kann nicht in die Sammlung aufgenommen werden. Bearbeitet Datei ist %s" -#: gimp.lua:209 +#: gimp.lua:251 msgid "GIMP not found" msgstr "GIMP nicht gefunden" -#: gimp.lua:224 +#: gimp.lua:266 msgid "Launching GIMP..." msgstr "Starten von GIMP" -#: gimp.lua:271 +#: gimp.lua:313 msgid "Edit with GIMP" msgstr "Bearbeiten mit GIMP" diff --git a/contrib/gimp.lua b/contrib/gimp.lua index f90db1d..61c4fdb 100644 --- a/contrib/gimp.lua +++ b/contrib/gimp.lua @@ -194,16 +194,58 @@ local function show_status(storage, image, format, filename, dt.print(string.format(_("Export Image %i/%i"), number, total)) end -local function fileMove(fromFile, toFile) - local result = os.execute("mv '" .. fromFile .. "' '" .. toFile .. "'") - dt.print_error("result is " .. tostring(result)) +local function fileCopy(fromFile, toFile) + local result = nil + -- if cp exists, use it + if checkIfBinExists("cp") then + result = os.execute("cp '" .. fromFile .. "' '" .. toFile .. "'") + end + -- if cp was not present, or if cp failed, then a pure lua solution if not result then - dt.print_error("fileMove Error: Unable to copy " .. fromFile .. " to " .. toFile .. ". Leaving " .. fromFile .. " in place.") - dt.print(string.format(_("Unable to move edited file into collection. Leaving it as %s"), fromFile)) + local fileIn, err = io.open(fromFile, 'rb') + if fileIn then + local fileOut, errr = io.open(toFile, 'w') + if fileOut then + local content = fileIn:read(4096) + while content do + fileOut:write(content) + content = fileIn:read(4096) + end + result = true + fileIn:close() + fileOut:close() + else + dt.print_error("fileCopy Error: " .. errr) + end + else + dt.print_error("fileCopy Error: " .. err) + end end return result end +local function fileMove(fromFile, toFile) + local success = os.rename(fromFile, toFile) + if not success then + -- an error occurred, so let's try using the operating system function + if checkIfBinExists("mv") then + success = os.execute("mv '" .. fromFile .. "' '" .. toFile .. "'") + end + -- if the mv didn't exist or succeed, then... + if not success then + -- pure lua solution + success = fileCopy(fromFile, toFile) + if success then + os.remove(fromFile) + else + dt.print_error("fileMove Error: Unable to move " .. fromFile .. " to " .. toFile .. ". Leaving " .. fromFile .. " in place.") + dt.print(string.format(_("Unable to move edited file into collection. Leaving it as %s"), fromFile)) + end + end + end + return success -- nil on error, some value if success +end + local function gimp_edit(storage, image_table, extra_data) --finalize if not checkIfBinExists("gimp") then dt.print_error(_("GIMP not found"))