Skip to content

Commit

Permalink
Fix multiple instance bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nico-abram committed Dec 11, 2021
1 parent 81c4120 commit 041532a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Core/Platform/PlatformWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,24 @@ namespace Core::Platform {
}

bool isOtherInstanceRunning(int argc, char** argv){
// We create a system-wide mutex with a unique name. If it does not exist, we know
// there are no other instances. This is a fix for an issue where some windows had
// a title of "Etterna" and it generated false positives (Notably explorer on an Etterna folder)
//
// SHA256 of ETTERNA in the middle
CreateMutex(NULL, TRUE, TEXT(" ETTERNA2aced23fdf1270d6a97c9425f957829fce5ad666fec0c6fdfcdae5561f8b905dETTERNA "));
switch (GetLastError()) {
case ERROR_SUCCESS:
// Process was not running already
// We leak the mutex, it is released when our process dies. If another instance
// attempts to start it will now fail here.
return false;
case ERROR_ALREADY_EXISTS:
// Process is running already
default:
// Error occured, not sure whether process is running already.
break;
}
/* Search for the existing window. Prefer to use the class name, which is
* less likely to have a false match, and will match the gameplay window.
* If that fails, try the window name, which should match the loading
Expand Down

0 comments on commit 041532a

Please sign in to comment.