Skip to content
Snippets Groups Projects
Commit 93ef4bf7 authored by leprob001's avatar leprob001
Browse files

Updated versioning system. Artoa now checks if your loaded interim file is...

Updated versioning system. Artoa now checks if your loaded interim file is compatible to the artoa version you are using.
parent 30e05005
No related branches found
No related tags found
No related merge requests found
177
\ No newline at end of file
178
\ No newline at end of file
......@@ -2,7 +2,7 @@ function [] = loadInterim(~, ~)
%LOADINTERIM Loads the current state of ARTOA4 from the file specified by dialog.
%
global artoaDataInput;
global artoaDataInput artoaWorkspace;
%% Get required variables
folder = artoa.data.getMember(artoaDataInput, {'ini', 'directory', 'interim'}, pwd());
......@@ -35,5 +35,11 @@ artoa.controller.edit.offsets.updateGui();
%% Update menu buttons
artoa.controller.updateMenuButtons();
%% Notify user if he loaded an outdated interim version
[upToDate, message] = artoa.versioning.checkInterim(artoaWorkspace);
if ~upToDate
msgbox(message, 'Interim file version outdated!', 'warn');
end
end
function [versionString] = getVersionString()
%GETVERSIONSTRING Summary of this function goes here
% Detailed explanation goes here
%% Get version information
versionString = [ ...
'Version 4.' ...
strtrim(fileread(fullfile(fileparts(mfilename('fullpath')), '..', '..', '..', '..', 'VERSION'))) ...
];
end
......@@ -238,7 +238,7 @@ gitInfo = getGitInfo();
artoaGui.main.textVersionInfo = uicontrol( ...
'Parent', artoaGui.figures.main, ...
'String', artoa.controller.main.getVersionString(), ...
'String', artoa.versioning.getVersionString(), ...
'Style', 'text', ...
'FontSize', 10, ...
'Units', 'characters', ...
......
function [] = apply(pInterimFilename)
%APPLY Applies all migrations that are required to upgrade to the latest version.
%
global artoaWorkspace artoaDataInput;
workspaceSaved = false;
%% Check if workspace needs to be saved
if ~isempty(artoaWorkspace) && ~isempty(artoaDataInput)
workspaceSaved = true;
end
%% Save workspace
if workspaceSaved
disp('Saving workspace...');
tmpWorkspace = artoaWorkspace;
tmpDataInput = artoaDataInput;
clear artoaWorkspace artoaDataInput;
disp('...success!');
end
%% Check if file exists
if (~isfile(pInterimFilename))
warning('The given file does not exist! Aborting...');
restoreWorkspace();
return
end
%% Find all versions available
[versionsFilePath, ~, ~] = fileparts(mfilename('fullpath'));
versionsFileNames = dir(fullfile(versionsFilePath, 'versions', 'v*.m'));
%% Load the interim file
load(pInterimFilename, 'artoaWorkspace', 'artoaDataInput', '-mat');
%% Get itm version
itmVersion = 'unknown';
if isfield(artoaWorkspace, 'artoaVersion')
itmVersion = artoaWorkspace.artoaVersion;
end
disp(['Starting migration from Version ' itmVersion ' to Version ' versionsFileNames(end).name(2:end - 2)]);
%% Modify required variables
for o = 1:size(versionsFileNames)
if (versionsFileNames(o).isdir)
warning([versionsFileNames(o).name 'is a directory and will be omitted...']);
continue;
end
currentVersionNumber = versionsFileNames(o).name(2:end - 2);
if ~strcmp('unknown Version', itmVersion) & (currentVersionNumber <= itmVersion)
continue;
end
disp(['Applying Version' currentVersionNumber '...']);
run(fullfile(versionsFileNames(o).folder, versionsFileNames(o).name));
artoaWorkspace.artoaVersion = currentVersionNumber;
disp('...done!');
end
%% Save with added version number
[path, name, ext] = fileparts(pInterimFilename);
adjustedFilename = fullfile(path, [name '_' versionsFileNames(end).name(2:end - 2) ext]);
save( ...
adjustedFilename, ...
'artoaWorkspace', 'artoaDataInput', ...
'-mat' ...
);
%% Restore workspace
if workspaceSaved
restoreWorkspace();
end
disp(['Adjusted interim file has been written to:' newline adjustedFilename]);
function restoreWorkspace()
disp('Restoring workspace...');
clear artoaWorkspace artoaDataInput;
artoaWorkspace = tmpWorkspace;
artoaDataInput = tmpDataInput;
disp('...success!');
end
end
function [] = apply(pInterimFilename)
%APPLY Applies all migrations that are required to upgrade to the latest version.
%
global artoaWorkspace artoaDataInput;
workspaceSaved = false;
success = true;
%% Check if workspace needs to be saved
if ~isempty(artoaWorkspace) && ~isempty(artoaDataInput)
workspaceSaved = true;
end
%% Save workspace
if workspaceSaved
disp('Saving workspace...');
tmpWorkspace = artoaWorkspace;
tmpDataInput = artoaDataInput;
artoaWorkspace = [];
artoaDataInput = [];
disp('...success!');
end
try
%% Check if file exists
if (~isfile(pInterimFilename))
warning('The given file does not exist! Aborting...');
restoreWorkspace();
return
end
%% Find all versions available
[versionsFilePath, ~, ~] = fileparts(mfilename('fullpath'));
versionsFileNames = dir(fullfile(versionsFilePath, 'versions', 'v*.m'));
%% Load the interim file
load(pInterimFilename, 'artoaWorkspace', 'artoaDataInput', '-mat');
%% Get itm version
itmVersion = 'unknown';
if isfield(artoaWorkspace, 'artoaVersion')
itmVersion = artoaWorkspace.artoaVersion;
end
disp(['Starting migration from Version ' itmVersion ' to Version ' versionsFileNames(end).name(2:end - 2)]);
%% Modify required variables
for o = 1:size(versionsFileNames)
if (versionsFileNames(o).isdir)
warning([versionsFileNames(o).name 'is a directory and will be omitted...']);
continue;
end
currentVersionNumber = versionsFileNames(o).name(2:end - 2);
if ~strcmp('unknown', itmVersion) & (currentVersionNumber <= itmVersion)
continue;
end
disp(['Applying Version' currentVersionNumber '...']);
run(fullfile(versionsFileNames(o).folder, versionsFileNames(o).name));
artoaWorkspace.artoaVersion = currentVersionNumber;
disp('...done!');
end
%% Save with added version number
[path, name, ext] = fileparts(pInterimFilename);
adjustedFilename = fullfile(path, [name '_' versionsFileNames(end).name(2:end - 2) ext]);
save( ...
adjustedFilename, ...
'artoaWorkspace', 'artoaDataInput', ...
'-mat' ...
);
catch Ex
disp(Ex);
success = false;
end
%% Restore workspace
if workspaceSaved
restoreWorkspace();
else
clearvars -global artoaWorkspace artoaDataInput;
end
if success
disp(['Adjusted interim file has been written to:' newline adjustedFilename]);
end
%% Nested functions
function restoreWorkspace()
disp('Restoring workspace...');
artoaWorkspace = [];
artoaDataInput = [];
artoaWorkspace = tmpWorkspace;
artoaDataInput = tmpDataInput;
disp('...success!');
end
end
function [maxVersion] = getLatestVersionNumber()
%GETLATESTVERSIONNUMBER Summary of this function goes here
% Detailed explanation goes here
%% Get all migration versions
[versionsFilePath, ~, ~] = fileparts(mfilename('fullpath'));
versionsFileNames = dir(fullfile(versionsFilePath, 'versions', 'v*.m'));
%% Extract version numbers
versions = {versionsFileNames(:).name};
versions = str2double(cellfun(@(x) x(3:end-2), versions, 'UniformOutput', false));
maxVersion = max(versions);
end
function [upToDate, message] = checkInterim(pArtoaWorkspace)
%CHECKINTERIMVERSION Summary of this function goes here
% Detailed explanation goes here
%% Initialize return variables
upToDate = true;
message = '';
%% Check if the stored version is the most recent one
currentArtoaVersion = str2num(artoa.versioning.getVersionString(true));
maxMigration = artoa.versioning.migrations.getLatestVersionNumber();
if ~isfield(pArtoaWorkspace, 'artoaVersion')
message = [ ...
'You loaded an iterim file with an unknown Version.' newline ...
'Your artoa4 instance is on Version 4.' num2str(currentArtoaVersion) '.' newline ...
'Please consider upgrading your interim file using the' newline newline ...
'artoa.versioning.migrations.apply(yourArtoaFilePath)' newline newline ...
'command.' newline ...
'Artoa might be unstable otherwise!'
];
upToDate = false;
return;
end
workspaceVersion = str2num(pArtoaWorkspace.artoaVersion(2:end));
if workspaceVersion < currentArtoaVersion & workspaceVersion < maxMigration
message = [ ...
'You loaded an iterim file that has Version 4.' ...
num2str(workspaceVersion) ...
'.' newline ...
'Your artoa4 instance is on Version 4.' num2str(currentArtoaVersion) '.' newline ...
'Please consider upgrading your interim file using the' newline newline ...
'artoa.versioning.migrations.apply(yourArtoaFilePath)' newline newline ...
'command.' newline ...
'Artoa might be unstable otherwise!'
];
upToDate = false;
else
end
function [versionString] = getVersionString(pCommitNumberOnly)
%GETVERSIONSTRING Summary of this function goes here
% Detailed explanation goes here
%% Initialize input parameter
if nargin == 0
pCommitNumberOnly = false;
end
%% Read version string
versionString = strtrim( ...
fileread( ...
fullfile(fileparts(mfilename('fullpath')), '..', '..', '..', 'VERSION') ...
) ...
);
if pCommitNumberOnly
return;
end
versionString = ['Version 4.' versionString];
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment