0
Wird überprüft

toolbox updater tool - a elementary implementation

john doe vor 9 Jahren aktualisiert von Pavel Holoborodko vor 9 Jahren 4

the intuition tells me that in the very near future this tool will be very useful; It seems that Pavel prepares a lot of updates (very pleasing, I think)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function advanpix_update()
% check for a newer version than the locally installed,
% download the new version and then launches the installer


v = sscanf (version, '%d.%d.%d') ; % /matlabcentral/fileexchange/17285-getversion
v = 10.^(0:-1:-(length(v)-1))*v ;
if ~(v>=8.4), disp(' ... this implementation requires Matlab R2014b or newer.')
return; end

try
text = webread('http://www.advanpix.com/download/','Timeout',5);
% get version available for download
newver = strtrim(strtok(regexprep(text,'.+Download Trial.+Ver.',''),'<'));
% get local installed version
info = evalc('mp.Info');
text = regexp(info,'Version.*','ignorecase','dotexceptnewline','match');
curver = regexprep(strtrim(regexprep(char(text),'[^0-9.\s]','')),'\s+','.');
if ~strcmp(newver,curver)
instdir = winqueryreg('HKEY_CURRENT_USER','Software\Advanpix','InstallDir');
if exist(fullfile(instdir,'download'),'dir')~=7
mkdir(fullfile(instdir,'download'));
end
Url = 'http://www.advanpix.com/wp-content/plugins/download-monitor/download.php?id=1';
exe_name = ['AdvanpixMCT-',newver,'-Setup.exe'];
disp('Try downloading the newest version of the toolbox. Wait, please ...');
% Check for supported Microsoft .NET Framework
if NET.isNETSupported
disp('Supported .NET Framework not found')
% create .Net object to handle the file download
NET.addAssembly('System.Net');
client = System.Net.WebClient;
installer = fullfile(instdir,'download',exe_name);
client.DownloadFile(Url,fullfile(instdir,'download',installer));
else
options = weboptions('Timeout',30,'ContentType','binary');
olddir = cd(fullfile(instdir,'download'));
try installer = websave(exe_name,Url,options);
catch, cd(olddir); end
cd(olddir);
end
% run the installer
system(installer);
else
disp('The latest version of the toolbox is already installed.');
end
catch ME
rethrow(ME)
end
end
Wird überprüft
I think script for automatic updates will be very helpful for many people.
Thank you for sharing it!
Probably I will re-port it on advanpix homepage, if you allow (?)

The line 33

client.DownloadFile(Url,fullfile(instdir,'download',installer));

must be replaced with:

client.DownloadFile(Url,installer);

Thank you very much for correction!