I wrote a function to do this in Delphi:
Code:
function GetSteamID(): String;
var
Reg: TRegistry;
Input: Integer;
Beginning: Boolean;
TextLine, SteamPath: String;
begin
try
// Init our classes.
Reg := TRegistry.Create;
// Obtain steam path.
Reg.RootKey := HKEY_CURRENT_USER;
Reg.OpenKey('Software\Valve\Steam\', false);
SteamPath := Reg.ReadString('SteamPath');
// Copy the file to prevent IO error.
CopyFile(PChar(SteamPath + '/Steam.log'), PChar(SteamPath + '/Steam2.log'), False);
// Read the last entry containing a steamid.
Input := FileOpen (SteamPath + '/Steam2.log', 0);
FileSeek(Input, 0, 2);
repeat
ReadBack(Input, TextLine, Beginning);
if Pos('for ', TextLine) <> 0 then
begin
// Delete all the crap and keep the steamid.
Delete(TextLine, 1, Pos('for ', TextLine) + 3);
Result := 'STEAM_' + TextLine;
// Free.
Reg.Free;
FileClose(Input);
DeleteFile(SteamPath + '/Steam2.log');
Exit;
end;
until Beginning;
// Free.
Result := '0';
Reg.Free;
FileClose(Input);
DeleteFile(SteamPath + '/Steam2.log');
except
Result := '0';
end;
end;
This is the ReadBack function I use:
Code:
procedure ReadBack(const F: Integer; var Line: String; var Beginning: Boolean);
const
MAXLINELENGTH = 256;
var
Current, Before: LongInt;
Buffer: array [0..MAXLINELENGTH] of Char;
P: PChar;
begin
Current := FileSeek(F, 0, 1);
Before := Current - MAXLINELENGTH;
if Before < 0 then
Before := 0;
FileSeek (F, Before, 0);
FileRead (F, Buffer, Current - Before);
Buffer[Current - Before] := #0;
P := StrRScan(Buffer, #10);
if P = nil then
begin
Line := StrPas(Buffer);
FileSeek(F, 0, 0);
Beginning := True
end
else
begin
Line := StrPas (p + 1);
FileSeek (F, Before + LongInt(P) - LongInt(@Buffer), 0);
Beginning := False
end;
if Length(Line) > 0 then
if Line[Length (Line)] = #13 then
begin
SetLength (Line, Length(Line) - 1)
end
end;