是否自动获得SHA256,以便使用Inno Setup 6.1下载文件? [英] Automate obtaining the SHA256 for a file to download with Inno Setup 6.1?

查看:134
本文介绍了是否自动获得SHA256,以便使用Inno Setup 6.1下载文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DownloadTemporaryFile 的文档对 RequiredSHA256OfFile 参数:

如果设置了 RequiredSHA256OfFile ,它将与下载文件的SHA-256进行比较,如果哈希值不匹配,则会引发异常.

If RequiredSHA256OfFile is set it will compare this to the SHA-256 of the downloaded file and raise an exception if the hashes don't match.

如果发生错误,将引发异常.否则,返回下载的字节数.如果设置了 RequiredSHA256OfFile 并且文件已经下载,则返回0.

An exception will be raised if there was an error. Otherwise, returns the number of bytes downloaded. Returns 0 if RequiredSHA256OfFile is set and the file was already downloaded.

从答案的这里,我确定获取校验和的正确命令行方法是:

From the answer here I have determined that the correct commandline method to obtain the checksum is:

CertUtil -hashfile MSAHelpDocumentationSetup.exe SHA256

这是我添加此特定文件并将其添加到脚本中的方式:

This is how I add adding this particular file to my script:

AddFileForDownload('{#HelpDocSetupURL}', 'HelpDocSetup.exe');

其中扩展到:

procedure AddFileForDownload(Url, FileName: string);
begin
    DownloadPage.Add(Url, FileName, '');
    FilesToDownload := FilesToDownload + '      ' + ExtractFileName(FileName) + #13#10;
    Log('File to download: ' + Url);
end;

有没有办法实现自动化:

Is there way to automate:

  1. 获取我文件的校验和.
  2. 将该校验和缓存为字符串.
  3. 在构建脚本时使用该校验和值.

通过自动执行此任务,它将提供两个好处:

By automating this task it will provide two benefits:

  • 最小化复制/粘贴校验和值时的用户错误.
  • 保持校验和更新为最新状态,而无需用户干预.

在带有Pascal脚本的Inno设置中这可行吗?

Is this feasible in Inno Setup with Pascal Script?

推荐答案

Pascal脚本无法为您提供帮助.您需要在编译时使用该值.因此使用预处理器.您确实可以执行 certutil .但是,在这种情况下,imo可以更轻松地使用PowerShell及其

Pascal Script won't help you. You need the value at the compile time. So using a preprocessor. You can indeed execute the certutil. But imo, in this case, it's easier to use PowerShell and its Get-FileHash cmdlet:

#define GetSHA256OfFile(FileName) \
  Local[0] = AddBackslash(GetEnv("TEMP")) + "sha256.txt", \
  Local[1] = \
    "-ExecutionPolicy Unrestricted -Command """ + \
    "Set-Content -Path '" + Local[0] + "' -NoNewline -Value " + \
    "(Get-FileHash('" + FileName + "')).Hash" + \
    """", \
  Exec("powershell.exe", Local[1], SourcePath, , SW_HIDE), \
  Local[2] = FileOpen(Local[0]), \
  Local[3] = FileRead(Local[2]), \
  FileClose(Local[2]), \
  DeleteFileNow(Local[0]), \
  LowerCase(Local[3])

然后您可以像这样使用它:

And then you can use it like:

AddFileForDownload(
  '{#HelpDocSetupURL}', 'HelpDocSetup.exe', '{#GetSHA256OfFile("HelpDocSetup.exe")}');

您当然需要将第三个参数添加到您的 AddFileForDownload 函数中,并将其传递给 TDownloadWizardPage.Add .您可能还需要向该文件添加路径,以便预处理器可以找到它.

You of course need to add the third parameter to your AddFileForDownload function and pass it to TDownloadWizardPage.Add. You also may need to add a path to the file, so that the preprocessor can find it.

这篇关于是否自动获得SHA256,以便使用Inno Setup 6.1下载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆