@@ -143,41 +143,39 @@ bool Model::setLink(int id) {
143143}
144144
145145void Model::setupGame (int id) {
146- std::array<QVector<QString>, 2 > list = data.getFileList (id);
147- const size_t s = list[0 ].size ();
148- const size_t sm = list[1 ].size ();
149- if (s != sm) {
150- qDebug ()
151- << " Corrupt list, there seems to bee"
152- << " more or less checksums for the files\n " ;
153- assert (false );
154- }
146+ QVector<FileList> list = data.getFileList (id);
147+ const size_t s = list.size ();
155148 assert (s != 0 );
156- const QString sd = " /Original.TR" + QString::number (id) +" /" ;
157- const QString sg = getGameDirectory (id) + " /" ;
149+
150+ const QString levelPath = " /Original.TR" + QString::number (id) +" /" ;
151+ const QString gamePath = getGameDirectory (id) + " /" ;
152+
158153 for (size_t i = 0 ; i < s; i++) {
159- const QString& fFile = list[0 ][i];
160- const QString& fMd5sum = list[1 ][i];
161- const QString& calculated = fileManager.calculateMD5 (sg+fFile , true );
162- if (fMd5sum == calculated) {
163- fileManager.copyFile (sg+fFile , sd+fFile , true );
154+ const QString levelFile = QString (" %1%2" ).arg (levelPath, list[i].path );
155+ const QString gameFile = QString (" %1%2" ).arg (gamePath, list[i].path );
156+ const QString calculated = fileManager.calculateMD5 (gameFile, true );
157+
158+ if (list[i].md5sum == calculated) {
159+ fileManager.copyFile (gameFile, levelFile, true );
164160 } else {
165- qDebug () << " Original file was modified, had" << fMd5sum
161+ qDebug () << " Original file was modified, had" << list[i]. md5sum
166162 << " got " << calculated << " for file "
167- << fFile << Qt::endl;
168- fileManager.cleanWorkingDir (sd + fFile );
163+ << list[i]. path << Qt::endl;
164+ fileManager.cleanWorkingDir (levelPath );
169165 break ;
170166 }
171167 }
172- if (fileManager.backupGameDir (sg)) {
173- const QString src = sd.chopped (1 );
174- const QString des = sg.chopped (1 );
168+ if (fileManager.backupGameDir (gamePath)) {
169+ // remove the ending '/' and instantly link to
170+ // the game directory link to new game directory
171+ const QString src = levelPath.chopped (1 );
172+ const QString des = gamePath.chopped (1 );
175173 if (!fileManager.linkGameDir (src, des)) {
176- checkCommonFiles ();
174+ checkCommonFiles (); // TODO(noisecode3): Remove this
177175 return ;
178176 }
179177 }
180- checkCommonFiles ();
178+ checkCommonFiles (); // TODO(noisecode3): Remove this
181179}
182180
183181bool Model::getGame (int id) {
0 commit comments