mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-22 22:13:35 +02:00
finished hashing error
This commit is contained in:
parent
4103bb9e55
commit
6e29633ccb
@ -359,8 +359,9 @@ void FirstLaunchView::extractGogData()
|
|||||||
return; // should not happen - but avoid deleting wrong folder in any case
|
return; // should not happen - but avoid deleting wrong folder in any case
|
||||||
|
|
||||||
QString tmpFileExe = tempDir.filePath("h3_gog.exe");
|
QString tmpFileExe = tempDir.filePath("h3_gog.exe");
|
||||||
|
QString tmpFileBin = tempDir.filePath("h3_gog-1.bin");
|
||||||
QFile(fileExe).copy(tmpFileExe);
|
QFile(fileExe).copy(tmpFileExe);
|
||||||
QFile(fileBin).copy(tempDir.filePath("h3_gog-1.bin"));
|
QFile(fileBin).copy(tmpFileBin);
|
||||||
|
|
||||||
QString errorText{};
|
QString errorText{};
|
||||||
|
|
||||||
@ -387,6 +388,10 @@ void FirstLaunchView::extractGogData()
|
|||||||
ui->progressBarGog->setValue(progress * 100);
|
ui->progressBarGog->setValue(progress * 100);
|
||||||
qApp->processEvents();
|
qApp->processEvents();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QString hashError;
|
||||||
|
if(!errorText.isEmpty())
|
||||||
|
hashError = Innoextract::getHashError(tmpFileExe, tmpFileBin);
|
||||||
|
|
||||||
ui->progressBarGog->setVisible(false);
|
ui->progressBarGog->setVisible(false);
|
||||||
ui->pushButtonGogInstall->setVisible(true);
|
ui->pushButtonGogInstall->setVisible(true);
|
||||||
@ -395,8 +400,12 @@ void FirstLaunchView::extractGogData()
|
|||||||
QStringList dirData = tempDir.entryList({"data"}, QDir::Filter::Dirs);
|
QStringList dirData = tempDir.entryList({"data"}, QDir::Filter::Dirs);
|
||||||
if(!errorText.isEmpty() || dirData.empty() || QDir(tempDir.filePath(dirData.front())).entryList({"*.lod"}, QDir::Filter::Files).empty())
|
if(!errorText.isEmpty() || dirData.empty() || QDir(tempDir.filePath(dirData.front())).entryList({"*.lod"}, QDir::Filter::Files).empty())
|
||||||
{
|
{
|
||||||
if(!errorText.isEmpty()) //
|
if(!errorText.isEmpty())
|
||||||
|
{
|
||||||
QMessageBox::critical(this, tr("Extracting error!"), errorText, QMessageBox::Ok, QMessageBox::Ok);
|
QMessageBox::critical(this, tr("Extracting error!"), errorText, QMessageBox::Ok, QMessageBox::Ok);
|
||||||
|
if(!hashError.isEmpty())
|
||||||
|
QMessageBox::critical(this, tr("Hash error!"), hashError, QMessageBox::Ok, QMessageBox::Ok);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
QMessageBox::critical(this, tr("No Heroes III data!"), tr("Selected files do not contain Heroes III data!"), QMessageBox::Ok, QMessageBox::Ok);
|
QMessageBox::critical(this, tr("No Heroes III data!"), tr("Selected files do not contain Heroes III data!"), QMessageBox::Ok, QMessageBox::Ok);
|
||||||
tempDir.removeRecursively();
|
tempDir.removeRecursively();
|
||||||
|
@ -61,7 +61,7 @@ QString Innoextract::extract(QString installer, QString outDir, std::function<vo
|
|||||||
return errorText;
|
return errorText;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Innoextract::getHashError(QFile exe, std::optional<QFile> bin)
|
QString Innoextract::getHashError(QString exeFile, QString binFile)
|
||||||
{
|
{
|
||||||
enum filetype
|
enum filetype
|
||||||
{
|
{
|
||||||
@ -101,6 +101,7 @@ QString Innoextract::getHashError(QFile exe, std::optional<QFile> bin)
|
|||||||
int exeSize = 0;
|
int exeSize = 0;
|
||||||
int binSize = 0;
|
int binSize = 0;
|
||||||
|
|
||||||
|
auto exe = QFile(exeFile);
|
||||||
if(exe.open(QFile::ReadOnly)) {
|
if(exe.open(QFile::ReadOnly)) {
|
||||||
QCryptographicHash hash(QCryptographicHash::Algorithm::Sha1);
|
QCryptographicHash hash(QCryptographicHash::Algorithm::Sha1);
|
||||||
if(hash.addData(&exe))
|
if(hash.addData(&exe))
|
||||||
@ -109,21 +110,22 @@ QString Innoextract::getHashError(QFile exe, std::optional<QFile> bin)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
return QString{}; // reading problem
|
return QString{}; // reading problem
|
||||||
if(bin)
|
if(!binFile.isEmpty())
|
||||||
{
|
{
|
||||||
if((*bin).open(QFile::ReadOnly)) {
|
auto bin = QFile(binFile);
|
||||||
|
if(bin.open(QFile::ReadOnly)) {
|
||||||
QCryptographicHash hash(QCryptographicHash::Algorithm::Sha1);
|
QCryptographicHash hash(QCryptographicHash::Algorithm::Sha1);
|
||||||
if(hash.addData(&(*bin)))
|
if(hash.addData(&bin))
|
||||||
binHash = hash.result().toHex().toLower().toStdString();
|
binHash = hash.result().toHex().toLower().toStdString();
|
||||||
binSize = (*bin).size();
|
binSize = bin.size();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return QString{}; // reading problem
|
return QString{}; // reading problem
|
||||||
}
|
}
|
||||||
|
|
||||||
QString hashOutput = tr("Hash:\n") + tr("Exe") + ": " + QString::fromStdString(exeHash) + " (" + QString::number(1) + " " + tr("bytes") + ")";
|
QString hashOutput = tr("Hash:\n") + tr("Exe") + ": " + QString::fromStdString(exeHash) + " (" + QString::number(exeSize) + " " + tr("bytes") + ")";
|
||||||
if(!binHash.empty())
|
if(!binHash.empty())
|
||||||
hashOutput += "\n" + tr("Bin") + ": " + QString::fromStdString(binHash) + " (" + QString::number(1) + " " + tr("bytes") + ")";
|
hashOutput += "\n" + tr("Bin") + ": " + QString::fromStdString(binHash) + " (" + QString::number(binSize) + " " + tr("bytes") + ")";
|
||||||
|
|
||||||
QString foundKnown;
|
QString foundKnown;
|
||||||
QString exeLang;
|
QString exeLang;
|
||||||
@ -139,13 +141,13 @@ QString Innoextract::getHashError(QFile exe, std::optional<QFile> bin)
|
|||||||
binLang = lang;
|
binLang = lang;
|
||||||
it = std::find_if(++it, knownHashes.end(), find);
|
it = std::find_if(++it, knownHashes.end(), find);
|
||||||
}
|
}
|
||||||
if(!exeLang.isEmpty() && !binLang.isEmpty() && exeLang != binLang && bin)
|
if(!exeLang.isEmpty() && !binLang.isEmpty() && exeLang != binLang && !binFile.isEmpty())
|
||||||
return tr("Language mismatch.\n\n") + foundKnown + "\n\n" + hashOutput;
|
return tr("Language mismatch.\n\n") + foundKnown + "\n\n" + hashOutput;
|
||||||
else if((!exeLang.isEmpty() || !binLang.isEmpty()) && bin)
|
else if((!exeLang.isEmpty() || !binLang.isEmpty()) && !binFile.isEmpty())
|
||||||
return tr("Only one file known.\n\n") + foundKnown + "\n\n" + hashOutput;
|
return tr("Only one file known.\n\n") + foundKnown + "\n\n" + hashOutput;
|
||||||
else if(!exeLang.isEmpty() && !bin)
|
else if(!exeLang.isEmpty() && binFile.isEmpty())
|
||||||
return QString{};
|
return QString{};
|
||||||
else if(!exeLang.isEmpty() && bin && exeLang == binLang)
|
else if(!exeLang.isEmpty() && !binFile.isEmpty() && exeLang == binLang)
|
||||||
return QString{};
|
return QString{};
|
||||||
|
|
||||||
return tr("Unknown files. Maybe files are corrupted? Please download again.\n\n") + hashOutput;
|
return tr("Unknown files. Maybe files are corrupted? Please download again.\n\n") + hashOutput;
|
||||||
|
@ -13,5 +13,5 @@ class Innoextract : public QObject
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static QString extract(QString installer, QString outDir, std::function<void (float percent)> cb = nullptr);
|
static QString extract(QString installer, QString outDir, std::function<void (float percent)> cb = nullptr);
|
||||||
QString getHashError(QFile exe, std::optional<QFile> bin);
|
static QString getHashError(QString exeFile, QString binFile);
|
||||||
};
|
};
|
||||||
|
@ -84,7 +84,10 @@ bool ChroniclesExtractor::extractGogInstaller(QString file)
|
|||||||
|
|
||||||
if(!errorText.isEmpty())
|
if(!errorText.isEmpty())
|
||||||
{
|
{
|
||||||
|
QString hashError = Innoextract::getHashError(file, {});
|
||||||
QMessageBox::critical(parent, tr("Extracting error!"), errorText);
|
QMessageBox::critical(parent, tr("Extracting error!"), errorText);
|
||||||
|
if(!hashError.isEmpty())
|
||||||
|
QMessageBox::critical(parent, tr("Hash error!"), hashError, QMessageBox::Ok, QMessageBox::Ok);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user