Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
you can get current OS / build information, exe name, restart tpt, open a link in the web browser, and use clipboard copy/paste functions Also remove some older Platform.h file which wasn't really needed or used
- Loading branch information
Showing
30 changed files
with
283 additions
and
317 deletions.
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
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,127 @@ | ||
#include <cstdlib> | ||
#include <cstring> | ||
#include <cstdio> | ||
#ifdef WIN | ||
#include <shlobj.h> | ||
#include <shlwapi.h> | ||
#include <windows.h> | ||
#else | ||
#include <unistd.h> | ||
#include <time.h> | ||
#include <sys/time.h> | ||
#endif | ||
#ifdef MACOSX | ||
#include <mach-o/dyld.h> | ||
#endif | ||
#include "Platform.h" | ||
#include "Misc.h" | ||
|
||
namespace Platform | ||
{ | ||
|
||
char *ExecutableName(void) | ||
{ | ||
#if defined(WIN) | ||
char *name = (char *)malloc(64); | ||
DWORD max = 64, res; | ||
while ((res = GetModuleFileName(NULL, name, max)) >= max) | ||
{ | ||
#elif defined MACOSX | ||
char *fn = (char*)malloc(64),*name = (char*)malloc(PATH_MAX); | ||
uint32_t max = 64, res; | ||
if (_NSGetExecutablePath(fn, &max) != 0) | ||
{ | ||
fn = (char*)realloc(fn, max); | ||
_NSGetExecutablePath(fn, &max); | ||
} | ||
if (realpath(fn, name) == NULL) | ||
{ | ||
free(fn); | ||
free(name); | ||
return NULL; | ||
} | ||
res = 1; | ||
#else | ||
char fn[64], *name = (char *)malloc(64); | ||
size_t max = 64, res; | ||
sprintf(fn, "/proc/self/exe"); | ||
memset(name, 0, max); | ||
while ((res = readlink(fn, name, max)) >= max-1) | ||
{ | ||
#endif | ||
#ifndef MACOSX | ||
max *= 2; | ||
name = (char *)realloc(name, max); | ||
memset(name, 0, max); | ||
} | ||
#endif | ||
if (res <= 0) | ||
{ | ||
free(name); | ||
return NULL; | ||
} | ||
return name; | ||
} | ||
|
||
void DoRestart() | ||
{ | ||
char *exename = ExecutableName(); | ||
if (exename) | ||
{ | ||
#ifdef WIN | ||
ShellExecute(NULL, "open", exename, NULL, NULL, SW_SHOWNORMAL); | ||
#elif defined(LIN) || defined(MACOSX) | ||
execl(exename, "powder", NULL); | ||
#endif | ||
free(exename); | ||
} | ||
exit(-1); | ||
} | ||
|
||
void OpenURI(std::string uri) | ||
{ | ||
#if defined(WIN) | ||
ShellExecute(0, "OPEN", uri.c_str(), NULL, NULL, 0); | ||
#elif defined(MACOSX) | ||
char *cmd = (char*)malloc(7+uri.length()); | ||
strcpy(cmd, "open "); | ||
strappend(cmd, (char*)uri.c_str()); | ||
system(cmd); | ||
#elif defined(LIN) | ||
char *cmd = (char*)malloc(11+uri.length()); | ||
strcpy(cmd, "xdg-open "); | ||
strappend(cmd, (char*)uri.c_str()); | ||
system(cmd); | ||
#else | ||
printf("Cannot open browser\n"); | ||
#endif | ||
} | ||
|
||
void Millisleep(long int t) | ||
{ | ||
#ifdef WIN | ||
Sleep(t); | ||
#else | ||
struct timespec s; | ||
s.tv_sec = t / 1000; | ||
s.tv_nsec = (t % 1000) * 10000000; | ||
nanosleep(&s, NULL); | ||
#endif | ||
} | ||
|
||
long unsigned int GetTime() | ||
{ | ||
#ifdef WIN | ||
return GetTickCount(); | ||
#elif defined(MACOSX) | ||
struct timeval s; | ||
gettimeofday(&s, NULL); | ||
return (unsigned int)(s.tv_sec * 1000 + s.tv_usec / 1000); | ||
#else | ||
struct timespec s; | ||
clock_gettime(CLOCK_MONOTONIC, &s); | ||
return s.tv_sec * 1000 + s.tv_nsec / 1000000; | ||
#endif | ||
} | ||
|
||
} |
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,17 @@ | ||
#ifndef PLATFORM_H | ||
#define PLATFORM_H | ||
|
||
#include <string> | ||
|
||
namespace Platform | ||
{ | ||
char * ExecutableName(); | ||
void DoRestart(); | ||
|
||
void OpenURI(std::string uri); | ||
|
||
void Millisleep(long int t); | ||
long unsigned int GetTime(); | ||
} | ||
|
||
#endif |
Oops, something went wrong.