source: sans/Release/trunk/NCNR_User_Procedures/SANS/Analysis/Models/Packages/NCNR_Install.ipf @ 363

Last change on this file since 363 was 363, checked in by srkline, 15 years ago

Merging changes from Dev/trunk up to revision #362 into Release/trunk

File size: 10.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//
11
12
13Function InstallNCNRMacros()
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 the platform
29        Variable isMac=0
30        if(cmpstr("Macintosh",IgorInfo(2))==0)
31                isMac=1
32        endif
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                        Print "Move "+ tmpStr
60                        MoveFile/O/P=ExPath tmpStr as homePathStr+"NCNR_Moved_Files:"+tmpStr
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                        Print "Move "+ tmpStr
72                        MoveFolder extPathStr+tmpStr as homePathStr+"NCNR_Moved_Files:NCNR_Moved_Folders:"+tmpStr
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                        Print "Move "+ tmpStr
89                        MoveFile/O/P=UPPath tmpStr as homePathStr+"NCNR_Moved_Files:"+tmpStr
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                        Print "Move "+ tmpStr
103                        MoveFolder UPPathStr + tmpStr as homePathStr+"NCNR_Moved_Files:NCNR_Moved_Folders:"+tmpStr
104                endif
105        endfor
106
107// clean up the Igor help files
108        NewPath /Q/O IHPath, igorPathStr+"Igor Help Files:"
109        PathInfo IHPath
110        String IHPathStr = S_Path
111        strFileList = IndexedFile(IHPath, -1, "????" )                  //for files
112       
113        Wave/T IHFilesWave=root:IHFiles
114       
115        for (i=0; i<itemsInList(strFileList); i+=1)
116                tmpStr = StringFromList(i,strFileList)
117                isThere = CheckForMatch(tmpStr,IHFilesWave)
118                if(isThere)
119                        Print "Move "+ tmpStr
120                        MoveFile/O/P=IHPath tmpStr as homePathStr+"NCNR_Moved_Files:"+tmpStr
121                endif
122        endfor 
123       
124        // then anything that shows up as a folder
125        Wave/T IHFilesWave=root:IHFolders
126        strFileList = IndexedDir(IHPath, -1, 0)
127        for (i=0; i<itemsInList(strFileList); i+=1)
128                tmpStr = StringFromList(i,strFileList)
129                isThere = CheckForMatch(tmpStr,IHFolders)
130                if(isThere)
131                        Print "Move "+ tmpStr
132                        MoveFolder IHPathStr + tmpStr as homePathStr+"NCNR_Moved_Files:NCNR_Moved_Folders:"+tmpStr
133                endif
134        endfor
135       
136// INSTALL the new stuff
137//(1) copy the items to install to the User Procedures folder
138//(2) set up the aliases from there
139//
140// the old ones should be gone already, so just put in the new ones
141//  and then create shortcuts for XOP and help files
142        MoveFolder homePathStr+"NCNR_Help_Files" as UPPathStr+"NCNR_Help_Files"
143        CreateAliasShortcut/O/P=UPPath "NCNR_Help_Files" as igorPathStr+"Igor Help Files:NCNR_Help_Files"
144       
145        MoveFolder homePathStr+"NCNR_User_Procedures" as UPPathStr+"NCNR_User_Procedures"
146        // don't need an alias for the UserProcedures - they're already here....
147
148        MoveFolder homePathStr+"NCNR_Extensions" as UPPathStr+"NCNR_Extensions"
149        if(isMac)
150                CreateAliasShortcut/O/P=UPPath "NCNR_Extensions:Mac_XOP" as igorPathStr+"Igor Extensions:NCNR_Extensions"
151        else
152                CreateAliasShortcut/O/P=UPPath "NCNR_Extensions:Win_XOP" as igorPathStr+"Igor Extensions:NCNR_Extensions"
153        endif
154       
155
156// put shortcuts to the template in the "top" folder
157//??
158        NewPath/O/Q UtilPath, homePathStr+"NCNR_SANS_Utilities:"
159        strFileList = IndexedFile(UtilPath,-1,".pxt")   
160        for (i=0; i<itemsInList(strFileList); i+=1)
161                tmpStr = StringFromList(i,strFileList)
162//              isThere = CheckForMatch(tmpStr,IHFolders)
163//              if(isThere)
164//                      Print "Move "+ tmpStr
165//                      MoveFolder/O/P=IHPath tmpStr as homePathStr+"NCNR_Moved_Files:"+tmpStr
166                        CreateAliasShortcut/O/P=UtilPath tmpStr as homePathStr +tmpStr
167//              endif
168        endfor
169       
170// old method, used shortcuts from main package (risky if user deletes them)
171//      CreateAliasShortcut/O/P=home "NCNR_Help_Files" as igorPathStr+"Igor Help Files:NCNR_Help_Files"
172//      CreateAliasShortcut/O/P=home "NCNR_User_Procedures" as igorPathStr+"User Procedures:NCNR_User_Procedures"
173//      if(isMac)
174//              CreateAliasShortcut/O/P=home "NCNR_Extensions:Mac XOP" as igorPathStr+"Igor Extensions:NCNR_Extensions"
175//      else
176//              CreateAliasShortcut/O/P=home "NCNR_Extensions:Win XOP" as igorPathStr+"Igor Extensions:NCNR_Extensions"
177//      endif
178       
179
180// installation is done, quit to start fresh
181        doAlert 1, "Quit Igor to complete installation.\rQuit now? "
182        if (V_Flag==1)
183                execute "Quit /Y"
184        endif
185       
186        return 1
187End
188
189// return (1) if str is an entry in tw
190// must be an exact match, with or without ".lnk" extension
191//
192Function CheckForMatch(str,tw)
193        String str
194        Wave/T tw
195       
196        Variable num=numpnts(tw),ii=0
197       
198        do
199                if(cmpstr(str,tw[ii])==0 || cmpstr(str+".lnk",tw[ii])==0)
200                        return (1)
201                endif
202                ii+=1
203        while(ii<num)
204       
205        return(0)
206End
207
208
209Function InstallButtonProc(ba) : ButtonControl
210        STRUCT WMButtonAction &ba
211
212        switch( ba.eventCode )
213                case 2: // mouse up
214                        // click code here
215                        InstallNCNRMacros()
216                        break
217        endswitch
218
219        return 0
220End
221
222Function UpdateCheckButtonProc(ba) : ButtonControl
223        STRUCT WMButtonAction &ba
224
225        switch( ba.eventCode )
226                case 2: // mouse up
227                        // click code here
228                        Execute "CheckForLatestVersion()"
229                        break
230        endswitch
231
232        return 0
233End
234
235Function DiagnosticsProc(ba) : ButtonControl
236        STRUCT WMButtonAction &ba
237
238        switch( ba.eventCode )
239                case 2: // mouse up
240                        // click code here
241                        InstallDiagnostics()
242                        break
243        endswitch
244
245        return 0
246End
247
248Window InstallerPanel() : Panel
249        PauseUpdate; Silent 1           // building window...
250        NewPanel /W=(150,50,445,292)    /K=2
251        Button button0,pos={73,24},size={150,40},proc=InstallButtonProc,title="Install SANS Macros"
252        Button button0,fColor=(1,26214,0)
253        Button button0_1,pos={75,94},size={150,40},proc=UpdateCheckButtonProc,title="Check for Updates"
254        Button button0_1,fColor=(1,26221,39321)
255        Button button0_2,pos={75,164},size={150,40},proc=DiagnosticsProc,title="Print Diagnostics"
256        Button button0_2,fColor=(65535,0,0)
257EndMacro
258
259// generate a notebook with install diagnostics suitable for e-mail
260Function InstallDiagnostics()
261       
262        String nb="Install_Diagnostics_v6",textStr
263       
264        DoWindow/F $nb
265        if(V_flag==0)
266                NewNotebook/N=$nb/F=0 /W=(387,44,995,686) as nb
267        else
268                //clear contents
269                Notebook $nb selection={startOfFile, endOfFile}
270                Notebook $nb text="\r"
271        endif   
272       
273// what version, what platform
274        Notebook $nb text="**Install Diagnostics**\r\r"
275        Notebook $nb text="**Version / Platform**\r"
276        textStr =  IgorInfo(0)+"\r"
277        Notebook $nb text=textStr
278        textStr =  IgorInfo(2)+"\r"
279        Notebook $nb text=textStr
280// what is the currently installed version from the string
281        PathInfo Igor
282        String IgorPathStr = S_Path
283        String fileNameStr = IgorPathStr + "User Procedures:NCNR_User_Procedures:InstalledVersion.txt"
284        String installedStr
285        Variable refnum
286       
287        Open/R/Z refNum as fileNameStr
288        if(V_flag != 0)
289                //couldn't find the file
290                textstr = "I could not determine what version of the SANS Macros you are running."
291        else
292                FReadLine refNum, installedStr
293                Close refnum
294                textStr = installedStr
295        endif
296       
297        Notebook $nb text="\r\r**InstalledVersion.txt**\r"
298        Notebook $nb text=textStr +"\r"
299
300// get listings of everything in each folder
301        string strfileList=""
302
303// what is the listing of the Igor Extensions
304        Notebook $nb text="\r\r**Igor Extensions (files)**\r"
305        NewPath /Q/O ExPath, igorPathStr+"Igor Extensions:"
306       
307        //files
308        strFileList = IndexedFile(ExPath, -1, "????" )
309        textStr = ReplaceString(";", strFileList, "\r")
310        Notebook $nb text=textStr
311
312        //folders
313        Notebook $nb text="\r**Igor Extensions (folders)**\r"
314        strFileList = IndexedDir(ExPath, -1, 0 )
315        textStr = ReplaceString(";", strFileList, "\r")
316        Notebook $nb text=textStr+"\r"
317
318
319// what is the listing of Igor Help files
320        Notebook $nb text="\r\r**Igor Help (files)**\r"
321        NewPath /Q/O IHPath, igorPathStr+"Igor Help Files:"
322
323        //files
324        strFileList = IndexedFile(IHPath, -1, "????" )
325        textStr = ReplaceString(";", strFileList, "\r")
326        Notebook $nb text=textStr
327
328        //folders
329        Notebook $nb text="\r**Igor Help (folders)**\r"
330        strFileList = IndexedDir(IHPath, -1, 0 )
331        textStr = ReplaceString(";", strFileList, "\r")
332        Notebook $nb text=textStr+"\r"
333       
334       
335// what is the listing of the User Procedures
336        Notebook $nb text="\r\r**User Procedures (files)**\r"
337        NewPath /Q/O UPPath, igorPathStr+"User Procedures:"
338        //files
339        strFileList = IndexedFile(UPPath, -1, "????" )
340        textStr = ReplaceString(";", strFileList, "\r")
341        Notebook $nb text=textStr
342
343        //folders
344        Notebook $nb text="\r**User Procedures (folders)**\r"
345        strFileList = IndexedDir(UPPath, -1, 0 )
346        textStr = ReplaceString(";", strFileList, "\r")
347        Notebook $nb text=textStr+"\r"
348       
349// what is the listing of the Igor Procedures
350
351//  generating a path for this seems to be problematic - since it can't be killed , or found on another computer
352// that is (apparently) because if there is anything included from the IgP folder (and there is on even the default installation)
353// - then the path is "in use" and can't be killed...
354//
355        Notebook $nb text="\r\r**Igor Procedures (files)**\r"
356        NewPath /Q/O IgorProcPath, igorPathStr+"Igor Procedures:"
357
358        //files
359        strFileList = IndexedFile(IgorProcPath, -1, "????" )
360        textStr = ReplaceString(";", strFileList, "\r")
361        Notebook $nb text=textStr
362
363        //folders
364        Notebook $nb text="\r**Igor Procedures (folders)**\r"
365        strFileList = IndexedDir(IgorProcPath, -1, 0 )
366        textStr = ReplaceString(";", strFileList, "\r")
367        Notebook $nb text=textStr+"\r"
368
369
370        //move to the beginning of the notebook
371        Notebook $nb selection={startOfFile, startOfFile}       
372        Notebook $nb text=""
373       
374        return(0)
375End
Note: See TracBrowser for help on using the repository browser.