-
Notifications
You must be signed in to change notification settings - Fork 1
/
sm_utils.pas
118 lines (106 loc) · 2.67 KB
/
sm_utils.pas
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
unit sm_utils;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, sm_settings;
//equal 2 strings
function Eq(aValue1, aValue2: string): boolean;
function SM_StrToDate(str: string): TDateTime;
function GetPackageUrl(s: string):string;
function GetScriptName(s: string):string;
//function convert path like {$SIMBA_SPS}/RUNESCAPE_OTHER
//to X:/Simba/Include/SPS/Img/RUNESCAPE_OTHER/
function ConvertPath(s: string; Opt: TOption): string;
const
ReservedWords : array[0..5] of string[20] = ('{$SIMBA}','{$SIMBA_SCRIPTS}','{$SIMBA_SPS}','{$SIMBA_SRL}','{$SIMBA_FONTS}','{$SIMBA_PLUGINS}');
implementation
function Eq(aValue1, aValue2: string): boolean;
//--------------------------------------------------------
begin
Result := AnsiCompareText(Trim(aValue1),Trim(aValue2))=0;
end;
function SM_StrToDate(str: string): TDateTime;
var frmstg: TFormatSettings;
begin
//GetLocaleFormatSettings(0, frmstg);
frmstg.DateSeparator := '.';
frmstg.ShortDateFormat := 'yyyy.mm.dd';
frmstg.TimeSeparator := '.';
frmstg.LongTimeFormat := 'hh.nn';
if not TryStrToDateTime(str, Result, frmstg) then
Result := Now();
end;
function GetPackageUrl(s: string): string;
var
c: char;
i, k: Integer;
begin
k := 0;
SetLength(Result, Length(s));
for i := 0 to Length(s) - 1 do
begin
c := s[i + 1];
if c in [ 'a'..'z', 'A'..'Z' ] then
begin
Inc(k);
Result[k] := c;
end;
end;
SetLength(Result, k);
result:=lowercase(result+'.tar.bz2');
end;
function GetScriptName(s: string): string;
var
c: char;
i, k: Integer;
begin
k := 0;
SetLength(Result, Length(s));
for i := 0 to Length(s) - 1 do
begin
c := s[i + 1];
if c in [ 'a'..'z', 'A'..'Z' ] then
begin
Inc(k);
Result[k] := c;
end;
end;
SetLength(Result, k);
result:=lowercase(result+'.simba');
end;
function ConvertPath(s: string; Opt: TOption): string;
function GetPathType(path: string; var res: string): integer; {very shitty code. Somebody, rewrote me please!!!}
var
i: integer;
j: integer;
begin
result:=-1;
res:='';
for i:=0 to 5 do
begin
j:=pos(trim(reservedWords[i]),path);
if j <> 0 then
begin
res:=path;
delete(res,j,length(trim(reservedWords[i])));
result:=i;
end
end;
end;
var
res: string;
ptype: integer;
begin
ptype:=GetPathType(s,res);
if ptype > -1 then
case ptype of
0:res:=opt.Simba+res;
1:res:=opt.Simba_Scripts+res;
2:res:=opt.Simba_SPS+res;
3:res:=opt.Simba_SRL+res;
4:res:=opt.Simba_Fonts+res;
5:res:=opt.Simba_Plugins+res;
end;
result:=res;
end;
end.