Newer
Older
function tsg_preferences(hTsgGUI, app_name)
% tsg_preferences(S1,S2) returns structure tsg saved in S1.mat file
% and with S2 internal version number.
% If S1.mat dosn't exist, call tsg_initialisation to create it in
% prefdir directory
%
% Input
% -----
% hTsgGUI ............ Handle to the main user interface
% app_name ............ application name
%
% Output
% ------
% none
%
% $Id$
%
global VERSION
% init empty tsg structure
% ------------------------
tsg = [];
% Construct config file path
% --------------------------
config_file = [prefdir, filesep, app_name, '.mat'];
% Open config file
% ----------------
%config = fopen( config_file, 'r' );
config = -1;
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
98
99
100
101
102
103
104
105
106
% test fopen return value
% -----------------------
if config == -1
% config file dosn't exist, call default tsg_initialisation
% ---------------------------------------------------------
tsg = tsg_initialisation;
% ccall new config private function
% ---------------------------------
new_config;
else
% file exist, load in workspace
% -----------------------------
try
load( config_file, 'root', 'tsg' );
% set current preference autoload in submenu option/preference
% ------------------------------------------------------------
set(findobj('tag', 'TAG_UIMENU_OPTION_PREFERENCES', ...
'checked', root.preference.autoload));
catch
warning('tsgqc_GUI:tsg_preferences', ['Can''t load' config_file]);
%datagui_closereq_callback;
end
% If there no field version or wrong version, initialize
% -------------------------------------------------------
if ~isfield( root, 'version') || ~strcmp(root.version, VERSION)
% call new config private function
% --------------------------------
new_config;
end
end
% Save structure tsg
% ------------------
setappdata( hTsgGUI, 'tsg_data', tsg);
% cas d'erreur si l'utilisation change de disque (cle USB -> disque dur
% par ex, self.path ne sera pas a jour et la lecture fichier genere une
% erreur
% if ~exist( root.path, 'dir' )
% root.path = [pwd filesep];
% end
% ----------------------------------------------------------------------
% private function new_config
% ----------------------------------------------------------------------
function new_config
% init root structure to default values
% -------------------------------------
root.preference.autoload = 'off';
root.version = VERSION;
% save root and tsg to prefdir mat file
% -------------------------------------
save(config_file, 'root', 'tsg');
% save root in root object for next use
% -------------------------------------
set(0, 'userdata', root);
end
end