Fixed line ending style.

This commit is contained in:
Joerg Henrichs 2017-05-01 08:17:15 +10:00
parent 92709b2ada
commit 29e1541b47
2 changed files with 140 additions and 140 deletions

View File

@ -21,8 +21,8 @@
#include "utils/string_utils.hpp"
#ifdef WIN32
# include <windows.h>
#endif
# include <windows.h>
#endif
Steam * Steam::m_steam = NULL;
@ -32,50 +32,50 @@ Steam::Steam()
m_steam_available = false;
#ifdef WIN32
// Based on: https://msdn.microsoft.com/en-us/library/windows/desktop/ms682499(v=vs.85).aspx
SECURITY_ATTRIBUTES sec_attr;
// Set the bInheritHandle flag so pipe handles are inherited.
sec_attr.nLength = sizeof(SECURITY_ATTRIBUTES);
sec_attr.bInheritHandle = TRUE;
sec_attr.lpSecurityDescriptor = NULL;
// Create a pipe for the child process's STDOUT.
if (!CreatePipe(&m_child_stdout_read, &m_child_stdout_write, &sec_attr, 0))
{
Log::error("Steam", "Error creating StdoutRd CreatePipe");
return;
}
// Ensure the read handle to the pipe for STDOUT is not inherited.
if (!SetHandleInformation(m_child_stdout_read, HANDLE_FLAG_INHERIT, 0))
{
Log::error("Steam", "Stdout SetHandleInformation");
return;
}
// Create a pipe for the child process's STDIN.
if (!CreatePipe(&m_child_stdin_read, &m_child_stdin_write, &sec_attr, 0))
{
Log::error("Steam", "Stdin CreatePipe");
return;
}
// Ensure the write handle to the pipe for STDIN is not inherited.
if (!SetHandleInformation(m_child_stdin_write, HANDLE_FLAG_INHERIT, 0))
{
Log::error("Steam", "Stdin SetHandleInformation");
return;
}
// Create the child process.
if (!createChildProcess())
{
Log::error("Steam", "Could not start ssm.exe");
return;
}
#endif
SECURITY_ATTRIBUTES sec_attr;
// Set the bInheritHandle flag so pipe handles are inherited.
sec_attr.nLength = sizeof(SECURITY_ATTRIBUTES);
sec_attr.bInheritHandle = TRUE;
sec_attr.lpSecurityDescriptor = NULL;
// Create a pipe for the child process's STDOUT.
if (!CreatePipe(&m_child_stdout_read, &m_child_stdout_write, &sec_attr, 0))
{
Log::error("Steam", "Error creating StdoutRd CreatePipe");
return;
}
// Ensure the read handle to the pipe for STDOUT is not inherited.
if (!SetHandleInformation(m_child_stdout_read, HANDLE_FLAG_INHERIT, 0))
{
Log::error("Steam", "Stdout SetHandleInformation");
return;
}
// Create a pipe for the child process's STDIN.
if (!CreatePipe(&m_child_stdin_read, &m_child_stdin_write, &sec_attr, 0))
{
Log::error("Steam", "Stdin CreatePipe");
return;
}
// Ensure the write handle to the pipe for STDIN is not inherited.
if (!SetHandleInformation(m_child_stdin_write, HANDLE_FLAG_INHERIT, 0))
{
Log::error("Steam", "Stdin SetHandleInformation");
return;
}
// Create the child process.
if (!createChildProcess())
{
Log::error("Steam", "Could not start ssm.exe");
return;
}
#endif
std::string s = sendCommand("init");
if (s != "1")
{
@ -85,23 +85,23 @@ Steam::Steam()
s = sendCommand("name");
m_user_name = decodeString(s);
if (m_user_name == "")
{
Log::error("Steam", "Can not get Steam user name.");
return;
}
m_user_name_wchar = StringUtils::utf8ToWide(m_user_name);
if (m_user_name == "")
{
Log::error("Steam", "Can not get Steam user name.");
return;
}
m_user_name_wchar = StringUtils::utf8ToWide(m_user_name);
s = sendCommand("id");
m_steam_id = decodeString(s);
if (m_steam_id== "")
{
Log::error("Steam", "Can not get Steam id.");
return;
}
m_steam_available = true;
if (m_steam_id== "")
{
Log::error("Steam", "Can not get Steam id.");
return;
}
m_steam_available = true;
} // Steam
// ----------------------------------------------------------------------------
/** Terminates the child processes and shuts down the Steam API.
@ -122,52 +122,52 @@ Steam::~Steam()
#ifdef WIN32
bool Steam::createChildProcess()
{
TCHAR command_line[] = TEXT("ssm.exe 1");
PROCESS_INFORMATION piProcInfo;
STARTUPINFO siStartInfo;
// Set up members of the PROCESS_INFORMATION structure.
ZeroMemory(&piProcInfo, sizeof(PROCESS_INFORMATION));
// Set up members of the STARTUPINFO structure.
// This structure specifies the STDIN and STDOUT handles for redirection.
ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));
siStartInfo.cb = sizeof(STARTUPINFO);
siStartInfo.hStdError = m_child_stdout_write;
siStartInfo.hStdOutput = m_child_stdout_write;
siStartInfo.hStdInput = m_child_stdin_read;
siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
// Create the child process.
bool success = CreateProcess(NULL,
command_line, // command line
NULL, // process security attributes
NULL, // primary thread security attributes
TRUE, // handles are inherited
0, // creation flags
NULL, // use parent's environment
NULL, // use parent's current directory
&siStartInfo, // STARTUPINFO pointer
&piProcInfo) != 0; // receives PROCESS_INFORMATION
if (!success)
{
return false;
}
// Close handles to the child process and its primary thread.
// Some applications might keep these handles to monitor the status
// of the child process, for example.
CloseHandle(piProcInfo.hProcess);
CloseHandle(piProcInfo.hThread);
return true;
TCHAR command_line[] = TEXT("ssm.exe 1");
PROCESS_INFORMATION piProcInfo;
STARTUPINFO siStartInfo;
// Set up members of the PROCESS_INFORMATION structure.
ZeroMemory(&piProcInfo, sizeof(PROCESS_INFORMATION));
// Set up members of the STARTUPINFO structure.
// This structure specifies the STDIN and STDOUT handles for redirection.
ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));
siStartInfo.cb = sizeof(STARTUPINFO);
siStartInfo.hStdError = m_child_stdout_write;
siStartInfo.hStdOutput = m_child_stdout_write;
siStartInfo.hStdInput = m_child_stdin_read;
siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
// Create the child process.
bool success = CreateProcess(NULL,
command_line, // command line
NULL, // process security attributes
NULL, // primary thread security attributes
TRUE, // handles are inherited
0, // creation flags
NULL, // use parent's environment
NULL, // use parent's current directory
&siStartInfo, // STARTUPINFO pointer
&piProcInfo) != 0; // receives PROCESS_INFORMATION
if (!success)
{
return false;
}
// Close handles to the child process and its primary thread.
// Some applications might keep these handles to monitor the status
// of the child process, for example.
CloseHandle(piProcInfo.hProcess);
CloseHandle(piProcInfo.hThread);
return true;
} // createChildProcess
#endif
#endif
// ----------------------------------------------------------------------------
/** Reads a command from the input pipe.
@ -175,16 +175,16 @@ bool Steam::createChildProcess()
std::string Steam::getLine()
{
#ifdef WIN32
#define BUFSIZE 1024
char buffer[BUFSIZE];
DWORD bytes_read;
// Read from pipe that is the standard output for child process.
bool success = ReadFile(m_child_stdout_read, buffer, BUFSIZE-1,
&bytes_read, NULL)!=0;
if (success && bytes_read < BUFSIZE)
{
buffer[bytes_read] = 0;
std::string s = buffer;
#define BUFSIZE 1024
char buffer[BUFSIZE];
DWORD bytes_read;
// Read from pipe that is the standard output for child process.
bool success = ReadFile(m_child_stdout_read, buffer, BUFSIZE-1,
&bytes_read, NULL)!=0;
if (success && bytes_read < BUFSIZE)
{
buffer[bytes_read] = 0;
std::string s = buffer;
return s;
}
#endif
@ -196,18 +196,18 @@ std::string Steam::getLine()
* \return Answer from SSM.
*/
std::string Steam::sendCommand(const std::string &command)
{
#ifdef WIN32
// Write to the pipe that is the standard input for a child process.
// Data is written to the pipe's buffers, so it is not necessary to wait
// until the child process is running before writing data.
DWORD bytes_written;
bool success = WriteFile(m_child_stdin_write, (command+"\n").c_str(),
command.size(), &bytes_written, NULL) != 0;
return getLine();
#endif
return std::string("");
{
#ifdef WIN32
// Write to the pipe that is the standard input for a child process.
// Data is written to the pipe's buffers, so it is not necessary to wait
// until the child process is running before writing data.
DWORD bytes_written;
bool success = WriteFile(m_child_stdin_write, (command+"\n").c_str(),
command.size(), &bytes_written, NULL) != 0;
return getLine();
#endif
return std::string("");
} // sendCommand
// ----------------------------------------------------------------------------

View File

@ -21,8 +21,8 @@
#include "irrString.h"
#ifdef WIN32
# include <windows.h>
#endif
# include <windows.h>
#endif
#include <assert.h>
#include <string>
@ -37,27 +37,27 @@
class Steam
{
private:
/** Singleton pointer. */
static Steam *m_steam;
/** Singleton pointer. */
static Steam *m_steam;
/** True if a connection to steam was made successfully. */
bool m_steam_available;
/** Steam user name. Only defined if m_steam_available. */
/** Steam user name. Only defined if m_steam_available. */
std::string m_user_name;
/** User name as irr::stringw (wchar), which is used in STK. */
irr::core::stringw m_user_name_wchar;
/** Unique steam id. */
std::string m_steam_id;
/** Unique steam id. */
std::string m_steam_id;
#ifdef WIN32
// Various handles for the window pipes
HANDLE m_child_stdin_read;
HANDLE m_child_stdin_write;
HANDLE m_child_stdout_read;
HANDLE m_child_stdout_write;
HANDLE m_child_stdin_read;
HANDLE m_child_stdin_write;
HANDLE m_child_stdout_read;
HANDLE m_child_stdout_write;
bool createChildProcess();
#endif