source: sans/Dev/trunk/NCNR_User_Procedures/Common/Installer/NCNR_Install.ipf @ 490

Last change on this file since 490 was 490, checked in by srkline, 13 years ago

minor changes and comments

File size: 17.4 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2
3
4
5///
6// ***********
7// it may be prefereable to COPY the files to the UP folder, so that the installer doesn't "eat" itself
8// and require users to re-download if they do something wrong. the difficulty with CopyFolder is that
9// on Windows it does a "mix-in" copy, rather than a delete/overwrite all. So it may be better to just leave
10// the installer as is, requiring a fresh copy each time. SRK 10MAR09
11//
12//
13///
14
15// Install the NCNR Macros
16
17//InstallNCNRMacros() // run this function when experiment is loaded
18//InstallerPanel() // run this function when experiment is loaded
19
20//
21// package-6.001
22// - lots more diagnostics added
23
24Function InstallNCNRMacros(forceInstall)
25        Variable forceInstall           // if == 1, install whatever possible, even if R/W errors from the OS
26
27        //first step, check for Igor 6!!!
28        if(NumberByKey("IGORVERS", IgorInfo(0)) < 6)
29                Abort "You must be running Igor 6 or later to use these macros."
30        endif
31       
32       
33        // check to see if the installer has already been run... if so, the folders will be gone... stop now BEFORE removing things
34        String test = IndexedDir(home, -1, 0)   
35        if(stringmatch(test, "*NCNR_User_Procedures*") == 0)
36                print test
37                Abort "You've already run the installer. If you want to re-install, you'll need a fresh copy from the NCNR website."
38        endif
39       
40        // check for install problems
41        // locked folders, OS errors _err will be non-zero if there is an error
42        Variable UP_err,IH_err,IE_err
43        UP_err = FolderPermissionCheck("User Procedures:")
44        IH_err = FolderPermissionCheck("Igor Help Files:")
45        IE_err = FolderPermissionCheck("Igor Extensions:")     
46//      Print UP_err,IH_err,IE_err
47
48        String alertStr=""
49        if(UP_err != 0)
50                alertStr += "User Procedures has no write permission.\r"
51        endif
52        if(IH_err != 0)
53                alertStr += "Igor Help Files has no write permission.\r"
54        endif
55        if(IE_err != 0)
56                alertStr += "Igor Extensions has no write permission.\r"
57        endif
58       
59        if(forceInstall == 0)
60                if(UP_err != 0 || IH_err != 0 || IE_err != 0)
61                        alertStr += "You will need to install manually."
62                        DoAlert 0,alertStr
63                        return(0)
64                endif
65        endif
66       
67       
68        // check the platform
69        Variable isMac=0
70        if(cmpstr("Macintosh",IgorInfo(2))==0)
71                isMac=1
72        endif
73       
74
75        String igorPathStr,homePathStr
76        PathInfo Igor
77        igorPathStr = S_Path            //these have trailing colons
78        PathInfo home                                   //the location where this was run from...
79        homePathStr = S_Path
80       
81        // clean up old stuff, moving to home:old_moved_files
82        // extensions - these show up as files, even the aliases
83        // help files - these are files
84        // user procedures - these can be in folders or as files
85        variable i=0, AliasSet=0, isThere = 0
86        String tmpStr
87       
88// clean up the Igor Extensions
89        NewPath /Q/O ExPath, igorPathStr+"Igor Extensions:"
90        PathInfo ExPath
91        String extPathStr = S_Path
92        string strFileList = IndexedFile(ExPath, -1, "????" )
93       
94        Wave/T extFiles=root:IExtFiles
95       
96        for (i=0; i<itemsInList(strFileList); i+=1)
97                tmpStr = StringFromList(i,strFileList)
98                isThere = CheckForMatch(tmpStr,extFiles)
99                if(isThere)
100                        MoveFile/O/P=ExPath tmpStr as homePathStr+"NCNR_Moved_Files:"+tmpStr
101                        Print "Move file "+ tmpStr + " from Igor Extensions: "+num2str(V_flag)
102                endif
103        endfor
104       
105        //then anything that shows up as a folder
106        Wave/T extFolders=root:IExtFolders
107        strFileList = IndexedDir(ExPath, -1, 0 )
108        for (i=0; i<itemsInList(strFileList); i+=1)
109                tmpStr = StringFromList(i,strFileList)
110                isThere = CheckForMatch(tmpStr,extFolders)
111                if(isThere)
112                        MoveFolder extPathStr+tmpStr as homePathStr+"NCNR_Moved_Files:NCNR_Moved_Folders:"+tmpStr
113                        Print "Move folder "+ tmpStr + " from Igor Extensions: "+num2str(V_flag)
114                endif
115        endfor
116       
117// clean up the user procedures (files first)
118        NewPath /Q/O UPPath, igorPathStr+"User Procedures:"
119        PathInfo UPPath
120        String UPPathStr = S_Path
121        strFileList = IndexedFile(UPPath, -1, "????" )                  //for files
122       
123        Wave/T UPFilesWave=root:UPFiles
124       
125        for (i=0; i<itemsInList(strFileList); i+=1)
126                tmpStr = StringFromList(i,strFileList)
127                isThere = CheckForMatch(tmpStr,UPFilesWave)
128                if(isThere)
129                        MoveFile/O/P=UPPath tmpStr as homePathStr+"NCNR_Moved_Files:"+tmpStr
130                        Print "Move file "+ tmpStr + " from User Procedures: "+num2str(V_flag)
131                endif
132        endfor
133       
134// clean up the user procedures (folders second)
135        strFileList = IndexedDir(UPPath, -1, 0)                 //for folders, just the names, not full paths
136       
137        Wave/T UPFoldersWave=root:UPFolders
138       
139        for (i=0; i<itemsInList(strFileList); i+=1)
140                tmpStr = StringFromList(i,strFileList)
141                isThere = CheckForMatch(tmpStr,UPFoldersWave)
142                if(isThere)
143                // THIS is the problem, when NCNR_Help_Files is moved - it is in use
144                        MoveFolder/Z UPPathStr + tmpStr as homePathStr+"NCNR_Moved_Files:NCNR_Moved_Folders:"+tmpStr
145                        Print "Move folder "+ tmpStr + " from User Procedures: "+num2str(V_flag)
146                endif
147        endfor
148
149// now try to move the  Igor Help files out
150        NewPath /Q/O IHPath, igorPathStr+"Igor Help Files:"
151        PathInfo IHPath
152        String IHPathStr = S_Path
153        strFileList = IndexedFile(IHPath, -1, "????" )                  //for files
154       
155        Wave/T IHFilesWave=root:IHFiles
156       
157        for (i=0; i<itemsInList(strFileList); i+=1)
158                tmpStr = StringFromList(i,strFileList)
159                isThere = CheckForMatch(tmpStr,IHFilesWave)
160                if(isThere)
161                        MoveFile/O/P=IHPath tmpStr as homePathStr+"NCNR_Moved_Files:"+tmpStr
162                        Print "Move file "+ tmpStr + " from Igor Help Files: "+num2str(V_flag)
163                endif
164        endfor 
165       
166        // then anything that shows up as a folder
167        Wave/T IHFilesWave=root:IHFolders
168        strFileList = IndexedDir(IHPath, -1, 0)
169        for (i=0; i<itemsInList(strFileList); i+=1)
170                tmpStr = StringFromList(i,strFileList)
171                isThere = CheckForMatch(tmpStr,IHFolders)
172                if(isThere)
173                        MoveFolder IHPathStr + tmpStr as homePathStr+"NCNR_Moved_Files:NCNR_Moved_Folders:"+tmpStr
174                        Print "Move folder "+ tmpStr + " from Igor Help Files: "+num2str(V_flag)
175                endif
176        endfor
177       
178// INSTALL the new stuff
179//(1) copy the items to install to the User Procedures folder
180//(2) set up the aliases from there
181//
182// the old ones should be gone already, so just put in the new ones
183
184// they may not be possible to remove, so try to overwrite...
185
186//  and then create shortcuts for XOP and help files
187//      MoveFolder/Z=1/O homePathStr+"NCNR_Help_Files" as UPPathStr+"NCNR_Help_Files"
188//      Print "Move folder NCNR_Help_Files into User Procedures, overwrite if needed: "+num2str(V_flag)
189//      if(V_Flag != 0)
190                MoveFolder/Z=1 homePathStr+"NCNR_Help_Files" as UPPathStr+"NCNR_Help_Files"
191                Print "******Move folder NCNR_Help_Files into User Procedures, NO overwite: "+num2str(V_flag)
192//      endif
193        CreateAliasShortcut/O/P=UPPath "NCNR_Help_Files" as igorPathStr+"Igor Help Files:NCNR_Help_Files"
194        Print "Creating shortcut from NCNR_Help_Files into Igor Help Files: "+num2str(V_flag)
195       
196       
197//      MoveFolder/Z=1/O homePathStr+"NCNR_User_Procedures" as UPPathStr+"NCNR_User_Procedures"
198//      Print "Move folder NCNR_User_Procedures into User Procedures, overwrite if needed: "+num2str(V_flag)
199//      if(V_flag !=0)
200                MoveFolder/Z=1 homePathStr+"NCNR_User_Procedures" as UPPathStr+"NCNR_User_Procedures"
201                Print "*******Move folder NCNR_User_Procedures into User Procedures, NO overwrite: "+num2str(V_flag)
202//      endif   
203        // don't need an alias for the UserProcedures - they're already here....
204
205
206//      MoveFolder/Z=1/O homePathStr+"NCNR_Extensions" as UPPathStr+"NCNR_Extensions"
207//      Print "Move folder NCNR_Extensions into User Procedures, overwrite if needed: "+num2str(V_flag)
208//      if(V_flag !=0)
209                MoveFolder/Z=1 homePathStr+"NCNR_Extensions" as UPPathStr+"NCNR_Extensions"
210                Print "*******Move folder NCNR_Extensions into User Procedures, NO overwrite: "+num2str(V_flag)
211//      endif
212        if(isMac)
213                CreateAliasShortcut/O/P=UPPath "NCNR_Extensions:Mac_XOP" as igorPathStr+"Igor Extensions:NCNR_Extensions"
214        else
215                CreateAliasShortcut/O/P=UPPath "NCNR_Extensions:Win_XOP" as igorPathStr+"Igor Extensions:NCNR_Extensions"
216        endif
217        Print "Creating shortcut for XOP into Igor Extensions: "+num2str(V_flag)
218       
219
220// put shortcuts to the template in the "top" folder
221//??
222        NewPath/O/Q UtilPath, homePathStr+"NCNR_SANS_Utilities:"
223        strFileList = IndexedFile(UtilPath,-1,".pxt")   
224        for (i=0; i<itemsInList(strFileList); i+=1)
225                tmpStr = StringFromList(i,strFileList)
226//              isThere = CheckForMatch(tmpStr,IHFolders)
227//              if(isThere)
228//                      Print "Move "+ tmpStr
229//                      MoveFolder/O/P=IHPath tmpStr as homePathStr+"NCNR_Moved_Files:"+tmpStr
230                        CreateAliasShortcut/O/P=UtilPath tmpStr as homePathStr +tmpStr
231                        Print "Creating shortcut for "+tmpStr+" into top level: "+num2str(V_flag)
232//              endif
233        endfor
234       
235// old method, used shortcuts from main package (risky if user deletes them)
236//      CreateAliasShortcut/O/P=home "NCNR_Help_Files" as igorPathStr+"Igor Help Files:NCNR_Help_Files"
237//      CreateAliasShortcut/O/P=home "NCNR_User_Procedures" as igorPathStr+"User Procedures:NCNR_User_Procedures"
238//      if(isMac)
239//              CreateAliasShortcut/O/P=home "NCNR_Extensions:Mac XOP" as igorPathStr+"Igor Extensions:NCNR_Extensions"
240//      else
241//              CreateAliasShortcut/O/P=home "NCNR_Extensions:Win XOP" as igorPathStr+"Igor Extensions:NCNR_Extensions"
242//      endif
243       
244
245// installation is done, quit to start fresh
246        DoAlert 1, "Quit Igor to complete installation.\rQuit now? "
247        if (V_Flag==1)
248                execute "Quit /Y"
249        endif
250       
251        return 1
252End
253
254// return (1) if str is an entry in tw
255// must be an exact match, with or without ".lnk" extension
256//
257Function CheckForMatch(str,tw)
258        String str
259        Wave/T tw
260       
261        Variable num=numpnts(tw),ii=0
262       
263        do
264                if(cmpstr(str,tw[ii])==0 || cmpstr(str,tw[ii]+".lnk")==0)
265                        return (1)
266                endif
267                ii+=1
268        while(ii<num)
269       
270        return(0)
271End
272
273
274Function InstallButtonProc(ba) : ButtonControl
275        STRUCT WMButtonAction &ba
276
277        switch( ba.eventCode )
278                case 2: // mouse up
279                        // click code here
280                        InstallNCNRMacros(0)
281                        break
282        endswitch
283
284        return 0
285End
286
287Function UpdateCheckButtonProc(ba) : ButtonControl
288        STRUCT WMButtonAction &ba
289
290        switch( ba.eventCode )
291                case 2: // mouse up
292                        // click code here
293                        Execute "CheckForLatestVersion()"
294                        break
295        endswitch
296
297        return 0
298End
299
300Function DiagnosticsProc(ba) : ButtonControl
301        STRUCT WMButtonAction &ba
302
303        switch( ba.eventCode )
304                case 2: // mouse up
305                        // click code here
306                        InstallDiagnostics()
307                        break
308        endswitch
309
310        return 0
311End
312
313Window InstallerPanel() : Panel
314        PauseUpdate; Silent 1           // building window...
315        NewPanel /W=(150,50,445,292)    /K=2
316        Button button0,pos={73,24},size={150,40},proc=InstallButtonProc,title="Install SANS Macros"
317        Button button0,fColor=(1,26214,0)
318        Button button0_1,pos={75,94},size={150,40},proc=UpdateCheckButtonProc,title="Check for Updates"
319        Button button0_1,fColor=(1,26221,39321)
320        Button button0_2,pos={75,164},size={150,40},proc=DiagnosticsProc,title="Print Diagnostics"
321        Button button0_2,fColor=(65535,0,0)
322EndMacro
323
324// generate a notebook with install diagnostics suitable for e-mail
325Function InstallDiagnostics()
326       
327        String nb="Install_Diagnostics_v6",textStr
328       
329        DoWindow/F $nb
330        if(V_flag==0)
331                NewNotebook/N=$nb/F=0 /W=(387,44,995,686) as nb
332        else
333                //clear contents
334                Notebook $nb selection={startOfFile, endOfFile}
335                Notebook $nb text="\r"
336        endif   
337       
338// what version, what platform
339        Notebook $nb text="**Install Diagnostics**\r\r"
340        Notebook $nb text="**Version / Platform**\r"
341        textStr =  IgorInfo(0)+"\r"
342        Notebook $nb text=textStr
343        textStr =  IgorInfo(2)+"\r"
344        Notebook $nb text=textStr
345// what is the currently installed version from the string
346        PathInfo Igor
347        String IgorPathStr = S_Path
348        String fileNameStr = IgorPathStr + "User Procedures:NCNR_User_Procedures:InstalledVersion.txt"
349        String installedStr
350        Variable refnum
351       
352        Open/R/Z refNum as fileNameStr
353        if(V_flag != 0)
354                //couldn't find the file
355                textstr = "I could not determine what version of the SANS Macros you are running."
356        else
357                FReadLine refNum, installedStr
358                Close refnum
359                textStr = installedStr
360        endif
361       
362        // check for permissions
363        Variable UP_err,IH_err,IE_err
364        UP_err = FolderPermissionCheck("User Procedures:")
365        IH_err = FolderPermissionCheck("Igor Help Files:")
366        IE_err = FolderPermissionCheck("Igor Extensions:")
367       
368        Print UP_err,IH_err,IE_err
369       
370        String alertStr=""
371        if(UP_err != 0)
372                alertStr += "User Procedures has no write permission. Error = "+num2Str(UP_err)+"\r"
373        else
374                alertStr += "User Procedures permission is OK.\r"
375        endif
376        if(IH_err != 0)
377                alertStr += "Igor Help Files has no write permission. Error = "+num2Str(IH_err)+"\r"
378        else
379                alertStr += "Igor Help Files permission is OK.\r"
380        endif
381        if(IE_err != 0)
382                alertStr += "Igor Extensions has no write permission. Error = "+num2Str(IE_err)+"\r"
383        else
384                alertStr += "Igor Extensions permission is OK.\r"
385        endif
386       
387        if(UP_err != 0 || IH_err != 0 || IE_err != 0)
388                alertStr += "You will need to install manually."
389        endif
390       
391        Notebook $nb text="\r\r**Folder Permissions**\r"
392        Notebook $nb text=AlertStr +"\r"
393       
394       
395        Notebook $nb text="\r\r**InstalledVersion.txt**\r"
396        Notebook $nb text=textStr +"\r"
397
398// get listings of everything in each folder
399        string strfileList=""
400
401// what is the listing of the Igor Extensions
402        Notebook $nb text="\r\r**Igor Extensions (files)**\r"
403        NewPath /Q/O ExPath, igorPathStr+"Igor Extensions:"
404       
405        //files
406        strFileList = IndexedFile(ExPath, -1, "????" )
407        textStr = ReplaceString(";", strFileList, "\r")
408        Notebook $nb text=textStr
409
410        //folders
411        Notebook $nb text="\r**Igor Extensions (folders)**\r"
412        strFileList = IndexedDir(ExPath, -1, 0 )
413        textStr = ReplaceString(";", strFileList, "\r")
414        Notebook $nb text=textStr+"\r"
415
416
417// what is the listing of Igor Help files
418        Notebook $nb text="\r\r**Igor Help (files)**\r"
419        NewPath /Q/O IHPath, igorPathStr+"Igor Help Files:"
420
421        //files
422        strFileList = IndexedFile(IHPath, -1, "????" )
423        textStr = ReplaceString(";", strFileList, "\r")
424        Notebook $nb text=textStr
425
426        //folders
427        Notebook $nb text="\r**Igor Help (folders)**\r"
428        strFileList = IndexedDir(IHPath, -1, 0 )
429        textStr = ReplaceString(";", strFileList, "\r")
430        Notebook $nb text=textStr+"\r"
431       
432       
433// what is the listing of the User Procedures
434        Notebook $nb text="\r\r**User Procedures (files)**\r"
435        NewPath /Q/O UPPath, igorPathStr+"User Procedures:"
436        //files
437        strFileList = IndexedFile(UPPath, -1, "????" )
438        textStr = ReplaceString(";", strFileList, "\r")
439        Notebook $nb text=textStr
440
441        //folders
442        Notebook $nb text="\r**User Procedures (folders)**\r"
443        strFileList = IndexedDir(UPPath, -1, 0 )
444        textStr = ReplaceString(";", strFileList, "\r")
445        Notebook $nb text=textStr+"\r"
446       
447// what is the listing of the Igor Procedures
448
449//  generating a path for this seems to be problematic - since it can't be killed , or found on another computer
450// that is (apparently) because if there is anything included from the IgP folder (and there is on even the default installation)
451// - then the path is "in use" and can't be killed...
452//
453        Notebook $nb text="\r\r**Igor Procedures (files)**\r"
454        NewPath /Q/O IgorProcPath, igorPathStr+"Igor Procedures:"
455
456        //files
457        strFileList = IndexedFile(IgorProcPath, -1, "????" )
458        textStr = ReplaceString(";", strFileList, "\r")
459        Notebook $nb text=textStr
460
461        //folders
462        Notebook $nb text="\r**Igor Procedures (folders)**\r"
463        strFileList = IndexedDir(IgorProcPath, -1, 0 )
464        textStr = ReplaceString(";", strFileList, "\r")
465        Notebook $nb text=textStr+"\r"
466//
467//
468        // then get a listing of the "home" directory. If files were not moved properly, they will still be here
469        Notebook $nb text="\r\r**Home (files)**\r"
470//      NewPath /Q/O IgorProcPath, igorPathStr+"Igor Procedures:"
471
472        //files
473        strFileList = IndexedFile(home, -1, "????" )
474        textStr = ReplaceString(";", strFileList, "\r")
475        Notebook $nb text=textStr
476
477        //folders
478        Notebook $nb text="\r**Home (folders)**\r"
479        strFileList = IndexedDir(home, -1, 0 )
480        textStr = ReplaceString(";", strFileList, "\r")
481        Notebook $nb text=textStr+"\r"
482       
483        //move to the beginning of the notebook
484        Notebook $nb selection={startOfFile, startOfFile}       
485        Notebook $nb text=""
486       
487        return(0)
488End
489
490Function AskUserToKillHelp()
491
492        //// clean up the Igor help files
493// first, kill any open help files
494// there are 5 of them
495        Variable numHelpFilesOpen=0
496//      do
497                numHelpFilesOpen = 0
498                // V_flag is set to zero if it's found, non-zero (unspecified value?) if it's not found
499                DisplayHelpTopic/Z "Beta SANS Tools"
500                if(V_flag==0)
501                        numHelpFilesOpen += 1
502                endif
503               
504                DisplayHelpTopic/Z "SANS Data Analysis Documentation"
505                if(V_flag==0)
506                        numHelpFilesOpen += 1
507                endif
508                               
509                DisplayHelpTopic/Z "SANS Model Function Documentation"
510                if(V_flag==0)
511                        numHelpFilesOpen += 1
512                endif
513                               
514                DisplayHelpTopic/Z "SANS Data Reduction Tutorial"
515                if(V_flag==0)
516                        numHelpFilesOpen += 1
517                endif
518                               
519                DisplayHelpTopic/Z "USANS Data Reduction"
520                if(V_flag==0)
521                        numHelpFilesOpen += 1
522                endif
523                       
524//              PauseForUser            // can't use this, it keeps you from interacting with anything....
525//      while(NumHelpFilesOpen != 0)
526        DoWindow HelpNotebook
527        if(V_flag)
528                DoWindow/K HelpNotebook
529        endif
530       
531        String helpStr = "Please kill the open Help Files by holding down the OPTION key (Macintosh) or ALT key (Windows) and then CLICKING on the close box of each help window."
532        helpStr += " Once you have finished, please close this window and install the SANS Macros."
533        if(NumHelpFilesOpen != 0)
534                NewNotebook/F=1/K=1/N=HelpNotebook /W=(5,44,547,380) as "Please close the open help files"
535                Notebook HelpNotebook,fsize=18,fstyle=1,showRuler=0,text=helpStr
536                return(0)
537        endif
538
539        return(0)
540End
541
542//check each of the three folders
543// folder string MUST have the trailing colon
544Function FolderPermissionCheck(folderStr)
545        String folderStr
546        Variable refnum
547        String str="delete me"
548       
549        String igorPathStr,resultStr=""
550        PathInfo Igor
551        igorPathStr = S_Path
552       
553        NewPath /Q/O tmpPath, igorPathStr+folderStr
554
555       
556        Open/Z/P=tmpPath refnum as "test.txt"
557        if(V_flag != 0)
558                return(V_flag)
559        else
560                FBinWrite refnum,str
561                Close refnum
562               
563//              Print "folder OK"
564                DeleteFile/Z/P=tmpPath  "test.txt"
565        endif
566       
567       
568        return(V_flag)
569end
570
571// this will "force" an install, even if there are R/W errors
572Macro ForceInstall()
573
574        Execute "InstallNCNRMacros(1)"
575end
Note: See TracBrowser for help on using the repository browser.