diff options
author | Xan Lopez <xan@src.gnome.org> | 2003-11-28 07:46:32 +0800 |
---|---|---|
committer | Xan Lopez <xan@src.gnome.org> | 2003-11-28 07:46:32 +0800 |
commit | 493334ce5b250010cd55fddfef9d83470b6d0c70 (patch) | |
tree | b0ca55562c16790de3626e99f38e0aa75e735e5a | |
parent | 9bba3e204ba22f682e2ab211f9fccf760ae58a93 (diff) | |
download | gsoc2013-epiphany-493334ce5b250010cd55fddfef9d83470b6d0c70.tar gsoc2013-epiphany-493334ce5b250010cd55fddfef9d83470b6d0c70.tar.gz gsoc2013-epiphany-493334ce5b250010cd55fddfef9d83470b6d0c70.tar.bz2 gsoc2013-epiphany-493334ce5b250010cd55fddfef9d83470b6d0c70.tar.lz gsoc2013-epiphany-493334ce5b250010cd55fddfef9d83470b6d0c70.tar.xz gsoc2013-epiphany-493334ce5b250010cd55fddfef9d83470b6d0c70.tar.zst gsoc2013-epiphany-493334ce5b250010cd55fddfef9d83470b6d0c70.zip |
Do not blindly overwrite when downloading a file with the same name than a
* embed/mozilla/ContentHandler.cpp:
* embed/mozilla/EphyHeaderSniffer.cpp:
* embed/mozilla/MozDownload.cpp:
* embed/mozilla/MozDownload.h:
Do not blindly overwrite when downloading a file with the same
name than a local one, append a number after the name.
Fixes (more or less) #12775
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | embed/mozilla/ContentHandler.cpp | 44 | ||||
-rw-r--r-- | embed/mozilla/EphyHeaderSniffer.cpp | 40 | ||||
-rw-r--r-- | embed/mozilla/MozDownload.cpp | 70 | ||||
-rw-r--r-- | embed/mozilla/MozDownload.h | 1 |
5 files changed, 87 insertions, 79 deletions
@@ -1,3 +1,14 @@ +2003-11-28 Xan Lopez <xan@masilla.org> + + * embed/mozilla/ContentHandler.cpp: + * embed/mozilla/EphyHeaderSniffer.cpp: + * embed/mozilla/MozDownload.cpp: + * embed/mozilla/MozDownload.h: + + Do not blindly overwrite when downloading a file with the same + name than a local one, append a number after the name. + Fixes (more or less) #12775 + 2003-11-27 Piers Cornwell <piers@myrealbox.com> * data/glade/prefs-dialog.glade: diff --git a/embed/mozilla/ContentHandler.cpp b/embed/mozilla/ContentHandler.cpp index 7286ba3ff..1ad9095ff 100644 --- a/embed/mozilla/ContentHandler.cpp +++ b/embed/mozilla/ContentHandler.cpp @@ -25,6 +25,7 @@ #include "ContentHandler.h" #include "MozillaPrivate.h" +#include "MozDownload.h" #include "nsCOMPtr.h" #include "nsString.h" @@ -104,47 +105,8 @@ NS_IMETHODIMP GContentHandler::PromptForSaveToFile( const PRUnichar *aSuggestedFileExtension, nsILocalFile **_retval) { - char *path, *download_dir; - - download_dir = eel_gconf_get_string (CONF_STATE_DOWNLOAD_DIR); - if (!download_dir) - { - /* Emergency download destination */ - download_dir = g_strdup (g_get_home_dir ()); - } - - if (!strcmp (download_dir, "Desktop")) - { - if (eel_gconf_get_boolean (CONF_DESKTOP_IS_HOME_DIR)) - { - path = g_build_filename - (g_get_home_dir (), - NS_ConvertUCS2toUTF8 (aDefaultFile).get(), - NULL); - } - else - { - path = g_build_filename - (g_get_home_dir (), "Desktop", - NS_ConvertUCS2toUTF8 (aDefaultFile).get(), - NULL); - } - } - else - { - path = g_build_filename - (gnome_vfs_expand_initial_tilde (download_dir), - NS_ConvertUCS2toUTF8 (aDefaultFile).get(), - NULL); - } - g_free (download_dir); - - nsCOMPtr <nsILocalFile> destFile (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID)); - destFile->InitWithNativePath (nsDependentCString (path)); - g_free (path); - - NS_IF_ADDREF (*_retval = destFile); - return NS_OK; + return BuildDownloadPath (NS_ConvertUCS2toUTF8 (aDefaultFile).get(), + _retval); } #if MOZILLA_SNAPSHOT < 10 diff --git a/embed/mozilla/EphyHeaderSniffer.cpp b/embed/mozilla/EphyHeaderSniffer.cpp index a1e621fad..b6bc1ffb0 100644 --- a/embed/mozilla/EphyHeaderSniffer.cpp +++ b/embed/mozilla/EphyHeaderSniffer.cpp @@ -324,46 +324,10 @@ nsresult EphyHeaderSniffer::PerformSave (nsIURI* inOriginalURI) return NS_OK; } - /* FIXME ask user if overwriting ? */ - /* FIXME: how to inform user of failed save ? */ - download_dir = eel_gconf_get_string (CONF_STATE_DOWNLOAD_DIR); - if (!download_dir) - { - /* Emergency download destination */ - download_dir = g_strdup (g_get_home_dir ()); - } - - if (!strcmp (download_dir, "Desktop")) - { - if (eel_gconf_get_boolean (CONF_DESKTOP_IS_HOME_DIR)) - { - path = g_build_filename - (g_get_home_dir (), - NS_ConvertUCS2toUTF8 (defaultFileName).get(), - NULL); - } - else - { - path = g_build_filename - (g_get_home_dir (), "Desktop", - NS_ConvertUCS2toUTF8 (defaultFileName).get(), - NULL); - } - } - else - { - path = g_build_filename - (gnome_vfs_expand_initial_tilde (download_dir), - NS_ConvertUCS2toUTF8 (defaultFileName).get(), - NULL); - } - g_free (download_dir); - - nsCOMPtr<nsILocalFile> destFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID); - destFile->InitWithNativePath (nsDependentCString (path)); - g_free (path); + nsILocalFile *destFile; + BuildDownloadPath (NS_ConvertUCS2toUTF8 (defaultFileName).get(), &destFile); return InitiateDownload (destFile); } diff --git a/embed/mozilla/MozDownload.cpp b/embed/mozilla/MozDownload.cpp index d4931737c..8e7df243c 100644 --- a/embed/mozilla/MozDownload.cpp +++ b/embed/mozilla/MozDownload.cpp @@ -43,6 +43,9 @@ #include "MozDownload.h" #include "mozilla-download.h" +#include "eel-gconf-extensions.h" +#include "ephy-prefs.h" +#include <libgnomevfs/gnome-vfs-utils.h> #include "nsIExternalHelperAppService.h" #include "nsDirectoryServiceDefs.h" @@ -472,3 +475,70 @@ nsresult InitiateMozillaDownload (nsIDOMDocument *domDocument, nsIURI *sourceURI return rv; } + +static char* +GetFilePath (const char *filename) +{ + char *path, *download_dir; + + download_dir = eel_gconf_get_string (CONF_STATE_DOWNLOAD_DIR); + if (!download_dir) + { + /* Emergency download destination */ + download_dir = g_strdup (g_get_home_dir ()); + } + + if (!strcmp (download_dir, "Desktop")) + { + if (eel_gconf_get_boolean (CONF_DESKTOP_IS_HOME_DIR)) + { + path = g_build_filename + (g_get_home_dir (), + filename, + NULL); + } + else + { + path = g_build_filename + (g_get_home_dir (), "Desktop", + filename, + NULL); + } + } + else + { + path = g_build_filename + (gnome_vfs_expand_initial_tilde (download_dir), + filename, + NULL); + } + g_free (download_dir); + + return path; +} + +nsresult BuildDownloadPath (const char *defaultFileName, nsILocalFile **_retval) +{ + char *path; + int i = 0; + + path = GetFilePath (defaultFileName); + + while (g_file_test (path, G_FILE_TEST_EXISTS)) + { + g_free (path); + + char *tmp_path; + tmp_path = g_strdup_printf ("%s.%d", defaultFileName, ++i); + path = GetFilePath (tmp_path); + g_free (tmp_path); + } + + nsCOMPtr <nsILocalFile> destFile (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID)); + destFile->InitWithNativePath (nsDependentCString (path)); + g_free (path); + + NS_IF_ADDREF (*_retval = destFile); + return NS_OK; +} + diff --git a/embed/mozilla/MozDownload.h b/embed/mozilla/MozDownload.h index 89d20b8c3..930e110b8 100644 --- a/embed/mozilla/MozDownload.h +++ b/embed/mozilla/MozDownload.h @@ -80,6 +80,7 @@ nsresult InitiateMozillaDownload (nsIDOMDocument *domDocument, nsIURI *sourceUri nsILocalFile* inDestFile, const char *contentType, nsIURI* inOriginalURI, MozillaEmbedPersist *embedPersist, nsIInputStream *postData, nsISupports *aCacheKey); +nsresult BuildDownloadPath (const char *defaultFileName, nsILocalFile **_retval); class MozDownload : public nsIDownload, public nsIWebProgressListener |