source: trunk/Installers/GitHub/GHInstaller_support.ipf @ 1117

Last change on this file since 1117 was 1117, checked in by ilavsky, 17 months ago

Fix USAXS data ASCII export

  • Property svn:eol-style set to native
File size: 150.7 KB
Line 
1#pragma TextEncoding = "UTF-8"          // For details execute DisplayHelpTopic "The TextEncoding Pragma"
2#pragma rtGlobals=3             // Use modern global access method and strict wave access.
3#pragma version = 1.12
4
5
6//1.12 fix GH links issue which was failing to loacate proper name for new folder.
7//1.11 critical upgrade, fix for bug in code which relies on bug in Igor behavior which will be fixed in Igor 8.05 and 9
8//1.08 added better messaging to user for failed installations
9//1.05 minor fixes
10//1.04 Addes recording of installation (method, packages, success etc) for statistical purposes.
11//1.03 updated to handle better failed downloads of files from Github.
12//1.02 Fixes to some paths which were causing issues unzipping files
13//1.0 promoted to 1.0, seems to work.
14//0.7 added check to handle Widows unzip problem.
15//0.6 added instructions for handling the two most common errors seen up to now - donwload error and Mac unzip failed.
16//0.5 fixed more bugs, better handling of releases by now.
17//0.4 improved handling of data from local folder, now it can find out the versions of packages
18//0.3 added lots of new functionality and was tested on Windows 10
19//0.2 added functions to load IgorInstallerConfig.xml and parse the content into text waves in Igor
20//0.1 Added and modified XML code. Code from ALways_First.ipf by Jon Tischler. Functions renamed to protect name space. 
21//                      added support for reading and extracting infomrmation from specific form ox xml configuration file. 
22
23// this is support package for installer of Igor Pro software from Github
24//Function GHW_ReadConfigurationFile()                                  this function scans and generates lists of data.
25
26
27
28//Known keywords:
29//VersionCheck/KnownPackages
30//                                      /current_release, current_beta_release
31//InstallerConfig/release
32//                                                      SourceFileAddress
33//                                                      Package/name, version, PackageList, VersionCheckFile
34
35//<?xml version="1.0" encoding="UTF-8" ?>
36//
37//<IgorInstaller>
38//                      <!--
39//                              The structure of this file "IgorInstallerConfig.xml" is used to define Installer functionality.
40//                              Its name is fixed in the code. Its location is something similar to this:
41//                              "http://raw.githubusercontent.com/jilavsky/SAXS_IgorCode/master/"               
42//                              VersionCheck defines what the known packages are and what the current releases are
43//                              InstallerConfig lists for each release for all packages : version, PackageList (contains list of paths and files to be copied
44//                              and version check file (file in which code will look for #pragma version =)
45//                              -->
46//      <VersionCheck>
47//              <KnownPackages>
48//                      <Package>Irena</Package>
49//                      <Package>Nika</Package>
50//                      <Package>Indra</Package>
51//                      <Package>xop</Package>
52//              </KnownPackages>
53//              <current_release>March2016</current_release>
54//              <current_beta_release>March2016_2</current_beta_release>
55//      </VersionCheck>
56//
57//      <InstallerConfig>
58//              <release name="March2016">
59//                      <SourceFileAddress>https://github.com/jilavsky/SAXS_IgorCode/archive/TestVersion.zip</SourceFileAddress>
60//                      <Package>
61//                              <name>Irena</name>
62//                              <version>2.62</version>
63//                              <PackageList>IrenaPckg.xml</PackageList>
64//                              <VersionCheckFile>/Igor Procedures/Boot Irena1 modeling.ipf</VersionCheckFile>
65//                      </Package>
66//                      <Package>
67//                              <name>Nika</name>
68//                              <version>1.5</version>
69//                              <PackageList>NikaPckg.xml</PackageList>
70//                              <VersionCheckFile>/Igor Procedures/Boot Nika.ipf</VersionCheckFile>
71//                      </Package>
72//                      <Package>
73//                              <name>Indra</name>
74//                              <version>1.88</version>
75//                              <PackageList>IndraPckg.xml</PackageList>
76//                              <VersionCheckFile>/Igor Procedures/Boot Indra2.ipf</VersionCheckFile>
77//                      </Package>
78//                      <Package>
79//                              <name>xop</name>
80//                              <version></version>
81//                              <PackageList>xopPckg.xml</PackageList>
82//                              <VersionCheckFile></VersionCheckFile>
83//                      </Package>
84//                      <VersionComment>Added Panel Scaling</VersionComment>
85//              </release>
86//              <release name="March2016_2" beta="true">
87//                      <SourceFileAddress>https://github.com/jilavsky/SAXS_IgorCode/archive/TestVersion.zip</SourceFileAddress>
88//                      <Package>
89//                              <name>Irena</name>
90//                              <version>2.62</version>
91//                              <PackageList>IrenaPckg.xml</PackageList>
92//                              <VersionCheckFile>/Igor Procedures/Boot Irena1 modeling.ipf</VersionCheckFile>
93//                      </Package>
94//                      <Package>
95//                              <name>Nika</name>
96//                              <version>1.5</version>
97//                              <PackageList>NikaPckg.xml</PackageList>
98//                              <VersionCheckFile>/Igor Procedures/Boot Nika.ipf</VersionCheckFile>
99//                      </Package>
100//                      <Package>
101//                              <name>Indra</name>
102//                              <version>1.88</version>
103//                              <PackageList>IndraPckg.xml</PackageList>
104//                              <VersionCheckFile>/Igor Procedures/Boot Indra2.ipf</VersionCheckFile>
105//                      </Package>
106//                      <Package>
107//                              <name>xop</name>
108//                              <version></version>
109//                              <PackageList>xopPckg.xml</PackageList>
110//                              <VersionCheckFile></VersionCheckFile>
111//                      </Package>
112//                      <VersionComment>Added Panel Scaling</VersionComment>
113//              </release>
114//      </InstallerConfig>
115//</IgorInstaller>
116
117//  ======================================================================================  //
118Function GHW_DwnldConfFileAndScanLocal(DownloadAnything)
119        variable DownloadAnything               //set to 0 to just intialize locally...
120        //this function scans and provides list of available releases.
121        if(!DataFolderExists("root:Packages:GHInstaller"))
122                GHW_InitializeInstaller()
123        endif
124        DFREF saveDFR=GetDataFolderDFR()                // Get reference to current data folder
125        SetDataFOlder root:Packages:GHInstaller
126        Wave/T ListOfReleases = root:Packages:GHInstaller:ListOfReleases
127        Wave/T ListOfPackages = root:Packages:GHInstaller:ListOfPackages
128        NVAR UseLocalFolder = root:Packages:GHInstaller:UseLocalFolder
129        Redimension/N=(0,3) ListOfReleases
130        Redimension/N=0 ListOfPackages
131        SVAR CurrentReleaseName = root:Packages:GHInstaller:CurrentReleaseName
132        SVAR CurrentBetaReleaseName = root:Packages:GHInstaller:CurrentBetaReleaseName
133        SVAR ListOfReleaseNames = root:Packages:GHInstaller:ListOfReleaseNames
134        SVAR ListOfBetaReleaseNames = root:Packages:GHInstaller:ListOfBetaReleaseNames
135        SVAR GUIReportActivityForUser=root:Packages:GHInstaller:GUIReportActivityForUser
136        SVAR LocalFolderPath = root:Packages:GHInstaller:LocalFolderPath
137        SVAR SelectedReleaseName = root:Packages:GHInstaller:SelectedReleaseName
138        variable fileID
139        string FileContent=""
140        string OldSelectedReleaseName = SelectedReleaseName
141       
142        if(DownloadAnything)
143                GHW_DownloadWarning()
144       
145                if(UseLocalFolder)
146                        GUIReportActivityForUser = "Reading Configuration from local folder"
147                        //source is local folder
148                        String FileNameWithPath=LocalFolderPath+ksNameOfConfFile
149                        //check for the file to exists
150                        GetFileFolderInfo/Z/Q FileNameWithPath
151                        if(V_Flag!=0)   //error, not found
152                                GHW_MakeRecordOfProgress( "Abort in : "+GetRTStackInfo(3)+"Did not find necessary configuration file "+FileNameWithPath, abortProgress=1)
153                        endif
154                        FileContent = PadString(FileContent, V_logEOF, 0x20 )
155                        Open fileID  as FileNameWithPath
156                        FBinRead fileID, FileContent
157                        close fileID
158                else            //web is the source     
159                        GUIReportActivityForUser = "Downloading Configuration from GitHub"
160                        DoUpdate /W=DownloadWarning
161                        string ConfigFileURL=ksWebAddressForConfFile+ksNameOfConfFile
162                        URLRequest/Z url=ConfigFileURL
163                        Variable error = GetRTError(1)
164                        if (error != 0 || V_Flag!=0)
165                                DoWIndow/K DownloadWarning
166                                GHW_MakeRecordOfProgress( "Abort in : "+GetRTStackInfo(3)+"Error downloading data "+ConfigFileURL, abortProgress=0)
167                                BrowseURL "https://github.com/jilavsky/SAXS_IgorCode/wiki/Installation-Problems"
168                                Abort "Could not obtain release information from Github. This is usually network issue - check your network connection. Fix if needed and try again. Check history area for any other information." 
169                        endif
170                        FileContent =  S_serverResponse
171                endif
172                //print FileContent
173                FileContent=GHI_XMLremoveComments(FileContent)          //get rid of comments, confuse rest of the code...
174                //FileContent now contains content of the file...
175                string InstallerText=GHI_XMLtagContents("IgorInstaller",FileContent)    //if nothing, wrong format
176                if(strlen(InstallerText)<10)    //no real content
177                        DoWIndow/K DownloadWarning
178                        SetDataFolder saveDFR                                   // Restore current data folder
179                        BrowseURL "https://github.com/jilavsky/SAXS_IgorCode/wiki/Installation-Problems"
180                        GHW_MakeRecordOfProgress( "Abort in : "+GetRTStackInfo(3)+" Installer text too short", abortProgress=1)
181                endif
182                //list all Installable files here so we have cache of them.
183                GHW_MakeRecordOfProgress( "Recording local installed files, this may take a while")
184                GHW_ListAllInstallableFiles()
185                DoWIndow/K DownloadWarning
186                //get what are the names of packages we should be able to find
187                GHW_ListPackagesName(InstallerText, ListOfPackages)
188                CurrentReleaseName = GHW_GetCurrentRelease(InstallerText)
189                CurrentBetaReleaseName = GHW_GetCurrentBetaRelease(InstallerText)
190                GHW_ListReleases(FileContent, ListOfReleases)
191                //Parse these for further use by GUI
192                ListOfReleaseNames=""
193                ListOfBetaReleaseNames=""
194                variable i
195                For(i=0;i<dimsize(ListOfReleases,0);i+=1)
196                        if(StringMatch(ListOfReleases[i][1], "normal" ))
197                                ListOfReleaseNames+=ListOfReleases[i][0]+";"
198                        elseif(StringMatch(ListOfReleases[i][1], "beta" ))
199                                ListOfBetaReleaseNames+=ListOfReleases[i][0]+";"
200                        endif
201                endfor
202        endif
203        //and now we have all data from XML file in Igor as Igor waves/strings. 
204        SetDataFolder saveDFR                                   // Restore current data folder
205end
206//  ======================================================================================  //
207//****************************************************************
208//****************************************************************
209Function GHW_DownloadWarning() : Panel
210        PauseUpdate; Silent 1           // building window...
211        NewPanel /K=1/N=DownloadWarning /W=(153,101,502,259) as "The code is working"
212        SVAR GUIReportActivityForUser=root:Packages:GHInstaller:GUIReportActivityForUser
213        SetDrawLayer UserBack
214        SetDrawEnv fsize= 16,textrgb= (65535,0,0)
215        DrawText 131,37,"Installer is :"
216        SetDrawEnv fsize= 16,textrgb= (65535,0,0)
217        DrawText 94,101,"This may take a while"
218        SetDrawEnv fsize= 16,textrgb= (65535,0,0)
219        DrawText 40,133,"This window will disapper when done"
220        SetVariable UserMessage,pos={26.00,49.00},size={290.00,17.00},title="Info: "
221        SetVariable UserMessage,fSize=11,fStyle=1,valueColor=(65535,0,0)
222        SetVariable UserMessage,value= root:Packages:GHInstaller:GUIReportActivityForUser,noedit= 1
223EndMacro
224
225//  ======================================================================================  //
226Function GHW_InitializeInstaller()
227        DFREF saveDFR=GetDataFolderDFR()                // Get reference to current data folder
228        NewDataFolder/O/S root:Packages
229        NewDataFolder/O/S root:Packages:GHInstaller
230        make/O/N=(0,3)/T ListOfReleases //0 will be "release", 1 normal or beta, 2 content of all tags as kw=list;
231        make/O/N=0/T ListOfPackages
232        string/g CurrentReleaseName
233        string/g SelectedReleaseName
234        string/g PopListOfReleaseNames
235        string/g ListOfReleaseNames
236        string/g ListOfBetaReleaseNames
237        string/g CurrentBetaReleaseName
238        string/g GUIReportActivityForUser
239        String/g ReleaseNotes
240        variable/g DisplayBetaReleases
241        variable/g UseLocalFolder
242        string/g LocalFolderPath
243        SetDataFolder saveDFR                                   // Restore current data folder
244end
245//  ======================================================================================  //
246Function/T GHW_GetCurrentRelease(str)
247        string str
248        string VersionCheckStr
249        VersionCheckStr = GHI_XMLtagContents("VersionCheck",str)
250        return GHI_XMLtagContents("current_release",VersionCheckStr)
251end
252//  ======================================================================================  //
253Function/T GHW_GetCurrentBetaRelease(str)
254        string str
255        string VersionCheckStr
256        VersionCheckStr = GHI_XMLtagContents("VersionCheck",str)
257        return GHI_XMLtagContents("current_beta_release",VersionCheckStr)
258end
259//  ======================================================================================  //
260Function GHW_ListPackagesName(str, tw)
261        string str
262        wave/T tw
263        Variable start=0
264        string result = ""
265        string VersionCheckStr, PackagesStr     
266        VersionCheckStr = GHI_XMLtagContents("VersionCheck",str)
267        PackagesStr = GHI_XMLtagContents("KnownPackages",VersionCheckStr)
268        String feed
269        do
270                feed = GHI_XMLtagContents("Package",PackagesStr, start=start)
271                if(strlen(feed)>0)
272                        Redimension/N=(dimsize(tw,0)+1) tw
273                        tw[dimsize(tw,0)-1] = feed
274                endif
275        while(strlen(feed))
276        return 1
277end
278//  ======================================================================================  //
279Function/T GHW_ListPlatformSpecificValues(str, Key, Platform)
280        string str, Key, Platform
281       
282        string WholeContent, ListOfNodes, ListOfRequestedKeys
283        WholeContent = GHI_XMLtagContents("PackageContent",str)
284        ListOfNodes = GHI_XMLNodeList(WholeContent)             //all nodes on this level
285        ListOfRequestedKeys = GrepList(ListOfNodes, Key )               //just the ones called what we want this time
286        string KeyAttribs, KeyStr, ResultingList
287        ResultingList=""
288        variable i, j
289        for(i=0;i<ItemsInList(ListOfRequestedKeys);i+=1)
290                KeyAttribs = GHI_XMLattibutes2KeyList(Key,WholeContent,occurance=i)
291                //choices: "", "os=Windows", "os=Macintosh", "os=all"
292                //Platform: "Windows" or "Macintosh", both include "" or "all"
293                KeyStr = GHI_XMLtagContents(Key,WholeContent,occurance=i)
294                if(strlen(KeyAttribs)<3 || stringmatch(StringByKey("os", KeyAttribs, "=", ";"),"all"))
295                        ResultingList += KeyStr+";"
296                endif
297                if(stringmatch(StringByKey("os", KeyAttribs, "=", ";"),Platform))
298                        ResultingList += KeyStr+";"
299                endif
300
301        endfor
302        return ResultingList
303end
304//  ======================================================================================  //
305Function/T GHW_ListReleases(str, Releasetw)
306        string str
307        wave/T Releasetw
308       
309        Redimension/N=(0,3) Releasetw
310        variable rel_i, beta_i
311        rel_i = 0
312        string InstallerConfigStr, ListOfReleases
313        InstallerConfigStr = GHI_XMLtagContents("InstallerConfig",str)
314        ListOfReleases = GHI_XMLNodeList(InstallerConfigStr)            //all nodes on this level
315        ListOfReleases = GrepList(ListOfReleases, "release")            //just the ones called release
316        string ReleaseAttribs, ReleaseStr, ListOfTags, TagList, Curtag
317        variable i, j
318        for(i=0;i<ItemsInList(ListOfReleases);i+=1)
319                ReleaseAttribs = GHI_XMLattibutes2KeyList("release",InstallerConfigStr,occurance=i)
320                ReleaseStr = GHI_XMLtagContents("release",InstallerConfigStr,occurance=i)
321                ListOfTags = GHI_XMLNodeList(ReleaseStr)
322                TagList=GHW_ReadReleaseContent(ReleaseStr)
323                rel_i+=1
324                redimension/N=(rel_i,3) Releasetw
325                Releasetw[rel_i-1][0]=StringByKey("name", ReleaseAttribs,"=")
326                if(Stringmatch(StringByKey("beta", ReleaseAttribs,"="),"true"))
327                        Releasetw[rel_i-1][1]= "beta"
328                else
329                        Releasetw[rel_i-1][1]= "normal"
330                endif
331                Releasetw[rel_i-1][2]=TagList
332        endfor
333end
334//  ======================================================================================  //
335Function/T GHW_ReadReleaseContent(Str)
336        string Str
337               
338        string Content=""
339        variable i, j
340        string tempStr, tmpList
341        string ListOfTags=GHI_XMLNodeList(Str)
342        string ListOfPackages, ListOfOtherStuff
343        //ListOfOtherStuff = GrepList(ListOfTags, "^((?.release).)*$")
344        ListOfOtherStuff = GrepList(ListOfTags, "Package",1)
345        ListOfPackages = GrepList(ListOfTags,"Package")
346        For(i=0;i<ItemsInList(ListOfPackages);i+=1)
347                tempStr=GHI_XMLtagContents(stringFromList(i,ListOfPackages),Str, occurance=i)
348                Content+=GHW_ReadPackageContent(tempStr)
349        endfor 
350
351        For(i=0;i<ItemsInList(ListOfOtherStuff);i+=1)
352                tempStr=GHI_XMLtagContents(stringFromList(i,ListOfOtherStuff),Str)
353                Content+=StringFromList(i,ListOfOtherStuff)+"="+tempStr+";"
354        endfor 
355        return Content
356end
357//  ======================================================================================  //
358Function/T GHW_ReadPackageContent(Str)
359        string Str
360               
361        string Content=""
362        variable i, j
363        string tempStr, tmpList, PackageName
364        string ListOfTags=GHI_XMLNodeList(Str)
365        string ListOfOtherStuff=RemoveFromList("name", ListOfTags)
366        ListOfOtherStuff=RemoveFromList("version", ListOfOtherStuff)
367        PackageName=GHI_XMLtagContents("name",Str)
368        Content+=PackageName+"="+GHI_XMLtagContents("version",Str)+";"
369
370        For(i=0;i<ItemsInList(ListOfOtherStuff);i+=1)
371                tempStr=GHI_XMLtagContents(stringFromList(i,ListOfOtherStuff),Str)
372                Content+=PackageName+"_"+StringFromList(i,ListOfOtherStuff)+"="+tempStr+";"
373        endfor 
374        return Content
375end
376//  ======================================================================================  //
377Function/T GHW_ListFilesInPckgList(Str)
378        string Str
379               
380        string Content=""
381        variable i, j
382        string tempStr, tmpList, PackageName, buf
383        buf = GHI_XMLtagContents("PackageContent",Str)
384        //print buf
385        Variable start=0
386        String feed
387        do
388                feed = GHI_XMLtagContents("File",buf, start=start)
389                //print feed
390                Content += feed+";"
391        while(strlen(feed))
392        return Content
393end
394
395
396//  ======================================================================================  //
397//  ======================================================================================  //
398//  ================================ Start of Generic XML ================================  //
399//
400//      XML support      (occurance optionally allows selecting the the occuranceth instance of xmltag), note vectors usually delimited by a space
401//
402//      GHI_XMLNodeList(buf)                                                                                    returns a list with all top level nodes in buf
403//      GHI_XMLtagContents(xmltag,buf,[occurance])                              returns the contents of xmltag
404//      GHI_XMLtagContents2List(xmltag,buf,[occurance,delimiters])      returns the contents of xmltag as a list, useful for vectors in the contents
405//      GHI_XMLattibutes2KeyList(xmltag,buf)                                            return a list with all of the attribute value pairs for xmltag
406//      GHI_XMLremoveComments(str)                                                                      remove all xml comments from str
407//
408//      for GHI_XMLtagContents() and GHI_XMLattibutes2KeyList()
409// when there are MANY occurances of xmltag, do not use occurance, but rather:
410//      Variable start=0
411//      String feed
412//      do
413//              feed = GHI_XMLtagContents("feed",buf, start=start)
414//              other code goes here ...
415//      while(strlen(feed))
416
417ThreadSafe Function/T GHI_XMLNodeList(buf)                      // returns a list of node names at top most level in buf
418        String buf
419        String name,nodes=""
420        Variable i0=0, i1,i2
421        do
422                i0 = strsearch(buf,"<",i0)                                      // find start of a tag
423                if (i0<0)
424                        break
425                endif
426                i1 = strsearch(buf," ",i0)                                      // find end of tag name using i1 or i2, end will be in i1
427                i1 = i1<0 ? Inf : i1
428                i2 = strsearch(buf,">",i0)
429                i2 = i2<0 ? Inf : i2
430                i1 = min(i1,i2)
431                if (numtype(i1) || (i1-i0-1)<1)
432                        break
433                endif
434                name = ReplaceString(";",buf[i0+1,i1-1],"_")// name cannot contain semi-colons
435                nodes += name+";"
436
437                i2 = strsearch(buf,"</"+name+">",i0)            // find the closer for this tag, check for '</name>'
438                if (i2<0)
439                        i0 = strsearch(buf,">",i1+1)                            // no '</name>', just a simple node
440                else
441                        i0 = i2 + strlen(name) + 3                              // first character after '</name>'
442                endif
443        while(i0>0)
444        return nodes
445End
446
447//ThreadSafe
448 Function/T GHI_XMLtagContents(xmltag,buf,[occurance,start])
449        String xmltag
450        String buf
451        Variable occurance                                                                      // use 0 for first occurance, 1 for second, ...
452        Variable &start                                                                         // offset in buf, start searching at buf[start], new start is returned
453                                                                                                                                // both occurance and start may be used together, but usually you only want to use one of them
454        occurance = ParamIsDefault(occurance) ? 0 : occurance
455        Variable startLocal = ParamIsDefault(start) ? 0 : start
456        startLocal = numtype(startLocal) || startLocal<1 ? 0 : round(startLocal)
457
458        Variable i0,i1
459        if (startLocal>0)
460                i0 = GHI_startOfxmltag(xmltag,buf[startLocal,Inf],occurance) + startLocal
461        else
462                i0 = GHI_startOfxmltag(xmltag,buf,occurance)
463        endif
464        if (i0<0)
465                return ""
466        endif
467        i0 = strsearch(buf,">",i0)                                              // character after '>' in intro
468        if (i0<0)                                                                                               // this is an ERROR
469                return ""
470        endif
471        i0 += 1                                                                                                 // start of contents
472
473        i1 = strsearch(buf,"</"+xmltag+">",i0)-1        // character just before closing '<tag>'
474        startLocal = strsearch(buf,">",i1)+1                    // character just after closing '<tag>'
475
476        if (i1<i0 || i1<0)
477                if (!ParamIsDefault(start))
478                        start = -1
479                endif
480                return ""
481        endif
482
483        if (!ParamIsDefault(start))
484                start = startLocal
485        endif
486
487        return buf[i0,i1]
488End
489
490//ThreadSafe
491 Function/T GHI_XMLtagContents2List(xmltag,buf,[occurance,delimiters]) //reads a tag contensts and converts it to a list
492        String xmltag
493        String buf
494        Variable occurance                              // use 0 for first occurance, 1 for second, ...
495        String delimiters                                       // characters that might be used for delimiters (NOT semi-colon), default is space, tab, cr, or nl = " \t\r\n"
496        occurance = ParamIsDefault(occurance) ? 0 : occurance
497        if (ParamIsDefault(delimiters) || strlen(delimiters)==0)
498                delimiters = " \t\r\n"                                                  // the usual white-space characters
499        endif
500
501        String str = GHI_XMLtagContents(xmltag,buf,occurance=occurance)
502        str = ReplaceString(";",str,"_")                                // cannot have any semi-colons in input string
503
504        Variable i
505        for (i=0;i<strlen(delimiters);i+=1)
506                str = ReplaceString(delimiters[i],str,";")              // replace every occurance of a character in delimiters with a semi-colon
507        endfor
508
509        do
510                str = ReplaceString(";;",str,";")                       // replace all multiple semi-colons with a single semi-colon
511        while(strsearch(str,";;",0)>=0)
512
513        if (char2num(str[0])==char2num(";"))                    // remove any leaing semi-colon
514                str = str[1,Inf]
515        endif
516        return str
517End
518
519//ThreadSafe
520 Function/T GHI_XMLattibutes2KeyList(xmltag,buf,[occurance,start])// return a list with all of the attribute value pairs for xmltag
521        String xmltag                                                                                   // name of tag to find
522        String buf                                                                                              // buf containing xml
523        Variable occurance                                                                      // use 0 for first occurance, 1 for second, ...
524        Variable &start                                                                         // offset in buf, start searching at buf[start], new start is returned
525                                                                                                                                // both occurance and start may be used together, but usually you only want to use one of them
526        occurance = ParamIsDefault(occurance) ? 0 : occurance
527        Variable startLocal = ParamIsDefault(start) ? 0 : start
528        startLocal = numtype(startLocal) || startLocal<1 ? 0 : round(startLocal)
529
530        Variable i0,i1
531        if (startLocal>0)
532                i0 = GHI_startOfxmltag(xmltag,buf[startLocal,Inf],occurance) + startLocal
533        else
534                i0 = GHI_startOfxmltag(xmltag,buf,occurance)
535        endif
536        if (i0<0)
537                return ""
538        endif
539        i0 += strlen(xmltag)+2                                                          // start of attributes
540        i1 = strsearch(buf,">",i0)-1                                            // end of attributes
541        String key, value, keyVals=""
542
543        if (i1 < i0)                                                                                    // this is an ERROR
544                startLocal = -1
545        else
546                startLocal = i1 + 2                                                             // character just after closing '>'
547                // parse buf into key=value pairs
548                buf = buf[i0,i1]
549                buf = ReplaceString("\t",buf," ")
550                buf = ReplaceString("\r",buf," ")
551                buf = ReplaceString("\n",buf," ")
552                buf = GHI_TrimFrontBackWhiteSpace(buf)
553                i0 = 0
554                do
555                        i1 = strsearch(buf,"=",i0,0)
556                        key = GHI_TrimFrontBackWhiteSpace(buf[i0,i1-1])
557                        i0 = strsearch(buf,"\"",i1,0)+1                         // character after the first double quote around value
558                        i1 = strsearch(buf,"\"",i0,0)-1                         // character before the second double quote around value
559                        value = buf[i0,i1]
560                        if (strlen(key)>0)
561                                keyVals = ReplaceStringByKey(key,keyVals,value,"=")
562                        endif
563                        i0 = strsearch(buf," ",i1,0)                                    // find space separator, set up for next key="val" pair
564                while(i0>0 && strlen(key))
565        endif
566
567        if (!ParamIsDefault(start))                                                     // set start if it was passed
568                start = startLocal
569        endif
570        return keyVals
571End
572ThreadSafe Function/T GHI_TrimFrontBackWhiteSpace(str)
573        String str
574        str = GHI_TrimLeadingWhiteSpace(str)
575        str = GHI_TrimTrailingWhiteSpace(str)
576        return str
577End
578//
579ThreadSafe Function/T GHI_TrimLeadingWhiteSpace(str)
580        String str
581        Variable i, N=strlen(str)
582        for (i=0;char2num(str[i])<=32 && i<N;i+=1)      // find first non-white space
583        endfor
584        return str[i,Inf]
585End
586//
587ThreadSafe Function/T GHI_TrimTrailingWhiteSpace(str)
588        String str
589        Variable i
590        for (i=strlen(str)-1; char2num(str[i])<=32 && i>=0; i-=1)       // find last non-white space
591        endfor
592        return str[0,i]
593End
594
595//
596
597
598ThreadSafe Function/T GHI_XMLremoveComments(str)        // remove all xml comments from str
599        String str
600        Variable i0,i1
601        do
602                i0 = strsearch(str,"<!--",0)                                    // start of a comment
603                i1 = strsearch(str,"-->",0)                                     // end of a comment
604                if (i0<0 || i1<=i0)
605                        break
606                endif
607                str[i0,i1+2] = ""                                                                       // snip out comment
608        while(1)
609        return str
610End
611//
612ThreadSafe Static Function GHI_startOfxmltag(xmltag,buf,occurance)      // returns the index into buf pointing to the start of xmltag
613        String xmltag, buf
614        Variable occurance                                                                      // use 0 for first occurance, 1 for second, ...
615
616        Variable i0,i1, i, start
617        for (i=0,i0=0;i<=occurance;i+=1)
618                start = i0
619                i0 = strsearch(buf,"<"+xmltag+" ",start)        // find start of a tag with attributes
620                i1 = strsearch(buf,"<"+xmltag+">",start)        // find start of a tag without attributes
621                i0 = i0<0 ? Inf : i0
622                i1 = i1<0 ? Inf : i1
623                i0 = min(i0,i1)
624                i0 += (i<occurance) ? strlen(xmltag)+2 : 0      // for more, move starting point forward
625        endfor
626        i0 = numtype(i0) || i0<0 ? -1 : i0
627        return i0
628End
629
630//  ================================= End of Generic XML =================================  //
631//  ======================================================================================  //
632//  ============    Index Procedure files so we can find what we have... =================  //
633//****************************************************************
634//****************************************************************
635static Function GHW_ListAllInstallableFiles()
636        String path
637        SVAR GUIReportActivityForUser=root:Packages:GHInstaller:GUIReportActivityForUser
638        //Igor Procedures
639        GUIReportActivityForUser = "Scanning local Igor Procedures"
640        DoUpdate  /W=DownloadWarning
641        GetFileFolderInfo/Q/Z/P=Igor "Igor Procedures" 
642        if(V_Flag==0)
643                GHW_ListProcFiles(S_Path,1,"UseProcedureFiles" )
644        endif
645        GetFileFolderInfo/Q/Z GHW_GetIgorUserFilesPath()+"Igor Procedures:"
646        if(V_Flag==0)
647                GHW_ListProcFiles(GHW_GetIgorUserFilesPath()+"Igor Procedures:",0,"UseProcedureFiles")
648        endif
649        //user procedures
650        GUIReportActivityForUser = "Scanning local User Procedures"
651        DoUpdate  /W=DownloadWarning
652        GetFileFolderInfo/Q/Z/P=Igor "User Procedures" 
653        if(V_Flag==0)
654                GHW_ListProcFiles(S_Path,0,"UseProcedureFiles")
655        endif
656        path = GHW_GetIgorUserFilesPath()                               //HR This is needed because of a bug in SpecialDirPath prior to 6.20B03.
657        path += "User Procedures:"                                     
658        GetFileFolderInfo/Q/Z (path)   
659        if(V_Flag==0)
660                GHW_ListProcFiles(path,0,"UseProcedureFiles")   //HR Reuse path variable
661        endif
662        //xops
663        GUIReportActivityForUser = "Scanning local xop packages"
664        DoUpdate  /W=DownloadWarning
665        GetFileFolderInfo/Q/Z/P=Igor "Igor Extensions (64-bit)"
666        if(V_Flag==0)
667                GHW_ListProcFiles(S_Path, 0,"UseProcedureFiles")
668        endif
669        GetFileFolderInfo/Q/Z (GHW_GetIgorUserFilesPath()+"Igor Extensions (64-bit):")
670        if(V_Flag==0)
671                GHW_ListProcFiles(GHW_GetIgorUserFilesPath()+"Igor Extensions (64-bit):",0,"UseProcedureFiles")
672        endif
673        GetFileFolderInfo/Q/Z/P=Igor "Igor Extensions" 
674        if(V_Flag==0)
675                GHW_ListProcFiles(S_Path, 0,"UseProcedureFiles")
676        endif
677        GetFileFolderInfo/Q/Z (GHW_GetIgorUserFilesPath()+"Igor Extensions:")
678        if(V_Flag==0)
679                GHW_ListProcFiles(GHW_GetIgorUserFilesPath()+"Igor Extensions:",0,"UseProcedureFiles")
680        endif
681        KillPath/Z tempPath
682end
683//****************************************************************
684static Function GHW_ListUserProcFiles()
685        GetFileFolderInfo/Q/Z/P=Igor "User Procedures" 
686        if(V_Flag==0)
687                GHW_ListProcFiles(S_Path,1,"UseProcedureFiles")
688        endif
689
690        String path
691                                                                                                                        //HR Create path variable for easier debugging
692        path = GHW_GetIgorUserFilesPath()                               //HR This is needed because of a bug in SpecialDirPath prior to 6.20B03.
693        path += "User Procedures:"                                              //HR Removed trailing colon though that is not necessary //JIL and HR was wrong, it fails afterwards
694        GetFileFolderInfo/Q/Z (path)   
695        if(V_Flag==0)
696                GHW_ListProcFiles(path,0,"UseProcedureFiles")   //HR Reuse path variable
697        endif
698
699        KillPath/Z tempPath
700end
701//****************************************************************
702static Function GHW_ListIgorProcFiles()
703        GetFileFolderInfo/Q/Z/P=Igor "Igor Procedures" 
704        if(V_Flag==0)
705                GHW_ListProcFiles(S_Path,1,"UseProcedureFiles" )
706        endif
707        GetFileFolderInfo/Q/Z GHW_GetIgorUserFilesPath()+"Igor Procedures:"
708        if(V_Flag==0)
709                GHW_ListProcFiles(GHW_GetIgorUserFilesPath()+"Igor Procedures:",0,"UseProcedureFiles")
710        endif
711        KillPath/Z tempPath
712end
713//****************************************************************
714static Function GHW_ListIgorExtensionsFiles()
715        GetFileFolderInfo/Q/Z/P=Igor "Igor Extensions (64-bit)"
716        if(V_Flag==0)
717                GHW_ListProcFiles(S_Path, 1,"UseProcedureFiles")
718        endif
719        GetFileFolderInfo/Q/Z (GHW_GetIgorUserFilesPath()+"Igor Extensions (64-bit):")
720        if(V_Flag==0)
721                GHW_ListProcFiles(GHW_GetIgorUserFilesPath()+"Igor Extensions (64-bit):",0,"UseProcedureFiles")
722        endif
723        KillPath/Z tempPath
724end
725//****************************************************************
726static Function/S GHW_GetIgorUserFilesPath()
727        // This should be a Macintosh path but, because of a bug prior to Igor Pro 6.20B03
728        // it may be a Windows path.
729        String path = SpecialDirPath("Igor Pro User Files", 0, 0, 0)
730        path = GHW_Windows2IgorPath(path)
731        return path
732End
733//****************************************************************
734static Function /S GHW_Windows2IgorPath(pathIn)
735        String pathIn
736        String pathOut = ParseFilePath(5, pathIn, ":", 0, 0)
737        return pathOut
738End
739
740//****************************************************************
741//****************************************************************
742static  Function GHW_ListProcFiles(PathStr, resetWaves, LocateWhere)
743        string PathStr
744        variable resetWaves
745        string LocateWhere              //name of folder where to locate the files in Procedures
746        //old version needs "UseProcedureFiles"
747       
748       
749        String abortMessage     //HR Used if we have to abort because of an unexpected error
750       
751        string OldDf=GetDataFolder(1)
752        //create location for the results waves...
753        NewDataFolder/O/S root:Packages
754        NewDataFolder/O/S $("root:Packages:"+LocateWhere)
755        //if this is top call to the routine we need to wipe out the waves so we remove old junk
756        string CurFncName=GetRTStackInfo(1)
757        string CallingFncName=GetRTStackInfo(2)
758        variable runningTopLevel=0
759        if(!stringmatch(CurFncName,CallingFncName))
760                runningTopLevel=1
761        endif
762        if(resetWaves)
763                        Make/O/N=0/T FileNames         
764                        Make/O/N=0/T PathToFiles
765                        Make/O/N=0 FileVersions
766        endif
767       
768       
769        //if this was first call, now the waves are gone.
770        //and now we need to create the output waves
771        Wave/Z/T FileNames
772        Wave/Z/T PathToFiles
773        Wave/Z FIleVersions
774        If(!WaveExists(FileNames) || !WaveExists(PathToFiles) || !WaveExists(FIleVersions))
775                Make/O/T/N=0 FileNames, PathToFIles
776                Make/O/N=0 FileVersions
777                Wave/T FileNames
778                Wave/T PathToFiles
779                Wave FileVersions
780                //I am not sure if we really need all of those declarations, but, well, it should not hurt...
781        endif
782        string str
783        //this is temporary path to the place we are looking into now... 
784        NewPath/Q/O tempPath, PathStr
785        if (V_flag != 0)                //HR Add error checking to prevent infinite loop
786                sprintf abortMessage, "Unexpected error creating a symbolic path pointing to \"%s\"", PathStr
787                str= abortMessage       // To make debugging easier
788                //Inst_Append2Log(str,0)
789                BrowseURL "https://github.com/jilavsky/SAXS_IgorCode/wiki/Installation-Problems"
790                Abort abortMessage
791        endif
792
793        //list al items in this path
794        string ItemsInTheFolder= IndexedFile(tempPath,-1,"????")+IndexedDir(tempPath, -1, 0 )
795        //HR If there is a shortcut in "Igor Procedures", ItemsInTheFolder will include something like "HDF5 Browser.ipf.lnk". Windows shortcuts are .lnk files.       
796        //remove all . files.
797        ItemsInTheFolder = GrepList(ItemsInTheFolder, "^\." ,1)
798        //Now we removed all junk files on Macs (starting with .)
799        //now lets check what each of these files are and add to the right lists or follow...
800        variable i, imax=ItemsInList(ItemsInTheFolder)
801        string tempFileName, tempScraptext, tempPathStr
802        variable IamOnMac, isItXOP
803        if(stringmatch(IgorInfo(2),"Windows"))
804                IamOnMac=0
805        else
806                IamOnMac=1
807        endif
808        For(i=0;i<imax;i+=1)
809                tempFileName = stringfromlist(i,ItemsInTheFolder)
810                GetFileFolderInfo/Z/Q/P=tempPath tempFileName
811                isItXOP = IamOnMac * stringmatch(tempFileName, "*xop*" )
812               
813                if(V_isAliasShortcut)
814                        //HR If tempFileName is "HDF5 Browser.ipf.lnk", or any other shortcut to a file, S_aliasPath is a path to a file, not a folder.
815                        //HR Thus the "NewPath tempPath" command will fail.
816                        //HR Thus tempPath will retain its old value, causing you to recurse the same folder as before, resulting in an infinite loop.
817                       
818                        //is alias, need to follow and look further. Use recursion...
819                        if(strlen(S_aliasPath)>3)               //in case user has stale alias, S_aliasPath has 0 length. Need to skip this pathological case.
820                                //HR Recurse only if S_aliasPath points to a folder. I don't really know what I'm doing here but this seems like it will prevent the infinite loop.
821                                GetFileFolderInfo/Z/Q/P=tempPath S_aliasPath   
822                                isItXOP = IamOnMac * stringmatch(S_Path, "*xop*" )
823                                if (V_flag==0 && V_isFolder&&!isItXOP)          //this is folder, so all items in the folder are included... Except XOP is folder too...
824                                        GHW_ListProcFiles(S_Path, 0,LocateWhere)
825                                elseif(V_flag==0 && (!V_isFolder || isItXOP))   //this is link to file. Need to include the info on the file...
826                                        //*************
827                                        Redimension/N=(numpnts(FileNames)+1) FileNames, PathToFiles,FileVersions
828                                        tempFileName =stringFromList(ItemsInList(S_Path,":")-1, S_Path,":")
829                                        tempPathStr = RemoveFromList(tempFileName, S_Path,":")
830                                        FileNames[numpnts(FileNames)-1] = tempFileName
831                                        PathToFiles[numpnts(FileNames)-1] = tempPathStr
832                                        //try to get version from #pragma version = ... This seems to be the most robust way I found...
833                                        NewPath/Q/O tempPath, tempPathStr
834                                        if(stringmatch(tempFileName, "*.ipf"))
835                                                Grep/P=tempPath/E="(?i)^#pragma[ ]*version[ ]*=[ ]*" tempFileName as "Clipboard"
836                                                sleep/s (0.02)
837                                                tempScraptext = GetScrapText()
838                                                if(strlen(tempScraptext)>10)            //found line with #pragma version"
839                                                        tempScraptext = replaceString("#pragma",tempScraptext,"")       //remove #pragma
840                                                        tempScraptext = replaceString("version",tempScraptext,"")               //remove version
841                                                        tempScraptext = replaceString("=",tempScraptext,"")                     //remove =
842                                                        tempScraptext = replaceString("\t",tempScraptext,"  ")                  //remove optional tabulators, some actually use them.
843                                                        tempScraptext = removeending(tempScraptext," \r")                       //remove optional tabulators, some actually use them.
844                                                        //forget about the comments behind the text.
845                                                       //str2num is actually quite clever in this and converts start of the string which makes sense.
846                                                        FileVersions[numpnts(FileNames)-1]=str2num(tempScraptext)
847                                                else             //no version found, set to NaN
848                                                        FileVersions[numpnts(FileNames)-1]=NaN
849                                                endif
850                                        else                    //no version for non-ipf files
851                                                FileVersions[numpnts(FileNames)-1]=NaN
852                                        endif
853                                        //************
854                                endif
855                        endif
856                        //and now when we got back, fix the path definition to previous or all will crash...
857                        NewPath/Q/O tempPath, PathStr
858                        if (V_flag != 0)                //HR Add error checking to prevent infinite loop
859                                sprintf abortMessage, "Unexpected error creating a symbolic path pointing to \"%s\"", PathStr
860                                str= abortMessage       // To make debugging easier
861                                Abort abortMessage
862                        endif
863                elseif(V_isFolder&&!isItXOP)   
864                        //is folder, need to follow into it. Use recursion.
865                        GHW_ListProcFiles(PathStr+tempFileName+":", 0,LocateWhere)
866                        //and fix the path back or all will fail...
867                        NewPath/Q/O tempPath, PathStr
868                        if (V_flag != 0)                //HR Add error checking to prevent infinite loop
869                                sprintf abortMessage, "Unexpected error creating a symbolic path pointing to \"%s\"", PathStr
870                                str= abortMessage       // To make debugging easier
871                                Abort abortMessage
872                        endif
873                elseif(V_isFile||isItXOP)
874                        //this is real file. Store information as needed.
875                        Redimension/N=(numpnts(FileNames)+1) FileNames, PathToFiles,FileVersions
876                        FileNames[numpnts(FileNames)-1] = tempFileName
877                        PathToFiles[numpnts(FileNames)-1] = PathStr
878                        //try to get version from #pragma version = ... This seems to be the most robust way I found...
879                        if(stringmatch(tempFileName, "*.ipf"))
880                                Grep/P=tempPath/E="(?i)^#pragma[ ]*version[ ]*=[ ]*" tempFileName as "Clipboard"
881                                sleep/s(0.02)
882                                tempScraptext = GetScrapText()
883                                if(strlen(tempScraptext)>10)            //found line with #pragma version"
884                                        tempScraptext = replaceString("#pragma",tempScraptext,"")       //remove #pragma
885                                        tempScraptext = replaceString("version",tempScraptext,"")               //remove version
886                                        tempScraptext = replaceString("=",tempScraptext,"")                     //remove =
887                                        tempScraptext = replaceString("\t",tempScraptext,"  ")                  //remove optional tabulators, some actually use them.
888                                        //forget about the comments behind the text.
889                                       //str2num is actually quite clever in this and converts start of the string which makes sense.
890                                        FileVersions[numpnts(FileNames)-1]=str2num(tempScraptext)
891                                else             //no version found, set to NaN
892                                        FileVersions[numpnts(FileNames)-1]=NaN
893                                endif
894                        else                    //no version for non-ipf files
895                                FileVersions[numpnts(FileNames)-1]=NaN
896                        endif
897                endif
898        endfor
899//      if(runningTopLevel)
900//              //some output here...
901//              print "Found   "+num2str(numpnts(FileNames))+"  files in   "+PathStr+" folder, its subfolders and linked folders and subfolders"
902//              KillPath/Z tempPath
903//      endif
904 
905        setDataFolder OldDf
906end
907//***********************************
908//***********************************
909//****************************************************************
910//****************************************************************
911static Function GHW_FindFileVersion(FilenameStr)
912        string FilenameStr
913       
914        Wave/T PathToFIles= root:Packages:UseProcedureFiles:PathToFIles
915        Wave/T FileNames=root:Packages:UseProcedureFiles:FileNames
916        Wave FileVersions =root:Packages:UseProcedureFiles:FileVersions
917        variable i, imax=Numpnts(FileNames), versionFound
918        string tempname
919        versionFound=-1
920        For(i=0;i<imax;i+=1)
921                tempname = FileNames[i]
922                if(stringmatch(tempname,FileNameStr))
923                        versionFound = FileVersions[i]
924                        return versionFound
925                endif
926        endfor
927        return -1
928end
929//****************************************************************
930//****************************************************************
931static Function GHW_FindFileVersionLocal(FilenameStr)
932        string FilenameStr
933       
934        Wave/T/Z PathToFIles= root:Packages:LocalPackageFolder:PathToFIles
935        if(WaveExists(PathToFIles))
936                Wave/T FileNames=root:Packages:LocalPackageFolder:FileNames
937                Wave FileVersions =root:Packages:LocalPackageFolder:FileVersions
938                variable i, imax=Numpnts(FileNames), versionFound
939                string tempname
940                versionFound=-1
941                For(i=0;i<imax;i+=1)
942                        tempname = FileNames[i]
943                        if(stringmatch(tempname,FileNameStr))
944                                versionFound = FileVersions[i]
945                                return versionFound
946                        endif
947                endfor
948        endif
949        return -1
950end
951//****************************************************************
952//****************************************************************
953
954//static
955Function GHW_FindVersionOfSingleFile(tempFileName,PathStr)
956        string tempFileName, PathStr
957               
958                string tempScraptext
959                Grep/P=$(PathStr)/Z/E="(?i)^#pragma[ ]*version[ ]*=[ ]*" tempFileName as "Clipboard"
960                sleep/s (0.02)
961                tempScraptext = GetScrapText()
962                if(strlen(tempScraptext)>10)            //found line with #pragma version"
963                        tempScraptext = replaceString("#pragma",tempScraptext,"")       //remove #pragma
964                        tempScraptext = replaceString("version",tempScraptext,"")               //remove version
965                        tempScraptext = replaceString("=",tempScraptext,"")                     //remove =
966                        tempScraptext = replaceString("\t",tempScraptext,"  ")                  //remove optional tabulators, some actually use them.
967                        tempScraptext = RemoveEnding(tempScraptext,"\r")                        //remove optional tabulators, some actually use them.
968                        //forget about the comments behind the text.
969                    //str2num is actually quite clever in this and converts start of the string which makes sense.
970                        return str2num(tempScraptext)
971                else             //no version found, set to NaN
972                        return NaN
973                endif
974
975end
976
977
978//****************************************************************
979//****************************************************************
980Function GHW_PrepareGUIData()
981        DFREF saveDFR=GetDataFolderDFR()                // Get reference to current data folder
982        SetDataFOlder root:Packages:GHInstaller
983
984        Wave/T ListOfPackages = root:Packages:GHInstaller:ListOfPackages
985        Wave/T ListOfReleases = root:Packages:GHInstaller:ListOfReleases
986        SVAR CurrentBetaReleaseName = root:Packages:GHInstaller:CurrentBetaReleaseName
987        SVAR CurrentReleaseName = root:Packages:GHInstaller:CurrentReleaseName
988        SVAR SelectedReleaseName = root:Packages:GHInstaller:SelectedReleaseName
989        SVAR ListOfReleaseNames = root:Packages:GHInstaller:ListOfReleaseNames
990        SVAR ListOfBetaReleaseNames = root:Packages:GHInstaller:ListOfBetaReleaseNames
991        SVAR PopListOfReleaseNames = root:Packages:GHInstaller:PopListOfReleaseNames
992        NVAR DisplayBetaReleases = root:Packages:GHInstaller:DisplayBetaReleases
993        NVAR UseLocalFolder = root:Packages:GHInstaller:UseLocalFolder
994 
995        if(DisplayBetaReleases)
996                PopListOfReleaseNames = CurrentReleaseName+";"+CurrentBetaReleaseName+";---;"+ListOfReleaseNames+";"+ListOfBetaReleaseNames+"master"+";"
997                SelectedReleaseName = CurrentReleaseName
998        else
999                PopListOfReleaseNames = CurrentReleaseName+";---;"+ListOfReleaseNames+";"
1000                SelectedReleaseName = CurrentReleaseName
1001        endif
1002        if(UseLocalFolder)
1003                PopListOfReleaseNames = "Local Folder"+";"
1004                SelectedReleaseName = "Local Folder"
1005        endif
1006        DoWIndow GH_MainPanel
1007        if(V_Flag)
1008                        PopupMenu SelectReleaseToInstall,win=GH_MainPanel ,mode=1,value= #"root:Packages:GHInstaller:PopListOfReleaseNames"
1009        endif
1010        GHW_PrepareListboxGUIData()
1011        SetDataFolder saveDFR                                   // Restore current data folder
1012end
1013//****************************************************************
1014//****************************************************************
1015
1016Function GHW_PrepareListboxGUIData()
1017//this function prepares data for GUI so they can be easily used.
1018        DFREF saveDFR=GetDataFolderDFR()                // Get reference to current data folder
1019        SetDataFOlder root:Packages:GHInstaller
1020        //expect to find below listed strings and text waves
1021        Wave/T ListOfPackages = root:Packages:GHInstaller:ListOfPackages
1022        Wave/T ListOfReleases = root:Packages:GHInstaller:ListOfReleases
1023        SVAR CurrentBetaReleaseName = root:Packages:GHInstaller:CurrentBetaReleaseName
1024        SVAR CurrentReleaseName = root:Packages:GHInstaller:CurrentReleaseName
1025        SVAR SelectedReleaseName = root:Packages:GHInstaller:SelectedReleaseName
1026        SVAR ListOfReleaseNames = root:Packages:GHInstaller:ListOfReleaseNames
1027        SVAR ListOfBetaReleaseNames = root:Packages:GHInstaller:ListOfBetaReleaseNames
1028        SVAR PopListOfReleaseNames = root:Packages:GHInstaller:PopListOfReleaseNames
1029        NVAR DisplayBetaReleases = root:Packages:GHInstaller:DisplayBetaReleases
1030        SVAR ReleaseNotes = root:Packages:GHInstaller:ReleaseNotes
1031        SVAR LocalFolderPath = root:Packages:GHInstaller:LocalFolderPath
1032        NVAR UseLocalFolder = root:Packages:GHInstaller:UseLocalFolder
1033        //need to prepare new stuff...
1034        variable NumOfReleases=DimSize(ListOfReleases, 0 )
1035        variable NumOfPackages=DimSize(ListOfPackages, 0 )
1036        make/O/T/N=(NumOfPackages,4) VersionsAndInstall
1037        make/O/N=(NumOfPackages,4) SelVersionsAndInstall
1038        Wave/T VersionsAndInstall
1039        VersionsAndInstall = ""
1040        Wave SelVersionsAndInstall
1041        SelVersionsAndInstall = 0
1042        SetDimLabel 1,0,$"Package",VersionsAndInstall
1043        SetDimLabel 1,1,$"Local ver.",VersionsAndInstall
1044        SetDimLabel 1,2,$"Release ver.",VersionsAndInstall
1045        SetDimLabel 1,3,$"Select?",VersionsAndInstall
1046        SelVersionsAndInstall[][3] =32
1047        //avoid crash at the start when list of releases is empty
1048        if(dimSize(ListOfReleases,0)<1)
1049                return 0
1050        endif
1051        //find out versions...
1052        //column 1 are Local versions, look inside local files
1053        //column 2 are remote versions in the release
1054        variable i
1055        variable TmpVer, TmpVer2
1056        string TempStr, tempKey, tempVerName
1057        string LookHere
1058        variable WhichReleaseUserWants=NaN
1059        if(StringMatch(SelectedReleaseName, "master")||UseLocalFolder)
1060                For(i=0;i<dimsize(ListOfReleases,0);i+=1)
1061                        if(StringMatch(ListOfReleases[i][0], CurrentReleaseName ))      //fake and use current release name
1062                                WhichReleaseUserWants = i
1063                                break   
1064                        endif
1065                endfor
1066       
1067        else    //normal release chosen
1068                For(i=0;i<dimsize(ListOfReleases,0);i+=1)
1069                        if(StringMatch(ListOfReleases[i][0], SelectedReleaseName ))
1070                                WhichReleaseUserWants = i
1071                                break   
1072                        endif
1073                endfor
1074        endif
1075        ReleaseNotes = ""
1076        if(StringMatch(SelectedReleaseName, "master")||UseLocalFolder || numtype(WhichReleaseUserWants)!=0)
1077                if(StringMatch(SelectedReleaseName, "master" ))
1078                        ReleaseNotes = "master = development versions in GH at this moment!"
1079                        tempVerName = "Developer"
1080                elseif(UseLocalFolder)          //local package used
1081                        ReleaseNotes = "LocalFolder = versions in : "+LocalFolderPath
1082                        tempVerName = "unknown"
1083                        GHW_DownloadWarning()
1084                        SVAR GUIReportActivityForUser=root:Packages:GHInstaller:GUIReportActivityForUser
1085                        GUIReportActivityForUser = "Reading Configuration of data in local distribution folder"
1086                        GHW_ListProcFiles(LocalFolderPath, 1, "LocalPackageFolder")
1087                        DoWIndow/K DownloadWarning
1088                else            //unknown package system
1089                        ReleaseNotes = "unknown packaged system : "
1090                        tempVerName = "unknown"
1091                endif
1092                LookHere = ListOfReleases[0][2]
1093                For(i=0;i<numpnts(ListOfPackages);i+=1)
1094                        VersionsAndInstall[i][0]=ListOfPackages[i]
1095                        TempStr = StringByKey(ListOfPackages[i]+"_VersionCheckFile", LookHere,"=",";")
1096                        TmpVer = GHW_FindFileVersion(TempStr)
1097                        TmpVer2 = GHW_FindFileVersionLocal(TempStr)
1098                        VersionsAndInstall[i][1]=num2str(TmpVer)
1099                        if(TmpVer2>0)
1100                                VersionsAndInstall[i][2]=num2str(TmpVer2)               
1101                        else
1102                                VersionsAndInstall[i][2]=tempVerName           
1103                        endif
1104                endfor
1105                KillDataFolder /Z root:Packages:LocalPackageFolder:             //this is here to find version  of packages in Loacl distribtuion folder
1106                                                                                                                                                                //delete, not necessary anymore.
1107        else
1108                LookHere = ListOfReleases[WhichReleaseUserWants][2]
1109                For(i=0;i<numpnts(ListOfPackages);i+=1)
1110                        VersionsAndInstall[i][0]=ListOfPackages[i]
1111                        TempStr = StringByKey(ListOfPackages[i]+"_VersionCheckFile", LookHere,"=",";")
1112                        TmpVer = GHW_FindFileVersion(TempStr)
1113                        VersionsAndInstall[i][1]=num2str(TmpVer)
1114                        VersionsAndInstall[i][2]=StringByKey(ListOfPackages[i], LookHere,"=",";")
1115                endfor
1116                ReleaseNotes = StringByKey("VersionComment", LookHere,"=",";")
1117        endif
1118       
1119        SetDataFolder saveDFR                                   // Restore current data folder
1120end
1121//****************************************************************
1122//****************************************************************
1123//Function/S GHW_FindNonStPckgVerNum(VersionCheckFile)
1124//      string VersionCheckFile
1125//
1126//      //find VersionCheckFIle in Subfolders of local package in root:Packages:GHInstaller:LocalFolderPath
1127//      //and find its version number
1128//
1129//     
1130//      return ""
1131//end
1132
1133//**************************************************************************************************************************************
1134//**************************************************************************************************************************************
1135Function GHW_Uninstall()
1136        DFREF saveDFR=GetDataFolderDFR()                // Get reference to current data folder
1137        SetDataFOlder root:Packages:GHInstaller
1138 
1139        Wave/T ListOfReleases = root:Packages:GHInstaller:ListOfReleases
1140        Wave SelVersionsAndInstall = root:Packages:GHInstaller:SelVersionsAndInstall
1141        Wave/T VersionsAndInstall = root:Packages:GHInstaller:VersionsAndInstall
1142        SVAR SelectedReleaseName = root:Packages:GHInstaller:SelectedReleaseName
1143        SVAR GUIReportActivityForUser=root:Packages:GHInstaller:GUIReportActivityForUser
1144        string/g ToModifyPackagesList=""
1145        string/g PackageListsToDownload=""
1146        string/g ListOfProcFilesToClose=""
1147        variable i, j
1148        variable WhichReleaseUserWants=NaN
1149        For(i=0;i<dimsize(ListOfReleases,0);i+=1)
1150                if(StringMatch(ListOfReleases[i][0], SelectedReleaseName ))
1151                        WhichReleaseUserWants = i
1152                        break   
1153                endif
1154        endfor
1155        //if using local folder, this will fial. Pick the first one here.
1156        if(numtype(WhichReleaseUserWants)!=0)
1157                WhichReleaseUserWants = 0
1158        endif
1159        string LookHere = ListOfReleases[WhichReleaseUserWants][2]
1160        For(i=0;i<dimsize(SelVersionsAndInstall,0);i+=1)
1161                if(SelVersionsAndInstall[i][3]>32)
1162                        ToModifyPackagesList+=VersionsAndInstall[i][0]+";"
1163                        PackageListsToDownload+=StringByKey(VersionsAndInstall[i][0]+"_PackageList", LookHere  , "=", ";")+";"
1164                endif
1165        endfor
1166        //print ToModifyPackagesList
1167        //print PackageListsToDownload
1168        //download xml files with list of files
1169        variable fileID
1170        string FileContent=""
1171        string ConfigFileURL, tempStr
1172        GUIReportActivityForUser = "Downloading Configuration from GitHub"
1173        GHW_DownloadWarning()
1174        GHW_MakeRecordOfProgress("Started Unistallation of the packages", header=1)
1175        NewPath /Q/Z/O IgorUserPath, SpecialDirPath("Igor Pro User Files", 0, 0, 0 )
1176        DoUpdate /W=DownloadWarning
1177        string LinksList, LinkListFixed
1178        variable ij
1179        For(i=0;i<ItemsInList(ToModifyPackagesList);i+=1)
1180                GUIReportActivityForUser = "Downloading "+StringFromList(i,PackageListsToDownload)
1181                DoUpdate /W=DownloadWarning
1182                ConfigFileURL=ksWebAddressForConfFile+StringFromList(i,PackageListsToDownload)
1183                FileContent=FetchURL(ConfigFileURL)
1184                Variable error = GetRTError(1)
1185                if (error == 0)
1186                        GHW_MakeRecordOfProgress("Downloaded file : "+ConfigFileURL)
1187                else
1188                        DoWIndow/K DownloadWarning
1189                        GHW_MakeRecordOfProgress("Abort in : "+GetRTStackInfo(3)+"Error downloading data, cannot proceed", abortProgress=1)
1190                endif
1191                FileContent=GHI_XMLremoveComments(FileContent)          //get rid of comments, confuses the rest of the code...
1192                //FileContent now contains content of the file...
1193                string InstallerText=GHI_XMLtagContents("PackageContent",FileContent)   //if nothing, wrong format
1194                if(strlen(InstallerText)<10)    //no real content
1195                        DoWIndow/K DownloadWarning
1196                        SetDataFolder saveDFR                                   // Restore current data folder
1197                        GHW_MakeRecordOfProgress("Abort in : "+GetRTStackInfo(3)+"No content came from server, cannot proceed  ", abortProgress=1)
1198                endif
1199                GUIReportActivityForUser = "Deleting files for "+StringFromList(i,PackageListsToDownload)
1200                DoUpdate /W=DownloadWarning
1201                string igorCmd
1202                string/g $(StringFromList(i,PackageListsToDownload)+"Pkcg")
1203                SVAR PackgList=$(StringFromList(i,PackageListsToDownload)+"Pkcg")
1204                //PackgList=GHW_ListFilesInPckgList(FileContent)
1205                PackgList= GHW_ListPlatformSpecificValues(FileContent, "File", IgorInfo(2))
1206//              LinksList=GHW_ListPlatformSpecificValues(FileContent, "xopLinks", IgorInfo(2))
1207//              if(stringMatch(IgorInfo(2),"Windows"))
1208//                      For(ij=0;ij<ItemsInList(LinksList);ij+=1)
1209//                              LinkListFixed=LinksList+".lnk"+";"
1210//                      endfor
1211//              else
1212//                      LinkListFixed=LinksList
1213//              endif
1214//              PackgList+=LinkListFixed
1215                For(j=0;j<ItemsInList(PackgList);j+=1)
1216                        tempStr = StringFromList(j,PackgList,";")
1217                        string FoldStr
1218                        if(strlen(tempStr)>2)           //clean up accidental empty lines
1219                                if(!stringMatch(tempStr[0],":"))
1220                                        tempStr = ":"+tempStr
1221                                endif
1222                                tempStr = replaceString("/",tempStr,":")
1223                                //tempStr = StringFromList(ItemsInList(tempStr, "/")-1, tempStr , "/")
1224                                GetFileFolderInfo/Q/Z/P=IgorUserPath  tempStr+".deleteMe"
1225                                if(V_Flag==0)           //file/xop found, get rid of it
1226                                        if(V_isFile)
1227                                                DeleteFile /P=IgorUserPath /Z tempStr+".deleteMe"
1228                                                if(V_flag!=0)
1229                                                        GHW_MakeRecordOfProgress("Could not delete "+tempStr+".deleteMe")
1230                                                else
1231                                                        GHW_MakeRecordOfProgress( "Deleted old file : "+tempStr+".deleteMe")   
1232                                                endif
1233                                        elseif(V_isFolder)
1234                                                //here is nasty overwrite using OS script...
1235                                                PathInfo IgorUserPath
1236                                                FoldStr = replaceString("::",S_Path+tempStr,":")
1237                                                FoldStr=RemoveFromList(StringFromList(0,FoldStr  , ":"), FoldStr  , ":")
1238                                                FoldStr = ParseFilePath(5, FoldStr, "\\", 0, 0)
1239                                                FoldStr = ReplaceString("\\", FoldStr, "/")
1240                                                FoldStr = "rm -Rdf  '/"+ReplaceString(".xop", FoldStr, ".xop.deleteMe")+"'"
1241                                                sprintf igorCmd, "do shell script \"%s\"", FoldStr
1242                                                //print igorCmd
1243                                                ExecuteScriptText igorCmd
1244                                                GetFileFolderInfo/Q/Z/P=IgorUserPath  tempStr+".deleteMe"
1245                                                if(V_flag==0)
1246                                                        GHW_MakeRecordOfProgress( "Could not delete folder/xop"+tempStr+".deleteMe")
1247                                                else
1248                                                        GHW_MakeRecordOfProgress( "Deleted old file : "+tempStr+".deleteMe")
1249                                                endif
1250                                        elseif(V_isAliasShortcut)
1251                                                DeleteFile /P=IgorUserPath /Z tempStr+".deleteMe"
1252                                                if(V_flag!=0)
1253                                                        GHW_MakeRecordOfProgress( "Could not delete "+tempStr+".deleteMe")
1254                                                else
1255                                                        GHW_MakeRecordOfProgress( "Deleted old file : "+tempStr+".deleteMe")   
1256                                                endif           
1257                                        endif
1258                                endif
1259                                //OK, now we can, if needed rename existing file AND keep the user folder cleaner
1260                                //now check for existing target file and delete/rename if necessary
1261                                GetFileFolderInfo/Q/Z/P=IgorUserPath  tempStr
1262                                if(V_Flag==0)           //old file/xop found, get rid of it
1263                                        if(V_isFile)
1264                                                DeleteFile /P=IgorUserPath /Z tempStr
1265                                                if(V_flag!=0)
1266                                                        MoveFile /O/P=IgorUserPath tempStr as tempStr+".deleteMe"
1267                                                        GHW_MakeRecordOfProgress( "Moved to .deleteMe existing file : "+tempStr)
1268                                                else
1269                                                        GHW_MakeRecordOfProgress( "Deleted existing file : "+tempStr)
1270                                                endif
1271                                        elseif(V_isFolder)
1272                                                MoveFolder /O/P=IgorUserPath tempStr as tempStr+".deleteMe"
1273                                                if(V_Flag==0)
1274                                                        GHW_MakeRecordOfProgress( "Moved to .deleteMe existing file : "+tempStr)
1275                                                else
1276                                                        GHW_MakeRecordOfProgress( "Could NOT move existing file : "+tempStr+" to .deleteMe")
1277                                                endif
1278                                        elseif(V_isAliasShortcut)
1279                                                DeleteFile /P=IgorUserPath /Z tempStr
1280                                                if(V_flag!=0)
1281                                                        MoveFile /O/P=IgorUserPath tempStr as tempStr+".deleteMe"
1282                                                        GHW_MakeRecordOfProgress( "Moved to .deleteMe existing file : "+tempStr)
1283                                                else
1284                                                        GHW_MakeRecordOfProgress( "Deleted existing file : "+tempStr)
1285                                                endif           
1286                                        endif
1287                                endif
1288                        endif
1289                endfor
1290        endfor 
1291        GHW_MakeRecordOfProgress( "Finished unistallation of selected packages, All done.")
1292        DoWIndow/K DownloadWarning
1293        DoAlert/T="Finished unistallation" 0, "Selected packages were uninstalled. You need to REINSTALL any packages from this GitHub repository you want to use."
1294        SetDataFolder saveDFR                                   // Restore current data folder
1295end
1296//**************************************************************************************************************************************
1297//**************************************************************************************************************************************
1298//**************************************************************************************************************************************
1299//**************************************************************************************************************************************
1300
1301Function GHW_Install()
1302        DFREF saveDFR=GetDataFolderDFR()                // Get reference to current data folder
1303        SetDataFOlder root:Packages:GHInstaller
1304 
1305        Wave/T ListOfReleases = root:Packages:GHInstaller:ListOfReleases
1306        Wave SelVersionsAndInstall = root:Packages:GHInstaller:SelVersionsAndInstall
1307        Wave/T VersionsAndInstall = root:Packages:GHInstaller:VersionsAndInstall
1308        SVAR SelectedReleaseName = root:Packages:GHInstaller:SelectedReleaseName
1309        SVAR GUIReportActivityForUser=root:Packages:GHInstaller:GUIReportActivityForUser
1310        NVAR UseLocalFolder=root:Packages:GHInstaller:UseLocalFolder
1311        SVAR LocalFolderPath=root:Packages:GHInstaller:LocalFolderPath
1312        string/g ToModifyPackagesList=""
1313        string/g PackageListsToDownload=""
1314        string/g ListOfProcFilesToClose=""
1315        string/g ListOfPackagesToInstall="Failure getting distribution data"
1316        SVAR            ListOfPackagesToInstall
1317        variable i, j
1318        variable WhichReleaseUserWants=NaN
1319        string LookHere
1320        GHW_MakeRecordOfProgress("", header=1)
1321        //special cases SelectedReleaseName : "master" and "Local Folder"
1322        if(stringmatch(SelectedReleaseName,"Local Folder"))     //using local folder.   
1323                GetFileFolderInfo/Q/Z  LocalFolderPath
1324                if(V_Flag!=0)
1325                        GHW_MakeRecordOfProgress("Abort in : "+GetRTStackInfo(3)+"Installation from local folder "+LocalFolderPath+" cannot proceed, folder not found", abortProgress=1)
1326                else
1327                        GHW_MakeRecordOfProgress("Installation from local folder "+LocalFolderPath+" started. Found the source folder. " )
1328                endif
1329                //at this moment we should have a folder called $(InternalDataName) on the desktop with the rigth ditribution files and can install them as user wants.
1330                //install packages as user requested   
1331                LookHere = ListOfReleases[0][2]
1332                ListOfPackagesToInstall =""     
1333                For(i=0;i<dimsize(SelVersionsAndInstall,0);i+=1)
1334                        if(SelVersionsAndInstall[i][3]>32)
1335                                ListOfPackagesToInstall += VersionsAndInstall[i][0]+"_"+VersionsAndInstall[i][2]+","
1336                                ToModifyPackagesList+=VersionsAndInstall[i][0]+";"
1337                                PackageListsToDownload+=StringByKey(VersionsAndInstall[i][0]+"_PackageList", LookHere  , "=", ";")+";"
1338                        endif
1339                endfor
1340                GHW_MakeRecordOfProgress("User picked following packages to install: "+PackageListsToDownload )
1341                For(i=0;i<ItemsInList(ToModifyPackagesList);i+=1)
1342                        GHW_MakeRecordOfProgress("*****   Started installation of file from  : "+StringFromList(i,PackageListsToDownload) +"  *******")
1343                        GHW_InstallPackage(LocalFolderPath,StringFromList(i,PackageListsToDownload))
1344                endfor
1345                GHW_MakeRecordOfProgress("Installation from local folder "+LocalFolderPath+" finished. All done. " )
1346                GHW_SubmitRecordToWeb(ListOfPackagesToInstall, "Local Folder", "success")
1347                DoAlert /T="Installation succesfully finished" 0, "Requested Installation finished succesfully. Delete the InstallLog.txt, if you do not need it anymore."
1348        else            //dowload folder from remote location...
1349                For(i=0;i<dimsize(ListOfReleases,0);i+=1)
1350                        if(StringMatch(ListOfReleases[i][0], SelectedReleaseName ))
1351                                WhichReleaseUserWants = i
1352                                break   
1353                        endif
1354                endfor
1355                if(stringmatch(SelectedReleaseName,"master"))
1356                        WhichReleaseUserWants = 0                               //let's get any one of the addresses and remove the name of the zip file
1357                endif                                                                                           //then append repoName-master.zip and that is current version (SAXS_IgorCode-master.zip)
1358                LookHere = ListOfReleases[WhichReleaseUserWants][2]
1359                string URLtoGet=StringByKey("SourceFileAddress", LookHere  , "=",";")
1360                //need to build name of data inside the zip file...
1361                variable ItemsInPath=ItemsInList(URLtoGet,"/")
1362                //string InternalDataName = StringFromList(ItemsInPath-3, URLtoGet, "/")        //thsi fails now on GH changing zip file links
1363                string InternalDataName = "SAXS_IgorCode"
1364                if(stringmatch(SelectedReleaseName,"master"))
1365                        URLtoGet = RemoveListItem(ItemsInPath-1, URLtoGet, "/")+"master.zip"
1366                        InternalDataName =InternalDataName+"-master"
1367                else
1368                        InternalDataName +="-"+ RemoveEnding(StringFromList(ItemsInPath-1, URLtoGet, "/"),".zip")
1369                endif
1370                GHW_MakeRecordOfProgress("Installation from Github zip source "+URLtoGet+" started. " )
1371                string FileContent
1372                variable refNum
1373                NewPath/O/C/Q userDesktop, SpecialDirPath("Desktop",0,0,0)
1374                String destinationZip = SpecialDirPath("Desktop",0,0,0)+InternalDataName+".zip"
1375                String DesktopFldr = SpecialDirPath("Desktop",0,0,0)
1376                String destinationFldr = DesktopFldr+InternalDataName
1377                variable SkipDownload=0
1378                if (GHW_FileFolderExists(destinationZip,file=1))
1379                        Doalert/T="Existing file found" 2, "The file '"+InternalDataName+".zip' already exists on the desktop. Do you want to use it [yes] or delete it and download new one? [no]"
1380                        if(V_Flag==1)
1381                                //use existing
1382                                SkipDownload = 1
1383                                GHW_MakeRecordOfProgress("Found existing "+InternalDataName+".zip file and user choose to use it. " )
1384                        elseif(V_Flag==2)
1385                                DeleteFile /P=userDesktop (InternalDataName+".zip") 
1386                                GHW_MakeRecordOfProgress("Found existing "+InternalDataName+".zip file and user choose to delete it. " )
1387                        else
1388                                GHW_MakeRecordOfProgress("Found existing "+InternalDataName+".zip file and user choose to abort. ", abortprogress=1 )
1389                        endif
1390                endif
1391                if(!SkipDownload)
1392                        GHW_DownloadWarning()
1393                        GUIReportActivityForUser = "Downloading Package zip file from GitHub"
1394                        GHW_MakeRecordOfProgress("Downloading Package zip file "+URLtoGet+" from GitHub " )
1395                        FileContent=FetchURL(URLtoGet)
1396                        Variable error = GetRTError(1)
1397                        if (error != 0)
1398                                DoWIndow/K DownloadWarning
1399                                GHW_MakeRecordOfProgress("Abort in : "+GetRTStackInfo(3)+"Error Downloading Package zip file "+URLtoGet+" from GitHub.", abortprogress=0)
1400                                print "**************************************************************************************************************************************"
1401                                print "**************************************************************************************************************************************"
1402                                print "Instructions for fix : "
1403                                print "Download of distribution zip file : "+ URLtoGet + "   failed."
1404                                print "This is typically firewall/network problem beyond installer control"
1405                                print "You need to download this file manually using web browser"
1406                                print "Place it on Desktop and unzip - make sure that a folder with same name as the zip file is created on the desktop"
1407                                print "Now start the installation again, but check \"Use local folder?\" checkbox and point installer to the newly created folder. Install from there."
1408                                print "**************************************************************************************************************************************"
1409                                print "**************************************************************************************************************************************"
1410                                DoAlert /T="Download error, installer will abort." 0, "Download of distribution file failed. See history area for instructions"
1411                                BrowseURL "https://github.com/jilavsky/SAXS_IgorCode/wiki/Installation-Problems"
1412                                abort
1413                        endif
1414                        sleep/S 3               //just to flush the data to disk and avoid getting ahead of system with reading file in cache.
1415                        //                      str= "Done downloading distribution zip file, got : "+num2str(1.0486*strlen(fileBytes)/(1024*1024))+" Mbytes"
1416                        //                      Inst_Append2Log(str,0)
1417                        Open/P=userDesktop  refNum as (InternalDataName+".zip")
1418                        FBinWrite refNum, FileContent
1419                        Close refNum
1420                        FileContent=""
1421                        DoWIndow/K DownloadWarning
1422                endif
1423                //the distribution zip file should be on the desktop.
1424                variable err
1425                GHW_DownloadWarning()
1426                if(stringmatch(IgorInfo(2),"Windows"))
1427                        //WIndows, need to get user to unzip the file
1428                        GUIReportActivityForUser = "Unzipping "+InternalDataName+".zip file."
1429                        GHW_MakeRecordOfProgress("Windows : Unzipping the file "+InternalDataName+".zip file. " )       
1430                        GHW_UnzipFileOnDesktopWindows(InternalDataName+".zip", InternalDataName, 0)
1431                else
1432                        //unzip on Mac using script.
1433                        GUIReportActivityForUser = "Unzipping "+InternalDataName+".zip file."
1434                        GHW_MakeRecordOfProgress("Macintosh : unzipping "+InternalDataName+".zip file." )
1435                        err = GHW_UnZipOnMac(InternalDataName+".zip",DesktopFldr,deleteZip=0, overWrite=1, printIt=1)
1436                        if(err)
1437                                GHW_MakeRecordOfProgress("Abort in : "+GetRTStackInfo(3)+"Error in unzipping of "+InternalDataName+".zip file on OSX.", abortprogress=1 )
1438                        endif
1439                endif
1440                DoWIndow/K DownloadWarning
1441                //at this moment we should have a folder called $(InternalDataName) on the desktop with the rigth ditribution files and can install them as user wants.
1442                //install packages as user requested   
1443                ListOfPackagesToInstall =""     
1444                For(i=0;i<dimsize(SelVersionsAndInstall,0);i+=1)
1445                        if(SelVersionsAndInstall[i][3]>32)
1446                                ListOfPackagesToInstall += VersionsAndInstall[i][0]+"_"+VersionsAndInstall[i][2]+","
1447                                ToModifyPackagesList+=VersionsAndInstall[i][0]+";"
1448                                PackageListsToDownload+=StringByKey(VersionsAndInstall[i][0]+"_PackageList", LookHere  , "=", ";")+";"
1449                        endif
1450                endfor
1451                GHW_MakeRecordOfProgress("User picked following packages to install: "+PackageListsToDownload )
1452                For(i=0;i<ItemsInList(ToModifyPackagesList);i+=1)
1453                        GHW_MakeRecordOfProgress("*****   Started installation of file from  : "+StringFromList(i,PackageListsToDownload) +"  *******")
1454                        GHW_InstallPackage(DesktopFldr+InternalDataName,StringFromList(i,PackageListsToDownload))
1455                endfor
1456                GHW_MakeRecordOfProgress("Installation from local folder "+LocalFolderPath+" finished. All done. " )
1457                GHW_SubmitRecordToWeb(ListOfPackagesToInstall, SelectedReleaseName, "success")
1458                DoAlert /T="Installation succesfully finished" 0, "Requested Installation finished succesfully. Igor will next try to delete distribution zip file, folder with unzipped data, and InstallLog.txt. Let it do so unless you expect to need them. "
1459                DeleteFile /P=userDesktop/Z  InternalDataName+".zip"
1460                DeleteFile /P=userDesktop/Z  "InstallRecord.log"
1461                DeleteFolder /P=userDesktop/Z  InternalDataName
1462        endif   
1463        SetDataFolder saveDFR                                   // Restore current data folder
1464end
1465//**************************************************************************************************************************************
1466//**************************************************************************************************************************************
1467//PackageListsToDownload contains WhichPackages
1468//SelectedReleaseName contains InstallMethodType if "Local Folder" or Master,
1469Function GHW_SubmitRecordToWeb(WhichPackages, InstallMethodType, ResultMessage)
1470        string WhichPackages, ResultMessage, InstallMethodType
1471
1472        string Accesskey="IrenaNikaInstallations"
1473        string PackagesInstalled=WhichPackages
1474        string IgorVersionStr=IgorInfo(2)+" "+num2str(IgorVersion())
1475        string DataPath=SpecialDirPath("Igor Pro User Files", 0, 0, 0 )
1476        string DownloadType=InstallMethodType
1477        string Success=ResultMessage
1478       
1479        string pathtourl=""
1480        pathtourl = strConstRecordwwwAddress
1481        pathtourl += "key="+Accesskey+"&"
1482        pathtourl += "packages="+PackagesInstalled+"&"
1483        pathtourl += "igor_version="+IgorVersionStr+"&"
1484        pathtourl += "path="+DataPath+"&"
1485        pathtourl += "install_method="+DownloadType+"&"
1486        pathtourl += "status="+Success 
1487        pathtourl = ReplaceString(" ", pathtourl, "%20")
1488        //print pathtourl       
1489        URLRequest /TIME=2/Z url=pathtourl
1490        //print V_Flag
1491        //print V_responseCode
1492        //print S_serverResponse
1493end
1494//**************************************************************************************************************************************
1495//**************************************************************************************************************************************
1496
1497Static Function GHW_UnZipOnMac(zipFile,DestFolder,[deleteZip,overWrite,printIt])
1498        String zipFile                          // name of zip file to expand
1499        String DestFolder                       // folder to put results (defaults to same folder as zip file"
1500        Variable deleteZip              // if True, delete the zip file when done (default is NO delete)
1501        Variable overWrite              // if True, over write existing files when un-zipping (default is NOT overwite)
1502        Variable printIt
1503        deleteZip = ParamIsDefault(deleteZip) || numtype(deleteZip) ? 0 : deleteZip
1504        overWrite = ParamIsDefault(overWrite) || numtype(overWrite) ? 0 : overWrite
1505        printIt = ParamIsDefault(printIt) || numtype(printIt) ? strlen(GetRTStackInfo(2))==0 : printIt
1506        String str=""
1507        if (!StringMatch(IgorInfo(2),"Macintosh"))
1508                GHW_MakeRecordOfProgress("Macintosh : ERROR -- UnZipOnMac() only works on Macintosh")
1509                return 1
1510        endif
1511
1512        //create Path to Desktop
1513        NewPath/O Desktop, SpecialDirPath("Desktop", 0, 0, 0 )
1514        // check for valid input zip file
1515        // check for valid input zip file
1516        GetFileFolderInfo/P=Desktop/Q/Z=1 zipFile
1517        if (V_Flag || !V_isFile)
1518                if (printIt)
1519                        sprintf str, "Macintosh : Error - did not find valid \"%s\" file\r",zipFile
1520                        GHW_MakeRecordOfProgress(str)
1521                endif
1522                return 1
1523        endif
1524        printIt = StringMatch(S_Path,zipFile) ? printIt : 1
1525
1526        zipFile = S_Path
1527        if (!StringMatch(ParseFilePath(4,zipFile,":",0,0),"zip"))
1528                if (printIt)
1529                        sprintf str, "Macintosh : ERROR -- \"%s\" is not a zip file\r",zipFile
1530                        GHW_MakeRecordOfProgress(str)
1531                endif
1532                return 1
1533        endif
1534
1535        // check for valid destination folder
1536        if (strlen(DestFolder)<1)
1537                DestFolder = ParseFilePath(1,zipFile,":",1,0)
1538        endif
1539        GetFileFolderInfo/P=Desktop/Q/Z=1 DestFolder
1540        if (V_Flag || !V_isFolder)
1541                if (printIt)
1542                        GHW_MakeRecordOfProgress("Macintosh : ERROR -- destination folder not found, nothing done")
1543                endif
1544                return 1
1545        endif
1546        DestFolder = S_Path
1547        printIt = StringMatch(S_Path,DestFolder) ? printIt : 1
1548
1549        // get POSIX versions of paths for the shell script
1550        String zipFilePOSIX = ParseFilePath(5,zipFile,"/",0,0)
1551        String DestFolderPOSIX = ParseFilePath(5,DestFolder,"/",0,0)
1552
1553        // create the shell script and execute it
1554        String cmd, switches=SelectString(overWrite,""," -o")
1555        sprintf cmd, "do shell script \"unzip %s \\\"%s\\\" -d \\\"%s\\\"\"", switches, zipFilePOSIX,DestFolderPOSIX
1556        ExecuteScriptText/Z/UNQ cmd                                             //returns something only on error
1557        if (V_flag)
1558                sprintf str, "\r  ERROR -unzipping,  V_flag =",V_flag
1559                GHW_MakeRecordOfProgress(str)
1560                sprintf str, "cmd = ",ReplaceString("\n",cmd,"\r")
1561                GHW_MakeRecordOfProgress(str)
1562                sprintf str, "\r  S_value =",ReplaceString("\n",S_value,"\r")
1563                GHW_MakeRecordOfProgress(str)
1564                DoAlert /T="Error, Instructions how to fix it : " 0, "Automatic unzip of distribution zip file : "+zipFile+" on Desktop failed. This installation will now abort. Unzip the file to Desktop manually. Restart and install from (the just created) local folder."
1565                DoAlert /T="And now - help me!" 0, "I am unable to reproduce this bug. Please send me, ilavsky@aps.anl.gov, the InstallRecord.log file from the desktop. There should be error message there which may help."
1566                return V_flag                                                                   // all done, to not consider deleting the zip file
1567        elseif (printIt)
1568                sprintf str, "unzipping \"%s\"  -->  \"%s\"\r", zipFilePOSIX, DestFolderPOSIX
1569                GHW_MakeRecordOfProgress(str)
1570        endif
1571
1572        // optionally delete the zip file if requested
1573        if (deleteZip)
1574                DeleteFile/M="Delete the zip file"/Z zipFile
1575                if (V_flag==0 && printIt)
1576                        sprintf str, "Macintosh : Deleted:  \"%s\"\r", zipFile
1577                        GHW_MakeRecordOfProgress(str)
1578                endif
1579        endif
1580        return V_flag
1581End
1582//**************************************************************************************************************************************
1583//**************************************************************************************************************************************
1584Function GHW_UnzipFileOnDesktopWindows(ZipFileName, UnzippedFolderName, deleteSource)
1585        string ZipFileName                      // name of zip file on Desktop
1586        string UnzippedFolderName       //the folder name inside the zip file
1587        variable deleteSource           // also delete the source zip file if this is TRUE
1588        if (!StringMatch(IgorInfo(2),"Windows"))
1589                GHW_MakeRecordOfProgress("Abort in : "+GetRTStackInfo(3)+" ERROR -- UnzipFileOnDesktopWindows() only works on Windows",abortprogress=1)
1590                return 1
1591        endif
1592
1593        //create Path to Desktop
1594        NewPath/O Desktop, SpecialDirPath("Desktop", 0, 0, 0 )
1595        string strToDesktop = SpecialDirPath("Desktop", 0, 1, 0 )
1596        string strToTemp = SpecialDirPath("Temporary", 0, 1, 0 )
1597        //check that the file exists
1598        GetFileFolderInfo /P=Desktop /Q/Z=1 ZipFileName
1599        if(V_Flag!=0)
1600                BrowseURL "https://github.com/jilavsky/SAXS_IgorCode/wiki/Installation-Problems"
1601                GHW_MakeRecordOfProgress("Zip file not found on Desktop" )     
1602                Abort "Zip file not found on Desktop"
1603        endif   
1604
1605        //for WIndows 8 and higher, use new method using PowerShell
1606  variable WinVersion=str2num(StringByKey("OS", igorinfo(3))[7,12])             //this extracts simply number from OS key, should be 7, 8, 10 for now.
1607  variable success
1608  if (WinVersion>7.99)                          //Powershell is available only on Windows 8+
1609                GHW_MakeRecordOfProgress("Windows : Unzipping the file "+ZipFileName+" using Windows 8+ method. " )     
1610                success = GHW_unzipArchive(strToDesktop+ZipFileName, strToDesktop)
1611                if(success<0.5)         //0 means code failed.
1612                        GHW_MakeRecordOfProgress("Windows : FAILED Unzipping the file "+ZipFileName+" using Windows 8+ method. " )     
1613                        Abort "FAILED Unzipping the file "+ZipFileName+" using Windows 8+ method."
1614                endif
1615        else
1616                //create the command file on the desktop, this is Zipjs.bat per
1617                //from <a href="https://github.com/npocmaka/batch.scripts/blob/master/hybrids/jscript/zipjs.bat" title="https://github.com/npocmaka/batch.scripts/blob/master/hybrids/jscript/zipjs.bat" rel="nofollow">https://github.com/npocmaka/batch.scripts/blob/master/hybrids/jscript/zi...</a>
1618                DoWindow zipjsbat
1619                if(V_Flag==0)
1620                        GHW_CreateZipjsbat()   
1621                endif
1622                SaveNotebook/O/P=Desktop zipjsbat as "zipjs.bat"
1623           sleep/s 5  //wait to flush buffer so the file actually exists...
1624                DoWindow/K zipjsbat
1625                //created the zipjs.bat command file which will unzip the file for us, note must kill the internal Notebook
1626                //or Igor will held the file and Windows will throw errors
1627                //now create cmd in line with
1628                //             zipjs.bat unzip -source C:\myDir\myZip.zip -destination C:\MyDir -keep no -force no
1629                // the destination folder is created by the script.
1630                // -keep yes will keep the content of the zip file, -force yes will overwrite the tempfolder for the data if exists
1631                // be careful, -force yes will wipe out the destination, if exists, so make sure the data are directed to non-existing folder.
1632                string cmd = strToDesktop+"zipjs.bat unzip -source "
1633                cmd +=strToDesktop+stringFromList(ItemsInList(ZipFileName,":")-1, ZipFileName,":")+" -destination "
1634                cmd +=strToTemp+"IgorCode -keep yes -force yes"
1635                ExecuteScriptText cmd
1636           sleep/s 5  //wait to flush buffer so the file actually exists...
1637                //delete the batch file to clean up...
1638                DeleteFile /P=Desktop /Z  "zipjs.bat"
1639                if(deleteSource)
1640                        DeleteFile /P=Desktop /Z  ZipFileName           
1641                endif
1642                GHW_MakeRecordOfProgress("Windows : Unzipped file "+ZipFileName+" to temp folder")
1643                //now the folder IgorCode is in the Desktop/ZipFileTempFldr
1644                //and we need it in Desktop...
1645                //NewPath /C /O/Q/Z tempForIgorCode, strToDesktop+"IgorCode"
1646                cmd ="Xcopy  "+strToTemp+"IgorCode\\"+UnzippedFolderName+"\\*    "+strToDesktop+UnzippedFolderName+"\\ /s /y"
1647                //cmd =strToDesktop+"moveData.bat "+strToDesktop+"IgorCode\\IgorCode\\    "+strToDesktop+"IgorCode"
1648                ExecuteScriptText cmd
1649                GHW_MakeRecordOfProgress("Windows : Copied unzipped file "+ZipFileName+" from temp folder to folder : "+strToDesktop+UnzippedFolderName)
1650                sleep/s 5               //wait for some time to get OS chance to sort things out...
1651                //check that a file exists so we know the zip worked, and if not, let user unzip manually...
1652        endif
1653
1654        String TestFilePath = strToDesktop+UnzippedFolderName
1655        GetFileFolderInfo /Q/Z=1 TestFilePath
1656        if(V_Flag!=0)
1657                GHW_MakeRecordOfProgress("Windows : Unzipping/copy of file "+ZipFileName+" failed. Asked user to unzip manually.")
1658                DoAlert 0, "Uzipping was NOT succesful, Fix this: On your Desktop is file IgorCode.zip, manually copy the folder from inside of this zip file to desktop. THEN push \"OK\" button so the installation can continue"
1659                GetFileFolderInfo /Q/Z=1 TestFilePath
1660                if(V_Flag!=0)
1661                        GHW_MakeRecordOfProgress("Windows : Even request for user to manually unzip the "+ZipFileName+" failed. aborting. ")
1662                        BrowseURL "https://github.com/jilavsky/SAXS_IgorCode/wiki/Installation-Problems"
1663                        Abort "Still unable to find the Source folder. Download the distribution zip file manually, uzip, place in same location as this Igor experiment and run Use Local Folder method. Aborting. "
1664                        return 1
1665                endif
1666        endif
1667        return 0
1668End     
1669//
1670Static Function GHW_CreateZipjsbat()
1671        //from https://github.com/npocmaka/batch.scripts/blob/master/hybrids/jscript/zipjs.bat
1672        //how to use see
1673        //http://stackoverflow.com/questions/28043589/how-can-i-compress-zip-and-uncompress-unzip-files-and-folders-with-bat
1674        // this is short summary of the description there. Can unzpi, zip and do much more...
1675        //
1676        //// unzip content of a zip to given folder.content of the zip will be not preserved (-keep no).Destination will be not overwritten (-force no)
1677        //call zipjs.bat unzip -source C:\myDir\myZip.zip -destination C:\MyDir -keep no -force no
1678        //
1679        //// lists content of a zip file and full paths will be printed (-flat yes)
1680        //call zipjs.bat list -source C:\myZip.zip\inZipDir -flat yes
1681        //
1682        //// lists content of a zip file and the content will be list as a tree (-flat no)
1683        //call zipjs.bat list -source C:\myZip.zip -flat no
1684        //
1685        //// prints uncompressed size in bytes
1686        //zipjs.bat getSize -source C:\myZip.zip
1687        //
1688        //// zips content of folder without the folder itself
1689        //call zipjs.bat zipDirItems -source C:\myDir\ -destination C:\MyZip.zip -keep yes -force no
1690        //
1691        //// zips file or a folder (with the folder itslelf)
1692        //call zipjs.bat zipItem -source C:\myDir\myFile.txt -destination C:\MyZip.zip -keep yes -force no
1693        //
1694        //// unzips only part of the zip with given path inside
1695        //call zipjs.bat unZipItem -source C:\myDir\myZip.zip\InzipDir\InzipFile -destination C:\OtherDir -keep no -force yes
1696        //call zipjs.bat unZipItem -source C:\myDir\myZip.zip\InzipDir -destination C:\OtherDir
1697        //
1698        //// adds content to a zip file
1699        //call zipjs.bat addToZip -source C:\some_file -destination C:\myDir\myZip.zip\InzipDir -keep no
1700        //call zipjs.bat addToZip -source  C:\some_file -destination C:\myDir\myZip.zip
1701
1702
1703        String nb = "zipjsbat"
1704        NewNotebook/N=$nb/F=0/V=0/K=1/W=(321,81.5,820.5,376.25)
1705        Notebook $nb defaultTab=20, statusWidth=252
1706        Notebook $nb font="Arial", fSize=10, fStyle=0, textRGB=(0,0,0)
1707        Notebook $nb text="@if (@X)==(@Y) @end /* JScript comment\r"
1708        Notebook $nb text="\t@echo off\r"
1709        Notebook $nb text="\t\r"
1710        Notebook $nb text="\trem :: the first argument is the script name as it will be used for proper help message\r"
1711        Notebook $nb text="\tcscript //E:JScript //nologo \"%~f0\" \"%~nx0\" %*\r"
1712        Notebook $nb text="\r"
1713        Notebook $nb text="\texit /b %errorlevel%\r"
1714        Notebook $nb text="\t\r"
1715        Notebook $nb text="@if (@X)==(@Y) @end JScript comment */\r"
1716        Notebook $nb text="\r"
1717        Notebook $nb text="\r"
1718        Notebook $nb text="/*\r"
1719        Notebook $nb text="Compression/uncompression command-line tool that uses Shell.Application and WSH/Jscript -\r"
1720        Notebook $nb text="http://msdn.microsoft.com/en-us/library/windows/desktop/bb774085(v=vs.85).aspx\r"
1721        Notebook $nb text="\r"
1722        Notebook $nb text="Some resources That I've used:\r"
1723        Notebook $nb text="http://www.robvanderwoude.com/vbstech_files_zip.php\r"
1724        Notebook $nb text="https://code.google.com/p/jsxt/source/browse/trunk/js/win32/ZipFile.js?r=161\r"
1725        Notebook $nb text="\r"
1726        Notebook $nb text="\r"
1727        Notebook $nb text="\r"
1728        Notebook $nb text="\r"
1729        Notebook $nb text="UPDATE *17-03-15*\r"
1730        Notebook $nb text="\r"
1731        Notebook $nb text="Devnullius Plussed noticed a bug in ZipDirItems  and ZipItem functions (now fixed)\r"
1732        Notebook $nb text="And also following issues (at the moment not handled by the script):\r"
1733        Notebook $nb text="- if there's not enough space on the system drive (usually C:\\) the script could produce various errors "
1734        Notebook $nb text=", most often the script halts.\r"
1735        Notebook $nb text="- Folders and files that contain unicode symbols cannot be handled by Shell.Application object.\r"
1736        Notebook $nb text="\r"
1737        Notebook $nb text="UPDATE *24-03-15*\r"
1738        Notebook $nb text="\r"
1739        Notebook $nb text="Error messages are caught in waitforcount method and if shuch pops-up the script is stopped.\r"
1740        Notebook $nb text="As I don't know hoe to check the content of the pop-up the exact reason for the failure is not given\r"
1741        Notebook $nb text="but only the possible reasons.\r"
1742        Notebook $nb text="\r"
1743        Notebook $nb text="------\r"
1744        Notebook $nb text="It's possible to be ported for C#,Powershell and JScript.net so I'm planning to do it at some time.\r"
1745        Notebook $nb text="\r"
1746        Notebook $nb text="For sure there's a lot of room for improvements and optimization and I'm absolutely sure there are some "
1747        Notebook $nb text="bugs\r"
1748        Notebook $nb text="as the script is big enough to not have.\r"
1749        Notebook $nb text="\r"
1750        Notebook $nb text="\r"
1751        Notebook $nb text="\r"
1752        Notebook $nb text="!!!\r"
1753        Notebook $nb text="For suggestions contact me at - npocmaka@gmail.com\r"
1754        Notebook $nb text="!!!\r"
1755        Notebook $nb text="\r"
1756        Notebook $nb text="*/\r"
1757        Notebook $nb text="\r"
1758        Notebook $nb text="\r"
1759        Notebook $nb text="//////////////////////////////////////\r"
1760        Notebook $nb text="//   CONSTANTS\r"
1761        Notebook $nb text="\r"
1762        Notebook $nb text="// TODO - Shell.Application and Scripting.FileSystemObject objects could be set as global variables to a"
1763        Notebook $nb text="void theit creation\r"
1764        Notebook $nb text="// in every method.\r"
1765        Notebook $nb text="\r"
1766        Notebook $nb text="//empty zip character sequense\r"
1767        Notebook $nb text="var ZIP_DATA= \"PK\" + String.fromCharCode(5) + String.fromCharCode(6) + \"\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0"
1768        Notebook $nb text="\\0\\0\";\r"
1769        Notebook $nb text="\r"
1770        Notebook $nb text="var SLEEP_INTERVAL=200;\r"
1771        Notebook $nb text="\r"
1772        Notebook $nb text="//copy option(s) used by Shell.Application.CopyHere/MoveHere\r"
1773        Notebook $nb text="var NO_PROGRESS_BAR=4;\r"
1774        Notebook $nb text="\r"
1775        Notebook $nb text="\r"
1776        Notebook $nb text="//oprions used for zip/unzip\r"
1777        Notebook $nb text="var force=true;\r"
1778        Notebook $nb text="var move=false;\r"
1779        Notebook $nb text="\r"
1780        Notebook $nb text="//option used for listing content of archive\r"
1781        Notebook $nb text="var flat=false;\r"
1782        Notebook $nb text="\r"
1783        Notebook $nb text="var source=\"\";\r"
1784        Notebook $nb text="var destination=\"\";\r"
1785        Notebook $nb text="\r"
1786        Notebook $nb text="var ARGS = WScript.Arguments;\r"
1787        Notebook $nb text="var scriptName=ARGS.Item(0);\r"
1788        Notebook $nb text="\r"
1789        Notebook $nb text="//\r"
1790        Notebook $nb text="//////////////////////////////////////\r"
1791        Notebook $nb text="\r"
1792        Notebook $nb text="//////////////////////////////////////\r"
1793        Notebook $nb text="//   ADODB.Stream extensions\r"
1794        Notebook $nb text="\r"
1795        Notebook $nb text="if ( ! this.ADODB ) {\r"
1796        Notebook $nb text="\tvar ADODB = {};\r"
1797        Notebook $nb text="}\r"
1798        Notebook $nb text="\r"
1799        Notebook $nb text="if ( ! ADODB.Stream ) {\r"
1800        Notebook $nb text="\tADODB.Stream = {};\r"
1801        Notebook $nb text="}\r"
1802        Notebook $nb text="\r"
1803        Notebook $nb text="// writes a binary data to a file\r"
1804        Notebook $nb text="if ( ! ADODB.Stream.writeFile ) {\r"
1805        Notebook $nb text="\tADODB.Stream.writeFile = function(filename, bindata)\r"
1806        Notebook $nb text="\t{\r"
1807        Notebook $nb text="        var stream = new ActiveXObject(\"ADODB.Stream\");\r"
1808        Notebook $nb text="        stream.Type = 2;\r"
1809        Notebook $nb text="        stream.Mode = 3;\r"
1810        Notebook $nb text="        stream.Charset =\"ASCII\";\r"
1811        Notebook $nb text="        stream.Open();\r"
1812        Notebook $nb text="        stream.Position = 0;\r"
1813        Notebook $nb text="        stream.WriteText(bindata);\r"
1814        Notebook $nb text="        stream.SaveToFile(filename, 2);\r"
1815        Notebook $nb text="        stream.Close();\r"
1816        Notebook $nb text="\t\treturn true;\r"
1817        Notebook $nb text="\t};\r"
1818        Notebook $nb text="}\r"
1819        Notebook $nb text="\r"
1820        Notebook $nb text="//\r"
1821        Notebook $nb text="//////////////////////////////////////\r"
1822        Notebook $nb text="\r"
1823        Notebook $nb text="//////////////////////////////////////\r"
1824        Notebook $nb text="//   common\r"
1825        Notebook $nb text="\r"
1826        Notebook $nb text="if ( ! this.Common ) {\r"
1827        Notebook $nb text="\tvar Common = {};\r"
1828        Notebook $nb text="}\r"
1829        Notebook $nb text="\r"
1830        Notebook $nb text="if ( ! Common.WaitForCount ) {\r"
1831        Notebook $nb text="\tCommon.WaitForCount = function(folderObject,targetCount,countFunction){\r"
1832        Notebook $nb text="\t\tvar shell = new ActiveXObject(\"Wscript.Shell\");\r"
1833        Notebook $nb text="\t\twhile (countFunction(folderObject) < targetCount ){\r"
1834        Notebook $nb text="\t\t\tWScript.Sleep(SLEEP_INTERVAL);\r"
1835        Notebook $nb text="\t\t\t//checks if a pop-up with error message appears while zipping\r"
1836        Notebook $nb text="\t\t\t//at the moment I have no idea how to read the pop-up content\r"
1837        Notebook $nb text="\t\t\t// to give the exact reason for failing\r"
1838        Notebook $nb text="\t\t\tif (shell.AppActivate(\"Compressed (zipped) Folders Error\")) {\r"
1839        Notebook $nb text="\t\t\t\tWScript.Echo(\"Error While zipping\");\r"
1840        Notebook $nb text="\t\t\t\tWScript.Echo(\"\");\r"
1841        Notebook $nb text="\t\t\t\tWScript.Echo(\"Possible reasons:\");\r"
1842        Notebook $nb text="\t\t\t\tWScript.Echo(\" -source contains filename(s) with unicode characters\");\r"
1843        Notebook $nb text="\t\t\t\tWScript.Echo(\" -produces zip exceeds 8gb size (or 2,5 gb for XP and 2003)\");\r"
1844        Notebook $nb text="\t\t\t\tWScript.Echo(\" -not enough space on system drive (usually C:\\\\)\");\r"
1845        Notebook $nb text="\t\t\t\tWScript.Quit(432);\r"
1846        Notebook $nb text="\t\t\t}\r"
1847        Notebook $nb text="\t\t\t\r"
1848        Notebook $nb text="\t\t}\r"
1849        Notebook $nb text="\t}\r"
1850        Notebook $nb text="}\r"
1851        Notebook $nb text="\r"
1852        Notebook $nb text="if ( ! Common.getParent ) {\r"
1853        Notebook $nb text="\tCommon.getParent = function(path){\r"
1854        Notebook $nb text="\t\tvar splitted=path.split(\"\\\\\");\r"
1855        Notebook $nb text="\t\tvar result=\"\";\r"
1856        Notebook $nb text="\t\tfor (var s=0;s<splitted.length-1;s++){\r"
1857        Notebook $nb text="\t\t\tif (s==0) {\r"
1858        Notebook $nb text="\t\t\t\tresult=splitted[s];\r"
1859        Notebook $nb text="\t\t\t} else {\r"
1860        Notebook $nb text="\t\t\t\tresult=result+\"\\\\\"+splitted[s];\r"
1861        Notebook $nb text="\t\t\t}\r"
1862        Notebook $nb text="\t\t}\r"
1863        Notebook $nb text="\t\treturn result;\r"
1864        Notebook $nb text="\t}\r"
1865        Notebook $nb text="}\r"
1866        Notebook $nb text="\r"
1867        Notebook $nb text="if ( ! Common.getName ) {\r"
1868        Notebook $nb text="\tCommon.getName = function(path){\r"
1869        Notebook $nb text="\t\tvar splitted=path.split(\"\\\\\");\r"
1870        Notebook $nb text="\t\treturn splitted[splitted.length-1];\r"
1871        Notebook $nb text="\t}\r"
1872        Notebook $nb text="}\r"
1873        Notebook $nb text="\r"
1874        Notebook $nb text="//file system object has a problem to create a folder with slashes at the end\r"
1875        Notebook $nb text="if ( ! Common.stripTrailingSlash ) {\r"
1876        Notebook $nb text="\tCommon.stripTrailingSlash = function(path){\r"
1877        Notebook $nb text="\t\twhile (path.substr(path.length - 1,path.length) == '\\\\') {\r"
1878        Notebook $nb text="\t\t\tpath=path.substr(0, path.length - 1);\r"
1879        Notebook $nb text="\t\t}\r"
1880        Notebook $nb text="\t\treturn path;\r"
1881        Notebook $nb text="\t}\r"
1882        Notebook $nb text="}\r"
1883        Notebook $nb text="//\r"
1884        Notebook $nb text="//////////////////////////////////////\r"
1885        Notebook $nb text="\r"
1886        Notebook $nb text="//////////////////////////////////////\r"
1887        Notebook $nb text="//   Scripting.FileSystemObject extensions\r"
1888        Notebook $nb text="\r"
1889        Notebook $nb text="if (! this.Scripting) {\r"
1890        Notebook $nb text="\tvar Scripting={};\r"
1891        Notebook $nb text="}\r"
1892        Notebook $nb text="\r"
1893        Notebook $nb text="if (! Scripting.FileSystemObject) {\r"
1894        Notebook $nb text="\tScripting.FileSystemObject={};\r"
1895        Notebook $nb text="}\r"
1896        Notebook $nb text="\r"
1897        Notebook $nb text="if ( ! Scripting.FileSystemObject.DeleteItem ) {\r"
1898        Notebook $nb text="\tScripting.FileSystemObject.DeleteItem = function (item) \r"
1899        Notebook $nb text="\t{\r"
1900        Notebook $nb text="\t\tvar FSOObj= new ActiveXObject(\"Scripting.FileSystemObject\");\r"
1901        Notebook $nb text="\t\tif (FSOObj.FileExists(item)){\r"
1902        Notebook $nb text="\t\t\tFSOObj.DeleteFile(item);\r"
1903        Notebook $nb text="\t\t\treturn true;\r"
1904        Notebook $nb text="\t\t} else if (FSOObj.FolderExists(item) ) {\r"
1905        Notebook $nb text="\t\t\tFSOObj.DeleteFolder(Common.stripTrailingSlash(item));\r"
1906        Notebook $nb text="\t\t\treturn true;\r"
1907        Notebook $nb text="\t\t} else {\r"
1908        Notebook $nb text="\t\t\treturn false;\r"
1909        Notebook $nb text="\t\t}\r"
1910        Notebook $nb text="\t}\r"
1911        Notebook $nb text="}\r"
1912        Notebook $nb text="\r"
1913        Notebook $nb text="\r"
1914        Notebook $nb text="if ( ! Scripting.FileSystemObject.ExistsFile ) {\r"
1915        Notebook $nb text="\tScripting.FileSystemObject.ExistsFile = function (path)\r"
1916        Notebook $nb text="\t{\r"
1917        Notebook $nb text="\t\tvar FSOObj= new ActiveXObject(\"Scripting.FileSystemObject\");\r"
1918        Notebook $nb text="\t\treturn FSOObj.FileExists(path);\r"
1919        Notebook $nb text="\t}\r"
1920        Notebook $nb text="}\r"
1921        Notebook $nb text="if ( !Scripting.FileSystemObject.ExistsFolder ) {\r"
1922        Notebook $nb text="\tScripting.FileSystemObject.ExistsFolder = function (path){\r"
1923        Notebook $nb text="\tvar FSOObj= new ActiveXObject(\"Scripting.FileSystemObject\");\r"
1924        Notebook $nb text="\t\treturn FSOObj.FolderExists(path);\r"
1925        Notebook $nb text="\t}\r"
1926        Notebook $nb text="}\r"
1927        Notebook $nb text="\r"
1928        Notebook $nb text="if ( ! Scripting.FileSystemObject.isFolder ) {\r"
1929        Notebook $nb text="\tScripting.FileSystemObject.isFolder = function (path){\r"
1930        Notebook $nb text="\tvar FSOObj= new ActiveXObject(\"Scripting.FileSystemObject\");\r"
1931        Notebook $nb text="\t\treturn FSOObj.FolderExists(path);\r"
1932        Notebook $nb text="\t}\r"
1933        Notebook $nb text="}\r"
1934        Notebook $nb text="\r"
1935        Notebook $nb text="\r"
1936        Notebook $nb text="\r"
1937        Notebook $nb text="if ( ! Scripting.FileSystemObject.isEmptyFolder ) {\r"
1938        Notebook $nb text="\tScripting.FileSystemObject.isEmptyFolder = function (path){\r"
1939        Notebook $nb text="\tvar FSOObj= new ActiveXObject(\"Scripting.FileSystemObject\");\r"
1940        Notebook $nb text="\t\tif(FSOObj.FileExists(path)){\r"
1941        Notebook $nb text="\t\t\treturn false;\r"
1942        Notebook $nb text="\t\t}else if (FSOObj.FolderExists(path)){\t\r"
1943        Notebook $nb text="\t\t\tvar folderObj=FSOObj.GetFolder(path);\r"
1944        Notebook $nb text="\t\t\tif ((folderObj.Files.Count+folderObj.SubFolders.Count)==0){\r"
1945        Notebook $nb text="\t\t\t\treturn true;\r"
1946        Notebook $nb text="\t\t\t}\r"
1947        Notebook $nb text="\t\t}\r"
1948        Notebook $nb text="\t\treturn false;\t\r"
1949        Notebook $nb text="\t}\r"
1950        Notebook $nb text="\r"
1951        Notebook $nb text="}\r"
1952        Notebook $nb text="\r"
1953        Notebook $nb text="if ( ! Scripting.FileSystemObject.CreateFolder) {\r"
1954        Notebook $nb text="\tScripting.FileSystemObject.CreateFolder = function (path){\r"
1955        Notebook $nb text="\t\tvar FSOObj= new ActiveXObject(\"Scripting.FileSystemObject\");\r"
1956        Notebook $nb text="\t\tFSOObj.CreateFolder(path);\r"
1957        Notebook $nb text="\t\treturn FSOObj.FolderExists(path);\r"
1958        Notebook $nb text="\t}\r"
1959        Notebook $nb text="}\r"
1960        Notebook $nb text="\r"
1961        Notebook $nb text="if ( ! Scripting.FileSystemObject.ExistsItem) {\r"
1962        Notebook $nb text="\tScripting.FileSystemObject.ExistsItem = function (path){\r"
1963        Notebook $nb text="\t\tvar FSOObj= new ActiveXObject(\"Scripting.FileSystemObject\");\r"
1964        Notebook $nb text="\t\treturn FSOObj.FolderExists(path)||FSOObj.FileExists(path);\r"
1965        Notebook $nb text="\t}\r"
1966        Notebook $nb text="}\r"
1967        Notebook $nb text="\r"
1968        Notebook $nb text="if ( ! Scripting.FileSystemObject.getFullPath) {\r"
1969        Notebook $nb text="\tScripting.FileSystemObject.getFullPath = function (path){\r"
1970        Notebook $nb text="\t\tvar FSOObj= new ActiveXObject(\"Scripting.FileSystemObject\");\r"
1971        Notebook $nb text="        return FSOObj.GetAbsolutePathName(path);\r"
1972        Notebook $nb text="\t}\r"
1973        Notebook $nb text="}\r"
1974        Notebook $nb text="//\r"
1975        Notebook $nb text="//////////////////////////////////////\r"
1976        Notebook $nb text="\r"
1977        Notebook $nb text="//////////////////////////////////////\r"
1978        Notebook $nb text="//   Shell.Application extensions\r"
1979        Notebook $nb text="if ( ! this.Shell ) {\r"
1980        Notebook $nb text="\tvar Shell = {};\r"
1981        Notebook $nb text="}\r"
1982        Notebook $nb text="\r"
1983        Notebook $nb text="if (! Shell.Application ) {\r"
1984        Notebook $nb text="\tShell.Application={};\r"
1985        Notebook $nb text="}\r"
1986        Notebook $nb text="\r"
1987        Notebook $nb text="if ( ! Shell.Application.ExistsFolder ) {\r"
1988        Notebook $nb text="\tShell.Application.ExistsFolder = function(path){\r"
1989        Notebook $nb text="\t\tvar ShellObj=new ActiveXObject(\"Shell.Application\");\r"
1990        Notebook $nb text="\t\tvar targetObject = new Object;\r"
1991        Notebook $nb text="\t\tvar targetObject=ShellObj.NameSpace(path);\r"
1992        Notebook $nb text="\t\tif (typeof targetObject === 'undefined' || targetObject == null ){\r"
1993        Notebook $nb text="\t\t\treturn false;\r"
1994        Notebook $nb text="\t\t}\r"
1995        Notebook $nb text="\t\treturn true;\r"
1996        Notebook $nb text="\t\r"
1997        Notebook $nb text="\t}\r"
1998        Notebook $nb text="}\r"
1999        Notebook $nb text="\r"
2000        Notebook $nb text="if ( ! Shell.Application.ExistsSubItem ) {\r"
2001        Notebook $nb text="\tShell.Application.ExistsSubItem = function(path){\r"
2002        Notebook $nb text="\t\tvar ShellObj=new ActiveXObject(\"Shell.Application\");\r"
2003        Notebook $nb text="\t\tvar targetObject = new Object;\r"
2004        Notebook $nb text="\t\tvar targetObject=ShellObj.NameSpace(Common.getParent(path));\r"
2005        Notebook $nb text="\t\tif (typeof targetObject === 'undefined' || targetObject == null ){\r"
2006        Notebook $nb text="\t\t\treturn false;\r"
2007        Notebook $nb text="\t\t}\r"
2008        Notebook $nb text="\t\t\r"
2009        Notebook $nb text="\t\tvar subItem=targetObject.ParseName(Common.getName(path));\r"
2010        Notebook $nb text="\t\tif(subItem === 'undefined' || subItem == null ){\r"
2011        Notebook $nb text="\t\t\treturn false;\r"
2012        Notebook $nb text="\t\t}\r"
2013        Notebook $nb text="\t\treturn true;\r"
2014        Notebook $nb text="\t\r"
2015        Notebook $nb text="\t}\r"
2016        Notebook $nb text="}\r"
2017        Notebook $nb text="\r"
2018        Notebook $nb text="\r"
2019        Notebook $nb text="if ( ! Shell.Application.ItemCounterL1 ) {\r"
2020        Notebook $nb text="\tShell.Application.ItemCounterL1 = function(path){\r"
2021        Notebook $nb text="\t\tvar ShellObj=new ActiveXObject(\"Shell.Application\");\r"
2022        Notebook $nb text="\t\tvar targetObject = new Object;\r"
2023        Notebook $nb text="\t\tvar targetObject=ShellObj.NameSpace(path);\r"
2024        Notebook $nb text="\t\tif (targetObject != null ){\r"
2025        Notebook $nb text="\t\t\treturn targetObject.Items().Count;\t\r"
2026        Notebook $nb text="\t\t} else {\r"
2027        Notebook $nb text="\t\t\treturn 0;\r"
2028        Notebook $nb text="\t\t}\r"
2029        Notebook $nb text="\t}\r"
2030        Notebook $nb text="}\r"
2031        Notebook $nb text="// shell application item.size returns the size of uncompressed state of the file.\r"
2032        Notebook $nb text="if ( ! Shell.Application.getSize ) {\r"
2033        Notebook $nb text="\tShell.Application.getSize = function(path){\r"
2034        Notebook $nb text="\t\tvar ShellObj=new ActiveXObject(\"Shell.Application\");\r"
2035        Notebook $nb text="\t\tvar targetObject = new Object;\r"
2036        Notebook $nb text="\t\tvar targetObject=ShellObj.NameSpace(path);\r"
2037        Notebook $nb text="\t\tif (! Shell.Application.ExistsFolder (path)){\r"
2038        Notebook $nb text="\t\t\tWScript.Echo(path + \"does not exists or the file is incorrect type.Be sure you are using full path to"
2039        Notebook $nb text=" the file\");\r"
2040        Notebook $nb text="\t\t\treturn 0;\r"
2041        Notebook $nb text="\t\t}\r"
2042        Notebook $nb text="\t\tif (typeof size === 'undefined'){\r"
2043        Notebook $nb text="\t\t\tvar size=0;\r"
2044        Notebook $nb text="\t\t}\r"
2045        Notebook $nb text="\t\tif (targetObject != null ){\r"
2046        Notebook $nb text="\t\t\t\r"
2047        Notebook $nb text="\t\t\tfor (var i=0; i<targetObject.Items().Count;i++){\r"
2048        Notebook $nb text="\t\t\t\tif(!targetObject.Items().Item(i).IsFolder){\r"
2049        Notebook $nb text="\t\t\t\t\tsize=size+targetObject.Items().Item(i).Size;\r"
2050        Notebook $nb text="\t\t\t\t} else if (targetObject.Items().Item(i).Count!=0){\r"
2051        Notebook $nb text="\t\t\t\t\tsize=size+Shell.Application.getSize(targetObject.Items().Item(i).Path);\r"
2052        Notebook $nb text="\t\t\t\t}\r"
2053        Notebook $nb text="\t\t\t}\r"
2054        Notebook $nb text="\t\t} else {\r"
2055        Notebook $nb text="\t\t\treturn 0;\r"
2056        Notebook $nb text="\t\t}\r"
2057        Notebook $nb text="\t\treturn size;\r"
2058        Notebook $nb text="\t}\r"
2059        Notebook $nb text="}\r"
2060        Notebook $nb text="if ( ! Shell.Application.TakeAction ) {\r"
2061        Notebook $nb text="\tShell.Application.TakeAction = function(destination,item, move ,option){\r"
2062        Notebook $nb text="\t\tif(typeof destination != 'undefined' && move){\r"
2063        Notebook $nb text="\t\t\tdestination.MoveHere(item,option);\r"
2064        Notebook $nb text="\t\t} else if(typeof destination != 'undefined') {\r"
2065        Notebook $nb text="\t\t\tdestination.CopyHere(item,option);\r"
2066        Notebook $nb text="\t\t} \r"
2067        Notebook $nb text="\t}\r"
2068        Notebook $nb text="}\r"
2069        Notebook $nb text="\r"
2070        Notebook $nb text="//ProcessItem and  ProcessSubItems can be used both for zipping and unzipping\r"
2071        Notebook $nb text="// When an item is zipped another process is ran and the control is released\r"
2072        Notebook $nb text="// but when the script stops also the copying to the zipped file stops.\r"
2073        Notebook $nb text="// Though the zipping is transactional so a zipped files will be visible only after the zipping is done\r"
2074        Notebook $nb text="// and we can rely on items count when zip operation is performed. \r"
2075        Notebook $nb text="// Also is impossible to compress an empty folders.\r"
2076        Notebook $nb text="// So when it comes to zipping two additional checks are added - for empty folders and for count of item"
2077        Notebook $nb text="s at the \r"
2078        Notebook $nb text="// destination.\r"
2079        Notebook $nb text="\r"
2080        Notebook $nb text="if ( ! Shell.Application.ProcessItem ) {\r"
2081        Notebook $nb text="\tShell.Application.ProcessItem = function(toProcess, destination  , move ,isZipping,option){\r"
2082        Notebook $nb text="\t\tvar ShellObj=new ActiveXObject(\"Shell.Application\");\r"
2083        Notebook $nb text="\t\tdestinationObj=ShellObj.NameSpace(destination);\r"
2084        Notebook $nb text="\t\t\t\r"
2085        Notebook $nb text="\t\tif (destinationObj!= null ){\r"
2086        Notebook $nb text="\t\t\tif (isZipping && Scripting.FileSystemObject.isEmptyFolder(toProcess)) {\r"
2087        Notebook $nb text="\t\t\t\tWScript.Echo(toProcess +\" is an empty folder and will be not processed\");\r"
2088        Notebook $nb text="\t\t\t\treturn;\r"
2089        Notebook $nb text="\t\t\t}\r"
2090        Notebook $nb text="\t\t\tShell.Application.TakeAction(destinationObj,toProcess, move ,option);\r"
2091        Notebook $nb text="\t\t\tvar destinationCount=Shell.Application.ItemCounterL1(destination);\r"
2092        Notebook $nb text="\t\t\tvar final_destination=destination + \"\\\\\" + Common.getName(toProcess);\r"
2093        Notebook $nb text="\t\t\t\r"
2094        Notebook $nb text="\t\t\tif (isZipping && !Shell.Application.ExistsSubItem(final_destination)) {\r"
2095        Notebook $nb text="\t\t\t\tCommon.WaitForCount(destination\r"
2096        Notebook $nb text="\t\t\t\t\t,destinationCount+1,Shell.Application.ItemCounterL1);\r"
2097        Notebook $nb text="\t\t\t} else if (isZipping && Shell.Application.ExistsSubItem(final_destination)){\r"
2098        Notebook $nb text="\t\t\t\tWScript.Echo(final_destination + \" already exists and task cannot be completed\");\r"
2099        Notebook $nb text="\t\t\t\treturn;\r"
2100        Notebook $nb text="\t\t\t}\r"
2101        Notebook $nb text="\t\t}\t\r"
2102        Notebook $nb text="\t}\r"
2103        Notebook $nb text="}\r"
2104        Notebook $nb text="\r"
2105        Notebook $nb text="\r"
2106        Notebook $nb text="\r"
2107        Notebook $nb text="if ( ! Shell.Application.ProcessSubItems ) {\r"
2108        Notebook $nb text="\tShell.Application.ProcessSubItems = function(toProcess, destination  , move ,isZipping ,option){\r"
2109        Notebook $nb text="\t\tvar ShellObj=new ActiveXObject(\"Shell.Application\");\r"
2110        Notebook $nb text="\t\tvar destinationObj=ShellObj.NameSpace(destination);\r"
2111        Notebook $nb text="\t\tvar toItemsToProcess=new Object;\r"
2112        Notebook $nb text="\t\ttoItemsToProcess=ShellObj.NameSpace(toProcess).Items();\r"
2113        Notebook $nb text="\t\t\t\r"
2114        Notebook $nb text="\t\tif (destinationObj!= null ){\r"
2115        Notebook $nb text="\t\t\t\t\t\t\r"
2116        Notebook $nb text="\t\t\tfor (var i=0;i<toItemsToProcess.Count;i++) {\r"
2117        Notebook $nb text="\t\t\t\t\r"
2118        Notebook $nb text="\t\t\t\tif (isZipping && Scripting.FileSystemObject.isEmptyFolder(toItemsToProcess.Item(i).Path)){\r"
2119        Notebook $nb text="\r"
2120        Notebook $nb text="\t\t\t\t\tWScript.Echo(\"\");\r"
2121        Notebook $nb text="\t\t\t\t\tWScript.Echo(toItemsToProcess.Item(i).Path + \" is empty and will be not processed\");\r"
2122        Notebook $nb text="\t\t\t\t\tWScript.Echo(\"\");\r"
2123        Notebook $nb text="\r"
2124        Notebook $nb text="\t\t\t\t} else {\r"
2125        Notebook $nb text="\t\t\t\t\tShell.Application.TakeAction(destinationObj,toItemsToProcess.Item(i),move,option);\r"
2126        Notebook $nb text="\t\t\t\t\tvar destinationCount=Shell.Application.ItemCounterL1(destination);\r"
2127        Notebook $nb text="\t\t\t\t\tif (isZipping) {\r"
2128        Notebook $nb text="\t\t\t\t\t\tCommon.WaitForCount(destination,destinationCount+1,Shell.Application.ItemCounterL1);\r"
2129        Notebook $nb text="\t\t\t\t\t}\r"
2130        Notebook $nb text="\t\t\t\t}\r"
2131        Notebook $nb text="\t\t\t}\t\r"
2132        Notebook $nb text="\t\t}\t\r"
2133        Notebook $nb text="\t}\r"
2134        Notebook $nb text="}\r"
2135        Notebook $nb text="\r"
2136        Notebook $nb text="if ( ! Shell.Application.ListItems ) {\r"
2137        Notebook $nb text="\tShell.Application.ListItems = function(parrentObject){\r"
2138        Notebook $nb text="\t\tvar ShellObj=new ActiveXObject(\"Shell.Application\");\r"
2139        Notebook $nb text="\t\tvar targetObject = new Object;\r"
2140        Notebook $nb text="\t\tvar targetObject=ShellObj.NameSpace(parrentObject);\r"
2141        Notebook $nb text="\r"
2142        Notebook $nb text="\t\tif (! Shell.Application.ExistsFolder (parrentObject)){\r"
2143        Notebook $nb text="\t\t\tWScript.Echo(parrentObject + \"does not exists or the file is incorrect type.Be sure the full path the"
2144        Notebook $nb text=" path is used\");\r"
2145        Notebook $nb text="\t\t\treturn;\r"
2146        Notebook $nb text="\t\t}\r"
2147        Notebook $nb text="\t\tif (typeof initialSCount == 'undefined') {\r"
2148        Notebook $nb text="\t\t\tinitialSCount=(parrentObject.split(\"\\\\\").length-1);\r"
2149        Notebook $nb text="\t\t\tWScript.Echo(parrentObject);\r"
2150        Notebook $nb text="\t\t}\r"
2151        Notebook $nb text="\t\t\r"
2152        Notebook $nb text="\t\tvar spaces=function(path){\r"
2153        Notebook $nb text="\t\t\tvar SCount=(path.split(\"\\\\\").length-1)-initialSCount;\r"
2154        Notebook $nb text="\t\t\tvar s=\"\";\r"
2155        Notebook $nb text="\t\t\tfor (var i=0;i<=SCount;i++) {\r"
2156        Notebook $nb text="\t\t\t\ts=\" \"+s;\r"
2157        Notebook $nb text="\t\t\t}\r"
2158        Notebook $nb text="\t\t\treturn s;\r"
2159        Notebook $nb text="\t\t}\r"
2160        Notebook $nb text="\t\t\r"
2161        Notebook $nb text="\t\tvar printP = function (item,end){\r"
2162        Notebook $nb text="\t\t\tif (flat) {\r"
2163        Notebook $nb text="\t\t\t\tWScript.Echo(targetObject.Items().Item(i).Path+end);\r"
2164        Notebook $nb text="\t\t\t}else{\r"
2165        Notebook $nb text="\t\t\t\tWScript.Echo( spaces(targetObject.Items().Item(i).Path)+targetObject.Items().Item(i).Name+end);\r"
2166        Notebook $nb text="\t\t\t}\r"
2167        Notebook $nb text="\t\t}\r"
2168        Notebook $nb text="\r"
2169        Notebook $nb text="\t\tif (targetObject != null ){\r"
2170        Notebook $nb text="\t\t\tvar folderPath=\"\";\r"
2171        Notebook $nb text="\r"
2172        Notebook $nb text="\t\t\t\tfor (var i=0; i<targetObject.Items().Count;i++) {\r"
2173        Notebook $nb text="\t\t\t\t\tif(targetObject.Items().Item(i).IsFolder && targetObject.Items().Item(i).Count==0 ){\r"
2174        Notebook $nb text="\t\t\t\t\t\tprintP(targetObject.Items().Item(i),\"\\\\\");\r"
2175        Notebook $nb text="\t\t\t\t\t} else if (targetObject.Items().Item(i).IsFolder){\r"
2176        Notebook $nb text="\t\t\t\t\t\tfolderPath=parrentObject+\"\\\\\"+targetObject.Items().Item(i).Name;\r"
2177        Notebook $nb text="\t\t\t\t\t\tprintP(targetObject.Items().Item(i),\"\\\\\")\r"
2178        Notebook $nb text="\t\t\t\t\t\tShell.Application.ListItems(folderPath);\t\t\t\t\t\t\r"
2179        Notebook $nb text="\r"
2180        Notebook $nb text="\t\t\t\t\t} else {\r"
2181        Notebook $nb text="\t\t\t\t\t\tprintP(targetObject.Items().Item(i),\"\")\r"
2182        Notebook $nb text="\t\t\t\t\t\t\r"
2183        Notebook $nb text="\t\t\t\t\t}\r"
2184        Notebook $nb text="\t\t\t\t}\r"
2185        Notebook $nb text="\r"
2186        Notebook $nb text="\t\t\t}\r"
2187        Notebook $nb text="\t}\r"
2188        Notebook $nb text="}\r"
2189        Notebook $nb text="\r"
2190        Notebook $nb text="//\r"
2191        Notebook $nb text="//////////////////////////////////////\r"
2192        Notebook $nb text="\r"
2193        Notebook $nb text="\r"
2194        Notebook $nb text="//////////////////////////////////////\r"
2195        Notebook $nb text="//     ZIP Utils\r"
2196        Notebook $nb text="\r"
2197        Notebook $nb text="if ( ! this.ZIPUtils ) {\r"
2198        Notebook $nb text="\tvar ZIPUtils = {};\r"
2199        Notebook $nb text="}\r"
2200        Notebook $nb text="\r"
2201        Notebook $nb text="\r"
2202        Notebook $nb text="if ( ! this.ZIPUtils.ZipItem) {\t\r"
2203        Notebook $nb text="\tZIPUtils.ZipItem = function(source, destination ) {\r"
2204        Notebook $nb text="\t\tif (!Scripting.FileSystemObject.ExistsFolder(source)) {\r"
2205        Notebook $nb text="\t\t\tWScript.Echo(\"\");\r"
2206        Notebook $nb text="\t\t\tWScript.Echo(\"file \" + source +\" does not exist\");\r"
2207        Notebook $nb text="\t\t\tWScript.Quit(2);\t\r"
2208        Notebook $nb text="\t\t}\r"
2209        Notebook $nb text="\t\t\r"
2210        Notebook $nb text="\t\tif (Scripting.FileSystemObject.ExistsFile(destination) && force ) {\r"
2211        Notebook $nb text="\t\t\tScripting.FileSystemObject.DeleteItem(destination);\r"
2212        Notebook $nb text="\t\t\tADODB.Stream.writeFile(destination,ZIP_DATA);\r"
2213        Notebook $nb text="\t\t} else if (!Scripting.FileSystemObject.ExistsFile(destination)) {\r"
2214        Notebook $nb text="\t\t\tADODB.Stream.writeFile(destination,ZIP_DATA);\r"
2215        Notebook $nb text="\t\t} else {\r"
2216        Notebook $nb text="\t\t\tWScript.Echo(\"Destination \"+destination+\" already exists.Operation will be aborted\");\r"
2217        Notebook $nb text="\t\t\tWScript.Quit(15);\r"
2218        Notebook $nb text="\t\t}\r"
2219        Notebook $nb text="\t\tsource=Scripting.FileSystemObject.getFullPath(source);\r"
2220        Notebook $nb text="\t\tdestination=Scripting.FileSystemObject.getFullPath(destination);\r"
2221        Notebook $nb text="\t\t\r"
2222        Notebook $nb text="\t\tShell.Application.ProcessItem(source,destination,move,true ,NO_PROGRESS_BAR);\r"
2223        Notebook $nb text="\r"
2224        Notebook $nb text="\t}\r"
2225        Notebook $nb text="}\r"
2226        Notebook $nb text="\r"
2227        Notebook $nb text="\r"
2228        Notebook $nb text="if ( ! this.ZIPUtils.ZipDirItems) {\t\r"
2229        Notebook $nb text="\tZIPUtils.ZipDirItems = function(source, destination ) {\r"
2230        Notebook $nb text="\t\tif (!Scripting.FileSystemObject.ExistsFolder(source)) {\r"
2231        Notebook $nb text="\t\t\tWScript.Echo();\r"
2232        Notebook $nb text="\t\t\tWScript.Echo(\"file \" + source +\" does not exist\");\r"
2233        Notebook $nb text="\t\t\tWScript.Quit(2);\t\r"
2234        Notebook $nb text="\t\t}\r"
2235        Notebook $nb text="\t\tif (Scripting.FileSystemObject.ExistsFile(destination) && force ) {\r"
2236        Notebook $nb text="\t\t\tScripting.FileSystemObject.DeleteItem(destination);\r"
2237        Notebook $nb text="\t\t\tADODB.Stream.writeFile(destination,ZIP_DATA);\r"
2238        Notebook $nb text="\t\t} else if (!Scripting.FileSystemObject.ExistsFile(destination)) {\r"
2239        Notebook $nb text="\t\t\tADODB.Stream.writeFile(destination,ZIP_DATA);\r"
2240        Notebook $nb text="\t\t} else {\r"
2241        Notebook $nb text="\t\t\tWScript.Echo(\"Destination \"+destination+\" already exists.Operation will be aborted\");\r"
2242        Notebook $nb text="\t\t\tWScript.Quit(15);\r"
2243        Notebook $nb text="\t\t}\r"
2244        Notebook $nb text="\t\t\r"
2245        Notebook $nb text="\t\tsource=Scripting.FileSystemObject.getFullPath(source);\r"
2246        Notebook $nb text="\t\tdestination=Scripting.FileSystemObject.getFullPath(destination);\r"
2247        Notebook $nb text="\t\t\r"
2248        Notebook $nb text="\t\tShell.Application.ProcessSubItems(source, destination, move ,true,NO_PROGRESS_BAR);\r"
2249        Notebook $nb text="\t\t\r"
2250        Notebook $nb text="\t\tif (move){\r"
2251        Notebook $nb text="\t\t\tScripting.FileSystemObject.DeleteItem(source);\r"
2252        Notebook $nb text="\t\t}\r"
2253        Notebook $nb text="\t}\r"
2254        Notebook $nb text="}\r"
2255        Notebook $nb text="\r"
2256        Notebook $nb text="if ( ! this.ZIPUtils.Unzip) {\t\r"
2257        Notebook $nb text="\tZIPUtils.Unzip = function(source, destination ) {\r"
2258        Notebook $nb text="\t\tif(!Shell.Application.ExistsFolder(source) ){\r"
2259        Notebook $nb text="\t\t\tWScript.Echo(\"Either the target does not exist or is not a correct type\");\r"
2260        Notebook $nb text="\t\t\treturn;\r"
2261        Notebook $nb text="\t\t}\r"
2262        Notebook $nb text="\t\t\r"
2263        Notebook $nb text="\t\tif (Scripting.FileSystemObject.ExistsItem(destination) && force ) {\r"
2264        Notebook $nb text="\t\t\tScripting.FileSystemObject.DeleteItem(destination);\r"
2265        Notebook $nb text="\t\t} else if (Scripting.FileSystemObject.ExistsItem(destination)){\r"
2266        Notebook $nb text="\t\t\tWScript.Echo(\"Destination \" + destination + \" already exists\");\r"
2267        Notebook $nb text="\t\t\treturn;\r"
2268        Notebook $nb text="\t\t}\r"
2269        Notebook $nb text="\t\tScripting.FileSystemObject.CreateFolder(destination);\r"
2270        Notebook $nb text="\t\tsource=Scripting.FileSystemObject.getFullPath(source);\r"
2271        Notebook $nb text="\t\tdestination=Scripting.FileSystemObject.getFullPath(destination);\r"
2272        Notebook $nb text="\t\tShell.Application.ProcessSubItems(source, destination, move ,false,NO_PROGRESS_BAR);\t\r"
2273        Notebook $nb text="\t\t\r"
2274        Notebook $nb text="\t\tif (move){\r"
2275        Notebook $nb text="\t\t\tScripting.FileSystemObject.DeleteItem(source);\r"
2276        Notebook $nb text="\t\t}\r"
2277        Notebook $nb text="    }\t\t\r"
2278        Notebook $nb text="}\r"
2279        Notebook $nb text="\r"
2280        Notebook $nb text="if ( ! this.ZIPUtils.AddToZip) {\r"
2281        Notebook $nb text="\tZIPUtils.AddToZip = function(source, destination ) {\r"
2282        Notebook $nb text="\t\tif(!Shell.Application.ExistsFolder(destination)) {\r"
2283        Notebook $nb text="\t\t\tWScript.Echo(destination +\" is not valid path to/within zip.Be sure you are not using relative paths\""
2284        Notebook $nb text=");\r"
2285        Notebook $nb text="\t\t\tWscript.Exit(\"101\");\r"
2286        Notebook $nb text="\t\t}\r"
2287        Notebook $nb text="\t\tif(!Scripting.FileSystemObject.ExistsItem(source)){\r"
2288        Notebook $nb text="\t\t\tWScript.Echo(source +\" does not exist\");\r"
2289        Notebook $nb text="\t\t\tWscript.Exit(\"102\");\r"
2290        Notebook $nb text="\t\t}\r"
2291        Notebook $nb text="\t\tsource=Scripting.FileSystemObject.getFullPath(source);\r"
2292        Notebook $nb text="\t\tShell.Application.ProcessItem(source,destination,move,true ,NO_PROGRESS_BAR); \r"
2293        Notebook $nb text="\t}\r"
2294        Notebook $nb text="}\r"
2295        Notebook $nb text="\r"
2296        Notebook $nb text="if ( ! this.ZIPUtils.UnzipItem) {\t\r"
2297        Notebook $nb text="\tZIPUtils.UnzipItem = function(source, destination ) {\r"
2298        Notebook $nb text="\r"
2299        Notebook $nb text="\t\tif(!Shell.Application.ExistsSubItem(source)){\r"
2300        Notebook $nb text="\t\t\tWScript.Echo(source + \":Either the target does not exist or is not a correct type\");\r"
2301        Notebook $nb text="\t\t\treturn;\r"
2302        Notebook $nb text="\t\t}\r"
2303        Notebook $nb text="\t\t\r"
2304        Notebook $nb text="\t\tif (Scripting.FileSystemObject.ExistsItem(destination) && force ) {\r"
2305        Notebook $nb text="\t\t\tScripting.FileSystemObject.DeleteItem(destination);\r"
2306        Notebook $nb text="\t\t} else if (Scripting.FileSystemObject.ExistsItem(destination)){\r"
2307        Notebook $nb text="\t\t\tWScript.Echo(destination+\" - Destination already exists\");\r"
2308        Notebook $nb text="\t\t\treturn;\r"
2309        Notebook $nb text="\t\t} \r"
2310        Notebook $nb text="\t\t\r"
2311        Notebook $nb text="\t\tScripting.FileSystemObject.CreateFolder(destination);\r"
2312        Notebook $nb text="\t\tdestination=Scripting.FileSystemObject.getFullPath(destination);\r"
2313        Notebook $nb text="\t\tShell.Application.ProcessItem(source, destination, move ,false,NO_PROGRESS_BAR);\r"
2314        Notebook $nb text="\t\t                            \r"
2315        Notebook $nb text="    }\t\t\r"
2316        Notebook $nb text="}\r"
2317        Notebook $nb text="if ( ! this.ZIPUtils.getSize) {\t\r"
2318        Notebook $nb text="\tZIPUtils.getSize = function(path) {\r"
2319        Notebook $nb text="\t\t// first getting a full path to the file is attempted\r"
2320        Notebook $nb text="\t\t// as it's required by shell.application\r"
2321        Notebook $nb text="\t\t// otherwise is assumed that a file within a zip \r"
2322        Notebook $nb text="\t\t// is aimed\r"
2323        Notebook $nb text="\t\t\r"
2324        Notebook $nb text="\t\t//TODO - find full path even if the path points to internal for the \r"
2325        Notebook $nb text="\t\t// zip directory\r"
2326        Notebook $nb text="\t\t\r"
2327        Notebook $nb text="\t\tif (Scripting.FileSystemObject.ExistsFile(path)){\r"
2328        Notebook $nb text="\t\t\tpath=Scripting.FileSystemObject.getFullPath(path);\r"
2329        Notebook $nb text="\t\t}\r"
2330        Notebook $nb text="\t\tWScript.Echo(Shell.Application.getSize(path));\r"
2331        Notebook $nb text="\t}\r"
2332        Notebook $nb text="}\r"
2333        Notebook $nb text="\r"
2334        Notebook $nb text="if ( ! this.ZIPUtils.list) {\t\r"
2335        Notebook $nb text="\tZIPUtils.list = function(path) {\r"
2336        Notebook $nb text="\t\t// first getting a full path to the file is attempted\r"
2337        Notebook $nb text="\t\t// as it's required by shell.application\r"
2338        Notebook $nb text="\t\t// otherwise is assumed that a file within a zip \r"
2339        Notebook $nb text="\t\t// is aimed\r"
2340        Notebook $nb text="\t\t\r"
2341        Notebook $nb text="\t\t//TODO - find full path even if the path points to internal for the \r"
2342        Notebook $nb text="\t\t// zip directory\r"
2343        Notebook $nb text="\t\t\r"
2344        Notebook $nb text="\t\t// TODO - optional printing of each file uncompressed size\r"
2345        Notebook $nb text="\t\t\r"
2346        Notebook $nb text="\t\tif (Scripting.FileSystemObject.ExistsFile(path)){\r"
2347        Notebook $nb text="\t\t\tpath=Scripting.FileSystemObject.getFullPath(path);\r"
2348        Notebook $nb text="\t\t}\r"
2349        Notebook $nb text="\t\tShell.Application.ListItems(path);\r"
2350        Notebook $nb text="\t}\r"
2351        Notebook $nb text="}\r"
2352        Notebook $nb text="\r"
2353        Notebook $nb text="//\r"
2354        Notebook $nb text="//////////////////////////////////////\r"
2355        Notebook $nb text="\r"
2356        Notebook $nb text="/////////////////////////////////////\r"
2357        Notebook $nb text="//   parsing'n'running\r"
2358        Notebook $nb text="function printHelp(){\r"
2359        Notebook $nb text="\r"
2360        Notebook $nb text="\tWScript.Echo( scriptName + \" list -source zipFile [-flat yes|no]\");\r"
2361        Notebook $nb text="\tWScript.Echo( \"\t\tlist the content of a zip file\");\r"
2362        Notebook $nb text="\tWScript.Echo( \"\tzipFile - absolute path to the zip file\");\r"
2363        Notebook $nb text="\tWScript.Echo( \"\t\t\tcould be also a directory or a directory inside a zip file or\");\r"
2364        Notebook $nb text="\tWScript.Echo( \"\t\t\tor a .cab file or an .iso file\");\r"
2365        Notebook $nb text="\tWScript.Echo( \"\t-flat - indicates if the structure of the zip will be printed as tree\");\r"
2366        Notebook $nb text="\tWScript.Echo( \"\t\t\tor with absolute paths (-flat yes).Default is yes.\");\r"
2367        Notebook $nb text="\tWScript.Echo( \"Example:\");\r"
2368        Notebook $nb text="\tWScript.Echo( \"\t\" + scriptName + \" list -source C:\\\\myZip.zip -flat no\" );\r"
2369        Notebook $nb text="\tWScript.Echo( \"\t\" + scriptName + \" list -source C:\\\\myZip.zip\\\\inZipDir -flat yes\" );\r"
2370        Notebook $nb text="\t\r"
2371        Notebook $nb text="\tWScript.Echo( scriptName + \" getSize -source zipFile\");\r"
2372        Notebook $nb text="\tWScript.Echo( \"\t\tprints uncompressed size of the zipped file in bytes\");\r"
2373        Notebook $nb text="\tWScript.Echo( \"\tzipFile - absolute path to the zip file\");\r"
2374        Notebook $nb text="\tWScript.Echo( \"\t\t\tcould be also a directory or a directory inside a zip file or\");\r"
2375        Notebook $nb text="\tWScript.Echo( \"\t\t\tor a .cab file or an .iso file\");\r"
2376        Notebook $nb text="\tWScript.Echo( \"Example:\");\r"
2377        Notebook $nb text="\tWScript.Echo( \"\t\" + scriptName + \" getSize -source C:\\\\myZip.zip\" );\r"
2378        Notebook $nb text="\t\r"
2379        Notebook $nb text="\tWScript.Echo( scriptName + \" zipDirItems -source source_dir -destination destination.zip [-force yes|no"
2380        Notebook $nb text="] [-keep yes|no]\");\r"
2381        Notebook $nb text="\tWScript.Echo( \"\t\tzips the content of given folder without the folder itself \");\r"
2382        Notebook $nb text="\tWScript.Echo( \"\tsource_dir - path to directory which content will be compressed\");\r"
2383        Notebook $nb text="\tWScript.Echo( \"\t\tEmpty folders in the source directory will be ignored\");\r"
2384        Notebook $nb text="\tWScript.Echo( \"\tdestination.zip - path/name  of the zip file that will be created\");\r"
2385        Notebook $nb text="\tWScript.Echo( \"\t-force - indicates if the destination will be overwritten if already exists.\");\r"
2386        Notebook $nb text="\tWScript.Echo( \"\t\tdefault is yes\");\r"
2387        Notebook $nb text="\tWScript.Echo( \"\t-keep - indicates if the source content will be moved or just copied/kept.\");\r"
2388        Notebook $nb text="\tWScript.Echo( \"\t\tdefault is yes\");\r"
2389        Notebook $nb text="\tWScript.Echo( \"Example:\");\r"
2390        Notebook $nb text="\tWScript.Echo( \"\t\" + scriptName + \" zipDirItems -source C:\\\\myDir\\\\ -destination C:\\\\MyZip.zip -keep yes"
2391        Notebook $nb text=" -force no\" );\r"
2392        Notebook $nb text="\t\r"
2393        Notebook $nb text="\tWScript.Echo( scriptName + \" zipItem -source item -destination destination.zip [-force yes|no] [-keep y"
2394        Notebook $nb text="es|no]\");\r"
2395        Notebook $nb text="\tWScript.Echo( \"\t\tzips file or directory to a destination.zip file \");\r"
2396        Notebook $nb text="\tWScript.Echo( \"\titem - path to file or directory which content will be compressed\");\r"
2397        Notebook $nb text="\tWScript.Echo( \"\t\tIf points to an empty folder it will be ignored\");\r"
2398        Notebook $nb text="\tWScript.Echo( \"\t\tIf points to a folder it also will be included in the zip file alike zipdiritems comma"
2399        Notebook $nb text="nd\");\r"
2400        Notebook $nb text="\tWScript.Echo( \"\t\tEventually zipping a folder in this way will be faster as it does not process every el"
2401        Notebook $nb text="ement one by one\");\r"
2402        Notebook $nb text="\tWScript.Echo( \"\tdestination.zip - path/name  of the zip file that will be created\");\r"
2403        Notebook $nb text="\tWScript.Echo( \"\t-force - indicates if the destination will be overwritten if already exists.\");\r"
2404        Notebook $nb text="\tWScript.Echo( \"\t\tdefault is yes\");\r"
2405        Notebook $nb text="\tWScript.Echo( \"\t-keep - indicates if the source content will be moved or just copied/kept.\");\r"
2406        Notebook $nb text="\tWScript.Echo( \"\t\tdefault is yes\");\r"
2407        Notebook $nb text="\tWScript.Echo( \"Example:\");\r"
2408        Notebook $nb text="\tWScript.Echo( \"\t\" + scriptName + \" zipItem -source C:\\\\myDir\\\\myFile.txt -destination C:\\\\MyZip.zip -ke"
2409        Notebook $nb text="ep yes -force no\" );\r"
2410        Notebook $nb text="\t\r"
2411        Notebook $nb text="\tWScript.Echo( scriptName + \" unzip -source source.zip -destination destination_dir [-force yes|no] [-ke"
2412        Notebook $nb text="ep yes|no]\");\r"
2413        Notebook $nb text="\tWScript.Echo( \"\t\tunzips the content of a zip file to a given directory \");\r"
2414        Notebook $nb text="\tWScript.Echo( \"\tsource - path to the zip file that will be expanded\");\r"
2415        Notebook $nb text="\tWScript.Echo( \"\t\tEventually .iso , .cab or even an ordinary directory can be used as a source\");\r"
2416        Notebook $nb text="\tWScript.Echo( \"\tdestination_dir - path to directory where unzipped items will be stored\");\r"
2417        Notebook $nb text="\tWScript.Echo( \"\t-force - indicates if the destination will be overwritten if already exists.\");\r"
2418        Notebook $nb text="\tWScript.Echo( \"\t\tdefault is yes\");\r"
2419        Notebook $nb text="\tWScript.Echo( \"\t-keep - indicates if the source content will be moved or just copied/kept.\");\r"
2420        Notebook $nb text="\tWScript.Echo( \"\t\tdefault is yes\");\r"
2421        Notebook $nb text="\tWScript.Echo( \"Example:\");\r"
2422        Notebook $nb text="\tWScript.Echo( \"\t\" + scriptName + \" unzip -source C:\\\\myDir\\\\myZip.zip -destination C:\\\\MyDir -keep no -"
2423        Notebook $nb text="force no\" );\r"
2424        Notebook $nb text="\t\r"
2425        Notebook $nb text="\tWScript.Echo( scriptName + \" unZipItem -source source.zip -destination destination_dir [-force yes|no] "
2426        Notebook $nb text="[-keep yes|no]\");\r"
2427        Notebook $nb text="\tWScript.Echo( \"\t\tunzips  a single within a given zip file to a destination directory\");\r"
2428        Notebook $nb text="\tWScript.Echo( \"\tsource - path to the file/folcer within a zip  that will be expanded\");\r"
2429        Notebook $nb text="\tWScript.Echo( \"\t\tEventually .iso , .cab or even an ordinary directory can be used as a source\");\r"
2430        Notebook $nb text="\tWScript.Echo( \"\tdestination_dir - path to directory where unzipped item will be stored\");\r"
2431        Notebook $nb text="\tWScript.Echo( \"\t-force - indicates if the destination directory will be overwritten if already exists.\""
2432        Notebook $nb text=");\r"
2433        Notebook $nb text="\tWScript.Echo( \"\t\tdefault is yes\");\r"
2434        Notebook $nb text="\tWScript.Echo( \"\t-keep - indicates if the source content will be moved or just copied/kept.\");\r"
2435        Notebook $nb text="\tWScript.Echo( \"\t\tdefault is yes\");\r"
2436        Notebook $nb text="\tWScript.Echo( \"Example:\");\r"
2437        Notebook $nb text="\tWScript.Echo( \"\t\" + scriptName + \" unZipItem -source C:\\\\myDir\\\\myZip.zip\\\\InzipDir\\\\InzipFile -destina"
2438        Notebook $nb text="tion C:\\\\OtherDir -keep no -force yes\" );\r"
2439        Notebook $nb text="\tWScript.Echo( \"\t\" + scriptName + \" unZipItem -source C:\\\\myDir\\\\myZip.zip\\\\InzipDir -destination C:\\\\Ot"
2440        Notebook $nb text="herDir \" );\r"
2441        Notebook $nb text="\t\r"
2442        Notebook $nb text="\tWScript.Echo( scriptName + \" addToZip -source sourceItem -destination destination.zip  [-keep yes|no]\")"
2443        Notebook $nb text=";\r"
2444        Notebook $nb text="\tWScript.Echo( \"\t\tadds file or folder to already exist zip file\");\r"
2445        Notebook $nb text="\tWScript.Echo( \"\tsource - path to the item that will be processed\");\r"
2446        Notebook $nb text="\tWScript.Echo( \"\tdestination_zip - path to the zip where the item will be added\");\r"
2447        Notebook $nb text="\tWScript.Echo( \"\t-keep - indicates if the source content will be moved or just copied/kept.\");\r"
2448        Notebook $nb text="\tWScript.Echo( \"\t\tdefault is yes\");\r"
2449        Notebook $nb text="\tWScript.Echo( \"Example:\");\r"
2450        Notebook $nb text="\tWScript.Echo( \"\t\" + scriptName + \" addToZip -source C:\\\\some_file -destination C:\\\\myDir\\\\myZip.zip\\\\In"
2451        Notebook $nb text="zipDir -keep no \" );\r"
2452        Notebook $nb text="\tWScript.Echo( \"\t\" + scriptName + \" addToZip -source  C:\\\\some_file -destination C:\\\\myDir\\\\myZip.zip \" "
2453        Notebook $nb text=");\r"
2454        Notebook $nb text="\t\r"
2455        Notebook $nb text="\tWScript.Echo( \"\tby Vasil \\\"npocmaka\\\" Arnaudov - npocmaka@gmail.com\" );\r"
2456        Notebook $nb text="\tWScript.Echo( \"\tver 0.1 \" );\r"
2457        Notebook $nb text="\tWScript.Echo( \"\tlatest version could be found here https://github.com/npocmaka/batch.scripts/blob/maste"
2458        Notebook $nb text="r/hybrids/jscript/zipjs.bat\" );\r"
2459        Notebook $nb text="\t\r"
2460        Notebook $nb text="\t\r"
2461        Notebook $nb text="}\r"
2462        Notebook $nb text="\r"
2463        Notebook $nb text="function parseArguments(){\r"
2464        Notebook $nb text="\tif (WScript.Arguments.Length==1 || WScript.Arguments.Length==2 || ARGS.Item(1).toLowerCase() == \"-help\""
2465        Notebook $nb text=" ||  ARGS.Item(1).toLowerCase() == \"-h\" ) {\r"
2466        Notebook $nb text="\t\tprintHelp();\r"
2467        Notebook $nb text="\t\tWScript.Quit(0);\r"
2468        Notebook $nb text="   }\r"
2469        Notebook $nb text="   \r"
2470        Notebook $nb text="   //all arguments are key-value pairs plus one for script name and action taken - need to be even numbe"
2471        Notebook $nb text="r\r"
2472        Notebook $nb text="\tif (WScript.Arguments.Length % 2 == 1 ) {\r"
2473        Notebook $nb text="\t\tWScript.Echo(\"Illegal arguments \");\r"
2474        Notebook $nb text="\t\tprintHelp();\r"
2475        Notebook $nb text="\t\tWScript.Quit(1);\r"
2476        Notebook $nb text="\t}\r"
2477        Notebook $nb text="\t\r"
2478        Notebook $nb text="\t//ARGS\r"
2479        Notebook $nb text="\tfor(var arg = 2 ; arg<ARGS.Length-1;arg=arg+2) {\r"
2480        Notebook $nb text="\t\tif (ARGS.Item(arg) == \"-source\") {\r"
2481        Notebook $nb text="\t\t\tsource = ARGS.Item(arg +1);\r"
2482        Notebook $nb text="\t\t}\r"
2483        Notebook $nb text="\t\tif (ARGS.Item(arg) == \"-destination\") {\r"
2484        Notebook $nb text="\t\t\tdestination = ARGS.Item(arg +1);\r"
2485        Notebook $nb text="\t\t}\r"
2486        Notebook $nb text="\t\tif (ARGS.Item(arg).toLowerCase() == \"-keep\" && ARGS.Item(arg +1).toLowerCase() == \"no\") {\r"
2487        Notebook $nb text="\t\t\tmove=true;\r"
2488        Notebook $nb text="\t\t}\r"
2489        Notebook $nb text="\t\tif (ARGS.Item(arg).toLowerCase() == \"-force\" && ARGS.Item(arg +1).toLowerCase() == \"no\") {\r"
2490        Notebook $nb text="\t\t\tforce=false;\r"
2491        Notebook $nb text="\t\t}\r"
2492        Notebook $nb text="\t\tif (ARGS.Item(arg).toLowerCase() == \"-flat\" && ARGS.Item(arg +1).toLowerCase() == \"yes\") {\r"
2493        Notebook $nb text="\t\t\tflat=true;\r"
2494        Notebook $nb text="\t\t}\r"
2495        Notebook $nb text="\t}\r"
2496        Notebook $nb text="\t\r"
2497        Notebook $nb text="\tif (source == \"\"){\r"
2498        Notebook $nb text="\t\tWScript.Echo(\"Source not given\");\r"
2499        Notebook $nb text="\t\tprintHelp();\r"
2500        Notebook $nb text="\t\tWScript.Quit(59);\r"
2501        Notebook $nb text="\t}\r"
2502        Notebook $nb text="\r"
2503        Notebook $nb text="}\r"
2504        Notebook $nb text="\r"
2505        Notebook $nb text="var checkDestination=function(){\r"
2506        Notebook $nb text="\tif (destination == \"\"){\r"
2507        Notebook $nb text="\t\tWScript.Echo(\"Destination not given\");\r"
2508        Notebook $nb text="\t\tprintHelp();\r"
2509        Notebook $nb text="\t\tWScript.Quit(65);\r"
2510        Notebook $nb text="\t}\r"
2511        Notebook $nb text="}\r"
2512        Notebook $nb text="\r"
2513        Notebook $nb text="var main=function(){\r"
2514        Notebook $nb text="\tparseArguments();\r"
2515        Notebook $nb text="\tswitch (ARGS.Item(1).toLowerCase()) {\r"
2516        Notebook $nb text="\tcase \"list\":\r"
2517        Notebook $nb text="\t\tZIPUtils.list(source);\r"
2518        Notebook $nb text="\t\tbreak;\r"
2519        Notebook $nb text="\tcase \"getsize\":\r"
2520        Notebook $nb text="\t\tZIPUtils.getSize(source);\r"
2521        Notebook $nb text="\t\tbreak;\r"
2522        Notebook $nb text="\tcase \"zipdiritems\":\r"
2523        Notebook $nb text="\t\tcheckDestination();\r"
2524        Notebook $nb text="\t\tZIPUtils.ZipDirItems(source,destination);\r"
2525        Notebook $nb text="\t\tbreak;\r"
2526        Notebook $nb text="\tcase \"zipitem\":\r"
2527        Notebook $nb text="\t\tcheckDestination();\r"
2528        Notebook $nb text="\t\tZIPUtils.ZipDirItems(source,destination);\r"
2529        Notebook $nb text="\t\tbreak;\r"
2530        Notebook $nb text="\tcase \"unzip\":\r"
2531        Notebook $nb text="\t\tcheckDestination();\r"
2532        Notebook $nb text="\t\tZIPUtils.Unzip(source,destination);\r"
2533        Notebook $nb text="\t\tbreak;\r"
2534        Notebook $nb text="\tcase \"unzipitem\":\r"
2535        Notebook $nb text="\t\tcheckDestination();\r"
2536        Notebook $nb text="\t\tZIPUtils.UnzipItem(source,destination);\r"
2537        Notebook $nb text="\t\tbreak;\r"
2538        Notebook $nb text="\tcase \"addtozip\":\r"
2539        Notebook $nb text="\t\tcheckDestination();\r"
2540        Notebook $nb text="\t\tZIPUtils.AddToZip(source,destination);\r"
2541        Notebook $nb text="\t\tbreak;\r"
2542        Notebook $nb text="\tdefault:\r"
2543        Notebook $nb text="\t\tWScript.Echo(\"No valid switch has been passed\");\r"
2544        Notebook $nb text="\t\tprintHelp();\r"
2545        Notebook $nb text="\t\t\r"
2546        Notebook $nb text="\t}\r"
2547        Notebook $nb text="\t\r"
2548        Notebook $nb text="}\r"
2549        Notebook $nb text="main();\r"
2550        Notebook $nb text="//\r"
2551        Notebook $nb text="//////////////////////////////////////"
2552end
2553
2554// ===================================== End of Un-Zipping ===================================== //
2555// ============================================================================================= //
2556
2557
2558//**************************************************************************************************************************************
2559//**************************************************************************************************************************************
2560Function GHW_MakeRecordOfProgress(MessageToRecord, [header, abortProgress])
2561        string MessageToRecord
2562        variable header, abortProgress
2563       
2564        if(ParamIsDefault(header))
2565                header=0
2566        endif
2567        if(ParamIsDefault(abortProgress))
2568                abortProgress=0
2569        endif
2570        print MessageToRecord
2571        variable FileNum
2572        string LogFileName="InstallRecord.log"
2573        PathInfo InstallerRecordPath
2574        if(V_Flag==0)
2575                NewPath /O/Q InstallerRecordPath  , SpecialDirPath("Desktop", 0, 0, 0 )
2576        endif
2577        GetFileFolderInfo/Q/Z/P=InstallerRecordPath  LogFileName
2578        if(V_Flag!=0)
2579                Open  /P=InstallerRecordPath /T=".txt"  FileNum  as LogFileName
2580                Close FIleNum   
2581        endif
2582        Open /P=InstallerRecordPath  FileNum  as LogFileName
2583        if (strlen(S_fileName)<1)
2584                return 1
2585        endif
2586        FStatus FileNum
2587        FSetPos FileNum, V_logEOF
2588        if (V_logEOF<2 || header)                       
2589                String str, head=SelectString(V_logEOF>2,"","\r\r\r\r")
2590                head += "********************************************************************************\r"
2591                head += "********************************************************************************\r"
2592                sprintf str,"       Starting Installation using  %s\r", IgorInfo(1)
2593                head += str
2594                sprintf str,"       on %s, %s\r", Secs2Date(DateTime,1), Secs2Time(DateTime,1)
2595                head += str
2596                sprintf str,"       Logging everything in history window to:\r\t\t\"%s\"\r\r\r",LogFileName
2597                head += str
2598                fprintf FileNum,head
2599                print head
2600        endif
2601        fprintf FileNum, MessageToRecord+"\r"
2602        Close FileNum
2603        if(abortProgress)       
2604                SVAR PackageListsToDownload
2605                SVAR SelectedReleaseName
2606                SVAR ListOfPackagesToInstall
2607                GHW_SubmitRecordToWeb(ListOfPackagesToInstall, SelectedReleaseName, MessageToRecord)
2608                BrowseURL "https://github.com/jilavsky/SAXS_IgorCode/wiki/Installation-Problems"
2609                Abort "Installation aborted due to error.\rPlease send the InstallRecord.log file from your Desktop to ilavsky@aps.anl.gov for analysis of the failure reason and debugging. "
2610        endif
2611        return 0
2612End
2613//**************************************************************************************************************************************
2614//**************************************************************************************************************************************
2615
2616Function GHW_InstallPackage(PathToLocalData,PackageListxml)
2617        string PathToLocalData,PackageListxml
2618        DFREF saveDFR=GetDataFolderDFR()                // Get reference to current data folder
2619        SetDataFOlder root:Packages:GHInstaller
2620       
2621        //print PathToLocalData, PackageListxml
2622        variable fileID
2623        string FileContent="", tempStr
2624        string PackgListFiles, PackgListFilePaths, PackgListxopLinks, PackgListFileLinks
2625        PathToLocalData = RemoveEnding(PathToLocalData, ":")+":"                //make sure we have correct path ending to use
2626        //Open/R/Z fileID as PathToLocalData+PackageListxml
2627        GetFileFolderInfo/Z/Q PathToLocalData+PackageListxml
2628        if(V_flag!=0)
2629                BrowseURL "https://github.com/jilavsky/SAXS_IgorCode/wiki/Installation-Problems"
2630                GHW_MakeRecordOfProgress("Abort in : "+GetRTStackInfo(3)+" - xml configuration file was not found",abortProgress=1 )
2631        endif
2632        FileContent = PadString(FileContent, V_logEOF, 0x20 )
2633        Open fileID  as PathToLocalData+PackageListxml
2634        FBinRead fileID, FileContent
2635        close fileID
2636        FileContent=GHI_XMLremoveComments(FileContent)          //get rid of comments, confuses the rest of the code...
2637        //FileContent now contains content of the xml configuration file...
2638        string InstallerText=GHI_XMLtagContents("PackageContent",FileContent)   //if nothing, wrong format
2639        if(strlen(InstallerText)<10)    //no real content
2640                SetDataFolder saveDFR                                   // Restore current data folder
2641                BrowseURL "https://github.com/jilavsky/SAXS_IgorCode/wiki/Installation-Problems"
2642                GHW_MakeRecordOfProgress("Abort in : "+GetRTStackInfo(3)+" - Nothing found in a file "+PathToLocalData+PackageListxml,abortProgress=1 )
2643        endif
2644        //known keywords: xopLinks for xop from Wavemetrics -> link to Igor Extensions (64-bit)
2645        //FileLinks for ipf files from Wavemetrics  -> link to User Procedures
2646        //and for ipf/ihf FolderFileLocation & File - copy from source to same place in User Procedures
2647        PackgListFiles                  = GHW_ListPlatformSpecificValues(FileContent, "File", IgorInfo(2))
2648        PackgListFilePaths              = stringFromList(0,GHW_ListPlatformSpecificValues(FileContent, "FolderFileLocation", IgorInfo(2)),";") 
2649        PackgListxopLinks               = GHW_ListPlatformSpecificValues(FileContent, "xopLinks", IgorInfo(2))
2650        PackgListFileLinks      = GHW_ListPlatformSpecificValues(FileContent, "FileLinks", IgorInfo(2))
2651        //these are list of files to copy and link as necessary
2652        variable j
2653        //process file and folders
2654        For(j=0;j<ItemsInList(PackgListFiles);j+=1)
2655                GHW_CopyOneFileFromDistribution(PathToLocalData, PackgListFilePaths, StringFromList(j,PackgListFiles,";"))
2656        endfor
2657        //process links.
2658        For(j=0;j<ItemsInList(PackgListxopLinks);j+=1)
2659                GHW_CreateLinks( StringFromList(j,PackgListxopLinks,";"))
2660        endfor
2661        For(j=0;j<ItemsInList(PackgListFileLinks);j+=1)
2662                GHW_CreateLinks(StringFromList(j,PackgListFileLinks,";"))
2663        endfor
2664       
2665       
2666end
2667//**************************************************************************************************************************************
2668//**************************************************************************************************************************************
2669
2670
2671Function GHW_CreateLinks(FileToLink)
2672        string  FileToLink
2673        //the FileToLink is either Wavemetrics xop
2674        //of Wavemetrics ipf file. Nothing else supportede at this time.
2675        FileToLink = ReplaceString("/", FileToLink, ":")
2676        string ExtOrProcPath
2677        string FileToLinkLoc
2678        if(StringMatch(FileToLink, "*.xop"))            //xop
2679                if(stringMatch(FileToLink,"* (64-bit)*"))
2680                        ExtOrProcPath = "Igor Extensions (64-bit)"
2681                else    //old 32 bits
2682                        ExtOrProcPath = "Igor Extensions"
2683                endif
2684        else
2685                ExtOrProcPath = "Igor Procedures"
2686        endif
2687        if(stringMatch(IgorInfo(2),"Macintosh"))
2688                FileToLinkLoc   =       FileToLink
2689        else            //windows, add .lnk to the name
2690                FileToLinkLoc   =       FileToLink+".lnk"
2691        endif
2692        string FileToLinkName=StringFromList(ItemsInList(FileToLinkLoc, ":")-1, FileToLinkLoc, ":")
2693        NewPath /O/Q targetFileFolderPath, SpecialDirPath("Igor Pro User Files", 0, 0, 0 )+ExtOrProcPath
2694        string IgorUserFilePathStr=SpecialDirPath("Igor Pro User Files", 0, 0, 0 )+ExtOrProcPath+":"
2695        NewPath /O/Q sourceFileFolderPath, SpecialDirPath("Igor Application", 0, 0, 0 )
2696        string SourceFileFolderPathStr = SpecialDirPath("Igor Application", 0, 0, 0 )
2697        //same process as with files, get rid of the old ones, if it can be done
2698        GetFileFolderInfo/Q/Z/P=targetFileFolderPath  FileToLinkName+".deleteMe"
2699        if(V_Flag==0)           //file/xop found, get rid of it
2700                if(V_isFile)
2701                        DeleteFile /P=targetFileFolderPath /Z FileToLinkName+".deleteMe"
2702                        if(V_flag!=0)
2703                                GHW_MakeRecordOfProgress("Could not delete "+FileToLinkName+".deleteMe")
2704                        endif
2705                elseif(V_isFolder)
2706                        DeleteFolder /P=targetFileFolderPath /Z FileToLinkName+".deleteMe"
2707                        if(V_flag!=0)
2708                                GHW_MakeRecordOfProgress("Could not delete "+FileToLinkName+".deleteMe")
2709                        endif
2710                elseif(V_isAliasShortcut)
2711                        DeleteFile /P=targetFileFolderPath /Z FileToLinkName+".deleteMe"
2712                        if(V_flag!=0)
2713                                GHW_MakeRecordOfProgress("Could not delete "+FileToLinkName+".deleteMe")
2714                        endif           
2715                endif
2716                GHW_MakeRecordOfProgress("Deleted old file : "+FileToLinkName+".deleteMe")
2717        endif
2718        //OK, now we can, if needed rename existing file AND keep the user folder cleaner
2719        //now check for existing target file and delete/rename if necessary
2720        GetFileFolderInfo/Q/Z/P=targetFileFolderPath  FileToLinkName
2721        if(V_Flag==0)           //old file/xop found, get rid of it
2722                if(V_isFile)
2723                        DeleteFile /P=targetFileFolderPath /Z FileToLinkName
2724                        if(V_flag!=0)
2725                                MoveFile /O/P=targetFileFolderPath FileToLinkName as FileToLinkName+".deleteMe"
2726                                GHW_MakeRecordOfProgress("Moved to .deleteMe existing file : "+FileToLinkName)
2727                        else
2728                                GHW_MakeRecordOfProgress("Deleted existing file : "+FileToLinkName)
2729                        endif
2730                elseif(V_isFolder)
2731                        DeleteFolder /P=targetFileFolderPath /Z FileToLinkName
2732                        if(V_flag!=0)
2733                                MoveFolder /O/P=targetFileFolderPath FileToLinkName as FileToLinkName+".deleteMe"
2734                                GHW_MakeRecordOfProgress("Moved to .deleteMe existing file : "+FileToLinkName)
2735                        else
2736                                GHW_MakeRecordOfProgress("Deleted existing file : "+FileToLinkName)
2737                        endif
2738                elseif(V_isAliasShortcut)
2739                        DeleteFile /P=targetFileFolderPath /Z FileToLinkName
2740                        if(V_flag!=0)
2741                                MoveFile /O/P=targetFileFolderPath FileToLinkName as FileToLinkName+".deleteMe"
2742                                GHW_MakeRecordOfProgress("Moved to .deleteMe existing file : "+FileToLinkName)
2743                        else
2744                                GHW_MakeRecordOfProgress("Deleted existing file : "+FileToLinkName)
2745                        endif           
2746                endif
2747                //print "Deleted/moved to .deleteMe existing file : "+FileToLinkName
2748        endif
2749        //now we should be able to make the alias
2750        //depends on platform and xop/not-xop...
2751        if(stringmatch(FileToLinkName,"*.xop*")&&stringMatch(IgorInfo(2),"Macintosh"))          //it is xop (folder) on Mac
2752                CreateAliasShortcut /D/I=0 /O /Z  (SourceFileFolderPathStr+FileToLink)   as    (IgorUserFilePathStr+FileToLinkName) 
2753                if(V_Flag==0)
2754                        GHW_MakeRecordOfProgress("Created shortcut : "+S_path+ "  linking to : "+SourceFileFolderPathStr+FileToLink)
2755                else
2756                        GHW_MakeRecordOfProgress("Could not create shortcut for "+IgorUserFilePathStr+FileToLinkName)
2757                endif
2758        else
2759                CreateAliasShortcut /I=0 /O /Z  (SourceFileFolderPathStr+FileToLink)   as    (IgorUserFilePathStr+removeEnding(FileToLinkName,".lnk")) 
2760                if(V_Flag==0)
2761                        GHW_MakeRecordOfProgress("Created shortcut : "+S_path+ "  linking to : "+SourceFileFolderPathStr+FileToLink )
2762                else
2763                        GHW_MakeRecordOfProgress("Could not create shortcut for "+IgorUserFilePathStr+FileToLinkName )
2764                endif
2765        endif
2766end
2767//**************************************************************************************************************************************
2768//**************************************************************************************************************************************
2769
2770
2771Function GHW_CopyOneFileFromDistribution(PathToLocalData, PackgListFilePaths, FileToCopy)
2772        string PathToLocalData, PackgListFilePaths, FileToCopy
2773
2774        if(strlen(FileToCopy)<2)
2775                return 0
2776        endif
2777        FileToCopy =  ReplaceString("/", FileToCopy, ":")
2778        if(!StringMatch(FileToCopy[0],":" ))            //make this in relative path for
2779                FileToCopy = ":"+FileToCopy
2780        endif
2781        //we get path to file/folder(xop) and will copy from source (PathToLocalData) to location
2782        //PackgListFilePaths is specific path where to look for the souce, not reproduced in target
2783        //FileToCopy is source and target path.
2784        //distribution is in PathToLocalData
2785        //target is in Igor User home area - Documents/Wavemetrics/Igor Pro 7 user Files
2786        //existing files needs to be deleted or if not possible, renamed into ....DeleteMe
2787        //any existing file with ....DeleteMe will be deleted first.
2788        //Path where to put the files
2789        NewPath /O/Q targetFileFolderPath, SpecialDirPath("Igor Pro User Files", 0, 0, 0 )
2790        string IgorUserFilePathStr=SpecialDirPath("Igor Pro User Files", 0, 0, 0 )
2791        NewPath /O/Q sourceFileFolderPath, PathToLocalData+PackgListFilePaths
2792        //PathInfo sourceFileFolderPath
2793        //print S_Path+FileToCopy
2794        //variable fileNum
2795        string tempStr, igorCmd
2796        GetFileFolderInfo/Q/Z/P=targetFileFolderPath  FileToCopy+".deleteMe"
2797        if(V_Flag==0)           //file/xop found, get rid of it
2798                if(V_isFile)
2799                        DeleteFile /P=targetFileFolderPath /Z FileToCopy+".deleteMe"
2800                        if(V_flag!=0)
2801                                GHW_MakeRecordOfProgress("Could not delete "+FileToCopy+".deleteMe")
2802                        endif
2803                elseif(V_isFolder)
2804                                //this does not work unless user approves DeleteFolder: DeleteFolder /P=targetFileFolderPath /Z FileToCopy+".deleteMe"
2805                                //here is nasty workaround using OS script...
2806                                PathInfo targetFileFolderPath
2807                                tempStr = replaceString("::",S_Path+FileToCopy,":")
2808                                tempStr=  RemoveFromList(StringFromList(0,tempStr  , ":"), tempStr  , ":")
2809                                tempStr = ParseFilePath(5, tempStr, "\\", 0, 0)
2810                                tempStr = ReplaceString("\\", tempStr, "/")
2811                                tempStr = "rm -Rdf  '/"+ReplaceString(".xop", tempStr, ".xop.deleteMe")+"'"
2812                                sprintf igorCmd, "do shell script \"%s\"", tempStr
2813                                //print igorCmd
2814                                ExecuteScriptText igorCmd
2815                                GetFileFolderInfo/Q/Z/P=targetFileFolderPath  FileToCopy+".deleteMe"
2816                                if(V_flag==0)
2817                                        GHW_MakeRecordOfProgress( "Could not delete folder/xop"+FileToCopy+".deleteMe")
2818                                else
2819                                        GHW_MakeRecordOfProgress( "Deleted old file : "+FileToCopy+".deleteMe")
2820                                endif
2821                elseif(V_isAliasShortcut)
2822                        DeleteFile /P=targetFileFolderPath /Z FileToCopy+".deleteMe"
2823                        if(V_flag!=0)
2824                                GHW_MakeRecordOfProgress( "Could not delete "+FileToCopy+".deleteMe")
2825                        endif           
2826                endif
2827                GHW_MakeRecordOfProgress( "Deleted old file : "+FileToCopy+".deleteMe")
2828        endif
2829        //OK, now we can, if needed rename existing file AND keep the user folder cleaner
2830        //now check for existing target file and delete/rename if necessary
2831        GetFileFolderInfo/Q/Z/P=targetFileFolderPath  FileToCopy
2832        if(V_Flag==0)           //old file/xop found, get rid of it
2833                if(V_isFile)
2834                        DeleteFile /P=targetFileFolderPath /Z FileToCopy
2835                        if(V_flag!=0)
2836                                MoveFile /O/P=targetFileFolderPath FileToCopy as FileToCopy+".deleteMe"
2837                                GHW_MakeRecordOfProgress( "Moved to .deleteMe existing file : "+FileToCopy)
2838                        else
2839                                GHW_MakeRecordOfProgress( "Deleted existing file : "+FileToCopy)               
2840                        endif
2841                elseif(V_isFolder)
2842                                GetFileFolderInfo/Q/Z/P=targetFileFolderPath  FileToCopy+".deleteMe"
2843                                if(V_flag!=0)
2844                                        MoveFolder /O/P=targetFileFolderPath FileToCopy as FileToCopy+".deleteMe"
2845                                        GHW_MakeRecordOfProgress( "Moved to .deleteMe existing file : "+FileToCopy)
2846                                else
2847                                        GHW_MakeRecordOfProgress( "Cannot delete existing file : "+FileToCopy +" the old .deleteMe file is still present")             
2848                                endif
2849                elseif(V_isAliasShortcut)
2850                        DeleteFile /P=targetFileFolderPath /Z FileToCopy
2851                        if(V_flag!=0)
2852                                MoveFile /O/P=targetFileFolderPath FileToCopy as FileToCopy+".deleteMe"
2853                                GHW_MakeRecordOfProgress( "Moved to .deleteMe existing file : "+FileToCopy)
2854                        else
2855                                GHW_MakeRecordOfProgress( "Deleted existing file : "+FileToCopy)               
2856                        endif
2857                endif
2858        endif
2859        //and now we can copy the file/folder in the right place
2860        //first need to check the target folder exists...
2861        string tempFldrName, FixedFileToCOpy, AlreadyCreatedPath
2862        string tmpIgorUserFilePathStr=IgorUserFilePathStr
2863        AlreadyCreatedPath = ""
2864        variable i
2865        if(stringmatch(FileToCopy[0],":"))
2866                FixedFileToCopy=FileToCopy[1,inf]
2867        else
2868                FixedFileToCopy=FileToCopy
2869        endif
2870        for(i=0;i<(ItemsInList(FixedFileToCopy,":")-1);i+=1)
2871                tempFldrName=AlreadyCreatedPath+StringFromList(i,FixedFileToCopy,":")
2872                AlreadyCreatedPath += StringFromList(i,FixedFileToCopy,":")+":"
2873                GetFileFolderInfo/Q/Z replaceString("::",IgorUserFilePathStr+tempFldrName,":")
2874                if(V_Flag!=0)   //deas not exist, make it
2875                        NewPath /C/O/Q tmpCreatePath  replaceString("::",IgorUserFilePathStr+tempFldrName,":")
2876                        GHW_MakeRecordOfProgress( "Created new folder " + replaceString("::",IgorUserFilePathStr+tempFldrName,":"))
2877                endif
2878                tmpIgorUserFilePathStr = replaceString("::",IgorUserFilePathStr+tempFldrName,":")+":"
2879        endfor
2880        GetFileFolderInfo/Q/Z/P=sourceFileFolderPath  FileToCopy                //this is source file
2881        if(V_Flag==0)                           //exists...
2882                if(V_isFile)                            //ipf, ihf, dll,... simply a file
2883                        CopyFile /O/P=sourceFileFolderPath /Z  FileToCopy as replaceString("::",IgorUserFilePathStr+FileToCopy,":")
2884                        if(V_flag)
2885                                GHW_MakeRecordOfProgress( "Abort in : "+GetRTStackInfo(3)+"Failed to copy "+FileToCopy, abortProgress=1)
2886                        endif
2887                elseif(V_isFolder)      //xops on Mac are folders
2888                        CopyFolder /O /P=sourceFileFolderPath/Z  FileToCopy as replaceString("::",IgorUserFilePathStr+FileToCopy,":")
2889                        if(V_flag)
2890                                GHW_MakeRecordOfProgress( "Abort in : "+GetRTStackInfo(3)+"Failed to copy "+FileToCopy, abortProgress=1)
2891                        endif   
2892                endif
2893                //note, this cannot handle links, separate code needed for making links.
2894                GHW_MakeRecordOfProgress( "Copied " + FileToCopy + " from "+PathToLocalData+PackgListFilePaths)
2895        else
2896                BrowseURL "https://github.com/jilavsky/SAXS_IgorCode/wiki/Installation-Problems"
2897                GHW_MakeRecordOfProgress( "Abort in : "+GetRTStackInfo(3)+"ERROR: Source File not found : " +FileToCopy, abortprogress=1)
2898        endif
2899        return 1
2900end
2901//**************************************************************************************************************************************
2902//**************************************************************************************************************************************
2903
2904Function/T GHW_FindNonStandardPckgVerNum(PathToLocalFile)
2905        string  PathToLocalFile
2906       
2907        return ""
2908end
2909//****************************************************************
2910//****************************************************************
2911
2912Function GHW_GenerateHelp()
2913        doWindow Inst_Help
2914        if(V_Flag)
2915                DoWindow/F Inst_Help
2916        else   
2917                String nb = "Inst_Help"
2918                NewNotebook/N=$nb/F=1/V=1/K=1/ENCG={3,1}/W=(159,40.25,652.5,736.25)
2919                Notebook $nb defaultTab=36, magnification=100
2920                Notebook $nb showRuler=1, rulerUnits=1, updating={1, 60}
2921                Notebook $nb newRuler=Normal, justification=0, margins={0,0,468}, spacing={0,0,0}, tabs={}, rulerDefaults={"Arial",10,0,(0,0,0)}
2922                Notebook $nb newRuler=Header, justification=1, margins={0,0,468}, spacing={0,0,0}, tabs={}, rulerDefaults={"Arial",10,0,(0,0,0)}
2923                Notebook $nb ruler=Header, fSize=12, fStyle=1, text="Installer for Irena, Nika, and Indra packages\r"
2924                Notebook $nb text="using Github depository.\r"
2925                Notebook $nb text="https://github.com/jilavsky/SAXS_IgorCode\r"
2926                Notebook $nb ruler=Normal, fSize=-1, fStyle=-1, text="\r"
2927                Notebook $nb fStyle=2, text="Jan Ilavsky, May 2020\r"
2928                Notebook $nb fStyle=-1, text="\r"
2929                Notebook $nb fStyle=1, text="NOTE:", fSize=9, text=" ", fStyle=-1
2930                Notebook $nb text="Install ONLY packages you really need. Here are hints...\r"
2931                Notebook $nb text="Irena ... package for modeling of small-angle scattering data (and reflectivity)\r"
2932                Notebook $nb text="Nika ...  package for reduction of data from area detectors (pinhole cameras) 2D -> 1D\r"
2933                Notebook $nb text="Indra ... package for data reduction of USAXS data (unless you measured on APS USAXS or own Rigaku USAXS"
2934                Notebook $nb text=", this is _NOT_ for you) \r"
2935                Notebook $nb fSize=-1, text="\r"
2936                Notebook $nb fStyle=3, textRGB=(52428,1,1), text="Help:\r"
2937                Notebook $nb fStyle=-1, textRGB=(0,0,0), text="\r"
2938                Notebook $nb text="1. ", fStyle=4, textRGB=(0,0,65535), text="https://www.youtube.com/channel/UCDTzjGr3mAbRi3O4DJG7xHA\r"
2939                Notebook $nb fStyle=-1, textRGB=(0,0,0), text="2. ", fStyle=4, textRGB=(0,0,65535)
2940                Notebook $nb text="https://saxs-igorcodedocs.readthedocs.io/en/stable/Installation.html#instructions-for-installation\r"
2941                Notebook $nb fStyle=-1, textRGB=(0,0,0), text="3. ", fStyle=4, textRGB=(0,0,65535)
2942                Notebook $nb text="https://github.com/jilavsky/SAXS_IgorCode/wiki/Installation-Problems", fStyle=-1, textRGB=(0,0,0)
2943                Notebook $nb text=" \r"
2944                Notebook $nb text="\r"
2945                Notebook $nb fStyle=1, text="Requirements", fStyle=-1, text=": \r"
2946                Notebook $nb fSize=9
2947                Notebook $nb text="1.   Igor 8.04 or higher.  Igor 7.08 is end of life, upgrade (it may still work, but is untested now). \r"
2948                Notebook $nb text="2.   Access to the depository or downloaded zip file of a release from this depository (", fStyle=1
2949                Notebook $nb text="https://github.com/jilavsky/SAXS_IgorCode)\r"
2950                Notebook $nb fSize=-1, fStyle=-1, text="\r"
2951                Notebook $nb fStyle=1, textRGB=(65535,0,0), text="Use", fStyle=-1, textRGB=(0,0,0), text=": \r"
2952                Notebook $nb text="1.\tSelect from \"", fStyle=2, text="Instal Packages", fStyle=-1, text="\" the menu the option \""
2953                Notebook $nb fStyle=2, text="Open GitHub GUI", fStyle=-1, text="\" to get the \"", fStyle=2, text="Install/Uninstall Package"
2954                Notebook $nb fStyle=-1, text="\"  Panel. \r"
2955                Notebook $nb text="2.\tSelect method of distribution you want to use: \r"
2956                Notebook $nb fSize=9, text="\ta/\t", fStyle=1, text="Default is Github", fStyle=-1
2957                Notebook $nb text=". Installer will download zip file, unzip, and install from it. \r"
2958                Notebook $nb text="\t\tMake sure the \"", fStyle=1, text="Use Local Folder", fStyle=-1, text="?\"checkbox is ", fStyle=5
2959                Notebook $nb text="unchecked", fStyle=-1, text=".  \r"
2960                Notebook $nb text="\t\tPush \"", fStyle=1, text="Check packages versions", fStyle=-1, text="\". \r"
2961                Notebook $nb text="\tb/\t", fStyle=1, text="Optional is local copy", fStyle=-1, text=" of the depository. \r"
2962                Notebook $nb text="\t\tMake sure the \"", fStyle=1, text="Use Local Folder", fStyle=-1, text="?\"checkbox is ", fStyle=5
2963                Notebook $nb text="checked", fStyle=4, text=".\r"
2964                Notebook $nb fStyle=-1, text="\t\tDownload zip file with version of packages from Github manually.\r"
2965                Notebook $nb text="\t\tUnzip, and place the folder from inside of the zip file (typically named SAXS_IgorCode_MonthYear) \r"
2966                Notebook $nb text="\t\t\ton the desktop together with this Igor Installer experiment.\r"
2967                Notebook $nb text="\t\tPush \"", fStyle=1, text="Check packages versions", fStyle=-1, text="\"\r"
2968                Notebook $nb fSize=-1, text="\r"
2969                Notebook $nb text="3.\tInstaller will check what version is available. It will offer table with versions. \r"
2970                Notebook $nb text="4.\tSelect package/releases to install (or unistall)  in \"", fStyle=3, text="Select release to install"
2971                Notebook $nb fStyle=-1, text="\". \r"
2972                Notebook $nb text="5.\tPush \"", fStyle=1, text="Install/Update", fStyle=-1, text="\" or \"", fStyle=1, text="Unistall"
2973                Notebook $nb fStyle=-1, text="\" buttons as needed\r"
2974                Notebook $nb text="\r"
2975                Notebook $nb text="when succesfully finished, you will get \"All done.\" Alert window and message in the history area. \r"
2976                Notebook $nb text="\r"
2977                Notebook $nb fStyle=1, text="Beta versions", fStyle=-1, text=": \r"
2978                Notebook $nb text="If you need/want latest beta version, check checkbox \"", fStyle=1, text="Include Beta releases"
2979                Notebook $nb fStyle=-1, text="\" and list in \"", fStyle=1, text="Select release to install", fStyle=-1
2980                Notebook $nb text="\" will include Beta versions and \"", fStyle=1, text="master", fStyle=-1
2981                Notebook $nb text="\" (listed at the end of the list).  \r"
2982                Notebook $nb text="\t", fStyle=1, text="Beta versions", fStyle=-1
2983                Notebook $nb text=" are released as needed when code is relatively stable. \r"
2984                Notebook $nb text="\t\"", fStyle=1, text="master", fStyle=-1
2985                Notebook $nb text="\" is latest version at the time of download available in the depository. \r"
2986                Notebook $nb text="Note, there are no guarrantees the master will even work, that code is under developement! "
2987                Notebook $nb fStyle=3, textRGB=(52428,1,1)
2988                Notebook $nb text="Install Master only when instructed by author. Typically because a bug you have issues with was fixed fo"
2989                Notebook $nb text="r you.", fStyle=1, text="  \r"
2990                Notebook $nb fStyle=-1, textRGB=(0,0,0), text="\r"
2991                Notebook $nb text="If there are problems, you will get error message with instructions. First follow instructions on :"
2992                Notebook $nb fStyle=4, textRGB=(0,0,65535), text=" https://github.com/jilavsky/SAXS_IgorCode/wiki/Installation-Problems \r"
2993                Notebook $nb fStyle=-1, textRGB=(0,0,0), text="\r"
2994                Notebook $nb text="If that does not work, let author know and", textRGB=(0,1,2), text=", please, send me the log file \""
2995                Notebook $nb textRGB=(0,0,0), text="InstallRecord.txt", textRGB=(0,1,2)
2996                Notebook $nb text="\" from your desktop together with information on yoru computer - Windows version, path to your .../Wavem"
2997                Notebook $nb text="etrics/Igor Pro User Files and anything else special on yrou computer.\r"
2998                Notebook $nb textRGB=(0,0,0), text="\r"
2999                Notebook $nb text="After sucessful installation, code will attempt to delete the distribution zip file and the unzipped fol"
3000                Notebook $nb text="der from desktop. It will ask for permissions to do it. If it fails - or you do not let it - do it manua"
3001                Notebook $nb text="lly. You can delete also the logfile (InstallRecord.txt) file from desktop.\r"
3002                Notebook $nb text="\r"
3003                Notebook $nb text="note: download of distribution zip file may take a long time (they are around 100Mb). You may want to ke"
3004                Notebook $nb text="ep it in case you want to reinstall in short future. If proper zip file is found on desktop, it will be "
3005                Notebook $nb text="used even in subsequent installations. \r"
3006                Notebook $nb text="\r"
3007                Notebook $nb text="Install xop files based on bit-version you intend to use (or simply install both if you have 64-bit mach"
3008                Notebook $nb text="ine). The xop packages are needed for any package.\r"
3009                Notebook $nb text="\r"
3010                Notebook $nb text="After any unistallation, you should reinstall packages you intend to use. Another words, since packages "
3011                Notebook $nb text="share libraries, after any uninstallation of only one package the other packages are likely unusable. \r"
3012                Notebook $nb text="\r"
3013                Notebook $nb text="*** ", fSize=11, fStyle=1, textRGB=(52428,1,1)
3014                Notebook $nb text="You can always update to the latest version of the packages using this experiment. When I update the on "
3015                Notebook $nb text="line depository, this experiment will pick the listing and re-download ALL packages again. To check whic"
3016                Notebook $nb text="h version is the last one available on the web, use button \"Check packages versions"
3017                Notebook $nb fSize=-1, fStyle=-1, textRGB=(0,1,2), text="\".\r"
3018                Notebook $nb text="\r"
3019                Notebook $nb text="ilavsky@aps.anl.gov\r"
3020        endif
3021end
3022
3023
3024//**************************************************************************************************************************************
3025//**************************************************************************************************************************************
3026// this is unzip method using PowerShell. Works for Windows 8 and 10. It would also work for Mac, not that is not needed.
3027
3028// returns 1 for success, 0 for failure
3029function GHW_unzipArchive(archivePathStr, unzippedPathStr)
3030    string archivePathStr, unzippedPathStr
3031       
3032    string validExtensions="zip;" // set to "" to skip check
3033    variable verbose=1  // choose whether to print output from executescripttext
3034    verbose = 0                                 //does not work on Windows anyway...
3035    string msg, unixCmd, cmd
3036       
3037    GetFileFolderInfo /Q/Z archivePathStr
3038
3039    if(V_Flag || V_isFile==0)
3040        printf "Could not find file %s\r", archivePathStr
3041        return 0
3042    endif
3043
3044    if(itemsInList(validExtensions) && findlistItem(ParseFilePath(4, archivePathStr, ":", 0, 0), validExtensions, ";", 0, 0)==-1)
3045        printf "%s doesn't appear to be a zip archive\r", ParseFilePath(0, archivePathStr, ":", 1, 0)
3046        return 0
3047    endif
3048   
3049    if(strlen(unzippedPathStr)==0)
3050        unzippedPathStr=SpecialDirPath("Desktop",0,0,0)+ParseFilePath(3, archivePathStr, ":", 0, 0)
3051        sprintf msg, "Unzip to %s:%s?", ParseFilePath(0, unzippedPathStr, ":", 1, 1), ParseFilePath(0, unzippedPathStr, ":", 1, 0)
3052        doALert 1, msg
3053        if (v_flag==2)
3054            return 0
3055        endif
3056    else
3057        GetFileFolderInfo /Q/Z unzippedPathStr
3058        if(V_Flag || V_isFolder==0)
3059            sprintf msg, "Could not find unzippedPathStr folder\rCreate %s?", unzippedPathStr
3060            doalert 1, msg
3061            if (v_flag==2)
3062                return 0
3063            endif
3064        endif   
3065    endif
3066   
3067    // make sure unzippedPathStr folder exists - necessary for mac
3068    newpath /C/O/Q acw_tmpPath, unzippedPathStr
3069    killpath /Z acw_tmpPath
3070
3071    if(stringmatch(StringByKey("OS", igorinfo(3))[0,2],"Win")) // Windows
3072        // The following works with .Net 4.5, which is available in Windows 8 and up.
3073        // current versions of Windows with Powershell 5 can use the more succinct PS command
3074        // 'Expand-Archive -LiteralPath C:\archive.zip -DestinationPath C:\Dest'
3075        //  Expand-Archive -LiteralPath C:\Archives\Invoices.Zip -DestinationPath C:\InvoicesUnzipped -Force
3076        //https://blog.netwrix.com/2018/11/06/using-powershell-to-create-zip-archives-and-unzip-files/
3077        //string strVersion=StringByKey("OSVERSION", igorinfo(3))  //this does not work, Windows 10 report 6.x
3078        variable WinVersion=str2num(StringByKey("OS", igorinfo(3))[7,12])               //this extractssimply number from OS key, should be 7, 8, 10 for now.
3079        if (WinVersion<8)
3080            print "unzipArchive requires Windows 8 or later"
3081            return 0
3082        endif
3083       
3084        archivePathStr=parseFilePath(5, archivePathStr, "\\", 0, 0)
3085        unzippedPathStr=parseFilePath(5, unzippedPathStr, "\\", 0, 0)
3086        cmd="powershell.exe -nologo -noprofile -command \"& { Add-Type -A 'System.IO.Compression.FileSystem';"
3087        sprintf cmd "%s [IO.Compression.ZipFile]::ExtractToDirectory('%s', '%s'); }\"", cmd, archivePathStr, unzippedPathStr
3088    else // Mac
3089        sprintf unixCmd, "unzip %s -d %s", ParseFilePath(5, archivePathStr, "/", 0,0), ParseFilePath(5, unzippedPathStr, "/", 0,0)
3090        sprintf cmd, "do shell script \"%s\"", unixCmd
3091    endif
3092   
3093    executescripttext /B/UNQ/Z cmd
3094    if(verbose)
3095        print S_value // output from executescripttext
3096    endif
3097   
3098    return (v_flag==0)
3099end
Note: See TracBrowser for help on using the repository browser.