From d912c740f34c9e88c0a197ac18933ff0f29a3c35 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Sat, 14 May 2011 19:34:32 +0200 Subject: [PATCH] Installer: Early check whether the installation directory is writable This avoids the user from going through all the settings again in case a directory was chosen that cannot be written to in setup's very last copy step. Signed-off-by: Sebastian Schuberth --- share/WinGit/helpers.inc.iss | 22 ++++++++++++++++++++++ share/WinGit/install.iss | 21 +++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/share/WinGit/helpers.inc.iss b/share/WinGit/helpers.inc.iss index b6f4b299..769818f1 100644 --- a/share/WinGit/helpers.inc.iss +++ b/share/WinGit/helpers.inc.iss @@ -141,3 +141,25 @@ begin Result:=(Pos(Component,Value)>0); end; end; + +// Checks whether the specified directory can be created and written to. +// Note that the created dummy file is not explicitly deleted here, so that +// needs to be done as part of the uninstall process. +function IsDirWritable(DirName:String):Boolean; +var + FileName:String; +begin + Result:=False; + + if not ForceDirectories(DirName) then begin + Exit; + end; + + FileName:=DirName+'\setup.ini'; + + if not SetIniBool('Dummy','Writable',true,FileName) then begin + Exit; + end; + + Result:=GetIniBool('Dummy','Writable',false,FileName); +end; diff --git a/share/WinGit/install.iss b/share/WinGit/install.iss index 965c6766..c9a5a5be 100644 --- a/share/WinGit/install.iss +++ b/share/WinGit/install.iss @@ -690,6 +690,14 @@ procedure CurPageChanged(CurPageID:Integer); var i:Integer; begin + if CurPageID=wpSelectDir then begin + if not IsDirWritable(WizardDirValue) then begin + // If the default directory is not writable, choose another default that most likely is. + // This will be checked later again when the user clicks "Next". + WizardForm.DirEdit.Text:=ExpandConstant('{localappdata}\{#APP_NAME}'); + end; + end; + // Uncheck the console font option by default. if CurPageID=wpSelectComponents then begin for i:=0 to WizardForm.ComponentsList.Items.Count-1 do begin @@ -714,6 +722,19 @@ var begin Result:=True; + if CurPageID=wpSelectDir then begin + if not IsDirWritable(WizardDirValue) then begin + MsgBox( + 'The specified installation directory does not seem to be writable. ' + + + 'Please choose another directory or restart setup as a user with sufficient permissions.' + , mbCriticalError + , MB_OK + ); + Result:=False; + Exit; + end; + end; + if (PuTTYPage<>NIL) and (CurPageID=PuTTYPage.ID) then begin Result:=RdbSSH[GS_OpenSSH].Checked or (RdbSSH[GS_Plink].Checked and FileExists(EdtPlink.Text)); -- 2.11.4.GIT