diff --git a/innosetup.iss b/innosetup.iss index 8ba5ab9e..a409439d 100644 --- a/innosetup.iss +++ b/innosetup.iss @@ -70,18 +70,83 @@ Filename: "{tmp}\vc_redist.x64.exe"; StatusMsg: "Installing Visual C++ Redistrib Filename: "{app}\console.bat"; Description: {cm:LaunchProgram,ODM Console}; Flags: nowait postinstall skipifsilent [Code] + +function GetShortPath(const LongPath: string): string; +var + ResultCode: Integer; + TmpFileName: string; + ExecStdout: AnsiString; + Parameters: string; +begin + + // Create LongPath folder + if not ForceDirectories(LongPath) then begin + Result := LongPath; + Exit; + end; + + TmpFileName := ExpandConstant('{tmp}') + '\short_result.txt'; + Parameters := '-Command "(New-Object -ComObject Scripting.FileSystemObject).GetFolder(''' + LongPath + ''').ShortPath | Out-File -FilePath ''' + TmpFileName + ''' -Encoding ASCII"'; + + // Execute the PowerShell command and save the output to the TmpFileName + if Exec('powershell.exe', Parameters, '', 0, ewWaitUntilTerminated, ResultCode) then + begin + // Read the output from the TmpFileName + if LoadStringFromFile(TmpFileName, ExecStdout) then begin + Result := Trim(ExecStdout); + end + else begin + Result := LongPath; + end; + + DeleteFile(TmpFileName); + // Delete the folder + if not RemoveDir(LongPath) then begin + Result := LongPath; + Exit; + end; + + end + else + begin + Result := LongPath; + end; +end; + + +function NextButtonClick(CurPageID: Integer): Boolean; +var + Dir: string; +begin + if CurPageID = wpSelectDir then + begin + // Get the selected directory + Dir := WizardForm.DirEdit.Text; + + // Check if the path contains spaces + if Pos(' ', Dir) > 0 then + begin + // Get the short path name + Dir := GetShortPath(Dir); + // Set the selected directory to the short path name + WizardForm.DirEdit.Text := Dir; + end; + end; + Result := True; +end; + function VC2019RedistNeedsInstall: Boolean; -var +var Version: String; begin if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64', 'Version', Version) then begin - // Is the installed version at least 14.14 ? + // Is the installed version at least 14.14 ? Log('VC Redist Version check : found ' + Version); Result := (CompareStr(Version, 'v14.14.26429.03')<0); end - else + else begin // Not even an old version installed Result := True;