29 #include "arcspackagemanager.h"
30 #include "arcsdownloader.h"
35 #include <QTextStream>
39 #include <QDomDocument>
44 ARCSPackageManager::ARCSPackageManager()
47 hS[
"repositoryPath"]=
"";
48 hS[
"repositoryUrl"]=
"";
49 hS[
"repositoryFile"]=
"";
51 hS[
"archiveExtension"]=
"";
52 hS[
"compressCommand"]=
"";
53 hS[
"unCompressCommand"]=
"";
56 ARCSPackageManager::~ARCSPackageManager()
61 bool ARCSPackageManager::checkSettings()
63 fetchSetting(
"repositoryPath");
64 fetchSetting(
"repositoryUrl");
65 fetchSetting(
"repositoryFile",
"REPOSITORY");
66 fetchSetting(
"archiveExtension",
".zip");
67 fetchSetting(
"compressCommand",
"zip -r %a %p");
68 fetchSetting(
"unCompressCommand",
"unzip -o %a");
69 if (!settings.contains(
"pkg/sourcePath"))
71 char* buildpath = getenv(
"ARCSBUILDPATH");
74 std::cerr <<
"You must define a ARCSBUILPATH environment variable" << std::endl;
77 hS[
"sourcePath"] = buildpath;
81 fetchSetting(
"sourcePath");
87 void ARCSPackageManager::displaySettings()
89 std::cout <<
"Current settings" << std::endl;
90 QHashIterator<QString,QString> i(hS);
94 displaySetting(i.key());
99 void ARCSPackageManager::storeSettings()
101 QHashIterator<QString,QString> i(hS);
105 storeSetting(i.key());
113 QFile data(hS[
"sourcePath"] + QDir::separator() + hS[
"repositoryFile"]);
114 parseRepositoryFile(data);
117 data.copy(hS[
"repositoryPath"] + QDir::separator() + hS[
"repositoryFile"]);
119 QDir::setCurrent(hS[
"sourcePath"]);
121 for (
int i=0; i < libs.count() ; i++)
124 if (QFileInfo(libPaths[i]).exists())
126 QString command = hS[
"compressCommand"];
127 command.replace(
"%a",hS[
"repositoryPath"]+QDir::separator()+libs[i]+hS[
"archiveExtension"])
128 .replace(
"%p",libPaths[i]);
129 std::cout <<
"Performing command: " << qPrintable(command) << std::endl;
130 QProcess::execute(command);
132 QStringList relatedFiles = getRelatedFiles(hS[
"sourcePath"]+QDir::separator()+libPaths[i]);
133 for (
int j=0; j < relatedFiles.count(); j++)
135 if (QFileInfo(relatedFiles[j]).exists())
137 QString command = hS[
"compressCommand"];
138 command.replace(
"%a",hS[
"repositoryPath"]+QDir::separator()+libs[i]+hS[
"archiveExtension"])
139 .replace(
"%p",relatedFiles[j]);
140 std::cout <<
"Performing command: " << qPrintable(command) << std::endl;
141 QProcess::execute(command);
146 std::cerr <<
"Library '" << qPrintable(libs[i]) <<
"': path '"
147 << qPrintable(libPaths[i]) <<
"' does not exist." << std::endl;
151 void ARCSPackageManager::installAll()
153 QDir::setCurrent(hS[
"sourcePath"]);
154 ad->download(hS[
"repositoryUrl"]+
"/"+hS[
"repositoryFile"]);
156 if (!QFile::exists(hS[
"repositoryFile"]))
159 QFile data(hS[
"repositoryFile"]);
160 parseRepositoryFile(data);
162 for (
int i=0; i< libs.length(); i++)
164 installLibrary(libs[i]);
170 void ARCSPackageManager::installLibrary(QString libraryName)
172 QDir::setCurrent(hS[
"sourcePath"]);
173 QString fullName = libraryName+hS[
"archiveExtension"];
174 ad->download(hS[
"repositoryUrl"]+
"/"+fullName);
176 if(QFile::exists(fullName))
178 QString command = hS[
"unCompressCommand"];
179 command.replace(
"%a",fullName);
180 if(!QProcess::execute(command))
181 QFile::remove(fullName);
184 std::cerr <<
"Failed to perform command: " << qPrintable(command) << std::endl;
191 void ARCSPackageManager::parseRepositoryFile(QFile& data )
196 if (!data.open(QFile::ReadOnly))
198 std::cerr <<
"Failed to open repository file: "
199 << qPrintable(hS[
"sourcePath"] + QDir::separator() + hS[
"repositoryFile"]) << std::endl;
203 std::cout <<
"Parsing repository file: "
204 << qPrintable(hS[
"repositoryFile"]) << std::endl;
206 QTextStream repos(&data);
210 line = repos.readLine();
211 QStringList sl=line.split(
';');
213 if (sl.count() >= 2 && !sl[0].startsWith(
"#"))
215 std::cout <<
"Registering library " << qPrintable(sl[0]) << std::endl;
219 }
while(!line.isNull());
223 QStringList ARCSPackageManager::getRelatedFiles(QString libraryPath)
225 QDir dir(libraryPath);
227 return QStringList();
229 QStringList alxFiles = dir.entryList(QStringList(QString(
"*.alx")),QDir::Files);
232 for (
int i=0; i<alxFiles.count() ; i++)
235 QFile alxFile(dir.absolutePath()+QDir::separator()+alxFiles[i]);
236 if (alxFile.open(QIODevice::ReadOnly))
238 if (doc.setContent(&alxFile))
240 QDomElement root = doc.documentElement();
241 QDomNodeList dnl = root.elementsByTagName(
"related");
243 for (
int j=0; j< dnl.count(); j++)
245 QDomElement elt = dnl.at(j).toElement();
246 QString s = elt.attribute(
"path");