|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbTools module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 |
|
26 #include <hbdocumentloader.h> |
|
27 #include <QtGui> |
|
28 #include <assert.h> |
|
29 #include <iostream> |
|
30 |
|
31 |
|
32 void showHelp() { |
|
33 std::cout << "docml2bin.exe usage:\n\n"; |
|
34 |
|
35 std::cout << "docml2bin -s sourceFile [-t targetFile]\n\n"; |
|
36 |
|
37 std::cout << " Converts plain text docml file to a binary file.\n\n"; |
|
38 |
|
39 std::cout << " If target file name is not given creates file named\n"; |
|
40 std::cout << " <source file> + \".bin\".\n\n"; |
|
41 |
|
42 std::cout << "options:\n\n"; |
|
43 |
|
44 std::cout << " -s \t\tname of the source file (\"<filename.docml>\").\n"; |
|
45 std::cout << " -t \t\tname of the targe file (\"<binaryfile.bin>\").\n\n"; |
|
46 |
|
47 std::cout << "Example:\n"; |
|
48 std::cout << "docml2bin.exe -s myfile.docml -t c:/resouces/bin/mybinary.docml\n\n"; |
|
49 } |
|
50 |
|
51 int main(int argc, char *argv[]) |
|
52 { |
|
53 QApplication app(argc, argv, false); // GUIenabled=false |
|
54 |
|
55 if (argc <= 2) { |
|
56 showHelp(); |
|
57 } else { |
|
58 QString source, target; |
|
59 QStringList args(app.arguments()); |
|
60 |
|
61 for (int n = 0; n < args.count(); n++) { |
|
62 if (args[n].toLower() == "-s") { |
|
63 source = args[n+1]; |
|
64 n++; |
|
65 } else if (args[n].toLower() == "-t") { |
|
66 target = args[n+1]; |
|
67 n++; |
|
68 } |
|
69 } |
|
70 |
|
71 if (source.length() > 0) { |
|
72 if (!QFile::exists(source)) { |
|
73 std::cout << "Error: file " << source.toStdString() << " does not exist.\n"; |
|
74 } else { |
|
75 // Open file and parse lines. Each line should have three value separated with: |
|
76 QFile sourceFile(source); |
|
77 if (sourceFile.open(QIODevice::ReadOnly | QIODevice::Text)) { |
|
78 if (!target.length()) { |
|
79 target = source + ".bin"; |
|
80 } |
|
81 if (QFile::exists(target)) { |
|
82 std::cout << "Error: target file already exists.\n"; |
|
83 } else { |
|
84 QFile targetFile(target); |
|
85 if (targetFile.open(QIODevice::WriteOnly)) { |
|
86 HbDocumentLoader loader; |
|
87 loader.createBinary( &sourceFile, &targetFile ); |
|
88 targetFile.close(); |
|
89 } |
|
90 } |
|
91 sourceFile.close(); |
|
92 } |
|
93 } |
|
94 } |
|
95 } |
|
96 |
|
97 return 0; |
|
98 } |
|
99 |