forked from ThornyFFXI/tCrossBar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.lua
More file actions
68 lines (57 loc) · 2.1 KB
/
Copy pathhelpers.lua
File metadata and controls
68 lines (57 loc) · 2.1 KB
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
function GetImagePath(image, default)
if (string.sub(image, 1, 5) == 'ITEM:') then
return image;
end
if (string.sub(image, 1, 7) == 'STATUS:') then
return image;
end
local potentialPaths = T{
image,
string.format('%sconfig/addons/%s/resources/%s', AshitaCore:GetInstallPath(), addon.name, image),
string.format('%saddons/%s/resources/%s', AshitaCore:GetInstallPath(), addon.name, image),
default or '',
string.format('%sconfig/addons/%s/resources/misc/unknown.png', AshitaCore:GetInstallPath(), addon.name),
string.format('%saddons/%s/resources/misc/unknown.png', AshitaCore:GetInstallPath(), addon.name),
};
for _,path in ipairs(potentialPaths) do
if (path ~= '') and (ashita.fs.exists(path)) then
return path;
end
end
return nil;
end
function GetResourcePath(resource)
local potentialPaths = T{
resource,
string.format('%sconfig/addons/%s/resources/%s', AshitaCore:GetInstallPath(), addon.name, resource),
string.format('%sconfig/addons/%s/resources/%s.lua', AshitaCore:GetInstallPath(), addon.name, resource),
string.format('%saddons/%s/resources/%s', AshitaCore:GetInstallPath(), addon.name, resource),
string.format('%saddons/%s/resources/%s.lua', AshitaCore:GetInstallPath(), addon.name, resource)
};
for _,path in ipairs(potentialPaths) do
if (path ~= '') and (ashita.fs.exists(path)) then
return path;
end
end
end
function LoadFile_s(filePath)
if (filePath == nil) then
return nil;
end
if not ashita.fs.exists(filePath) then
return nil;
end
local success, loadError = loadfile(filePath);
if not success then
Error(string.format('Failed to load resource file: $H%s', filePath));
Error(loadError);
return nil;
end
local result, output = pcall(success);
if not result then
Error(string.format('Failed to execute resource file: $H%s', filePath));
Error(loadError);
return nil;
end
return output;
end