forked from DC-SWAT/DreamShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartup.lua
More file actions
189 lines (155 loc) · 4.86 KB
/
Copy pathstartup.lua
File metadata and controls
189 lines (155 loc) · 4.86 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
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
180
181
182
183
184
185
186
187
188
189
-----------------------------------------
-- --
-- @name: Startup script --
-- @author: SWAT --
-- @url: http://www.dc-swat.ru --
-- --
-----------------------------------------
--
-- Internal DreamShell lua functions:
--
-- OpenModule Open module file and return ID
-- CloseModule Close module by ID
-- GetModuleByName Get module ID by module NAME
--
-- AddApp Add app by XML file, return app NAME
-- OpenApp Open app by NAME (second argument for args)
-- CloseApp Close app by NAME (second argument for change unload flag)
--
-- ShowConsole
-- HideConsole
-- SetDebugIO Set the debug output (scif, dclsocket, fb, ds, sd). By default is ds.
-- Sleep Sleep in current thread (in ms)
-- MapleAttached Check for attached maple device
--
-- Bit library: bit.or, bit.and, bit.not, bit.xor
-- File system library: lfs.chdir, lfs.currentdir, lfs.dir, lfs.mkdir, lfs.rmdir
--
------------------------------------------
local DreamShell = {
initialized = false,
modules = {
--"tolua",
--"tolua_2plus",
--"luaDS", -- Depends: tolua
--"luaKOS", -- Depends: tolua
--"luaSDL", -- Depends: tolua
--"luaGUI", -- Depends: tolua
--"luaMXML", -- Depends: tolua
--"luaSTD", -- Depends: tolua
--"sqlite3",
--"luaSQL", -- Depends: sqlite3
--"luaSocket",
--"luaTask",
--"angelscript",
--"bzip2",
--"minilzo",
--"zip", -- Depends: bzip2
--"http",
--"httpd",
--"telnetd",
--"mongoose",
--"ppp",
--"mpg123",
--"oggvorbis",
--"adx",
--"s3m",
--"xvid",
--"SDL_mixer", -- Depends: oggvorbis
--"ffmpeg", -- Depends: oggvorbis, mpg123, bzip2
--"opengl",
--"isofs", -- Depends: minilzo
--"isoldr", -- Depends: isofs
--"SDL_net",
--"opkg", -- Depends: minilzo
--"aicaos",
--"gumbo",
--"ini",
--"aicaos",
--"bflash"
},
Initialize = function(self)
os.execute("env USER Default");
local path = os.getenv("PATH");
print(os.getenv("HOST") .. " " .. os.getenv("VERSION") .. "\n");
print(os.getenv("ARCH") .. ": " .. os.getenv("BOARD_ID") .. "\n");
print("Date: " .. os.date() .. "\n");
print("Base path: " .. path .. "\n");
print("User: " .. os.getenv("USER") .. "\n");
local emu = os.getenv("EMU");
if emu ~= nil then
print("Emulator: " .. emu .. "\n");
end
print("\n");
if not MapleAttached("Keyboard") then
table.insert(self.modules, "vkb");
end
table.foreach(self.modules, function(k, name)
print("DS_PROCESS: Loading module " .. name .. "...\n");
if not OpenModule(path .. "/modules/" .. name .. ".klf") then
print("DS_ERROR: Can't load module " .. path .. "/modules/" .. name .. ".klf\n");
end
end);
self:CheckUpdates(path);
self:InstallingApps(path .. "/apps");
OpenApp(os.getenv("APP"));
self.initialized = true;
end,
CheckUpdates = function(self, path)
print("DS_PROCESS: Checking for updates on " .. path .. " ...\n");
local f = io.open(path.. "/update/version.dat");
local v = os.getenv("VERSION");
local ins = false;
local update = "";
local uf = nil;
for ver in f:lines() do
if ins then
update = path .. "/update/pkg/" .. ver .. ".opk";
uf = io.open(update);
if uf ~= nil then
uf:close();
ShowConsole();
print("DS_PROCESS: Installing update " .. update .. "\n");
if not GetModuleByName("opkg") then
if not OpenModule(path .. "/modules/minilzo.klf") or
not OpenModule(path .. "/modules/opkg.klf") then
print("DS_ERROR: Can't open opkg module\n");
f:close();
HideConsole();
return;
end
end
os.execute("opkg -i -f " .. update);
HideConsole();
end
end
if ver == v then
ins = true;
end
end
f:close();
end,
InstallingApps = function(self, path)
print("DS_PROCESS: Installing apps...\n");
local name = nil;
local list = {};
for ent in lfs.dir(path) do
if ent ~= nil and ent.name ~= ".." and ent.name ~= "." and ent.name ~= ".svn" and ent.attr ~= 0 then
table.insert(list, ent.name);
end
end
table.sort(list, function(a, b) return a > b end);
for index, directory in ipairs(list) do
name = AddApp(path .. "/" .. directory .. "/app.xml");
if not name then
print("DS_ERROR: " .. directory .. "\n");
else
print("DS_OK: " .. name .. "\n");
end
end
return true;
end
};
if not DreamShell.initialized then
DreamShell:Initialize();
end