92 } |
92 } |
93 |
93 |
94 if (!QDir(cfgdir->absolutePath() + "/Schemes").exists()) { |
94 if (!QDir(cfgdir->absolutePath() + "/Schemes").exists()) { |
95 QDir().mkdir(cfgdir->absolutePath() + "/Schemes"); |
95 QDir().mkdir(cfgdir->absolutePath() + "/Schemes"); |
96 } |
96 } |
|
97 QStringList defaultAmmos; |
|
98 for(int i = 0; i < cDefaultAmmos.size(); ++i) |
|
99 { |
|
100 defaultAmmos.append(cDefaultAmmos[i].first.toLower()); |
|
101 } |
97 if (!QDir(cfgdir->absolutePath() + "/Schemes/Ammo").exists()) { |
102 if (!QDir(cfgdir->absolutePath() + "/Schemes/Ammo").exists()) { |
98 qDebug("No /Schemes/Ammo directory found. Trying to import weapon schemes from weapons.ini."); |
103 qDebug("No /Schemes/Ammo directory found. Trying to import weapon schemes from weapons.ini."); |
99 QDir().mkdir(cfgdir->absolutePath() + "/Schemes/Ammo"); |
104 QDir().mkdir(cfgdir->absolutePath() + "/Schemes/Ammo"); |
100 |
105 |
101 QSettings old_wconf(cfgdir->absolutePath() + "/weapons.ini", QSettings::IniFormat); |
106 QSettings old_wconf(cfgdir->absolutePath() + "/weapons.ini", QSettings::IniFormat); |
102 |
107 |
103 QStringList defaultAmmos; |
|
104 for(int i = 0; i < cDefaultAmmos.size(); ++i) |
|
105 { |
|
106 defaultAmmos.append(cDefaultAmmos[i].first); |
|
107 } |
|
108 |
|
109 QStringList keys = old_wconf.allKeys(); |
108 QStringList keys = old_wconf.allKeys(); |
110 int imported = 0; |
109 int imported = 0; |
111 for(int i = 0; i < keys.size(); i++) |
110 for(int i = 0; i < keys.size(); i++) |
112 { |
111 { |
113 if (!defaultAmmos.contains(keys[i])) { |
112 if (!defaultAmmos.contains(keys[i].toLower())) { |
114 wconf->insert(keys[i], fixWeaponSet(old_wconf.value(keys[i]).toString())); |
113 wconf->insert(keys[i], fixWeaponSet(old_wconf.value(keys[i]).toString())); |
115 QFile file(cfgdir->absolutePath() + "/Schemes/Ammo/" + keys[i] + ".hwa"); |
114 QFile file(cfgdir->absolutePath() + "/Schemes/Ammo/" + keys[i] + ".hwa"); |
116 if (file.open(QIODevice::WriteOnly)) { |
115 if (file.open(QIODevice::WriteOnly)) { |
117 QTextStream stream( &file ); |
116 QTextStream stream( &file ); |
118 stream << old_wconf.value(keys[i]).toString() << endl; |
117 stream << old_wconf.value(keys[i]).toString() << endl; |
138 // Chop off file name suffix |
137 // Chop off file name suffix |
139 QString schemeName = schemes[i]; |
138 QString schemeName = schemes[i]; |
140 if (schemeName.endsWith(".hwa", Qt::CaseInsensitive)) { |
139 if (schemeName.endsWith(".hwa", Qt::CaseInsensitive)) { |
141 schemeName.chop(4); |
140 schemeName.chop(4); |
142 } |
141 } |
143 wconf->insert(schemeName, fixWeaponSet(config)); |
142 // Don't load weapon scheme if name collides with any default scheme |
|
143 if (!defaultAmmos.contains(schemeName.toLower())) |
|
144 wconf->insert(schemeName, fixWeaponSet(config)); |
|
145 else |
|
146 qWarning("Weapon scheme \"%s\" not loaded from file, name collides with a default scheme!", qPrintable(schemeName)); |
144 } |
147 } |
145 } |
148 } |
146 |
149 |
147 QString currentState = *cDefaultAmmoStore; |
150 QString currentState = *cDefaultAmmoStore; |
148 |
151 |