2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-21 08:09:43 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the tools applications of the Qt Toolkit.
|
|
|
|
**
|
2016-01-21 08:09:43 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
2012-09-20 06:20:30 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-02-11 12:37:56 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-21 08:09:43 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-20 06:20:30 +00:00
|
|
|
**
|
2016-01-21 08:09:43 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <QAxObject>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QTextStream>
|
|
|
|
#include <qt_windows.h>
|
|
|
|
|
|
|
|
QT_USE_NAMESPACE
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2019-06-04 12:45:46 +00:00
|
|
|
if (FAILED(CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED))) {
|
2018-08-08 19:09:51 +00:00
|
|
|
qErrnoWarning("CoInitializeEx() failed.");
|
2013-01-18 11:10:16 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
enum State {
|
|
|
|
Default = 0,
|
|
|
|
OutOption
|
|
|
|
} state;
|
|
|
|
state = Default;
|
2014-01-15 21:17:52 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QByteArray outname;
|
|
|
|
QByteArray object;
|
2014-01-15 21:17:52 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
for (int a = 1; a < argc; ++a) {
|
|
|
|
QByteArray arg(argv[a]);
|
|
|
|
const char first = arg[0];
|
|
|
|
switch(state) {
|
|
|
|
case Default:
|
|
|
|
if (first == '-' || first == '/') {
|
2014-09-09 10:42:22 +00:00
|
|
|
arg = arg.mid(1).toLower();
|
2011-04-27 10:05:43 +00:00
|
|
|
if (arg == "o")
|
|
|
|
state = OutOption;
|
|
|
|
else if (arg == "v") {
|
|
|
|
qWarning("dumpdoc: Version 1.0");
|
|
|
|
return 0;
|
|
|
|
} else if (arg == "h") {
|
|
|
|
qWarning("dumpdoc Usage:\n\tdumpdoc object [-o <file>]"
|
|
|
|
" \n\tobject : object[/subobject]*"
|
|
|
|
" \n\tsubobject: property\n"
|
|
|
|
" \nexample:\n\tdumpdoc Outlook.Application/Session/CurrentUser -o outlook.html");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
object = arg;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OutOption:
|
|
|
|
outname = arg;
|
|
|
|
state = Default;
|
|
|
|
break;
|
2014-01-15 21:17:52 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-01-15 21:17:52 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
if (object.isEmpty()) {
|
|
|
|
qWarning("dumpdoc: No object name provided.\n"
|
|
|
|
" Use -h for help.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
QFile outfile;
|
|
|
|
if (!outname.isEmpty()) {
|
|
|
|
outfile.setFileName(QString::fromLatin1(outname.constData()));
|
|
|
|
if (!outfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
|
|
|
qWarning("dumpdoc: Could not open output file '%s'", outname.data());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
outfile.open(stdout, QIODevice::WriteOnly);
|
|
|
|
}
|
|
|
|
QTextStream out(&outfile);
|
2014-01-15 21:17:52 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QByteArray subobject = object;
|
|
|
|
int index = subobject.indexOf('/');
|
|
|
|
if (index != -1)
|
2014-10-09 12:27:48 +00:00
|
|
|
subobject.truncate(index);
|
2014-01-15 21:17:52 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QAxObject topobject(QString::fromLatin1(subobject.constData()));
|
2014-01-15 21:17:52 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
if (topobject.isNull()) {
|
|
|
|
qWarning("dumpdoc: Could not instantiate COM object '%s'", subobject.data());
|
|
|
|
return -2;
|
|
|
|
}
|
2014-01-15 21:17:52 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QAxObject *axobject = &topobject;
|
|
|
|
while (index != -1 && axobject) {
|
|
|
|
index++;
|
|
|
|
subobject = object.mid(index);
|
|
|
|
if (object.indexOf('/', index) != -1) {
|
|
|
|
int oldindex = index;
|
|
|
|
index = object.indexOf('/', index);
|
2014-01-15 21:17:52 +00:00
|
|
|
subobject = object.mid(oldindex, index-oldindex);
|
2011-04-27 10:05:43 +00:00
|
|
|
} else {
|
|
|
|
index = -1;
|
|
|
|
}
|
2014-01-15 21:17:52 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
axobject = axobject->querySubObject(subobject);
|
|
|
|
}
|
|
|
|
if (!axobject || axobject->isNull()) {
|
|
|
|
qWarning("dumpdoc: Subobject '%s' does not exist in '%s'", subobject.data(), object.data());
|
|
|
|
return -3;
|
|
|
|
}
|
2014-01-15 21:17:52 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QString docu = axobject->generateDocumentation();
|
|
|
|
out << docu;
|
|
|
|
return 0;
|
|
|
|
}
|