-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathDirectory.lua
76 lines (65 loc) · 1.67 KB
/
Directory.lua
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
-- Services
local HttpService = game:GetService("HttpService")
-- Variables
local directory = {}
-- Functions
local function createFolder(path)
if not isfolder(path) then
makefolder(path)
end
end
local function createBranch(tree, branch, bPath)
for i, v in branch do
local name = (typeof(v) == "table") and i or v
bPath = (bPath or "").."/"..name
createFolder(bPath)
tree[name] = bPath
if typeof(v) == "table" then
createBranch(tree, v, bPath)
end
end
end
directory.Create = function(tree, fPath)
fPath = fPath and fPath.."/" or ""
local t = {}
for i, v in tree do
local tPath = fPath..(typeof(v) == "table" and i or v)
t.Root = tPath
createFolder(tPath)
if typeof(v) == "table" then
createBranch(t, v, tPath)
end
break
end
return t
end
directory.WriteConfig = function(fPath, data)
local success = pcall(function()
writefile(fPath, HttpService:JSONEncode(data))
end)
return success
end
directory.DecodeConfig = function(fPath)
local success, result = pcall(function()
return HttpService:JSONDecode(readfile(fPath))
end)
return success, (success and result or {})
end
directory.GetNameFromDirectory = function(fPath, noExtension)
local splt = fPath:split([[\]])
local name = splt[#splt]
if noExtension then
local i = name:find("%.[^.]+$")
if i then
name = name:sub(1, i - 1)
end
end
return name
end
-- Main
for i, v in directory do
if typeof(v) == "function" then
getgenv()[i] = v
end
end
return directory