-
Notifications
You must be signed in to change notification settings - Fork 10
/
unitutils.pas
180 lines (146 loc) · 4.32 KB
/
unitutils.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
unit UnitUtils;
interface
uses
Classes, Forms, SysUtils, Graphics, FileUtil, Zipper, UnitLib;
const
ApplicationName = 'Unbound Bible';
ApplicationVersion = '5.4';
LangDirectory = 'localization';
Untitled = 'Untitled';
RecentMax = 10;
var
ApplicationUpdate : boolean = false;
IsPortable : boolean = false;
function DataPath: string;
function DatabaseList: TStringArray;
function ConfigFile: string;
function ModulesFile: string;
function HistoryFile: string;
function HomeURL: string;
function DownloadsURL: string;
function IssueURL: string;
function DonateURL: string;
function BibleHubURL(book, chapter, number: integer): string;
procedure CreateDataDirectory;
procedure UnzipDefaultsFiles;
implementation
uses UnitLocal;
const
BibleHubArray : array [1..66] of string = (
'genesis','exodus','leviticus','numbers','deuteronomy','joshua','judges','ruth','1_samuel','2_samuel',
'1_kings','2_kings','1_chronicles','2_chronicles','ezra','nehemiah','esther','job','psalms','proverbs',
'ecclesiastes','songs','isaiah','jeremiah','lamentations','ezekiel','daniel','hosea','joel','amos',
'obadiah','jonah','micah','nahum','habakkuk','zephaniah','haggai','zechariah','malachi','matthew',
'mark','luke','john','acts','romans','1_corinthians','2_corinthians','galatians','ephesians','philippians',
'colossians','1_thessalonians','2_thessalonians','1_timothy','2_timothy','titus','philemon','hebrews',
'james','1_peter','2_peter','1_john','2_john','3_john','jude','revelation'
);
function PortableDataPath: string;
begin
Result := Application.Location + 'data';
end;
function DataPath: string;
begin
if IsPortable then
Result := PortableDataPath
else
Result := GetUserDir + ApplicationName;
end;
function DatabaseList: TStringArray;
var
s, item : string;
const
ext : array [1..4] of string = ('.unbound','.bbli','.mybible','.SQLite3');
begin
Result := [];
for item in GetFileList(DataPath, '*.*') do
for s in ext do
if Suffix(s, item) then Result.Add(item);
end;
function GetUnboundBiblesList: TStringArray;
begin
Result := GetFileList(DataPath, '*.bbl.unbound');
end;
function ConfigPath: string;
begin
if IsPortable then
Result := Application.Location + Slash + 'configs'
else
begin
{$ifdef windows} Result := LocalAppDataPath + ApplicationName; {$endif}
{$ifdef unix} Result := GetUserDir + '.config/unboundbible'; {$endif}
end;
end;
function ConfigFile: string;
begin
Result := ConfigPath + Slash + 'config.ini';
end;
function ModulesFile: string;
begin
Result := ConfigPath + Slash + 'modules.ini';
end;
function HistoryFile: string;
begin
Result := ConfigPath + Slash + 'history.ini';
end;
function ru: string;
begin
Result := '';
if (Localization.id = 'ru') or (Localization.id = 'uk') then Result := 'ru';
end;
function HomeURL: string;
begin
Result := 'https://unboundbible.net/' + ru;
end;
function DownloadsURL: string;
begin
Result := 'https://unboundbible.net/goto/ubdownload' + ru + '.php';
end;
function IssueURL: string;
begin
Result := 'https://unboundbible.net/goto/contact' + ru + '.php'
end;
function DonateURL: string;
begin
Result := 'https://unboundbible.net/goto/donate' + ru + '.php'
end;
function BibleHubURL(book, chapter, number: integer): string;
begin
if not (book in [1..66]) then Exit('');
Result := 'http://biblehub.com/interlinear/' + BibleHubArray[book] + '/';
Result += ToStr(chapter) + '-' + ToStr(number) + '.htm';
end;
procedure CreateDataDirectory;
begin
if not DirectoryExists(DataPath) then ForceDirectories(DataPath);
end;
procedure UnzipDefaultsFiles;
var
UnZipper: TUnZipper;
List : TStringArray;
Empty : boolean;
f, d : string;
begin
if not DirectoryExists(DataPath) then ForceDirectories(DataPath);
Empty := GetUnboundBiblesList.IsEmpty;
if not ApplicationUpdate and not Empty then Exit;
List := GetFileList(SharePath + 'modules', '*.zip');
UnZipper := TUnZipper.Create;
UnZipper.UseUTF8 := True;
UnZipper.OutputPath := DataPath;
for f in List do
begin
d := DataPath + Slash + ExtractOnlyName(f);
if not empty and not FileExists(d) then Continue;
try
UnZipper.FileName := f;
UnZipper.UnZipAllFiles;
except
//
end;
end;
UnZipper.Free;
end;
initialization
if DirectoryExists(PortableDataPath) then IsPortable := true;
end.