зеркало из https://github.com/mozilla/pjs.git
b215194 - autodownload overwrites existing files
- append/insert -# to file names to prevent overwriting.
This commit is contained in:
Родитель
24dfcc033b
Коммит
07c21ef757
|
@ -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) { }
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче