mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 10:30:28 +00:00
(svn r23490) -Add [FS#2750]: OpenBrowser function to open a browser on major OSes
This commit is contained in:
parent
0143f00d6f
commit
b4fdba2fb3
@ -359,6 +359,15 @@ void MakeNewgameSettingsLive()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OpenBrowser(const char *url)
|
||||||
|
{
|
||||||
|
/* Make sure we only accept urls that are sure to open a browser. */
|
||||||
|
if (strstr(url, "http://") != url && strstr(url, "https://") != url) return;
|
||||||
|
|
||||||
|
extern void OSOpenBrowser(const char *url);
|
||||||
|
OSOpenBrowser(url);
|
||||||
|
}
|
||||||
|
|
||||||
/** Callback structure of statements to be executed after the NewGRF scan. */
|
/** Callback structure of statements to be executed after the NewGRF scan. */
|
||||||
struct AfterNewGRFScan : NewGRFScanCallback {
|
struct AfterNewGRFScan : NewGRFScanCallback {
|
||||||
Year startyear; ///< The start year.
|
Year startyear; ///< The start year.
|
||||||
|
@ -118,6 +118,10 @@ void ShowOSErrorBox(const char *buf, bool system)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OSOpenBrowser(const char *url)
|
||||||
|
{
|
||||||
|
[ [ NSWorkspace sharedWorkspace ] openURL:[ NSURL URLWithString:[ NSString stringWithUTF8String:url ] ] ];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine and return the current user's locale.
|
* Determine and return the current user's locale.
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "../../openttd.h"
|
#include "../../openttd.h"
|
||||||
#include "../../crashlog.h"
|
#include "../../crashlog.h"
|
||||||
#include "../../core/random_func.hpp"
|
#include "../../core/random_func.hpp"
|
||||||
|
#include "../../debug.h"
|
||||||
|
|
||||||
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
@ -348,4 +349,18 @@ uint GetCPUCoreCount()
|
|||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OSOpenBrowser(const char *url)
|
||||||
|
{
|
||||||
|
pid_t child_pid = fork();
|
||||||
|
if (child_pid != 0) return;
|
||||||
|
|
||||||
|
const char *args[3];
|
||||||
|
args[0] = "/usr/bin/xdg-open";
|
||||||
|
args[1] = url;
|
||||||
|
args[2] = NULL;
|
||||||
|
execv(args[0], const_cast<char * const *>(args));
|
||||||
|
DEBUG(misc, 0, "Failed to open url: %s", url);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <shlobj.h> /* SHGetFolderPath */
|
#include <shlobj.h> /* SHGetFolderPath */
|
||||||
|
#include <Shellapi.h>
|
||||||
#include "win32.h"
|
#include "win32.h"
|
||||||
#include "../../core/alloc_func.hpp"
|
#include "../../core/alloc_func.hpp"
|
||||||
#include "../../openttd.h"
|
#include "../../openttd.h"
|
||||||
@ -79,6 +80,11 @@ void ShowOSErrorBox(const char *buf, bool system)
|
|||||||
MessageBox(GetActiveWindow(), MB_TO_WIDE(buf), _T("Error!"), MB_ICONSTOP);
|
MessageBox(GetActiveWindow(), MB_TO_WIDE(buf), _T("Error!"), MB_ICONSTOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OSOpenBrowser(const char *url)
|
||||||
|
{
|
||||||
|
ShellExecute(GetActiveWindow(), _T("open"), MB_TO_WIDE(url), NULL, NULL, SW_SHOWNORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
/* Code below for windows version of opendir/readdir/closedir copied and
|
/* Code below for windows version of opendir/readdir/closedir copied and
|
||||||
* modified from Jan Wassenberg's GPL implementation posted over at
|
* modified from Jan Wassenberg's GPL implementation posted over at
|
||||||
* http://www.gamedev.net/community/forums/topic.asp?topic_id=364584&whichpage=1� */
|
* http://www.gamedev.net/community/forums/topic.asp?topic_id=364584&whichpage=1� */
|
||||||
|
Loading…
Reference in New Issue
Block a user