1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
3 // Copyright (C) 2012 - DIGITEO - Allan CORNET
5 // This file must be used under the terms of the CeCILL.
6 // This source file is licensed as described in the file COPYING, which
7 // you should have received as part of this distribution. The terms
8 // are also available at
9 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
13 // Add toolboxes to the list of packages that are automatically loaded at Scilab start
14 // This function has an impact on the following files :
17 function nbChanges = atomsSetConfig(field, value)
21 systemUpdateNeeded = %F;
23 // Check number of input arguments
24 // =========================================================================
27 error(msprintf(gettext("%s: Wrong number of input argument: %d expected.\n"), "atomsSetConfig", 2));
30 // Check input parameters type
31 // =========================================================================
33 if type(field) <> 10 then
34 error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"), "atomsSetConfig", 1));
37 if type(value) <> 10 then
38 error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"), "atomsSetConfig", 2));
41 // field and value must have the same size
42 // =========================================================================
44 if or( size(field) <> size(value) ) then
45 error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n"), "atomsSetConfig", 1, 2));
48 for element = field(:)
49 if strcmpi("verbose",element) == 0 then
50 field(i) = convstr(part(element,1),"u") + part(element,2:length(element));
52 field(i) = convstr(part(element,1),"l") + part(element,2:length(element));
56 if element == "offLine" then
57 // Prior to version 5.4.0, offline was called Offline
62 if element == "useProxy" ..
63 | element == "offline" ..
64 | element == "autoload" ..
65 | element == "autoloadAddAfterInstall" ..
66 | element == "Verbose" ..
71 case "true" then value(i)="True",
72 case "false" then value(i)="False",
74 error(msprintf(gettext("%s: Wrong value for input configuration argument: True or False expected.\n"), value(i)));
76 elseif element == "proxyHost" ..
77 | element == "proxyPort" ..
78 | element == "proxyUser" ..
79 | element == "proxyPassword" ..
80 | element == "downloadTool" ..
81 | element == "downloadTimeout" ..
82 | element == "updateTime" ..
85 error(msprintf(gettext("%s: Wrong key for input configuration argument.\n"), element));
90 // Load Atoms Internals lib if it's not already loaded
91 // =========================================================================
92 if ~ exists("atomsinternalslib") then
93 load("SCI/modules/atoms/macros/atoms_internals/lib");
96 // Define the path of the file that will record the change
97 // =========================================================================
98 atoms_directory = atomsPath("system", "user");
100 // Does the atoms_directory exist, if not create it
101 // =========================================================================
103 if ~ isdir(atoms_directory) then
104 mkdir(atoms_directory);
107 // Get the current config struct
108 // =========================================================================
110 config_struct = atomsGetConfig();
113 // =========================================================================
115 for i=1:size(field, "*")
117 if (~isfield(config_struct, field(i))) | (config_struct(field(i)) <> value(i)) then
118 nbChanges = nbChanges + 1;
123 if field(i) == "offline" then
124 systemUpdateNeeded = %T;
127 config_struct(field(i)) = value(i);
131 // =========================================================================
132 if nbChanges == 0 then
137 // =========================================================================
139 config_fields = getfield(1, config_struct);
140 config_fields(1:2) = [];
141 config_fields = gsort(config_fields);
145 for i=1:size(config_fields, "*")
146 config_str = [ config_str ; config_fields(i) + " = " + config_struct(config_fields(i)) ];
149 mputl(config_str, atoms_directory + "config");
152 // =========================================================================
154 if systemUpdateNeeded then