summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkh1 <karsten.heimrich@nokia.com>2011-11-22 17:52:59 +0100
committerKarsten Heimrich <karsten.heimrich@nokia.com>2011-11-23 12:10:48 +0100
commit707956ed5d2b9c127e4a5f5705addcda8d8cfd4a (patch)
tree6899c949063e233fcf63a43ec4f27756c44a6f6a
parentc6475d72ca53282224dd9a0a18d434d3ef4be47f (diff)
Let the the gui application open a console on Windows.
If running in verbose mode, redirect all output to our window. Change-Id: Id93fb0b81ceaa7f0ad5eda26d5d313529976f661 Reviewed-by: Niels Weber <niels.2.weber@nokia.com> Reviewed-by: Alexander Lenhardt <alexander.lenhardt@nokia.com> Reviewed-by: Tim Jenssen <tim.jenssen@nokia.com> Reviewed-by: Karsten Heimrich <karsten.heimrich@nokia.com>
-rw-r--r--installerbuilder/installerbase/installerbase.cpp52
-rw-r--r--installerbuilder/installerbase/installerbase_p.cpp122
-rw-r--r--installerbuilder/installerbase/installerbase_p.h14
3 files changed, 135 insertions, 53 deletions
diff --git a/installerbuilder/installerbase/installerbase.cpp b/installerbuilder/installerbase/installerbase.cpp
index a2ade55f0..c066cdee3 100644
--- a/installerbuilder/installerbase/installerbase.cpp
+++ b/installerbuilder/installerbase/installerbase.cpp
@@ -56,9 +56,6 @@
#include <QtNetwork/QNetworkProxyFactory>
-#include <iostream>
-#include <iomanip>
-
#define QUOTE_(x) #x
#define QUOTE(x) QUOTE_(x)
#define VERSION "Installerbase SHA1: \"" QUOTE(_GIT_SHA1_) "\" , Build date: " QUOTE(__DATE__) "."
@@ -81,43 +78,8 @@ static QSet<Repository> repositories(const QStringList &arguments, const int ind
return set;
}
-void usage()
-{
- std::cout << "Usage: SDKMaintenanceTool [OPTIONS]" << std::endl << std::endl;
- std::cout << "User:"<<std::endl;
- std::cout << std::setw(55) << std::setiosflags(std::ios::left)
- << " --help" << std::setw(40) << "Show commandline usage" << std::endl;
- std::cout << std::setw(55) << std::setiosflags(std::ios::left)
- << " --version" << std::setw(40) << "Show current version" << std::endl;
- std::cout << std::setw(55) << std::setiosflags(std::ios::left)
- << " --checkupdates" << std::setw(40) << "Check for updates and return an XML file of the available updates"
- << std::endl;
- std::cout << std::setw(55) << std::setiosflags(std::ios::left)
- << " --proxy" << std::setw(40) << "Set system proxy on Win and Mac. This option has no effect on Linux" << std::endl;
- std::cout << std::setw(55) << std::setiosflags(std::ios::left) << " --verbose" << std::setw(40)
- << "Show debug output on the console" << std::endl;
-
- std::cout << "Developer:"<< std::endl;
- std::cout << std::setw(55) << std::setiosflags(std::ios::left)
- << " --runoperation [operationName] [arguments...]" << std::setw(40)
- << "Perform an operation with a list of arguments" << std::endl;
- std::cout << std::setw(55) << std::setiosflags(std::ios::left)
- << " --undooperation [operationName] [arguments...]" << std::setw(40)
- << "Undo an operation with a list of arguments" <<std::endl;
- std::cout << std::setw(55) << std::setiosflags(std::ios::left)
- << " --script [scriptName]" << std::setw(40) << "Execute a script" << std::endl;
- std::cout << std::setw(55) << std::setiosflags(std::ios::left) << " --no-force-installations"
- << std::setw(40) << "Enable deselection of forced components" << std::endl;
- std::cout << std::setw(55) << std::setiosflags(std::ios::left) << " --addTempRepository [URI]"
- << std::setw(40) << "Add a local or remote repo to the list of available repos." << std::endl;
- std::cout << std::setw(55) << std::setiosflags(std::ios::left) << " --setTempRepository [URI]"
- << std::setw(40) << "Set the update URL to an arbitrary local or remote URI. URI must be prefixed with the protocol, i.e. file:// or http://" << std::endl;
- std::cout << std::setw(55) << std::setiosflags(std::ios::left) << " --show-virtual-components"
- << std::setw(40) << "Show virtual components in package manager and updater" << std::endl;
- std::cout << std::setw(55) << std::setiosflags(std::ios::left)
- << " --update-installerbase [path/to/new/installerbase]" << std::setw(40)
- << "Patch a full installer with a new installer base" << std::endl;
-}
+
+// -- main
int main(int argc, char *argv[])
{
@@ -128,7 +90,7 @@ int main(int argc, char *argv[])
const QStringList args = QInstaller::parseCommandLineArgs(argc, argv);
try {
if (args.contains(QLatin1String("--version"))) {
- InstallerBase::showVersion(argc, argv, QLatin1String(VERSION));
+ InstallerBase::showVersion(QLatin1String(VERSION));
return 0;
}
@@ -192,8 +154,10 @@ int main(int argc, char *argv[])
Sleep::sleep(1);
}
- if (args.contains(QLatin1String("--verbose")) || args.contains(QLatin1String("Verbose")))
+ if (args.contains(QLatin1String("--verbose")) || args.contains(QLatin1String("Verbose"))) {
+ app.setVerbose();
QInstaller::setVerbose(true);
+ }
// install the default translator
const QString localeFile =
@@ -289,7 +253,7 @@ int main(int argc, char *argv[])
|| argument == QLatin1String("ManagePackages")) && core.isUninstaller()) {
core.setPackageManager();
} else if (argument == QLatin1String("--help") || argument == QLatin1String("-h")) {
- usage();
+ InstallerBase::showUsage();
return PackageManagerCore::Success;
} else if (argument == QLatin1String("--addTempRepository")
|| argument == QLatin1String("--setTempRepository")) {
@@ -312,7 +276,7 @@ int main(int argc, char *argv[])
PackageManagerCore::setNoForceInstallation(true);
} else {
std::cerr << "Unknown option: " << argument << std::endl;
- usage();
+ InstallerBase::showUsage();
return PackageManagerCore::Failure;
}
}
diff --git a/installerbuilder/installerbase/installerbase_p.cpp b/installerbuilder/installerbase/installerbase_p.cpp
index d0a0b2de4..e3dc0dd83 100644
--- a/installerbuilder/installerbase/installerbase_p.cpp
+++ b/installerbuilder/installerbase/installerbase_p.cpp
@@ -51,6 +51,8 @@
#include <QtGui/QMessageBox>
+#include <iomanip>
+
using namespace KDUpdater;
using namespace QInstaller;
using namespace QInstallerCreator;
@@ -75,13 +77,81 @@ bool MyCoreApplication::notify(QObject *receiver, QEvent *event)
}
+// -- MyApplicationConsole
+
+class MyApplicationConsole
+{
+public:
+ MyApplicationConsole()
+ {
+#ifdef Q_OS_WIN
+ AllocConsole();
+
+ HANDLE stdOutHandle = GetStdHandle(STD_OUTPUT_HANDLE);
+ if (stdOutHandle != INVALID_HANDLE_VALUE) {
+ COORD largestConsoleWindowSize = GetLargestConsoleWindowSize(stdOutHandle);
+ largestConsoleWindowSize.X -= 1;
+ largestConsoleWindowSize.Y -= 1;
+ SetConsoleScreenBufferSize(stdOutHandle, largestConsoleWindowSize);
+ SetConsoleMode(stdOutHandle, ENABLE_QUICK_EDIT_MODE | ENABLE_EXTENDED_FLAGS);
+ }
+
+ m_oldCin = std::cin.rdbuf();
+ m_newCin.open("CONIN$");
+ std::cin.rdbuf(m_newCin.rdbuf());
+
+ m_oldCout = std::cout.rdbuf();
+ m_newCout.open("CONOUT$");
+ std::cout.rdbuf(m_newCout.rdbuf());
+
+ m_oldCerr = std::cerr.rdbuf();
+ m_newCerr.open("CONOUT$");
+ std::cerr.rdbuf(m_newCerr.rdbuf());
+#endif
+ }
+ ~MyApplicationConsole()
+ {
+#ifdef Q_OS_WIN
+ system("PAUSE");
+
+ std::cin.rdbuf(m_oldCin);
+ std::cerr.rdbuf(m_oldCerr);
+ std::cout.rdbuf(m_oldCout);
+
+ FreeConsole();
+#endif
+ }
+
+private:
+ std::ifstream m_newCin;
+ std::ofstream m_newCout;
+ std::ofstream m_newCerr;
+
+ std::streambuf* m_oldCin;
+ std::streambuf* m_oldCout;
+ std::streambuf* m_oldCerr;
+};
+
+
// -- MyApplication
MyApplication::MyApplication(int &argc, char **argv)
: QApplication(argc, argv)
+ , m_console(0)
{
}
+MyApplication::~MyApplication()
+{
+ delete m_console;
+}
+
+void MyApplication::setVerbose()
+{
+ if (!m_console)
+ m_console = new MyApplicationConsole;
+}
+
// re-implemented from QApplication so we can throw exceptions in scripts and slots
bool MyApplication::notify(QObject *receiver, QEvent *event)
{
@@ -193,15 +263,51 @@ int InstallerBase::replaceMaintenanceToolBinary(QStringList arguments)
}
/* static*/
-void InstallerBase::showVersion(int &argc, char **argv, const QString &version)
+void InstallerBase::showUsage()
{
-#ifdef Q_OS_WIN
- MyApplication app(argc, argv);
- QMessageBox::information(0, tr("Version"), version);
-#else
- Q_UNUSED(argc) Q_UNUSED(argv)
- fprintf(stdout, "%s\n", qPrintable(version));
-#endif
+ MyApplicationConsole c;
+ std::cout << "Usage: SDKMaintenanceTool [OPTIONS]" << std::endl << std::endl;
+
+ std::cout << "User:"<<std::endl;
+ std::cout << std::setw(55) << std::setiosflags(std::ios::left) << " --help" << std::setw(40)
+ << "Show commandline usage" << std::endl;
+ std::cout << std::setw(55) << std::setiosflags(std::ios::left) << " --version" << std::setw(40)
+ << "Show current version" << std::endl;
+ std::cout << std::setw(55) << std::setiosflags(std::ios::left) << " --checkupdates" << std::setw(40)
+ << "Check for updates and return an XML file of the available updates" << std::endl;
+ std::cout << std::setw(55) << std::setiosflags(std::ios::left) << " --proxy" << std::setw(40)
+ << "Set system proxy on Win and Mac. This option has no effect on Linux." << std::endl;
+ std::cout << std::setw(55) << std::setiosflags(std::ios::left) << " --verbose" << std::setw(40)
+ << "Show debug output on the console" << std::endl;
+
+ std::cout << "Developer:"<< std::endl;
+ std::cout << std::setw(55) << std::setiosflags(std::ios::left)
+ << " --runoperation [operationName] [arguments...]" << std::setw(40)
+ << "Perform an operation with a list of arguments" << std::endl;
+ std::cout << std::setw(55) << std::setiosflags(std::ios::left)
+ << " --undooperation [operationName] [arguments...]" << std::setw(40)
+ << "Undo an operation with a list of arguments" <<std::endl;
+ std::cout << std::setw(55) << std::setiosflags(std::ios::left)
+ << " --script [scriptName]" << std::setw(40) << "Execute a script" << std::endl;
+ std::cout << std::setw(55) << std::setiosflags(std::ios::left) << " --no-force-installations"
+ << std::setw(40) << "Enable deselection of forced components" << std::endl;
+ std::cout << std::setw(55) << std::setiosflags(std::ios::left) << " --addTempRepository [URI]"
+ << std::setw(40) << "Add a local or remote repo to the list of available repos." << std::endl;
+ std::cout << std::setw(55) << std::setiosflags(std::ios::left) << " --setTempRepository [URI]"
+ << std::setw(40) << "Set the update URL to an arbitrary local or remote URI. URI must be prefixed "
+ "with the protocol, i.e. file:/// or http://" << std::endl;
+ std::cout << std::setw(55) << std::setiosflags(std::ios::left) << " --show-virtual-components"
+ << std::setw(40) << "Show virtual components in package manager and updater" << std::endl;
+ std::cout << std::setw(55) << std::setiosflags(std::ios::left)
+ << " --update-installerbase [path/to/new/installerbase]" << std::setw(40)
+ << "Patch a full installer with a new installer base" << std::endl;
+}
+
+/* static*/
+void InstallerBase::showVersion(const QString &version)
+{
+ MyApplicationConsole c;
+ std::cout << qPrintable(version) << std::endl;
}
diff --git a/installerbuilder/installerbase/installerbase_p.h b/installerbuilder/installerbase/installerbase_p.h
index 904e6541a..b21adf60f 100644
--- a/installerbuilder/installerbase/installerbase_p.h
+++ b/installerbuilder/installerbase/installerbase_p.h
@@ -33,6 +33,9 @@
#include <QtCore/QThread>
#include <QtGui/QApplication>
+#include <fstream>
+#include <iostream>
+
namespace KDUpdater {
class FileDownloader;
}
@@ -41,6 +44,7 @@ QT_BEGIN_NAMESPACE
class QFile;
QT_END_NAMESPACE
+class MyApplicationConsole;
class Sleep : public QThread
{
@@ -60,7 +64,9 @@ public:
~InstallerBase();
int replaceMaintenanceToolBinary(QStringList arguments);
- static void showVersion(int &argc, char **argv, const QString &version);
+
+ static void showUsage();
+ static void showVersion(const QString &version);
private slots:
void downloadStarted();
@@ -88,5 +94,11 @@ class MyApplication : public QApplication
{
public:
MyApplication(int &argc, char **argv);
+ ~MyApplication();
+
+ void setVerbose();
virtual bool notify(QObject *receiver, QEvent *event);
+
+private:
+ MyApplicationConsole *m_console;
};