|
226 | 226 | return;
|
227 | 227 | }
|
228 | 228 |
|
229 |
| - filePath = filePath || svc.data.settings.saveFileLocation, backupFileName; |
| 229 | + filePath = filePath || svc.data.settings.saveFileLocation; |
230 | 230 | fs.copyFileSync(filePath, backupFileName);
|
231 | 231 | var fileName = saveName;
|
232 | 232 | var type = 'manual';
|
233 | 233 | if (opts && opts.type) type = opts.type;
|
234 | 234 | var save = new Save(fileName, backupFileName, svc.data.settings.selectedCategory, type);
|
235 | 235 | svc.data.saves.push(save);
|
236 | 236 |
|
| 237 | + // Remove oldest autosaves that are higher then the max autosave count |
| 238 | + // svc.cleanupAutosaves(); |
| 239 | + |
237 | 240 | svc.saveSettings();
|
238 | 241 | if (!filePath) {
|
239 | 242 | svc.showSuccessToast(messages.backupCreated)
|
|
268 | 271 | svc.showSuccessToast(messages.backupRestored);
|
269 | 272 | return;
|
270 | 273 | }
|
271 |
| - |
| 274 | + |
272 | 275 | svc.showSuccessToast(messages.backupDestBackupNotFound);
|
273 | 276 | };
|
274 | 277 |
|
|
384 | 387 | svc.stopAutosave();
|
385 | 388 | }
|
386 | 389 | }, true);
|
| 390 | + |
| 391 | + // svc.cleanupAutosaves = function () { |
| 392 | + // if (!svc.data.settings.autosaveMaxLimit) return; |
| 393 | + // if (svc.data.saves.length === 0) return; |
| 394 | + // var autosaves = _.filter(svc.data.saves, x => x.type === 'auto'); |
| 395 | + // if (autosaves.length > svc.data.settings.autosaveMaxCount) { |
| 396 | + // var toRemove = _(autosaves).sortBy(x => x.time).reverse().slice(parseInt(svc.data.settings.autosaveMaxCount)).value(); |
| 397 | + // for (var i = 0; i < toRemove.length; i++) { |
| 398 | + // var currentSave = toRemove[i]; |
| 399 | + // if (fs.existsSync(currentSave.path)) |
| 400 | + // fs.unlinkSync(currentSave.path); |
| 401 | + // if (!fs.existsSync(currentSave.path)) { |
| 402 | + // svc.data.saves.splice(currentSave, 1); |
| 403 | + // } |
| 404 | + // } |
| 405 | + // console.log(toRemove); |
| 406 | + // } |
| 407 | + // }; |
387 | 408 | };
|
388 | 409 |
|
389 | 410 |
|
|
0 commit comments