From: Konrad Rosenbaum Date: Sun, 10 Mar 2013 15:42:16 +0000 (+0100) Subject: make storage dirs configurable X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=56a0d5c6f66555b3ea9ac2a2106376b5ce97b7ac;p=web%2Fkonrad%2Fsmoke.git make storage dirs configurable --- diff --git a/src/main.cpp b/src/main.cpp index 5d87374..9a14b2a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,6 +11,7 @@ // #include +#include #include #include #include @@ -71,16 +72,37 @@ static QString dataDir; #include -static inline void initDataDir() -{ #ifdef Q_OS_WIN32 - dataDir=getenv("APPDATA"); +#define BASEDIRVAR "APPDATA" #else - dataDir=getenv("HOME"); +#define BASEDIRVAR "HOME" #endif - if(dataDir=="") - qFatal("Cannot determine application data directory."); - dataDir+="/.magicSmoke2"; + +static inline QString resolveDir(const QString &dirspec) +{ + //resolve pattern + const QStringList dirspecl=dirspec.split('/',QString::KeepEmptyParts); + bool notfirst=false; + QString rdir; + for(QString dcom:dirspecl){ + if(dcom=="$BASE"){ + dcom=getenv(BASEDIRVAR); + if(dcom.isEmpty()) + qFatal("Cannot determine base application data directory. While resolving %s",dirspec.toLatin1().data()); + }else if(dcom=="$APP") + dcom=qApp->applicationDirPath(); + else if(dcom.startsWith("$")) + dcom=getenv(dcom.mid(1).toLatin1().data()); + //append component + if(notfirst)rdir+="/"; + else notfirst=true; + rdir+=dcom; + } + //make sure it exists + if(!QDir::current().mkpath(rdir)) + qFatal("Unable to create path '%s' for spec '%s'.",rdir.toLatin1().data(),dirspec.toLatin1().data()); + //return it + return rdir; } #define HOMEPAGE_BASEURL "http://smoke.silmor.de" @@ -234,14 +256,35 @@ MApplication::MApplication(int&ac,char**av) //install event filter for random generator installEventFilter(ef=new EFilter); + //check parameters + qDebug()<<"arguments"<(qApp)) #endif