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

Last change on this file since 476 was 413, checked in by ajj, 14 years ago

More file moving

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