forked from mtex-toolbox/mtex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_mtex.m
80 lines (56 loc) · 1.68 KB
/
update_mtex.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
function update_mtex()
try
newver = getlatesMTEXversion();
vinst = ver2num(getMTEXpref('version'));
vnew = ver2num(newver);
for k=1:numel(vinst)
if vinst(k) > vnew(k)
break
elseif vinst(k) ~= vnew(k)
downloadAndInstallMTEX(newver);
return
end
end
disp(['no MTEX updates available, your version is ' newver])
catch e
throwAsCaller(e)
end
end
function ver = getlatesMTEXversion()
dpage = urlread('https://code.google.com/p/mtex/downloads/list');
v = regexp(dpage,'(?<vers>mtex-\d+.\d+.\d+)','names');
v = sort(unique({v.vers}));
ver = v{end};
end
function downloadAndInstallMTEX(ver)
url = ['https://mtex.googlecode.com/files/' ver '.zip'];
thispath = fileparts(mfilename('fullpath'));
instpath = fileparts(thispath);
disp(['Latest available MTEX version is ' ver])
disp(' ')
disp([' ' url])
disp(' ')
disp('Do you want to download and install the package to')
disp(' ')
disp([' ' fullfile(instpath,ver)])
disp(' ')
reply = input('Y/N [Y]: ','s');
if strncmpi(reply,'y',1)
disp(' ')
disp(['Downloading ' ver '.zip to ' fullfile(instpath,ver)]);
if exist(fullfile(instpath,ver),'dir')
error('MTEX:update','The specified Folder already exists')
end
files = unzip(url,instpath);
installfile = files{~cellfun('isempty',strfind(files,[ filesep 'install_mtex.m']))};
disp(installfile);
cd(fileparts(installfile));
run(installfile);
cd(thispath);
disp('Successfully updated MTEX, please restart matlab');
end
end
function n = ver2num(v)
vs = '(?<major>\d+).(?<minor>\d+).(?<rev>\d+)';
n = structfun(@str2num,regexp(v,vs,'names'));
end