- installed packages and dependencies are now saved into binary files
[scilab.git] / scilab / modules / atoms / macros / atoms_internals / atomsSaveInstalled.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
3 //
4 // This file must be used under the terms of the CeCILL.
5 // This source file is licensed as described in the file COPYING, which
6 // you should have received as part of this distribution.  The terms
7 // are also available at
8 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
9
10 // Internal function
11
12 function  atomsSaveInstalled(installed_struct,allusers)
13         
14         rhs = argn(2);
15         
16         // Check number of input arguments
17         // =========================================================================
18         
19         if rhs <> 2 then
20                 error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"),"atomsSaveInstalled",2));
21         end
22         
23         // Check type of input argument type
24         // =========================================================================
25         
26         if type(installed_struct) <> 17 then
27                 error(msprintf(gettext("%s: Wrong type for input argument #%d: A struct expected.\n"),"atomsSaveInstalled",1));
28         end
29         
30         if type(allusers) <> 4 then
31                 error(msprintf(gettext("%s: Wrong type for input argument #%d: A boolean expected.\n"),"atomsSaveInstalled",2));
32         end
33         
34         // Define the path of the file that will record the change according to
35         // the "allusers" value
36         // =========================================================================
37         
38         if allusers then
39                 atoms_directory = pathconvert(SCI+"/.atoms");
40         else
41                 atoms_directory = pathconvert(SCIHOME+"/atoms");
42         end
43         
44         // Does the atoms_directory exist, if not create it
45         // =========================================================================
46         
47         if ~ isdir(atoms_directory) then
48                 mkdir(atoms_directory);
49         end
50         
51         // Define the path of the file that will record the change according 
52         // =========================================================================
53         installed_txt = atoms_directory+"installed.txt";
54         installed_bin = atoms_directory+"installed.bin";
55         
56         // Build the installed_mat and the installed_str
57         // =========================================================================
58         
59         installed_mat = [];
60         installed_str = [];
61         
62         packages      = getfield(1,installed_struct);
63         packages(1:2) = [];
64         
65         for i=1:size(packages,"*")
66                 
67                 this_package_details  = installed_struct(packages(i));
68                 
69                 this_package_name     = this_package_details(1);
70                 this_package_version  = this_package_details(2);
71                 this_package_path     = this_package_details(3);
72                 this_package_allusers = this_package_details(4);
73                 this_package_status   = this_package_details(5);
74                 
75                 installed_mat = [ installed_mat ; this_package_name this_package_version this_package_allusers this_package_path this_package_status];
76                 installed_str = [ installed_str ; "[ "+this_package_name+" - "+this_package_version+" - "+this_package_allusers+" - "+this_package_path+" - "+this_package_status+" ]" ];
77                 
78         end
79         
80         // If packages is empty, no need to keep the files
81         // =========================================================================
82         
83         if isempty(packages) then
84                 mdelete(installed_txt);
85                 mdelete(installed_bin);
86                 return;
87         end
88         
89         // write files
90         // =========================================================================
91         
92         mputl( installed_str , installed_txt);
93         save( installed_bin , installed_struct , installed_mat );
94         
95 endfunction