如何在Inno Setup的INI文件中写入无盘符安装路径
解决Inno Setup中INI路径移除盘符的问题
问题场景
当前Inno Setup的[INI]段配置如下:
[INI] Filename: "{app}\\game.ini"; Section: "Nancy Data"; Key: "CDDrive1"; \\ String: "{drive:{src}}\\"; Flags: createkeyifdoesntexist Filename: "{app}\\game.ini"; Section: "Nancy Data"; Key: "CDDrive2"; \\ String: "{drive:{src}}\\"; Flags: createkeyifdoesntexist Filename: "{app}\\game.ini"; Section: "Nancy Data"; Key: "HDDrive"; \\ String: "{drive:{src}}"; Flags: createkeyifdoesntexist Filename: "{app}\\game.ini"; Section: "Nancy Data"; Key: "IDPath"; \\ String: "{app}\\Нэнси Дрю. Секреты могут убивать"; Flags: createkeyifdoesntexist Filename: "{app}\\game.ini"; Section: "Nancy Data"; Key: "CifTreePath"; \\ String: "{app}\\Нэнси Дрю. Секреты могут убивать\\ciftree\\"; \\ Flags: createkeyifdoesntexist
生成的INI文件中,IDPath和CifTreePath会自动带上盘符:
[Nancy Data] CDDrive1=C: CDDrive2=C: HDDrive=C: IDPath=C:\\Program Files (x86)\\My Program\\Нэнси Дрю. Секреты могут убивать CifTreePath=C:\\Program Files (x86)\\My Program\\Нэнси Дрю. Секреты могут убивать\\ciftree\\
需要实现无盘符的路径写入。
解决方案
利用Inno Setup内置的{pathwithoutdrive:...}常量,该常量会自动剥离路径中的盘符部分。只需修改[INI]段中对应行的{app}为{pathwithoutdrive:{app}}即可:
[INI] Filename: "{app}\\game.ini"; Section: "Nancy Data"; Key: "CDDrive1"; \\ String: "{drive:{src}}\\"; Flags: createkeyifdoesntexist Filename: "{app}\\game.ini"; Section: "Nancy Data"; Key: "CDDrive2"; \\ String: "{drive:{src}}\\"; Flags: createkeyifdoesntexist Filename: "{app}\\game.ini"; Section: "Nancy Data"; Key: "HDDrive"; \\ String: "{drive:{src}}"; Flags: createkeyifdoesntexist Filename: "{app}\\game.ini"; Section: "Nancy Data"; Key: "IDPath"; \\ String: "{pathwithoutdrive:{app}}\\Нэнси Дрю. Секреты могут убивать"; Flags: createkeyifdoesntexist Filename: "{app}\\game.ini"; Section: "Nancy Data"; Key: "CifTreePath"; \\ String: "{pathwithoutdrive:{app}}\\Нэнси Дрю. Секреты могут убивать\\ciftree\\"; \\ Flags: createkeyifdoesntexist
可选调整
如果不需要路径开头的反斜杠,可以结合{trimleft:...}进一步处理,将String部分修改为:
String: "{trimleft:{pathwithoutdrive:{app}},1}\\Нэнси Дрю. Секреты могут убивать"; Flags: createkeyifdoesntexist
最终生成的路径会变为Program Files (x86)\\My Program\\Нэнси Дрю. Секреты могут убивать。
内容的提问来源于stack exchange,提问作者livingsamurai
相关产品推荐
相关产品推荐

