forked from ITS-NIGHTOWL/CSSource-Texture-Installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
170 lines (166 loc) · 7.45 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
(async () => {
const steamcmd = require('./util/steamcmd')
const regedit = require('regedit').promisified
const progress = require('./util/progress')
const fs = require('fs-extra')
const enquirer = require('enquirer')
const figlet = require('figlet')
const chalk = require('chalk')
const vdf_parser = require('vdf-parser')
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('CSSTI+', {
font: 'Slant2',
horizontalLayout: 'fitted',
verticalLayout: 'fitted'
}) + chalk.blueBright('v1.3.0 stable')))
console.log(chalk.magenta(`A utility designed to make installing CSSource textures into Garry's Mod ${chalk.blue('easy, safe, and legal')}, by scripting SteamCMD.`))
console.log(chalk.hex('#7289DA')(`If you have any issues, be sure to file on GitHub: https://github.com/zulc22/CSS-Texture-Installer-Plus/issues`))
progress.start('Verifying steam directory...')
let steamIPath = await (async () => {
steam_search_locations = [
"HKCU\\SOFTWARE\\Valve\\Steam",
"HKCU\\SOFTWARE\\WOW6432Node\\Valve\\Steam",
"HKLM\\SOFTWARE\\Valve\\Steam",
"HKLM\\SOFTWARE\\WOW6432Node\\Valve\\Steam"
];
for (const loc of steam_search_locations) {
try {
reg = await regedit.list(loc);
return reg[loc].values['SteamPath'].value;
break;
} catch {
continue;
}
}
return null;
})()
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}`)
let gmodIPath = await (async () => {
return new Promise(function (resolve) {
if (fs.existsSync(steamIPath + "/steamapps/appmanifest_4000.acf")) {
resolve(steamIPath + "/steamapps/common/GarrysMod")
} else if (fs.existsSync(steamIPath + "/steamapps/libraryfolders.vdf")) {
var libraryfolders_vdf = vdf_parser.parse(fs.readFileSync(steamIPath + "/steamapps/libraryfolders.vdf").toString())
if ("libraryfolders" in libraryfolders_vdf) {
for (e in libraryfolders_vdf["libraryfolders"]) {
var _e = libraryfolders_vdf["libraryfolders"][e]
if ("4000" in _e["apps"]) {
resolve(_e["path"].replace("\\\\", "/") + "/steamapps/common/GarrysMod")
return
}
}
resolve(false)
} else resolve(false)
} else resolve(false)
})
})()
if (!gmodIPath || !fs.existsSync(gmodIPath)) {
return progress.fail('Garry\'s Mod could not be found on your computer.\nAutomatically closing window in 10 seconds.', 10000)
}
progress.succeed(`Garry's 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 Garry\'s 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 Garry's Mod.\nInstallation path: ${gmodIPath}/addons/css_content`)
progress.log('You may now close this console window.')
})
})()