source: trunk/SunriseChatCoreUtils.pas

Last change on this file was 13, checked in by george, 16 years ago

Opraveno: Načítání seznamu síťových adaptérů na Linuxu.
Přidáno: Úpravy pro potřeby ladění problému s nepřijímáním UDP paketů.

  • Property svn:executable set to *
File size: 2.8 KB
Line 
1unit SunriseChatCoreUtils;
2
3interface
4
5uses
6 Windows, SysUtils, WinSock;
7
8type
9 TArrayOfString = array of string;
10
11 function LocalHostName: string;
12 function GetUserName: string;
13 function Explode(Separator: Char; Data: string): TArrayOfString;
14 function SecondsIdle: Cardinal;
15 function GetWindowsVersionStr: string;
16
17implementation
18
19var
20 GetLastInputInfo2: function(var plii: TLastInputInfo): BOOL; stdcall;
21 LibHandle: HInst; //dll handle
22
23function GetWindowsVersionStr: string;
24begin
25 case Win32Platform of
26 1: case Win32MajorVersion of
27 4: case Win32MinorVersion of
28 0: Result:= '95';
29 10: Result:= '98';
30 90: Result:= 'Me';
31 end;
32 end;
33 2: case Win32MajorVersion of
34 4: case Win32MinorVersion of
35 0: Result:= 'NT 4.0';
36 end;
37 5: case Win32MinorVersion of
38 0: Result:= '2000';
39 1: Result:= 'XP';
40 2: Result:= 'Server 2003';
41 end;
42 6: case Win32MinorVersion of
43 0: Result := 'Vista';
44 end
45 end;
46 end;
47 Result:= 'Windows ' + Result;
48end;
49
50function GetUserName: string;
51const
52 MaxUsernameLength = 256;
53var
54 L : LongWord;
55begin
56 L := MaxUsernameLength + 2;
57 SetLength(Result, L);
58 if Windows.GetUserName(PChar(Result), L) and (L > 0) then
59 SetLength(Result, StrLen(PChar(Result))) else Result := '';
60end;
61
62function Explode(Separator: Char; Data: string): TArrayOfString;
63begin
64 SetLength(Result, 0);
65 while Pos(Separator, Data) > 0 do begin
66 SetLength(Result, Length(Result) + 1);
67 Result[High(Result)] := Copy(Data, 1, Pos(Separator, Data) - 1);
68 Delete(Data, 1, Pos(Separator, Data));
69 end;
70 SetLength(Result, Length(Result) + 1);
71 Result[High(Result)] := Data;
72end;
73
74function SecondsIdle: Cardinal;
75var
76 liInfo: TLastInputInfo;
77begin
78 // Try to load indirectly function GetLastInputInfo for compatibility with Win9x
79 LibHandle := LoadLibrary('user32.dll');
80 if LibHandle = 0 then begin
81 GetLastInputInfo2 := nil;
82 end else begin
83 @GetLastInputInfo2 := GetProcAddress(LibHandle,'GetLastInputInfo');
84 if (@GetLastInputInfo2 = nil) then FreeLibrary(LibHandle);
85 end;
86
87 // Only WinNT+
88 if Assigned(GetLastInputInfo2) then begin
89 liInfo.cbSize := SizeOf(TLastInputInfo) ;
90 GetLastInputInfo2(liInfo) ;
91 Result := (GetTickCount - liInfo.dwTime) DIV 1000;
92 end else Result:= 0;
93// MainWindow.RichEdit1.Lines.Add(IntToStr(Result));
94// SysUtils.Beep;
95// Result:= IdleTrackerGetLastTickCount div 1000;
96// Button1.Caption:= IntToStr(Result);
97// Result:= 0;
98end;
99
100function LocalHostName: String;
101var
102 Buf: array[0..255] of Char;
103begin
104// if gethostname(@Buf, Sizeof(Buf)) <> 0 then
105// raise Exception.Create('LocalHostName not available');
106// Result := PChar(@Buf);
107 Result := '';
108end;
109
110end.
Note: See TracBrowser for help on using the repository browser.