View Single Post
  #845  
Old 14.07.2019, 12:39
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,533
Default

Quote:
Originally Posted by SMS View Post
If file to be downloaded is called foo.zip, but the download directory already contains a subdirectory called foo, then foo.zip shouldn't be downloaded (for example by using link.setEnabled(false);).
Code:
// Disable all download link(s) of an archive, if the download folder contains a sub-folder with archive name
// Trigger: A Download Started

var archive = link.getArchive();
var archiveLinks = archive && getPath(link.getPackage().getDownloadFolder() + "/" + archive.getName()).exists() ? archive.getDownloadLinks() : [];

archiveLinks.forEach(function(link) {
    link.setEnabled(false);
    // var partFile = getPath(link.getDownloadPath() + ".part");
    // if (partFile.exists()) partFile.delete();
})
Reply With Quote