New platform APIs and new OpenAL cmake

This commit is contained in:
Eduardo Bart
2013-02-22 16:53:28 -03:00
parent 5b573afdfc
commit e4e3d7d053
6 changed files with 53 additions and 3 deletions

View File

@@ -32,8 +32,11 @@ public:
void processArgs(std::vector<std::string>& args);
bool spawnProcess(const std::string& process, const std::vector<std::string>& args);
int getProcessId();
bool isProcessRunning(const std::string& name);
bool killProcess(const std::string& name);
std::string getTempPath();
bool copyFile(std::string from, std::string to);
bool fileExists(const std::string& file);
void openUrl(std::string url);
std::string getCPUName();
double getTotalSystemMemory();

View File

@@ -64,6 +64,16 @@ int Platform::getProcessId()
return getpid();
}
bool Platform::isProcessRunning(const std::string& name)
{
return false;
}
bool Platform::killProcess(const std::string& name)
{
return false;
}
std::string Platform::getTempPath()
{
return "/tmp/";
@@ -74,6 +84,12 @@ bool Platform::copyFile(std::string from, std::string to)
return system(stdext::format("/bin/cp '%s' '%s'", from, to).c_str()) == 0;
}
bool Platform::fileExists(const std::string& file)
{
struct stat buffer;
return (stat(file.c_str(), &buffer) == 0);
}
void Platform::openUrl(std::string url)
{
if(url.find("http://") == std::string::npos)

View File

@@ -61,6 +61,27 @@ int Platform::getProcessId()
return GetCurrentProcessId();
}
bool Platform::isProcessRunning(const std::string& name)
{
if(FindWindowA(name.c_str(), NULL) != NULL)
return true;
return false;
}
bool Platform::killProcess(const std::string& name)
{
HWND window = FindWindowA(name.c_str(), NULL);
if(window == NULL)
return false;
DWORD pid = GetProcessId(window);
HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, false, pid);
if(handle == NULL)
return false;
bool ok = TerminateProcess(handle, 1) != 0;
CloseHandle(handle);
return ok;
}
std::string Platform::getTempPath()
{
wchar_t path[MAX_PATH];
@@ -68,6 +89,13 @@ std::string Platform::getTempPath()
return stdext::utf16_to_utf8(path);
}
bool Platform::fileExists(const std::string& file)
{
std::wstring wfile = stdext::utf8_to_utf16(file);
DWORD dwAttrib = GetFileAttributesW(wfile.c_str());
return (dwAttrib != INVALID_FILE_ATTRIBUTES && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}
bool Platform::copyFile(std::string from, std::string to)
{
boost::replace_all(from, "/", "\\");