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 /embed/mozilla/MozDownload.cpp | |
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
Diffstat (limited to 'embed/mozilla/MozDownload.cpp')
-rw-r--r-- | embed/mozilla/MozDownload.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
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; +} + |