Inno Setup shorten file path string to fit FilenameLabel

杀马特。学长 韩版系。学妹 提交于 2019-12-19 04:14:51

问题


On the WizardForm.InstallingPage, the WizardForm.FilenameLabel automatically truncates the string containing the file path, to include the drive letter at the beginning, followed by the maximum displayable path, truncating from the top level of the path, to fit the size of the label, so that the file name is always shown e.g. C:\...\LongFilePathNameWithMultipleSubDirectories\Filename.ext.

I have looked at the Length, Pos, Copy and ExtractFileDrive String Functions, but given that there are an almost infinite number path and file name possibilities, as the user can choose any installation path they wish, I am struggling to work out a way to show the maximum possible length of the path, without truncating the file name.

I think I need a function like Pos that returns the number of matches and the index for every \ it finds, which would mean I could use Length between each index to determine where to Copy from, but I haven't been able to find any way of doing this.


回答1:


The MinimizePathName() function is available to scripting, it takes a string & a font and returns a reformatted string that will fit in a given number of pixels in the given font.




回答2:


You can use MinimizePathName function.

Something like this:

YourLabelControl.Caption :=
   MinimizePathName(
     'C:\First Folder\Second Folder\Third Folder\Filename.ext',
     YourLabelControl.Font, YourLabelControl.Width);

(untested)



来源:https://stackoverflow.com/questions/45084729/inno-setup-shorten-file-path-string-to-fit-filenamelabel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!