Skip to content

Commit 349a336

Browse files
committed
improved fpc linux compatibility
1 parent 691f6d2 commit 349a336

16 files changed

+500
-51
lines changed

Diff for: Quick.AppService.pas

+2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ interface
4141
{$ENDIF}
4242

4343
uses
44+
{$IFDEF MSWINDOWS}
4445
Windows,
46+
{$ENDIF}
4547
SysUtils,
4648
{$IFNDEF FPC}
4749
WinSvc,

Diff for: Quick.Commons.pas

+65-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Author : Kike Pérez
88
Version : 1.4
99
Created : 14/07/2017
10-
Modified : 29/03/2018
10+
Modified : 16/05/2018
1111
1212
This file is part of QuickLib: https://github.com/exilon/QuickLib
1313
@@ -44,6 +44,9 @@ interface
4444
{$ENDIF MSWINDOWS}
4545
{$IFDEF FPC}
4646
Quick.Files,
47+
{$IFDEF LINUX}
48+
FileInfo,
49+
{$ENDIF}
4750
{$ELSE}
4851
IOUtils,
4952
{$ENDIF}
@@ -104,6 +107,9 @@ TDirectoryHelper = record helper for TDirectory
104107
{$ENDIF}
105108

106109
{$IFDEF FPC}
110+
{$IFDEF LINUX}
111+
UINT = cardinal;
112+
{$ENDIF}
107113
PLASTINPUTINFO = ^LASTINPUTINFO;
108114
tagLASTINPUTINFO = record
109115
cbSize: UINT;
@@ -163,7 +169,9 @@ EShellError = class(Exception);
163169
//checks if is a console app
164170
function IsConsole : Boolean;
165171
//checks if compiled in debug mode
172+
{$ENDIF}
166173
function IsDebug : Boolean;
174+
{$IFDEF MSWINDOWS}
167175
//checks if running as a service
168176
function IsService : Boolean;
169177
//gets number of seconds without user interaction (mouse, keyboard)
@@ -197,12 +205,10 @@ EShellError = class(Exception);
197205
//Upper case for first letter
198206
function Capitalize(s: string): string;
199207
function CapitalizeWords(s: string): string;
200-
{$IFDEF MSWINDOWS}
201208
//returns current logged user
202209
function GetLoggedUserName : string;
203210
//returns computer name
204211
function GetComputerName : string;
205-
{$ENDIF}
206212
//Changes incorrect delims in path
207213
function NormalizePathDelim(const cPath : string; const Delim : Char) : string;
208214
//Removes last segment of a path
@@ -211,16 +217,18 @@ EShellError = class(Exception);
211217
function ParamFindSwitch(const Switch : string) : Boolean;
212218
//gets value for a switch if exists
213219
function ParamGetSwitch(const Switch : string; var cvalue : string) : Boolean;
214-
{$IFDEF MSWINDOWS}
220+
//returns app name (filename based)
221+
function GetAppName : string;
215222
//returns app version (major & minor)
216223
function GetAppVersionStr: string;
217224
//returns app version full (major, minor, release & compiled)
218225
function GetAppVersionFullStr: string;
219-
{$ENDIF}
220226
//UTC DateTime to Local DateTime
221227
function UTCToLocalTime(GMTTime: TDateTime): TDateTime;
222228
//Local DateTime to UTC DateTime
223229
function LocalTimeToUTC(LocalTime : TDateTime): TDateTime;
230+
//return GTM time string
231+
function DateTimeToGMT(aDate : TDateTime) : string;
224232
//count number of digits of a Integer
225233
function CountDigits(anInt: Cardinal): Cardinal; inline;
226234
//save stream to file
@@ -231,7 +239,7 @@ EShellError = class(Exception);
231239
//get last error message
232240
function GetLastOSError : String;
233241
{$ENDIF}
234-
{$IFDEF FPC}
242+
{$IF DEFINED(FPC) AND DEFINED(MSWINDOWS)}
235243
function GetLastInputInfo(var plii: TLastInputInfo): BOOL;stdcall; external 'user32' name 'GetLastInputInfo';
236244
{$ENDIF}
237245

@@ -432,6 +440,7 @@ function IsConsole: Boolean;
432440
Result := False;
433441
{$ENDIF CONSOLE}
434442
end;
443+
{$ENDIF}
435444

436445
function IsDebug: Boolean;
437446
begin
@@ -442,6 +451,7 @@ function IsDebug: Boolean;
442451
{$ENDIF DEBUG}
443452
end;
444453

454+
{$IFDEF MSWINDOWS}
445455
function IsService : Boolean;
446456
begin
447457
//only working with my Quick.AppService unit
@@ -550,7 +560,6 @@ function IsLike(cText, Pattern: string) : Boolean;
550560
match : Boolean;
551561
wildcard : Boolean;
552562
CurrentPattern : Char;
553-
aux : string;
554563
begin
555564
Result := False;
556565
wildcard := False;
@@ -572,7 +581,6 @@ function IsLike(cText, Pattern: string) : Boolean;
572581

573582
if wildcard then
574583
begin
575-
aux := Copy(Pattern,i+1,Pattern.Length);
576584
n := Pos(Copy(Pattern,i+1,Pattern.Length),cText);
577585
if (n > i) or (Pattern.Length = i) then
578586
begin
@@ -611,8 +619,8 @@ function CapitalizeWords(s: string): string;
611619
end;
612620
end;
613621

614-
{$IFDEF MSWINDOWS}
615622
function GetLoggedUserName : string;
623+
{$IFDEF MSWINDOWS}
616624
const
617625
cnMaxUserNameLen = 254;
618626
var
@@ -625,8 +633,16 @@ function GetLoggedUserName : string;
625633
SetLength( sUserName, dwUserNameLen );
626634
Result := sUserName;
627635
end;
636+
{$ENDIF}
637+
{$IF DEFINED(FPC) AND DEFINED(LINUX)}
638+
begin
639+
Result := GetEnvironmentVariable('USERNAME');
640+
end;
641+
642+
{$ENDIF}
628643

629644
function GetComputerName : string;
645+
{$IFDEF MSWINDOWS}
630646
var
631647
dwLength: dword;
632648
begin
@@ -635,6 +651,12 @@ function GetComputerName : string;
635651
if not Windows.GetComputerName(pchar(result), dwLength) then Result := 'Not detected!';
636652
Result := pchar(result);
637653
end;
654+
{$ENDIF}
655+
{$IF DEFINED(FPC) AND DEFINED(LINUX)}
656+
begin
657+
Result := GetEnvironmentVariable('COMPUTERNAME');
658+
end;
659+
638660
{$ENDIF}
639661

640662
function NormalizePathDelim(const cPath : string; const Delim : Char) : string;
@@ -729,8 +751,13 @@ function ParamGetSwitch(const Switch : string; var cvalue : string) : Boolean;
729751
end;
730752

731753

732-
{$IFDEF MSWINDOWS}
754+
function GetAppName : string;
755+
begin
756+
Result := ExtractFilenameWithoutExt(ParamStr(0));
757+
end;
758+
733759
function GetAppVersionStr: string;
760+
{$IFDEF MSWINDOWS}
734761
var
735762
Rec: LongRec;
736763
ver : Cardinal;
@@ -743,8 +770,18 @@ function GetAppVersionStr: string;
743770
end
744771
else Result := '';
745772
end;
773+
{$ENDIF}
774+
{$IF DEFINED(FPC) AND DEFINED(LINUX)}
775+
var
776+
version : TProgramVersion;
777+
begin
778+
if GetProgramVersion(version) then Result := Format('%d.%d', [version.Major, version.Minor])
779+
else Result := '';
780+
end;
781+
{$ENDIF}
746782

747783
function GetAppVersionFullStr: string;
784+
{$IFDEF MSWINDOWS}
748785
var
749786
Exe: string;
750787
Size, Handle: DWORD;
@@ -788,6 +825,14 @@ function GetAppVersionFullStr: string;
788825
end;
789826
end;
790827
{$ENDIF}
828+
{$IF DEFINED(FPC) AND DEFINED(LINUX)}
829+
var
830+
version : TProgramVersion;
831+
begin
832+
if GetProgramVersion(version) then Result := Format('%d.%d.%d.%d', [version.Major, version.Minor, version.Revision, version.Build])
833+
else Result := '';
834+
end;
835+
{$ENDIF}
791836

792837
function UTCToLocalTime(GMTTime: TDateTime): TDateTime;
793838
begin
@@ -807,6 +852,16 @@ function LocalTimeToUTC(LocalTime : TDateTime): TDateTime;
807852
{$ENDIF}
808853
end;
809854

855+
function DateTimeToGMT(aDate : TDateTime) : string;
856+
var
857+
FmtSettings : TFormatSettings;
858+
begin
859+
FmtSettings.DateSeparator := '-';
860+
FmtSettings.TimeSeparator := ':';
861+
FmtSettings.ShortDateFormat := 'YYYY-MM-DD"T"HH:NN:SS.ZZZ" GMT"';
862+
Result := DateTimeToStr(aDate,FmtSettings);
863+
end;
864+
810865
function CountDigits(anInt: Cardinal): Cardinal; inline;
811866
var
812867
cmp: Cardinal;

0 commit comments

Comments
 (0)