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

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

Change (1):
In preparation for release, updated pragma IgorVersion?=6.1 in all procedures

Change (2):
As a side benefit of requiring 6.1, we can use the MultiThread? keyword to thread any model function we like. The speed benefit is only noticeable on functions that require at least one integration and at least 100 points (resolution smearing is NOT threaded, too many threadSafe issues, too little benefit). I have chosen to use the MultiThread? only on the XOP assignment. In the Igor code there are too many functions that are not explicitly declared threadsafe, making for a mess.

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