Quick.SysInfo.pas 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. { ***************************************************************************
  2. Copyright (c) 2016-2018 Kike Pérez
  3. Unit : Quick.SysInfo
  4. Description : System Info functions
  5. Author : Kike Pérez
  6. Version : 1.1
  7. Created : 17/05/2018
  8. Modified : 08/09/2018
  9. This file is part of QuickLib: https://github.com/exilon/QuickLib
  10. ***************************************************************************
  11. Licensed under the Apache License, Version 2.0 (the "License");
  12. you may not use this file except in compliance with the License.
  13. You may obtain a copy of the License at
  14. http://www.apache.org/licenses/LICENSE-2.0
  15. Unless required by applicable law or agreed to in writing, software
  16. distributed under the License is distributed on an "AS IS" BASIS,
  17. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. See the License for the specific language governing permissions and
  19. limitations under the License.
  20. *************************************************************************** }
  21. unit Quick.SysInfo;
  22. interface
  23. {$IFDEF FPC}
  24. {$modeSwitch advancedRecords}
  25. {$ENDIF}
  26. uses
  27. SysUtils,
  28. {$IFNDEF FPC}
  29. {$IFDEF ANDROID}
  30. System.IOUtils,
  31. Androidapi.Helpers,
  32. {$ENDIF}
  33. {$ENDIF}
  34. Quick.Commons;
  35. type
  36. TSystemInfo = record
  37. private
  38. fAppName : string;
  39. fAppVersion : string;
  40. fAppPath : string;
  41. fHostName : string;
  42. fUserName : string;
  43. fOSVersion : string;
  44. fCPUCores : Integer;
  45. function GetOSVersion : string;
  46. public
  47. procedure GetInfo;
  48. property AppName : string read fAppName write fAppName;
  49. property AppVersion : string read fAppVersion write fAppVersion;
  50. property AppPath : string read fAppPath write fAppPath;
  51. property HostName : string read fHostName write fHostName;
  52. property UserName : string read fUserName write fUserName;
  53. property OsVersion : string read fOSVersion write fOSVersion;
  54. property CPUCores : Integer read fCPUCores write fCPUCores;
  55. end;
  56. var
  57. SystemInfo : TSystemInfo;
  58. implementation
  59. { TSystemInfo }
  60. procedure TSystemInfo.GetInfo;
  61. begin
  62. {$IFNDEF NEXTGEN}
  63. fAppName := ExtractFilenameWithoutExt(ParamStr(0));
  64. {$ELSE}
  65. fAppName := JStringToString(SharedActivityContext.getPackageName);
  66. {$ENDIF}
  67. fAppVersion := GetAppVersionFullStr;
  68. {$IFNDEF NEXTGEN}
  69. fAppPath := ExtractFilePath(ParamStr(0));
  70. {$ELSE}
  71. fAppPath := TPath.GetDocumentsPath;
  72. {$ENDIf}
  73. fUserName := Trim(GetLoggedUserName);
  74. fHostName := GetComputerName;
  75. fOSVersion := GetOSVersion;
  76. fCPUCores := CPUCount;
  77. end;
  78. function TSystemInfo.GetOSVersion: string;
  79. begin
  80. Result := {$IFDEF FPC}{$I %FPCTARGETOS%}+'-'+{$I %FPCTARGETCPU%}{$ELSE}TOSVersion.ToString{$ENDIF};
  81. end;
  82. initialization
  83. SystemInfo.GetInfo;
  84. end.