Reset all setup settings to their default values
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开发者_JAVA百科 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?
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.
精彩评论