【问题标题】:Inno Setup image downloadInno 安装程序图像下载
【发布时间】:2011-05-22 11:17:52
【问题描述】:

我正在使用 Inno Setup Compiler(Pascal 脚本)。 我的表单有一个图像对象 (TBitmapImage),我想提供从 Web URL 获得的动态图像。是否可以在 Inno Setup 脚本中静默下载图像(或其他类型的文件)?

【问题讨论】:

    标签: download inno-setup pascal


    【解决方案1】:

    我会写一个从网上下载文件的小Win32程序,比如

    program dwnld;
    
    uses
      SysUtils, Windows, WinInet;
    
    const
      PARAM_USER_AGENT = 1;
      PARAM_URL = 2;
      PARAM_FILE_NAME = 3;
    
    function DownloadFile(const UserAgent, URL, FileName: string): boolean;
    const
      BUF_SIZE = 4096;
    var
      hInet, hURL: HINTERNET;
      f: file;
      buf: PByte;
      amtc: cardinal;
      amti: integer;
    begin
      result := false;
      hInet := InternetOpen(PChar(UserAgent), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
      try
        hURL := InternetOpenUrl(hInet, PChar(URL), nil, 0, 0, 0);
        try
          GetMem(buf, BUF_SIZE);
          try
            FileMode := fmOpenWrite;
            AssignFile(f, FileName);
            try
              Rewrite(f, 1);
              repeat
                InternetReadFile(hURL, buf, BUF_SIZE, amtc);
                BlockWrite(f, buf^, amtc, amti);
              until amtc = 0;
              result := true;
            finally
              CloseFile(f);
            end;
          finally
            FreeMem(buf);
          end;
        finally
          InternetCloseHandle(hURL);
        end;
      finally
        InternetCloseHandle(hInet);
      end;
    end;
    
    begin
    
      ExitCode := 0;
    
      if ParamCount < 3 then
      begin
        MessageBox(0,
          PChar(Format('%s: This program requires three command-line arguments.',
            [ExtractFileName(ParamStr(0))])),
          PChar(ExtractFileName(ParamStr(0))),
          MB_ICONERROR);
        Exit;
      end;
    
      if FileExists(ParamStr(PARAM_FILE_NAME)) then
        DeleteFile(PChar(ParamStr(PARAM_FILE_NAME)));
    
      if DownloadFile(ParamStr(PARAM_USER_AGENT), ParamStr(PARAM_URL),
          ParamStr(PARAM_FILE_NAME)) then
        ExitCode := 1;
    
    end.
    

    该程序采用三个命令行参数:要发送到 Web 服务器的 UserAgent(可以是任何东西,例如“MyApp Setup Utility”)、Internet 上文件的 URL 以及正在创建的文件。不要忘记将参数括在引号(")内。如果下载失败,程序的退出代码为 0,如果下载成功,则为 1。

    然后,在您的 Inno Setup 脚本中,您可以这样做

    [Files]
    Source: "dwnld.exe"; DestDir: "{app}"; Flags: dontcopy
    
    [Code]
    
    function InitializeSetup: boolean;
    var
      ResultCode: integer;
    begin
      ExtractTemporaryFile('dwnld.exe');
      if Exec(ExpandConstant('{tmp}\dwnld.exe'),
          ExpandConstant('"{AppName} Setup Utility" "http://privat.rejbrand.se/sample.bmp" "{tmp}\bg.bmp"'),
          '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode) then
        if ResultCode = 1 then    
          (* Now you can do something with the file ExpandConstant('{tmp}\bg.bmp') *);
    end;
    

    不幸的是,我不知道在运行时您可以通过什么方式更改WizardImageFile...

    【讨论】:

      【解决方案2】:

      实际上可以使用InnoTools Downloader从网上下载几乎任何东西。

      【讨论】:

        【解决方案3】:

        Inno setup 没有为此提供任何内置函数,但是,您可以使用为您完成这项工作的批处理文件来执行此操作。

        1) 下载命令行 URL 资源下载器,例如 - http://www.chami.com/free/url2file_wincon.html

        关于如何使用它的一些提示 - http://www.chami.com/tips/windows/062598W.html

        2) 将其打包到您的安装程序中

        3) 创建一个批处理文件,调用 url2file.exe 并将您的图像提取到应用程序目录中

        4) 在 Inno Setup 安装脚本的初始化设置命令中调用这个批处理文件。

        5) 随时随地使用该图像!

        ps - 如果您在设置中使用图像,请检查是否允许加载不同的图像。我不确定。 如果您有任何其他问题,请告诉我

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-04-11
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多