PageRenderTime 52ms CodeModel.GetById 18ms app.highlight 29ms RepoModel.GetById 1ms app.codeStats 0ms

/src/q4wine-helper/q4wine-helper.cpp

https://github.com/brezerk/q4wine
C++ | 176 lines | 140 code | 16 blank | 20 comment | 47 complexity | 940b0124e0e2b83fe8a16f268a750fc3 MD5 | raw file
  1/***************************************************************************
  2 *   Copyright (C) 2008-2017 by Oleksii S. Malakhov <brezerk@gmail.com>    *
  3 *                                                                         *
  4 *   This program is free software: you can redistribute it and/or modify  *
  5 *   it under the terms of the GNU General Public License as published by  *
  6 *   the Free Software Foundation, either version 3 of the License, or     *
  7 *   (at your option) any later version.                                   *
  8 *                                                                         *
  9 *   This program is distributed in the hope that it will be useful,       *
 10 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 11 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 12 *   GNU General Public License for more details.                          *
 13 *                                                                         *
 14 *   You should have received a copy of the GNU General Public License     *
 15 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 16 *                                                                         *
 17 ***************************************************************************/
 18
 19#include "q4wine-helper.h"
 20
 21int main(int argc, char *argv[])
 22{
 23    QCoreApplication app(argc, argv);
 24    QTextStream QErr(stderr);
 25
 26     //! This is need for libq4wine-core.so import;
 27    typedef void *CoreLibPrototype (bool);
 28    CoreLibPrototype *CoreLibClassPointer;
 29    std::unique_ptr<corelib> CoreLib;
 30    QLibrary libq4wine;
 31
 32    // Loading libq4wine-core.so
 33#ifdef RELEASE
 34    libq4wine.setFileName(_CORELIB_PATH_);
 35#else
 36    libq4wine.setFileName(QString("%1/q4wine-lib/libq4wine-core").arg(QString::fromUtf8(APP_BUILD)));
 37#endif
 38
 39    if (!libq4wine.load()){
 40        libq4wine.load();
 41    }
 42
 43    // Getting corelib calss pointer
 44    CoreLibClassPointer = (CoreLibPrototype *) libq4wine.resolve("createCoreLib");
 45    CoreLib.reset(static_cast<corelib *>(CoreLibClassPointer(false)));
 46
 47    if (!CoreLib.get()){
 48        QErr<<"[EE] Cannot load shared library."<<endl;
 49        return -1;
 50    }
 51
 52    DataBase db;
 53    if (!db.checkDb()){
 54        QErr<<"[EE] Cannot initialize database engine."<<endl;
 55        return -1;
 56    }
 57
 58    QTranslator qtt;
 59
 60#ifdef RELEASE
 61    #ifdef _OS_DARWIN_
 62        QString l10nPath = QString("%1/%2.app/Contents/l10n").arg(QDir::currentPath()).arg(APP_SHORT_NAME);
 63    #else
 64        QString l10nPath = QString("%1/share/%2/l10n").arg(QString::fromUtf8(APP_PREF)).arg(APP_SHORT_NAME);
 65    #endif
 66#else
 67    QString l10nPath = QString("%1/l10n").arg(QString::fromUtf8(APP_BUILD));
 68#endif
 69
 70    qtt.load(CoreLib->getTranslationLang(), l10nPath);
 71    app.installTranslator(&qtt);
 72
 73    if (!CoreLib->isConfigured()){
 74       QErr<<"[EE] App is not configured! Rerun wizard, or delete Q4Wine broken config files."<<endl;
 75       return -1;
 76    }
 77
 78    QTextStream Qcout(stdout);
 79    WineObject wineObject;
 80
 81    if (argc==1){
 82        app.arguments().append("-h");
 83        argc++;
 84    }
 85
 86    for (int i=1; i<argc; i++){
 87        qDebug()<<app.arguments().at(i);
 88        if ((app.arguments().at(1)=="--version") or (app.arguments().at(1)=="-v")){
 89            Qcout<<QString("%1-helper %2").arg(APP_SHORT_NAME).arg(APP_VERS)<<endl;
 90            Qcout<<QString("Copyright (C) 2008-2017 by Oleksii S. Malakhov <brezerk@gmail.com>")<<endl;
 91            Qcout<<QString("License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.")<<endl;
 92            Qcout<<QObject::tr("This is free software: you are free to change and redistribute it.")<<endl;
 93            Qcout<<QObject::tr("There is NO WARRANTY, to the extent permitted by law.")<<endl;
 94            CoreLib->getBuildFlags();
 95            Qcout<<QObject::tr("Author: %1.").arg("Oleksii S. Malakhov")<<endl;
 96            return 0;
 97        } else if (app.arguments().at(i)=="--prefix"){
 98            i++;
 99            if (i<argc)
100                wineObject.setPrefix(app.arguments().at(i));
101        }  else if (app.arguments().at(i)=="--wine-debug"){
102            i++;
103            if (i<argc)
104                wineObject.setProgramDebug(app.arguments().at(i));
105        }  else if (app.arguments().at(i)=="--console"){
106            i++;
107            if (i<argc)
108                wineObject.setUseConsole(app.arguments().at(i).toInt());
109        }  else if (app.arguments().at(i)=="--display"){
110            i++;
111            if (i<argc)
112                wineObject.setProgramDisplay(app.arguments().at(i));
113        }  else if (app.arguments().at(i)=="--nice"){
114            i++;
115            if (i<argc)
116                wineObject.setProgramNice(app.arguments().at(i).toInt());
117        }  else if (app.arguments().at(i)=="--desktop"){
118            i++;
119            if (i<argc)
120                wineObject.setProgramDesktop(app.arguments().at(i));
121        }  else if (app.arguments().at(i)=="--program-bin") {
122            i++;
123            if (i<argc)
124                wineObject.setProgramBinary(app.arguments().at(i));
125        } else if (app.arguments().at(i)=="--program-args") {
126            i++;
127            if (i<argc)
128                wineObject.setProgramArgs(app.arguments().at(i));
129        } else if (app.arguments().at(i)=="--wrkdir") {
130            i++;
131            if (i<argc)
132                wineObject.setProgramWrkdir(app.arguments().at(i));
133        } else if (app.arguments().at(i)=="--program-lang") {
134            i++;
135            if (i<argc)
136                wineObject.setProgramLang(app.arguments().at(i));
137        } else if (app.arguments().at(i)=="--override") {
138            i++;
139            if (i<argc)
140                wineObject.setProgramOverride(app.arguments().at(i));
141        } else if (app.arguments().at(i)=="--prerun") {
142            i++;
143            if (i<argc)
144                wineObject.setPreRun(app.arguments().at(i));
145        } else if (app.arguments().at(i)=="--postrun") {
146            i++;
147            if (i<argc)
148                wineObject.setPostRun(app.arguments().at(i));
149        } else {
150            Qcout<<QObject::tr("Usage:")<<endl;
151            Qcout<<QObject::tr("  %1-helper [KEYs]...").arg(APP_SHORT_NAME)<<endl;
152            Qcout<<QObject::tr("Console utility for Q4Wine which helps to handle Wine application exit status and its stdout/stderr output logging.")<<endl<<endl;
153            Qcout<<QObject::tr("KEYs list:")<<endl;
154            Qcout<<qSetFieldWidth(25)<<left<<"  --prefix"<<QObject::tr("sets the current prefix name")<<qSetFieldWidth(0)<<endl;
155            Qcout<<qSetFieldWidth(25)<<left<<"  --wine-debug"<<QObject::tr("sets WINEDEBUG variable")<<qSetFieldWidth(0)<<endl;
156            Qcout<<qSetFieldWidth(25)<<left<<"  --console"<<QObject::tr("run with output in console")<<qSetFieldWidth(0)<<endl;
157            Qcout<<qSetFieldWidth(25)<<left<<"  --display"<<QObject::tr("sets DISPLAY variable")<<qSetFieldWidth(0)<<endl;
158            Qcout<<qSetFieldWidth(25)<<left<<"  --nice"<<QObject::tr("sets program niceness")<<qSetFieldWidth(0)<<endl;
159            Qcout<<qSetFieldWidth(25)<<left<<"  --desktop"<<QObject::tr("sets program virtual desktop resolution")<<qSetFieldWidth(0)<<endl;
160            Qcout<<qSetFieldWidth(25)<<left<<"  --program-bin"<<QObject::tr("sets program binary")<<qSetFieldWidth(0)<<endl;
161            Qcout<<qSetFieldWidth(25)<<left<<"  --program-args"<<QObject::tr("sets program args")<<qSetFieldWidth(0)<<endl;
162            Qcout<<qSetFieldWidth(25)<<left<<"  --wrkdir"<<QObject::tr("sets program working directory")<<qSetFieldWidth(0)<<endl;
163            Qcout<<qSetFieldWidth(25)<<left<<"  --program-lang"<<QObject::tr("sets program LANG variable")<<qSetFieldWidth(0)<<endl;
164            Qcout<<qSetFieldWidth(25)<<left<<"  --override"<<QObject::tr("sets WINEDLLOVERRIDES variable")<<qSetFieldWidth(0)<<endl;
165            Qcout<<qSetFieldWidth(25)<<left<<"  --prerun"<<QObject::tr("execute script before program run")<<qSetFieldWidth(0)<<endl;
166            Qcout<<qSetFieldWidth(25)<<left<<"  --postrun"<<QObject::tr("execute script after program run")<<qSetFieldWidth(0)<<endl;
167            Qcout<<endl;
168            Qcout<<QObject::tr("Report %1 bugs to %2").arg(APP_SHORT_NAME).arg(APP_BUG_EMAIL)<<endl;
169            Qcout<<QObject::tr("%1 homepage: <%2>").arg(APP_SHORT_NAME).arg(APP_WEBSITE)<<endl;
170            Qcout<<QObject::tr("General help using GNU software: <http://www.gnu.org/gethelp/>")<<endl;
171            return 0;
172        }
173    }
174
175    return wineObject.run();
176}