3

So I am using InnoSetup 6 which natively supports downloading files from the internet during installation. I have figured out downloading files given a direct link, from this thread Inno Setup: Install file from Internet

However, I can't for the life of me figure out how to download the latest version of a file given a permalink URL. My specific example is to download the Microsoft Hosting package. https://dotnet.microsoft.com/permalink/dotnetcore-current-windows-runtime-bundle-installer

Going to this page automatically downloads the latest package. Inno doesn't like this link (or I don't know how to get Inno to use it) since it doesn't point to the direct file. If I use the direct link (https://download.visualstudio.microsoft.com/download/pr/24847c36-9f3a-40c1-8e3f-4389d954086d/0e8ae4f4a8e604a6575702819334d703/dotnet-hosting-5.0.6-win.exe) this works for obvious reasons.

I'd like to always download the latest, but I'm not sure how to accomplish this. Any suggestions? Adding super basic code being used...

DownloadPage.Clear;
DownloadPage.Add('https://dotnet.microsoft.com/permalink/dotnetcore-current-windows-runtime-bundle-installer', 'dotnet-hosting.exe', '');
DownloadPage.Show;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
S Yuki
  • 85
  • 5

2 Answers2

2

You would have to retrieve the HTML page, find the URL in the HTML code and use it in your download code.

See Inno Setup - HTTP request - Get www/web content

It would be quite unreliable. Microsoft can change the HTML any time.


You better setup your own webpage (web service) that will provide an up to date link to your installer. The web page can even do what I suggested: retrieve the URL from the Microsoft's download page. In case Microsoft changes the HTML, you can fix your web page any time. What you cannot do with the installer.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • Seems like it could get a little complicated, but seeing as the URL for the download page is a permalink I think there's less chance Microsoft will change the HTML. Perhaps something to search for and extract the DirectLink located on the page is not a bad option. Unless I get any other suggestions I may explore this option and update if I get any solutions. Thank you for the suggestion. – S Yuki May 27 '21 at 01:20
  • 1
    *"but seeing as the URL for the download page is a permalink I think there's less chance Microsoft will change the HTML"* – I do not see the connection here. – Again I suggest you create your own web page for that. The web page can even do what I suggested: retrieve the URL from the download page. In case Microsoft changes the HTML, you can fix your web page any time. What you cannot do with the installer. – Martin Prikryl May 27 '21 at 04:48
  • ` there's less chance Microsoft will change the HTML` is an absolutely incorrect statement, this coming from someone with 20+ years on the MS dev stack. Microsoft routinely changes their html and not only that discontinue downloads in favor of the latest and greatest. – Alexander Higgins May 27 '21 at 05:04
  • In fact, people balk at me but the whole `dotnet-core` thing will soon become a thing of the past. I am willing to bet $10,000 MS rebrands core within the two years and when then do all of your links and references to anything "core" related are likely to disappear. – Alexander Higgins May 27 '21 at 05:06
1

Without realizing it you are asking two different question here. That is because these "permalinks" aren't really permalinks but redirects to some dynamic resource that has a link to what you are looking for.

So first, addressing the Microsoft "permalink", you need to realize that under the hood you are accessing a URL that redirects to some page which will point to the latest. Then under the hood, that page invokes a JavaScript function, IF YOU ACCESSING VIA A WEB BROWSER, to download the installer. Note that both the page pointed to and the code to invoke the installer WILL eventually change. In fact, the code itself logs a "warning" when people attempt to download directly:

If you do a view source you'll see:

    <script>
        $(function () {
            recordDownload('.NET', 'runtime-aspnetcore-5.0.6-windows-hosting-bundle-installer');
            window.open("https://download.visualstudio.microsoft.com/download/pr/24847c36-9f3a-40c1-8e3f-4389d954086d/0e8ae4f4a8e604a6575702819334d703/dotnet-hosting-5.0.6-win.exe", "_self");
        });

        function recordManualDownload() {
            ga("send", "event", "Download.Warning", "Direct Link Used", "runtime-aspnetcore-5.0.6-windows-hosting-bundle-installer");
        }
    </script>

So you can download the HTML from this page and use some regex to get the directo downloadlink but beware, the link is going to change every time Microsoft releases a new version. Furthermore, WHEN (not if but when) MS decides to rebrand this entire process might break. So the best you can do here is try to download the html and try parse the download URL from this "permalink"

As an alternative. you can to download the latest DotNet powershell install script as described here.

If possible, execute that script directly. If not look at the function Get-AkaMSDownloadLink within the install script to see how it builds the url to get the latest version. You would probably be better served using that building and using that URL as opposed to attempting to download from some arbitrary HTML code.

Now, onto the second question you might not have realized your were asking is how to automate this for any random installer. The answer is you can't. Some might have a permalink that directly points to the latest but you are always going to find cases like Microsoft. Best you can down is hard code some links in some service, as @martin-prikryl suggested, and when the break update the links in those services.

Alexander Higgins
  • 6,765
  • 1
  • 23
  • 41