在Inno Setup中使用回调显示来自外部解压缩dll的文件名 [英] Using callback to display filenames from external decompression dll in Inno Setup

查看:81
本文介绍了在Inno Setup中使用回调显示来自外部解压缩dll的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最初要求这里,但被要求作为一个单独的问题提交。

Originally asked here, but was asked to submit it as a separate question.

我在C中使用的以下dll编码如下: Inno Setup Installer提取游戏文件。这是游戏的替代安装程序,该游戏最初使用16位安装程序,并且文件从CD-ROM复制。我希望能够使用 InnoTools InnoCallback 显示文件名使用我的dll提取,但是由于这是我第一次涉足C编码,因此我不知道该怎么做。可以在此处找到此功能的示例: http://freearc.org/InnoSetup.aspx

I have the following dll coded in C below that I'm using in an Inno Setup Installer to extract game files. This is a replacement installer for a game which originally used a 16-bit installer and files are copied off a CD-ROM. I'd like to be able to use InnoTools InnoCallback to display the file names extracted using my dll, but as this is my first venture into C coding, I have no idea how to do it. An example of this functionality may be found here: http://freearc.org/InnoSetup.aspx

我希望能够使用外部dll中的文件名设置WizardForm.FilenameLabel.Caption。

I would like to be able to set WizardForm.FilenameLabel.Caption using the file name from my external dll.

我的Inno Setup脚本的相关部分:

Relevant sections of my Inno Setup script:

function VolEx( filename, outputpath: String ): Integer; external 'VolEx@files:volex.dll stdcall';

(DriveLetter是CD-ROM的路径,即 D:\,因此输出当前显示为 D:\world\archive.vol。我的输出目标是 C:\game-path\world\archive\file.ext)

(DriveLetter is the path for the CD-ROM, ie "D:\" so the output currently reads "D:\world\archive.vol". The output I'm aiming for is "C:\game-path\world\archive\file.ext")

procedure VolExtract();
begin
  if not DirExists(WizardDirValue() + '\' + Worlds[w]) then
  begin
    CreateDir(WizardDirValue() + '\' + Worlds[w]);
  end;
  for n := 0 to 3 do begin
    WizardForm.FilenameLabel.Caption := DriveLetter + Worlds[w] + '\' + Reslists[n] + '.vol';

    if VolEx(DriveLetter + Worlds[w] + '\' + Reslists[n] + '.vol', WizardDirValue() + '\' + Worlds[w] + '\' + Reslists[n]) <> 0 then
    begin
      // Handle Fail
      MsgBox(CustomMessage('FileErr'), mbInformation, MB_OK);
      WizardForm.Close;
    end;

VolEx.c(包括blast.c和blast.h,位于此处: https://github.com/madler/zlib/tree/master/contrib/blast

VolEx.c (includes blast.c and blast.h from here: https://github.com/madler/zlib/tree/master/contrib/blast)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <sys/stat.h>
#include <time.h>
#include <utime.h>
#include "blast.h"

#define local static
#define VOLID "RESLIST"

struct inbuf {
    unsigned long left;
    unsigned char *buf;
    unsigned size;
    FILE *in;
};

struct stat statbuf;
time_t mtime;
time_t voltime;
struct utimbuf new_times;

local unsigned inf(void *how, unsigned char **buf)
{
    unsigned len;
    struct inbuf *inb = how;

    len = inb->size > inb->left ? inb->left : inb->size;
    len = fread(inb->buf, 1, len, inb->in);
    inb->left -= len;
    *buf = inb->buf;
    return len;
}

local int outf(void *how, unsigned char *buf, unsigned len)
{
    return fwrite(buf, 1, len, (FILE *)how) != len;
}

#define BUFSIZE 16384   /* must fit in unsigned */

local int extract(char *name, unsigned long len, FILE *in, const char *path, time_t prevtime)
{
    int err;
    FILE *out;
    struct inbuf inb;
    unsigned char buf[BUFSIZE];

    inb.left = len;
    inb.buf = buf;
    inb.size = BUFSIZE;
    inb.in = in;
    mkdir(path);
    char outPath[strlen(path) + 20];
    strcpy(outPath, path);
    strcat(outPath, "\\");
    strcat(outPath, name);
    out = fopen(outPath, "wb");
    if (out == NULL)
        return 2;
    err = blast(inf, &inb, outf, out);
    fclose(out);
    if (stat(outPath, &statbuf) < 0) {
        perror(outPath);
        return 1;
    }
    mtime = statbuf.st_mtime; /* seconds since the epoch */

    new_times.actime = statbuf.st_atime; /* keep atime unchanged */
    new_times.modtime = prevtime;    /* set mtime to current time */
    if (utime(outPath, &new_times) < 0) {
        perror(outPath);
        return 1;
    }
    return err;
}

int __stdcall __declspec(dllexport) VolEx(const char *filename, const char *outputpath)
{
    FILE *in = fopen(filename,"rb");
    unsigned long off, next;
    int err;
    unsigned char head[24];

    if (stat(filename, &statbuf) < 0) {
        perror(filename);
        return 1;
    }
    voltime = statbuf.st_mtime; /* seconds since the epoch */

    if (fread(head, 1, 8, in) != 8 || memcmp(head, VOLID, 8)) {
        /* fprintf(stderr, "not the expected .vol format\n"); */
        return 1;
    }
    off = 8;
    while ((next = fread(head, 1, 24, in)) == 24) {
        off += 24;
        next = head[20] + (head[21] << 8) + ((unsigned long)(head[22]) << 16) +
           ((unsigned long)(head[23]) << 24);

        head[20] = 0;
        err = extract((char *)head, next - off, in, outputpath, voltime);
        if (err) {
            /* fprintf(stderr, "extraction error %d on %s\n", err, head); */
            return 1;
        }
        off = next;
    }
    /* if (next)
        fprintf(stderr, "%lu bytes ignored at the end\n", next); */
    return 0;
}


推荐答案

看看这个例子 InnoTools回调附带的脚本。

Have a look at the example script included with InnoTools Callback.

这非常简单,您只需声明一个这样的过程(同样,假设您使用的是ANSI Inno,则必须为Unicode版本更改某些类型):

It's pretty straightforward, you just declare a procedure like this (again, assuming that you're using ANSI Inno -- some of the types would have to be changed for the Unicode version):

[Code]
type
    TMyCallback = procedure(Filename: PChar);

function WrapMyCallback(Callback: TMyCallback; ParamCount: Integer): LongWord;
    external 'WrapCallback@files:innocallback.dll stdcall';

procedure DoSomethingInTheDll(Blah: Integer; Foo: String; ...; Callback: LongWord);
    external 'DoSomethingInTheDll@files:mydll.dll stdcall';

procedure MyCallback(Filename: PChar);
begin
    // do whatever, eg. update the filename label
end;

// wherever you're about to call your DLL
var Callback : LongWord;
// ...
    Callback := WrapMyCallback(@MyCallback, 1); // 1 parameter
    // pass the callback to your DLL either via a dedicated function
    // or as a parameter of your existing function
    DoSomethingInTheDll(blah, foo, ..., Callback);

在DLL方面:

typedef void (__stdcall *MyCallback)(const char *filename);

然后可以声明 MyCallback 类型的变量在函数参数中调用它们,然后像​​调用它们是本机C函数一样调用它们,它将在Inno脚本中运行代码。

You can then declare variables of type MyCallback in function parameters and then call them as if they were native C functions, and it will run the code inside the Inno script.

void __stdcall __declspec(dllexport)
    DoSomethingInTheDll(int blah, const char *foo, ..., MyCallback callback)
{
    // ...
    callback(foo);
}

这篇关于在Inno Setup中使用回调显示来自外部解压缩dll的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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