-
Notifications
You must be signed in to change notification settings - Fork 7
/
wizard.cpp
559 lines (489 loc) · 20.4 KB
/
wizard.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
#include "wizard.h"
#include "ui_wizard.h"
#include "confighelper.h"
#include <QDir>
#include <QUuid>
#include "configfile.h"
#include <databasedialog.h>
#include <QMessageBox>
#include "connectionstringhelper.h"
#include <QFileDialog>
Wizard::Wizard(QWidget *parent, RegionWizard* regionWizard) :
QWizard(parent),
ui(new Ui::Wizard),
m_RegionWizard(regionWizard)
{
ui->setupUi(this);
m_lastId = 0;
m_missingUserName = 0;
QAbstractButton* nextButton = this->button(QWizard::NextButton);
connect(nextButton, SIGNAL(clicked()), SLOT(onNext_button_clicked()));
QAbstractButton* finishButton = this->button(QWizard::FinishButton);
connect(finishButton, SIGNAL(clicked()), SLOT(onFinish_button_clicked()));
m_GridConfig = true;
m_JoinGrid = true;
// hide DB label strings
ui->labelSimDBString->hide();
ui->labelGridDBString->hide();
ui->labelGridDbPlugin->hide();
ui->labelSimDBPlugin->hide();
ui->labelGridNhib->hide();
ui->labelPropProv->hide();
ui->labelModRexConnStr->hide();
loadDefaults();
setDatabasesFromConfig();
}
Wizard::~Wizard()
{
if(m_missingUserName!=0)
{
delete m_missingUserName;
m_missingUserName = 0;
}
delete ui;
}
void Wizard::SetTaigaPath(QString path)
{
ui->lineEditTaigaDir->setText(path);
}
void Wizard::changeEvent(QEvent *e)
{
QWizard::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void Wizard::Configure(bool foundTaiga)
{
if(!m_GridConfig)
{
this->removePage(3);
this->removePage(1);
}
if(!foundTaiga)
{
QString text = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">";
text.append("<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">");
text.append("p, li { white-space: pre-wrap; }");
text.append("</style></head><body style=\" font-family:'SansSerif'; font-size:8.25pt; font-weight:400; font-style:normal;\">");
text.append("<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;");
text.append("<\"-qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:10pt;\">");
text.append("We will need to know where to place the conf files. <br />");
text.append("<Please select bin folder of your Taiga instal. <br />");
text.append("This folder will contain the Taiga executables. <br /> Such as OpenSim.exe, OpenSim.Server.exe.</span></p></body></html>");
ui->lblLocateDirHelp->clear();
ui->lblLocateDirHelp->setText(text);
}
else if(foundTaiga)
{
QString text = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">";
text.append("<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">");
text.append("p, li { white-space: pre-wrap; }");
text.append("</style></head><body style=\" font-family:'SansSerif'; font-size:8.25pt; font-weight:400; font-style:normal;\">");
text.append("<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;");
text.append("<\"-qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:10pt;\">");
text.append("We have found Taiga directory. <br />");
text.append("If you agree this is right directory, continue by clicking next. <br />");
text.append("If not, please select the right location, that contains Taiga executables, <br /> such as OpenSim.exe, OpenSim.Server.exe.</span></p></body></html>");
ui->lblLocateDirHelp->clear();
ui->lblLocateDirHelp->setText(text);
}
setWritableFiles();
}
void Wizard::onNext_button_clicked()
{
int id = this->currentId();
if(m_GridConfig){
switch (id)
{
case 1:
if(!checkTaigaDir()){
QMessageBox box;
box.setText("Did not find OpenSim.exe from taiga dir check path");
box.exec();
this->back();
} else {
m_configHandler.OUTPUT_BIN = ui->lineEditTaigaDir->text();
}
break;
case 2:
break;
case 3:
break;
case 4:
constructDatabaseConnectionStringAndDBPlugin();
break;
case 5:
break;
case 6:
break;
}
} else {
switch (id)
{
case 1:
if(!checkTaigaDir()){
QMessageBox box;
box.setText("Did not find OpenSim.exe from taiga dir check path");
box.exec();
this->back();
} else {
m_configHandler.OUTPUT_BIN = ui->lineEditTaigaDir->text();
}
break;
case 2:
break;
}
}
m_lastId = id;
}
void Wizard::onFinish_button_clicked()
{
// read all values we have
QMap<QString, QString> map;
ConfigHelper::CollectAllTaggedValuesFromPage(&map, this); // get all values in wizard
m_configHandler.WriteUIValues2ConfigBasedOnConfigSetup(map);
// write configs to output folder
this->m_configHandler.ApplyConfigs(m_GridConfig, m_JoinGrid, m_Regions);
QMessageBox info;
info.setText("Files written to bin");
info.exec();
}
bool Wizard::checkTaigaDir()
{
QString openSimExePath = this->ui->lineEditTaigaDir->text() + QDir::separator() + "OpenSim.exe";
return ConfigHelper::CheckIfFileExists(openSimExePath);
}
void Wizard::on_btnAddRegion_clicked()
{
m_RegionWizard->GoToStart();
int retVal = this->m_RegionWizard->exec();
if(retVal!=0){
QMap<QString,QString> regionWizardMap;
ConfigHelper::CollectAllTaggedValuesFromPage(®ionWizardMap, m_RegionWizard);
QString regString = ConfigHelper::RegionMapToString(®ionWizardMap);
regString.append("|InternalAddress=0.0.0.0|AllowAlternatePorts=False");
QListWidget* widget = ui->listWidgetRegions;
QMap<QString, QMap<QString,QString>* > regions = ConfigHelper::ListWidgetToMap(widget);
QString ret = ConfigHelper::CheckRegionForConflicts(regions, ®ionWizardMap);
if(ret==""){
QString name = regionWizardMap.value("region_name");
name = ConfigHelper::RemoveQuotes(name);
// update region list
QListWidgetItem *item = new QListWidgetItem(ui->listWidgetRegions);
item->setToolTip(regString);
item->setText(name);
ui->listWidgetRegions->addItem(item);
}
else
{
regionConflict = new QMessageBox(this);
regionConflict->setText("Check:" + ret);
regionConflict->exec();
}
}
}
void Wizard::on_btnUpdateRegion_clicked()
{
QListWidgetItem * item = ui->listWidgetRegions->currentItem();
if(item!=0)
{
QMap<QString,QString>* map = ConfigHelper::StringToMap(item->toolTip(), "|", "=");
//QFormLayout* regionLayout = this->m_RegionWizard->GetRegionLayout();
QGridLayout* regionLayout = this->m_RegionWizard->GetRegionGridLayout();
QFormLayout* avatarLayout = this->m_RegionWizard->GetAvatarLayout();
ConfigHelper::MapToFormLayout(map, regionLayout);
ConfigHelper::MapToFormLayout(map, avatarLayout);
m_RegionWizard->GoToStart();
this->m_RegionWizard->exec();
QMap<QString,QString> regionWizardMap;
ConfigHelper::CollectAllTaggedValuesFromPage(®ionWizardMap, m_RegionWizard);
// update listWidgetRegions item
QString tooltip = ConfigHelper::RegionMapToString(®ionWizardMap);
item->setToolTip(tooltip);
QString name = regionWizardMap.value("region_name");
name = ConfigHelper::RemoveQuotes(name);
item->setText(name);
}
}
void Wizard::on_btnBrowseDirectory_clicked()
{
QDir cwd = QDir::current();
QString location = ConfigHelper::SelectPathOrFolder(QString("Select taiga location"),
this, cwd.absolutePath(), selectFolder, "");
ui->lineEditTaigaDir->setText(location);
}
void Wizard::on_checkBoxRobust_clicked()
{
if(this->ui->checkBoxRobust->isChecked())
{
ui->lineEditSimAssetUrl->setEnabled(false);
ui->lineEditSimInventoryUrl->setEnabled(false);
}
else
{
ui->lineEditSimAssetUrl->setEnabled(true);
ui->lineEditSimInventoryUrl->setEnabled(true);
}
}
void Wizard::on_lineEditSimGridUrl_textChanged(QString )
{
if(this->ui->checkBoxRobust->isChecked())
{
QString gridUrlText = ui->lineEditSimGridUrl->text();
ui->lineEditSimAssetUrl->setText(gridUrlText);
ui->lineEditSimInventoryUrl->setText(gridUrlText);
}
}
void Wizard::constructDatabaseConnectionStringAndDBPlugin()
{
QString dbUser = this->ui->lineEditGridDBUser->text();
QString dbPassword = this->ui->lineEditGridDBPassword->text();
QString dbDataSource = this->ui->lineEditDataSource->text();
QString dbPlugin = this->ui->comboDBPlugin->currentText();
ui->labelGridDbPlugin->setText(dbPlugin);
ui->labelSimDBPlugin->setText(dbPlugin);
QString connStr = "";
QString nhibConnStr = "";
QString propertyProvider = "";
QString modrexConnStr = "";
if(dbPlugin=="OpenSim.Data.MySQL.dll")
{
connStr = ConnectionStringHelper::ConstructMySqlConnectionString(dbDataSource, dbUser, dbPassword);
}
else if (dbPlugin=="OpenSim.Data.SQLite.dll")
{
connStr = ConnectionStringHelper::ConstructSqliteConnectionString();
}
nhibConnStr = ConnectionStringHelper::ConstructNHibernateConnectionString(dbDataSource, dbUser, dbPassword, dbPlugin, propertyProvider);
modrexConnStr = ConnectionStringHelper::ConstructModrexConnectionString(dbDataSource, dbUser, dbPassword, dbPlugin);
ui->labelSimDBString->setText(connStr);
ui->labelGridDBString->setText(connStr);
ui->labelGridNhib->setText(nhibConnStr);
ui->labelPropProv->setText(propertyProvider);
ui->labelModRexConnStr->setText(modrexConnStr);
}
void Wizard::on_btnSaveConfigs_clicked()
{
if(ui->lineEditSaveName->text()!="")
{
QDir cwd = QDir::current();
QString name = ui->lineEditSaveName->text();
QString saveDir = ConfigHandler::SAVE_DIR.replace("/", QDir::separator());
QString location = ConfigHelper::SelectPathOrFolder(QString("Select configs location"),
this, cwd.absolutePath() + QDir::separator() + saveDir, selectFolder);
QMap<QString,QString>* uiMap = new QMap<QString,QString>();
ConfigHelper::CollectAllTaggedValuesFromPage(uiMap, this);
m_configHandler.SaveConfigs(m_GridConfig, m_JoinGrid, m_Regions, uiMap, name, location);
}
else
{
QMessageBox box;
box.setText("Give name to configuration first");
box.exec();
}
}
void Wizard::loadDefaults()
{
ConfigHelper::SetConfigValuesToPage(m_configHandler.m_Defaults->m_Sections, this);
setRegionsFromIni();
}
void Wizard::setRegionsFromIni()
{
QString key = m_configHandler.m_RegionIni->m_Sections.keys().at(0);
foreach(QString region_name, m_configHandler.m_RegionIni->m_Sections.keys())
{
QMap<QString,QString>* map = m_configHandler.m_RegionIni->m_Sections.value(region_name);
map->insert("region_name", region_name);
QString toolTip = ConfigHelper::RegionMapToString(map);
QListWidgetItem* item = new QListWidgetItem(ui->listWidgetRegions);
item->setToolTip(toolTip);
item->setText(region_name);
ui->listWidgetRegions->addItem(item);
}
}
void Wizard::ClearRegions()
{
ui->listWidgetRegions->clear();
}
void Wizard::on_btnRemoveRegion_clicked()
{
if(ui->listWidgetRegions->count()==1)
{
//
m_regionNotification = new QMessageBox(this);
m_regionNotification->setText("Must have at least one region configured, use update to update region");
m_regionNotification->show();
return;
}
int row = ui->listWidgetRegions->currentRow();
if(row!=-1)
{
QListWidgetItem* item = ui->listWidgetRegions->takeItem(row);
if(item!=0)
{
delete item;
}
}
}
void Wizard::setDatabasesFromConfig()
{
QStringList dbNames = m_configHandler.GetDatabasesFromConfigIni();
ui->listWidgetDBNames->clear();
foreach(QString dbName, dbNames){
ui->listWidgetDBNames->addItem(dbName);
}
}
void Wizard::on_btnChangeDataBaseNames_clicked()
{
DatabaseDialog dbd(this);
// read config values and set them to dialog
//QMap<QString, QString>* setDbNames = new QMap<QString, QString>();
QMap<QString, QMap<QString,QString>* >& configIniSections = this->m_configHandler.m_ConfigSetupIni->m_Sections;
QString simulator_db_name = getCurrentDbName(configIniSections, "sim_db_connection_string", "OpenSim.ini", "Startup:storage_connection_string");
QString asset_service_db_name = getCurrentDbName(configIniSections, "grid_db_connection_string", "OpenSim.Server.ini", "AssetService:ConnectionString");
QString inventory_service_db_name = getCurrentDbName(configIniSections, "grid_db_connection_string", "OpenSim.Server.ini", "InventoryService:ConnectionString");
QString grid_service_db_name = getCurrentDbName(configIniSections, "grid_db_connection_string", "OpenSim.Server.ini", "GridService:ConnectionString");
QString user_service_db_name = getCurrentDbName(configIniSections, "grid_db_connection_string", "UserServer_Config.xml", "Config:database_connect");
QString messaging_service_db_name = getCurrentDbName(configIniSections, "grid_db_connection_string", "MessagingServer_Config.xml", "Config:database_connect");
QString nhibernate_service_db_name = getCurrentDbName(configIniSections, "grid_nhibernate", "OpenSim.Server.ini", "CableBeachService:ConnectionString");
QString modrex_db_name = getCurrentDbName(configIniSections, "modrex_db_connection_string", "addon-modules/ModreX/config/modrex.ini", "realXtend:db_connectionstring");
QMap<QString, QString>* names = new QMap<QString, QString>();
names->insert("simulator_db_name", simulator_db_name);
names->insert("asset_service_db_name", asset_service_db_name);
names->insert("inventory_service_db_name", inventory_service_db_name);
names->insert("grid_service_db_name", grid_service_db_name);
names->insert("user_service_db_name", user_service_db_name);
names->insert("messaging_service_db_name", messaging_service_db_name);
names->insert("nhibernate_service_db_name", nhibernate_service_db_name);
names->insert("modrex_db_name", modrex_db_name);
dbd.SetDatabaseNames(names);
dbd.exec();
if(dbd.result()==Accepted)
{
// do config editing
QMap<QString, QString>* dbNames = dbd.GetDatabaseNames();
QString simulator_db_name = dbNames->value("simulator_db_name");
setCurrentDbName(configIniSections, "sim_db_connection_string", "OpenSim.ini", "Startup:storage_connection_string", dbNames->value("simulator_db_name"));
setCurrentDbName(configIniSections, "grid_db_connection_string", "OpenSim.Server.ini", "AssetService:ConnectionString", dbNames->value("asset_service_db_name"));
setCurrentDbName(configIniSections, "grid_db_connection_string", "OpenSim.Server.ini", "InventoryService:ConnectionString", dbNames->value("inventory_service_db_name"));
setCurrentDbName(configIniSections, "grid_db_connection_string", "OpenSim.Server.ini", "GridService:ConnectionString", dbNames->value("grid_service_db_name"));
setCurrentDbName(configIniSections, "grid_db_connection_string", "UserServer_Config.xml", "Config:database_connect", dbNames->value("user_service_db_name"));
setCurrentDbName(configIniSections, "grid_db_connection_string", "MessagingServer_Config.xml", "Config:database_connect", dbNames->value("messaging_service_db_name"));
setCurrentDbName(configIniSections, "grid_nhibernate", "OpenSim.Server.ini", "CableBeachService:ConnectionString", dbNames->value("nhibernate_service_db_name"));
setCurrentDbName(configIniSections, "modrex_db_connection_string", "addon-modules/ModreX/config/modrex.ini", "realXtend:db_connectionstring",
dbNames->value("modrex_db_name"));
m_configHandler.m_ConfigSetupIni->UpdateFile();
QString cwd = QDir::currentPath();
QString sep = QDir::separator();
cwd = cwd.replace("\\", sep);
cwd = cwd.replace("/", sep);
//QString savePath = cwd + sep + "templates" + sep + "ConfigSetup.ini";
QString savePath = cwd + sep + "templates";
m_configHandler.m_ConfigSetupIni->SaveFile(savePath);
setDatabasesFromConfig();
}
}
void Wizard::setWritableFiles()
{
if(m_GridConfig)
{
ui->listWidgetFilesToWrite->addItem("OpenSim.Server.ini");
ui->listWidgetFilesToWrite->addItem("OpenSim.ini");
ui->listWidgetFilesToWrite->addItem("UserServer_Config.xml");
ui->listWidgetFilesToWrite->addItem("MessagingServer_Config.xml");
ui->listWidgetFilesToWrite->addItem("Regions.ini");
ui->listWidgetFilesToWrite->addItem("Modrex.ini");
}
else
{
ui->listWidgetFilesToWrite->addItem("Regions.ini");
}
}
void Wizard::on_lineEditGridDBPassword_textChanged(QString )
{
}
QString Wizard::getCurrentDbName(QMap<QString, QMap<QString,QString>* >& configIniSections, QString sectionName, QString fileName, QString searchString)
{
QString settingString = ((QMap<QString,QString>*)configIniSections.value(sectionName))->value(fileName);
int p0 = settingString.indexOf(searchString,0);
int p1 = settingString.indexOf("|", p0) + 1;
int p2 = settingString.indexOf(")", p1);
int len = p2 - p1;
QString db_name = settingString.mid(p1,len);
return db_name;
}
void Wizard::setCurrentDbName(QMap<QString, QMap<QString,QString>* >& configIniSections, QString sectionName, QString fileName, QString searchString, QString newName)
{
// find and cut down to 3 pieces, remove piece n. 2 and attach newName, and set it to configIniSections
QString settingString = ((QMap<QString,QString>*)configIniSections.value(sectionName))->value(fileName);
int p0 = settingString.indexOf(searchString,0);
int p1 = settingString.indexOf("|", p0) + 1;
int p2 = settingString.indexOf(")", p1);
//int len = p2 - p1;
QString string1 = settingString.left(p1);
//QString string2 = settingString.mid(p1, len);
QString string3 = settingString.mid(p2);
string1.append(newName);
string1.append(string3);
configIniSections.value(sectionName)->insert(fileName, string1);
}
void Wizard::on_lineEditSaveName_textChanged(QString )
{
QString saveName = ui->lineEditSaveName->text();
if(saveName!="")
{
ui->btnSaveConfigs->setEnabled(true);
}
else
{
ui->btnSaveConfigs->setEnabled(false);
}
}
QList<int> Wizard::GetRegionPorts()
{
QList<int> ports;
for(int i=0;i<this->ui->listWidgetRegions->count();i++)
{
QListWidgetItem* qlwi = ui->listWidgetRegions->item(i);
QString key = "sim_region_number_" + QString("%1").arg(i);
QString val = qlwi->toolTip();
QMap<QString,QString>* map = ConfigHelper::StringToMap(val, "|", "=");
QString portStr = map->value("InternalPort");
portStr = ConfigHelper::RemoveQuotes(portStr);
int port = portStr.toInt();
ports.append(port);
}
return ports;
}
void Wizard::SetDataBaseParams()
{
QString dbPlugin = ui->comboDBPlugin->currentText();
QString connStr = ui->labelSimDBString->text();
QString user = "";
QString passWord = "";
QString dataSource = "";
ConnectionStringHelper::DBParamsFromConnectionString(dbPlugin, connStr, user, passWord, dataSource);
ui->lineEditDataSource->setText(dataSource);
ui->lineEditGridDBUser->setText(user);
ui->lineEditGridDBPassword->setText(passWord);
}
void Wizard::on_comboDBPlugin_currentIndexChanged(QString text)
{
if(text=="OpenSim.Data.MySQL.dll")
{
ui->lineEditDataSource->setEnabled(true);
ui->lineEditGridDBUser->setEnabled(true);
ui->lineEditGridDBPassword->setEnabled(true);
}
else if (text=="OpenSim.Data.SQLite.dll")
{
ui->lineEditDataSource->setEnabled(false);
ui->lineEditGridDBUser->setEnabled(false);
ui->lineEditGridDBPassword->setEnabled(false);
}
}