-rw-r--r-- | noncore/settings/aqpkg/datamgr.cpp | 16 |
1 files changed, 0 insertions, 16 deletions
diff --git a/noncore/settings/aqpkg/datamgr.cpp b/noncore/settings/aqpkg/datamgr.cpp index b6e6e37..bb86766 100644 --- a/noncore/settings/aqpkg/datamgr.cpp +++ b/noncore/settings/aqpkg/datamgr.cpp | |||
@@ -1,239 +1,223 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | datamgr.cpp - description | 2 | datamgr.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Thu Aug 29 2002 | 4 | begin : Thu Aug 29 2002 |
5 | copyright : (C) 2002 by Andy Qua | 5 | copyright : (C) 2002 by Andy Qua |
6 | email : andy.qua@blueyonder.co.uk | 6 | email : andy.qua@blueyonder.co.uk |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * | 13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * (at your option) any later version. * | 14 | * (at your option) any later version. * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | #include <fstream> | 17 | #include <fstream> |
18 | #include <iostream> | 18 | #include <iostream> |
19 | using namespace std; | 19 | using namespace std; |
20 | 20 | ||
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | 22 | ||
23 | #include "datamgr.h" | 23 | #include "datamgr.h" |
24 | #include "global.h" | 24 | #include "global.h" |
25 | 25 | ||
26 | 26 | ||
27 | DataManager::DataManager() | 27 | DataManager::DataManager() |
28 | { | 28 | { |
29 | activeServer = ""; | 29 | activeServer = ""; |
30 | } | 30 | } |
31 | 31 | ||
32 | DataManager::~DataManager() | 32 | DataManager::~DataManager() |
33 | { | 33 | { |
34 | } | 34 | } |
35 | 35 | ||
36 | Server *DataManager :: getServer( const char *name ) | 36 | Server *DataManager :: getServer( const char *name ) |
37 | { | 37 | { |
38 | Server *s = 0; | 38 | Server *s = 0; |
39 | vector<Server>::iterator it = serverList.begin(); | 39 | vector<Server>::iterator it = serverList.begin(); |
40 | while ( it != serverList.end() && s == 0 ) | 40 | while ( it != serverList.end() && s == 0 ) |
41 | { | 41 | { |
42 | if ( it->getServerName() == name ) | 42 | if ( it->getServerName() == name ) |
43 | s = &(*it); | 43 | s = &(*it); |
44 | 44 | ||
45 | ++it; | 45 | ++it; |
46 | } | 46 | } |
47 | 47 | ||
48 | return s; | 48 | return s; |
49 | } | 49 | } |
50 | 50 | ||
51 | Destination *DataManager :: getDestination( const char *name ) | 51 | Destination *DataManager :: getDestination( const char *name ) |
52 | { | 52 | { |
53 | Destination *d = 0; | 53 | Destination *d = 0; |
54 | vector<Destination>::iterator it = destList.begin(); | 54 | vector<Destination>::iterator it = destList.begin(); |
55 | while ( it != destList.end() && d == 0 ) | 55 | while ( it != destList.end() && d == 0 ) |
56 | { | 56 | { |
57 | if ( it->getDestinationName() == name ) | 57 | if ( it->getDestinationName() == name ) |
58 | d = &(*it); | 58 | d = &(*it); |
59 | 59 | ||
60 | ++it; | 60 | ++it; |
61 | } | 61 | } |
62 | 62 | ||
63 | return d; | 63 | return d; |
64 | } | 64 | } |
65 | 65 | ||
66 | void DataManager :: loadServers() | 66 | void DataManager :: loadServers() |
67 | { | 67 | { |
68 | // First add our local server - not really a server but | 68 | // First add our local server - not really a server but |
69 | // the local config (which packages are installed) | 69 | // the local config (which packages are installed) |
70 | serverList.push_back( Server( LOCAL_SERVER, "" ) ); | 70 | serverList.push_back( Server( LOCAL_SERVER, "" ) ); |
71 | serverList.push_back( Server( LOCAL_IPKGS, "" ) ); | 71 | serverList.push_back( Server( LOCAL_IPKGS, "" ) ); |
72 | 72 | ||
73 | // Read file from /etc/ipkg.conf | 73 | // Read file from /etc/ipkg.conf |
74 | QString ipkg_conf = IPKG_CONF; | 74 | QString ipkg_conf = IPKG_CONF; |
75 | FILE *fp; | 75 | FILE *fp; |
76 | fp = fopen( ipkg_conf, "r" ); | 76 | fp = fopen( ipkg_conf, "r" ); |
77 | char line[130]; | 77 | char line[130]; |
78 | QString lineStr; | 78 | QString lineStr; |
79 | if ( fp == NULL ) | 79 | if ( fp == NULL ) |
80 | { | 80 | { |
81 | cout << "Couldn't open " << ipkg_conf << "! err = " << fp << endl; | 81 | cout << "Couldn't open " << ipkg_conf << "! err = " << fp << endl; |
82 | return; | 82 | return; |
83 | } | 83 | } |
84 | else | 84 | else |
85 | { | 85 | { |
86 | { | ||
87 | cout << "Before ipkg.conf read" << endl; | ||
88 | vector<Server>::iterator it; | ||
89 | for ( it = serverList.begin() ; it != serverList.end() ; ++it ) | ||
90 | cout << "servername - " << it->getServerName() << endl; | ||
91 | } | ||
92 | |||
93 | while ( fgets( line, sizeof line, fp) != NULL ) | 86 | while ( fgets( line, sizeof line, fp) != NULL ) |
94 | { | 87 | { |
95 | lineStr = line; | 88 | lineStr = line; |
96 | if ( lineStr.startsWith( "src" ) || lineStr.startsWith( "#src" ) || lineStr.startsWith( "# src" ) ) | 89 | if ( lineStr.startsWith( "src" ) || lineStr.startsWith( "#src" ) || lineStr.startsWith( "# src" ) ) |
97 | { | 90 | { |
98 | char alias[20]; | 91 | char alias[20]; |
99 | char url[100]; | 92 | char url[100]; |
100 | 93 | ||
101 | 94 | ||
102 | // Looks a little wierd but read up to the r of src (throwing it away), | 95 | // Looks a little wierd but read up to the r of src (throwing it away), |
103 | // then read up to the next space and throw that away, the alias | 96 | // then read up to the next space and throw that away, the alias |
104 | // is next. | 97 | // is next. |
105 | // Should Handle #src, # src, src, and combinations of | 98 | // Should Handle #src, # src, src, and combinations of |
106 | sscanf( lineStr, "%*[^r]%*[^ ] %s %s", alias, url ); | 99 | sscanf( lineStr, "%*[^r]%*[^ ] %s %s", alias, url ); |
107 | cout << "Adding alias " << alias << " to list" << endl; | ||
108 | cout << lineStr << endl; | ||
109 | Server s( alias, url ); | 100 | Server s( alias, url ); |
110 | serverList.push_back( s ); | 101 | serverList.push_back( s ); |
111 | 102 | ||
112 | if ( lineStr.startsWith( "src" ) ) | 103 | if ( lineStr.startsWith( "src" ) ) |
113 | setActiveServer( alias ); | 104 | setActiveServer( alias ); |
114 | } | 105 | } |
115 | else if ( lineStr.startsWith( "dest" ) ) | 106 | else if ( lineStr.startsWith( "dest" ) ) |
116 | { | 107 | { |
117 | char alias[20]; | 108 | char alias[20]; |
118 | char path[50]; | 109 | char path[50]; |
119 | sscanf( lineStr, "%*[^ ] %s %s", alias, path ); | 110 | sscanf( lineStr, "%*[^ ] %s %s", alias, path ); |
120 | Destination d( alias, path ); | 111 | Destination d( alias, path ); |
121 | destList.push_back( d ); | 112 | destList.push_back( d ); |
122 | } | 113 | } |
123 | } | 114 | } |
124 | { | ||
125 | cout << "After ipkg.conf read" << endl; | ||
126 | vector<Server>::iterator it; | ||
127 | for ( it = serverList.begin() ; it != serverList.end() ; ++it ) | ||
128 | cout << "servername - " << it->getServerName() << endl; | ||
129 | } | ||
130 | |||
131 | } | 115 | } |
132 | fclose( fp ); | 116 | fclose( fp ); |
133 | 117 | ||
134 | // Go through the server destination list and add root, cf and card if they | 118 | // Go through the server destination list and add root, cf and card if they |
135 | // don't already exist | 119 | // don't already exist |
136 | /* AQ - commented out as if you don't have a CF or SD card in then | 120 | /* AQ - commented out as if you don't have a CF or SD card in then |
137 | * this causes IPKG to try to create directories on non existant devices | 121 | * this causes IPKG to try to create directories on non existant devices |
138 | * (which of course fails), gives a nasty error message and can cause ipkg | 122 | * (which of course fails), gives a nasty error message and can cause ipkg |
139 | * to seg fault. | 123 | * to seg fault. |
140 | * | 124 | * |
141 | vector<Destination>::iterator dit; | 125 | vector<Destination>::iterator dit; |
142 | bool foundRoot = false; | 126 | bool foundRoot = false; |
143 | bool foundCF = false; | 127 | bool foundCF = false; |
144 | bool foundCard = false; | 128 | bool foundCard = false; |
145 | for ( dit = destList.begin() ; dit != destList.end() ; ++dit ) | 129 | for ( dit = destList.begin() ; dit != destList.end() ; ++dit ) |
146 | { | 130 | { |
147 | if ( dit->getDestinationPath() == "/" ) | 131 | if ( dit->getDestinationPath() == "/" ) |
148 | foundRoot = true; | 132 | foundRoot = true; |
149 | if ( dit->getDestinationPath() == "/mnt/cf" ) | 133 | if ( dit->getDestinationPath() == "/mnt/cf" ) |
150 | foundCF = true; | 134 | foundCF = true; |
151 | if ( dit->getDestinationPath() == "/mnt/card" ) | 135 | if ( dit->getDestinationPath() == "/mnt/card" ) |
152 | foundCard = true; | 136 | foundCard = true; |
153 | } | 137 | } |
154 | 138 | ||
155 | // If running on a Zaurus (arm) then if we didn't find root, CF or card | 139 | // If running on a Zaurus (arm) then if we didn't find root, CF or card |
156 | // destinations, add them as default | 140 | // destinations, add them as default |
157 | #ifdef QWS | 141 | #ifdef QWS |
158 | #ifndef X86 | 142 | #ifndef X86 |
159 | if ( !foundRoot ) | 143 | if ( !foundRoot ) |
160 | destList.push_back( Destination( "root", "/" ) ); | 144 | destList.push_back( Destination( "root", "/" ) ); |
161 | if ( !foundCF ) | 145 | if ( !foundCF ) |
162 | destList.push_back( Destination( "cf", "/mnt/cf" ) ); | 146 | destList.push_back( Destination( "cf", "/mnt/cf" ) ); |
163 | if ( !foundCF ) | 147 | if ( !foundCF ) |
164 | destList.push_back( Destination( "card", "/mnt/card" ) ); | 148 | destList.push_back( Destination( "card", "/mnt/card" ) ); |
165 | #endif | 149 | #endif |
166 | #endif | 150 | #endif |
167 | */ | 151 | */ |
168 | vector<Server>::iterator it; | 152 | vector<Server>::iterator it; |
169 | for ( it = serverList.begin() ; it != serverList.end() ; ++it ) | 153 | for ( it = serverList.begin() ; it != serverList.end() ; ++it ) |
170 | reloadServerData( it->getServerName() ); | 154 | reloadServerData( it->getServerName() ); |
171 | } | 155 | } |
172 | 156 | ||
173 | void DataManager :: reloadServerData( const char *serverName ) | 157 | void DataManager :: reloadServerData( const char *serverName ) |
174 | { | 158 | { |
175 | Server *s = getServer( serverName ); | 159 | Server *s = getServer( serverName ); |
176 | // Now we've read the config file in we need to read the servers | 160 | // Now we've read the config file in we need to read the servers |
177 | // The local server is a special case. This holds the contents of the | 161 | // The local server is a special case. This holds the contents of the |
178 | // status files the number of which depends on how many destinations | 162 | // status files the number of which depends on how many destinations |
179 | // we've set up | 163 | // we've set up |
180 | // The other servers files hold the contents of the server package list | 164 | // The other servers files hold the contents of the server package list |
181 | if ( s->getServerName() == LOCAL_SERVER ) | 165 | if ( s->getServerName() == LOCAL_SERVER ) |
182 | s->readStatusFile( destList ); | 166 | s->readStatusFile( destList ); |
183 | else if ( s->getServerName() == LOCAL_IPKGS ) | 167 | else if ( s->getServerName() == LOCAL_IPKGS ) |
184 | s->readLocalIpks( getServer( LOCAL_SERVER ) ); | 168 | s->readLocalIpks( getServer( LOCAL_SERVER ) ); |
185 | else | 169 | else |
186 | s->readPackageFile( getServer( LOCAL_SERVER ) ); | 170 | s->readPackageFile( getServer( LOCAL_SERVER ) ); |
187 | 171 | ||
188 | } | 172 | } |
189 | 173 | ||
190 | void DataManager :: writeOutIpkgConf() | 174 | void DataManager :: writeOutIpkgConf() |
191 | { | 175 | { |
192 | QString ipkg_conf = IPKG_CONF; | 176 | QString ipkg_conf = IPKG_CONF; |
193 | ofstream out( ipkg_conf ); | 177 | ofstream out( ipkg_conf ); |
194 | 178 | ||
195 | out << "# Written by AQPkg" << endl; | 179 | out << "# Written by AQPkg" << endl; |
196 | out << "# Must have one or more source entries of the form:" << endl; | 180 | out << "# Must have one or more source entries of the form:" << endl; |
197 | out << "#" << endl; | 181 | out << "#" << endl; |
198 | out << "# src <src-name> <source-url>" << endl; | 182 | out << "# src <src-name> <source-url>" << endl; |
199 | out << "#" << endl; | 183 | out << "#" << endl; |
200 | out << "# and one or more destination entries of the form:" << endl; | 184 | out << "# and one or more destination entries of the form:" << endl; |
201 | out << "#" << endl; | 185 | out << "#" << endl; |
202 | out << "# dest <dest-name> <target-path>" << endl; | 186 | out << "# dest <dest-name> <target-path>" << endl; |
203 | out << "#" << endl; | 187 | out << "#" << endl; |
204 | out << "# where <src-name> and <dest-names> are identifiers that" << endl; | 188 | out << "# where <src-name> and <dest-names> are identifiers that" << endl; |
205 | out << "# should match [a-zA-Z0-9._-]+, <source-url> should be a" << endl; | 189 | out << "# should match [a-zA-Z0-9._-]+, <source-url> should be a" << endl; |
206 | out << "# URL that points to a directory containing a Familiar" << endl; | 190 | out << "# URL that points to a directory containing a Familiar" << endl; |
207 | out << "# Packages file, and <target-path> should be a directory" << endl; | 191 | out << "# Packages file, and <target-path> should be a directory" << endl; |
208 | out << "# that exists on the target system." << endl << endl; | 192 | out << "# that exists on the target system." << endl << endl; |
209 | 193 | ||
210 | // Write out servers | 194 | // Write out servers |
211 | vector<Server>::iterator it = serverList.begin(); | 195 | vector<Server>::iterator it = serverList.begin(); |
212 | while ( it != serverList.end() ) | 196 | while ( it != serverList.end() ) |
213 | { | 197 | { |
214 | QString alias = it->getServerName(); | 198 | QString alias = it->getServerName(); |
215 | // Don't write out local as its a dummy | 199 | // Don't write out local as its a dummy |
216 | if ( alias != LOCAL_SERVER && alias != LOCAL_IPKGS ) | 200 | if ( alias != LOCAL_SERVER && alias != LOCAL_IPKGS ) |
217 | { | 201 | { |
218 | QString url = it->getServerUrl();; | 202 | QString url = it->getServerUrl();; |
219 | 203 | ||
220 | if ( !activeServer || alias != activeServer ) | 204 | if ( !activeServer || alias != activeServer ) |
221 | out << "#"; | 205 | out << "#"; |
222 | out << "src " << alias << " " << url << endl; | 206 | out << "src " << alias << " " << url << endl; |
223 | } | 207 | } |
224 | 208 | ||
225 | it++; | 209 | it++; |
226 | } | 210 | } |
227 | 211 | ||
228 | out << endl; | 212 | out << endl; |
229 | 213 | ||
230 | // Write out destinations | 214 | // Write out destinations |
231 | vector<Destination>::iterator it2 = destList.begin(); | 215 | vector<Destination>::iterator it2 = destList.begin(); |
232 | while ( it2 != destList.end() ) | 216 | while ( it2 != destList.end() ) |
233 | { | 217 | { |
234 | out << "dest " << it2->getDestinationName() << " " << it2->getDestinationPath() << endl; | 218 | out << "dest " << it2->getDestinationName() << " " << it2->getDestinationPath() << endl; |
235 | it2++; | 219 | it2++; |
236 | } | 220 | } |
237 | 221 | ||
238 | out.close(); | 222 | out.close(); |
239 | } | 223 | } |