forked from qrrk/Catapult
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoundpackManager.gd
185 lines (156 loc) · 5.26 KB
/
SoundpackManager.gd
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
extends Node
signal soundpack_installation_started
signal soundpack_installation_finished
signal soundpack_deletion_started
signal soundpack_deletion_finished
const SOUNDPACKS = [
{
"name": "CC-Sounds",
"url": "https://github.com/Fris0uman/CDDA-Soundpacks/releases/latest/download/CC-Sounds.zip",
"filename": "CC-Sounds.zip",
"internal_path": "CC-Sounds",
},
{
"name": "CC-Sounds-sfx-only",
"url": "https://github.com/Fris0uman/CDDA-Soundpacks/releases/latest/download/CC-Sounds-sfx-only.zip",
"filename": "CC-Sounds-sfx-only.zip",
"internal_path": "CC-Sounds-sfx-only",
},
{
"name": "CO.AG-music-only",
"url": "https://github.com/Fris0uman/CDDA-Soundpacks/releases/latest/download/CO.AG-music-only.zip",
"filename": "CO.AG-music-only.zip",
"internal_path": "CO.AG-music-only",
},
{
"name": "BeepBoopBip",
"url": "https://github.com/Fris0uman/CDDA-Soundpacks/releases/latest/download/BeepBoopBip.zip",
"filename": "BeepBoopBip.zip",
"internal_path": "BeepBoopBip",
},
{
"name": "@'s soundpack",
"url": "https://github.com/damalsk/damalsksoundpack/archive/refs/heads/master.zip",
"filename": "ats-soundpack.zip",
"internal_path": "damalsksoundpack-master",
},
{
"name": "CDDA-Soundpack",
"url": "https://github.com/budg3/CDDA-Soundpack/archive/master.zip",
"filename": "cdda-soundpack.zip",
"internal_path": "CDDA-Soundpack-master/CDDA-Soundpack",
},
{
"name": "ChestHole",
"url": "http://chezzo.com/cdda/ChestHoleSoundSet.zip",
"filename": "chesthole-soundpack.zip",
"internal_path": "ChestHole",
},
{
"name": "ChestHoleCC",
"url": "http://chezzo.com/cdda/ChestHoleCCSoundset.zip",
"filename": "chesthole-cc-soundpack.zip",
"internal_path": "ChestHoleCC",
},
{
"name": "ChestOldTimey",
"url": "http://chezzo.com/cdda/ChestOldTimeyLessismore.zip",
"filename": "chest-old-timey-soundpack.zip",
"internal_path": "ChestHoleOldTimey",
},
{
"name": "Otopack",
"url": "https://github.com/Kenan2000/Otopack-Mods-Updates/archive/master.zip",
"filename": "otopack.zip",
"internal_path": "Otopack-Mods-Updates-master/Otopack+ModsUpdates",
},
{
"name": "RRFSounds",
"url": "https://www.dropbox.com/s/d8dfmb2facvkdh6/RRFSounds.zip",
"filename": "rrfsounds.zip",
"internal_path": "data/sound/RRFSounds",
"manual_download": true,
},
]
func parse_sound_dir(sound_dir: String) -> Array:
if not Directory.new().dir_exists(sound_dir):
Status.post(tr("msg_no_sound_dir") % sound_dir, Enums.MSG_ERROR)
return []
var result = []
for subdir in FS.list_dir(sound_dir):
var f = File.new()
var info = sound_dir.plus_file(subdir).plus_file("soundpack.txt")
if f.file_exists(info):
f.open(info, File.READ)
var lines = f.get_as_text().split("\n", false)
var name = ""
var desc = ""
for line in lines:
if line.begins_with("VIEW: "):
name = line.trim_prefix("VIEW: ")
elif line.begins_with("DESCRIPTION: "):
desc = line.trim_prefix("DESCRIPTION: ")
var item = {}
item["name"] = name
item["description"] = desc
item["location"] = sound_dir.plus_file(subdir)
result.append(item)
f.close()
return result
func get_installed(include_stock = false) -> Array:
var packs = []
if Directory.new().dir_exists(Paths.sound_user):
packs.append_array(parse_sound_dir(Paths.sound_user))
for pack in packs:
pack["is_stock"] = false
if include_stock:
var stock = parse_sound_dir(Paths.sound_stock)
for pack in stock:
pack["is_stock"] = true
packs.append_array(stock)
return packs
func delete_pack(name: String) -> void:
for pack in get_installed():
if pack["name"] == name:
emit_signal("soundpack_deletion_started")
Status.post(tr("msg_deleting_sound") % pack["location"])
FS.rm_dir(pack["location"])
yield(FS, "rm_dir_done")
emit_signal("soundpack_deletion_finished")
return
Status.post(tr("msg_soundpack_not_found") % name, Enums.MSG_ERROR)
func install_pack(soundpack_index: int, from_file = null, reinstall = false, keep_archive = false) -> void:
var pack = SOUNDPACKS[soundpack_index]
var game = Settings.read("game")
var sound_dir = Paths.sound_user
var tmp_dir = Paths.tmp_dir.plus_file(pack["name"])
var archive = ""
emit_signal("soundpack_installation_started")
if reinstall:
Status.post(tr("msg_reinstalling_sound") % pack["name"])
else:
Status.post(tr("msg_installing_sound") % pack["name"])
if from_file:
archive = from_file
else:
archive = Paths.cache_dir.plus_file(pack["filename"])
if Settings.read("ignore_cache") or not Directory.new().file_exists(archive):
Downloader.download_file(pack["url"], Paths.cache_dir, pack["filename"])
yield(Downloader, "download_finished")
if not Directory.new().file_exists(archive):
Status.post(tr("msg_sound_download_failed"), Enums.MSG_ERROR)
emit_signal("soundpack_installation_finished")
return
if reinstall:
FS.rm_dir(sound_dir + "/" + pack["name"])
yield(FS, "rm_dir_done")
FS.extract(archive, tmp_dir)
yield(FS, "extract_done")
if not keep_archive and not Settings.read("keep_cache"):
Directory.new().remove(archive)
FS.move_dir(tmp_dir + "/" + pack["internal_path"], sound_dir + "/" + pack["name"])
yield(FS, "move_dir_done")
FS.rm_dir(tmp_dir)
yield(FS, "rm_dir_done")
Status.post(tr("msg_sound_installed"))
emit_signal("soundpack_installation_finished")