Don't redirect stdout for standalone exe invocation

This commit is contained in:
Cameron Gutman 2020-09-07 10:30:44 -07:00
parent 851eac0e72
commit f7de095417

View File

@ -833,13 +833,15 @@ void UpdatePcpPinholes()
free(addresses);
}
void ResetLogFile()
void ResetLogFile(bool standaloneExe)
{
char oldLogFilePath[MAX_PATH + 1];
char currentLogFilePath[MAX_PATH + 1];
char timeString[MAX_PATH + 1] = {};
SYSTEMTIME time;
if (!standaloneExe) {
char oldLogFilePath[MAX_PATH + 1];
char currentLogFilePath[MAX_PATH + 1];
ExpandEnvironmentStringsA("%ProgramData%\\MISS\\GSv6Fwd-old.log", oldLogFilePath, sizeof(oldLogFilePath));
ExpandEnvironmentStringsA("%ProgramData%\\MISS\\GSv6Fwd-current.log", currentLogFilePath, sizeof(currentLogFilePath));
@ -852,6 +854,7 @@ void ResetLogFile()
// Redirect stdout to this new file
freopen(currentLogFilePath, "w", stdout);
}
// Print a log header
printf("IPv6 Forwarder for GameStream v" VER_VERSION_STR "\n");
@ -862,12 +865,12 @@ void ResetLogFile()
printf("The current UTC time is: %s\n", timeString);
}
int Run(void)
int Run(bool standaloneExe)
{
int err;
WSADATA data;
ResetLogFile();
ResetLogFile(standaloneExe);
HANDLE ifaceChangeEvent = CreateEvent(nullptr, true, false, nullptr);
@ -912,7 +915,7 @@ int Run(void)
break;
}
ResetLogFile();
ResetLogFile(standaloneExe);
}
return 0;
@ -964,7 +967,7 @@ ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv)
SetServiceStatus(ServiceStatusHandle, &ServiceStatus);
// Start the relay
err = Run();
err = Run(false);
if (err != 0) {
ServiceStatus.dwCurrentState = SERVICE_STOPPED;
ServiceStatus.dwWin32ExitCode = err;
@ -982,7 +985,7 @@ static const SERVICE_TABLE_ENTRY ServiceTable[] = {
int main(int argc, char* argv[])
{
if (argc == 2 && !strcmp(argv[1], "exe")) {
Run();
Run(true);
return 0;
}