#pragma rtGlobals=1 // Use modern global access method. #if Exists("easyHttp") && Exists("XMLopenfile") Function update_package([package_name]) string package_name string available_packages="", manifest_url variable refNum, version, new_version string install_location, user_procedures, igor_procedures, igor_extensions, temp_location install_location = SpecialDirPath("Igor Pro User Files", 0, 0, 0) temp_location =SpecialDirPath("temporary", 0, 0, 0) user_procedures = install_location + "User Procedures:" igor_procedures = install_location + "Igor Procedures:" igor_extensions = install_location + "Igor Extensions:" newpath/o/q/z package_location, user_procedures + "packages:" if(paramisdefault(package_name)) available_packages = indexedfile(package_location, -1, ".xml") prompt package_name, "package", popup, available_packages Doprompt "Which package do you want to update?", package_name if(V_flag) abort endif endif //now go in and see if it can be updated. refNum = XMLopenfile(user_procedures+"packages:"+package_name) if(refnum < 0) Abort "Failed to parse XML installer script properly" endif version = str2num(XMLstrfmXpath(refNum, "/manifest/@version", "", "")) manifest_url = XMLstrfmXpath(refNum, "/manifest/@url", "", "") if(refNum > 0) XMLclosefile(refnum, 0) endif //now grab new manifest easyHttp/file=temp_location+package_name manifest_url if(V_flag) abort "Couldn't download new manifest for update" endif refnum = XMLopenfile(temp_location+package_name) if(refnum < 0) Abort "Failed to parse XML installer script properly" endif new_version = str2num(XMLstrfmXpath(refNum, "/manifest/@version", "", "")) if(new_version > version)//update the package print "FOUND NEW VERSION of: ", package_name execute/p "packageXMLinstaller(installerscript=\""+temp_location+package_name+"\")" endif if(refNum > 0) XMLclosefile(refnum, 0) endif End Function packageXMLinstaller([installerscript]) string installerscript string install_location, user_procedures, igor_procedures, igor_extensions variable refNum, ii, jj, kk, numnodes if(paramisdefault(installerscript)) open/r/d/f=".xml"/M="Please select the XML installer script" refnum installerscript = S_filename if(strlen(S_filename) ==0) abort "Installation aborted" endif endif install_location = SpecialDirPath("Igor Pro User Files", 0, 0, 0) user_procedures = install_location + "User Procedures:" igor_procedures = install_location + "Igor Procedures:" igor_extensions = install_location + "Igor Extensions:" try //open the installer script refNum = XMLopenfile(installerscript) if(refnum < 0) Abort "Failed to parse XML installer script properly" endif print "************* installing", installerscript, "******************" //go through and install all files into user procedures XMLlistXpath(refNum, "/manifest/up", "") Wave/t M_listXpath numnodes = dimsize(M_listXPath, 0) for(ii = 0 ; ii 0) XMLclosefile(refNum, 0) endif //put a copy of the installer script in /User Procedures/packages" newpath/o/q/c/z installed_packages, user_procedures + "packages" copyfile/o/d installerscript as user_procedures+"packages:" End Function download_and_install_packages(refNum, node_xpath, location) variable refNum string node_xpath, location variable ii, num_packages, jj, num_files string package_name, url_root, url, file_name, current_xpath, shortcut string install_location, user_procedures, igor_procedures, igor_extensions, igor_location, igor_help install_location = SpecialDirPath("Igor Pro User Files", 0, 0, 0) user_procedures = install_location + "User Procedures:" igor_procedures = install_location + "Igor Procedures:" igor_extensions = install_location + "Igor Extensions:" igor_help = install_location + "Igor Help Files:" pathinfo igor igor_location = S_path XMLlistXpath(refNum, node_xpath+"/package", "") Wave/t M_listXpath num_packages = dimsize(M_listXPath, 0) for(ii = 0 ; ii < num_packages ; ii+=1) XMLlistXpath(refNum, node_xpath+"/package", "") Wave/t M_listXpath package_name = xmlstrfmxpath(refnum, M_listxpath[ii][0]+"/@name", "","") url_root = xmlstrfmxpath(refnum, M_listxpath[ii][0]+"/@root", "","") shortcut = xmlstrfmxpath(refnum, M_listxpath[ii][0]+"/@shortcut", "","") current_xpath = M_listxpath[ii][0] //create the folder here if(strlen(package_name) > 0) Newpath/c/o/q/z package_path, location + package_name + ":" location += package_name + ":" endif download_and_install_packages(refNum, current_xpath, location) strswitch (shortcut) case "ip": createaliasshortcut/z location as igor_procedures + package_name + " alias" break case "igor": createaliasshortcut/z location as igor_location + package_name + " alias" break case "ie": createaliasshortcut/z location as igor_extensions + package_name + " alias" break case "ihf": createaliasshortcut/z location as igor_help + package_name + " alias" break default: break endswitch //now grab files. print "PACKAGE: "+package_name XMLlistXpath(refNum, current_xpath+"/file", "") Wave/t M_listXpath num_files = dimsize(M_listXPath, 0) for(jj = 0 ; jj < num_files ; jj+=1) url = xmlstrfmxpath(refnum, M_listxpath[jj][0]+"/@url", "","") file_name = xmlstrfmxpath(refnum, M_listxpath[jj][0]+"/@name", "","") shortcut = xmlstrfmxpath(refnum, M_listxpath[ii][0]+"/@shortcut", "","") print "FILE:\t", location + file_name, "\t\t from: \t\t", url_root+url easyHttp/file=(location+file_name) url_root+url if(V_flag) print "PROBLEM DOWNLOADING:\t ", url_root+url continue endif strswitch (shortcut) case "ip": createaliasshortcut/z location +file_name as igor_procedures + file_name + " alias" break case "igor": createaliasshortcut/z location +file_name as igor_location + file_name + " alias" break case "ie": createaliasshortcut/z location + file_name as igor_extensions + file_name + " alias" break case "ihf": createaliasshortcut/z location +file_name as igor_help + file_name + " alias" break default: break endswitch endfor killpath/z package_path endfor End #else Function packageXMLinstaller([installerscript]) string installerscript Doalert 0, "Please install XMLutils and easyHttp first" BrowseURL "http://www.igorexchange.com/project/XMLutils" BrowseURL "http://www.igorexchange.com/project/easyHttp" End #endif