save for the weekend

This commit is contained in:
Gerhard Hoffmann 2024-03-22 13:50:35 +01:00
parent f56e10a24e
commit 52def3f6a1
8 changed files with 336 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

78
deploy/helloworld.lpi Normal file
View File

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="helloworld"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<RequiredPackages>
<Item>
<PackageName Value="LazUtils"/>
</Item>
</RequiredPackages>
<Units>
<Unit>
<Filename Value="helloworld.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="unit1.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="Unit1"/>
</Unit>
<Unit>
<Filename Value="tariffcalculator.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="TariffCalculator"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="helloworld"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

148
deploy/helloworld.lpr Normal file
View File

@ -0,0 +1,148 @@
{%RunFlags MESSAGES+}
{$mode ObjFPC}{$H+}
program helloworld(output);
uses
TariffCalculator, CTypes, LazUtils, LazFileUtils, LazUtf8, SysUtils,
fpjson, jsonparser;
type
PTJSONObject = ^TJSONObject;
var
jData: TJSONData;
jObject, jObjTemp: TJSONObject;
jEnum: TJSONEnum;
jArray: TJSONArray;
s: Utf8String;
fileId: String;
localRepository: String;
//TariffCalc: TariffCalculatorHandle;
CustomerRepo: array[0..100] of char;
LocalRepo: array[0..100] of char;
LocalCustomerRepo: array[0..100] of char;
LocalBranchName: array[0..32] of char;
FileToCommit: array[0..128] of char;
CommitMessage: array[0..256] of char;
UserName: array[0..64] of char;
PassWord: array[0..64] of char;
P, R: PChar;
Q: String;
I: Integer;
begin
// TariffCalc := NewTariffCalculator;
// DeleteTariffCalculator(TariffCalc);
try
jArray := TJSONArray.Create;
jObject := TJSONObject.Create;
CustomerRepo := 'https://git.mimbach49.de/GerhardHoffmann/customer_999.git';
LocalCustomerRepo := 'H:\\customer_999';
LocalBranchName := 'zg1/zone1';
FileToCommit := 'etc/psa_tariff/tariff01.json';
CommitMessage := 'TEST TEST';
UserName := 'GerhardHoffmann';
PassWord := 'ghlinux12345';
LocalRepo := 'customer_999';
localRepository := 'customer_999';
if GetFileMenuAsJson(localRepository, @jObject) then begin
jArray := jObject['File-Menue'] as TJSONArray;
for jEnum in jArray do begin
jObjTemp := jEnum.Value as TJSONObject;
fileId := jObjTemp.Strings['File-ID'];
writeln();
writeLn(fileId);
s := GetFileNameStr(localRepository, fileId);
writeln();
writeLn(s);
end;
end;
halt;
P := GetFileMenu(LocalRepo);
if P <> nil then
begin
jData := GetJSON(P);
s := jData.FormatJSON;
writeLn(s);
jObject := jData as TJSONObject;
writeLn(jObject['File-Menue'].Count);
jArray := jObject['File-Menue'] as TJSONArray;
for jEnum in jArray do begin
jObjTemp := jEnum.Value as TJSONObject;
s := jObjTemp.Strings['File-ID'];
writeln();
writeLn(s);
end;
for i := 0 to jObject['File-Menue'].Count-1 do
begin
jObjTemp := jObject['File-Menue'].Items[i] as TJSONObject;
s := jObjTemp.Find('File-ID').AsString;
writeLn(s);
R := GetFileName(LocalRepo, PChar(s));
if R <> nil then
begin
writeLn(R);
writeLn(GetFileSize(LocalRepo, PChar(s)));
writeLn(GetFile(LocalRepo, PChar(s)));
DeleteMem(R);
end;
end;
//writeLn(jObject['File-Menue'].Items[0].ToString());
//jObject := jObject['File-Menue'].Items[0] as TJSONObject;
//s := jObject.FormatJSON;
//writeLn(s);
//s := jObject.Find('File-ID').AsString;
//writeLn(s);
//Q := ':';
//writeLn(UTF8Pos(Q, s));
//jArray := jObject.FindPath('File-Menue') as TJSONArray;
//s := jArray[0].AsString;
//writeLn(s);
//jArray := jObject.Get('File-Menue', TJSONArray.Create);
//writeLn(jArray.Extract(0).AsString);
DeleteMem(P)
end;
//:w
//StrDispose(PChar(P));
//if not DirectoryExistsUTF8(ExpandFilenameUtf8(LocalCustomerRepo)) then
// CreateDirUTF8(ExpandFilenameUtf8(LocalCustomerRepo));
//if InitGitLibrary() > 0 then
// Try
// writeLn('initialized git library') ;
// if not DirectoryExistsUTF8(ExpandFilenameUtf8(LocalCustomerRepo+'\\.git')) then
// CloneRepository(CustomerRepo, LocalCustomerRepo);
// if not CheckoutLocalBranch(LocalCustomerRepo, LocalBranchName) = 0 then
// writeLn('cannot check out') ;
// if not CommitFile(LocalCustomerRepo, LocalBranchName, FileToCommit, CommitMessage) = 0 then
// writeLn('cannot commit') ;
// if not PushLocalRepository(LocalCustomerRepo, LocalBranchName, UserName, PassWord) = 0 then
// writeLn('cannot push') ;
// Finally
// if ShutdownGitLibrary() >= 0 then
// writeLn('shutdown git library') ;
// end
//else
// begin
// writeLn('initializing git library FAILED') ;
// Readln;
// end;
finally
jArray.Free;
end;
end.

BIN
deploy/project1.res Normal file

Binary file not shown.

View File

@ -0,0 +1,97 @@
unit TariffCalculator;
{$mode ObjFPC}{$H+}
interface
uses
SysUtils, CTypes, fpjson, jsonparser;
type
// Can't use the class directly, so it is treated as an opaque handle.
// THandle is guaranteed to have the right size, even on other platforms.
TariffCalculatorHandle = THandle;
PTJSONObject = ^TJSONObject;
function NewTariffCalculator: TariffCalculatorHandle; stdcall;
procedure DeleteTariffCalculator(handle: TariffCalculatorHandle); stdcall;
function GetFileMenu(const localRepository: PChar): PChar; stdcall;
function GetFileMenuAsJson(const localRepository: String; jObj: PTJSONObject): Boolean;
function GetFileMenuSize(const localRepository: PChar): cint32; stdcall;
function GetFileName(const localRepository: PChar; const fileId: PChar): PChar; stdcall;
function GetFileNameStr(const localRepository: String; const fileId: String): String;
function GetFileSize(const localRepository: PChar; const fileId: PChar): cint32; stdcall;
function GetFile(const localRepository: PChar; const fileId: PChar): PChar; stdcall;
procedure DeleteMem(P: PChar); stdcall;
function InitGitLibrary: cint32; stdcall;
function ShutdownGitLibrary: cint32; stdcall;
function CloneRepository(var url; var local_path) : cint32; stdcall;
function CheckoutLocalBranch(var local_path; var branch_name) : cint32; stdcall;
function CommitFile(var local_path; var branch_name;
var file_name; var comment) : cint32; stdcall;
function PushLocalRepository(var local_path; var branch_name;
var user_name; var password) : cint32; stdcall;
implementation
const
DLLName = 'CalculatorCInterface.dll';
function GetFileNameStr(const localRepository: String; const fileId: String): String;
var
p: PChar;
begin
Result := '';
try
p := GetFileName(PChar(localRepository), PChar(fileId));
if p <> nil then begin
Result := String(p);
end;
finally
DeleteMem(p);
end;
end;
function GetFileMenuAsJson(const localRepository: String; jObj: PTJSONObject): Boolean;
var
p: PChar;
fileMenuContent: String;
begin
Result := false;
try
p := GetFileMenu(PChar(localRepository));
if p <> nil then begin
fileMenuContent := String(p);
writeln(fileMenuContent);
jObj^ := GetJSON(fileMenuContent) as TJSONObject;
Result := true;
end;
finally
DeleteMem(p);
end;
end;
function NewTariffCalculator: TariffCalculatorHandle; stdcall; external DLLName;
procedure DeleteTariffCalculator(handle: TariffCalculatorHandle); stdcall; external DLLName;
function GetFileMenu(const localRepository: PChar): PChar; stdcall; external DLLName;
function GetFileMenuSize(const localRepository: PChar): cint32; stdcall; external DLLName;
function GetFileName(const localRepository: PChar; const fileId: PChar): PChar; stdcall; external DLLName;
function GetFileSize(const localRepository: PChar; const fileId: PChar): cint32; stdcall; external DLLName;
function GetFile(const localRepository: PChar; const fileId: PChar): PChar; stdcall; external DLLName;
procedure DeleteMem(P: PChar); stdcall; external DLLName;
function InitGitLibrary: cint32; stdcall; external DLLName;
function ShutdownGitLibrary: cint32; stdcall; external DLLName;
function CloneRepository(var url; var local_path) : cint32; stdcall; external DLLName;
function CheckoutLocalBranch(var local_path; var branch_name) : cint32; stdcall; external DLLName;
function CommitFile(var local_path; var branch_name;
var file_name; var comment) : cint32; stdcall; external DLLName;
function PushLocalRepository(var local_path; var branch_name;
var user_name; var password) : cint32; stdcall; external DLLName;
end.

13
deploy/unit1.pas Normal file
View File

@ -0,0 +1,13 @@
unit Unit1;
{$mode ObjFPC}{$H+}
interface
procedure git_clone; cdecl; external 'C:\Users\G.Hoffmann\Downloads\libgit2-1.7.2\libgit2-1.7.2\build\Debug\git2.dll' name 'git_clone';
uses
Classes, SysUtils;
implementation
end.