我可以在删除文件和目录操作中将filespec传递给错误消息吗? [英] Can I pass the filespec to an Error Message in the Delete files and directories action?

查看:53
本文介绍了我可以在删除文件和目录操作中将filespec传递给错误消息吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在install4j Delete files and directories操作中,如果删除文件文件,则可以定义向用户显示的错误消息.只要消息没有任何参数,这对我来说就很好.

我想知道的是...如果此特定操作确实失败(即,由于某些异常原因而无法删除文件),是否可以将filespec作为参数传递给错误消息?例如,我的错误消息是定义为:

的资源字符串.

"An attempt to delete a critical file has failed {0}"

当我将此资源消息插入到操作的错误消息"属性中时,它看起来像这样:

${ i18n:DeleteCriticalFileFailed( "arg 0" ) }

但是我不知道如何将问题文件的文件规范作为该消息的参数传递.我浏览了install4j帮助文档,特别是此操作的帮助主题,但找不到有关如何完成此操作的任何详细信息.

也许无法完成?但是在这种情况下,我要处理一个必须删除的文件,以确保所生成的(更新)安装中的操作正确性.所以我希望这里有一个解决方案.对我来说,一种选择是使用脚本解决此问题,但总的来说,我更喜欢使用install4j提供的内置操作.

在此先感谢您提供的任何帮助或见解.

解决方案

操作上的错误消息功能是通用的.每个动作都具有这样的错误消息属性,并且该错误消息不采用特定于特定操作的参数.

您可以像这样覆盖标准的删除文件和目录"操作:

public class MyDeleteAction extends DeleteFileAction {
    protected boolean executeForSingleRecursiveFile(Context context, File file, File relativeSourceFile, ProgressAdapter progressAdapter) throws UserCanceledException, IOException {
        boolean success = super.executeForSingleRecursiveFile(context, file, relativeSourceFile, progressAdapter);
        if (!success) {
            Util.showErrorMessage("Could not delete " + file.getPath());
        }
        return success;
    }
}

您还需要在同一包中使用Beaninfo类:

public class MyDeleteActionBeanInfo extends DeleteFileActionBeanInfo {

}

要进行编译,您将需要classpath上的资源\ i4jruntime.jar和bin \ install4j.jar(后者为bean信息基类).然后将类文件添加到安装程序->自定义代码和资源",并通过"[添加按钮]->自定义代码->在自定义代码中搜索操作"在安装程序->屏幕和操作"上添加操作. /p>

In the install4j Delete files and directories action, it's possible to define an Error Message that is displayed to the user, should the deletion of a file file. This is working fine for me, so long as the message does not have any parameters.

What I would like to know is... If this particular action does fail (that is, the file could not be deleted for some unusual reason), is it possible to pass the filespec to the Error Message as a parameter? For example, my error message is a resource string that's defined as:

"An attempt to delete a critical file has failed {0}"

When I insert this resource message into the action's "Error Message" property, it looks like this:

${ i18n:DeleteCriticalFileFailed( "arg 0" ) }

But I don't know how to pass the filespec of the problem file as an argument to this message. I've looked through install4j Help documentation and, in particular the help topic for this action, and I couldn't find any details on how I might accomplish this.

Perhaps it can't be done? But in this case I'm dealing with a file that must be deleted in order to ensure operational correctness in the resulting (update) installation. So I'm hoping there's a solution here. One option for me would be to workaround this problem using a script, but generally speaking I prefer to use the built-in actions that are provided by install4j.

Thanks in advance for any help or insight you can offer.

解决方案

The error message facility on actions is generic. Every action has such an error message property and the error message does not take parameters that are specific to a particular action.

You could override the standard "Delete files and directories" action like this:

public class MyDeleteAction extends DeleteFileAction {
    protected boolean executeForSingleRecursiveFile(Context context, File file, File relativeSourceFile, ProgressAdapter progressAdapter) throws UserCanceledException, IOException {
        boolean success = super.executeForSingleRecursiveFile(context, file, relativeSourceFile, progressAdapter);
        if (!success) {
            Util.showErrorMessage("Could not delete " + file.getPath());
        }
        return success;
    }
}

You also need a Beaninfo class in the same package:

public class MyDeleteActionBeanInfo extends DeleteFileActionBeanInfo {

}

To compile you will need the resources\i4jruntime.jar as well as the bin\install4j.jar (the latter for the bean info base class) on the classpath. Then add the class files to "Installer->Custom Code & Resources" and add the action on "Installer->Screens & Actions" via "[Add button]->Custom Code->Search Action in Custom Code".

这篇关于我可以在删除文件和目录操作中将filespec传递给错误消息吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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