从文件中读取字符串并提供选择安装的选项

时间:2016-05-03 23:39:43

标签: inno-setup pascalscript

我想制作Steam备份安装程序。但是,Steam允许用户创建多个库文件夹,这使得安装变得困难。

我想要执行一些任务。

  1. 安装程序应识别来自注册表的路径,以识别Steam的安装位置。
  2. 从注册表打开文件

    生成的路径
    X:\Steam\config\config.vdf
    

    并读取"BaseInstallFolder_1""BaseInstallFolder_2""BaseInstallFolder_3"等的值。

    config.vdf的示例:

    "NoSavePersonalInfo"        "0"
    "MaxServerBrowserPingsPerMin"       "0"
    "DownloadThrottleKbps"      "0"
    "AllowDownloadsDuringGameplay"      "0"
    "StreamingThrottleEnabled"      "1"
    "AutoUpdateWindowStart"     "-1"
    "AutoUpdateWindowEnd"       "-1"
    "LastConfigstoreUploadTime"     "1461497849"
    "BaseInstallFolder_1"       "E:\\Steam_GAMES"
    
  3. 文件config.vdf生成的路径引入DirEdit

  4. 如果用户在不同位置有多个指向该文件夹的路径,则通过DirTreeView或Radiobuttons选择选项。

    它应该如何:

    enter image description here

  5. 我知道如何识别Steam路径

    WizardForm.DirEdit.Text := ExpandConstant('{reg:HKLM\SOFTWARE\Valve\Steam,InstallPath|{pf}\Steam}')+ '\steamapps\common\gamename';
    

    但是很难执行其他任务

    提前感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

解析config.vdf文件:

代码可能如下:

function ParseSteamConfig(FileName: string; var Paths: TArrayOfString): Boolean;
var
  Lines: TArrayOfString;
  I: Integer;
  Line: string;
  P: Integer;
  Key: string;
  Value: string;
  Count: Integer;
begin
  Result := LoadStringsFromFile(FileName, Lines);

  Count := 0;

  for I := 0 to GetArrayLength(Lines) - 1 do
  begin
    Line := Trim(Lines[I]);
    if Copy(Line, 1, 1) = '"' then
    begin
      Delete(Line, 1, 1);
      P := Pos('"', Line);
      if P > 0 then
      begin
        Key := Trim(Copy(Line, 1, P - 1));
        Delete(Line, 1, P);
        Line := Trim(Line);
        Log(Format('Found key "%s"', [Key]));

        if (CompareText(
              Copy(Key, 1, Length(BaseInstallFolderKeyPrefix)),
              BaseInstallFolderKeyPrefix) = 0) and
           (Line[1] = '"') then
        begin
          Log(Format('Found base install folder key "%s"', [Key]));
          Delete(Line, 1, 1);
          P := Pos('"', Line);
          if P > 0 then
          begin
            Value := Trim(Copy(Line, 1, P - 1));
            StringChange(Value, '\\', '\');
            Log(Format('Found base install folder "%s"', [Value]));
            Inc(Count);
            SetArrayLength(Paths, Count);
            Paths[Count - 1] := Value;
          end;
        end;
      end;
    end;
  end;
end;