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

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