source: sans/Dev/trunk/NCNR_User_Procedures/SANS/Analysis/Models/Packages/NCNR_Install.ipf @ 384

Last change on this file since 384 was 384, checked in by srkline, 14 years ago

New install instructions, for manual install

New diagnostics in the installer that check to see if proper permissions exist, and suggest manual instll if not OK.

Wrapper now behaves better when new data files are loaded, selecting and "popping" the new file in the dataSet popup. also some better behvior if useCursors is checked.

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