source: branches/work_304/AppConfig.cpp @ 330

Revision 330, 5.7 KB checked in by jls17, 7 years ago (diff)
  • CMain::Run stores argv[0] in appConfig, so it could be used later in the resource extractor
Line 
1//Copyright (C) 2009 Stefan Nerlich | stefan.nerlich@hotmail.com
2//
3//This file is part of ARInside.
4//
5//    ARInside is free software: you can redistribute it and/or modify
6//    it under the terms of the GNU General Public License as published by
7//    the Free Software Foundation, version 2 of the License.
8//
9//    ARInside 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 Foobar.  If not, see <http://www.gnu.org/licenses/>.
16
17#include "stdafx.h"
18#include "AppConfig.h"
19#include "FileSystemUtil.h"
20#include "tclap/CmdLine.h"
21#include "util/CommandLineValidator.h"
22#include "output/WebUtil.h"
23
24using namespace TCLAP;
25using namespace OUTPUT;
26
27bool AppConfig::verboseMode = false;
28
29AppConfig::AppConfig(void)
30{
31        // ARSystem data
32        userForm = "";
33        groupForm = "";
34        roleForm = "";
35        userQuery = "";
36        groupQuery = "";
37        roleQuery = "";
38        maxRetrieve = 0;
39        overlayMode = "";
40        slowObjectLoading = false;
41
42        // Output and Layout configuration
43        companyName = "";
44        companyUrl = "";
45        targetFolder = "";
46        fileMode        = false;
47        objListXML      = "";
48        oldNaming = false;
49        testMode = false;
50
51        // BlackList
52        blackList = "";
53
54        //Restrict ObjectLibrary
55        bLoadServerInfoList = true;
56        bLoadUserList = true;
57        bLoadGroupList = true;
58        bLoadRoleList = true;
59        bUseUtf8 = false;
60        bOverlaySupport;
61
62        serverName = "";
63        userName = "";
64        password = "";
65        tcpPort = 0;
66        rpcPort = 0;
67        apiTimeout = 0;
68        bCompactFolder = false;
69        bDeleteExistingFiles = false;
70        bGZCompression = false;
71
72        //Notes to be displayed on home page
73        runNotes = "";
74        argv_0 = "";
75}
76
77AppConfig::~AppConfig(void)
78{
79}
80
81void AppConfig::Validate(CommandLineValidator& cmdLine)
82{
83        OverrideSettingsByCommandLine(cmdLine);
84
85        // special checks for server mode
86        if (!fileMode) 
87        {
88                string missingArgs;
89                unsigned int missingCount = 0;
90
91                if (!fileMode && serverName.empty())
92                {
93                        missingCount++;
94                        missingArgs = "server / ServerName";
95                }
96                if (userName.empty())
97                {
98                        missingCount++;
99                        if (!missingArgs.empty()) missingArgs += ", ";
100                        missingArgs += "login / Username";
101                }
102
103                if (!missingArgs.empty())
104                {
105                        string msg;
106                        StdOutput _output;
107                        msg = "Required argument(s) missing: " + missingArgs;
108                       
109                        cout << endl;
110                        CmdLineParseException parseErr(msg);
111                        _output.failure(cmdLine.GetCmdLine(), parseErr);
112                }
113        }
114
115        // validate the path of the target folder
116        if (targetFolder.empty())
117        {
118                cout << "[ERR] Target folder setting is missing or not setup correctly!" << endl;
119                throw ExitException(1);
120        }
121
122        // Just in case someone has set "DeleteExistingFiles" on and specified the root of the file system.
123        // For security reasons we disallow the root directory.
124        string fullOutputPath = FileSystemUtil::GetRealPathName(targetFolder);
125        if (CUtil::StrEndsWith(fullOutputPath, ":\\") || CUtil::StrEndsWith(fullOutputPath, ":/") || fullOutputPath == "/")
126        {
127                cout << "[ERR] The target directory points to the root of the device. This is not allowed!" << endl;
128                throw ExitException(1);
129        }
130
131        // now configure the environment
132        if (bGZCompression)
133                CWebUtil::webpageFileExtension = CWebUtil::HtmlGZPageSuffix();
134        else
135                CWebUtil::webpageFileExtension = CWebUtil::HtmlPageSuffix();
136
137        // later we can support configuring specific layer documentation
138        if (overlayMode != "FALSE" && overlayMode != "TRUE")
139        {
140                overlayMode = "TRUE";
141        }
142
143        // should overlay support be disabled completely?
144        if (overlayMode == "FALSE")
145                bOverlaySupport = false;
146        else
147                bOverlaySupport = true;
148
149}
150
151void AppConfig::OverrideSettingsByCommandLine(CommandLineValidator& cmdLine)
152{
153        // override settings with values specified by the command line
154        if (cmdLine.isServerSet())
155                serverName = cmdLine.GetServer();
156
157        if (cmdLine.isOutputFolderSet())
158                targetFolder = cmdLine.GetOutputFolder();
159
160        if (cmdLine.isUsernameSet())
161                userName = cmdLine.GetUsername();
162
163        if (cmdLine.isPasswordSet())
164                password = cmdLine.GetPassword();
165
166        if (cmdLine.isTcpPortSet())
167                tcpPort = cmdLine.GetTcpPort();
168
169        if (cmdLine.isRpcPortSet())
170                rpcPort = cmdLine.GetRpcPort();
171
172        // the following settings are set by command line only
173        slowObjectLoading = cmdLine.GetSlowObjectLoading();
174
175#if ARINSIDE_TEST_SUPPORT
176        testMode = cmdLine.GetTestMode();
177#endif
178}
179
180void AppConfig::Dump()
181{
182        cout << "UserForm: " << userForm << endl;               
183        cout << "UserQuery: " << userQuery << endl;
184        cout << "GroupForm: " << groupForm << endl;
185        cout << "GroupQuery: " << groupQuery << endl;
186        cout << "RoleForm: " << roleForm << endl;
187        cout << "RoleQuery: " << roleQuery << endl;
188        cout << "MaxRetrieve: " << maxRetrieve << endl;
189        cout << "CompanyName: " << companyName << endl;
190        cout << "CompanyUrl: " << companyUrl << endl;
191        cout << "TargetFolder: " << targetFolder << endl;
192        cout << "FileMode: " << fileMode << endl;
193        cout << "ObjListXML: " << objListXML << endl;
194        cout << "OldNaming: " << oldNaming << endl;
195        cout << "BlackList: " << blackList << endl;
196        cout << "LoadServerInfoList: " << bLoadServerInfoList << endl;
197        cout << "LoadUserList: " << bLoadUserList << endl;
198        cout << "LoadGroupList: " << bLoadGroupList << endl;
199        cout << "LoadRoleList: " << bLoadRoleList << endl;
200        cout << "Utf-8: " << bUseUtf8 << endl;
201        cout << "CompactFolder: " << bCompactFolder << endl;
202        cout << "GZCompression: " << bGZCompression << endl;
203        cout << "DeleteExistingFiles: " << bDeleteExistingFiles << endl;
204        cout << "OverlayMode: " << overlayMode << endl;
205        cout << "RunNotes: " << runNotes << endl;
206        cout << endl;
207}
208
Note: See TracBrowser for help on using the repository browser.