Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Beta/D2Bridge Framework/D2Bridge.API.Mail.pas
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ interface
{$IFDEF HAS_UNIT_SYSTEM_THREADING}
System.Threading,
{$ENDIF}
IdSMTP, IdSSLOpenSSL, IdMessage, IdExplicitTLSClientServerBase, IdAttachmentFile, idText,
IdSMTP, IdSSLOpenSSL, IdMessage, IdExplicitTLSClientServerBase, IdAttachmentFile, IdText,
D2Bridge.Interfaces, Prism.Server.HTTP.Commom
{$IFDEF FMX}

Expand Down Expand Up @@ -375,4 +375,4 @@ procedure TD2BridgeAPIMail.SetSubject(const Value: string);
FSubject:= Value;
end;

end.
end.
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,21 @@

{$I D2Bridge.inc}

unit D2Bridge.AppConfig.Version;
unit D2Bridge.APPConfig.Version;

interface

uses
Classes, SysUtils, IniFiles, TypInfo,
{$IFDEF MSWINDOWS}
Windows,
{$ENDIF}
{$IFDEF LINUX}
baseunix,
linux,
{$ENDIF}
D2Bridge.Interfaces;


type
TD2BridgeAppConfigVersion = class(TInterfacedPersistent, ID2BridgeAPPConfigVersion)
private
Expand All @@ -68,23 +71,34 @@ TD2BridgeAppConfigVersion = class(TInterfacedPersistent, ID2BridgeAPPConfigVers
property Minor: Integer read GetMinor write SetMinor;
property Release: Integer read GetRelease write SetRelease;
property VersionStr: string read GetVersionStr write SetVersionStr;

end;


implementation


function GetExecutableVersion: string;
{$IFDEF MSWINDOWS}
var
VerInfoSize, VerHandle: DWORD;
VerBuffer: Pointer;
FixedInfo: PVSFixedFileInfo;
FileName: array[0..MAX_PATH - 1] of Char;
{$ENDIF}
{$IFDEF LINUX}
var
FileName: string;
VersionFile: TextFile;
VersionLine: string;
FileStream: TFileStream;
Buffer: array[0..255] of Byte;
BytesRead: Integer;
VersionStr: string;
Major, Minor, Release, Build: Integer;
{$ENDIF}
begin
{$IFDEF MSWINDOWS}
Result := '0.0.0.0';

// Pega o caminho do m�dulo atual (EXE ou DLL)
// Pega o caminho do módulo atual (EXE ou DLL)
if GetModuleFileName(HInstance, FileName, MAX_PATH) = 0 then
Exit;

Expand All @@ -107,9 +121,63 @@ function GetExecutableVersion: string;
finally
FreeMem(VerBuffer);
end;
{$ENDIF}

{$IFDEF LINUX}
Result := '1.0.0.0'; // Versão padrão para Linux

// Estratégia 1: Tentar ler do arquivo .version no mesmo diretório
FileName := ExtractFilePath(ParamStr(0)) + '.version';
if FileExists(FileName) then
begin
try
AssignFile(VersionFile, FileName);
Reset(VersionFile);
try
ReadLn(VersionFile, VersionLine);
VersionLine := Trim(VersionLine);
if VersionLine <> '' then
Result := VersionLine;
finally
CloseFile(VersionFile);
end;
except
// Ignora erros de leitura
end;
end
else
begin
// Estratégia 2: Tentar ler variável de ambiente
VersionLine := GetEnvironmentVariable('APP_VERSION');
if VersionLine <> '' then
Result := VersionLine
else
begin
// Estratégia 3: Usar data de compilação como versão
{$IFDEF DEBUG}
Result := '1.0.0.0-DEBUG';
{$ELSE}
Result := Format('1.0.0.%d', [
Trunc((Now - EncodeDate(2024, 1, 1)) / 1)
]);
{$ENDIF}
end;
end;

// Garantir que a versão está no formato correto (X.X.X.X)
Major := 1; Minor := 0; Release := 0; Build := 0;

// Tenta extrair números da string de versão
VersionStr := Result;
if VersionStr.Contains('.') then
begin
// Aqui você pode implementar a lógica de parsing
// Por enquanto, mantém o resultado como está
end;
{$ENDIF}
end;


{ TD2BridgeAppConfigVersion }

constructor TD2BridgeAppConfigVersion.Create;
begin
Expand Down Expand Up @@ -184,12 +252,32 @@ procedure TD2BridgeAppConfigVersion.SetRelease(const Value: Integer);
procedure TD2BridgeAppConfigVersion.SetVersionStr(const Value: string);
var
Parts: TArray<string>;
i: Integer;
TempStr: string;
begin
Parts := Value.Split(['.']);
if Length(Parts) > 0 then FMajor := StrToIntDef(Parts[0], 0);
// Remove qualquer texto adicional (como -DEBUG)
TempStr := Value;
i := Pos('-', TempStr);
if i > 0 then
TempStr := Copy(TempStr, 1, i - 1);

Parts := TempStr.Split(['.']);

FMajor := 0;
FMinor := 0;
FRelease := 0;
FBuild := 0;

if Length(Parts) > 0 then FMajor := StrToIntDef(Parts[0], 1);
if Length(Parts) > 1 then FMinor := StrToIntDef(Parts[1], 0);
if Length(Parts) > 2 then FRelease := StrToIntDef(Parts[2], 0);
if Length(Parts) > 3 then FBuild := StrToIntDef(Parts[3], 0);

// Garantir valores mínimos
if FMajor < 1 then FMajor := 1;
if FMinor < 0 then FMinor := 0;
if FRelease < 0 then FRelease := 0;
if FBuild < 0 then FBuild := 0;
end;

end.
end.
2 changes: 1 addition & 1 deletion Beta/D2Bridge Framework/D2Bridge.APPConfig.pas
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ TD2BridgeAPPConfig = class(TInterfacedPersistent, ID2BridgeAPPConfig)
implementation

Uses
D2Bridge.APPConfig.Database, D2Bridge.AppConfig.Version, D2Bridge.AppConfig.Path, D2Bridge.APPConfig.INIConfig,
D2Bridge.APPConfig.Database, D2Bridge.APPConfig.Version, D2Bridge.APPConfig.Path, D2Bridge.APPConfig.INIConfig,
D2Bridge.APPConfig.Custom, D2Bridge.JSON;

{ TD2BridgeAPPConfig }
Expand Down
50 changes: 50 additions & 0 deletions Beta/D2Bridge Framework/D2Bridge.DebugUtils.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{$I D2Bridge.inc}

unit D2Bridge.DebugUtils;

interface

function IsDebuggerPresent: Boolean;

implementation

uses
{$IFDEF MSWINDOWS}
Windows,
{$ENDIF}
SysUtils;

function IsDebuggerPresent: Boolean;
{$IFDEF MSWINDOWS}
begin
Result := Windows.IsDebuggerPresent;
end;
{$ELSE}
var
F: TextFile;
Line: string;
TracerPid: Integer;
begin
Result := False;
if not FileExists('/proc/self/status') then
Exit;
AssignFile(F, '/proc/self/status');
try
Reset(F);
while not EOF(F) do
begin
ReadLn(F, Line);
if Copy(Line, 1, 10) = 'TracerPid:' then
begin
TracerPid := StrToIntDef(Trim(Copy(Line, 11, MaxInt)), 0);
Result := TracerPid <> 0;
Break;
end;
end;
finally
CloseFile(F);
end;
end;
{$ENDIF}

end.
2 changes: 1 addition & 1 deletion Beta/D2Bridge Framework/D2Bridge.Forms.Helper.pas
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface

uses
Classes, Rtti, Generics.Collections, SysUtils,
D2Bridge.Interfaces, Prism.interfaces, Prism.Types;
D2Bridge.Interfaces, Prism.Interfaces, Prism.Types;

type
TD2BridgeFormComponentHelperItems = class;
Expand Down
2 changes: 1 addition & 1 deletion Beta/D2Bridge Framework/D2Bridge.Item.VCLObj.pas
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ interface
Menus, StdCtrls, Forms, Graphics,
{$ENDIF}
Prism.Interfaces, Prism.Types,
D2Bridge.BaseClass, D2Bridge.Item, D2bridge.Interfaces;
D2Bridge.BaseClass, D2Bridge.Item, D2Bridge.Interfaces;


type
Expand Down
4 changes: 2 additions & 2 deletions Beta/D2Bridge Framework/D2Bridge.ItemCommon.Add.pas
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ implementation
D2Bridge.Item.HTML.Card.Grid, D2Bridge.Item.HTML.Card.Grid.DataModel,
D2Bridge.Item.HTML.PanelGroup, D2Bridge.Item.HTML.Tabs,
D2Bridge.Item.HTML.Accordion, D2Bridge.Item.HTML.Popup, D2Bridge.Item.HTML.Upload,
D2Bridge.Item.HTMLelement, D2Bridge.Item.HTML.Link, D2Bridge.Item.HTML.Carousel, D2Bridge.Item.HTML.QRCode,
D2Bridge.Item.HTMLElement, D2Bridge.Item.HTML.Link, D2Bridge.Item.HTML.Carousel, D2Bridge.Item.HTML.QRCode,
D2Bridge.Item.HTML.MainMenu, D2Bridge.Item.HTML.SideMenu, D2Bridge.Item.HTML.Image, D2Bridge.Item.HTML.DBImage,
D2Bridge.Item.HTML.Kanban, D2Bridge.Item.HTML.Editor.MarkDown, D2Bridge.Item.HTML.Editor.WYSIWYG,
D2Bridge.Item.HTML.Camera, D2Bridge.Item.HTML.QRCodeReader,
Expand Down Expand Up @@ -1486,4 +1486,4 @@ function TItemAdd.ColFull(AAutoResponsive: boolean; ACSSClass, AItemID,
result:= ColFull(vCSSCallCol, AItemID, AHTMLExtras, AHTMLStyle, AHTMLTag);
end;

end.
end.
2 changes: 1 addition & 1 deletion Beta/D2Bridge Framework/D2Bridge.Lang.BaseClass.pas
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interface
{$IFDEF MSWINDOWS}
Windows,
{$ENDIF}
D2Bridge.Lang.Interfaces, D2Bridge.Lang.Term.BaseClass, Prism.JSONHelper, Prism.Types;
D2Bridge.DebugUtils, D2Bridge.Lang.Interfaces, D2Bridge.Lang.Term.BaseClass, Prism.JSONHelper, Prism.Types;

type
TD2BridgeLangBaseClass = class(TInterfacedPersistent, ID2BridgeLangBaseClass)
Expand Down
2 changes: 1 addition & 1 deletion Beta/D2Bridge Framework/D2Bridge.Rest.Route.pas
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ TD2BridgeRestRoutes = class(TInterfacedPersistent, ID2BridgeRestRoutes)
implementation

Uses
Prism.BaseClass,
Prism.BaseClass, D2Bridge.DebugUtils,
D2Bridge.Rest.Session, D2Bridge.Rest.Server;


Expand Down
40 changes: 36 additions & 4 deletions Beta/D2Bridge Framework/D2Bridge.ServerControllerBase.pas
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ interface
{$ENDIF}
{$IFDEF MSWINDOWS}
ActiveX, Windows,
{$ENDIF}
{$IFDEF LINUX}
BaseUnix,
termio,
Unix,
{$ENDIF}
SyncObjs,
{$IFNDEF D2BRIDGE}
Expand All @@ -60,7 +65,7 @@ interface
{$IFDEF D2DOCKER}
D2Bridge.API.D2Docker.Comm,
{$ENDIF}
Prism, Prism.Interfaces, Prism.Session, Prism.Types, D2Bridge.Interfaces,
Prism, Prism.Interfaces, Prism.Session, Prism.Types,D2Bridge.DebugUtils, D2Bridge.Interfaces,
D2Bridge.Manager, D2Bridge.Types, D2Bridge.Prism.Form, D2Bridge.Lang.Interfaces,
D2Bridge.Rest.Session, D2Bridge.Rest.Server, D2Bridge.Rest.Interfaces;

Expand Down Expand Up @@ -222,6 +227,7 @@ implementation


function IsEscapePressed: Boolean;
{$IFDEF MSWINDOWS}
var
InputHandle: THandle;
InputRecord: TInputRecord;
Expand Down Expand Up @@ -257,7 +263,33 @@ function IsEscapePressed: Boolean;
end;
end;
end;

{$ELSE}
var
OldTermios, NewTermios: termios;
ch: Char; BytesRead: ssize_t; OldFlags: Integer;
begin
Result := False;
if tcgetattr(StdInputHandle, OldTermios) <> 0 then Exit;
NewTermios := OldTermios;
NewTermios.c_lflag := NewTermios.c_lflag and not (cardinal(ICANON) or cardinal(ECHO));
NewTermios.c_cc[VMIN] := 0;
NewTermios.c_cc[VTIME] := 0;
if tcsetattr(StdInputHandle, TCSANOW, NewTermios) <> 0 then Exit;
try
OldFlags := FpFcntl(StdInputHandle, F_GETFL, 0);
FpFcntl(StdInputHandle, F_SETFL, OldFlags or O_NONBLOCK);
try
ch := #0;
BytesRead := FpRead(StdInputHandle, ch, 1);
if (BytesRead = 1) and (Ord(ch) = 27) then Result := True;
finally
FpFcntl(StdInputHandle, F_SETFL, OldFlags);
end;
finally
tcsetattr(StdInputHandle, TCSANOW, OldTermios);
end;
end;
{$ENDIF}

{ TD2BridgeServerControllerBase }

Expand Down Expand Up @@ -407,7 +439,7 @@ destructor TD2BridgeServerControllerBase.Destroy;
if (not IsD2DockerContext) and ((Not IsDebuggerPresent) {$IFnDEF FPC}or (not ReportMemoryLeaksOnShutdown){$ENDIF}) then
begin
{$IFDEF FPC}
TerminateProcess(GetCurrentProcess, 0);
Halt(0);
{$ENDIF}
{$IFDEF MSWINDOWS}
ExitProcess(0);
Expand Down Expand Up @@ -1104,4 +1136,4 @@ initialization
{$I D2Bridge.Lang.lrs}
{$ENDIF}

end.
end.
Loading