Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="design"/>
</Category>
</Info>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info location="resolveFilePath.m" type="File"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="design"/>
</Category>
</Info>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info location="incrementVersionNumber.m" type="File"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="design"/>
</Category>
</Info>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info location="readVersionNumber.m" type="File"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info location="loading_128.gif" type="File"/>
36 changes: 36 additions & 0 deletions widgets/+wt/+utility/incrementVersionNumber.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
function versionStr = incrementVersionNumber(filePath)
% Increments the last decimal of the version number
%
% Version file should be .txt and only contain a multi-part version with at
% least 2 parts.
% Valid version.txt Examples:
% 2.4
% 1.0.3
% 1.3.9.2019

% Copyright 2026 The MathWorks Inc.

arguments (Input)
filePath (1,1) string {mustBeFile}
end

arguments (Output)
versionStr (1,1) string
end

% Read in the version info
[~, versionParts] = wt.utility.readVersionNumber(filePath);

% Increment the build index in the version number
numVersionParts = numel(versionParts);
if numVersionParts < 2
versionParts(2) = uint32(1);
else
versionParts(end) = versionParts(end) + uint32(1);
end

% Format as string
versionStr = join(string(versionParts),".");

% Update the version file
writelines(versionStr, filePath);
28 changes: 28 additions & 0 deletions widgets/+wt/+utility/readVersionNumber.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function [versionStr, versionParts] = readVersionNumber(filePath)
% Retrieves the version number
%
% Version file should be .txt and only contain a multi-part version with at
% least 2 parts.
% Valid version.txt Examples:
% 2.4
% 1.0.3
% 1.3.9.2019

% Copyright 2026 The MathWorks Inc.

arguments (Input)
filePath (1,1) string {mustBeFile}
end

arguments (Output)
versionStr (1,1) string
versionParts (1,:) uint32 {mustBeNonempty}
end

% Read in the version parts
versionParts = readmatrix(filePath,...
"Delimiter",".",...
"OutputType","uint32");

% Format as string
versionStr = join(string(versionParts),".");
117 changes: 117 additions & 0 deletions widgets/+wt/+utility/resolveFilePath.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
function filePath = resolveFilePath(fileName)
% Searches for a valid path to the specified file name
%
% Order of priority:
% 1. Full path provided
% 2. If deployed, installation folder of the application
% (e.g. C:\Program Files\...)
% 3. Folder of the calling function, or the first non-namespace folder
% (@/+) up from the calling function's folder.
% 4. MATLAB path (via "which" command)

% Copyright 2026 The MathWorks Inc.

arguments
fileName (1,1) string
end

% Default output
filePath = ""; %#ok<NASGU>


%% Check if a full path was provided already
if strlength( fileparts(fileName) ) > 0

% If a full path was provided, and it is valid, just use it
if isfile(fileName)

filePath = fileName;
return

else

% Throw a warning
id = "resolvePathFromFileName:BadPath";
msg = "File was provided with a path that does not exist: %s";
warning(id, msg, fileName);

% Return the input as-is
filePath = fileName;

return
end

end %if


%% If deployed, next look in the installation folder
if isdeployed

% The install folder will be where the executable runs from
[~, systemPath] = system('set PATH');
installPath = extractBetween(string(systemPath), "Path=", ";");

% Check for the file there
testPath = fullfile(installPath, fileName);
if isfile(testPath)
filePath = testPath;
return
end

end %if


%% Next, look at the folder containing the calling function

% Get the calling function
stackInfo = dbstack(1,"-completenames");
if ~isempty(stackInfo)

callingFcn = stackInfo(1).file;
folderPath = fileparts(callingFcn);

% Check for the file in the same folder with calling fcn
testPath = fullfile(folderPath, fileName);
if isfile(testPath)
filePath = testPath;
return
end

% If not found, walk up the folder hierarchy for a normal folder
% (not a + or @ folder)
% Walk up the folder hierarchy
[~, leafFolder] = fileparts(folderPath);
while strlength(leafFolder) && startsWith(leafFolder, {'+', '@'})
[folderPath, ~] = fileparts(folderPath);
[~, leafFolder] = fileparts(folderPath);
end

% Check for the file in the top folder found
testPath = fullfile(folderPath, fileName);
if isfile(testPath)
filePath = testPath;
return
end

end %if


%% Finally, check the MATLAB path
if isfile(fileName)

% Use WHICH to locate the file
filePath = which(fileName);
return

else

% Unable to find the file. Throw a warning.
id = "resolvePathFromFileName:NotFound";
msg = "File not found or does not exist: %s";
warning(id, msg, fileName);

% Return the original path
filePath = fileName;
return

end %if
Binary file added widgets/icons/loading_128.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading