Download / Error Message
-
I was just doing some work on my own downloader and I realised you don't need to do this check. What you need to do is only run the extraction if
this.data.success == true
.So you would do something like this.
if (this.data.finished) { if (this.data.success) // extract the zip file else // show an error message }
-
@d-healey I just woke up had the same thought, thanks!
-
@d-healey so that solved it, and I also added a command to delete the incomplete .zip file if the downloaded is aborted either by the user or lost connection. This prevents a duplicate file being created with a '(2)' suffix in the filename which will be inconsistent with the filename given to the extraction process, and ensures the correct file is unzipped.
However.... this does not take into account the app being closed before the download is completed (for whatever reason, user shutdown etc). In that scenario the incomplete zip file is left there. The Server.download command doesn't overwrite the file; a duplicate will be created again as above.
So, is there a way to check if that file exists before the download kicks in and, if it does, delete it?
-
@DanH isnt it as simple as doing this before you begin the download...:
// get dir first...then... e = dir.getChildFile("SAMPLES.zip"); if(e.isFile()) { // it exists so delete it... }
-
@Lindon maybe, let me try! I always forget about the isFile option
-
@Lindon So as I thought might happen it checks if the file exists, deletes it, but also executes the download at the same time and seems to delete it's own file perhaps.... The app downloads but not to a visible file and therefore can't unzip it when finished.
I've had to put the check in the startDownload function which occurs before my original code above. Is there a way to separate the check and the download process? Maybe another function....
inline function startDownload() { Engine.showYesNoWindow("SELECT FOLDER", "SELECT WHERE YOU WANT TO STORE THE SAMPLES", function(response) { if (response) { FileSystem.browseForDirectory(downloadsFolder, function(dir) { if (isDefined(dir) && dir.isDirectory()) { Server.setBaseURL("https://mtfunkyURL"); var f = dir.getChildFile("SAMPLES.zip"); if(f.isFile()) { f.deleteFileOrDirectory(); download = Server.downloadFile(url, {}, f, downloadCallback); } else { download = Server.downloadFile(url, {}, f, downloadCallback); } } }); } }); }
-
@DanH why are you putting the check in the startDownload function?
Your program logic needs to reflect what you want to do
- start the program (init processing)
- check if theres an old zip on the machine (checkRemoveOldZip())
- do your download...
-
@Lindon because there's one button which opens the dialogue for the user to select the location and then executes the download. So I'm trying to shoehorn the check into there. I can't do the check until the dir is defined as you pointed out but in this case its also the same function as the download...
-
@DanH - but you always want to delete old zips dont you?
-
@Lindon yes but there's no way of knowing where they are until dir is defined. which is the same function as the download. Can you think of a way of separating these? I'm trying with a timer.... ...... ok hang on... just exported it and the behaviour is different to within Hise and I thiiiink it might work with what I posted above after all... which would be nice!
Thanks for your help :)