mirror of
https://github.com/huderlem/porymap.git
synced 2026-04-19 16:17:33 -05:00
Update git search error messages
This commit is contained in:
parent
96664e9680
commit
31cf00de8b
|
|
@ -352,6 +352,8 @@ private:
|
|||
void setLayoutOnlyMode(bool layoutOnly);
|
||||
|
||||
bool isInvalidProject(Project *project);
|
||||
bool checkProjectSanity(Project *project);
|
||||
bool checkProjectVersion(Project *project);
|
||||
bool loadProjectData();
|
||||
bool setProjectUI();
|
||||
void clearProjectUI();
|
||||
|
|
|
|||
|
|
@ -725,39 +725,50 @@ bool MainWindow::loadProjectData() {
|
|||
}
|
||||
|
||||
bool MainWindow::isInvalidProject(Project *project) {
|
||||
if (!project->sanityCheck()) {
|
||||
logWarn(QString("The directory '%1' failed the project sanity check.").arg(project->root));
|
||||
return !(checkProjectSanity(project) && checkProjectVersion(project));
|
||||
}
|
||||
|
||||
ErrorMessage msgBox(QStringLiteral("The selected directory appears to be invalid."), porysplash);
|
||||
msgBox.setInformativeText(QString("The directory '%1' is missing key files.\n\n"
|
||||
"Make sure you selected the correct project directory "
|
||||
"(the one used to make your .gba file, e.g. 'pokeemerald').").arg(project->root));
|
||||
auto tryAnyway = msgBox.addButton("Try Anyway", QMessageBox::ActionRole);
|
||||
msgBox.exec();
|
||||
bool MainWindow::checkProjectSanity(Project *project) {
|
||||
if (project->sanityCheck())
|
||||
return true;
|
||||
|
||||
// The user may choose to try to load this project anyway.
|
||||
logWarn(QString("The directory '%1' failed the project sanity check.").arg(project->root));
|
||||
|
||||
ErrorMessage msgBox(QStringLiteral("The selected directory appears to be invalid."), porysplash);
|
||||
msgBox.setInformativeText(QString("The directory '%1' is missing key files.\n\n"
|
||||
"Make sure you selected the correct project directory "
|
||||
"(the one used to make your .gba file, e.g. 'pokeemerald').").arg(project->root));
|
||||
auto tryAnyway = msgBox.addButton("Try Anyway", QMessageBox::ActionRole);
|
||||
msgBox.exec();
|
||||
if (msgBox.clickedButton() == tryAnyway) {
|
||||
// The user has chosen to try to load this project anyway.
|
||||
// This will almost certainly fail, but they'll get a more specific error message.
|
||||
if (msgBox.clickedButton() != tryAnyway){
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MainWindow::checkProjectVersion(Project *project) {
|
||||
QString error;
|
||||
int projectVersion = project->getSupportedMajorVersion(&error);
|
||||
if (projectVersion <= 0) {
|
||||
if (projectVersion < 0) {
|
||||
// Failed to identify a supported major version.
|
||||
// We can't draw any conclusions from this, so we don't consider the project to be invalid.
|
||||
logWarn(error.isEmpty() ? QStringLiteral("Unable to identify project's Porymap version.") : error);
|
||||
QString msg = QStringLiteral("Failed to check project version");
|
||||
logWarn(error.isEmpty() ? msg : QString("%1: '%2'").arg(msg).arg(error));
|
||||
} else {
|
||||
logInfo(QString("Successful project version check. Supports at least Porymap v%1.").arg(projectVersion));
|
||||
QString msg = QStringLiteral("Successfully checked project version. ");
|
||||
logInfo(msg + ((projectVersion != 0) ? QString("Supports at least Porymap v%1").arg(projectVersion)
|
||||
: QStringLiteral("Too old for any Porymap version")));
|
||||
|
||||
if (projectVersion < porymapVersion.majorVersion() && projectConfig.forcedMajorVersion < porymapVersion.majorVersion()) {
|
||||
// We were unable to find the necessary changes for Porymap's current major version.
|
||||
// Warn the user that this might mean their project is missing breaking changes.
|
||||
// Unless they have explicitly suppressed this message, warn the user that this might mean their project is missing breaking changes.
|
||||
// Note: Do not report 'projectVersion' to the user in this message. We've already logged it for troubleshooting.
|
||||
// It is very plausible that the user may have reproduced the required changes in an
|
||||
// unknown commit, rather than merging the required changes directly from the base repo.
|
||||
// In this case the 'projectVersion' may actually be too old to use for their repo.
|
||||
ErrorMessage msgBox(QStringLiteral("Your project may be incompatible!"), this);
|
||||
ErrorMessage msgBox(QStringLiteral("Your project may be incompatible!"), porysplash);
|
||||
msgBox.setInformativeText(QString("Make sure '%1' has all the required changes for Porymap version %2."
|
||||
"") // TODO: Once we have a wiki or manual page describing breaking changes, link that here.
|
||||
.arg(project->getProjectTitle())
|
||||
|
|
@ -765,13 +776,13 @@ bool MainWindow::isInvalidProject(Project *project) {
|
|||
auto tryAnyway = msgBox.addButton("Try Anyway", QMessageBox::ActionRole);
|
||||
msgBox.exec();
|
||||
if (msgBox.clickedButton() != tryAnyway){
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
// User opted to try with this version anyway. Don't warn them about this version again.
|
||||
projectConfig.forcedMajorVersion = porymapVersion.majorVersion();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void MainWindow::showProjectOpenFailure() {
|
||||
|
|
|
|||
|
|
@ -79,13 +79,15 @@ bool Project::sanityCheck() {
|
|||
// We can use the project's git history (if it has one, and we're able to get it) to make a reasonable guess.
|
||||
// We know the hashes of the commits in the base repos that contain breaking changes, so if we find one of these then the project
|
||||
// should support at least up to that Porymap major version. If this fails for any reason it returns a version of -1.
|
||||
// This has relatively tight timeout windows (500ms for each process, compared to the default 30,000ms). This version check
|
||||
// is not important enough to significantly slow down project launch, we'd rather just timeout.
|
||||
int Project::getSupportedMajorVersion(QString *errorOut) {
|
||||
// This has relatively tight timeout windows (500ms for each process, compared to the default 30,000ms). This version check
|
||||
// is not important enough to significantly slow down project launch, we'd rather just timeout.
|
||||
const int timeoutLimit = 500;
|
||||
const int failureVersion = -1;
|
||||
QString gitPath = QStandardPaths::findExecutable("git");
|
||||
QString gitName = "git";
|
||||
QString gitPath = QStandardPaths::findExecutable(gitName);
|
||||
if (gitPath.isEmpty()) {
|
||||
if (errorOut) *errorOut = QStringLiteral("Failed to identify project history: Unable to locate git.");
|
||||
if (errorOut) *errorOut = QString("Unable to locate %1.").arg(gitName);
|
||||
return failureVersion;
|
||||
}
|
||||
|
||||
|
|
@ -95,14 +97,14 @@ int Project::getSupportedMajorVersion(QString *errorOut) {
|
|||
process.setReadChannel(QProcess::StandardOutput);
|
||||
process.setStandardInputFile(QProcess::nullDevice()); // We won't have any writing to do.
|
||||
|
||||
// First we need to know which (if any) known git history this project belongs to.
|
||||
// First we need to know which (if any) known history this project belongs to.
|
||||
// We'll get the root commit, then compare it to the known root commits for the base project repos.
|
||||
static const QStringList args_getRootCommit = { "rev-list", "--max-parents=0", "HEAD" };
|
||||
process.setArguments(args_getRootCommit);
|
||||
process.start();
|
||||
if (!process.waitForFinished(500) || process.exitStatus() != QProcess::ExitStatus::NormalExit || process.exitCode() != 0) {
|
||||
if (!process.waitForFinished(timeoutLimit) || process.exitStatus() != QProcess::ExitStatus::NormalExit || process.exitCode() != 0) {
|
||||
if (errorOut) {
|
||||
*errorOut = QStringLiteral("Failed to identify project history");
|
||||
*errorOut = QStringLiteral("Failed to identify commit history");
|
||||
if (process.error() != QProcess::UnknownError && !process.errorString().isEmpty()) {
|
||||
errorOut->append(QString(": %1").arg(process.errorString()));
|
||||
} else {
|
||||
|
|
@ -145,8 +147,8 @@ int Project::getSupportedMajorVersion(QString *errorOut) {
|
|||
}},
|
||||
};
|
||||
if (!historyMap.contains(rootCommit)) {
|
||||
// Either this repo does not share history with one of the base repos,
|
||||
// (that's ok, don't report an error) or we got some unexpected result.
|
||||
// Either this repo does not share history with one of the base repos, or we got some unexpected result.
|
||||
if (errorOut) *errorOut = QStringLiteral("Unrecognized commit history");
|
||||
return failureVersion;
|
||||
}
|
||||
|
||||
|
|
@ -162,9 +164,9 @@ int Project::getSupportedMajorVersion(QString *errorOut) {
|
|||
}
|
||||
process.setArguments({ "merge-base", "--is-ancestor", commitHash, "HEAD" });
|
||||
process.start();
|
||||
if (!process.waitForFinished(500) || process.exitStatus() != QProcess::ExitStatus::NormalExit) {
|
||||
if (!process.waitForFinished(timeoutLimit) || process.exitStatus() != QProcess::ExitStatus::NormalExit) {
|
||||
if (errorOut) {
|
||||
*errorOut = QStringLiteral("Failed to identify project's supported Porymap version");
|
||||
*errorOut = QStringLiteral("Failed to search commit history");
|
||||
if (process.error() != QProcess::UnknownError && !process.errorString().isEmpty()) {
|
||||
errorOut->append(QString(": %1").arg(process.errorString()));
|
||||
} else {
|
||||
|
|
@ -180,7 +182,8 @@ int Project::getSupportedMajorVersion(QString *errorOut) {
|
|||
return versionNum;
|
||||
}
|
||||
}
|
||||
return failureVersion;
|
||||
// We recognized the commit history, but it's too old for any version of Porymap to support.
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Project::load() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user