杉宫竹苑工作室

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2304|回复: 0

Inno Setup 实现获取原程序的安装目录的父目录

[复制链接]
发表于 2017-1-9 16:38:31 | 显示全部楼层 |阅读模式

正式会员享受无限制浏览网站功能和高速网盘下载,赶快加入本站吧!

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. [Setup]
  2. AppName=Adobe Premiere 6.5 Patch
  3. AppVerName=Adobe Premiere 4.0.0.58版本
  4. AppPublisher=Adobe Premiere 6.5
  5. ;DefaultDirName={reg:HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Adobe Premiere 6.5,InstallLocation}
  6. ;默认安装目录改为从代码段获取,以便在注册表值为空时可以做更多的处理,
  7. '如给出提示并终止安装,或使用默认目录(示例脚本为默认目录)
  8. DefaultDirName={code:MyConst}
  9. OutputDir=C:\Users\Public\Desktop
  10. OutputBaseFilename=Patch
  11. SolidCompression=yes
  12. Compression=lzma/ultra64
  13. //此压缩为7z极限压缩算法
  14. DisableDirPage=no
  15. DisableProgramGroupPage=yes
  16. DirExistsWarning=no
  17. Uninstallable=no
  18. WizardImageFile=C:\Users\Administrator\Desktop\Office2007Gray.bmp
  19. SetupIconFile=C:\Users\Administrator\Desktop\dd.ico
  20. RestartIfNeededByRun=no
  21. VersionInfoVersion=2016.10.2
  22. VersionInfoTextVersion=2016.10.2
  23. ShowLanguageDialog=auto
  24. ;安装密码
  25. ;版本号
  26. DisableReadyMemo=yes
  27. ;如果设置为 yes,无显示准备安装向导页
  28. [Files]
  29. ; Add the Visual Style resource contains resources used for skinning,
  30. ; you can also use Microsoft Visual Styles (*.msstyles) resources.
  31. Source: {#ExtendDir}\ISSkin\Styles\Office2007.cjstyles; DestDir: {tmp}; Flags: dontcopy
  32. Source: "C:\Users\Administrator\Desktop\aaa\*"; DestDir: "{app}"; Flags: overwritereadonly ignoreversion
  33. ;Source: "C:\Users\Administrator\Desktop\kara.lic";DestDir: "{app}"; Flags: overwritereadonly ignoreversion
  34. ;修改为目标目录从 Code 段获取,即为 App 目录的父目录
  35. Source: "C:\Users\Administrator\Desktop\kara.lic";DestDir: "{code:ParentPath}"; Flags: overwritereadonly ignoreversion

  36. [Code]
  37. //获取注册表中的安装目录
  38. Function MyConst(Path: String): String;
  39. begin
  40.   Result := ExpandConstant('{pf}') + ‘Adobe Premiere 6.5’;  //预定义一个默认安装目录
  41.   RegQueryStringValue(HKLM,‘SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Adobe Premiere 6.5','InstallLocation',Path);
  42.   if Path <> '' then
  43.      //Result := ExtractFileDrive(path);   //提取根目录
  44.      Result := path;
  45. end;

  46. //获取父目录函数
  47. Function ParentPath(Path: String): String;
  48. var
  49.   i,k: Integer;
  50.   substr: string;
  51. begin
  52.   //传入的 Path 参数为空的话,赋值为 App 值
  53.   if Path = '' then Path := ExpandConstant('{app}');
  54.   substr := '\';  //定义要被查找的字符
  55.   Result := Path;  //备份 Path,以避免截取子字符串后 Path 值改变
  56.   //如果 Result 最后一个字符是 substr 的话,删除最后一个字符
  57.   if copy(Result,Length(Result),1) = substr then begin
  58.      Result := copy(Result,1,Length(Result) - 1);
  59.   end;
  60.   //获取 substr 在 Result  中的首个位置值
  61.   i := Pos(substr,Result);
  62.   //循环截取子字符串,并获取 substr 在子字符串 Result  中的位置值,记录 substr 在原字符串 Path 中的最后位置值
  63.   while i > 0 do
  64.      begin
  65.      k := k + i;   //记录每次截取和查找后 substr 在原字符串 Path 中的位置值
  66.      Result := Copy(Result,i + 1,Length(Result) - i);  //截取找到位置 i + 1 到 Result 最后字符的子字符串  
  67.      i := Pos(substr,Result);   //再次获取 substr 在新 Result  中的首个位置值
  68.   end;
  69.   //如果找到 substr 值,获取 path 中第一个字符到最后 substr 位置为止的子字符串
  70.   if k > 0 then Result := Copy(Path,1,k);
  71. end;

  72. //在选择安装目录页中单击下一步时显示获取父目录函数的测试结果,实际使用时请删除
  73. function NextButtonClick(CurPageID : Integer): Boolean;  
  74. begin
  75.   Result := true;
  76.   if CurPageID = wpSelectDir then begin
  77.      msgbox(ExpandConstant('{app}'), mbInformation, MB_OK);
  78.      msgbox(ParentPath(ExpandConstant('{app}')), mbInformation, MB_OK);
  79.   end;
  80. end;
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SgzyStudio

GMT+8, 2024-5-19 18:08 , Processed in 0.104214 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表