@@ -143,7 +143,7 @@ module App =
143143        Kernel.Value.AddPayload( text.ToString()) 
144144
145145    /// Installs the ifsharp files if they do not exist, then starts jupyter with the ifsharp profile 
146-      let  InstallAndStart ( forceInstall )  =  
146+      let  InstallAndStart ( forceInstall ,   start )  =  
147147
148148        let  thisExecutable  =  Assembly.GetEntryAssembly() .Location
149149        let  userDir  =  Environment.GetFolderPath( Environment.SpecialFolder.UserProfile); 
@@ -161,12 +161,31 @@ module App =
161161        createDir tempDir
162162        createDir customDir
163163
164-         let  configFile  =  Path.Combine( kernelDir,  " ipython_config.py" ) 
165-         let  configqtFile  =  Path.Combine( kernelDir,  " ipython_qtconsole_config.py" ) 
166-         let  kernelFile  =  Path.Combine( kernelDir,  " kernel.json" ) 
167-         if  forceInstall ||  ( File.Exists( configFile)  =  false )  then 
164+         let  allFiles  =  new  System.Collections.Generic.List< string>() 
165+         let  addFile  fn  =  allFiles.Add( fn);  fn
166+         let  configFile  =  Path.Combine( kernelDir,  " ipython_config.py" )  |>  addFile
167+         let  configqtFile  =  Path.Combine( kernelDir,  " ipython_qtconsole_config.py" )  |>  addFile
168+         let  kernelFile  =  Path.Combine( kernelDir,  " kernel.json" )  |>  addFile
169+         let  logoFile  =  Path.Combine( customDir,  " ifsharp_logo.png" )  |>  addFile
170+         let  kjsFile  =  Path.Combine( kernelDir,  " kernel.js" )  |>  addFile
171+         let  fjsFile  =  Path.Combine( customDir,  " fsharp.js" )  |>  addFile
172+         let  wjsFile  =  Path.Combine( customDir,  " webintellisense.js" )  |>  addFile
173+         let  wcjsFile  =  Path.Combine( customDir,  " webintellisense-codemirror.js" )  |>  addFile
174+         let  logo64File  =  Path.Combine( kernelDir,  " logo-64x64.png" )  |>  addFile
175+         let  logo32File  =  Path.Combine( kernelDir,  " logo-32x32.png" )  |>  addFile
176+         let  versionFile  =  Path.Combine( kernelDir,  " version.txt" )  |>  addFile
177+         let  missingFiles  =  Seq.exists ( fun  fn  ->  File.Exists( fn)  =  false )  allFiles
178+         
179+         let  differentVersion  =  File.Exists( versionFile)  &&  File.ReadAllText( versionFile)  <>  Config.Version
180+ 
181+         if  forceInstall then  printfn " Force install required, performing install..." 
182+         else  if  missingFiles then  printfn " One or more files are missing, performing install..." 
183+         else  if  differentVersion then  printfn " Different version found, performing install..." 
184+ 
185+         if  forceInstall ||  missingFiles ||  differentVersion then 
168186
169-             printfn " Config file does not exist, performing install..." 
187+             // write the version file 
188+             File.WriteAllText( versionFile,  Config.Version); 
170189
171190            // write the startup script 
172191            let  codeTemplate  =  IfSharpResources.ipython_ config() 
@@ -184,7 +203,6 @@ module App =
184203            File.WriteAllText( configqtFile,  codeqt) 
185204
186205            // write custom logo file 
187-             let  logoFile  =  Path.Combine( customDir,  " ifsharp_logo.png" ) 
188206            printfn " Saving custom logo [%s  ]"   logoFile
189207            IfSharpResources.ifsharp_ logo() .Save( logoFile) 
190208
@@ -194,24 +212,20 @@ module App =
194212            File.WriteAllText( cssFile,  IfSharpResources.fsharp_ css()) 
195213
196214            // write kernel js file 
197-             let  jsFile  =  Path.Combine( kernelDir,  " kernel.js" ) 
198-             printfn " Saving kernel js [%s  ]"   jsFile
199-             File.WriteAllText( jsFile,  IfSharpResources.kernel_ js()) 
215+             printfn " Saving kernel js [%s  ]"   kjsFile
216+             File.WriteAllText( kjsFile,  IfSharpResources.kernel_ js()) 
200217
201218            // write fsharp js file 
202-             let  jsFile  =  Path.Combine( customDir,  " fsharp.js" ) 
203-             printfn " Saving fsharp js [%s  ]"   jsFile
204-             File.WriteAllText( jsFile,  IfSharpResources.fsharp_ js()) 
219+             printfn " Saving fsharp js [%s  ]"   fjsFile
220+             File.WriteAllText( fjsFile,  IfSharpResources.fsharp_ js()) 
205221
206222            // write webintellisense js file 
207-             let  jsFile  =  Path.Combine( customDir,  " webintellisense.js" ) 
208-             printfn " Saving webintellisense js [%s  ]"   jsFile
209-             File.WriteAllText( jsFile,  IfSharpResources.webintellisense_ js()) 
223+             printfn " Saving webintellisense js [%s  ]"   wjsFile
224+             File.WriteAllText( wjsFile,  IfSharpResources.webintellisense_ js()) 
210225
211226            // write webintellisense-codemirror js file 
212-             let  jsFile  =  Path.Combine( customDir,  " webintellisense-codemirror.js" ) 
213-             printfn " Saving webintellisense-codemirror js [%s  ]"   jsFile
214-             File.WriteAllText( jsFile,  IfSharpResources.webintellisense_ codemirror_ js()) 
227+             printfn " Saving webintellisense-codemirror js [%s  ]"   wcjsFile
228+             File.WriteAllText( wcjsFile,  IfSharpResources.webintellisense_ codemirror_ js()) 
215229
216230            // Make the Kernel info folder  
217231            let  jsonTemplate  =  IfSharpResources.ifsharp_ kernel_ json() 
@@ -224,31 +238,35 @@ module App =
224238            printfn " Saving custom kernel.json file [%s  ]"   kernelFile
225239            File.WriteAllText( kernelFile,  code) 
226240
227-             let  logo64File  =  Path.Combine( kernelDir,  " logo-64x64.png" ) 
228241            printfn " Saving kernel icon [%s  ]"   logo64File
229242            IfSharpResources.ifsharp_ 64logo() .Save( logo64File) 
230243
231-             let  logo32File  =  Path.Combine( kernelDir,  " logo-32x32.png" ) 
232244            printfn " Saving kernel icon [%s  ]"   logo32File
233245            IfSharpResources.ifsharp_ 32logo() .Save( logo32File) 
234246
235-         printfn " Starting Jupyter notebook..." 
236-         let  p  =  new  Process() 
237-         p.StartInfo.FileName <-  " jupyter" 
238-         p.StartInfo.Arguments <-  " notebook" 
239-         p.StartInfo.WorkingDirectory <-  userDir
247+         if  start then 
248+           ( 
249+           printfn " Starting ipython..." 
250+           let  p  =  new  Process() 
251+           p.StartInfo.FileName <-  " jupyter" 
252+           p.StartInfo.Arguments <-  " notebook" 
253+           p.StartInfo.WorkingDirectory <-  userDir
240254
241-         // tell the user something bad happened 
242-         if  p.Start()  =  false  then  printfn " Unable to start jupyter, please install jupyter first" 
255+           // tell the user something bad happened 
256+           if  p.Start()  =  false  then  printfn " Unable to start jupyter, please install jupyter first" 
257+           ) 
243258
244259    /// First argument must be an ipython connection file, blocks forever 
245260     let  Start   ( args  :  array < string >)  =  
246261
247262        if  args.Length =  0  then 
248263
249-             InstallAndStart( true ) 
264+             InstallAndStart( true ,   true ) 
250265
251266        else 
267+             // Verify kernel installation status 
268+             InstallAndStart( false ,  false ) 
269+ 
252270            // Clear the temporary folder 
253271            try 
254272              if  Directory.Exists( Config.TempDir)  then  Directory.Delete( Config.TempDir,  true ) 
0 commit comments