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

Last change on this file since 1163 was 1163, checked in by ilavsky, 13 months ago

New Installer, fix bioSAXS tools saving _sub data when NOT using liberal names.

  • Property svn:eol-style set to native
File size: 150.8 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 issue with Giithub chanign location of zip files.            string InternalDataName = "SAXS_IgorCode"
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 disappear 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                //or use ksWebAddressForMaster???
1359                LookHere = ListOfReleases[WhichReleaseUserWants][2]
1360                string URLtoGet=StringByKey("SourceFileAddress", LookHere  , "=",";")
1361                //need to build name of data inside the zip file...
1362                variable ItemsInPath=ItemsInList(URLtoGet,"/")
1363                //string InternalDataName = StringFromList(ItemsInPath-3, URLtoGet, "/") - this breaks on GH chanign location of zip file
1364                string InternalDataName = "SAXS_IgorCode"
1365                if(stringmatch(SelectedReleaseName,"master"))
1366                        URLtoGet = RemoveListItem(ItemsInPath-1, URLtoGet, "/")+"master.zip"
1367                        URLtoGet = ReplaceString("tags", URLtoGet, "heads")
1368                        InternalDataName =InternalDataName+"-master"
1369                else
1370                        InternalDataName +="-"+ RemoveEnding(StringFromList(ItemsInPath-1, URLtoGet, "/"),".zip")
1371                endif
1372                GHW_MakeRecordOfProgress("Installation from Github zip source "+URLtoGet+" started. " )
1373                string FileContent
1374                variable refNum
1375                NewPath/O/C/Q userDesktop, SpecialDirPath("Desktop",0,0,0)
1376                String destinationZip = SpecialDirPath("Desktop",0,0,0)+InternalDataName+".zip"
1377                String DesktopFldr = SpecialDirPath("Desktop",0,0,0)
1378                String destinationFldr = DesktopFldr+InternalDataName
1379                variable SkipDownload=0
1380                if (GHW_FileFolderExists(destinationZip,file=1))
1381                        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]"
1382                        if(V_Flag==1)
1383                                //use existing
1384                                SkipDownload = 1
1385                                GHW_MakeRecordOfProgress("Found existing "+InternalDataName+".zip file and user choose to use it. " )
1386                        elseif(V_Flag==2)
1387                                DeleteFile /P=userDesktop (InternalDataName+".zip") 
1388                                GHW_MakeRecordOfProgress("Found existing "+InternalDataName+".zip file and user choose to delete it. " )
1389                        else
1390                                GHW_MakeRecordOfProgress("Found existing "+InternalDataName+".zip file and user choose to abort. ", abortprogress=1 )
1391                        endif
1392                endif
1393                if(!SkipDownload)
1394                        GHW_DownloadWarning()
1395                        GUIReportActivityForUser = "Downloading Package zip file from GitHub"
1396                        GHW_MakeRecordOfProgress("Downloading Package zip file "+URLtoGet+" from GitHub " )
1397                        FileContent=FetchURL(URLtoGet)
1398                        Variable error = GetRTError(1)
1399                        if (error != 0)
1400                                DoWIndow/K DownloadWarning
1401                                GHW_MakeRecordOfProgress("Abort in : "+GetRTStackInfo(3)+"Error Downloading Package zip file "+URLtoGet+" from GitHub.", abortprogress=0)
1402                                print "**************************************************************************************************************************************"
1403                                print "**************************************************************************************************************************************"
1404                                print "Instructions for fix : "
1405                                print "Download of distribution zip file : "+ URLtoGet + "   failed."
1406                                print "This is typically firewall/network problem beyond installer control"
1407                                print "You need to download this file manually using web browser"
1408                                print "Place it on Desktop and unzip - make sure that a folder with same name as the zip file is created on the desktop"
1409                                print "Now start the installation again, but check \"Use local folder?\" checkbox and point installer to the newly created folder. Install from there."
1410                                print "**************************************************************************************************************************************"
1411                                print "**************************************************************************************************************************************"
1412                                DoAlert /T="Download error, installer will abort." 0, "Download of distribution file failed. See history area for instructions"
1413                                BrowseURL "https://github.com/jilavsky/SAXS_IgorCode/wiki/Installation-Problems"
1414                                abort
1415                        endif
1416                        sleep/S 3               //just to flush the data to disk and avoid getting ahead of system with reading file in cache.
1417                        //                      str= "Done downloading distribution zip file, got : "+num2str(1.0486*strlen(fileBytes)/(1024*1024))+" Mbytes"
1418                        //                      Inst_Append2Log(str,0)
1419                        Open/P=userDesktop  refNum as (InternalDataName+".zip")
1420                        FBinWrite refNum, FileContent
1421                        Close refNum
1422                        FileContent=""
1423                        DoWIndow/K DownloadWarning
1424                endif
1425                //the distribution zip file should be on the desktop.
1426                variable err
1427                GHW_DownloadWarning()
1428                if(stringmatch(IgorInfo(2),"Windows"))
1429                        //WIndows, need to get user to unzip the file
1430                        GUIReportActivityForUser = "Unzipping "+InternalDataName+".zip file."
1431                        GHW_MakeRecordOfProgress("Windows : Unzipping the file "+InternalDataName+".zip file. " )       
1432                        GHW_UnzipFileOnDesktopWindows(InternalDataName+".zip", InternalDataName, 0)
1433                else
1434                        //unzip on Mac using script.
1435                        GUIReportActivityForUser = "Unzipping "+InternalDataName+".zip file."
1436                        GHW_MakeRecordOfProgress("Macintosh : unzipping "+InternalDataName+".zip file." )
1437                        err = GHW_UnZipOnMac(InternalDataName+".zip",DesktopFldr,deleteZip=0, overWrite=1, printIt=1)
1438                        if(err)
1439                                GHW_MakeRecordOfProgress("Abort in : "+GetRTStackInfo(3)+"Error in unzipping of "+InternalDataName+".zip file on OSX.", abortprogress=1 )
1440                        endif
1441                endif
1442                DoWIndow/K DownloadWarning
1443                //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.
1444                //install packages as user requested   
1445                ListOfPackagesToInstall =""     
1446                For(i=0;i<dimsize(SelVersionsAndInstall,0);i+=1)
1447                        if(SelVersionsAndInstall[i][3]>32)
1448                                ListOfPackagesToInstall += VersionsAndInstall[i][0]+"_"+VersionsAndInstall[i][2]+","
1449                                ToModifyPackagesList+=VersionsAndInstall[i][0]+";"
1450                                PackageListsToDownload+=StringByKey(VersionsAndInstall[i][0]+"_PackageList", LookHere  , "=", ";")+";"
1451                        endif
1452                endfor
1453                GHW_MakeRecordOfProgress("User picked following packages to install: "+PackageListsToDownload )
1454                For(i=0;i<ItemsInList(ToModifyPackagesList);i+=1)
1455                        GHW_MakeRecordOfProgress("*****   Started installation of file from  : "+StringFromList(i,PackageListsToDownload) +"  *******")
1456                        GHW_InstallPackage(DesktopFldr+InternalDataName,StringFromList(i,PackageListsToDownload))
1457                endfor
1458                GHW_MakeRecordOfProgress("Installation from local folder "+LocalFolderPath+" finished. All done. " )
1459                GHW_SubmitRecordToWeb(ListOfPackagesToInstall, SelectedReleaseName, "success")
1460                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. "
1461                DeleteFile /P=userDesktop/Z  InternalDataName+".zip"
1462                DeleteFile /P=userDesktop/Z  "InstallRecord.log"
1463                DeleteFolder /P=userDesktop/Z  InternalDataName
1464        endif   
1465        SetDataFolder saveDFR                                   // Restore current data folder
1466end
1467//**************************************************************************************************************************************
1468//**************************************************************************************************************************************
1469//PackageListsToDownload contains WhichPackages
1470//SelectedReleaseName contains InstallMethodType if "Local Folder" or Master,
1471Function GHW_SubmitRecordToWeb(WhichPackages, InstallMethodType, ResultMessage)
1472        string WhichPackages, ResultMessage, InstallMethodType
1473
1474        string Accesskey="IrenaNikaInstallations"
1475        string PackagesInstalled=WhichPackages
1476        string IgorVersionStr=IgorInfo(2)+" "+num2str(IgorVersion())
1477        string DataPath=SpecialDirPath("Igor Pro User Files", 0, 0, 0 )
1478        string DownloadType=InstallMethodType
1479        string Success=ResultMessage
1480       
1481        string pathtourl=""
1482        pathtourl = strConstRecordwwwAddress
1483        pathtourl += "key="+Accesskey+"&"
1484        pathtourl += "packages="+PackagesInstalled+"&"
1485        pathtourl += "igor_version="+IgorVersionStr+"&"
1486        pathtourl += "path="+DataPath+"&"
1487        pathtourl += "install_method="+DownloadType+"&"
1488        pathtourl += "status="+Success 
1489        pathtourl = ReplaceString(" ", pathtourl, "%20")
1490        //print pathtourl       
1491        URLRequest /TIME=2/Z url=pathtourl
1492        //print V_Flag
1493        //print V_responseCode
1494        //print S_serverResponse
1495end
1496//**************************************************************************************************************************************
1497//**************************************************************************************************************************************
1498
1499Static Function GHW_UnZipOnMac(zipFile,DestFolder,[deleteZip,overWrite,printIt])
1500        String zipFile                          // name of zip file to expand
1501        String DestFolder                       // folder to put results (defaults to same folder as zip file"
1502        Variable deleteZip              // if True, delete the zip file when done (default is NO delete)
1503        Variable overWrite              // if True, over write existing files when un-zipping (default is NOT overwite)
1504        Variable printIt
1505        deleteZip = ParamIsDefault(deleteZip) || numtype(deleteZip) ? 0 : deleteZip
1506        overWrite = ParamIsDefault(overWrite) || numtype(overWrite) ? 0 : overWrite
1507        printIt = ParamIsDefault(printIt) || numtype(printIt) ? strlen(GetRTStackInfo(2))==0 : printIt
1508        String str=""
1509        if (!StringMatch(IgorInfo(2),"Macintosh"))
1510                GHW_MakeRecordOfProgress("Macintosh : ERROR -- UnZipOnMac() only works on Macintosh")
1511                return 1
1512        endif
1513
1514        //create Path to Desktop
1515        NewPath/O Desktop, SpecialDirPath("Desktop", 0, 0, 0 )
1516        // check for valid input zip file
1517        // check for valid input zip file
1518        GetFileFolderInfo/P=Desktop/Q/Z=1 zipFile
1519        if (V_Flag || !V_isFile)
1520                if (printIt)
1521                        sprintf str, "Macintosh : Error - did not find valid \"%s\" file\r",zipFile
1522                        GHW_MakeRecordOfProgress(str)
1523                endif
1524                return 1
1525        endif
1526        printIt = StringMatch(S_Path,zipFile) ? printIt : 1
1527
1528        zipFile = S_Path
1529        if (!StringMatch(ParseFilePath(4,zipFile,":",0,0),"zip"))
1530                if (printIt)
1531                        sprintf str, "Macintosh : ERROR -- \"%s\" is not a zip file\r",zipFile
1532                        GHW_MakeRecordOfProgress(str)
1533                endif
1534                return 1
1535        endif
1536
1537        // check for valid destination folder
1538        if (strlen(DestFolder)<1)
1539                DestFolder = ParseFilePath(1,zipFile,":",1,0)
1540        endif
1541        GetFileFolderInfo/P=Desktop/Q/Z=1 DestFolder
1542        if (V_Flag || !V_isFolder)
1543                if (printIt)
1544                        GHW_MakeRecordOfProgress("Macintosh : ERROR -- destination folder not found, nothing done")
1545                endif
1546                return 1
1547        endif
1548        DestFolder = S_Path
1549        printIt = StringMatch(S_Path,DestFolder) ? printIt : 1
1550
1551        // get POSIX versions of paths for the shell script
1552        String zipFilePOSIX = ParseFilePath(5,zipFile,"/",0,0)
1553        String DestFolderPOSIX = ParseFilePath(5,DestFolder,"/",0,0)
1554
1555        // create the shell script and execute it
1556        String cmd, switches=SelectString(overWrite,""," -o")
1557        sprintf cmd, "do shell script \"unzip %s \\\"%s\\\" -d \\\"%s\\\"\"", switches, zipFilePOSIX,DestFolderPOSIX
1558        ExecuteScriptText/Z/UNQ cmd                                             //returns something only on error
1559        if (V_flag)
1560                sprintf str, "\r  ERROR -unzipping,  V_flag =",V_flag
1561                GHW_MakeRecordOfProgress(str)
1562                sprintf str, "cmd = ",ReplaceString("\n",cmd,"\r")
1563                GHW_MakeRecordOfProgress(str)
1564                sprintf str, "\r  S_value =",ReplaceString("\n",S_value,"\r")
1565                GHW_MakeRecordOfProgress(str)
1566                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."
1567                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."
1568                return V_flag                                                                   // all done, to not consider deleting the zip file
1569        elseif (printIt)
1570                sprintf str, "unzipping \"%s\"  -->  \"%s\"\r", zipFilePOSIX, DestFolderPOSIX
1571                GHW_MakeRecordOfProgress(str)
1572        endif
1573
1574        // optionally delete the zip file if requested
1575        if (deleteZip)
1576                DeleteFile/M="Delete the zip file"/Z zipFile
1577                if (V_flag==0 && printIt)
1578                        sprintf str, "Macintosh : Deleted:  \"%s\"\r", zipFile
1579                        GHW_MakeRecordOfProgress(str)
1580                endif
1581        endif
1582        return V_flag
1583End
1584//**************************************************************************************************************************************
1585//**************************************************************************************************************************************
1586Function GHW_UnzipFileOnDesktopWindows(ZipFileName, UnzippedFolderName, deleteSource)
1587        string ZipFileName                      // name of zip file on Desktop
1588        string UnzippedFolderName       //the folder name inside the zip file
1589        variable deleteSource           // also delete the source zip file if this is TRUE
1590        if (!StringMatch(IgorInfo(2),"Windows"))
1591                GHW_MakeRecordOfProgress("Abort in : "+GetRTStackInfo(3)+" ERROR -- UnzipFileOnDesktopWindows() only works on Windows",abortprogress=1)
1592                return 1
1593        endif
1594
1595        //create Path to Desktop
1596        NewPath/O Desktop, SpecialDirPath("Desktop", 0, 0, 0 )
1597        string strToDesktop = SpecialDirPath("Desktop", 0, 1, 0 )
1598        string strToTemp = SpecialDirPath("Temporary", 0, 1, 0 )
1599        //check that the file exists
1600        GetFileFolderInfo /P=Desktop /Q/Z=1 ZipFileName
1601        if(V_Flag!=0)
1602                BrowseURL "https://github.com/jilavsky/SAXS_IgorCode/wiki/Installation-Problems"
1603                GHW_MakeRecordOfProgress("Zip file not found on Desktop" )     
1604                Abort "Zip file not found on Desktop"
1605        endif   
1606
1607        //for WIndows 8 and higher, use new method using PowerShell
1608  variable WinVersion=str2num(StringByKey("OS", igorinfo(3))[7,12])             //this extracts simply number from OS key, should be 7, 8, 10 for now.
1609  variable success
1610  if (WinVersion>7.99)                          //Powershell is available only on Windows 8+
1611                GHW_MakeRecordOfProgress("Windows : Unzipping the file "+ZipFileName+" using Windows 8+ method. " )     
1612                success = GHW_unzipArchive(strToDesktop+ZipFileName, strToDesktop)
1613                if(success<0.5)         //0 means code failed.
1614                        GHW_MakeRecordOfProgress("Windows : FAILED Unzipping the file "+ZipFileName+" using Windows 8+ method. " )     
1615                        Abort "FAILED Unzipping the file "+ZipFileName+" using Windows 8+ method."
1616                endif
1617        else
1618                //create the command file on the desktop, this is Zipjs.bat per
1619                //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>
1620                DoWindow zipjsbat
1621                if(V_Flag==0)
1622                        GHW_CreateZipjsbat()   
1623                endif
1624                SaveNotebook/O/P=Desktop zipjsbat as "zipjs.bat"
1625           sleep/s 5  //wait to flush buffer so the file actually exists...
1626                DoWindow/K zipjsbat
1627                //created the zipjs.bat command file which will unzip the file for us, note must kill the internal Notebook
1628                //or Igor will held the file and Windows will throw errors
1629                //now create cmd in line with
1630                //             zipjs.bat unzip -source C:\myDir\myZip.zip -destination C:\MyDir -keep no -force no
1631                // the destination folder is created by the script.
1632                // -keep yes will keep the content of the zip file, -force yes will overwrite the tempfolder for the data if exists
1633                // be careful, -force yes will wipe out the destination, if exists, so make sure the data are directed to non-existing folder.
1634                string cmd = strToDesktop+"zipjs.bat unzip -source "
1635                cmd +=strToDesktop+stringFromList(ItemsInList(ZipFileName,":")-1, ZipFileName,":")+" -destination "
1636                cmd +=strToTemp+"IgorCode -keep yes -force yes"
1637                ExecuteScriptText cmd
1638           sleep/s 5  //wait to flush buffer so the file actually exists...
1639                //delete the batch file to clean up...
1640                DeleteFile /P=Desktop /Z  "zipjs.bat"
1641                if(deleteSource)
1642                        DeleteFile /P=Desktop /Z  ZipFileName           
1643                endif
1644                GHW_MakeRecordOfProgress("Windows : Unzipped file "+ZipFileName+" to temp folder")
1645                //now the folder IgorCode is in the Desktop/ZipFileTempFldr
1646                //and we need it in Desktop...
1647                //NewPath /C /O/Q/Z tempForIgorCode, strToDesktop+"IgorCode"
1648                cmd ="Xcopy  "+strToTemp+"IgorCode\\"+UnzippedFolderName+"\\*    "+strToDesktop+UnzippedFolderName+"\\ /s /y"
1649                //cmd =strToDesktop+"moveData.bat "+strToDesktop+"IgorCode\\IgorCode\\    "+strToDesktop+"IgorCode"
1650                ExecuteScriptText cmd
1651                GHW_MakeRecordOfProgress("Windows : Copied unzipped file "+ZipFileName+" from temp folder to folder : "+strToDesktop+UnzippedFolderName)
1652                sleep/s 5               //wait for some time to get OS chance to sort things out...
1653                //check that a file exists so we know the zip worked, and if not, let user unzip manually...
1654        endif
1655
1656        String TestFilePath = strToDesktop+UnzippedFolderName
1657        GetFileFolderInfo /Q/Z=1 TestFilePath
1658        if(V_Flag!=0)
1659                GHW_MakeRecordOfProgress("Windows : Unzipping/copy of file "+ZipFileName+" failed. Asked user to unzip manually.")
1660                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"
1661                GetFileFolderInfo /Q/Z=1 TestFilePath
1662                if(V_Flag!=0)
1663                        GHW_MakeRecordOfProgress("Windows : Even request for user to manually unzip the "+ZipFileName+" failed. aborting. ")
1664                        BrowseURL "https://github.com/jilavsky/SAXS_IgorCode/wiki/Installation-Problems"
1665                        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. "
1666                        return 1
1667                endif
1668        endif
1669        return 0
1670End     
1671//
1672Static Function GHW_CreateZipjsbat()
1673        //from https://github.com/npocmaka/batch.scripts/blob/master/hybrids/jscript/zipjs.bat
1674        //how to use see
1675        //http://stackoverflow.com/questions/28043589/how-can-i-compress-zip-and-uncompress-unzip-files-and-folders-with-bat
1676        // this is short summary of the description there. Can unzpi, zip and do much more...
1677        //
1678        //// 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)
1679        //call zipjs.bat unzip -source C:\myDir\myZip.zip -destination C:\MyDir -keep no -force no
1680        //
1681        //// lists content of a zip file and full paths will be printed (-flat yes)
1682        //call zipjs.bat list -source C:\myZip.zip\inZipDir -flat yes
1683        //
1684        //// lists content of a zip file and the content will be list as a tree (-flat no)
1685        //call zipjs.bat list -source C:\myZip.zip -flat no
1686        //
1687        //// prints uncompressed size in bytes
1688        //zipjs.bat getSize -source C:\myZip.zip
1689        //
1690        //// zips content of folder without the folder itself
1691        //call zipjs.bat zipDirItems -source C:\myDir\ -destination C:\MyZip.zip -keep yes -force no
1692        //
1693        //// zips file or a folder (with the folder itslelf)
1694        //call zipjs.bat zipItem -source C:\myDir\myFile.txt -destination C:\MyZip.zip -keep yes -force no
1695        //
1696        //// unzips only part of the zip with given path inside
1697        //call zipjs.bat unZipItem -source C:\myDir\myZip.zip\InzipDir\InzipFile -destination C:\OtherDir -keep no -force yes
1698        //call zipjs.bat unZipItem -source C:\myDir\myZip.zip\InzipDir -destination C:\OtherDir
1699        //
1700        //// adds content to a zip file
1701        //call zipjs.bat addToZip -source C:\some_file -destination C:\myDir\myZip.zip\InzipDir -keep no
1702        //call zipjs.bat addToZip -source  C:\some_file -destination C:\myDir\myZip.zip
1703
1704
1705        String nb = "zipjsbat"
1706        NewNotebook/N=$nb/F=0/V=0/K=1/W=(321,81.5,820.5,376.25)
1707        Notebook $nb defaultTab=20, statusWidth=252
1708        Notebook $nb font="Arial", fSize=10, fStyle=0, textRGB=(0,0,0)
1709        Notebook $nb text="@if (@X)==(@Y) @end /* JScript comment\r"
1710        Notebook $nb text="\t@echo off\r"
1711        Notebook $nb text="\t\r"
1712        Notebook $nb text="\trem :: the first argument is the script name as it will be used for proper help message\r"
1713        Notebook $nb text="\tcscript //E:JScript //nologo \"%~f0\" \"%~nx0\" %*\r"
1714        Notebook $nb text="\r"
1715        Notebook $nb text="\texit /b %errorlevel%\r"
1716        Notebook $nb text="\t\r"
1717        Notebook $nb text="@if (@X)==(@Y) @end JScript comment */\r"
1718        Notebook $nb text="\r"
1719        Notebook $nb text="\r"
1720        Notebook $nb text="/*\r"
1721        Notebook $nb text="Compression/uncompression command-line tool that uses Shell.Application and WSH/Jscript -\r"
1722        Notebook $nb text="http://msdn.microsoft.com/en-us/library/windows/desktop/bb774085(v=vs.85).aspx\r"
1723        Notebook $nb text="\r"
1724        Notebook $nb text="Some resources That I've used:\r"
1725        Notebook $nb text="http://www.robvanderwoude.com/vbstech_files_zip.php\r"
1726        Notebook $nb text="https://code.google.com/p/jsxt/source/browse/trunk/js/win32/ZipFile.js?r=161\r"
1727        Notebook $nb text="\r"
1728        Notebook $nb text="\r"
1729        Notebook $nb text="\r"
1730        Notebook $nb text="\r"
1731        Notebook $nb text="UPDATE *17-03-15*\r"
1732        Notebook $nb text="\r"
1733        Notebook $nb text="Devnullius Plussed noticed a bug in ZipDirItems  and ZipItem functions (now fixed)\r"
1734        Notebook $nb text="And also following issues (at the moment not handled by the script):\r"
1735        Notebook $nb text="- if there's not enough space on the system drive (usually C:\\) the script could produce various errors "
1736        Notebook $nb text=", most often the script halts.\r"
1737        Notebook $nb text="- Folders and files that contain unicode symbols cannot be handled by Shell.Application object.\r"
1738        Notebook $nb text="\r"
1739        Notebook $nb text="UPDATE *24-03-15*\r"
1740        Notebook $nb text="\r"
1741        Notebook $nb text="Error messages are caught in waitforcount method and if shuch pops-up the script is stopped.\r"
1742        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"
1743        Notebook $nb text="but only the possible reasons.\r"
1744        Notebook $nb text="\r"
1745        Notebook $nb text="------\r"
1746        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"
1747        Notebook $nb text="\r"
1748        Notebook $nb text="For sure there's a lot of room for improvements and optimization and I'm absolutely sure there are some "
1749        Notebook $nb text="bugs\r"
1750        Notebook $nb text="as the script is big enough to not have.\r"
1751        Notebook $nb text="\r"
1752        Notebook $nb text="\r"
1753        Notebook $nb text="\r"
1754        Notebook $nb text="!!!\r"
1755        Notebook $nb text="For suggestions contact me at - npocmaka@gmail.com\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="\r"
1761        Notebook $nb text="//////////////////////////////////////\r"
1762        Notebook $nb text="//   CONSTANTS\r"
1763        Notebook $nb text="\r"
1764        Notebook $nb text="// TODO - Shell.Application and Scripting.FileSystemObject objects could be set as global variables to a"
1765        Notebook $nb text="void theit creation\r"
1766        Notebook $nb text="// in every method.\r"
1767        Notebook $nb text="\r"
1768        Notebook $nb text="//empty zip character sequense\r"
1769        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"
1770        Notebook $nb text="\\0\\0\";\r"
1771        Notebook $nb text="\r"
1772        Notebook $nb text="var SLEEP_INTERVAL=200;\r"
1773        Notebook $nb text="\r"
1774        Notebook $nb text="//copy option(s) used by Shell.Application.CopyHere/MoveHere\r"
1775        Notebook $nb text="var NO_PROGRESS_BAR=4;\r"
1776        Notebook $nb text="\r"
1777        Notebook $nb text="\r"
1778        Notebook $nb text="//oprions used for zip/unzip\r"
1779        Notebook $nb text="var force=true;\r"
1780        Notebook $nb text="var move=false;\r"
1781        Notebook $nb text="\r"
1782        Notebook $nb text="//option used for listing content of archive\r"
1783        Notebook $nb text="var flat=false;\r"
1784        Notebook $nb text="\r"
1785        Notebook $nb text="var source=\"\";\r"
1786        Notebook $nb text="var destination=\"\";\r"
1787        Notebook $nb text="\r"
1788        Notebook $nb text="var ARGS = WScript.Arguments;\r"
1789        Notebook $nb text="var scriptName=ARGS.Item(0);\r"
1790        Notebook $nb text="\r"
1791        Notebook $nb text="//\r"
1792        Notebook $nb text="//////////////////////////////////////\r"
1793        Notebook $nb text="\r"
1794        Notebook $nb text="//////////////////////////////////////\r"
1795        Notebook $nb text="//   ADODB.Stream extensions\r"
1796        Notebook $nb text="\r"
1797        Notebook $nb text="if ( ! this.ADODB ) {\r"
1798        Notebook $nb text="\tvar ADODB = {};\r"
1799        Notebook $nb text="}\r"
1800        Notebook $nb text="\r"
1801        Notebook $nb text="if ( ! ADODB.Stream ) {\r"
1802        Notebook $nb text="\tADODB.Stream = {};\r"
1803        Notebook $nb text="}\r"
1804        Notebook $nb text="\r"
1805        Notebook $nb text="// writes a binary data to a file\r"
1806        Notebook $nb text="if ( ! ADODB.Stream.writeFile ) {\r"
1807        Notebook $nb text="\tADODB.Stream.writeFile = function(filename, bindata)\r"
1808        Notebook $nb text="\t{\r"
1809        Notebook $nb text="        var stream = new ActiveXObject(\"ADODB.Stream\");\r"
1810        Notebook $nb text="        stream.Type = 2;\r"
1811        Notebook $nb text="        stream.Mode = 3;\r"
1812        Notebook $nb text="        stream.Charset =\"ASCII\";\r"
1813        Notebook $nb text="        stream.Open();\r"
1814        Notebook $nb text="        stream.Position = 0;\r"
1815        Notebook $nb text="        stream.WriteText(bindata);\r"
1816        Notebook $nb text="        stream.SaveToFile(filename, 2);\r"
1817        Notebook $nb text="        stream.Close();\r"
1818        Notebook $nb text="\t\treturn true;\r"
1819        Notebook $nb text="\t};\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="\r"
1825        Notebook $nb text="//////////////////////////////////////\r"
1826        Notebook $nb text="//   common\r"
1827        Notebook $nb text="\r"
1828        Notebook $nb text="if ( ! this.Common ) {\r"
1829        Notebook $nb text="\tvar Common = {};\r"
1830        Notebook $nb text="}\r"
1831        Notebook $nb text="\r"
1832        Notebook $nb text="if ( ! Common.WaitForCount ) {\r"
1833        Notebook $nb text="\tCommon.WaitForCount = function(folderObject,targetCount,countFunction){\r"
1834        Notebook $nb text="\t\tvar shell = new ActiveXObject(\"Wscript.Shell\");\r"
1835        Notebook $nb text="\t\twhile (countFunction(folderObject) < targetCount ){\r"
1836        Notebook $nb text="\t\t\tWScript.Sleep(SLEEP_INTERVAL);\r"
1837        Notebook $nb text="\t\t\t//checks if a pop-up with error message appears while zipping\r"
1838        Notebook $nb text="\t\t\t//at the moment I have no idea how to read the pop-up content\r"
1839        Notebook $nb text="\t\t\t// to give the exact reason for failing\r"
1840        Notebook $nb text="\t\t\tif (shell.AppActivate(\"Compressed (zipped) Folders Error\")) {\r"
1841        Notebook $nb text="\t\t\t\tWScript.Echo(\"Error While zipping\");\r"
1842        Notebook $nb text="\t\t\t\tWScript.Echo(\"\");\r"
1843        Notebook $nb text="\t\t\t\tWScript.Echo(\"Possible reasons:\");\r"
1844        Notebook $nb text="\t\t\t\tWScript.Echo(\" -source contains filename(s) with unicode characters\");\r"
1845        Notebook $nb text="\t\t\t\tWScript.Echo(\" -produces zip exceeds 8gb size (or 2,5 gb for XP and 2003)\");\r"
1846        Notebook $nb text="\t\t\t\tWScript.Echo(\" -not enough space on system drive (usually C:\\\\)\");\r"
1847        Notebook $nb text="\t\t\t\tWScript.Quit(432);\r"
1848        Notebook $nb text="\t\t\t}\r"
1849        Notebook $nb text="\t\t\t\r"
1850        Notebook $nb text="\t\t}\r"
1851        Notebook $nb text="\t}\r"
1852        Notebook $nb text="}\r"
1853        Notebook $nb text="\r"
1854        Notebook $nb text="if ( ! Common.getParent ) {\r"
1855        Notebook $nb text="\tCommon.getParent = function(path){\r"
1856        Notebook $nb text="\t\tvar splitted=path.split(\"\\\\\");\r"
1857        Notebook $nb text="\t\tvar result=\"\";\r"
1858        Notebook $nb text="\t\tfor (var s=0;s<splitted.length-1;s++){\r"
1859        Notebook $nb text="\t\t\tif (s==0) {\r"
1860        Notebook $nb text="\t\t\t\tresult=splitted[s];\r"
1861        Notebook $nb text="\t\t\t} else {\r"
1862        Notebook $nb text="\t\t\t\tresult=result+\"\\\\\"+splitted[s];\r"
1863        Notebook $nb text="\t\t\t}\r"
1864        Notebook $nb text="\t\t}\r"
1865        Notebook $nb text="\t\treturn result;\r"
1866        Notebook $nb text="\t}\r"
1867        Notebook $nb text="}\r"
1868        Notebook $nb text="\r"
1869        Notebook $nb text="if ( ! Common.getName ) {\r"
1870        Notebook $nb text="\tCommon.getName = function(path){\r"
1871        Notebook $nb text="\t\tvar splitted=path.split(\"\\\\\");\r"
1872        Notebook $nb text="\t\treturn splitted[splitted.length-1];\r"
1873        Notebook $nb text="\t}\r"
1874        Notebook $nb text="}\r"
1875        Notebook $nb text="\r"
1876        Notebook $nb text="//file system object has a problem to create a folder with slashes at the end\r"
1877        Notebook $nb text="if ( ! Common.stripTrailingSlash ) {\r"
1878        Notebook $nb text="\tCommon.stripTrailingSlash = function(path){\r"
1879        Notebook $nb text="\t\twhile (path.substr(path.length - 1,path.length) == '\\\\') {\r"
1880        Notebook $nb text="\t\t\tpath=path.substr(0, path.length - 1);\r"
1881        Notebook $nb text="\t\t}\r"
1882        Notebook $nb text="\t\treturn path;\r"
1883        Notebook $nb text="\t}\r"
1884        Notebook $nb text="}\r"
1885        Notebook $nb text="//\r"
1886        Notebook $nb text="//////////////////////////////////////\r"
1887        Notebook $nb text="\r"
1888        Notebook $nb text="//////////////////////////////////////\r"
1889        Notebook $nb text="//   Scripting.FileSystemObject extensions\r"
1890        Notebook $nb text="\r"
1891        Notebook $nb text="if (! this.Scripting) {\r"
1892        Notebook $nb text="\tvar Scripting={};\r"
1893        Notebook $nb text="}\r"
1894        Notebook $nb text="\r"
1895        Notebook $nb text="if (! Scripting.FileSystemObject) {\r"
1896        Notebook $nb text="\tScripting.FileSystemObject={};\r"
1897        Notebook $nb text="}\r"
1898        Notebook $nb text="\r"
1899        Notebook $nb text="if ( ! Scripting.FileSystemObject.DeleteItem ) {\r"
1900        Notebook $nb text="\tScripting.FileSystemObject.DeleteItem = function (item) \r"
1901        Notebook $nb text="\t{\r"
1902        Notebook $nb text="\t\tvar FSOObj= new ActiveXObject(\"Scripting.FileSystemObject\");\r"
1903        Notebook $nb text="\t\tif (FSOObj.FileExists(item)){\r"
1904        Notebook $nb text="\t\t\tFSOObj.DeleteFile(item);\r"
1905        Notebook $nb text="\t\t\treturn true;\r"
1906        Notebook $nb text="\t\t} else if (FSOObj.FolderExists(item) ) {\r"
1907        Notebook $nb text="\t\t\tFSOObj.DeleteFolder(Common.stripTrailingSlash(item));\r"
1908        Notebook $nb text="\t\t\treturn true;\r"
1909        Notebook $nb text="\t\t} else {\r"
1910        Notebook $nb text="\t\t\treturn false;\r"
1911        Notebook $nb text="\t\t}\r"
1912        Notebook $nb text="\t}\r"
1913        Notebook $nb text="}\r"
1914        Notebook $nb text="\r"
1915        Notebook $nb text="\r"
1916        Notebook $nb text="if ( ! Scripting.FileSystemObject.ExistsFile ) {\r"
1917        Notebook $nb text="\tScripting.FileSystemObject.ExistsFile = function (path)\r"
1918        Notebook $nb text="\t{\r"
1919        Notebook $nb text="\t\tvar FSOObj= new ActiveXObject(\"Scripting.FileSystemObject\");\r"
1920        Notebook $nb text="\t\treturn FSOObj.FileExists(path);\r"
1921        Notebook $nb text="\t}\r"
1922        Notebook $nb text="}\r"
1923        Notebook $nb text="if ( !Scripting.FileSystemObject.ExistsFolder ) {\r"
1924        Notebook $nb text="\tScripting.FileSystemObject.ExistsFolder = function (path){\r"
1925        Notebook $nb text="\tvar FSOObj= new ActiveXObject(\"Scripting.FileSystemObject\");\r"
1926        Notebook $nb text="\t\treturn FSOObj.FolderExists(path);\r"
1927        Notebook $nb text="\t}\r"
1928        Notebook $nb text="}\r"
1929        Notebook $nb text="\r"
1930        Notebook $nb text="if ( ! Scripting.FileSystemObject.isFolder ) {\r"
1931        Notebook $nb text="\tScripting.FileSystemObject.isFolder = function (path){\r"
1932        Notebook $nb text="\tvar FSOObj= new ActiveXObject(\"Scripting.FileSystemObject\");\r"
1933        Notebook $nb text="\t\treturn FSOObj.FolderExists(path);\r"
1934        Notebook $nb text="\t}\r"
1935        Notebook $nb text="}\r"
1936        Notebook $nb text="\r"
1937        Notebook $nb text="\r"
1938        Notebook $nb text="\r"
1939        Notebook $nb text="if ( ! Scripting.FileSystemObject.isEmptyFolder ) {\r"
1940        Notebook $nb text="\tScripting.FileSystemObject.isEmptyFolder = function (path){\r"
1941        Notebook $nb text="\tvar FSOObj= new ActiveXObject(\"Scripting.FileSystemObject\");\r"
1942        Notebook $nb text="\t\tif(FSOObj.FileExists(path)){\r"
1943        Notebook $nb text="\t\t\treturn false;\r"
1944        Notebook $nb text="\t\t}else if (FSOObj.FolderExists(path)){\t\r"
1945        Notebook $nb text="\t\t\tvar folderObj=FSOObj.GetFolder(path);\r"
1946        Notebook $nb text="\t\t\tif ((folderObj.Files.Count+folderObj.SubFolders.Count)==0){\r"
1947        Notebook $nb text="\t\t\t\treturn true;\r"
1948        Notebook $nb text="\t\t\t}\r"
1949        Notebook $nb text="\t\t}\r"
1950        Notebook $nb text="\t\treturn false;\t\r"
1951        Notebook $nb text="\t}\r"
1952        Notebook $nb text="\r"
1953        Notebook $nb text="}\r"
1954        Notebook $nb text="\r"
1955        Notebook $nb text="if ( ! Scripting.FileSystemObject.CreateFolder) {\r"
1956        Notebook $nb text="\tScripting.FileSystemObject.CreateFolder = function (path){\r"
1957        Notebook $nb text="\t\tvar FSOObj= new ActiveXObject(\"Scripting.FileSystemObject\");\r"
1958        Notebook $nb text="\t\tFSOObj.CreateFolder(path);\r"
1959        Notebook $nb text="\t\treturn FSOObj.FolderExists(path);\r"
1960        Notebook $nb text="\t}\r"
1961        Notebook $nb text="}\r"
1962        Notebook $nb text="\r"
1963        Notebook $nb text="if ( ! Scripting.FileSystemObject.ExistsItem) {\r"
1964        Notebook $nb text="\tScripting.FileSystemObject.ExistsItem = function (path){\r"
1965        Notebook $nb text="\t\tvar FSOObj= new ActiveXObject(\"Scripting.FileSystemObject\");\r"
1966        Notebook $nb text="\t\treturn FSOObj.FolderExists(path)||FSOObj.FileExists(path);\r"
1967        Notebook $nb text="\t}\r"
1968        Notebook $nb text="}\r"
1969        Notebook $nb text="\r"
1970        Notebook $nb text="if ( ! Scripting.FileSystemObject.getFullPath) {\r"
1971        Notebook $nb text="\tScripting.FileSystemObject.getFullPath = function (path){\r"
1972        Notebook $nb text="\t\tvar FSOObj= new ActiveXObject(\"Scripting.FileSystemObject\");\r"
1973        Notebook $nb text="        return FSOObj.GetAbsolutePathName(path);\r"
1974        Notebook $nb text="\t}\r"
1975        Notebook $nb text="}\r"
1976        Notebook $nb text="//\r"
1977        Notebook $nb text="//////////////////////////////////////\r"
1978        Notebook $nb text="\r"
1979        Notebook $nb text="//////////////////////////////////////\r"
1980        Notebook $nb text="//   Shell.Application extensions\r"
1981        Notebook $nb text="if ( ! this.Shell ) {\r"
1982        Notebook $nb text="\tvar Shell = {};\r"
1983        Notebook $nb text="}\r"
1984        Notebook $nb text="\r"
1985        Notebook $nb text="if (! Shell.Application ) {\r"
1986        Notebook $nb text="\tShell.Application={};\r"
1987        Notebook $nb text="}\r"
1988        Notebook $nb text="\r"
1989        Notebook $nb text="if ( ! Shell.Application.ExistsFolder ) {\r"
1990        Notebook $nb text="\tShell.Application.ExistsFolder = function(path){\r"
1991        Notebook $nb text="\t\tvar ShellObj=new ActiveXObject(\"Shell.Application\");\r"
1992        Notebook $nb text="\t\tvar targetObject = new Object;\r"
1993        Notebook $nb text="\t\tvar targetObject=ShellObj.NameSpace(path);\r"
1994        Notebook $nb text="\t\tif (typeof targetObject === 'undefined' || targetObject == null ){\r"
1995        Notebook $nb text="\t\t\treturn false;\r"
1996        Notebook $nb text="\t\t}\r"
1997        Notebook $nb text="\t\treturn true;\r"
1998        Notebook $nb text="\t\r"
1999        Notebook $nb text="\t}\r"
2000        Notebook $nb text="}\r"
2001        Notebook $nb text="\r"
2002        Notebook $nb text="if ( ! Shell.Application.ExistsSubItem ) {\r"
2003        Notebook $nb text="\tShell.Application.ExistsSubItem = function(path){\r"
2004        Notebook $nb text="\t\tvar ShellObj=new ActiveXObject(\"Shell.Application\");\r"
2005        Notebook $nb text="\t\tvar targetObject = new Object;\r"
2006        Notebook $nb text="\t\tvar targetObject=ShellObj.NameSpace(Common.getParent(path));\r"
2007        Notebook $nb text="\t\tif (typeof targetObject === 'undefined' || targetObject == null ){\r"
2008        Notebook $nb text="\t\t\treturn false;\r"
2009        Notebook $nb text="\t\t}\r"
2010        Notebook $nb text="\t\t\r"
2011        Notebook $nb text="\t\tvar subItem=targetObject.ParseName(Common.getName(path));\r"
2012        Notebook $nb text="\t\tif(subItem === 'undefined' || subItem == null ){\r"
2013        Notebook $nb text="\t\t\treturn false;\r"
2014        Notebook $nb text="\t\t}\r"
2015        Notebook $nb text="\t\treturn true;\r"
2016        Notebook $nb text="\t\r"
2017        Notebook $nb text="\t}\r"
2018        Notebook $nb text="}\r"
2019        Notebook $nb text="\r"
2020        Notebook $nb text="\r"
2021        Notebook $nb text="if ( ! Shell.Application.ItemCounterL1 ) {\r"
2022        Notebook $nb text="\tShell.Application.ItemCounterL1 = function(path){\r"
2023        Notebook $nb text="\t\tvar ShellObj=new ActiveXObject(\"Shell.Application\");\r"
2024        Notebook $nb text="\t\tvar targetObject = new Object;\r"
2025        Notebook $nb text="\t\tvar targetObject=ShellObj.NameSpace(path);\r"
2026        Notebook $nb text="\t\tif (targetObject != null ){\r"
2027        Notebook $nb text="\t\t\treturn targetObject.Items().Count;\t\r"
2028        Notebook $nb text="\t\t} else {\r"
2029        Notebook $nb text="\t\t\treturn 0;\r"
2030        Notebook $nb text="\t\t}\r"
2031        Notebook $nb text="\t}\r"
2032        Notebook $nb text="}\r"
2033        Notebook $nb text="// shell application item.size returns the size of uncompressed state of the file.\r"
2034        Notebook $nb text="if ( ! Shell.Application.getSize ) {\r"
2035        Notebook $nb text="\tShell.Application.getSize = function(path){\r"
2036        Notebook $nb text="\t\tvar ShellObj=new ActiveXObject(\"Shell.Application\");\r"
2037        Notebook $nb text="\t\tvar targetObject = new Object;\r"
2038        Notebook $nb text="\t\tvar targetObject=ShellObj.NameSpace(path);\r"
2039        Notebook $nb text="\t\tif (! Shell.Application.ExistsFolder (path)){\r"
2040        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"
2041        Notebook $nb text=" the file\");\r"
2042        Notebook $nb text="\t\t\treturn 0;\r"
2043        Notebook $nb text="\t\t}\r"
2044        Notebook $nb text="\t\tif (typeof size === 'undefined'){\r"
2045        Notebook $nb text="\t\t\tvar size=0;\r"
2046        Notebook $nb text="\t\t}\r"
2047        Notebook $nb text="\t\tif (targetObject != null ){\r"
2048        Notebook $nb text="\t\t\t\r"
2049        Notebook $nb text="\t\t\tfor (var i=0; i<targetObject.Items().Count;i++){\r"
2050        Notebook $nb text="\t\t\t\tif(!targetObject.Items().Item(i).IsFolder){\r"
2051        Notebook $nb text="\t\t\t\t\tsize=size+targetObject.Items().Item(i).Size;\r"
2052        Notebook $nb text="\t\t\t\t} else if (targetObject.Items().Item(i).Count!=0){\r"
2053        Notebook $nb text="\t\t\t\t\tsize=size+Shell.Application.getSize(targetObject.Items().Item(i).Path);\r"
2054        Notebook $nb text="\t\t\t\t}\r"
2055        Notebook $nb text="\t\t\t}\r"
2056        Notebook $nb text="\t\t} else {\r"
2057        Notebook $nb text="\t\t\treturn 0;\r"
2058        Notebook $nb text="\t\t}\r"
2059        Notebook $nb text="\t\treturn size;\r"
2060        Notebook $nb text="\t}\r"
2061        Notebook $nb text="}\r"
2062        Notebook $nb text="if ( ! Shell.Application.TakeAction ) {\r"
2063        Notebook $nb text="\tShell.Application.TakeAction = function(destination,item, move ,option){\r"
2064        Notebook $nb text="\t\tif(typeof destination != 'undefined' && move){\r"
2065        Notebook $nb text="\t\t\tdestination.MoveHere(item,option);\r"
2066        Notebook $nb text="\t\t} else if(typeof destination != 'undefined') {\r"
2067        Notebook $nb text="\t\t\tdestination.CopyHere(item,option);\r"
2068        Notebook $nb text="\t\t} \r"
2069        Notebook $nb text="\t}\r"
2070        Notebook $nb text="}\r"
2071        Notebook $nb text="\r"
2072        Notebook $nb text="//ProcessItem and  ProcessSubItems can be used both for zipping and unzipping\r"
2073        Notebook $nb text="// When an item is zipped another process is ran and the control is released\r"
2074        Notebook $nb text="// but when the script stops also the copying to the zipped file stops.\r"
2075        Notebook $nb text="// Though the zipping is transactional so a zipped files will be visible only after the zipping is done\r"
2076        Notebook $nb text="// and we can rely on items count when zip operation is performed. \r"
2077        Notebook $nb text="// Also is impossible to compress an empty folders.\r"
2078        Notebook $nb text="// So when it comes to zipping two additional checks are added - for empty folders and for count of item"
2079        Notebook $nb text="s at the \r"
2080        Notebook $nb text="// destination.\r"
2081        Notebook $nb text="\r"
2082        Notebook $nb text="if ( ! Shell.Application.ProcessItem ) {\r"
2083        Notebook $nb text="\tShell.Application.ProcessItem = function(toProcess, destination  , move ,isZipping,option){\r"
2084        Notebook $nb text="\t\tvar ShellObj=new ActiveXObject(\"Shell.Application\");\r"
2085        Notebook $nb text="\t\tdestinationObj=ShellObj.NameSpace(destination);\r"
2086        Notebook $nb text="\t\t\t\r"
2087        Notebook $nb text="\t\tif (destinationObj!= null ){\r"
2088        Notebook $nb text="\t\t\tif (isZipping && Scripting.FileSystemObject.isEmptyFolder(toProcess)) {\r"
2089        Notebook $nb text="\t\t\t\tWScript.Echo(toProcess +\" is an empty folder and will be not processed\");\r"
2090        Notebook $nb text="\t\t\t\treturn;\r"
2091        Notebook $nb text="\t\t\t}\r"
2092        Notebook $nb text="\t\t\tShell.Application.TakeAction(destinationObj,toProcess, move ,option);\r"
2093        Notebook $nb text="\t\t\tvar destinationCount=Shell.Application.ItemCounterL1(destination);\r"
2094        Notebook $nb text="\t\t\tvar final_destination=destination + \"\\\\\" + Common.getName(toProcess);\r"
2095        Notebook $nb text="\t\t\t\r"
2096        Notebook $nb text="\t\t\tif (isZipping && !Shell.Application.ExistsSubItem(final_destination)) {\r"
2097        Notebook $nb text="\t\t\t\tCommon.WaitForCount(destination\r"
2098        Notebook $nb text="\t\t\t\t\t,destinationCount+1,Shell.Application.ItemCounterL1);\r"
2099        Notebook $nb text="\t\t\t} else if (isZipping && Shell.Application.ExistsSubItem(final_destination)){\r"
2100        Notebook $nb text="\t\t\t\tWScript.Echo(final_destination + \" already exists and task cannot be completed\");\r"
2101        Notebook $nb text="\t\t\t\treturn;\r"
2102        Notebook $nb text="\t\t\t}\r"
2103        Notebook $nb text="\t\t}\t\r"
2104        Notebook $nb text="\t}\r"
2105        Notebook $nb text="}\r"
2106        Notebook $nb text="\r"
2107        Notebook $nb text="\r"
2108        Notebook $nb text="\r"
2109        Notebook $nb text="if ( ! Shell.Application.ProcessSubItems ) {\r"
2110        Notebook $nb text="\tShell.Application.ProcessSubItems = function(toProcess, destination  , move ,isZipping ,option){\r"
2111        Notebook $nb text="\t\tvar ShellObj=new ActiveXObject(\"Shell.Application\");\r"
2112        Notebook $nb text="\t\tvar destinationObj=ShellObj.NameSpace(destination);\r"
2113        Notebook $nb text="\t\tvar toItemsToProcess=new Object;\r"
2114        Notebook $nb text="\t\ttoItemsToProcess=ShellObj.NameSpace(toProcess).Items();\r"
2115        Notebook $nb text="\t\t\t\r"
2116        Notebook $nb text="\t\tif (destinationObj!= null ){\r"
2117        Notebook $nb text="\t\t\t\t\t\t\r"
2118        Notebook $nb text="\t\t\tfor (var i=0;i<toItemsToProcess.Count;i++) {\r"
2119        Notebook $nb text="\t\t\t\t\r"
2120        Notebook $nb text="\t\t\t\tif (isZipping && Scripting.FileSystemObject.isEmptyFolder(toItemsToProcess.Item(i).Path)){\r"
2121        Notebook $nb text="\r"
2122        Notebook $nb text="\t\t\t\t\tWScript.Echo(\"\");\r"
2123        Notebook $nb text="\t\t\t\t\tWScript.Echo(toItemsToProcess.Item(i).Path + \" is empty and will be not processed\");\r"
2124        Notebook $nb text="\t\t\t\t\tWScript.Echo(\"\");\r"
2125        Notebook $nb text="\r"
2126        Notebook $nb text="\t\t\t\t} else {\r"
2127        Notebook $nb text="\t\t\t\t\tShell.Application.TakeAction(destinationObj,toItemsToProcess.Item(i),move,option);\r"
2128        Notebook $nb text="\t\t\t\t\tvar destinationCount=Shell.Application.ItemCounterL1(destination);\r"
2129        Notebook $nb text="\t\t\t\t\tif (isZipping) {\r"
2130        Notebook $nb text="\t\t\t\t\t\tCommon.WaitForCount(destination,destinationCount+1,Shell.Application.ItemCounterL1);\r"
2131        Notebook $nb text="\t\t\t\t\t}\r"
2132        Notebook $nb text="\t\t\t\t}\r"
2133        Notebook $nb text="\t\t\t}\t\r"
2134        Notebook $nb text="\t\t}\t\r"
2135        Notebook $nb text="\t}\r"
2136        Notebook $nb text="}\r"
2137        Notebook $nb text="\r"
2138        Notebook $nb text="if ( ! Shell.Application.ListItems ) {\r"
2139        Notebook $nb text="\tShell.Application.ListItems = function(parrentObject){\r"
2140        Notebook $nb text="\t\tvar ShellObj=new ActiveXObject(\"Shell.Application\");\r"
2141        Notebook $nb text="\t\tvar targetObject = new Object;\r"
2142        Notebook $nb text="\t\tvar targetObject=ShellObj.NameSpace(parrentObject);\r"
2143        Notebook $nb text="\r"
2144        Notebook $nb text="\t\tif (! Shell.Application.ExistsFolder (parrentObject)){\r"
2145        Notebook $nb text="\t\t\tWScript.Echo(parrentObject + \"does not exists or the file is incorrect type.Be sure the full path the"
2146        Notebook $nb text=" path is used\");\r"
2147        Notebook $nb text="\t\t\treturn;\r"
2148        Notebook $nb text="\t\t}\r"
2149        Notebook $nb text="\t\tif (typeof initialSCount == 'undefined') {\r"
2150        Notebook $nb text="\t\t\tinitialSCount=(parrentObject.split(\"\\\\\").length-1);\r"
2151        Notebook $nb text="\t\t\tWScript.Echo(parrentObject);\r"
2152        Notebook $nb text="\t\t}\r"
2153        Notebook $nb text="\t\t\r"
2154        Notebook $nb text="\t\tvar spaces=function(path){\r"
2155        Notebook $nb text="\t\t\tvar SCount=(path.split(\"\\\\\").length-1)-initialSCount;\r"
2156        Notebook $nb text="\t\t\tvar s=\"\";\r"
2157        Notebook $nb text="\t\t\tfor (var i=0;i<=SCount;i++) {\r"
2158        Notebook $nb text="\t\t\t\ts=\" \"+s;\r"
2159        Notebook $nb text="\t\t\t}\r"
2160        Notebook $nb text="\t\t\treturn s;\r"
2161        Notebook $nb text="\t\t}\r"
2162        Notebook $nb text="\t\t\r"
2163        Notebook $nb text="\t\tvar printP = function (item,end){\r"
2164        Notebook $nb text="\t\t\tif (flat) {\r"
2165        Notebook $nb text="\t\t\t\tWScript.Echo(targetObject.Items().Item(i).Path+end);\r"
2166        Notebook $nb text="\t\t\t}else{\r"
2167        Notebook $nb text="\t\t\t\tWScript.Echo( spaces(targetObject.Items().Item(i).Path)+targetObject.Items().Item(i).Name+end);\r"
2168        Notebook $nb text="\t\t\t}\r"
2169        Notebook $nb text="\t\t}\r"
2170        Notebook $nb text="\r"
2171        Notebook $nb text="\t\tif (targetObject != null ){\r"
2172        Notebook $nb text="\t\t\tvar folderPath=\"\";\r"
2173        Notebook $nb text="\r"
2174        Notebook $nb text="\t\t\t\tfor (var i=0; i<targetObject.Items().Count;i++) {\r"
2175        Notebook $nb text="\t\t\t\t\tif(targetObject.Items().Item(i).IsFolder && targetObject.Items().Item(i).Count==0 ){\r"
2176        Notebook $nb text="\t\t\t\t\t\tprintP(targetObject.Items().Item(i),\"\\\\\");\r"
2177        Notebook $nb text="\t\t\t\t\t} else if (targetObject.Items().Item(i).IsFolder){\r"
2178        Notebook $nb text="\t\t\t\t\t\tfolderPath=parrentObject+\"\\\\\"+targetObject.Items().Item(i).Name;\r"
2179        Notebook $nb text="\t\t\t\t\t\tprintP(targetObject.Items().Item(i),\"\\\\\")\r"
2180        Notebook $nb text="\t\t\t\t\t\tShell.Application.ListItems(folderPath);\t\t\t\t\t\t\r"
2181        Notebook $nb text="\r"
2182        Notebook $nb text="\t\t\t\t\t} else {\r"
2183        Notebook $nb text="\t\t\t\t\t\tprintP(targetObject.Items().Item(i),\"\")\r"
2184        Notebook $nb text="\t\t\t\t\t\t\r"
2185        Notebook $nb text="\t\t\t\t\t}\r"
2186        Notebook $nb text="\t\t\t\t}\r"
2187        Notebook $nb text="\r"
2188        Notebook $nb text="\t\t\t}\r"
2189        Notebook $nb text="\t}\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="\r"
2196        Notebook $nb text="//////////////////////////////////////\r"
2197        Notebook $nb text="//     ZIP Utils\r"
2198        Notebook $nb text="\r"
2199        Notebook $nb text="if ( ! this.ZIPUtils ) {\r"
2200        Notebook $nb text="\tvar ZIPUtils = {};\r"
2201        Notebook $nb text="}\r"
2202        Notebook $nb text="\r"
2203        Notebook $nb text="\r"
2204        Notebook $nb text="if ( ! this.ZIPUtils.ZipItem) {\t\r"
2205        Notebook $nb text="\tZIPUtils.ZipItem = function(source, destination ) {\r"
2206        Notebook $nb text="\t\tif (!Scripting.FileSystemObject.ExistsFolder(source)) {\r"
2207        Notebook $nb text="\t\t\tWScript.Echo(\"\");\r"
2208        Notebook $nb text="\t\t\tWScript.Echo(\"file \" + source +\" does not exist\");\r"
2209        Notebook $nb text="\t\t\tWScript.Quit(2);\t\r"
2210        Notebook $nb text="\t\t}\r"
2211        Notebook $nb text="\t\t\r"
2212        Notebook $nb text="\t\tif (Scripting.FileSystemObject.ExistsFile(destination) && force ) {\r"
2213        Notebook $nb text="\t\t\tScripting.FileSystemObject.DeleteItem(destination);\r"
2214        Notebook $nb text="\t\t\tADODB.Stream.writeFile(destination,ZIP_DATA);\r"
2215        Notebook $nb text="\t\t} else if (!Scripting.FileSystemObject.ExistsFile(destination)) {\r"
2216        Notebook $nb text="\t\t\tADODB.Stream.writeFile(destination,ZIP_DATA);\r"
2217        Notebook $nb text="\t\t} else {\r"
2218        Notebook $nb text="\t\t\tWScript.Echo(\"Destination \"+destination+\" already exists.Operation will be aborted\");\r"
2219        Notebook $nb text="\t\t\tWScript.Quit(15);\r"
2220        Notebook $nb text="\t\t}\r"
2221        Notebook $nb text="\t\tsource=Scripting.FileSystemObject.getFullPath(source);\r"
2222        Notebook $nb text="\t\tdestination=Scripting.FileSystemObject.getFullPath(destination);\r"
2223        Notebook $nb text="\t\t\r"
2224        Notebook $nb text="\t\tShell.Application.ProcessItem(source,destination,move,true ,NO_PROGRESS_BAR);\r"
2225        Notebook $nb text="\r"
2226        Notebook $nb text="\t}\r"
2227        Notebook $nb text="}\r"
2228        Notebook $nb text="\r"
2229        Notebook $nb text="\r"
2230        Notebook $nb text="if ( ! this.ZIPUtils.ZipDirItems) {\t\r"
2231        Notebook $nb text="\tZIPUtils.ZipDirItems = function(source, destination ) {\r"
2232        Notebook $nb text="\t\tif (!Scripting.FileSystemObject.ExistsFolder(source)) {\r"
2233        Notebook $nb text="\t\t\tWScript.Echo();\r"
2234        Notebook $nb text="\t\t\tWScript.Echo(\"file \" + source +\" does not exist\");\r"
2235        Notebook $nb text="\t\t\tWScript.Quit(2);\t\r"
2236        Notebook $nb text="\t\t}\r"
2237        Notebook $nb text="\t\tif (Scripting.FileSystemObject.ExistsFile(destination) && force ) {\r"
2238        Notebook $nb text="\t\t\tScripting.FileSystemObject.DeleteItem(destination);\r"
2239        Notebook $nb text="\t\t\tADODB.Stream.writeFile(destination,ZIP_DATA);\r"
2240        Notebook $nb text="\t\t} else if (!Scripting.FileSystemObject.ExistsFile(destination)) {\r"
2241        Notebook $nb text="\t\t\tADODB.Stream.writeFile(destination,ZIP_DATA);\r"
2242        Notebook $nb text="\t\t} else {\r"
2243        Notebook $nb text="\t\t\tWScript.Echo(\"Destination \"+destination+\" already exists.Operation will be aborted\");\r"
2244        Notebook $nb text="\t\t\tWScript.Quit(15);\r"
2245        Notebook $nb text="\t\t}\r"
2246        Notebook $nb text="\t\t\r"
2247        Notebook $nb text="\t\tsource=Scripting.FileSystemObject.getFullPath(source);\r"
2248        Notebook $nb text="\t\tdestination=Scripting.FileSystemObject.getFullPath(destination);\r"
2249        Notebook $nb text="\t\t\r"
2250        Notebook $nb text="\t\tShell.Application.ProcessSubItems(source, destination, move ,true,NO_PROGRESS_BAR);\r"
2251        Notebook $nb text="\t\t\r"
2252        Notebook $nb text="\t\tif (move){\r"
2253        Notebook $nb text="\t\t\tScripting.FileSystemObject.DeleteItem(source);\r"
2254        Notebook $nb text="\t\t}\r"
2255        Notebook $nb text="\t}\r"
2256        Notebook $nb text="}\r"
2257        Notebook $nb text="\r"
2258        Notebook $nb text="if ( ! this.ZIPUtils.Unzip) {\t\r"
2259        Notebook $nb text="\tZIPUtils.Unzip = function(source, destination ) {\r"
2260        Notebook $nb text="\t\tif(!Shell.Application.ExistsFolder(source) ){\r"
2261        Notebook $nb text="\t\t\tWScript.Echo(\"Either the target does not exist or is not a correct type\");\r"
2262        Notebook $nb text="\t\t\treturn;\r"
2263        Notebook $nb text="\t\t}\r"
2264        Notebook $nb text="\t\t\r"
2265        Notebook $nb text="\t\tif (Scripting.FileSystemObject.ExistsItem(destination) && force ) {\r"
2266        Notebook $nb text="\t\t\tScripting.FileSystemObject.DeleteItem(destination);\r"
2267        Notebook $nb text="\t\t} else if (Scripting.FileSystemObject.ExistsItem(destination)){\r"
2268        Notebook $nb text="\t\t\tWScript.Echo(\"Destination \" + destination + \" already exists\");\r"
2269        Notebook $nb text="\t\t\treturn;\r"
2270        Notebook $nb text="\t\t}\r"
2271        Notebook $nb text="\t\tScripting.FileSystemObject.CreateFolder(destination);\r"
2272        Notebook $nb text="\t\tsource=Scripting.FileSystemObject.getFullPath(source);\r"
2273        Notebook $nb text="\t\tdestination=Scripting.FileSystemObject.getFullPath(destination);\r"
2274        Notebook $nb text="\t\tShell.Application.ProcessSubItems(source, destination, move ,false,NO_PROGRESS_BAR);\t\r"
2275        Notebook $nb text="\t\t\r"
2276        Notebook $nb text="\t\tif (move){\r"
2277        Notebook $nb text="\t\t\tScripting.FileSystemObject.DeleteItem(source);\r"
2278        Notebook $nb text="\t\t}\r"
2279        Notebook $nb text="    }\t\t\r"
2280        Notebook $nb text="}\r"
2281        Notebook $nb text="\r"
2282        Notebook $nb text="if ( ! this.ZIPUtils.AddToZip) {\r"
2283        Notebook $nb text="\tZIPUtils.AddToZip = function(source, destination ) {\r"
2284        Notebook $nb text="\t\tif(!Shell.Application.ExistsFolder(destination)) {\r"
2285        Notebook $nb text="\t\t\tWScript.Echo(destination +\" is not valid path to/within zip.Be sure you are not using relative paths\""
2286        Notebook $nb text=");\r"
2287        Notebook $nb text="\t\t\tWscript.Exit(\"101\");\r"
2288        Notebook $nb text="\t\t}\r"
2289        Notebook $nb text="\t\tif(!Scripting.FileSystemObject.ExistsItem(source)){\r"
2290        Notebook $nb text="\t\t\tWScript.Echo(source +\" does not exist\");\r"
2291        Notebook $nb text="\t\t\tWscript.Exit(\"102\");\r"
2292        Notebook $nb text="\t\t}\r"
2293        Notebook $nb text="\t\tsource=Scripting.FileSystemObject.getFullPath(source);\r"
2294        Notebook $nb text="\t\tShell.Application.ProcessItem(source,destination,move,true ,NO_PROGRESS_BAR); \r"
2295        Notebook $nb text="\t}\r"
2296        Notebook $nb text="}\r"
2297        Notebook $nb text="\r"
2298        Notebook $nb text="if ( ! this.ZIPUtils.UnzipItem) {\t\r"
2299        Notebook $nb text="\tZIPUtils.UnzipItem = function(source, destination ) {\r"
2300        Notebook $nb text="\r"
2301        Notebook $nb text="\t\tif(!Shell.Application.ExistsSubItem(source)){\r"
2302        Notebook $nb text="\t\t\tWScript.Echo(source + \":Either the target does not exist or is not a correct type\");\r"
2303        Notebook $nb text="\t\t\treturn;\r"
2304        Notebook $nb text="\t\t}\r"
2305        Notebook $nb text="\t\t\r"
2306        Notebook $nb text="\t\tif (Scripting.FileSystemObject.ExistsItem(destination) && force ) {\r"
2307        Notebook $nb text="\t\t\tScripting.FileSystemObject.DeleteItem(destination);\r"
2308        Notebook $nb text="\t\t} else if (Scripting.FileSystemObject.ExistsItem(destination)){\r"
2309        Notebook $nb text="\t\t\tWScript.Echo(destination+\" - Destination already exists\");\r"
2310        Notebook $nb text="\t\t\treturn;\r"
2311        Notebook $nb text="\t\t} \r"
2312        Notebook $nb text="\t\t\r"
2313        Notebook $nb text="\t\tScripting.FileSystemObject.CreateFolder(destination);\r"
2314        Notebook $nb text="\t\tdestination=Scripting.FileSystemObject.getFullPath(destination);\r"
2315        Notebook $nb text="\t\tShell.Application.ProcessItem(source, destination, move ,false,NO_PROGRESS_BAR);\r"
2316        Notebook $nb text="\t\t                            \r"
2317        Notebook $nb text="    }\t\t\r"
2318        Notebook $nb text="}\r"
2319        Notebook $nb text="if ( ! this.ZIPUtils.getSize) {\t\r"
2320        Notebook $nb text="\tZIPUtils.getSize = function(path) {\r"
2321        Notebook $nb text="\t\t// first getting a full path to the file is attempted\r"
2322        Notebook $nb text="\t\t// as it's required by shell.application\r"
2323        Notebook $nb text="\t\t// otherwise is assumed that a file within a zip \r"
2324        Notebook $nb text="\t\t// is aimed\r"
2325        Notebook $nb text="\t\t\r"
2326        Notebook $nb text="\t\t//TODO - find full path even if the path points to internal for the \r"
2327        Notebook $nb text="\t\t// zip directory\r"
2328        Notebook $nb text="\t\t\r"
2329        Notebook $nb text="\t\tif (Scripting.FileSystemObject.ExistsFile(path)){\r"
2330        Notebook $nb text="\t\t\tpath=Scripting.FileSystemObject.getFullPath(path);\r"
2331        Notebook $nb text="\t\t}\r"
2332        Notebook $nb text="\t\tWScript.Echo(Shell.Application.getSize(path));\r"
2333        Notebook $nb text="\t}\r"
2334        Notebook $nb text="}\r"
2335        Notebook $nb text="\r"
2336        Notebook $nb text="if ( ! this.ZIPUtils.list) {\t\r"
2337        Notebook $nb text="\tZIPUtils.list = function(path) {\r"
2338        Notebook $nb text="\t\t// first getting a full path to the file is attempted\r"
2339        Notebook $nb text="\t\t// as it's required by shell.application\r"
2340        Notebook $nb text="\t\t// otherwise is assumed that a file within a zip \r"
2341        Notebook $nb text="\t\t// is aimed\r"
2342        Notebook $nb text="\t\t\r"
2343        Notebook $nb text="\t\t//TODO - find full path even if the path points to internal for the \r"
2344        Notebook $nb text="\t\t// zip directory\r"
2345        Notebook $nb text="\t\t\r"
2346        Notebook $nb text="\t\t// TODO - optional printing of each file uncompressed size\r"
2347        Notebook $nb text="\t\t\r"
2348        Notebook $nb text="\t\tif (Scripting.FileSystemObject.ExistsFile(path)){\r"
2349        Notebook $nb text="\t\t\tpath=Scripting.FileSystemObject.getFullPath(path);\r"
2350        Notebook $nb text="\t\t}\r"
2351        Notebook $nb text="\t\tShell.Application.ListItems(path);\r"
2352        Notebook $nb text="\t}\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="\r"
2358        Notebook $nb text="/////////////////////////////////////\r"
2359        Notebook $nb text="//   parsing'n'running\r"
2360        Notebook $nb text="function printHelp(){\r"
2361        Notebook $nb text="\r"
2362        Notebook $nb text="\tWScript.Echo( scriptName + \" list -source zipFile [-flat yes|no]\");\r"
2363        Notebook $nb text="\tWScript.Echo( \"\t\tlist the content of a zip file\");\r"
2364        Notebook $nb text="\tWScript.Echo( \"\tzipFile - absolute path to the zip file\");\r"
2365        Notebook $nb text="\tWScript.Echo( \"\t\t\tcould be also a directory or a directory inside a zip file or\");\r"
2366        Notebook $nb text="\tWScript.Echo( \"\t\t\tor a .cab file or an .iso file\");\r"
2367        Notebook $nb text="\tWScript.Echo( \"\t-flat - indicates if the structure of the zip will be printed as tree\");\r"
2368        Notebook $nb text="\tWScript.Echo( \"\t\t\tor with absolute paths (-flat yes).Default is yes.\");\r"
2369        Notebook $nb text="\tWScript.Echo( \"Example:\");\r"
2370        Notebook $nb text="\tWScript.Echo( \"\t\" + scriptName + \" list -source C:\\\\myZip.zip -flat no\" );\r"
2371        Notebook $nb text="\tWScript.Echo( \"\t\" + scriptName + \" list -source C:\\\\myZip.zip\\\\inZipDir -flat yes\" );\r"
2372        Notebook $nb text="\t\r"
2373        Notebook $nb text="\tWScript.Echo( scriptName + \" getSize -source zipFile\");\r"
2374        Notebook $nb text="\tWScript.Echo( \"\t\tprints uncompressed size of the zipped file in bytes\");\r"
2375        Notebook $nb text="\tWScript.Echo( \"\tzipFile - absolute path to the zip file\");\r"
2376        Notebook $nb text="\tWScript.Echo( \"\t\t\tcould be also a directory or a directory inside a zip file or\");\r"
2377        Notebook $nb text="\tWScript.Echo( \"\t\t\tor a .cab file or an .iso file\");\r"
2378        Notebook $nb text="\tWScript.Echo( \"Example:\");\r"
2379        Notebook $nb text="\tWScript.Echo( \"\t\" + scriptName + \" getSize -source C:\\\\myZip.zip\" );\r"
2380        Notebook $nb text="\t\r"
2381        Notebook $nb text="\tWScript.Echo( scriptName + \" zipDirItems -source source_dir -destination destination.zip [-force yes|no"
2382        Notebook $nb text="] [-keep yes|no]\");\r"
2383        Notebook $nb text="\tWScript.Echo( \"\t\tzips the content of given folder without the folder itself \");\r"
2384        Notebook $nb text="\tWScript.Echo( \"\tsource_dir - path to directory which content will be compressed\");\r"
2385        Notebook $nb text="\tWScript.Echo( \"\t\tEmpty folders in the source directory will be ignored\");\r"
2386        Notebook $nb text="\tWScript.Echo( \"\tdestination.zip - path/name  of the zip file that will be created\");\r"
2387        Notebook $nb text="\tWScript.Echo( \"\t-force - indicates if the destination will be overwritten if already exists.\");\r"
2388        Notebook $nb text="\tWScript.Echo( \"\t\tdefault is yes\");\r"
2389        Notebook $nb text="\tWScript.Echo( \"\t-keep - indicates if the source content will be moved or just copied/kept.\");\r"
2390        Notebook $nb text="\tWScript.Echo( \"\t\tdefault is yes\");\r"
2391        Notebook $nb text="\tWScript.Echo( \"Example:\");\r"
2392        Notebook $nb text="\tWScript.Echo( \"\t\" + scriptName + \" zipDirItems -source C:\\\\myDir\\\\ -destination C:\\\\MyZip.zip -keep yes"
2393        Notebook $nb text=" -force no\" );\r"
2394        Notebook $nb text="\t\r"
2395        Notebook $nb text="\tWScript.Echo( scriptName + \" zipItem -source item -destination destination.zip [-force yes|no] [-keep y"
2396        Notebook $nb text="es|no]\");\r"
2397        Notebook $nb text="\tWScript.Echo( \"\t\tzips file or directory to a destination.zip file \");\r"
2398        Notebook $nb text="\tWScript.Echo( \"\titem - path to file or directory which content will be compressed\");\r"
2399        Notebook $nb text="\tWScript.Echo( \"\t\tIf points to an empty folder it will be ignored\");\r"
2400        Notebook $nb text="\tWScript.Echo( \"\t\tIf points to a folder it also will be included in the zip file alike zipdiritems comma"
2401        Notebook $nb text="nd\");\r"
2402        Notebook $nb text="\tWScript.Echo( \"\t\tEventually zipping a folder in this way will be faster as it does not process every el"
2403        Notebook $nb text="ement one by one\");\r"
2404        Notebook $nb text="\tWScript.Echo( \"\tdestination.zip - path/name  of the zip file that will be created\");\r"
2405        Notebook $nb text="\tWScript.Echo( \"\t-force - indicates if the destination will be overwritten if already exists.\");\r"
2406        Notebook $nb text="\tWScript.Echo( \"\t\tdefault is yes\");\r"
2407        Notebook $nb text="\tWScript.Echo( \"\t-keep - indicates if the source content will be moved or just copied/kept.\");\r"
2408        Notebook $nb text="\tWScript.Echo( \"\t\tdefault is yes\");\r"
2409        Notebook $nb text="\tWScript.Echo( \"Example:\");\r"
2410        Notebook $nb text="\tWScript.Echo( \"\t\" + scriptName + \" zipItem -source C:\\\\myDir\\\\myFile.txt -destination C:\\\\MyZip.zip -ke"
2411        Notebook $nb text="ep yes -force no\" );\r"
2412        Notebook $nb text="\t\r"
2413        Notebook $nb text="\tWScript.Echo( scriptName + \" unzip -source source.zip -destination destination_dir [-force yes|no] [-ke"
2414        Notebook $nb text="ep yes|no]\");\r"
2415        Notebook $nb text="\tWScript.Echo( \"\t\tunzips the content of a zip file to a given directory \");\r"
2416        Notebook $nb text="\tWScript.Echo( \"\tsource - path to the zip file that will be expanded\");\r"
2417        Notebook $nb text="\tWScript.Echo( \"\t\tEventually .iso , .cab or even an ordinary directory can be used as a source\");\r"
2418        Notebook $nb text="\tWScript.Echo( \"\tdestination_dir - path to directory where unzipped items will be stored\");\r"
2419        Notebook $nb text="\tWScript.Echo( \"\t-force - indicates if the destination will be overwritten if already exists.\");\r"
2420        Notebook $nb text="\tWScript.Echo( \"\t\tdefault is yes\");\r"
2421        Notebook $nb text="\tWScript.Echo( \"\t-keep - indicates if the source content will be moved or just copied/kept.\");\r"
2422        Notebook $nb text="\tWScript.Echo( \"\t\tdefault is yes\");\r"
2423        Notebook $nb text="\tWScript.Echo( \"Example:\");\r"
2424        Notebook $nb text="\tWScript.Echo( \"\t\" + scriptName + \" unzip -source C:\\\\myDir\\\\myZip.zip -destination C:\\\\MyDir -keep no -"
2425        Notebook $nb text="force no\" );\r"
2426        Notebook $nb text="\t\r"
2427        Notebook $nb text="\tWScript.Echo( scriptName + \" unZipItem -source source.zip -destination destination_dir [-force yes|no] "
2428        Notebook $nb text="[-keep yes|no]\");\r"
2429        Notebook $nb text="\tWScript.Echo( \"\t\tunzips  a single within a given zip file to a destination directory\");\r"
2430        Notebook $nb text="\tWScript.Echo( \"\tsource - path to the file/folcer within a zip  that will be expanded\");\r"
2431        Notebook $nb text="\tWScript.Echo( \"\t\tEventually .iso , .cab or even an ordinary directory can be used as a source\");\r"
2432        Notebook $nb text="\tWScript.Echo( \"\tdestination_dir - path to directory where unzipped item will be stored\");\r"
2433        Notebook $nb text="\tWScript.Echo( \"\t-force - indicates if the destination directory will be overwritten if already exists.\""
2434        Notebook $nb text=");\r"
2435        Notebook $nb text="\tWScript.Echo( \"\t\tdefault is yes\");\r"
2436        Notebook $nb text="\tWScript.Echo( \"\t-keep - indicates if the source content will be moved or just copied/kept.\");\r"
2437        Notebook $nb text="\tWScript.Echo( \"\t\tdefault is yes\");\r"
2438        Notebook $nb text="\tWScript.Echo( \"Example:\");\r"
2439        Notebook $nb text="\tWScript.Echo( \"\t\" + scriptName + \" unZipItem -source C:\\\\myDir\\\\myZip.zip\\\\InzipDir\\\\InzipFile -destina"
2440        Notebook $nb text="tion C:\\\\OtherDir -keep no -force yes\" );\r"
2441        Notebook $nb text="\tWScript.Echo( \"\t\" + scriptName + \" unZipItem -source C:\\\\myDir\\\\myZip.zip\\\\InzipDir -destination C:\\\\Ot"
2442        Notebook $nb text="herDir \" );\r"
2443        Notebook $nb text="\t\r"
2444        Notebook $nb text="\tWScript.Echo( scriptName + \" addToZip -source sourceItem -destination destination.zip  [-keep yes|no]\")"
2445        Notebook $nb text=";\r"
2446        Notebook $nb text="\tWScript.Echo( \"\t\tadds file or folder to already exist zip file\");\r"
2447        Notebook $nb text="\tWScript.Echo( \"\tsource - path to the item that will be processed\");\r"
2448        Notebook $nb text="\tWScript.Echo( \"\tdestination_zip - path to the zip where the item will be added\");\r"
2449        Notebook $nb text="\tWScript.Echo( \"\t-keep - indicates if the source content will be moved or just copied/kept.\");\r"
2450        Notebook $nb text="\tWScript.Echo( \"\t\tdefault is yes\");\r"
2451        Notebook $nb text="\tWScript.Echo( \"Example:\");\r"
2452        Notebook $nb text="\tWScript.Echo( \"\t\" + scriptName + \" addToZip -source C:\\\\some_file -destination C:\\\\myDir\\\\myZip.zip\\\\In"
2453        Notebook $nb text="zipDir -keep no \" );\r"
2454        Notebook $nb text="\tWScript.Echo( \"\t\" + scriptName + \" addToZip -source  C:\\\\some_file -destination C:\\\\myDir\\\\myZip.zip \" "
2455        Notebook $nb text=");\r"
2456        Notebook $nb text="\t\r"
2457        Notebook $nb text="\tWScript.Echo( \"\tby Vasil \\\"npocmaka\\\" Arnaudov - npocmaka@gmail.com\" );\r"
2458        Notebook $nb text="\tWScript.Echo( \"\tver 0.1 \" );\r"
2459        Notebook $nb text="\tWScript.Echo( \"\tlatest version could be found here https://github.com/npocmaka/batch.scripts/blob/maste"
2460        Notebook $nb text="r/hybrids/jscript/zipjs.bat\" );\r"
2461        Notebook $nb text="\t\r"
2462        Notebook $nb text="\t\r"
2463        Notebook $nb text="}\r"
2464        Notebook $nb text="\r"
2465        Notebook $nb text="function parseArguments(){\r"
2466        Notebook $nb text="\tif (WScript.Arguments.Length==1 || WScript.Arguments.Length==2 || ARGS.Item(1).toLowerCase() == \"-help\""
2467        Notebook $nb text=" ||  ARGS.Item(1).toLowerCase() == \"-h\" ) {\r"
2468        Notebook $nb text="\t\tprintHelp();\r"
2469        Notebook $nb text="\t\tWScript.Quit(0);\r"
2470        Notebook $nb text="   }\r"
2471        Notebook $nb text="   \r"
2472        Notebook $nb text="   //all arguments are key-value pairs plus one for script name and action taken - need to be even numbe"
2473        Notebook $nb text="r\r"
2474        Notebook $nb text="\tif (WScript.Arguments.Length % 2 == 1 ) {\r"
2475        Notebook $nb text="\t\tWScript.Echo(\"Illegal arguments \");\r"
2476        Notebook $nb text="\t\tprintHelp();\r"
2477        Notebook $nb text="\t\tWScript.Quit(1);\r"
2478        Notebook $nb text="\t}\r"
2479        Notebook $nb text="\t\r"
2480        Notebook $nb text="\t//ARGS\r"
2481        Notebook $nb text="\tfor(var arg = 2 ; arg<ARGS.Length-1;arg=arg+2) {\r"
2482        Notebook $nb text="\t\tif (ARGS.Item(arg) == \"-source\") {\r"
2483        Notebook $nb text="\t\t\tsource = ARGS.Item(arg +1);\r"
2484        Notebook $nb text="\t\t}\r"
2485        Notebook $nb text="\t\tif (ARGS.Item(arg) == \"-destination\") {\r"
2486        Notebook $nb text="\t\t\tdestination = ARGS.Item(arg +1);\r"
2487        Notebook $nb text="\t\t}\r"
2488        Notebook $nb text="\t\tif (ARGS.Item(arg).toLowerCase() == \"-keep\" && ARGS.Item(arg +1).toLowerCase() == \"no\") {\r"
2489        Notebook $nb text="\t\t\tmove=true;\r"
2490        Notebook $nb text="\t\t}\r"
2491        Notebook $nb text="\t\tif (ARGS.Item(arg).toLowerCase() == \"-force\" && ARGS.Item(arg +1).toLowerCase() == \"no\") {\r"
2492        Notebook $nb text="\t\t\tforce=false;\r"
2493        Notebook $nb text="\t\t}\r"
2494        Notebook $nb text="\t\tif (ARGS.Item(arg).toLowerCase() == \"-flat\" && ARGS.Item(arg +1).toLowerCase() == \"yes\") {\r"
2495        Notebook $nb text="\t\t\tflat=true;\r"
2496        Notebook $nb text="\t\t}\r"
2497        Notebook $nb text="\t}\r"
2498        Notebook $nb text="\t\r"
2499        Notebook $nb text="\tif (source == \"\"){\r"
2500        Notebook $nb text="\t\tWScript.Echo(\"Source not given\");\r"
2501        Notebook $nb text="\t\tprintHelp();\r"
2502        Notebook $nb text="\t\tWScript.Quit(59);\r"
2503        Notebook $nb text="\t}\r"
2504        Notebook $nb text="\r"
2505        Notebook $nb text="}\r"
2506        Notebook $nb text="\r"
2507        Notebook $nb text="var checkDestination=function(){\r"
2508        Notebook $nb text="\tif (destination == \"\"){\r"
2509        Notebook $nb text="\t\tWScript.Echo(\"Destination not given\");\r"
2510        Notebook $nb text="\t\tprintHelp();\r"
2511        Notebook $nb text="\t\tWScript.Quit(65);\r"
2512        Notebook $nb text="\t}\r"
2513        Notebook $nb text="}\r"
2514        Notebook $nb text="\r"
2515        Notebook $nb text="var main=function(){\r"
2516        Notebook $nb text="\tparseArguments();\r"
2517        Notebook $nb text="\tswitch (ARGS.Item(1).toLowerCase()) {\r"
2518        Notebook $nb text="\tcase \"list\":\r"
2519        Notebook $nb text="\t\tZIPUtils.list(source);\r"
2520        Notebook $nb text="\t\tbreak;\r"
2521        Notebook $nb text="\tcase \"getsize\":\r"
2522        Notebook $nb text="\t\tZIPUtils.getSize(source);\r"
2523        Notebook $nb text="\t\tbreak;\r"
2524        Notebook $nb text="\tcase \"zipdiritems\":\r"
2525        Notebook $nb text="\t\tcheckDestination();\r"
2526        Notebook $nb text="\t\tZIPUtils.ZipDirItems(source,destination);\r"
2527        Notebook $nb text="\t\tbreak;\r"
2528        Notebook $nb text="\tcase \"zipitem\":\r"
2529        Notebook $nb text="\t\tcheckDestination();\r"
2530        Notebook $nb text="\t\tZIPUtils.ZipDirItems(source,destination);\r"
2531        Notebook $nb text="\t\tbreak;\r"
2532        Notebook $nb text="\tcase \"unzip\":\r"
2533        Notebook $nb text="\t\tcheckDestination();\r"
2534        Notebook $nb text="\t\tZIPUtils.Unzip(source,destination);\r"
2535        Notebook $nb text="\t\tbreak;\r"
2536        Notebook $nb text="\tcase \"unzipitem\":\r"
2537        Notebook $nb text="\t\tcheckDestination();\r"
2538        Notebook $nb text="\t\tZIPUtils.UnzipItem(source,destination);\r"
2539        Notebook $nb text="\t\tbreak;\r"
2540        Notebook $nb text="\tcase \"addtozip\":\r"
2541        Notebook $nb text="\t\tcheckDestination();\r"
2542        Notebook $nb text="\t\tZIPUtils.AddToZip(source,destination);\r"
2543        Notebook $nb text="\t\tbreak;\r"
2544        Notebook $nb text="\tdefault:\r"
2545        Notebook $nb text="\t\tWScript.Echo(\"No valid switch has been passed\");\r"
2546        Notebook $nb text="\t\tprintHelp();\r"
2547        Notebook $nb text="\t\t\r"
2548        Notebook $nb text="\t}\r"
2549        Notebook $nb text="\t\r"
2550        Notebook $nb text="}\r"
2551        Notebook $nb text="main();\r"
2552        Notebook $nb text="//\r"
2553        Notebook $nb text="//////////////////////////////////////"
2554end
2555
2556// ===================================== End of Un-Zipping ===================================== //
2557// ============================================================================================= //
2558
2559
2560//**************************************************************************************************************************************
2561//**************************************************************************************************************************************
2562Function GHW_MakeRecordOfProgress(MessageToRecord, [header, abortProgress])
2563        string MessageToRecord
2564        variable header, abortProgress
2565       
2566        if(ParamIsDefault(header))
2567                header=0
2568        endif
2569        if(ParamIsDefault(abortProgress))
2570                abortProgress=0
2571        endif
2572        print MessageToRecord
2573        variable FileNum
2574        string LogFileName="InstallRecord.log"
2575        PathInfo InstallerRecordPath
2576        if(V_Flag==0)
2577                NewPath /O/Q InstallerRecordPath  , SpecialDirPath("Desktop", 0, 0, 0 )
2578        endif
2579        GetFileFolderInfo/Q/Z/P=InstallerRecordPath  LogFileName
2580        if(V_Flag!=0)
2581                Open  /P=InstallerRecordPath /T=".txt"  FileNum  as LogFileName
2582                Close FIleNum   
2583        endif
2584        Open /P=InstallerRecordPath  FileNum  as LogFileName
2585        if (strlen(S_fileName)<1)
2586                return 1
2587        endif
2588        FStatus FileNum
2589        FSetPos FileNum, V_logEOF
2590        if (V_logEOF<2 || header)                       
2591                String str, head=SelectString(V_logEOF>2,"","\r\r\r\r")
2592                head += "********************************************************************************\r"
2593                head += "********************************************************************************\r"
2594                sprintf str,"       Starting Installation using  %s\r", IgorInfo(1)
2595                head += str
2596                sprintf str,"       on %s, %s\r", Secs2Date(DateTime,1), Secs2Time(DateTime,1)
2597                head += str
2598                sprintf str,"       Logging everything in history window to:\r\t\t\"%s\"\r\r\r",LogFileName
2599                head += str
2600                fprintf FileNum,head
2601                print head
2602        endif
2603        fprintf FileNum, MessageToRecord+"\r"
2604        Close FileNum
2605        if(abortProgress)       
2606                SVAR PackageListsToDownload
2607                SVAR SelectedReleaseName
2608                SVAR ListOfPackagesToInstall
2609                GHW_SubmitRecordToWeb(ListOfPackagesToInstall, SelectedReleaseName, MessageToRecord)
2610                BrowseURL "https://github.com/jilavsky/SAXS_IgorCode/wiki/Installation-Problems"
2611                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. "
2612        endif
2613        return 0
2614End
2615//**************************************************************************************************************************************
2616//**************************************************************************************************************************************
2617
2618Function GHW_InstallPackage(PathToLocalData,PackageListxml)
2619        string PathToLocalData,PackageListxml
2620        DFREF saveDFR=GetDataFolderDFR()                // Get reference to current data folder
2621        SetDataFOlder root:Packages:GHInstaller
2622       
2623        //print PathToLocalData, PackageListxml
2624        variable fileID
2625        string FileContent="", tempStr
2626        string PackgListFiles, PackgListFilePaths, PackgListxopLinks, PackgListFileLinks
2627        PathToLocalData = RemoveEnding(PathToLocalData, ":")+":"                //make sure we have correct path ending to use
2628        //Open/R/Z fileID as PathToLocalData+PackageListxml
2629        GetFileFolderInfo/Z/Q PathToLocalData+PackageListxml
2630        if(V_flag!=0)
2631                BrowseURL "https://github.com/jilavsky/SAXS_IgorCode/wiki/Installation-Problems"
2632                GHW_MakeRecordOfProgress("Abort in : "+GetRTStackInfo(3)+" - xml configuration file was not found",abortProgress=1 )
2633        endif
2634        FileContent = PadString(FileContent, V_logEOF, 0x20 )
2635        Open fileID  as PathToLocalData+PackageListxml
2636        FBinRead fileID, FileContent
2637        close fileID
2638        FileContent=GHI_XMLremoveComments(FileContent)          //get rid of comments, confuses the rest of the code...
2639        //FileContent now contains content of the xml configuration file...
2640        string InstallerText=GHI_XMLtagContents("PackageContent",FileContent)   //if nothing, wrong format
2641        if(strlen(InstallerText)<10)    //no real content
2642                SetDataFolder saveDFR                                   // Restore current data folder
2643                BrowseURL "https://github.com/jilavsky/SAXS_IgorCode/wiki/Installation-Problems"
2644                GHW_MakeRecordOfProgress("Abort in : "+GetRTStackInfo(3)+" - Nothing found in a file "+PathToLocalData+PackageListxml,abortProgress=1 )
2645        endif
2646        //known keywords: xopLinks for xop from Wavemetrics -> link to Igor Extensions (64-bit)
2647        //FileLinks for ipf files from Wavemetrics  -> link to User Procedures
2648        //and for ipf/ihf FolderFileLocation & File - copy from source to same place in User Procedures
2649        PackgListFiles                  = GHW_ListPlatformSpecificValues(FileContent, "File", IgorInfo(2))
2650        PackgListFilePaths              = stringFromList(0,GHW_ListPlatformSpecificValues(FileContent, "FolderFileLocation", IgorInfo(2)),";") 
2651        PackgListxopLinks               = GHW_ListPlatformSpecificValues(FileContent, "xopLinks", IgorInfo(2))
2652        PackgListFileLinks      = GHW_ListPlatformSpecificValues(FileContent, "FileLinks", IgorInfo(2))
2653        //these are list of files to copy and link as necessary
2654        variable j
2655        //process file and folders
2656        For(j=0;j<ItemsInList(PackgListFiles);j+=1)
2657                GHW_CopyOneFileFromDistribution(PathToLocalData, PackgListFilePaths, StringFromList(j,PackgListFiles,";"))
2658        endfor
2659        //process links.
2660        For(j=0;j<ItemsInList(PackgListxopLinks);j+=1)
2661                GHW_CreateLinks( StringFromList(j,PackgListxopLinks,";"))
2662        endfor
2663        For(j=0;j<ItemsInList(PackgListFileLinks);j+=1)
2664                GHW_CreateLinks(StringFromList(j,PackgListFileLinks,";"))
2665        endfor
2666       
2667       
2668end
2669//**************************************************************************************************************************************
2670//**************************************************************************************************************************************
2671
2672
2673Function GHW_CreateLinks(FileToLink)
2674        string  FileToLink
2675        //the FileToLink is either Wavemetrics xop
2676        //of Wavemetrics ipf file. Nothing else supportede at this time.
2677        FileToLink = ReplaceString("/", FileToLink, ":")
2678        string ExtOrProcPath
2679        string FileToLinkLoc
2680        if(StringMatch(FileToLink, "*.xop"))            //xop
2681                if(stringMatch(FileToLink,"* (64-bit)*"))
2682                        ExtOrProcPath = "Igor Extensions (64-bit)"
2683                else    //old 32 bits
2684                        ExtOrProcPath = "Igor Extensions"
2685                endif
2686        else
2687                ExtOrProcPath = "Igor Procedures"
2688        endif
2689        if(stringMatch(IgorInfo(2),"Macintosh"))
2690                FileToLinkLoc   =       FileToLink
2691        else            //windows, add .lnk to the name
2692                FileToLinkLoc   =       FileToLink+".lnk"
2693        endif
2694        string FileToLinkName=StringFromList(ItemsInList(FileToLinkLoc, ":")-1, FileToLinkLoc, ":")
2695        NewPath /O/Q targetFileFolderPath, SpecialDirPath("Igor Pro User Files", 0, 0, 0 )+ExtOrProcPath
2696        string IgorUserFilePathStr=SpecialDirPath("Igor Pro User Files", 0, 0, 0 )+ExtOrProcPath+":"
2697        NewPath /O/Q sourceFileFolderPath, SpecialDirPath("Igor Application", 0, 0, 0 )
2698        string SourceFileFolderPathStr = SpecialDirPath("Igor Application", 0, 0, 0 )
2699        //same process as with files, get rid of the old ones, if it can be done
2700        GetFileFolderInfo/Q/Z/P=targetFileFolderPath  FileToLinkName+".deleteMe"
2701        if(V_Flag==0)           //file/xop found, get rid of it
2702                if(V_isFile)
2703                        DeleteFile /P=targetFileFolderPath /Z FileToLinkName+".deleteMe"
2704                        if(V_flag!=0)
2705                                GHW_MakeRecordOfProgress("Could not delete "+FileToLinkName+".deleteMe")
2706                        endif
2707                elseif(V_isFolder)
2708                        DeleteFolder /P=targetFileFolderPath /Z FileToLinkName+".deleteMe"
2709                        if(V_flag!=0)
2710                                GHW_MakeRecordOfProgress("Could not delete "+FileToLinkName+".deleteMe")
2711                        endif
2712                elseif(V_isAliasShortcut)
2713                        DeleteFile /P=targetFileFolderPath /Z FileToLinkName+".deleteMe"
2714                        if(V_flag!=0)
2715                                GHW_MakeRecordOfProgress("Could not delete "+FileToLinkName+".deleteMe")
2716                        endif           
2717                endif
2718                GHW_MakeRecordOfProgress("Deleted old file : "+FileToLinkName+".deleteMe")
2719        endif
2720        //OK, now we can, if needed rename existing file AND keep the user folder cleaner
2721        //now check for existing target file and delete/rename if necessary
2722        GetFileFolderInfo/Q/Z/P=targetFileFolderPath  FileToLinkName
2723        if(V_Flag==0)           //old file/xop found, get rid of it
2724                if(V_isFile)
2725                        DeleteFile /P=targetFileFolderPath /Z FileToLinkName
2726                        if(V_flag!=0)
2727                                MoveFile /O/P=targetFileFolderPath FileToLinkName as FileToLinkName+".deleteMe"
2728                                GHW_MakeRecordOfProgress("Moved to .deleteMe existing file : "+FileToLinkName)
2729                        else
2730                                GHW_MakeRecordOfProgress("Deleted existing file : "+FileToLinkName)
2731                        endif
2732                elseif(V_isFolder)
2733                        DeleteFolder /P=targetFileFolderPath /Z FileToLinkName
2734                        if(V_flag!=0)
2735                                MoveFolder /O/P=targetFileFolderPath FileToLinkName as FileToLinkName+".deleteMe"
2736                                GHW_MakeRecordOfProgress("Moved to .deleteMe existing file : "+FileToLinkName)
2737                        else
2738                                GHW_MakeRecordOfProgress("Deleted existing file : "+FileToLinkName)
2739                        endif
2740                elseif(V_isAliasShortcut)
2741                        DeleteFile /P=targetFileFolderPath /Z FileToLinkName
2742                        if(V_flag!=0)
2743                                MoveFile /O/P=targetFileFolderPath FileToLinkName as FileToLinkName+".deleteMe"
2744                                GHW_MakeRecordOfProgress("Moved to .deleteMe existing file : "+FileToLinkName)
2745                        else
2746                                GHW_MakeRecordOfProgress("Deleted existing file : "+FileToLinkName)
2747                        endif           
2748                endif
2749                //print "Deleted/moved to .deleteMe existing file : "+FileToLinkName
2750        endif
2751        //now we should be able to make the alias
2752        //depends on platform and xop/not-xop...
2753        if(stringmatch(FileToLinkName,"*.xop*")&&stringMatch(IgorInfo(2),"Macintosh"))          //it is xop (folder) on Mac
2754                CreateAliasShortcut /D/I=0 /O /Z  (SourceFileFolderPathStr+FileToLink)   as    (IgorUserFilePathStr+FileToLinkName) 
2755                if(V_Flag==0)
2756                        GHW_MakeRecordOfProgress("Created shortcut : "+S_path+ "  linking to : "+SourceFileFolderPathStr+FileToLink)
2757                else
2758                        GHW_MakeRecordOfProgress("Could not create shortcut for "+IgorUserFilePathStr+FileToLinkName)
2759                endif
2760        else
2761                CreateAliasShortcut /I=0 /O /Z  (SourceFileFolderPathStr+FileToLink)   as    (IgorUserFilePathStr+removeEnding(FileToLinkName,".lnk")) 
2762                if(V_Flag==0)
2763                        GHW_MakeRecordOfProgress("Created shortcut : "+S_path+ "  linking to : "+SourceFileFolderPathStr+FileToLink )
2764                else
2765                        GHW_MakeRecordOfProgress("Could not create shortcut for "+IgorUserFilePathStr+FileToLinkName )
2766                endif
2767        endif
2768end
2769//**************************************************************************************************************************************
2770//**************************************************************************************************************************************
2771
2772
2773Function GHW_CopyOneFileFromDistribution(PathToLocalData, PackgListFilePaths, FileToCopy)
2774        string PathToLocalData, PackgListFilePaths, FileToCopy
2775
2776        if(strlen(FileToCopy)<2)
2777                return 0
2778        endif
2779        FileToCopy =  ReplaceString("/", FileToCopy, ":")
2780        if(!StringMatch(FileToCopy[0],":" ))            //make this in relative path for
2781                FileToCopy = ":"+FileToCopy
2782        endif
2783        //we get path to file/folder(xop) and will copy from source (PathToLocalData) to location
2784        //PackgListFilePaths is specific path where to look for the souce, not reproduced in target
2785        //FileToCopy is source and target path.
2786        //distribution is in PathToLocalData
2787        //target is in Igor User home area - Documents/Wavemetrics/Igor Pro 7 user Files
2788        //existing files needs to be deleted or if not possible, renamed into ....DeleteMe
2789        //any existing file with ....DeleteMe will be deleted first.
2790        //Path where to put the files
2791        NewPath /O/Q targetFileFolderPath, SpecialDirPath("Igor Pro User Files", 0, 0, 0 )
2792        string IgorUserFilePathStr=SpecialDirPath("Igor Pro User Files", 0, 0, 0 )
2793        NewPath /O/Q sourceFileFolderPath, PathToLocalData+PackgListFilePaths
2794        //PathInfo sourceFileFolderPath
2795        //print S_Path+FileToCopy
2796        //variable fileNum
2797        string tempStr, igorCmd
2798        GetFileFolderInfo/Q/Z/P=targetFileFolderPath  FileToCopy+".deleteMe"
2799        if(V_Flag==0)           //file/xop found, get rid of it
2800                if(V_isFile)
2801                        DeleteFile /P=targetFileFolderPath /Z FileToCopy+".deleteMe"
2802                        if(V_flag!=0)
2803                                GHW_MakeRecordOfProgress("Could not delete "+FileToCopy+".deleteMe")
2804                        endif
2805                elseif(V_isFolder)
2806                                //this does not work unless user approves DeleteFolder: DeleteFolder /P=targetFileFolderPath /Z FileToCopy+".deleteMe"
2807                                //here is nasty workaround using OS script...
2808                                PathInfo targetFileFolderPath
2809                                tempStr = replaceString("::",S_Path+FileToCopy,":")
2810                                tempStr=  RemoveFromList(StringFromList(0,tempStr  , ":"), tempStr  , ":")
2811                                tempStr = ParseFilePath(5, tempStr, "\\", 0, 0)
2812                                tempStr = ReplaceString("\\", tempStr, "/")
2813                                tempStr = "rm -Rdf  '/"+ReplaceString(".xop", tempStr, ".xop.deleteMe")+"'"
2814                                sprintf igorCmd, "do shell script \"%s\"", tempStr
2815                                //print igorCmd
2816                                ExecuteScriptText igorCmd
2817                                GetFileFolderInfo/Q/Z/P=targetFileFolderPath  FileToCopy+".deleteMe"
2818                                if(V_flag==0)
2819                                        GHW_MakeRecordOfProgress( "Could not delete folder/xop"+FileToCopy+".deleteMe")
2820                                else
2821                                        GHW_MakeRecordOfProgress( "Deleted old file : "+FileToCopy+".deleteMe")
2822                                endif
2823                elseif(V_isAliasShortcut)
2824                        DeleteFile /P=targetFileFolderPath /Z FileToCopy+".deleteMe"
2825                        if(V_flag!=0)
2826                                GHW_MakeRecordOfProgress( "Could not delete "+FileToCopy+".deleteMe")
2827                        endif           
2828                endif
2829                GHW_MakeRecordOfProgress( "Deleted old file : "+FileToCopy+".deleteMe")
2830        endif
2831        //OK, now we can, if needed rename existing file AND keep the user folder cleaner
2832        //now check for existing target file and delete/rename if necessary
2833        GetFileFolderInfo/Q/Z/P=targetFileFolderPath  FileToCopy
2834        if(V_Flag==0)           //old file/xop found, get rid of it
2835                if(V_isFile)
2836                        DeleteFile /P=targetFileFolderPath /Z FileToCopy
2837                        if(V_flag!=0)
2838                                MoveFile /O/P=targetFileFolderPath FileToCopy as FileToCopy+".deleteMe"
2839                                GHW_MakeRecordOfProgress( "Moved to .deleteMe existing file : "+FileToCopy)
2840                        else
2841                                GHW_MakeRecordOfProgress( "Deleted existing file : "+FileToCopy)               
2842                        endif
2843                elseif(V_isFolder)
2844                                GetFileFolderInfo/Q/Z/P=targetFileFolderPath  FileToCopy+".deleteMe"
2845                                if(V_flag!=0)
2846                                        MoveFolder /O/P=targetFileFolderPath FileToCopy as FileToCopy+".deleteMe"
2847                                        GHW_MakeRecordOfProgress( "Moved to .deleteMe existing file : "+FileToCopy)
2848                                else
2849                                        GHW_MakeRecordOfProgress( "Cannot delete existing file : "+FileToCopy +" the old .deleteMe file is still present")             
2850                                endif
2851                elseif(V_isAliasShortcut)
2852                        DeleteFile /P=targetFileFolderPath /Z FileToCopy
2853                        if(V_flag!=0)
2854                                MoveFile /O/P=targetFileFolderPath FileToCopy as FileToCopy+".deleteMe"
2855                                GHW_MakeRecordOfProgress( "Moved to .deleteMe existing file : "+FileToCopy)
2856                        else
2857                                GHW_MakeRecordOfProgress( "Deleted existing file : "+FileToCopy)               
2858                        endif
2859                endif
2860        endif
2861        //and now we can copy the file/folder in the right place
2862        //first need to check the target folder exists...
2863        string tempFldrName, FixedFileToCOpy, AlreadyCreatedPath
2864        string tmpIgorUserFilePathStr=IgorUserFilePathStr
2865        AlreadyCreatedPath = ""
2866        variable i
2867        if(stringmatch(FileToCopy[0],":"))
2868                FixedFileToCopy=FileToCopy[1,inf]
2869        else
2870                FixedFileToCopy=FileToCopy
2871        endif
2872        for(i=0;i<(ItemsInList(FixedFileToCopy,":")-1);i+=1)
2873                tempFldrName=AlreadyCreatedPath+StringFromList(i,FixedFileToCopy,":")
2874                AlreadyCreatedPath += StringFromList(i,FixedFileToCopy,":")+":"
2875                GetFileFolderInfo/Q/Z replaceString("::",IgorUserFilePathStr+tempFldrName,":")
2876                if(V_Flag!=0)   //deas not exist, make it
2877                        NewPath /C/O/Q tmpCreatePath  replaceString("::",IgorUserFilePathStr+tempFldrName,":")
2878                        GHW_MakeRecordOfProgress( "Created new folder " + replaceString("::",IgorUserFilePathStr+tempFldrName,":"))
2879                endif
2880                tmpIgorUserFilePathStr = replaceString("::",IgorUserFilePathStr+tempFldrName,":")+":"
2881        endfor
2882        GetFileFolderInfo/Q/Z/P=sourceFileFolderPath  FileToCopy                //this is source file
2883        if(V_Flag==0)                           //exists...
2884                if(V_isFile)                            //ipf, ihf, dll,... simply a file
2885                        CopyFile /O/P=sourceFileFolderPath /Z  FileToCopy as replaceString("::",IgorUserFilePathStr+FileToCopy,":")
2886                        if(V_flag)
2887                                GHW_MakeRecordOfProgress( "Abort in : "+GetRTStackInfo(3)+"Failed to copy "+FileToCopy, abortProgress=1)
2888                        endif
2889                elseif(V_isFolder)      //xops on Mac are folders
2890                        CopyFolder /O /P=sourceFileFolderPath/Z  FileToCopy as replaceString("::",IgorUserFilePathStr+FileToCopy,":")
2891                        if(V_flag)
2892                                GHW_MakeRecordOfProgress( "Abort in : "+GetRTStackInfo(3)+"Failed to copy "+FileToCopy, abortProgress=1)
2893                        endif   
2894                endif
2895                //note, this cannot handle links, separate code needed for making links.
2896                GHW_MakeRecordOfProgress( "Copied " + FileToCopy + " from "+PathToLocalData+PackgListFilePaths)
2897        else
2898                BrowseURL "https://github.com/jilavsky/SAXS_IgorCode/wiki/Installation-Problems"
2899                GHW_MakeRecordOfProgress( "Abort in : "+GetRTStackInfo(3)+"ERROR: Source File not found : " +FileToCopy, abortprogress=1)
2900        endif
2901        return 1
2902end
2903//**************************************************************************************************************************************
2904//**************************************************************************************************************************************
2905
2906Function/T GHW_FindNonStandardPckgVerNum(PathToLocalFile)
2907        string  PathToLocalFile
2908       
2909        return ""
2910end
2911//****************************************************************
2912//****************************************************************
2913
2914Function GHW_GenerateHelp()
2915        doWindow Inst_Help
2916        if(V_Flag)
2917                DoWindow/F Inst_Help
2918        else   
2919                String nb = "Inst_Help"
2920                NewNotebook/N=$nb/F=1/V=1/K=1/ENCG={3,1}/W=(159,40.25,652.5,736.25)
2921                Notebook $nb defaultTab=36, magnification=100
2922                Notebook $nb showRuler=1, rulerUnits=1, updating={1, 60}
2923                Notebook $nb newRuler=Normal, justification=0, margins={0,0,468}, spacing={0,0,0}, tabs={}, rulerDefaults={"Arial",10,0,(0,0,0)}
2924                Notebook $nb newRuler=Header, justification=1, margins={0,0,468}, spacing={0,0,0}, tabs={}, rulerDefaults={"Arial",10,0,(0,0,0)}
2925                Notebook $nb ruler=Header, fSize=12, fStyle=1, text="Installer for Irena, Nika, and Indra packages\r"
2926                Notebook $nb text="using Github depository.\r"
2927                Notebook $nb text="https://github.com/jilavsky/SAXS_IgorCode\r"
2928                Notebook $nb ruler=Normal, fSize=-1, fStyle=-1, text="\r"
2929                Notebook $nb fStyle=2, text="Jan Ilavsky, May 2020\r"
2930                Notebook $nb fStyle=-1, text="\r"
2931                Notebook $nb fStyle=1, text="NOTE:", fSize=9, text=" ", fStyle=-1
2932                Notebook $nb text="Install ONLY packages you really need. Here are hints...\r"
2933                Notebook $nb text="Irena ... package for modeling of small-angle scattering data (and reflectivity)\r"
2934                Notebook $nb text="Nika ...  package for reduction of data from area detectors (pinhole cameras) 2D -> 1D\r"
2935                Notebook $nb text="Indra ... package for data reduction of USAXS data (unless you measured on APS USAXS or own Rigaku USAXS"
2936                Notebook $nb text=", this is _NOT_ for you) \r"
2937                Notebook $nb fSize=-1, text="\r"
2938                Notebook $nb fStyle=3, textRGB=(52428,1,1), text="Help:\r"
2939                Notebook $nb fStyle=-1, textRGB=(0,0,0), text="\r"
2940                Notebook $nb text="1. ", fStyle=4, textRGB=(0,0,65535), text="https://www.youtube.com/channel/UCDTzjGr3mAbRi3O4DJG7xHA\r"
2941                Notebook $nb fStyle=-1, textRGB=(0,0,0), text="2. ", fStyle=4, textRGB=(0,0,65535)
2942                Notebook $nb text="https://saxs-igorcodedocs.readthedocs.io/en/stable/Installation.html#instructions-for-installation\r"
2943                Notebook $nb fStyle=-1, textRGB=(0,0,0), text="3. ", fStyle=4, textRGB=(0,0,65535)
2944                Notebook $nb text="https://github.com/jilavsky/SAXS_IgorCode/wiki/Installation-Problems", fStyle=-1, textRGB=(0,0,0)
2945                Notebook $nb text=" \r"
2946                Notebook $nb text="\r"
2947                Notebook $nb fStyle=1, text="Requirements", fStyle=-1, text=": \r"
2948                Notebook $nb fSize=9
2949                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"
2950                Notebook $nb text="2.   Access to the depository or downloaded zip file of a release from this depository (", fStyle=1
2951                Notebook $nb text="https://github.com/jilavsky/SAXS_IgorCode)\r"
2952                Notebook $nb fSize=-1, fStyle=-1, text="\r"
2953                Notebook $nb fStyle=1, textRGB=(65535,0,0), text="Use", fStyle=-1, textRGB=(0,0,0), text=": \r"
2954                Notebook $nb text="1.\tSelect from \"", fStyle=2, text="Instal Packages", fStyle=-1, text="\" the menu the option \""
2955                Notebook $nb fStyle=2, text="Open GitHub GUI", fStyle=-1, text="\" to get the \"", fStyle=2, text="Install/Uninstall Package"
2956                Notebook $nb fStyle=-1, text="\"  Panel. \r"
2957                Notebook $nb text="2.\tSelect method of distribution you want to use: \r"
2958                Notebook $nb fSize=9, text="\ta/\t", fStyle=1, text="Default is Github", fStyle=-1
2959                Notebook $nb text=". Installer will download zip file, unzip, and install from it. \r"
2960                Notebook $nb text="\t\tMake sure the \"", fStyle=1, text="Use Local Folder", fStyle=-1, text="?\"checkbox is ", fStyle=5
2961                Notebook $nb text="unchecked", fStyle=-1, text=".  \r"
2962                Notebook $nb text="\t\tPush \"", fStyle=1, text="Check packages versions", fStyle=-1, text="\". \r"
2963                Notebook $nb text="\tb/\t", fStyle=1, text="Optional is local copy", fStyle=-1, text=" of the depository. \r"
2964                Notebook $nb text="\t\tMake sure the \"", fStyle=1, text="Use Local Folder", fStyle=-1, text="?\"checkbox is ", fStyle=5
2965                Notebook $nb text="checked", fStyle=4, text=".\r"
2966                Notebook $nb fStyle=-1, text="\t\tDownload zip file with version of packages from Github manually.\r"
2967                Notebook $nb text="\t\tUnzip, and place the folder from inside of the zip file (typically named SAXS_IgorCode_MonthYear) \r"
2968                Notebook $nb text="\t\t\ton the desktop together with this Igor Installer experiment.\r"
2969                Notebook $nb text="\t\tPush \"", fStyle=1, text="Check packages versions", fStyle=-1, text="\"\r"
2970                Notebook $nb fSize=-1, text="\r"
2971                Notebook $nb text="3.\tInstaller will check what version is available. It will offer table with versions. \r"
2972                Notebook $nb text="4.\tSelect package/releases to install (or unistall)  in \"", fStyle=3, text="Select release to install"
2973                Notebook $nb fStyle=-1, text="\". \r"
2974                Notebook $nb text="5.\tPush \"", fStyle=1, text="Install/Update", fStyle=-1, text="\" or \"", fStyle=1, text="Unistall"
2975                Notebook $nb fStyle=-1, text="\" buttons as needed\r"
2976                Notebook $nb text="\r"
2977                Notebook $nb text="when succesfully finished, you will get \"All done.\" Alert window and message in the history area. \r"
2978                Notebook $nb text="\r"
2979                Notebook $nb fStyle=1, text="Beta versions", fStyle=-1, text=": \r"
2980                Notebook $nb text="If you need/want latest beta version, check checkbox \"", fStyle=1, text="Include Beta releases"
2981                Notebook $nb fStyle=-1, text="\" and list in \"", fStyle=1, text="Select release to install", fStyle=-1
2982                Notebook $nb text="\" will include Beta versions and \"", fStyle=1, text="master", fStyle=-1
2983                Notebook $nb text="\" (listed at the end of the list).  \r"
2984                Notebook $nb text="\t", fStyle=1, text="Beta versions", fStyle=-1
2985                Notebook $nb text=" are released as needed when code is relatively stable. \r"
2986                Notebook $nb text="\t\"", fStyle=1, text="master", fStyle=-1
2987                Notebook $nb text="\" is latest version at the time of download available in the depository. \r"
2988                Notebook $nb text="Note, there are no guarrantees the master will even work, that code is under developement! "
2989                Notebook $nb fStyle=3, textRGB=(52428,1,1)
2990                Notebook $nb text="Install Master only when instructed by author. Typically because a bug you have issues with was fixed fo"
2991                Notebook $nb text="r you.", fStyle=1, text="  \r"
2992                Notebook $nb fStyle=-1, textRGB=(0,0,0), text="\r"
2993                Notebook $nb text="If there are problems, you will get error message with instructions. First follow instructions on :"
2994                Notebook $nb fStyle=4, textRGB=(0,0,65535), text=" https://github.com/jilavsky/SAXS_IgorCode/wiki/Installation-Problems \r"
2995                Notebook $nb fStyle=-1, textRGB=(0,0,0), text="\r"
2996                Notebook $nb text="If that does not work, let author know and", textRGB=(0,1,2), text=", please, send me the log file \""
2997                Notebook $nb textRGB=(0,0,0), text="InstallRecord.txt", textRGB=(0,1,2)
2998                Notebook $nb text="\" from your desktop together with information on yoru computer - Windows version, path to your .../Wavem"
2999                Notebook $nb text="etrics/Igor Pro User Files and anything else special on yrou computer.\r"
3000                Notebook $nb textRGB=(0,0,0), text="\r"
3001                Notebook $nb text="After sucessful installation, code will attempt to delete the distribution zip file and the unzipped fol"
3002                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"
3003                Notebook $nb text="lly. You can delete also the logfile (InstallRecord.txt) file from desktop.\r"
3004                Notebook $nb text="\r"
3005                Notebook $nb text="note: download of distribution zip file may take a long time (they are around 100Mb). You may want to ke"
3006                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 "
3007                Notebook $nb text="used even in subsequent installations. \r"
3008                Notebook $nb text="\r"
3009                Notebook $nb text="Install xop files based on bit-version you intend to use (or simply install both if you have 64-bit mach"
3010                Notebook $nb text="ine). The xop packages are needed for any package.\r"
3011                Notebook $nb text="\r"
3012                Notebook $nb text="After any unistallation, you should reinstall packages you intend to use. Another words, since packages "
3013                Notebook $nb text="share libraries, after any uninstallation of only one package the other packages are likely unusable. \r"
3014                Notebook $nb text="\r"
3015                Notebook $nb text="*** ", fSize=11, fStyle=1, textRGB=(52428,1,1)
3016                Notebook $nb text="You can always update to the latest version of the packages using this experiment. When I update the on "
3017                Notebook $nb text="line depository, this experiment will pick the listing and re-download ALL packages again. To check whic"
3018                Notebook $nb text="h version is the last one available on the web, use button \"Check packages versions"
3019                Notebook $nb fSize=-1, fStyle=-1, textRGB=(0,1,2), text="\".\r"
3020                Notebook $nb text="\r"
3021                Notebook $nb text="ilavsky@aps.anl.gov\r"
3022        endif
3023end
3024
3025
3026//**************************************************************************************************************************************
3027//**************************************************************************************************************************************
3028// this is unzip method using PowerShell. Works for Windows 8 and 10. It would also work for Mac, not that is not needed.
3029
3030// returns 1 for success, 0 for failure
3031function GHW_unzipArchive(archivePathStr, unzippedPathStr)
3032    string archivePathStr, unzippedPathStr
3033       
3034    string validExtensions="zip;" // set to "" to skip check
3035    variable verbose=1  // choose whether to print output from executescripttext
3036    verbose = 0                                 //does not work on Windows anyway...
3037    string msg, unixCmd, cmd
3038       
3039    GetFileFolderInfo /Q/Z archivePathStr
3040
3041    if(V_Flag || V_isFile==0)
3042        printf "Could not find file %s\r", archivePathStr
3043        return 0
3044    endif
3045
3046    if(itemsInList(validExtensions) && findlistItem(ParseFilePath(4, archivePathStr, ":", 0, 0), validExtensions, ";", 0, 0)==-1)
3047        printf "%s doesn't appear to be a zip archive\r", ParseFilePath(0, archivePathStr, ":", 1, 0)
3048        return 0
3049    endif
3050   
3051    if(strlen(unzippedPathStr)==0)
3052        unzippedPathStr=SpecialDirPath("Desktop",0,0,0)+ParseFilePath(3, archivePathStr, ":", 0, 0)
3053        sprintf msg, "Unzip to %s:%s?", ParseFilePath(0, unzippedPathStr, ":", 1, 1), ParseFilePath(0, unzippedPathStr, ":", 1, 0)
3054        doALert 1, msg
3055        if (v_flag==2)
3056            return 0
3057        endif
3058    else
3059        GetFileFolderInfo /Q/Z unzippedPathStr
3060        if(V_Flag || V_isFolder==0)
3061            sprintf msg, "Could not find unzippedPathStr folder\rCreate %s?", unzippedPathStr
3062            doalert 1, msg
3063            if (v_flag==2)
3064                return 0
3065            endif
3066        endif   
3067    endif
3068   
3069    // make sure unzippedPathStr folder exists - necessary for mac
3070    newpath /C/O/Q acw_tmpPath, unzippedPathStr
3071    killpath /Z acw_tmpPath
3072
3073    if(stringmatch(StringByKey("OS", igorinfo(3))[0,2],"Win")) // Windows
3074        // The following works with .Net 4.5, which is available in Windows 8 and up.
3075        // current versions of Windows with Powershell 5 can use the more succinct PS command
3076        // 'Expand-Archive -LiteralPath C:\archive.zip -DestinationPath C:\Dest'
3077        //  Expand-Archive -LiteralPath C:\Archives\Invoices.Zip -DestinationPath C:\InvoicesUnzipped -Force
3078        //https://blog.netwrix.com/2018/11/06/using-powershell-to-create-zip-archives-and-unzip-files/
3079        //string strVersion=StringByKey("OSVERSION", igorinfo(3))  //this does not work, Windows 10 report 6.x
3080        variable WinVersion=str2num(StringByKey("OS", igorinfo(3))[7,12])               //this extractssimply number from OS key, should be 7, 8, 10 for now.
3081        if (WinVersion<8)
3082            print "unzipArchive requires Windows 8 or later"
3083            return 0
3084        endif
3085       
3086        archivePathStr=parseFilePath(5, archivePathStr, "\\", 0, 0)
3087        unzippedPathStr=parseFilePath(5, unzippedPathStr, "\\", 0, 0)
3088        cmd="powershell.exe -nologo -noprofile -command \"& { Add-Type -A 'System.IO.Compression.FileSystem';"
3089        sprintf cmd "%s [IO.Compression.ZipFile]::ExtractToDirectory('%s', '%s'); }\"", cmd, archivePathStr, unzippedPathStr
3090    else // Mac
3091        sprintf unixCmd, "unzip %s -d %s", ParseFilePath(5, archivePathStr, "/", 0,0), ParseFilePath(5, unzippedPathStr, "/", 0,0)
3092        sprintf cmd, "do shell script \"%s\"", unixCmd
3093    endif
3094   
3095    executescripttext /B/UNQ/Z cmd
3096    if(verbose)
3097        print S_value // output from executescripttext
3098    endif
3099   
3100    return (v_flag==0)
3101end
Note: See TracBrowser for help on using the repository browser.