1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182:
| uses Registry;
type TSteamAccount = packed record Name: string; ID: string; end; PSteamAccount = ^TSteamAccount;
TSteamAccountList = array of PSteamAccount;
function GetSteamAccounts(): TSteamAccountList;
function IsFileInUse(const FileName: string): Boolean; var HFileRes: HFILE; begin Result := false;
if FileExists(FileName) then begin HFileRes := CreateFile(PChar(FileName), GENERIC_READ or GENERIC_WRITE, 0, NIL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); Result := HFileRes = INVALID_HANDLE_VALUE;
if not Result then CloseHandle(HFileRes); end; end;
function CorrectPath(const AValue: string): string; var I: Integer; begin Result := AValue;
if Result <> '' then begin for I := 1 to Length(Result) do if Result[I] = '/' then Result[I] := '\';
if Result[Length(Result)] <> '\' then Result := Result + '\'; end; end;
resourcestring SErrorFileInUse = 'Error #10000'#13#10'Steam.log is already in use.'; SErrorKeyNotFound = 'Error #10001'#13#10'Key not found.'; SErrorCannotOpenKey = 'Error #10002'#13#10'Cannot open key.'; SErrorValueNotFound = 'Error #10003'#13#10'Value not found.'; SErrorResultFormat = 'Error #10004'#13#10'Unknown error!'; const SPos1 = 'CreateSession'; SPos2 = 'Attempting new connection'; SKey = 'Software\Valve\Steam'; SName = 'SteamPath'; var TMP, SteamPath, SteamLog, Name, ID: string; LogFile, Names, IDs: TStringList; Account: PSteamAccount; Found: Boolean; Reg: TRegistry; I, Q: Integer; begin SetLength(Result, 0); FillChar(Result, Length(Result), #0); SteamPath := ''; Found := false;
Reg := TRegistry.Create; try Reg.RootKey := HKEY_CURRENT_USER;
if Reg.KeyExists(SKey) then begin if Reg.OpenKey(SKey, false) then begin if Reg.ValueExists(SName) then begin SteamPath := Reg.ReadString(SName); Found := true; end else raise Exception.Create(SErrorValueNotFound); end else raise Exception.Create(SErrorCannotOpenKey); end else raise Exception.Create(SErrorKeyNotFound); finally Reg.Free; end;
if (Found) and (SteamPath <> '') then begin SteamLog := CorrectPath(SteamPath) + 'steam.log';
if IsFileInUse(SteamLog) then begin raise Exception.Create(SErrorFileInUse);
Exit; end;
LogFile := TStringList.Create; Names := TStringList.Create; IDs := TStringList.Create; try LogFile.LoadFromFile(SteamLog);
for I := 0 to LogFile.Count - 1 do begin Found := false;
if Pos(SPos1, LogFile[I]) > 0 then begin TMP := LogFile[I]; Delete(TMP, 1, Pos('(', TMP)); Delete(TMP, Pos(',', TMP), Length(TMP)); Name := TMP;
if Pos(SPos2, LogFile[I + 1]) > 0 then begin TMP := LogFile[I + 1]; Delete(TMP, 1, Pos('for ', TMP) + 3); ID := 'STEAM_' + TMP;
for Q := 0 to Names.Count - 1 do begin if Names[Q] = Name then Found := true; end;
if not Found then begin Names.Add(Name); IDs.Add(ID); end; end; end; end;
if Names.Count <> IDs.Count then raise Exception.Create(SErrorResultFormat) else begin for I := 0 to Names.Count - 1 do begin New(Account);
Account.Name := Names[I]; Account.ID := IDs[I];
SetLength(Result, Length(Result) + 1); Result[I] := Account; end; end; finally LogFile.Free; Names.Free; IDs.Free; end; end; end;
procedure TfrmMain.FormCreate(Sender: TObject); var AccountList: TSteamAccountList; I: Integer; begin AccountList := GetSteamAccounts;
for I := 0 to Length(AccountList) - 1 do ValueListEditor1.InsertRow(AccountList[I].Name, AccountList[I].ID, true); end; |