11import { connection , documents , onEvent } from './server'
22import fetch from 'node-fetch'
33import { platform } from 'os'
4- import { createWriteStream , chmodSync , createReadStream , unlinkSync } from 'fs'
4+ import { createWriteStream , chmodSync , createReadStream , unlinkSync , read } from 'fs'
55import * as unzip from 'unzip'
66import { postError } from './utils'
77import { execSync } from 'child_process'
8+ import { serverLog } from './logging'
9+ import { dirname } from 'path'
810
911const url = {
1012 'win32' : 'https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-windows-x64-Release.zip' ,
1113 'linux' : 'https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-linux-Release.zip' ,
1214 'darwin' : 'https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-osx-Release.zip'
1315}
1416
17+ export let glslangReady = false
18+
1519export interface Config {
1620 readonly shaderpacksPath : string
1721 readonly glslangPath : string
@@ -21,17 +25,28 @@ export let conf: Config = {shaderpacksPath: '', glslangPath: ''}
2125
2226export const onConfigChange = async ( change ) => {
2327 const temp = change . settings . mcglsl as Config
28+ if ( temp . shaderpacksPath === conf . shaderpacksPath && temp . glslangPath === conf . glslangPath ) return
2429 conf = { shaderpacksPath : temp [ 'shaderpacksPath' ] . replace ( / \\ / g, '/' ) , glslangPath : temp [ 'glslangValidatorPath' ] . replace ( / \\ / g, '/' ) }
30+ serverLog . debug ( ( ) => 'new config: ' + JSON . stringify ( temp ) )
31+ serverLog . debug ( ( ) => 'old config: ' + JSON . stringify ( conf ) )
32+
33+ if ( conf . shaderpacksPath === '' || conf . shaderpacksPath . replace ( dirname ( conf . shaderpacksPath ) , '' ) !== '/shaderpacks' ) {
34+ serverLog . error ( ( ) => 'shaderpack path not set or doesn\'t end in \'shaderpacks\'' , null )
35+ connection . window . showErrorMessage ( 'mcglsl.shaderpacksPath is not set or doesn\'t end in \'shaderpacks\'. Please set it in your settings.' )
36+ return
37+ }
2538
2639 try {
2740 if ( ! execSync ( conf . glslangPath ) . toString ( ) . startsWith ( 'Usage' ) ) {
2841 documents . all ( ) . forEach ( onEvent )
42+ glslangReady = true
2943 } else {
3044 promptDownloadGlslang ( )
3145 }
3246 } catch ( e ) {
3347 if ( ( e . stdout . toString ( ) as string ) . startsWith ( 'Usage' ) ) {
3448 documents . all ( ) . forEach ( onEvent )
49+ glslangReady = true
3550 } else {
3651 promptDownloadGlslang ( )
3752 }
@@ -47,11 +62,6 @@ async function promptDownloadGlslang() {
4762
4863 if ( ! chosen || chosen . title !== 'Download' ) return
4964
50- if ( conf . shaderpacksPath === '' ) {
51- connection . window . showErrorMessage ( 'Please set mcglsl.shaderpacksPath as this is where glslangValidator will be saved to.' )
52- return
53- }
54-
5565 downloadGlslang ( )
5666}
5767
@@ -76,7 +86,8 @@ async function downloadGlslang() {
7686 chmodSync ( conf . shaderpacksPath + '/glslangValidator' , 0o775 )
7787 unlinkSync ( conf . shaderpacksPath + '/glslangValidator.zip' )
7888 connection . sendNotification ( 'update-config' , conf . shaderpacksPath + '/glslangValidator' )
79- connection . window . showInformationMessage ( 'glslangValidator has been downloaded to ' + conf . shaderpacksPath + '/glslangValidator' )
89+ connection . window . showInformationMessage ( 'glslangValidator has been downloaded to ' + conf . shaderpacksPath + '/glslangValidator. Your config should be updated automatically.' )
90+ glslangReady = true
8091 } )
8192 } )
8293 } catch ( e ) {
0 commit comments