summaryrefslogtreecommitdiff
path: root/src/corelib/gfx_utils.pas
blob: 6dfa2d2d6e0e88d589741aa7b81246f9be12f405 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
unit gfx_utils;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, gfxbase;

// Platform specific encoding handling functions
function fpgToOSEncoding(aString: TfpgString): string;
function fpgFromOSEncoding(aString: string): TfpgString;

// Common functions for all platforms
function fpgAddTrailingValue(const ALine, AValue: TfpgString; ADuplicates: boolean = true): TfpgString;

// RTL wrapper filesystem functions with platform independant encoding
// These functions are common for all platforms and rely on fpgXXXPlatformEncoding

function fpgFindFirst(const Path: TfpgString; Attr: Longint; out Rslt: TSearchRec): Longint;
function fpgFindNext(var Rslt: TSearchRec): Longint;
function fpgGetCurrentDir: TfpgString;
function fpgSetCurrentDir(const NewDir: TfpgString): Boolean;
function fpgExpandFileName(const FileName: TfpgString): TfpgString;
function fpgFileExists(const FileName: TfpgString): Boolean;

{ ***  Examples of others we could do  *** }

// function fpgCreateDir(const NewDir: TfpgString): Boolean;
// function fpgRemoveDir(const Dir: TfpgString): Boolean;
// function fpgForceDirectories(const Dir: TfpgString): Boolean;
// function fpgDeleteFile(const FileName: TfpgString): Boolean;
// function fpgRenameFile(const OldName, NewName: TfpgString): Boolean;
// function fpgFileSearch(const Name, DirList: TfpgString): TfpgString;
// function fpgFileIsReadOnly(const FileName: TfpgString): Boolean;
// ....


implementation


// Platform specific encoding handling functions
{$I gfx_utils_impl.inc}


// the common code for all platforms
function fpgAddTrailingValue(const ALine, AValue: TfpgString; ADuplicates: boolean = true): TfpgString;
begin
  if ALine = '' then
  begin
    result := ALine;
    Exit; //==>
  end;

  if ADuplicates then
  begin
    result := ALine + AValue;
    Exit; //==>
  end;

  if (not SameText(Copy(ALine, Length(ALine) - Length(AValue) + 1, Length(AValue)), AValue)) then
    result := ALine + AValue
  else
    result := ALine;
end;

// RTL wrapper filesystem functions

function fpgFindFirst(const Path: TfpgString; Attr: Longint; out
  Rslt: TSearchRec): Longint;
begin
  Result := FindFirst(fpgToOSEncoding(Path), Attr, Rslt);
  Rslt.Name := fpgFromOSEncoding(Rslt.Name);
end;

function fpgFindNext(var Rslt: TSearchRec): Longint;
begin
  Result := FindNext(Rslt);
  Rslt.Name := fpgFromOSEncoding(Rslt.Name);
end;

function fpgGetCurrentDir: TfpgString;
begin
  Result := fpgFromOSEncoding(GetCurrentDir);
end;

function fpgSetCurrentDir(const NewDir: TfpgString): Boolean;
begin
  Result := SetCurrentDir(fpgToOSEncoding(NewDir));
end;

function fpgExpandFileName(const FileName: TfpgString): TfpgString;
begin
  Result := fpgFromOSEncoding(ExpandFileName(fpgToOSEncoding(FileName)));
end;

function fpgFileExists(const FileName: TfpgString): Boolean;
begin
  Result := FileExists(fpgToOSEncoding(FileName));
end;


end.