aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code/Classes/UPlatform.pas
blob: bdd6cf7821461d77a8f2832621d2fd5ef0bbc1dc (plain) (blame)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
unit UPlatform;

// Comment by Eddie:
// This unit defines an interface for platform specific utility functions.
// The Interface is implemented in separate files for each platform:
// UPlatformWindows, UPlatformLinux and UPlatformWindows.

interface

{$IFDEF FPC}
  {$MODE Delphi}
{$ENDIF}

{$I switches.inc}

uses Classes;

type
  
  TDirectoryEntry = Record
                      Name        : WideString;
                      IsDirectory : Boolean;
                      IsFile      : Boolean;
                    end;
 
  TDirectoryEntryArray = Array of TDirectoryEntry;
	
  IPlatform = Interface
  ['{63A5EBC3-3F4D-4F23-8DFB-B5165FCA23DF}']
    Function DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray;
    function TerminateIfAlreadyRunning(var WndTitle : String) : Boolean;

    function GetLogPath        : WideString;
    function GetGameSharedPath : WideString;
    function GetGameUserPath   : WideString;
  end;
 
  TPlatform = class( TInterfacedOBject, IPlatform )

	  // DirectoryFindFiles returns all files matching the filter. Do not use '*' in the filter.
	  // If you set ReturnAllSubDirs = true all directories will be returned, if yout set it to false
	  // directories are completely ignored.
    Function DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; virtual; abstract;

    function TerminateIfAlreadyRunning(var WndTitle : String) : Boolean; virtual;

//    function GetGamePath       : WideString; virtual;
    function GetLogPath        : WideString; virtual;
    function GetGameSharedPath : WideString; virtual;
    function GetGameUserPath   : WideString; virtual;

  end;


var
  Platform : IPlatform;

implementation

uses
  SysUtils,
  {$IFDEF MSWINDOWS}
  UPlatformWindows;
  {$ENDIF}
  {$IFDEF LINUX}
  UPlatformLinux;
  {$ENDIF}
  {$IFDEF DARWIN}
  UPlatformMacOSX;
  {$ENDIF}

{ TPlatform }

(*
function TPlatform.GetGamePath: WideString;
begin
  // Windows and Linux use this:
  Result := ExtractFilePath(ParamStr(0));
end;
*)
function TPlatform.GetLogPath        : WideString;
begin
  result := ExtractFilePath(ParamStr(0));
end;

function TPlatform.GetGameSharedPath : WideString;
begin
  result := ExtractFilePath(ParamStr(0));
end;

function TPlatform.GetGameUserPath   : WideString;
begin
  result := ExtractFilePath(ParamStr(0));
end;



function TPlatform.TerminateIfAlreadyRunning(var WndTitle : String) : Boolean;
begin
  // Linux and Mac don't check for running apps at the moment
  Result := false;
end;

initialization

  {$IFDEF MSWINDOWS}
    Platform := TPlatformWindows.Create;
  {$ENDIF}
  {$IFDEF LINUX}
    Platform := TPlatformLinux.Create;
  {$ENDIF}
  {$IFDEF DARWIN}
    Platform := TPlatformMacOSX.Create;
  {$ENDIF}

finalization
    Platform := nil;
end.