-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Game exe path command line argument #713
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c1c9d3a
feat: --exePath commandline argument
ToeKneeRED b7aa972
tweak: add explicit target exe error
ToeKneeRED 8da8dd8
tweak: clang format
ToeKneeRED 1bc1a1b
fix: properly terminate process when no exe path given
ToeKneeRED 50488e3
tweak: safer args bounds check + more explicit errors
ToeKneeRED 0f9c6ad
tweak: remove global exePath & titlePath
ToeKneeRED 855a9b1
tweak: clang format
ToeKneeRED 79f3ba8
tweak: const naming
ToeKneeRED File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include "PathArgument.h" | ||
|
||
#include "TargetConfig.h" | ||
|
||
#include "Utils/Error.h" | ||
#include "utils/Registry.h" | ||
|
||
#include <filesystem> | ||
|
||
namespace oobe | ||
{ | ||
using namespace TiltedPhoques; | ||
|
||
namespace | ||
{ | ||
constexpr wchar_t kTiltedRegistryPath[] = LR"(Software\TiltedPhoques\TiltedEvolution\)" SHORT_NAME; | ||
|
||
#define DIE_NOW(err) \ | ||
{ \ | ||
Die(err, true); \ | ||
return false; \ | ||
} | ||
|
||
bool ValidatePath(const std::wstring& acPath) | ||
{ | ||
const std::wstring cTitlePath = acPath.substr(0, acPath.find_last_of('\\')); | ||
std::wstring errorText{}; | ||
|
||
if (acPath.find_last_of('\\') == std::string::npos || acPath.ends_with(*"\\")) | ||
{ | ||
SetLastError(ERROR_BAD_PATHNAME); | ||
errorText += L"Invalid path\n"; | ||
} | ||
|
||
if (!acPath.ends_with(L".exe")) | ||
{ | ||
SetLastError(ERROR_BAD_ARGUMENTS); | ||
errorText += acPath.substr(acPath.find_last_of('\\') + 1, acPath.back()) + L" is not an executable file\n"; | ||
} | ||
else if (!acPath.ends_with(TARGET_NAME L".exe")) | ||
{ | ||
SetLastError(ERROR_FILE_NOT_FOUND); | ||
errorText += TARGET_NAME L".exe not found\n"; | ||
} | ||
|
||
if (!std::filesystem::exists(acPath) || !std::filesystem::exists(cTitlePath)) | ||
{ | ||
SetLastError(ERROR_BAD_PATHNAME); | ||
errorText += L"Path does not exist\n"; | ||
} | ||
|
||
if (!errorText.empty()) | ||
{ | ||
errorText += L"\nPath: " + acPath; | ||
DIE_NOW(errorText.c_str()) | ||
} | ||
|
||
return true; | ||
} | ||
} // namespace | ||
|
||
bool PathArgument(const std::string& acPath) | ||
{ | ||
const std::wstring cExePath = std::wstring(acPath.begin(), acPath.end()); | ||
const std::wstring cTitlePath = cExePath.substr(0, cExePath.find_last_of('\\')); | ||
|
||
if (!ValidatePath(cExePath)) | ||
{ | ||
DIE_NOW(L"Failed to validate path") | ||
} | ||
|
||
// Write to registry so oobe::SelectInstall can handle the rest | ||
const bool result = Registry::WriteString<wchar_t>(HKEY_CURRENT_USER, kTiltedRegistryPath, L"TitlePath", cTitlePath) && Registry::WriteString<wchar_t>(HKEY_CURRENT_USER, kTiltedRegistryPath, L"TitleExe", cExePath); | ||
|
||
if (!result) | ||
{ | ||
DIE_NOW(L"Failed to write to registry") | ||
} | ||
|
||
return true; | ||
} | ||
} // namespace oobe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
namespace oobe | ||
{ | ||
bool PathArgument(const std::string& acPath); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit dangerous. The problem arises because there's no guarantee that aArgv[i + 1] is a valid memory location. If "--exePath" is the last argument in the command line, i + 1 would be out of bounds of the aArgv array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be better in 50488e3
(clang formatted after)