Posts: 1,026
Threads: 245
Joined: Jul 2022
08-12-2024, 11:24 AM
(This post was last modified: 08-12-2024, 11:25 AM by Davider.)
Is there a wrapper in LA for downloading files with a progress bar? Something similar to the progress bar in QM
string url = "https://www.quickmacros.com/quickmac.exe";
string file = folders.Desktop + pathname.getName(url);
try
{
internet.http.Get(url, file);
}
catch (Exception e1)
{
print.warning($"Failed to download. {e1.ToStringWithoutStack()}");
return;
}
print.it("downloaded");
QM code:
str localfile="$desktop$\quickmac.ex_"
IntGetFile "https://www.quickmacros.com/quickmac.exe" localfile 16 0 1
ren- localfile "$desktop$\quickmac.exe"
Posts: 12,058
Threads: 140
Joined: Dec 2002
if (!internet.http.Get(url, dontWait: true).Download(file)) { print.it("canceled"); return; }
Posts: 1,026
Threads: 245
Joined: Jul 2022
Thank you.
Is there a simple way to modify the descriptive text in the dialog box?
https://i.ibb.co/GRKGcFS/A.png
Posts: 12,058
Threads: 140
Joined: Dec 2002
// script "download with progress.cs"
string url = "https://www.quickmacros.com/quickmac.exe";
url = "https://www.libreautomate.com/LibreAutomateSetup.exe";
string file = folders.Downloads + pathname.getName(url);
try {
#if !true //standard dialog
if (!internet.http.Get(url, dontWait: true).Download(file)) { print.it("canceled"); return; }
#else //custom dialog
if (!internet.http.Get(url, dontWait: true).Download2(file)) { print.it("canceled"); return; }
#endif
}
catch (Exception e1) {
print.warning($"Failed to download. {e1.ToStringWithoutStack()}");
return;
}
print.it("downloaded");
static class MyInternetExt {
/// <inheritdoc cref="ExtInternet.Download(System.Net.Http.HttpResponseMessage, string, Action{ProgressArgs}, CancellationToken)"/>
public static bool Download2(this System.Net.Http.HttpResponseMessage t, string file, CancellationToken cancel = default) {
t.EnsureSuccessStatusCode();
long size = t.Content.Headers.ContentLength ?? 0;
string filename = pathname.getName(t.RequestMessage.RequestUri.AbsolutePath);
string _DialogText(long bytes) => $"{filename}\n{bytes / 1048576d:0.#} MB";
var pd = dialog.showProgress(size == 0, "TODO: change this text", _DialogText(size));
Action<ProgressArgs> progress = pa => {
if (!pd.IsOpen) { pd = null; throw new OperationCanceledException(); }
if (size > 0) pd.Send.Progress(pa.Percent);
else pd.Send.ChangeText2(_DialogText(pa.Current), resizeDialog: false);
};
try {
if (!t.Download(file, progress, cancel)) return false;
}
catch (OperationCanceledException) { return false; }
finally { pd?.Send.Close(); }
return true;
}
}
Posts: 1,026
Threads: 245
Joined: Jul 2022