使用 pascal (innosetup) 获取文件的最后更新时间

发布于 2024-07-17 06:23:02 字数 108 浏览 5 评论 0原文

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

有谁知道 innosetup 兼容的 pascal 代码吗?

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.

Does anyone know the innosetup compatable pascal code for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

水波映月 2024-07-24 06:23:02

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

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 '[email protected] stdcall'; 

function FileTimeToSystemTime(
    FileTime:        FILETIME; 
    var SystemTime:  SYSTEMTIME
    ): Boolean; 
external '[email protected] stdcall'; 

您可以通过修改安装程序项目的 InitializeWizard 函数来测试它,如下所示:

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

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 '[email protected] stdcall'; 

function FileTimeToSystemTime(
    FileTime:        FILETIME; 
    var SystemTime:  SYSTEMTIME
    ): Boolean; 
external '[email protected] stdcall'; 

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;

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

趁年轻赶紧闹 2024-07-24 06:23:02

目前支持此功能的唯一方法是使用 DLL 并将其链接到您的卸载。

您必须编写具有您想要的功能的 DLL。

默认的 INNOSetup 安装有示例向您展示如何调用 DLL。 之后应该很简单。

只要会写一个DLL就可以了。

哈特哈,
瑞安.

At the moment the only way to support this would be to use a DLL and link it to your uninstall.

You will have to write the DLL that has the functionality your want.

The default INNOSetup install has examples showing you how to call DLLs. After that it should be simple.

As long as you can write a DLL.

HTH,
Ryan.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文