@@ -320,6 +320,74 @@ void NexusInterface::setUserAccount(const APIUserAccount& user)
320
320
emit requestsChanged (getAPIStats (), m_User);
321
321
}
322
322
323
+ void NexusInterface::interpretNonNexusFileName (const QString& fileName, QString& modName,
324
+ int & modID, bool query)
325
+ {
326
+ qDebug (" executing NexusInterface::interpretNonNexusFileName" );
327
+ // guess the mod name from the file name
328
+ static const QRegularExpression complex (
329
+ R"( ^([a-zA-Z0-9_'"\-.() ]*?)([-_ ][VvRr]+[0-9]+(?:(?:[\.][0-9]+){0,2}|(?:[_][0-9]+){0,2}|(?:[-.][0-9]+){0,2})?[ab]?)??-([1-9][0-9]+)?-.*?\.(zip|rar|7z))" );
330
+ // complex regex explanation:
331
+ // group 1: modname.
332
+ // group 2: optional version,
333
+ // assumed to start with v (empty most of the time).
334
+ // group 3: NexusId,
335
+ // assumed wrapped in "-", will miss single digit IDs for better accuracy.
336
+ // If no id is present the whole regex does not match.
337
+ static const QRegularExpression simple (R"( ^[^a-zA-Z]*([a-zA-Z_ ]+))" );
338
+ auto complexMatch = complex.match (fileName);
339
+ auto simpleMatch = simple.match (fileName);
340
+
341
+ // assume not found
342
+ modID = -1 ;
343
+
344
+ if (complexMatch.hasMatch ()) {
345
+ modName = complexMatch.captured (1 );
346
+ if (!query && !complexMatch.captured (3 ).isNull ()) {
347
+ modID = 0 ; // Todo when other website made an API
348
+ }
349
+ } else if (simpleMatch.hasMatch ()) {
350
+ modName = simpleMatch.captured (0 );
351
+ } else {
352
+ modName.clear ();
353
+ }
354
+
355
+ if (query) {
356
+ SelectionDialog selection (tr (" Please pick the mod ID for \" %1\" " ).arg (fileName));
357
+ int index = 0 ;
358
+ auto splits = fileName.split (QRegularExpression (" [^0-9]" ), Qt::KeepEmptyParts);
359
+ for (auto substr : splits) {
360
+ bool ok = false ;
361
+ int value = substr.toInt (&ok);
362
+ if (ok) {
363
+ QString highlight (fileName);
364
+ highlight.insert (index, " *" );
365
+ highlight.insert (index + substr.length () + 2 , " * " );
366
+
367
+ QStringList choice;
368
+ choice << substr;
369
+ choice << (index > 0 ? fileName.left (index - 1 ) : substr);
370
+ selection.addChoice (substr, highlight, choice);
371
+ }
372
+ index += substr.length () + 1 ;
373
+ }
374
+
375
+ if (selection.numChoices () > 0 ) {
376
+ if (selection.exec () == QDialog::Accepted) {
377
+ auto choice = selection.getChoiceData ().toStringList ();
378
+ modID = choice.at (0 ).toInt ();
379
+ modName = choice.at (1 );
380
+ modName = modName.replace (' _' , ' ' ).trimmed ();
381
+ log::debug (" user selected mod ID {} and mod name \" {}\" " , modID, modName);
382
+ } else {
383
+ log::debug (" user canceled mod ID selection" );
384
+ }
385
+ } else {
386
+ log::debug (" no possible mod IDs found in file name" );
387
+ }
388
+ }
389
+ }
390
+
323
391
void NexusInterface::interpretNexusFileName (const QString& fileName, QString& modName,
324
392
int & modID, bool query)
325
393
{
0 commit comments