将所有设置重置为其默认值

发布于 2024-09-15 00:54:22 字数 736 浏览 5 评论 0原文

有没有办法将 Inno Setup 中的所有设置“重置”为默认值?

我想在我的设置中添加 重置选项 按钮,单击该按钮会将所有选项设置为相同的值,就好像用户从未更改任何内容,而只是单击下一步下一步安装

但请注意,这些值与编译时默认值略有不同,例如AppDir可以默认为DefaultDirNamewizardForm .PrevAppDir。所以我希望所有选项都默认为动态默认值,对于AppDir来说是:

if wizardForm.PrevAppDir <> '' then
    result := wizardForm.PrevAppDir
else
    result := '{#SetupSetting("DefaultDirName")}';

我希望你明白我想要完成的任务。如果应用程序已安装,则将所有选项设置为上次安装的值,如果应用程序未安装,则将它们设置为默认值。

我知道安装程序在启动时完成了所有这些操作,但我想添加一个按钮,它将用户所做的所有更改(例如在 wpSelectComponents 中)恢复为其安装启动默认值。我怎样才能做到这一点?

Is there any way to "reset" all setup settings in Inno Setup into their default values?

I want to add Reset options button into my setup, and clicking that button would set all the options to the same value as if the user never changed anything, but was clicking just Next, Next, Install.

But please note that those values ale slightly different than compile-time default values, as for example AppDir can default to DefaultDirName or wizardForm.PrevAppDir. So I want all the options to default to dynamic defaults, which for AppDir is:

if wizardForm.PrevAppDir <> '' then
    result := wizardForm.PrevAppDir
else
    result := '{#SetupSetting("DefaultDirName")}';

I hope you understand what I want to accomplish. If the application is already installed, then set all options to the last-installation values, if the app is not installed, then set them to default values.

I know the setup does all of this at it's startup, but I want to add a button, which would revert all the changes user made (eg. in wpSelectComponents) to their setup-startup defaults. How can I do that?

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

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

发布评论

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

评论(1

早乙女 2024-09-22 00:54:22

所以我在[Code]中解决了这个问题。所有信息都可以通过 WizardForm 全局对象访问,因此当第一次显示配置页面时,您可以将这些值保存到变量中。然后,每当您需要重置配置时,只需再次通过WizardForm恢复所有设置即可。我不会在这里粘贴整个代码,因为它有点长(172 LOC),但只有 AppDir 部分:

[Code]
var storedAppDir : string;
    hasAppDir : boolean;

procedure OnAppDir;
begin
    if not hasAppDir then begin
        storedAppDir := wizardForm.DirEdit.Text;
        hasAppDir := true;
    end;
end;

procedure RestoreAppDir;
begin
    if hasAppDir then begin
        wizardForm.DirEdit.Text := storedAppDir;
    end;
end;

procedure InitializeDefaults;
begin
    //hasUserInfo := false;
    hasAppDir := false;
    //hasComponents := false;
    //hasProgramGroup := false;
    //hasTasks := false;
end;

procedure RestoreDefaults;
begin
    //RestoreUserInfo;
    RestoreAppDir;
    //RestoreComponents;
    //RestoreProgramGroup;
    //RestoreTasks;
end;

procedure DefaultsCurPageChanged(CurPageID : integer);
begin
    case CurPageID of
        //wpUserInfo: OnUserInfo;
        wpSelectDir: OnAppDir;
        //wpSelectComponents: OnComponents;
        //wpSelectProgramGroup: OnProgramGroup;
        //wpSelectTasks: OnTasks;
    end;
end;

procedure InitializeWizard;
begin
    InitializeDefaults;
end;

procedure CurPageChanged(CurPageID : Integer);
begin
    DefaultsCurPageChanged(CurPageID);
end;

当您需要重置所有配置时,只需调用 RestoreDefaults。当然,这不会恢复任何自定义向导选项/页面。但您可以自己轻松添加额外的存储/恢复代码。

So I've solved this in [Code]. All the information is accessible through WizardForm global object, so when the configuration pages are shown for the first time, you save those values into your variables. Then, whenever you need to reset the configuration, you just restore all the settings through WizardForm again. I won't paste the whole code here, as it's kinda long (172 LOC), but there is just the AppDir part:

[Code]
var storedAppDir : string;
    hasAppDir : boolean;

procedure OnAppDir;
begin
    if not hasAppDir then begin
        storedAppDir := wizardForm.DirEdit.Text;
        hasAppDir := true;
    end;
end;

procedure RestoreAppDir;
begin
    if hasAppDir then begin
        wizardForm.DirEdit.Text := storedAppDir;
    end;
end;

procedure InitializeDefaults;
begin
    //hasUserInfo := false;
    hasAppDir := false;
    //hasComponents := false;
    //hasProgramGroup := false;
    //hasTasks := false;
end;

procedure RestoreDefaults;
begin
    //RestoreUserInfo;
    RestoreAppDir;
    //RestoreComponents;
    //RestoreProgramGroup;
    //RestoreTasks;
end;

procedure DefaultsCurPageChanged(CurPageID : integer);
begin
    case CurPageID of
        //wpUserInfo: OnUserInfo;
        wpSelectDir: OnAppDir;
        //wpSelectComponents: OnComponents;
        //wpSelectProgramGroup: OnProgramGroup;
        //wpSelectTasks: OnTasks;
    end;
end;

procedure InitializeWizard;
begin
    InitializeDefaults;
end;

procedure CurPageChanged(CurPageID : Integer);
begin
    DefaultsCurPageChanged(CurPageID);
end;

And when you need to reset all the configuration, just call RestoreDefaults. Of course, this won't restore any custom wizard options/pages. But you can add additional storing/restoring code easily yourself.

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