1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Merge pull request #3442 from Laserlicht/autodetect_windows

Autodetect and copy installed heroes on windows
This commit is contained in:
Ivan Savenko 2024-01-10 16:37:55 +02:00 committed by GitHub
commit 4ef7f93514
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 7 deletions

View File

@ -134,7 +134,16 @@ void FirstLaunchView::activateTabHeroesData()
ui->pushButtonDataHelp->hide();
ui->labelDataHelp->hide();
}
heroesDataUpdate();
if(heroesDataUpdate())
return;
QString installPath = getHeroesInstallDir();
if(!installPath.isEmpty())
{
auto reply = QMessageBox::question(this, tr("Heroes III installation found!"), tr("Copy data to VCMI folder?"), QMessageBox::Yes | QMessageBox::No);
if(reply == QMessageBox::Yes)
copyHeroesData(installPath);
}
}
void FirstLaunchView::activateTabModPreset()
@ -164,12 +173,14 @@ void FirstLaunchView::languageSelected(const QString & selectedLanguage)
mainWindow->updateTranslation();
}
void FirstLaunchView::heroesDataUpdate()
bool FirstLaunchView::heroesDataUpdate()
{
if(heroesDataDetect())
bool detected = heroesDataDetect();
if(detected)
heroesDataDetected();
else
heroesDataMissing();
return detected;
}
void FirstLaunchView::heroesDataMissing()
@ -254,9 +265,26 @@ void FirstLaunchView::forceHeroesLanguage(const QString & language)
node->String() = language.toStdString();
}
void FirstLaunchView::copyHeroesData()
QString FirstLaunchView::getHeroesInstallDir()
{
QDir sourceRoot = QFileDialog::getExistingDirectory(this, "", "", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
#ifdef VCMI_WINDOWS
QString gogPath = QSettings("HKEY_LOCAL_MACHINE\\SOFTWARE\\GOG.com\\Games\\1207658787", QSettings::NativeFormat).value("path").toString();
if(!gogPath.isEmpty())
return gogPath;
QString cdPath = QSettings("HKEY_LOCAL_MACHINE\\SOFTWARE\\New World Computing\\Heroes of Might and Magic® III\\1.0", QSettings::NativeFormat).value("AppPath").toString();
if(!cdPath.isEmpty())
return cdPath;
#endif
return QString{};
}
void FirstLaunchView::copyHeroesData(const QString & path)
{
QDir sourceRoot = QDir(path);
if(path.isEmpty())
sourceRoot.setPath(QFileDialog::getExistingDirectory(this, {}, {}, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks));
if(!sourceRoot.exists())
return;

View File

@ -42,7 +42,7 @@ class FirstLaunchView : public QWidget
void languageSelected(const QString & languageCode);
// Tab Heroes III Data
void heroesDataUpdate();
bool heroesDataUpdate();
bool heroesDataDetect();
void heroesDataMissing();
@ -51,7 +51,8 @@ class FirstLaunchView : public QWidget
void heroesLanguageUpdate();
void forceHeroesLanguage(const QString & language);
void copyHeroesData();
QString getHeroesInstallDir();
void copyHeroesData(const QString & path = {});
// Tab Mod Preset
void modPresetUpdate();