From 96f0c0f9e6a4afbe7455b5c4567d40a25270a3a2 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 ff187bf5..0377dc52 100644 --- a/share/WinGit/helpers.inc.iss +++ b/share/WinGit/helpers.inc.iss @@ -60,3 +60,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 b5d1de30..1abcd13f 100644 --- a/share/WinGit/install.iss +++ b/share/WinGit/install.iss @@ -698,6 +698,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 @@ -723,6 +731,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