-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathntdownloader.dm
221 lines (187 loc) · 7.79 KB
/
ntdownloader.dm
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/datum/computer_file/program/ntnetdownload
filename = "ntndownloader"
filedesc = "Software Download Tool"
program_icon_state = "generic"
extended_desc = "This program allows downloads of software from official NT repositories"
unsendable = TRUE
undeletable = TRUE
size = 1
requires_ntnet = FALSE
requires_ntnet_feature = NTNET_SOFTWAREDOWNLOAD
available_on_ntnet = FALSE
ui_header = "downloader_finished.gif"
tgui_id = "NtosNetDownloader"
program_icon = "download"
alert_able = TRUE
var/datum/computer_file/program/downloaded_file = null
var/hacked_download = FALSE
var/download_completion = 0 //GQ of downloaded data.
var/download_netspeed = 0
var/downloaderror = ""
var/obj/item/modular_computer/my_computer = null
var/emagged = FALSE
///The list of categories to display in the UI, in order of which they appear.
var/static/list/show_categories = list(
PROGRAM_CATEGORY_DEVICE,
PROGRAM_CATEGORY_EQUIPMENT,
PROGRAM_CATEGORY_GAMES,
PROGRAM_CATEGORY_SECURITY,
PROGRAM_CATEGORY_ENGINEERING,
PROGRAM_CATEGORY_SUPPLY,
PROGRAM_CATEGORY_SCIENCE,
)
/datum/computer_file/program/ntnetdownload/run_emag()
if(emagged)
return FALSE
emagged = TRUE
return TRUE
/datum/computer_file/program/ntnetdownload/proc/begin_file_download(filename)
if(downloaded_file)
return FALSE
var/datum/computer_file/program/PRG = SSmodular_computers.find_ntnet_file_by_name(filename)
if(!PRG || !istype(PRG))
return FALSE
// Attempting to download antag only program, but without having emagged/syndicate computer. No.
if(PRG.available_on_syndinet && !emagged)
return FALSE
var/obj/item/computer_hardware/hard_drive/hard_drive = computer.all_components[MC_HDD]
if(!computer || !hard_drive || !hard_drive.can_store_file(PRG))
return FALSE
ui_header = "downloader_running.gif"
if(PRG in SSmodular_computers.available_station_software)
generate_network_log("Began downloading file [PRG.filename].[PRG.filetype] from NTNet Software Repository.")
hacked_download = FALSE
else if(PRG in SSmodular_computers.available_antag_software)
generate_network_log("Began downloading file **ENCRYPTED**.[PRG.filetype] from unspecified server.")
hacked_download = TRUE
else
generate_network_log("Began downloading file [PRG.filename].[PRG.filetype] from unspecified server.")
hacked_download = FALSE
downloaded_file = PRG.clone()
/datum/computer_file/program/ntnetdownload/proc/abort_file_download()
if(!downloaded_file)
return
generate_network_log("Aborted download of file [hacked_download ? "**ENCRYPTED**" : "[downloaded_file.filename].[downloaded_file.filetype]"].")
downloaded_file = null
download_completion = 0
ui_header = "downloader_finished.gif"
/datum/computer_file/program/ntnetdownload/proc/complete_file_download()
if(!downloaded_file)
return
generate_network_log("Completed download of file [hacked_download ? "**ENCRYPTED**" : "[downloaded_file.filename].[downloaded_file.filetype]"].")
var/obj/item/computer_hardware/hard_drive/hard_drive = computer.all_components[MC_HDD]
if(!computer || !hard_drive || !hard_drive.store_file(downloaded_file))
// The download failed
downloaderror = "I/O ERROR - Unable to save file. Check whether you have enough free space on your hard drive and whether your hard drive is properly connected. If the issue persists contact your system administrator for assistance."
computer.alert_call(src, "Aborted download of file [downloaded_file.filename].[downloaded_file.filetype].")
else
computer.alert_call(src, "Completed download of file [downloaded_file.filename].[downloaded_file.filetype].")
if(computer.active_program != src)
alert_pending = TRUE
downloaded_file = null
download_completion = 0
ui_header = "downloader_finished.gif"
/datum/computer_file/program/ntnetdownload/process_tick()
if(!downloaded_file)
return
if(download_completion >= downloaded_file.size)
complete_file_download()
return
// Download speed according to connectivity state. NTNet server is assumed to be on unlimited speed so we're limited by our local connectivity
download_netspeed = 0
// Speed defines are found in code/__DEFINES/machines.dm
switch(ntnet_status)
if(1)
download_netspeed = NTNETSPEED_LOWSIGNAL
if(2)
download_netspeed = NTNETSPEED_HIGHSIGNAL
if(3)
download_netspeed = NTNETSPEED_ETHERNET
if(ntnet_status != 3) // Ethernet unaffected by distance
var/dist = 100
// Loop through every ntnet relay, find the closest one and use that
for(var/obj/machinery/ntnet_relay/n as anything in SSmachines.get_machines_by_type(/obj/machinery/ntnet_relay))
var/cur_dist = get_dist_euclidian(n, computer)
if(n.is_operational() && cur_dist <= dist)
dist = cur_dist
// At 0 tiles distance, 3x download speed. At 100 tiles distance, 1x download speed.
download_netspeed *= max((-dist/50) + 3, 1)
download_completion = min(downloaded_file.size, download_completion + download_netspeed) // Add the progress
/datum/computer_file/program/ntnetdownload/ui_act(action, params)
if(..())
return TRUE
computer.play_interact_sound()
switch(action)
if("PRG_downloadfile")
if(!downloaded_file)
begin_file_download(params["filename"])
return TRUE
if("PRG_reseterror")
if(downloaderror)
download_completion = 0
download_netspeed = 0
downloaded_file = null
downloaderror = ""
return TRUE
return FALSE
/datum/computer_file/program/ntnetdownload/ui_data(mob/user)
var/list/data = get_header_data()
my_computer = computer
if(!istype(my_computer))
return data
var/obj/item/computer_hardware/card_slot/card_slot = computer.all_components[MC_CARD]
var/list/access = card_slot?.GetAccess()
data["downloading"] = !!downloaded_file
data["error"] = downloaderror || FALSE
// Download running. Wait please..
if(downloaded_file)
data["downloadname"] = downloaded_file.filename
data["downloaddesc"] = downloaded_file.filedesc
data["downloadsize"] = downloaded_file.size
data["downloadspeed"] = download_netspeed
data["downloadcompletion"] = round(download_completion, 0.1)
var/obj/item/computer_hardware/hard_drive/hard_drive = my_computer.all_components[MC_HDD]
data["disk_size"] = hard_drive.max_capacity
data["disk_used"] = hard_drive.used_capacity
data["emagged"] = emagged
var/list/repo = SSmodular_computers.available_antag_software | SSmodular_computers.available_station_software
data["programs"] = list()
for(var/datum/computer_file/program/programs as anything in repo)
data["programs"] += list(list(
"icon" = programs.program_icon,
"filename" = programs.filename,
"filedesc" = programs.filedesc,
"fileinfo" = programs.extended_desc,
"category" = programs.category,
"installed" = !!hard_drive.find_file_by_name(programs.filename),
"compatible" = check_compatibility(programs),
"size" = programs.size,
"access" = programs.can_run(user, transfer = TRUE, access = access),
"verifiedsource" = programs.available_on_ntnet,
))
data["categories"] = show_categories
return data
/datum/computer_file/program/ntnetdownload/proc/check_compatibility(datum/computer_file/program/P)
var/hardflag = computer.hardware_flag
if(P && P.is_supported_by_hardware(hardflag, 0))
return TRUE
return FALSE
/datum/computer_file/program/ntnetdownload/kill_program(forced)
abort_file_download()
return ..(forced)
/// A simple pre-emagged version
/datum/computer_file/program/ntnetdownload/emagged
emagged = TRUE
////////////////////////
//Syndicate Downloader//
////////////////////////
/// This app only lists programs normally found in the emagged section of the normal downloader app
/datum/computer_file/program/ntnetdownload/syndicate
filename = "syndownloader"
filedesc = "Software Download Tool"
program_icon_state = "generic"
extended_desc = "This program allows downloads of software from shared Syndicate repositories"
requires_ntnet = 0
ui_header = "downloader_finished.gif"
tgui_id = "NtosNetDownloader"
emagged = TRUE