Per the last comment on having only (copy) for the first one

Signed-off-by: Ido Green <greenido@gmail.com>
This commit is contained in:
Ido Green 2018-10-08 11:11:29 -07:00 committed by Morris Jobke
parent 48d74482c1
commit 313aee91ca
No known key found for this signature in database
GPG Key ID: FE03C3A163FEDE68
1 changed files with 19 additions and 5 deletions

View File

@ -2295,25 +2295,39 @@
targetPathAndName = targetPathAndName.replace(/(?=\.[^.]+$)/g, " (copy " + fileNumber + ")");
}
else {
// check if we have other files with _x and the same name
// Check if we have other files with 'copy X' and the same name
let maxNum = 1;
if (self.files !== null) {
leftPartOfName = leftPartOfName.replace("/", "");
leftPartOfName = leftPartOfName.replace(/\(copy\)/,"");
leftPartOfName = leftPartOfName.replace(/\(copy \d+\)/,"");
// find the last file with the number extention and add one to the new name
for (let j = 0; j < self.files.length; j++) {
const cName = self.files[j].name;
if (cName.indexOf(leftPartOfName) > -1) {
let cFileNumber = cName.match(/\(copy (\d+)\)/);
if (cFileNumber && parseInt(cFileNumber[1]) >= maxNum) {
maxNum = parseInt(cFileNumber[1]) + 1;
if (cName.indexOf("(copy)") > 0) {
targetPathAndName = targetPathAndName.replace(/ \(copy\)/,"");
if (maxNum == 1) {
maxNum = 2;
}
}
else {
let cFileNumber = cName.match(/\(copy (\d+)\)/);
if (cFileNumber && parseInt(cFileNumber[1]) >= maxNum) {
maxNum = parseInt(cFileNumber[1]) + 1;
}
}
}
}
targetPathAndName = targetPathAndName.replace(/ \(copy \d+\)/,"");
}
// Create the new file name with _x at the end
targetPathAndName = targetPathAndName.replace(/(?=\.[^.]+$)/g, " (copy " + maxNum +")");
// Start from 2 per a special request of the 'standard'
let extntionName = " (copy " + maxNum +")";
if (maxNum == 1) {
extntionName = " (copy)";
}
targetPathAndName = targetPathAndName.replace(/(?=\.[^.]+$)/g, extntionName);
}
}
}