Can I pass the filespec to an Error Message in the Delete files and directories action?

北慕城南 提交于 2019-12-24 07:15:49

问题


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.


回答1:


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".



来源:https://stackoverflow.com/questions/16487880/can-i-pass-the-filespec-to-an-error-message-in-the-delete-files-and-directories

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!