-
Notifications
You must be signed in to change notification settings - Fork 17
/
ConLib.cpp
108 lines (97 loc) · 3.12 KB
/
ConLib.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
/* This file is part of TSRE5.
*
* TSRE5 - train sim game engine and MSTS/OR Editors.
* Copyright (C) 2016 Piotr Gadecki <[email protected]>
*
* Licensed under GNU General Public License 3.0 or later.
*
* See LICENSE.md or https://www.gnu.org/licenses/gpl.html
*/
#include "ConLib.h"
#include "Consist.h"
#include <QDebug>
#include <QFile>
#include <QDir>
#include <QProgressDialog>
#include <QCoreApplication>
int ConLib::jestcon = 0;
std::unordered_map<int, Consist*> ConLib::con;
QVector<QString> ConLib::conFileList;
ConLib::ConLib() {
}
ConLib::~ConLib() {
}
int ConLib::addCon(QString path, QString name) {
QString pathid = (path + "/" + name).toLower();
pathid.replace("\\", "/");
pathid.replace("//", "/");
//qDebug() << pathid;
for ( auto it = con.begin(); it != con.end(); ++it ){
if(it->second == NULL) continue;
if (((Consist*) it->second)->pathid.length() == pathid.length())
if (((Consist*) it->second)->pathid == pathid) {
((Consist*) it->second)->ref++;
qDebug() <<"conid "<< pathid;
return (int)it->first;
}
}
qDebug() << "Nowy " << jestcon << " con: " << pathid;
con[jestcon] = new Consist(pathid, path, name);
return jestcon++;
}
int ConLib::refreshEngDataAll(){
for ( auto it = con.begin(); it != con.end(); ++it ){
if(it->second == NULL) continue;
(it->second)->refreshEngData();
}
return 0;
}
int ConLib::loadAll(QString gameRoot, bool gui){
QString path;
path = gameRoot + "/trains/consists/";
QDir dir(path);
QDir trainDir;
dir.setFilter(QDir::Files);
dir.setNameFilters(QStringList()<<"*.con");
qDebug() << path;
if(!dir.exists())
qDebug() << "not exist";
qDebug() << dir.count() <<" con files";
QProgressDialog *progress = NULL;
if(gui){
progress = new QProgressDialog("Loading CONSISTS...", "", 0, dir.count());
progress->setWindowModality(Qt::WindowModal);
progress->setCancelButton(NULL);
progress->setWindowFlags(Qt::CustomizeWindowHint);
}
int i = 0;
foreach(QString engfile, dir.entryList()){
ConLib::addCon(path,engfile);
if(progress != NULL){
progress->setValue(++i);
QCoreApplication::processEvents(QEventLoop::AllEvents, 50);
}
}
qDebug() << "loaded";
delete progress;
return 0;
}
int ConLib::loadSimpleList(QString gameRoot, bool reload){
if(ConLib::conFileList.size() > 0 && reload == false)
return 0;
ConLib::conFileList.clear();
QString path;
path = gameRoot + "/trains/consists/";
QDir dir(path);
QDir trainDir;
dir.setFilter(QDir::Files);
dir.setNameFilters(QStringList()<<"*.con");
qDebug() << path;
if(!dir.exists())
qDebug() << "not exist";
qDebug() << dir.count() <<" con files";
foreach(QString engfile, dir.entryList())
ConLib::conFileList.push_back(path.toLower()+engfile.toLower());
qDebug() << "loaded";
return 0;
}