Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated version checking. #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 66 additions & 14 deletions NPMK/NPMKverChecker.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,72 @@ function NPMKverChecker()
% 1.0.2.0: January 10, 2018
% - Added a clickable URL to the prompt.
%

persistent new_version
gitHubURL = 'https://github.com/BlackrockMicrosystems/NPMK/releases/latest';

%% Check for the latest version fo NPMK
try
FIDv = fopen('Versions.txt');
verFile = fscanf(FIDv, '%s');
fclose(FIDv);
latestVersion = verFile(findstr('LATEST', verFile)+7:findstr('LATEST', verFile)+13);
gitHubPage = urlread(gitHubURL);
newVersionAvailable = findstr(latestVersion, gitHubPage);
if isempty(newVersionAvailable)
disp('A new version of NPMK may be available.');
fprintf('Please visit <a href="%s">GitHub NPMK Page</a> to get the latest version.\n', gitHubURL)
if isempty(new_version)
%% Check for the latest version fo NPMK
try
% Local copy
FIDv = fopen('Versions.txt');
verFile = fscanf(FIDv, '%s');
fclose(FIDv);
latestVersion = verFile(findstr('LATEST', verFile)+7:findstr('LATEST', verFile)+13);

% Remote copy
gitHubPage = urlread(gitHubURL);
gitVersion = regexp(gitHubPage, '\<title\>.*(\d+\.\d+\.\d+\.\d+).*\</title\>', 'tokens');
gitVersion = gitVersion{1}{1};

new_version = compare_semver(gitVersion, latestVersion) == -1;
catch
end
end

if new_version
disp('A new version of NPMK may be available.');
fprintf('Please visit <a href="%s">GitHub NPMK Page</a> to get the latest version.\n', gitHubURL)
end
end

function cmp = compare_semver(a, b)
%% COMPARE_SEMVAR: Compare two "semantic version" strings
% INPUT:
% - a, b: Semantic version strings (as char arrays)
% OUTPUT:
% - cmp: Comparison value (like C's strcmp)
% -1 if a is more recent than b
% 0 if a and b are the same
% 1 if b is more recent than a
% NOTES:
% - In brief, semantic versions are MAJOR.MINOR.PATCH (etc). These are
% slightly different from "regular" decimals, in that version 1.2 is
% newer than 1.1, but 17 minor releases older than 1.19
% - This doesn't yet handle pre-release or other metadata stuff

a = strsplit(a, '.');
b = strsplit(b, '.');

if length(b) > length(a)
tmp = a;
a=b;
b=tmp;
end

while length(a) > length(b)
b{end+1} = 0;
end
a = str2double(a);
b = str2double(b);

for ii=1:length(a)
if a(ii) > b(ii)
cmp = -1;
return
elseif a(ii) < b(ii)
cmp = 1;
return;
end
catch
end
end
cmp = 0;
end