-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.js
149 lines (144 loc) · 6.83 KB
/
main.js
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
(async () => {
const steamcmd = require('./util/steamcmd')
const reg = require('./util/registry')
const progress = require('./util/progress')
const fs = require('fs-extra')
const enquirer = require('enquirer')
const figlet = require('figlet')
const chalk = require('chalk')
const appDirectory = require('path').dirname(process.pkg ? process.execPath : (require.main ? require.main.filename : process.argv[0])).replace(/\\/g, '/')
let i;
figlet.parseFont('Slant2', fs.readFileSync(__dirname + '/assets/Slant.flf', 'utf8'))
console.log(chalk.green(figlet.textSync('CSSource installer', {
font: 'Slant2',
horizontalLayout: 'fitted',
verticalLayout: 'fitted'
}) + chalk.blueBright('v1.1.0 stable')))
console.log(chalk.magenta(`A utility designed to help make installing CSSource textures into Garry\s Mod ${chalk.blue('safe')} while also doing it the ${chalk.blue('legal method')} by utilizing steamcmd.`))
console.log(chalk.hex('#7289DA')(`Have any questions? Join my discord: https://discord.gg/kb4KREA`))
progress.start('Verifying steam directory...')
let steamIPath = await (async () => {
return new Promise(function (resolve) {
reg.list('HKCU\\SOFTWARE\\Valve\\Steam', (registry) => {
if (!registry) {
reg.list('HKLM\\SOFTWARE\\Valve\\Steam', (registry) => {
if (!registry) {
reg.list('HKLM\\SOFTWARE\\WOW6432Node\\Valve\\Steam', (registry) => {
if (!registry) resolve(registry)
else resolve(registry.InstallPath.value)
})
} else resolve(registry.InstallPath.value)
})
} else resolve(registry.SteamPath.value)
})
})
})()
if (!steamIPath) {
return progress.fail('Steam could not be found on your computer.\nAutomatically closing window in 10 seconds.', 10000)
}
progress.succeed(`Steam installation directory found: ${steamIPath}`)
const gmodIPath = `${steamIPath}/steamapps/common/GarrysMod/garrysmod`
progress.start('Verifying Garrys Mod directory...')
if (!fs.existsSync(gmodIPath)) return progress.fail('Garrys Mod could not be found on your computer.\nAutomatically closing window in 10 seconds.', 10000)
progress.succeed(`Garrys Mod installation directory found: ${gmodIPath}`)
progress.start('Checking for steamcmd...')
if (!fs.existsSync(appDirectory + '/steam/steamcmd.exe')) {
await (async () => {
return new Promise(async function (resolve) {
progress.update('Downloading steamcmd.exe: 0%')
steamcmd.installToPath(`${appDirectory}/steamcmd.zip`, (dat) => {
if (dat.type === 'download') {
progress.update(`Downloading steamcmd.exe: ${dat.percent}%`)
}
if (dat.type === 'unzip') {
progress.update(`Extracting steamcmd.exe: ${dat.percent}% | ${dat.files} files`)
}
}).then((dat) => {
if (dat.success) {
fs.unlinkSync(dat.path)
progress.succeed(`Steamcmd.exe downloaded and extracted: ${appDirectory + '/steam/steamcmd.exe'}`)
resolve()
}
})
})
})()
} else {
progress.succeed(`Steamcmd.exe found: ${appDirectory + '/steam/steamcmd.exe'}`)
}
if (fs.existsSync(appDirectory + '/cssource')) {
progress.start(`Found cssource folder. This most likely may have been generated from past usage of the program, and as such is being automatically removed.`)
fs.removeSync(appDirectory + '/cssource')
progress.succeed(`Cssource folder removed.`)
}
enquirer.prompt({
type: 'confirm',
name: 'install',
message: 'Would you like to start installing the CSSource textures?'
}).then(async choice => {
if (!choice.install) return progress.fail('Installation cancelled.\nAutomatically closing window in 10 seconds.', 10000)
progress.log('Installation started...')
progress.start('Preparing Counter-Strike Source dedicated server files...\nthis may take a minute or two as steamcmd configures itself')
i = await (async () => {
return new Promise(async (resolve, reject) => {
steamcmd.download('232330', [
'login anonymous',
'force_install_dir ../cssource',
'app_update {{app_id}} -validate'
], (dat) => {
if (dat.code === '0x3') {
return progress.update(`Preparing Counter-Strike Source dedicated server files: ${Math.ceil(dat.progress)}%`)
}
if (dat.code === '0x5') {
return progress.update(`Validating Counter-Strike Source dedicated server files: ${Math.ceil(dat.progress)}%`)
}
if (dat.code === '0x61') {
return progress.update(`Downloading Counter-Strike Source dedicated server files: ${Math.ceil(dat.progress)}%`)
}
if (dat.code === '0x101') {
return progress.update(`Commiting Counter-Strike Source dedicated server files: ${Math.ceil(dat.progress)}%`)
}
return progress.update('Error: unexpected code. Perhaps try rerunning the program.\nAutomatically closing window in 10 seconds.', 10000)
}).then(() => {
progress.succeed('Downloaded Counter-Strike Source dedicated server files.')
resolve(true)
}).catch((err) => {
resolve(err)
})
})
})()
if (typeof i !== 'boolean') return progress.fail(`Error: ${i}.\nAutomatically closing window in 10 seconds.`, 10000)
i = await (async () => {
return new Promise(async (resolve, reject) => {
progress.start('Extracting Counter-Strike Source dedicated server files...')
steamcmd.extract(appDirectory + '/cssource/cstrike/cstrike_pak_dir.vpk', (dat) => {
progress.update(`Extracting Counter-Strike Source dedicated server files: ${dat.file}`)
}).then(() => {
progress.succeed(`Extracted Counter-Strike Source dedicated server files.`)
resolve(true)
}).catch((err) => {
resolve(err)
})
})
})()
if (typeof i !== 'boolean') return progress.fail(`Error: ${i}.\nAutomatically closing window in 10 seconds.`, 10000)
progress.start('Moving Counter-Strike Source textures into Garrys Mod... The console may freeze, this is normal.')
if (fs.existsSync(`${gmodIPath}/addons/css_content`)) {
progress.update('Deleting old css_content folder...')
fs.removeSync(`${gmodIPath}/addons/css_content`)
}
fs.ensureDirSync(`${gmodIPath}/addons/css_content`)
const copySet = ['materials', 'models', 'particles', 'sound', 'resource', 'maps']
for (let folder of copySet) {
progress.update(`Moving ${folder} into ${gmodIPath}/addons/css_content/${folder}`)
fs.moveSync(`${appDirectory}/cssource/cstrike/cstrike_pak_dir/${folder}`, `${gmodIPath}/addons/css_content/${folder}`)
}
progress.succeed(`Successfully moved ${copySet} from ${appDirectory}/cssource/cstrike/cstrike_pak_dir/ to ${gmodIPath}/addons/css_content/`)
progress.start('Cleaning up...')
const removeSet = ['cssource', 'steam']
for (let folder of removeSet) {
if (fs.existsSync(`${appDirectory}/${folder}`)) fs.removeSync(`${appDirectory}/${folder}`)
}
progress.succeed(`The Counter-Strike Source textures have been successfully installed into Garrys Mod.\nInstallation path: ${gmodIPath}/addons/css_content`)
progress.log('You may now close this console window.')
})
})()