b215194 - autodownload overwrites existing files

- append/insert -# to file names to prevent overwriting.
This commit is contained in:
ben%bengoodger.com 2003-08-06 20:11:59 +00:00
Родитель 24dfcc033b
Коммит 07c21ef757
2 изменённых файлов: 16 добавлений и 1 удалений

Просмотреть файл

@ -14,7 +14,7 @@
# The Original Code is Mozilla.org Code.
#
# The Initial Developer of the Original Code is
# Doron Rosenberg.
# Ben Goodger.
# Portions created by the Initial Developer are Copyright (C) 2001
# the Initial Developer. All Rights Reserved.
#

Просмотреть файл

@ -132,6 +132,21 @@ nsUnknownContentTypeDialog.prototype = {
try {
result = prefs.getComplexValue(kDownloadFolderPref, Components.interfaces.nsILocalFile);
result.append(aDefaultFile);
// Since we're automatically downloading, we don't get the file picker's
// logic to check for existing files, so we need to do that here.
while (result.exists()) {
var parts = /.+-(\d+)(\..*)?$/.exec(result.leafName);
if (parts) {
result.leafName = result.leafName.replace(/((\d+)\.)/,
function (str, p1, part, s) {
return (parseInt(part) + 1) + ".";
});
}
else {
result.leafName = result.leafName.replace(/\./, "-1$&");
}
}
}
catch (e) { }