From fb5fe4f31dce92934ea16e87799716194d18fa79 Mon Sep 17 00:00:00 2001 From: Xan Lopez Date: Wed, 11 Feb 2004 19:46:15 +0000 Subject: Put the serial numbers in duplicated filenames just before the last dot so * embed/mozilla/MozDownload.cpp: Put the serial numbers in duplicated filenames just before the last dot so we won't confuse apps like file-roller. --- embed/mozilla/MozDownload.cpp | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'embed/mozilla') diff --git a/embed/mozilla/MozDownload.cpp b/embed/mozilla/MozDownload.cpp index 66b7077e8..b8c0f1833 100644 --- a/embed/mozilla/MozDownload.cpp +++ b/embed/mozilla/MozDownload.cpp @@ -568,18 +568,38 @@ GetFilePath (const char *filename) nsresult BuildDownloadPath (const char *defaultFileName, nsILocalFile **_retval) { char *path; - int i = 0; path = GetFilePath (defaultFileName); - while (g_file_test (path, G_FILE_TEST_EXISTS)) + if (g_file_test (path, G_FILE_TEST_EXISTS)) { - g_free (path); + int i = 1; + char *dot_pos, *serial = NULL; + GString *tmp_path; + gssize position; - char *tmp_path; - tmp_path = g_strdup_printf ("%s.%d", defaultFileName, ++i); - path = GetFilePath (tmp_path); - g_free (tmp_path); + dot_pos = g_strrstr (defaultFileName, "."); + if (dot_pos) + { + position = dot_pos - defaultFileName; + } + else + { + position = strlen (defaultFileName); + } + tmp_path = g_string_new (NULL); + + do { + g_free (path); + g_string_assign (tmp_path, defaultFileName); + serial = g_strdup_printf ("(%d)", i++); + g_string_insert (tmp_path, position, serial); + g_free (serial); + path = GetFilePath (tmp_path->str); + + } while (g_file_test (path, G_FILE_TEST_EXISTS)); + + g_string_free (tmp_path, TRUE); } nsCOMPtr destFile (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID)); -- cgit v1.2.3