PageRenderTime 54ms CodeModel.GetById 26ms RepoModel.GetById 0ms 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
Possible License(s): GPL-3.0, LGPL-3.0, LGPL-2.1
  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. #include "q4wine-helper.h"
  19. int main(int argc, char *argv[])
  20. {
  21. QCoreApplication app(argc, argv);
  22. QTextStream QErr(stderr);
  23. //! This is need for libq4wine-core.so import;
  24. typedef void *CoreLibPrototype (bool);
  25. CoreLibPrototype *CoreLibClassPointer;
  26. std::unique_ptr<corelib> CoreLib;
  27. QLibrary libq4wine;
  28. // Loading libq4wine-core.so
  29. #ifdef RELEASE
  30. libq4wine.setFileName(_CORELIB_PATH_);
  31. #else
  32. libq4wine.setFileName(QString("%1/q4wine-lib/libq4wine-core").arg(QString::fromUtf8(APP_BUILD)));
  33. #endif
  34. if (!libq4wine.load()){
  35. libq4wine.load();
  36. }
  37. // Getting corelib calss pointer
  38. CoreLibClassPointer = (CoreLibPrototype *) libq4wine.resolve("createCoreLib");
  39. CoreLib.reset(static_cast<corelib *>(CoreLibClassPointer(false)));
  40. if (!CoreLib.get()){
  41. QErr<<"[EE] Cannot load shared library."<<endl;
  42. return -1;
  43. }
  44. DataBase db;
  45. if (!db.checkDb()){
  46. QErr<<"[EE] Cannot initialize database engine."<<endl;
  47. return -1;
  48. }
  49. QTranslator qtt;
  50. #ifdef RELEASE
  51. #ifdef _OS_DARWIN_
  52. QString l10nPath = QString("%1/%2.app/Contents/l10n").arg(QDir::currentPath()).arg(APP_SHORT_NAME);
  53. #else
  54. QString l10nPath = QString("%1/share/%2/l10n").arg(QString::fromUtf8(APP_PREF)).arg(APP_SHORT_NAME);
  55. #endif
  56. #else
  57. QString l10nPath = QString("%1/l10n").arg(QString::fromUtf8(APP_BUILD));
  58. #endif
  59. qtt.load(CoreLib->getTranslationLang(), l10nPath);
  60. app.installTranslator(&qtt);
  61. if (!CoreLib->isConfigured()){
  62. QErr<<"[EE] App is not configured! Rerun wizard, or delete Q4Wine broken config files."<<endl;
  63. return -1;
  64. }
  65. QTextStream Qcout(stdout);
  66. WineObject wineObject;
  67. if (argc==1){
  68. app.arguments().append("-h");
  69. argc++;
  70. }
  71. for (int i=1; i<argc; i++){
  72. qDebug()<<app.arguments().at(i);
  73. if ((app.arguments().at(1)=="--version") or (app.arguments().at(1)=="-v")){
  74. Qcout<<QString("%1-helper %2").arg(APP_SHORT_NAME).arg(APP_VERS)<<endl;
  75. Qcout<<QString("Copyright (C) 2008-2017 by Oleksii S. Malakhov <brezerk@gmail.com>")<<endl;
  76. Qcout<<QString("License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.")<<endl;
  77. Qcout<<QObject::tr("This is free software: you are free to change and redistribute it.")<<endl;
  78. Qcout<<QObject::tr("There is NO WARRANTY, to the extent permitted by law.")<<endl;
  79. CoreLib->getBuildFlags();
  80. Qcout<<QObject::tr("Author: %1.").arg("Oleksii S. Malakhov")<<endl;
  81. return 0;
  82. } else if (app.arguments().at(i)=="--prefix"){
  83. i++;
  84. if (i<argc)
  85. wineObject.setPrefix(app.arguments().at(i));
  86. } else if (app.arguments().at(i)=="--wine-debug"){
  87. i++;
  88. if (i<argc)
  89. wineObject.setProgramDebug(app.arguments().at(i));
  90. } else if (app.arguments().at(i)=="--console"){
  91. i++;
  92. if (i<argc)
  93. wineObject.setUseConsole(app.arguments().at(i).toInt());
  94. } else if (app.arguments().at(i)=="--display"){
  95. i++;
  96. if (i<argc)
  97. wineObject.setProgramDisplay(app.arguments().at(i));
  98. } else if (app.arguments().at(i)=="--nice"){
  99. i++;
  100. if (i<argc)
  101. wineObject.setProgramNice(app.arguments().at(i).toInt());
  102. } else if (app.arguments().at(i)=="--desktop"){
  103. i++;
  104. if (i<argc)
  105. wineObject.setProgramDesktop(app.arguments().at(i));
  106. } else if (app.arguments().at(i)=="--program-bin") {
  107. i++;
  108. if (i<argc)
  109. wineObject.setProgramBinary(app.arguments().at(i));
  110. } else if (app.arguments().at(i)=="--program-args") {
  111. i++;
  112. if (i<argc)
  113. wineObject.setProgramArgs(app.arguments().at(i));
  114. } else if (app.arguments().at(i)=="--wrkdir") {
  115. i++;
  116. if (i<argc)
  117. wineObject.setProgramWrkdir(app.arguments().at(i));
  118. } else if (app.arguments().at(i)=="--program-lang") {
  119. i++;
  120. if (i<argc)
  121. wineObject.setProgramLang(app.arguments().at(i));
  122. } else if (app.arguments().at(i)=="--override") {
  123. i++;
  124. if (i<argc)
  125. wineObject.setProgramOverride(app.arguments().at(i));
  126. } else if (app.arguments().at(i)=="--prerun") {
  127. i++;
  128. if (i<argc)
  129. wineObject.setPreRun(app.arguments().at(i));
  130. } else if (app.arguments().at(i)=="--postrun") {
  131. i++;
  132. if (i<argc)
  133. wineObject.setPostRun(app.arguments().at(i));
  134. } else {
  135. Qcout<<QObject::tr("Usage:")<<endl;
  136. Qcout<<QObject::tr(" %1-helper [KEYs]...").arg(APP_SHORT_NAME)<<endl;
  137. Qcout<<QObject::tr("Console utility for Q4Wine which helps to handle Wine application exit status and its stdout/stderr output logging.")<<endl<<endl;
  138. Qcout<<QObject::tr("KEYs list:")<<endl;
  139. Qcout<<qSetFieldWidth(25)<<left<<" --prefix"<<QObject::tr("sets the current prefix name")<<qSetFieldWidth(0)<<endl;
  140. Qcout<<qSetFieldWidth(25)<<left<<" --wine-debug"<<QObject::tr("sets WINEDEBUG variable")<<qSetFieldWidth(0)<<endl;
  141. Qcout<<qSetFieldWidth(25)<<left<<" --console"<<QObject::tr("run with output in console")<<qSetFieldWidth(0)<<endl;
  142. Qcout<<qSetFieldWidth(25)<<left<<" --display"<<QObject::tr("sets DISPLAY variable")<<qSetFieldWidth(0)<<endl;
  143. Qcout<<qSetFieldWidth(25)<<left<<" --nice"<<QObject::tr("sets program niceness")<<qSetFieldWidth(0)<<endl;
  144. Qcout<<qSetFieldWidth(25)<<left<<" --desktop"<<QObject::tr("sets program virtual desktop resolution")<<qSetFieldWidth(0)<<endl;
  145. Qcout<<qSetFieldWidth(25)<<left<<" --program-bin"<<QObject::tr("sets program binary")<<qSetFieldWidth(0)<<endl;
  146. Qcout<<qSetFieldWidth(25)<<left<<" --program-args"<<QObject::tr("sets program args")<<qSetFieldWidth(0)<<endl;
  147. Qcout<<qSetFieldWidth(25)<<left<<" --wrkdir"<<QObject::tr("sets program working directory")<<qSetFieldWidth(0)<<endl;
  148. Qcout<<qSetFieldWidth(25)<<left<<" --program-lang"<<QObject::tr("sets program LANG variable")<<qSetFieldWidth(0)<<endl;
  149. Qcout<<qSetFieldWidth(25)<<left<<" --override"<<QObject::tr("sets WINEDLLOVERRIDES variable")<<qSetFieldWidth(0)<<endl;
  150. Qcout<<qSetFieldWidth(25)<<left<<" --prerun"<<QObject::tr("execute script before program run")<<qSetFieldWidth(0)<<endl;
  151. Qcout<<qSetFieldWidth(25)<<left<<" --postrun"<<QObject::tr("execute script after program run")<<qSetFieldWidth(0)<<endl;
  152. Qcout<<endl;
  153. Qcout<<QObject::tr("Report %1 bugs to %2").arg(APP_SHORT_NAME).arg(APP_BUG_EMAIL)<<endl;
  154. Qcout<<QObject::tr("%1 homepage: <%2>").arg(APP_SHORT_NAME).arg(APP_WEBSITE)<<endl;
  155. Qcout<<QObject::tr("General help using GNU software: <http://www.gnu.org/gethelp/>")<<endl;
  156. return 0;
  157. }
  158. }
  159. return wineObject.run();
  160. }