-
Notifications
You must be signed in to change notification settings - Fork 10
/
cdgea.m
97 lines (81 loc) · 3.27 KB
/
cdgea.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
function [pw1, pw0] = cdgea(isconfirmed)
%CDGEA - Change working directory to the scGEAToolbox folder
if nargin < 1
isconfirmed = true;
end
pw0 = pwd; % Get current directory
pw1 = fileparts(mfilename('fullpath')); % Get directory of this file
% Check if current directory differs from scGEAToolbox directory
if ~strcmp(pw0, pw1) && ~isconfirmed
% Ask the user for confirmation before changing directory
selectedButton = uigetpref('scgeatoolbox', ... % Group
'cdgea_ask', ... % Preference
'Changing Working Directory', ... % Window title
{'Do you want to change current working directory to scGEApp directory?'}, ...
{'always', 'never'; 'Yes', 'No'}, ... % Values and button strings
'ExtraOptions', 'Cancel', ... % Additional button
'DefaultButton', 'Yes');
switch selectedButton
case {'always', 'Yes'}
cd(pw1); % Change directory to scGEAToolbox folder
case {'never', 'No', 'Cancel'}
% Do nothing
end
else
cd(pw1); % Automatically change directory without confirmation
end
% Only run the following if not compiled or deployed
if ~(ismcc || isdeployed)
% Check if required directories exist, else download them
if ~exist(fullfile(pw1, 'example_data/'), 'dir') || ...
~exist(fullfile(pw1, 'resources/'), 'dir') || ...
~exist(fullfile(pw1, '+run', 'external/'), 'dir')
f = waitbar(0.33, 'Initializing SCGEATOOL on the first run...');
% Download example_data if missing
if ~exist(fullfile(pw1, 'example_data/'), 'dir')
try
unzip('https://github.com/jamesjcai/jamesjcai.github.io/raw/master/data/example_data.zip');
catch ME
warndlg(ME.message);
warning(ME.message);
end
end
waitbar(0.66, f, 'Initializing SCGEATOOL on the first run...');
% Download resources if missing
if ~exist(fullfile(pw1, 'resources/'), 'dir')
try
unzip('https://github.com/jamesjcai/jamesjcai.github.io/raw/master/data/resources.zip');
catch ME
warndlg(ME.message);
warning(ME.message);
end
end
waitbar(0.85, f, 'Initializing SCGEATOOL on the first run...');
% Download external tools if missing
if ~exist(fullfile(pw1, '+run', 'external/'), 'dir')
try
a = unzip('https://github.com/jamesjcai/jamesjcai.github.io/raw/master/data/external.zip');
catch ME
warndlg(ME.message);
warning(ME.message);
end
if ~iscell(a)
errordlg('SCGEATOOL could not download the supporting file.\nPlease check network connection and try again.');
return;
end
try
movefile(fullfile(pw1, 'external/'), fullfile(pw1, '+run', 'external/'));
catch ME
warndlg(ME.message);
warning(ME.message);
end
end
pause(0.5);
waitbar(1, f, 'Finishing');
pause(1);
if isvalid(f)
close(f); % Close waitbar when finished
end
end
end
end