Open URIs without popping up console windows
This commit is contained in:
parent
6490654733
commit
126b7adfaa
@ -91,25 +91,22 @@ void DoRestart()
|
|||||||
void OpenURI(ByteString uri)
|
void OpenURI(ByteString uri)
|
||||||
{
|
{
|
||||||
#if defined(WIN)
|
#if defined(WIN)
|
||||||
ShellExecute(0, "OPEN", uri.c_str(), NULL, NULL, 0);
|
if ((int)ShellExecute(NULL, NULL, uri.c_str(), NULL, NULL, SW_SHOWNORMAL) <= 32)
|
||||||
#elif defined(MACOSX)
|
|
||||||
char *cmd = (char*)malloc(7+uri.length());
|
|
||||||
strcpy(cmd, "open ");
|
|
||||||
strappend(cmd, (char*)uri.c_str());
|
|
||||||
if (system(cmd))
|
|
||||||
{
|
{
|
||||||
fprintf(stderr, "system(cmd) return non-zero value\n");
|
fprintf(stderr, "cannot open URI: ShellExecute(...) failed\n");
|
||||||
|
}
|
||||||
|
#elif defined(MACOSX)
|
||||||
|
if (system(("open \"" + uri + "\"").c_str()))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "cannot open URI: system(...) failed\n");
|
||||||
}
|
}
|
||||||
#elif defined(LIN)
|
#elif defined(LIN)
|
||||||
char *cmd = (char*)malloc(11+uri.length());
|
if (system(("xdg-open \"" + uri + "\"").c_str()))
|
||||||
strcpy(cmd, "xdg-open ");
|
|
||||||
strappend(cmd, (char*)uri.c_str());
|
|
||||||
if (system(cmd))
|
|
||||||
{
|
{
|
||||||
fprintf(stderr, "system(cmd) return non-zero value\n");
|
fprintf(stderr, "cannot open URI: system(...) failed\n");
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
printf("Cannot open browser\n");
|
fprintf(stderr, "cannot open URI: not implemented\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
#include "SDLCompat.h"
|
#include "SDLCompat.h"
|
||||||
|
#include "Platform.h"
|
||||||
|
|
||||||
#include "gui/Style.h"
|
#include "gui/Style.h"
|
||||||
#include "gui/interface/Button.h"
|
#include "gui/interface/Button.h"
|
||||||
@ -290,22 +291,15 @@ OptionsView::OptionsView():
|
|||||||
currentY+=20;
|
currentY+=20;
|
||||||
ui::Button * dataFolderButton = new ui::Button(ui::Point(8, currentY), ui::Point(90, 16), "Open Data Folder");
|
ui::Button * dataFolderButton = new ui::Button(ui::Point(8, currentY), ui::Point(90, 16), "Open Data Folder");
|
||||||
dataFolderButton->SetActionCallback({ [] {
|
dataFolderButton->SetActionCallback({ [] {
|
||||||
//one of these should always be defined
|
auto *cwd = getcwd(NULL, 0);
|
||||||
#ifdef WIN
|
if (cwd)
|
||||||
const char* openCommand = "explorer ";
|
|
||||||
#elif MACOSX
|
|
||||||
const char* openCommand = "open ";
|
|
||||||
//#elif LIN
|
|
||||||
#else
|
|
||||||
const char* openCommand = "xdg-open ";
|
|
||||||
#endif
|
|
||||||
char* workingDirectory = new char[FILENAME_MAX+strlen(openCommand)];
|
|
||||||
sprintf(workingDirectory, "%s\"%s\"", openCommand, getcwd(NULL, 0));
|
|
||||||
if (system(workingDirectory))
|
|
||||||
{
|
{
|
||||||
fprintf(stderr, "system(cmd) return non-zero value\n");
|
Platform::OpenURI(cwd);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "cannot open data folder: getcwd(...) failed\n");
|
||||||
}
|
}
|
||||||
delete[] workingDirectory;
|
|
||||||
} });
|
} });
|
||||||
scrollPanel->AddChild(dataFolderButton);
|
scrollPanel->AddChild(dataFolderButton);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user