本文介绍了使用pascal(innosetup)获取文件的最新更新时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在innosetup脚本的卸载部分中,我想添加一项检查,以查看特定文件的上次更新日期时间是否发生在最近的10分钟之内.

In the uninstall portion of an innosetup script, I'd like to add a check to see if a specific file's last update datetime occured within the last 10 mins.

有人知道为此兼容innosetup的pascal代码吗?

Does anyone know the innosetup compatable pascal code for this?

推荐答案

您可以使用Windows API函数GetFileAttributesEx来获取最后的修改日期.将其放在您的[CODE]部分中应该可以正常工作:

You can use the Windows API function GetFileAttributesEx to get the last modification date. Putting this in your [CODE] section should work:

const
    GetFileExInfoStandard = $0;

type
    FILETIME = record
      LowDateTime:  DWORD;
      HighDateTime: DWORD;
    end;

    WIN32_FILE_ATTRIBUTE_DATA = record
      FileAttributes: DWORD;
      CreationTime:   FILETIME;
      LastAccessTime: FILETIME;
      LastWriteTime:  FILETIME;
      FileSizeHigh:   DWORD;
      FileSizeLow:    DWORD;
    end;

    SYSTEMTIME = record
      Year:         WORD;
      Month:        WORD;
      DayOfWeek:    WORD;
      Day:          WORD;
      Hour:         WORD;
      Minute:       WORD;
      Second:       WORD;
      Milliseconds: WORD;
    end;

function GetFileAttributesEx (
    FileName:            string;
    InfoLevelId:         DWORD;
    var FileInformation: WIN32_FILE_ATTRIBUTE_DATA
    ): Boolean;
external 'GetFileAttributesExA@kernel32.dll stdcall';

function FileTimeToSystemTime(
    FileTime:        FILETIME;
    var SystemTime:  SYSTEMTIME
    ): Boolean;
external 'FileTimeToSystemTime@kernel32.dll stdcall';

您可以通过如下修改安装程序项目的InitializeWizard函数来对其进行测试:

You can test it by modifying the InitializeWizard function of your installer project like this:

procedure InitializeWizard();
    var
      FileInformation: WIN32_FILE_ATTRIBUTE_DATA;
      SystemInfo: SYSTEMTIME;
begin
    GetFileAttributesEx(
        'c:\ntldr',
        GetFileExInfoStandard ,
        FileInformation);

    FileTimeToSystemTime(
        FileInformation.LastWriteTime,
        SystemInfo);

    MsgBox(
        format(
            '%4.4d-%2.2d-%2.2d',
            [SystemInfo.Year, SystemInfo.Month, SystemInfo.Day]),
        mbInformation, MB_OK);
end;

在我的系统(XP SP3)上,消息框显示:2008-08-04

On my system (XP SP3), the messagebox says: 2008-08-04

这篇关于使用pascal(innosetup)获取文件的最新更新时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 05:34
查看更多