-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathinit.lua
165 lines (141 loc) · 4.95 KB
/
init.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
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
--- Vapor - LÖVE Distribution Client
-- @module Vapor
-- @author Josef N Patoprsty <[email protected]>
-- @copyright 2015
-- @license <a href="http://www.opensource.org/licenses/zlib-license.php">zlib/libpng</a>
local vapor = {
_VERSION = "Vapor 1.x",
_DESCRIPTION = "LÖVE Distribution Client",
_URL = "http://vapor.love2d.org",
_LICENSE = [[
The zlib/libpng License
Copyright (c) 2015 Josef N Patoprsty
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
]]
}
local cwd = (...):gsub('%.[^%.]+$', '')
vapor.class = {
game = require (cwd..".class.game"),
framework = require (cwd..".class.framework"),
image = require (cwd..".class.image"),
release = require (cwd..".class.release"),
mirror = require (cwd..".class.mirror"),
source = require (cwd..".class.source"),
download = require (cwd..".class.download"),
collection = require (cwd..".class.collection"),
}
vapor.util = require (cwd..".util")
vapor.status = {
fail = -1,
uninitialized = 0,
ready = 1,
download = 2,
downloading = 3,
downloaded = 4,
hashing = 5,
processing = 6,
processed = 7,
}
vapor.lang = require (cwd..".lang")
function vapor:getGameCollection()
return self._gameCollection
end
function vapor:getGameObject(id)
assert(type(id) == "number")
local games = self._gameCollection:find(
function(g)
return g:getIdentifier() == id
end)
return games[1]
end
function vapor:getFrameworkCollection()
return self._frameworkCollection
end
function vapor:getFrameworkObject(id)
assert(type(id) == "number")
local frameworks = self._frameworkCollection:find(
function(f)
return f:getIdentifier() == id
end)
return frameworks[1]
end
function vapor:getMirrorCollection()
return self._mirrorCollection
end
function vapor:getSourceCollection()
return self._sourceCollection
end
function vapor:update()
for _,v in pairs(self._gameCollection:all()) do
--v:update()
for _,w in pairs(v:getRelease():getVersionCollection():all()) do
w:update()
end
end
for _,v in pairs(self._frameworkCollection:all()) do
--v:update()
for _,w in pairs(v:getRelease():getVersionCollection():all()) do
w:update()
end
end
for _,v in pairs(self._mirrorCollection:all()) do
v:update()
if v:getStatus() == vapor.status.processed then
for _,game in pairs(v._processedData.games) do
local g = self._gameCollection:add( vapor.class.game.new(game) )
for _,version in pairs(game.release.versions) do
local v = vapor.class.download.new(version)
v:setFilenamePrefix('game_'..g:getIdentifier())
g:getRelease():getVersionCollection():add( v )
end
end
for _,framework in pairs(v._processedData.frameworks) do
local f = self._frameworkCollection:add( vapor.class.framework.new(framework) )
for _,version in pairs(framework.release.versions) do
local v = vapor.class.download.new(version)
v:setFilenamePrefix('framework_'..f:getIdentifier())
f:getRelease():getVersionCollection():add( v )
end
end
v:setStatus(vapor.status.ready)
end
end
for _,v in pairs(self._sourceCollection:all()) do
v:update()
end
end
-- LuaClassGen pregenerated functions
function vapor.new(init)
init = init or {}
local self={}
self._gameCollection = vapor.class.collection.new()
self.getGameCollection=vapor.getGameCollection
self.getGameObject=vapor.getGameObject
self._frameworkCollection = vapor.class.collection.new()
self.getFrameworkCollection=vapor.getFrameworkCollection
self.getFrameworkObject=vapor.getFrameworkObject
self._mirrorCollection = vapor.class.collection.new()
self.getMirrorCollection=vapor.getMirrorCollection
self._sourceCollection = vapor.class.collection.new()
self.getSourceCollection=vapor.getSourceCollection
self._cacheDir=init.cacheDir
self.getCacheDir=vapor.getCacheDir
self.setCacheDir=vapor.setCacheDir
self.update = vapor.update
self.class=vapor.class
self.util = vapor.util
self.status = vapor.status
self.labg = vapor.lang
return self
end
function vapor:getCacheDir()
return self._cacheDir
end
function vapor:setCacheDir(val)
self._cacheDir=val
end
return vapor