forked from dscalzi/HeliosLauncher
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmods.js
More file actions
165 lines (164 loc) · 9.87 KB
/
mods.js
File metadata and controls
165 lines (164 loc) · 9.87 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
const path = require('path'),
fs = require('fs'),
execSync = require('child_process').execSync,
dir = require('node-dir'),
md5File = require('md5-file'),
downloadCDN = 'https://github.com/resist-network/resist-mod-pack/raw/master'
function getFilesizeInBytes(filename) {
const stats = fs.statSync(filename)
const fileSizeInBytes = stats.size
return fileSizeInBytes
}
console.log('Scanning and creating JSON modlist file, please wait...')
var allJSONrequired = ''
var thisJSONrequired = '\t\t\t\t'
var allJSONoptional = ''
var thisJSONoptional = '\t\t\t\t'
fs.createReadStream(__dirname+'/app/assets/distribution-template.json').pipe(fs.createWriteStream(__dirname+'/app/assets/distribution.json'))
dir.files('../resist-mod-pack', function(err, files) {
files.forEach(function(file) {
var modFile = path.basename(file)
var pathSearch = file.toString()
//For now we do the libraries manually, but will eventually add them so they don't continually download due to hash mismatch!
if(pathSearch.indexOf('\\liteconfig\\') > 0) {
var fileName = modFile.split('.').slice(0, -1).join('.')
var target_type = 'File'
var target_size = getFilesizeInBytes(file)
// Requires md5sum on the Shell (Only Shell Dependent Aspect Currently for Speed)
var md5 = execSync("md5sum \""+file+"\" | awk '{ print $1 }'")
var target_md5 = md5.toString().replace(/\n|\r/g, "").replace('\\','')
//Node.JS MD5
//var target_md5 = md5File.sync(file)
//
var target_url = downloadCDN+file.toString().replace(/\\/g, '/').replace(/ /g,"%20").replace(/resist-mod-pack\//g,'')
console.log(fileName+' >> '+target_md5)
var target_id = fileName
var target_name = fileName
console.log(target_url)
var ext = path.extname(file)
var target_path = file.toString().replace(/\\/g, '/').replace('/config','').replace(/resist-mod-pack\//g,'')
var thisJSONoptional = '{\r\n\t\t\t"id": "'+target_id+'",\r\n\t\t\t"name": "'+target_name+'",\r\n\t\t\t"type": "'+target_type+'",\r\n\t\t\t\t\t"required": {\r\n\t\t\t\t\t"value": false,\r\n\t\t\t\t\t"def": true\r\n\t\t\t\t},\r\n\t\t\t"artifact": {\r\n\t\t\t\t\t\t"size": '+target_size+',\r\n\t\t\t\t\t"path": "'+target_path+'",\r\n\t\t\t\t\t"MD5": "'+target_md5+'",\r\n\t\t\t\t\t"url": "'+target_url+'"\r\n\t\t\t\t\t}\r\n\t\t\t},'
allJSONoptional += thisJSONoptional.toString()
} else if(pathSearch.indexOf('\\mods-optional\\') > 0) {
var fileName = modFile.split('.').slice(0, -1).join('.')
var target_type = 'File'
var target_size = getFilesizeInBytes(file)
var ext = path.extname(file)
// Requires md5sum on the Shell (Only Shell Dependent Aspect Currently for Speed)
var md5 = execSync("md5sum \""+file+"\" | awk '{ print $1 }'")
var target_md5 = md5.toString().replace(/\n|\r/g, "").replace('\\','')
//Node.JS MD5
//var target_md5 = md5File.sync(file)
//
var target_url = downloadCDN+file.toString().replace(/\\/g, '/').replace(/ /g,"%20").replace(/resist-mod-pack\//g,'')
console.log(fileName+' >> '+target_md5)
var target_id = 'net.resist:mod:'+target_md5.slice(0, -28)
var target_name =fileName
console.log(target_url)
var target_path = 'mods-optional/'+fileName+ext
var thisJSONoptional = '{\r\n\t\t\t\t\t"id": "'+target_id+'",\r\n\t\t\t\t\t"name": "'+target_name+'",\r\n\t\t\t\t"type": "'+target_type+'",\r\n\t\t\t\t"required": {\r\n\t\t\t\t\t"value": false,\r\n\t\t\t\t\t"def": true\r\n\t\t\t\t},\r\n\t\t\t\t\t"artifact": {\r\n\t\t\t\t"size": '+target_size+',\r\n\t\t\t\t\t"path": "'+target_path+'",\r\n\t\t\t\t\t"MD5": "'+target_md5+'",\r\n\t\t\t\t\t"url": "'+target_url+'"\r\n\t\t\t\t}\r\n\t\t\t},'
allJSONoptional += thisJSONoptional.toString()
} else if(pathSearch.indexOf('\\mods\\') > 0) {
var fileName = modFile.split('.').slice(0, -1).join('.')
var target_type = 'ForgeMod'
var target_size = getFilesizeInBytes(file)
// Requires md5sum on the Shell (Only Shell Dependent Aspect Currently for Speed)
var md5 = execSync("md5sum \""+file+"\" | awk '{ print $1 }'")
var target_md5 = md5.toString().replace(/\n|\r/g, "").replace('\\','')
//Node.JS MD5
//var target_md5 = md5File.sync(file)
//
var target_url = downloadCDN+file.toString().replace(/\\/g, '/').replace(/ /g,"%20").replace(/resist-mod-pack\//g,'')
console.log(fileName+' >> '+target_md5)
var target_id = 'net.resist:mod:'+target_md5.slice(0, -28)
var target_name = fileName
console.log(target_url)
var ext = path.extname(file)
var target_path = file.toString().replace(/\\/g, '/').replace(/mods\//g,'modstore\/').replace(/resist-mod-pack\//g,'')
var thisJSONoptional = '{\r\n\t\t\t\t"id": "'+target_id+'",\r\n\t\t\t\t"name": "'+target_name+'",\r\n\t\t"type": "'+target_type+'",\r\n\t\t\t"required": {\r\n\t\t\t\t\t"value": true,\r\n\t\t\t\t\t"def": true\r\n\t\t\t\t},\r\n\t\t\t\t\t"artifact": {\r\n\t\t\t\t"size": '+target_size+',\r\n\t\t\t\t\t"path": "'+target_path+'",\r\n\t\t\t\t\t"MD5": "'+target_md5+'",\r\n\t\t\t\t\t"url": "'+target_url+'"\r\n\t\t\t\t}\r\n\t\t\t},'
allJSONoptional += thisJSONoptional.toString()
} else if(pathSearch.indexOf('\\scripts\\') > 0) {
var fileName = modFile.split('.').slice(0, -1).join('.')
var target_type = 'File'
var target_size = getFilesizeInBytes(file)
// Requires md5sum on the Shell (Only Shell Dependent Aspect Currently for Speed)
var md5 = execSync("md5sum \""+file+"\" | awk '{ print $1 }'")
var target_md5 = md5.toString().replace(/\n|\r/g, "").replace('\\','')
//Node.JS MD5
//var target_md5 = md5File.sync(file)
//
var target_url = downloadCDN+file.toString().replace(/\\/g, '/').replace(/ /g,"%20").replace(/resist-mod-pack\//g,'')
console.log(fileName+' >> '+target_md5)
var target_id = fileName
var target_name = fileName
console.log(target_url)
var ext = path.extname(file)
var target_path = file.toString().replace(/\\/g, '/').replace(/mods\//g,'modstore\/').replace(/resist-mod-pack\//g,'')
var thisJSONoptional = '{\r\n\t\t\t\t"id": "'+target_id+'",\r\n\t\t\t\t"name": "'+target_name+'",\r\n\t\t"type": "'+target_type+'",\r\n\t\t\t"required": {\r\n\t\t\t\t\t"value": true,\r\n\t\t\t\t\t"def": true\r\n\t\t\t\t},\r\n\t\t\t\t\t"artifact": {\r\n\t\t\t\t"size": '+target_size+',\r\n\t\t\t\t\t"path": "'+target_path+'",\r\n\t\t\t\t\t"MD5": "'+target_md5+'",\r\n\t\t\t\t\t"url": "'+target_url+'"\r\n\t\t\t\t}\r\n\t\t\t},'
allJSONoptional += thisJSONoptional.toString()
} else if(pathSearch.indexOf('\\config\\') > 0) {
var fileName = modFile.split('.').slice(0, -1).join('.')
var target_type = 'File'
var target_size = getFilesizeInBytes(file)
// Requires md5sum on the Shell (Only Shell Dependent Aspect Currently for Speed)
var md5 = execSync("md5sum \""+file+"\" | awk '{ print $1 }'")
var target_md5 = md5.toString().replace(/\n|\r/g, "").replace('\\','')
//Node.JS MD5
//var target_md5 = md5File.sync(file)
//
var target_url = downloadCDN+file.toString().replace(/\\/g, '/').replace(/ /g,"%20").replace(/resist-mod-pack\//g,'')
console.log(fileName+' >> '+target_md5)
var target_id = fileName
var target_name = fileName
console.log(target_url)
var ext = path.extname(file)
var target_path = file.toString().replace(/\\/g, '/').replace(/resist-mod-pack\//g,'')
var thisJSONoptional = '{\r\n\t\t\t\t\t"id": "'+target_id+'",\r\n\t\t\t\t\t"name": "'+target_name+'",\r\n\t\t\t\t\t"type": "'+target_type+'",\r\n\t\t\t\t\t"required": {\r\n\t\t\t\t\t"value": false,\r\n\t\t\t\t\t"def": true\r\n\t\t\t\t},\r\n\t\t\t\t\t"artifact": {\r\n\t\t\t\t\t"size": '+target_size+',\r\n\t\t\t\t\t"path": "'+target_path+'",\r\n\t\t\t\t\t"MD5": "'+target_md5+'",\r\n\t\t\t\t\t"url": "'+target_url+'"\r\n\t\t\t\t}\r\n\t\t\t},'
allJSONoptional += thisJSONoptional.toString()
} else if(pathSearch.indexOf('\\resources\\') > 0) {
var fileName = modFile.split('.').slice(0, -1).join('.')
var target_type = 'File'
var target_size = getFilesizeInBytes(file)
// Requires md5sum on the Shell (Only Shell Dependent Aspect Currently for Speed)
var md5 = execSync("md5sum \""+file+"\" | awk '{ print $1 }'")
var target_md5 = md5.toString().replace(/\n|\r/g, "").replace('\\','')
//Node.JS MD5
//var target_md5 = md5File.sync(file)
//
var target_url = downloadCDN+file.toString().replace(/\\/g, '/').replace(/ /g,"%20").replace(/resist-mod-pack\//g,'')
console.log(fileName+' >> '+target_md5)
var target_id = fileName
var target_name = fileName
console.log(target_url)
var ext = path.extname(file)
var target_path = file.toString().replace(/\\/g, '/').replace('/config','').replace(/resist-mod-pack\//g,'')
var thisJSONoptional = '{\r\n\t\t\t\t"id": "'+target_id+'",\r\n\t\t\t\t"name": "'+target_name+'",\r\n\t\t\t\t\t"type": "'+target_type+'",\r\n\t\t\t\t\t"required": {\r\n\t\t\t\t\t"value": false,\r\n\t\t\t\t\t"def": true\r\n\t\t\t\t},\r\n\t\t\t"artifact": {\r\n\t\t\t\t\t\t"size": '+target_size+',\r\n\t\t\t\t\t"path": "'+target_path+'",\r\n\t\t\t\t\t"MD5": "'+target_md5+'",\r\n\t\t\t\t\t"url": "'+target_url+'"\r\n\t\t\t\t\t}\r\n\t\t\t},'
allJSONoptional += thisJSONoptional.toString()
}
})
allJSONoptional = allJSONoptional.slice(0, -1).toString()
allJSONrequired = allJSONrequired.slice(0, -1).toString()
if(allJSONrequired == ''){
allJSON = allJSONoptional+']\r\n\t\t}]\r\n}'
} else {
if(allJSONoptional == ''){
allJSON = allJSONrequired+']\r\n\t\t}]\r\n}'
} else {
allJSON = allJSONrequired+','+allJSONoptional+']\r\n\t\t}]\r\n}'
}
}
fs.appendFile(__dirname+'/app/assets/distribution.json', allJSON.replace(/\\/g, '/').replace(/\.\./g,'')+'', function (err) {
if (err) throw err
var fs = require('fs')
fs.readFile(__dirname+'/app/assets/distribution.json', 'utf8', function (err,data) {
if (err) {
return console.log(err)
}
var result = data.replace(/RESIST_CDN/g, ''+downloadCDN+'')
fs.writeFile(__dirname+'/app/assets/distribution.json', result, 'utf8', function (err) {
if (err) return console.log(err)
console.log('Wrote distribution.json to launcher repository!');
})
})
})
})