Preprocessor purge round 17: easy parts of WIN, LIN, MACOSX, AND
This commit is contained in:
parent
746dbb0cba
commit
163203b321
@ -314,6 +314,10 @@ else
|
|||||||
ident_platform = 'UNKNOWN'
|
ident_platform = 'UNKNOWN'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
install_check = get_option('install_check')
|
||||||
|
if host_platform == 'darwin' or host_platform == 'android'
|
||||||
|
install_check = false
|
||||||
|
endif
|
||||||
app_exe = get_option('app_exe')
|
app_exe = get_option('app_exe')
|
||||||
app_id = get_option('app_id')
|
app_id = get_option('app_id')
|
||||||
mod_id = get_option('mod_id')
|
mod_id = get_option('mod_id')
|
||||||
@ -328,7 +332,7 @@ conf_data.set('WIN', host_platform == 'windows')
|
|||||||
conf_data.set('MACOSX', host_platform == 'darwin')
|
conf_data.set('MACOSX', host_platform == 'darwin')
|
||||||
conf_data.set('X86', is_x86 ? 'true' : 'false')
|
conf_data.set('X86', is_x86 ? 'true' : 'false')
|
||||||
conf_data.set('BETA', is_beta ? 'true' : 'false')
|
conf_data.set('BETA', is_beta ? 'true' : 'false')
|
||||||
conf_data.set('INSTALL_CHECK', get_option('install_check') ? 'true' : 'false')
|
conf_data.set('INSTALL_CHECK', install_check ? 'true' : 'false')
|
||||||
conf_data.set('IGNORE_UPDATES', get_option('ignore_updates') ? 'true' : 'false')
|
conf_data.set('IGNORE_UPDATES', get_option('ignore_updates') ? 'true' : 'false')
|
||||||
conf_data.set('MOD_ID', mod_id)
|
conf_data.set('MOD_ID', mod_id)
|
||||||
conf_data.set('DEBUG', is_debug ? 'true' : 'false')
|
conf_data.set('DEBUG', is_debug ? 'true' : 'false')
|
||||||
|
@ -41,7 +41,6 @@ constexpr char PATH_SEP[] = "/";
|
|||||||
constexpr char PATH_SEP_CHAR = '/';
|
constexpr char PATH_SEP_CHAR = '/';
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//VersionInfoStart
|
|
||||||
constexpr int SAVE_VERSION = 97;
|
constexpr int SAVE_VERSION = 97;
|
||||||
constexpr int MINOR_VERSION = 0;
|
constexpr int MINOR_VERSION = 0;
|
||||||
constexpr int BUILD_NUM = 352;
|
constexpr int BUILD_NUM = 352;
|
||||||
@ -49,7 +48,6 @@ constexpr int SNAPSHOT_ID = @SNAPSHOT_ID@;
|
|||||||
constexpr int MOD_ID = @MOD_ID@;
|
constexpr int MOD_ID = @MOD_ID@;
|
||||||
constexpr int FUTURE_SAVE_VERSION = 97;
|
constexpr int FUTURE_SAVE_VERSION = 97;
|
||||||
constexpr int FUTURE_MINOR_VERSION = 0;
|
constexpr int FUTURE_MINOR_VERSION = 0;
|
||||||
//VersionInfoEnd
|
|
||||||
|
|
||||||
constexpr char IDENT_RELTYPE = SNAPSHOT ? 'S' : (BETA ? 'B' : 'R');
|
constexpr char IDENT_RELTYPE = SNAPSHOT ? 'S' : (BETA ? 'B' : 'R');
|
||||||
|
|
||||||
|
@ -13,33 +13,6 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#ifdef MACOSX
|
|
||||||
# include <mach-o/dyld.h>
|
|
||||||
# include <ApplicationServices/ApplicationServices.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef LIN
|
|
||||||
# include "icon_cps.png.h"
|
|
||||||
# include "icon_exe.png.h"
|
|
||||||
# include "save.xml.h"
|
|
||||||
# include "powder.desktop.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef WIN
|
|
||||||
# ifndef NOMINMAX
|
|
||||||
# define NOMINMAX
|
|
||||||
# endif
|
|
||||||
# include <shlobj.h>
|
|
||||||
# include <objidl.h>
|
|
||||||
# include <shlwapi.h>
|
|
||||||
# include <windows.h>
|
|
||||||
# include <direct.h>
|
|
||||||
# include "resource.h"
|
|
||||||
#else
|
|
||||||
# include <sys/stat.h>
|
|
||||||
# include <unistd.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "ClientListener.h"
|
#include "ClientListener.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Format.h"
|
#include "Format.h"
|
||||||
@ -1120,144 +1093,6 @@ void Client::SaveAuthorInfo(Json::Value *saveInto)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Client::DoInstallation()
|
|
||||||
{
|
|
||||||
bool ok = true;
|
|
||||||
#if defined(WIN)
|
|
||||||
auto deleteKey = [](ByteString path) {
|
|
||||||
RegDeleteKeyW(HKEY_CURRENT_USER, Platform::WinWiden(path).c_str());
|
|
||||||
};
|
|
||||||
auto createKey = [](ByteString path, ByteString value, ByteString extraKey = {}, ByteString extraValue = {}) {
|
|
||||||
auto ok = true;
|
|
||||||
auto wPath = Platform::WinWiden(path);
|
|
||||||
auto wValue = Platform::WinWiden(value);
|
|
||||||
auto wExtraKey = Platform::WinWiden(extraKey);
|
|
||||||
auto wExtraValue = Platform::WinWiden(extraValue);
|
|
||||||
HKEY k;
|
|
||||||
ok = ok && RegCreateKeyExW(HKEY_CURRENT_USER, wPath.c_str(), 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &k, NULL) == ERROR_SUCCESS;
|
|
||||||
ok = ok && RegSetValueExW(k, NULL, 0, REG_SZ, reinterpret_cast<const BYTE *>(wValue.c_str()), (wValue.size() + 1) * 2) == ERROR_SUCCESS;
|
|
||||||
if (wExtraKey.size())
|
|
||||||
{
|
|
||||||
ok = ok && RegSetValueExW(k, wExtraKey.c_str(), 0, REG_SZ, reinterpret_cast<const BYTE *>(wExtraValue.c_str()), (wExtraValue.size() + 1) * 2) == ERROR_SUCCESS;
|
|
||||||
}
|
|
||||||
RegCloseKey(k);
|
|
||||||
return ok;
|
|
||||||
};
|
|
||||||
|
|
||||||
CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
|
||||||
auto exe = Platform::ExecutableName();
|
|
||||||
auto icon = ByteString::Build(exe, ",-", IDI_DOC_ICON);
|
|
||||||
auto path = Platform::GetCwd();
|
|
||||||
auto open = ByteString::Build("\"", exe, "\" ddir \"", path, "\" \"file://%1\"");
|
|
||||||
auto ptsave = ByteString::Build("\"", exe, "\" ddir \"", path, "\" \"%1\"");
|
|
||||||
deleteKey("Software\\Classes\\ptsave");
|
|
||||||
deleteKey("Software\\Classes\\.cps");
|
|
||||||
deleteKey("Software\\Classes\\.stm");
|
|
||||||
deleteKey("Software\\Classes\\PowderToySave");
|
|
||||||
ok = ok && createKey("Software\\Classes\\ptsave", "Powder Toy Save", "URL Protocol", "");
|
|
||||||
ok = ok && createKey("Software\\Classes\\ptsave\\DefaultIcon", icon);
|
|
||||||
ok = ok && createKey("Software\\Classes\\ptsave\\shell\\open\\command", ptsave);
|
|
||||||
ok = ok && createKey("Software\\Classes\\.cps", "PowderToySave");
|
|
||||||
ok = ok && createKey("Software\\Classes\\.stm", "PowderToySave");
|
|
||||||
ok = ok && createKey("Software\\Classes\\PowderToySave", "Powder Toy Save");
|
|
||||||
ok = ok && createKey("Software\\Classes\\PowderToySave\\DefaultIcon", icon);
|
|
||||||
ok = ok && createKey("Software\\Classes\\PowderToySave\\shell\\open\\command", open);
|
|
||||||
IShellLinkW *shellLink = NULL;
|
|
||||||
IPersistFile *shellLinkPersist = NULL;
|
|
||||||
wchar_t programsPath[MAX_PATH];
|
|
||||||
ok = ok && SHGetFolderPathW(NULL, CSIDL_PROGRAMS, NULL, SHGFP_TYPE_CURRENT, programsPath) == S_OK;
|
|
||||||
ok = ok && CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW, (LPVOID *)&shellLink) == S_OK;
|
|
||||||
ok = ok && shellLink->SetPath(Platform::WinWiden(exe).c_str()) == S_OK;
|
|
||||||
ok = ok && shellLink->SetWorkingDirectory(Platform::WinWiden(path).c_str()) == S_OK;
|
|
||||||
ok = ok && shellLink->SetDescription(Platform::WinWiden(APPNAME).c_str()) == S_OK;
|
|
||||||
ok = ok && shellLink->QueryInterface(IID_IPersistFile, (LPVOID *)&shellLinkPersist) == S_OK;
|
|
||||||
ok = ok && shellLinkPersist->Save(Platform::WinWiden(ByteString::Build(Platform::WinNarrow(programsPath), "\\", APPNAME, ".lnk")).c_str(), TRUE) == S_OK;
|
|
||||||
if (shellLinkPersist)
|
|
||||||
{
|
|
||||||
shellLinkPersist->Release();
|
|
||||||
}
|
|
||||||
if (shellLink)
|
|
||||||
{
|
|
||||||
shellLink->Release();
|
|
||||||
}
|
|
||||||
CoUninitialize();
|
|
||||||
#elif defined(LIN)
|
|
||||||
auto desktopEscapeString = [](ByteString str) {
|
|
||||||
ByteString escaped;
|
|
||||||
for (auto ch : str)
|
|
||||||
{
|
|
||||||
auto from = " " "\n" "\t" "\r" "\\";
|
|
||||||
auto to = "s" "n" "t" "r" "\\";
|
|
||||||
if (auto off = strchr(from, ch))
|
|
||||||
{
|
|
||||||
escaped.append(1, '\\');
|
|
||||||
escaped.append(1, to[off - from]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
escaped.append(1, ch);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return escaped;
|
|
||||||
};
|
|
||||||
auto desktopEscapeExec = [](ByteString str) {
|
|
||||||
ByteString escaped;
|
|
||||||
for (auto ch : str)
|
|
||||||
{
|
|
||||||
if (strchr(" \t\n\"\'\\><~|&;$*?#()`", ch))
|
|
||||||
{
|
|
||||||
escaped.append(1, '\\');
|
|
||||||
}
|
|
||||||
escaped.append(1, ch);
|
|
||||||
}
|
|
||||||
return escaped;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (ok)
|
|
||||||
{
|
|
||||||
ByteString desktopData(powder_desktop, powder_desktop + powder_desktop_size);
|
|
||||||
auto exe = Platform::ExecutableName();
|
|
||||||
auto path = exe.SplitFromEndBy('/').Before();
|
|
||||||
desktopData = desktopData.Substitute("Exec=" + ByteString(APPEXE), "Exec=" + desktopEscapeString(desktopEscapeExec(exe)));
|
|
||||||
desktopData += ByteString::Build("Path=", desktopEscapeString(path), "\n");
|
|
||||||
ByteString file = ByteString::Build(APPVENDOR, "-", APPID, ".desktop");
|
|
||||||
ok = ok && Platform::WriteFile(std::vector<char>(desktopData.begin(), desktopData.end()), file);
|
|
||||||
ok = ok && !system(ByteString::Build("xdg-desktop-menu install ", file).c_str());
|
|
||||||
ok = ok && !system(ByteString::Build("xdg-mime default ", file, " application/vnd.powdertoy.save").c_str());
|
|
||||||
ok = ok && !system(ByteString::Build("xdg-mime default ", file, " x-scheme-handler/ptsave").c_str());
|
|
||||||
Platform::RemoveFile(file);
|
|
||||||
}
|
|
||||||
if (ok)
|
|
||||||
{
|
|
||||||
ByteString file = ByteString(APPVENDOR) + "-save.xml";
|
|
||||||
ok = ok && Platform::WriteFile(std::vector<char>(save_xml, save_xml + save_xml_size), file);
|
|
||||||
ok = ok && !system(ByteString::Build("xdg-mime install ", file).c_str());
|
|
||||||
Platform::RemoveFile(file);
|
|
||||||
}
|
|
||||||
if (ok)
|
|
||||||
{
|
|
||||||
ByteString file = ByteString(APPVENDOR) + "-cps.png";
|
|
||||||
ok = ok && Platform::WriteFile(std::vector<char>(icon_cps_png, icon_cps_png + icon_cps_png_size), file);
|
|
||||||
ok = ok && !system(ByteString::Build("xdg-icon-resource install --noupdate --context mimetypes --size 64 ", file, " application-vnd.powdertoy.save").c_str());
|
|
||||||
Platform::RemoveFile(file);
|
|
||||||
}
|
|
||||||
if (ok)
|
|
||||||
{
|
|
||||||
ByteString file = ByteString(APPVENDOR) + "-exe.png";
|
|
||||||
ok = ok && Platform::WriteFile(std::vector<char>(icon_exe_png, icon_exe_png + icon_exe_png_size), file);
|
|
||||||
ok = ok && !system(ByteString::Build("xdg-icon-resource install --noupdate --size 64 ", file, " ", APPVENDOR, "-", APPEXE).c_str());
|
|
||||||
Platform::RemoveFile(file);
|
|
||||||
}
|
|
||||||
if (ok)
|
|
||||||
{
|
|
||||||
ok = ok && !system("xdg-icon-resource forceupdate");
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
ok = false;
|
|
||||||
#endif
|
|
||||||
return ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AddCustomGol(String ruleString, String nameString, unsigned int highColor, unsigned int lowColor)
|
bool AddCustomGol(String ruleString, String nameString, unsigned int highColor, unsigned int lowColor)
|
||||||
{
|
{
|
||||||
auto &prefs = GlobalPrefs::Ref();
|
auto &prefs = GlobalPrefs::Ref();
|
||||||
@ -1408,7 +1243,7 @@ String Client::DoMigration(ByteString fromDir, ByteString toDir)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// chdir into the new directory
|
// chdir into the new directory
|
||||||
chdir(toDir.c_str());
|
Platform::ChangeDir(toDir);
|
||||||
|
|
||||||
if (scripts.size())
|
if (scripts.size())
|
||||||
RescanStamps();
|
RescanStamps();
|
||||||
|
@ -97,8 +97,6 @@ public:
|
|||||||
ByteString FileOpenDialogue();
|
ByteString FileOpenDialogue();
|
||||||
//std::string FileSaveDialogue();
|
//std::string FileSaveDialogue();
|
||||||
|
|
||||||
bool DoInstallation();
|
|
||||||
|
|
||||||
void AddServerNotification(std::pair<String, ByteString> notification);
|
void AddServerNotification(std::pair<String, ByteString> notification);
|
||||||
std::vector<std::pair<String, ByteString> > GetServerNotifications();
|
std::vector<std::pair<String, ByteString> > GetServerNotifications();
|
||||||
|
|
||||||
|
@ -444,8 +444,6 @@ namespace http
|
|||||||
HandleCURLcode(curl_easy_setopt(easy, CURLOPT_SSL_OPTIONS, CURLSSLOPT_REVOKE_BEST_EFFORT));
|
HandleCURLcode(curl_easy_setopt(easy, CURLOPT_SSL_OPTIONS, CURLSSLOPT_REVOKE_BEST_EFFORT));
|
||||||
#elif defined(CURL_AT_LEAST_VERSION) && CURL_AT_LEAST_VERSION(7, 44, 0)
|
#elif defined(CURL_AT_LEAST_VERSION) && CURL_AT_LEAST_VERSION(7, 44, 0)
|
||||||
HandleCURLcode(curl_easy_setopt(easy, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NO_REVOKE));
|
HandleCURLcode(curl_easy_setopt(easy, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NO_REVOKE));
|
||||||
#elif defined(WIN)
|
|
||||||
# error "That's unfortunate."
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "Platform.h"
|
#include "Platform.h"
|
||||||
|
#include "resource.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@ -23,6 +24,13 @@
|
|||||||
#ifdef MACOSX
|
#ifdef MACOSX
|
||||||
# include <cstdint>
|
# include <cstdint>
|
||||||
# include <mach-o/dyld.h>
|
# include <mach-o/dyld.h>
|
||||||
|
# include <ApplicationServices/ApplicationServices.h>
|
||||||
|
#endif
|
||||||
|
#ifdef LIN
|
||||||
|
# include "icon_cps.png.h"
|
||||||
|
# include "icon_exe.png.h"
|
||||||
|
# include "save.xml.h"
|
||||||
|
# include "powder.desktop.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Platform
|
namespace Platform
|
||||||
@ -205,6 +213,15 @@ bool MakeDirectory(ByteString dir)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ChangeDir(ByteString toDir)
|
||||||
|
{
|
||||||
|
#ifdef WIN
|
||||||
|
return _wchdir(WinWiden(toDir).c_str()) == 0;
|
||||||
|
#else
|
||||||
|
return chdir(toDir.c_str()) == 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// Returns a list of all files in a directory matching a search
|
// Returns a list of all files in a directory matching a search
|
||||||
// search - list of search terms. extensions - list of extensions to also match
|
// search - list of search terms. extensions - list of extensions to also match
|
||||||
std::vector<ByteString> DirectorySearch(ByteString directory, ByteString search, std::vector<ByteString> extensions)
|
std::vector<ByteString> DirectorySearch(ByteString directory, ByteString search, std::vector<ByteString> extensions)
|
||||||
@ -409,4 +426,160 @@ void DoRestart()
|
|||||||
}
|
}
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CanUpdate()
|
||||||
|
{
|
||||||
|
#ifdef MACOSX
|
||||||
|
return false;
|
||||||
|
#else
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CanInstall()
|
||||||
|
{
|
||||||
|
return INSTALL_CHECK;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Install()
|
||||||
|
{
|
||||||
|
bool ok = true;
|
||||||
|
#if defined(WIN)
|
||||||
|
auto deleteKey = [](ByteString path) {
|
||||||
|
RegDeleteKeyW(HKEY_CURRENT_USER, Platform::WinWiden(path).c_str());
|
||||||
|
};
|
||||||
|
auto createKey = [](ByteString path, ByteString value, ByteString extraKey = {}, ByteString extraValue = {}) {
|
||||||
|
auto ok = true;
|
||||||
|
auto wPath = Platform::WinWiden(path);
|
||||||
|
auto wValue = Platform::WinWiden(value);
|
||||||
|
auto wExtraKey = Platform::WinWiden(extraKey);
|
||||||
|
auto wExtraValue = Platform::WinWiden(extraValue);
|
||||||
|
HKEY k;
|
||||||
|
ok = ok && RegCreateKeyExW(HKEY_CURRENT_USER, wPath.c_str(), 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &k, NULL) == ERROR_SUCCESS;
|
||||||
|
ok = ok && RegSetValueExW(k, NULL, 0, REG_SZ, reinterpret_cast<const BYTE *>(wValue.c_str()), (wValue.size() + 1) * 2) == ERROR_SUCCESS;
|
||||||
|
if (wExtraKey.size())
|
||||||
|
{
|
||||||
|
ok = ok && RegSetValueExW(k, wExtraKey.c_str(), 0, REG_SZ, reinterpret_cast<const BYTE *>(wExtraValue.c_str()), (wExtraValue.size() + 1) * 2) == ERROR_SUCCESS;
|
||||||
|
}
|
||||||
|
RegCloseKey(k);
|
||||||
|
return ok;
|
||||||
|
};
|
||||||
|
|
||||||
|
CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
||||||
|
auto exe = Platform::ExecutableName();
|
||||||
|
#ifndef IDI_DOC_ICON
|
||||||
|
// make this fail so I don't remove #include "resource.h" again and get away with it
|
||||||
|
# error where muh IDI_DOC_ICON D:
|
||||||
|
#endif
|
||||||
|
auto icon = ByteString::Build(exe, ",-", IDI_DOC_ICON);
|
||||||
|
auto path = Platform::GetCwd();
|
||||||
|
auto open = ByteString::Build("\"", exe, "\" ddir \"", path, "\" \"file://%1\"");
|
||||||
|
auto ptsave = ByteString::Build("\"", exe, "\" ddir \"", path, "\" \"%1\"");
|
||||||
|
deleteKey("Software\\Classes\\ptsave");
|
||||||
|
deleteKey("Software\\Classes\\.cps");
|
||||||
|
deleteKey("Software\\Classes\\.stm");
|
||||||
|
deleteKey("Software\\Classes\\PowderToySave");
|
||||||
|
ok = ok && createKey("Software\\Classes\\ptsave", "Powder Toy Save", "URL Protocol", "");
|
||||||
|
ok = ok && createKey("Software\\Classes\\ptsave\\DefaultIcon", icon);
|
||||||
|
ok = ok && createKey("Software\\Classes\\ptsave\\shell\\open\\command", ptsave);
|
||||||
|
ok = ok && createKey("Software\\Classes\\.cps", "PowderToySave");
|
||||||
|
ok = ok && createKey("Software\\Classes\\.stm", "PowderToySave");
|
||||||
|
ok = ok && createKey("Software\\Classes\\PowderToySave", "Powder Toy Save");
|
||||||
|
ok = ok && createKey("Software\\Classes\\PowderToySave\\DefaultIcon", icon);
|
||||||
|
ok = ok && createKey("Software\\Classes\\PowderToySave\\shell\\open\\command", open);
|
||||||
|
IShellLinkW *shellLink = NULL;
|
||||||
|
IPersistFile *shellLinkPersist = NULL;
|
||||||
|
wchar_t programsPath[MAX_PATH];
|
||||||
|
ok = ok && SHGetFolderPathW(NULL, CSIDL_PROGRAMS, NULL, SHGFP_TYPE_CURRENT, programsPath) == S_OK;
|
||||||
|
ok = ok && CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW, (LPVOID *)&shellLink) == S_OK;
|
||||||
|
ok = ok && shellLink->SetPath(Platform::WinWiden(exe).c_str()) == S_OK;
|
||||||
|
ok = ok && shellLink->SetWorkingDirectory(Platform::WinWiden(path).c_str()) == S_OK;
|
||||||
|
ok = ok && shellLink->SetDescription(Platform::WinWiden(APPNAME).c_str()) == S_OK;
|
||||||
|
ok = ok && shellLink->QueryInterface(IID_IPersistFile, (LPVOID *)&shellLinkPersist) == S_OK;
|
||||||
|
ok = ok && shellLinkPersist->Save(Platform::WinWiden(ByteString::Build(Platform::WinNarrow(programsPath), "\\", APPNAME, ".lnk")).c_str(), TRUE) == S_OK;
|
||||||
|
if (shellLinkPersist)
|
||||||
|
{
|
||||||
|
shellLinkPersist->Release();
|
||||||
|
}
|
||||||
|
if (shellLink)
|
||||||
|
{
|
||||||
|
shellLink->Release();
|
||||||
|
}
|
||||||
|
CoUninitialize();
|
||||||
|
#elif defined(LIN)
|
||||||
|
auto desktopEscapeString = [](ByteString str) {
|
||||||
|
ByteString escaped;
|
||||||
|
for (auto ch : str)
|
||||||
|
{
|
||||||
|
auto from = " " "\n" "\t" "\r" "\\";
|
||||||
|
auto to = "s" "n" "t" "r" "\\";
|
||||||
|
if (auto off = strchr(from, ch))
|
||||||
|
{
|
||||||
|
escaped.append(1, '\\');
|
||||||
|
escaped.append(1, to[off - from]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
escaped.append(1, ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return escaped;
|
||||||
|
};
|
||||||
|
auto desktopEscapeExec = [](ByteString str) {
|
||||||
|
ByteString escaped;
|
||||||
|
for (auto ch : str)
|
||||||
|
{
|
||||||
|
if (strchr(" \t\n\"\'\\><~|&;$*?#()`", ch))
|
||||||
|
{
|
||||||
|
escaped.append(1, '\\');
|
||||||
|
}
|
||||||
|
escaped.append(1, ch);
|
||||||
|
}
|
||||||
|
return escaped;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (ok)
|
||||||
|
{
|
||||||
|
ByteString desktopData(powder_desktop, powder_desktop + powder_desktop_size);
|
||||||
|
auto exe = Platform::ExecutableName();
|
||||||
|
auto path = exe.SplitFromEndBy('/').Before();
|
||||||
|
desktopData = desktopData.Substitute("Exec=" + ByteString(APPEXE), "Exec=" + desktopEscapeString(desktopEscapeExec(exe)));
|
||||||
|
desktopData += ByteString::Build("Path=", desktopEscapeString(path), "\n");
|
||||||
|
ByteString file = ByteString::Build(APPVENDOR, "-", APPID, ".desktop");
|
||||||
|
ok = ok && Platform::WriteFile(std::vector<char>(desktopData.begin(), desktopData.end()), file);
|
||||||
|
ok = ok && !system(ByteString::Build("xdg-desktop-menu install ", file).c_str());
|
||||||
|
ok = ok && !system(ByteString::Build("xdg-mime default ", file, " application/vnd.powdertoy.save").c_str());
|
||||||
|
ok = ok && !system(ByteString::Build("xdg-mime default ", file, " x-scheme-handler/ptsave").c_str());
|
||||||
|
Platform::RemoveFile(file);
|
||||||
|
}
|
||||||
|
if (ok)
|
||||||
|
{
|
||||||
|
ByteString file = ByteString(APPVENDOR) + "-save.xml";
|
||||||
|
ok = ok && Platform::WriteFile(std::vector<char>(save_xml, save_xml + save_xml_size), file);
|
||||||
|
ok = ok && !system(ByteString::Build("xdg-mime install ", file).c_str());
|
||||||
|
Platform::RemoveFile(file);
|
||||||
|
}
|
||||||
|
if (ok)
|
||||||
|
{
|
||||||
|
ByteString file = ByteString(APPVENDOR) + "-cps.png";
|
||||||
|
ok = ok && Platform::WriteFile(std::vector<char>(icon_cps_png, icon_cps_png + icon_cps_png_size), file);
|
||||||
|
ok = ok && !system(ByteString::Build("xdg-icon-resource install --noupdate --context mimetypes --size 64 ", file, " application-vnd.powdertoy.save").c_str());
|
||||||
|
Platform::RemoveFile(file);
|
||||||
|
}
|
||||||
|
if (ok)
|
||||||
|
{
|
||||||
|
ByteString file = ByteString(APPVENDOR) + "-exe.png";
|
||||||
|
ok = ok && Platform::WriteFile(std::vector<char>(icon_exe_png, icon_exe_png + icon_exe_png_size), file);
|
||||||
|
ok = ok && !system(ByteString::Build("xdg-icon-resource install --noupdate --size 64 ", file, " ", APPVENDOR, "-", APPEXE).c_str());
|
||||||
|
Platform::RemoveFile(file);
|
||||||
|
}
|
||||||
|
if (ok)
|
||||||
|
{
|
||||||
|
ok = ok && !system("xdg-icon-resource forceupdate");
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
ok = false;
|
||||||
|
#endif
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
#include "common/String.h"
|
#include "common/String.h"
|
||||||
|
#include <string>
|
||||||
#ifdef WIN
|
|
||||||
# include <string>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Platform
|
namespace Platform
|
||||||
{
|
{
|
||||||
@ -41,11 +37,16 @@ namespace Platform
|
|||||||
bool ReadFile(std::vector<char> &fileData, ByteString filename);
|
bool ReadFile(std::vector<char> &fileData, ByteString filename);
|
||||||
bool WriteFile(std::vector<char> fileData, ByteString filename, bool replaceAtomically = false); // TODO: Revisit call sites, remove default.
|
bool WriteFile(std::vector<char> fileData, ByteString filename, bool replaceAtomically = false); // TODO: Revisit call sites, remove default.
|
||||||
|
|
||||||
#ifdef WIN
|
|
||||||
ByteString WinNarrow(const std::wstring &source);
|
ByteString WinNarrow(const std::wstring &source);
|
||||||
std::wstring WinWiden(const ByteString &source);
|
std::wstring WinWiden(const ByteString &source);
|
||||||
#endif
|
|
||||||
|
|
||||||
extern std::string originalCwd;
|
extern std::string originalCwd;
|
||||||
extern std::string sharedCwd;
|
extern std::string sharedCwd;
|
||||||
|
|
||||||
|
bool CanUpdate();
|
||||||
|
|
||||||
|
bool CanInstall();
|
||||||
|
bool Install();
|
||||||
|
|
||||||
|
bool ChangeDir(ByteString toDir);
|
||||||
}
|
}
|
||||||
|
@ -22,11 +22,6 @@
|
|||||||
#define _USE_MATH_DEFINES
|
#define _USE_MATH_DEFINES
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
//some compatibility stuff for non-standard compilers
|
|
||||||
#if defined(WIN) && !defined(strcasecmp)
|
|
||||||
#define strcasecmp stricmp
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef M_PI
|
#ifdef M_PI
|
||||||
constexpr float TPT_PI_FLT = float(M_PI);
|
constexpr float TPT_PI_FLT = float(M_PI);
|
||||||
constexpr double TPT_PI_DBL = double(M_PI);
|
constexpr double TPT_PI_DBL = double(M_PI);
|
||||||
|
@ -773,21 +773,10 @@ bool VideoBuffer::WritePNG(const ByteString &path) const
|
|||||||
{
|
{
|
||||||
rowPointers[y] = (png_const_bytep)&Buffer[y * Width];
|
rowPointers[y] = (png_const_bytep)&Buffer[y * Width];
|
||||||
}
|
}
|
||||||
#ifdef WIN
|
|
||||||
FILE *f = _wfopen(Platform::WinWiden(path).c_str(), L"wb");
|
|
||||||
#else
|
|
||||||
FILE *f = fopen(path.c_str(), "wb");
|
|
||||||
#endif
|
|
||||||
if (!f)
|
|
||||||
{
|
|
||||||
std::cerr << "WritePNG: fopen failed" << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||||
if (!png)
|
if (!png)
|
||||||
{
|
{
|
||||||
std::cerr << "WritePNG: png_create_write_struct failed" << std::endl;
|
std::cerr << "WritePNG: png_create_write_struct failed" << std::endl;
|
||||||
fclose(f);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
png_infop info = png_create_info_struct(png);
|
png_infop info = png_create_info_struct(png);
|
||||||
@ -795,7 +784,6 @@ bool VideoBuffer::WritePNG(const ByteString &path) const
|
|||||||
{
|
{
|
||||||
std::cerr << "WritePNG: png_create_info_struct failed" << std::endl;
|
std::cerr << "WritePNG: png_create_info_struct failed" << std::endl;
|
||||||
png_destroy_write_struct(&png, (png_infopp)NULL);
|
png_destroy_write_struct(&png, (png_infopp)NULL);
|
||||||
fclose(f);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (setjmp(png_jmpbuf(png)))
|
if (setjmp(png_jmpbuf(png)))
|
||||||
@ -803,10 +791,17 @@ bool VideoBuffer::WritePNG(const ByteString &path) const
|
|||||||
// libpng longjmp'd here in its infinite widsom, clean up and return
|
// libpng longjmp'd here in its infinite widsom, clean up and return
|
||||||
std::cerr << "WritePNG: longjmp from within libpng" << std::endl;
|
std::cerr << "WritePNG: longjmp from within libpng" << std::endl;
|
||||||
png_destroy_write_struct(&png, &info);
|
png_destroy_write_struct(&png, &info);
|
||||||
fclose(f);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
png_init_io(png, f);
|
struct InMemoryFile
|
||||||
|
{
|
||||||
|
std::vector<char> data;
|
||||||
|
} imf;
|
||||||
|
png_set_write_fn(png, (png_voidp)&imf, [](png_structp png, png_bytep data, size_t length) -> void {
|
||||||
|
auto ud = png_get_io_ptr(png);
|
||||||
|
auto &imf = *(InMemoryFile *)ud;
|
||||||
|
imf.data.insert(imf.data.end(), data, data + length);
|
||||||
|
}, NULL);
|
||||||
png_set_IHDR(png, info, Width, Height, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
png_set_IHDR(png, info, Width, Height, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
||||||
png_write_info(png, info);
|
png_write_info(png, info);
|
||||||
png_set_filler(png, 0, PNG_FILLER_AFTER);
|
png_set_filler(png, 0, PNG_FILLER_AFTER);
|
||||||
@ -814,8 +809,7 @@ bool VideoBuffer::WritePNG(const ByteString &path) const
|
|||||||
png_write_image(png, (png_bytepp)&rowPointers[0]);
|
png_write_image(png, (png_bytepp)&rowPointers[0]);
|
||||||
png_write_end(png, NULL);
|
png_write_end(png, NULL);
|
||||||
png_destroy_write_struct(&png, &info);
|
png_destroy_write_struct(&png, &info);
|
||||||
fclose(f);
|
return Platform::WriteFile(imf.data, path);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PngDataToPixels(std::vector<pixel> &imageData, int &imgw, int &imgh, const char *pngData, size_t pngDataSize, bool addBackground)
|
bool PngDataToPixels(std::vector<pixel> &imageData, int &imgw, int &imgh, const char *pngData, size_t pngDataSize, bool addBackground)
|
||||||
|
@ -252,22 +252,23 @@ void GameController::PlaceSave(ui::Point position)
|
|||||||
|
|
||||||
void GameController::Install()
|
void GameController::Install()
|
||||||
{
|
{
|
||||||
#if defined(MACOSX)
|
if (Platform::CanInstall())
|
||||||
new InformationMessage("No installation necessary", "You don't need to install " + String(APPNAME) + " on OS X", false);
|
{
|
||||||
#elif defined(WIN) || defined(LIN)
|
new ConfirmPrompt("Install " + String(APPNAME), "Do you wish to install " + String(APPNAME) + " on this computer?\nThis allows you to open save files and saves directly from the website.", { [] {
|
||||||
new ConfirmPrompt("Install " + String(APPNAME), "Do you wish to install " + String(APPNAME) + " on this computer?\nThis allows you to open save files and saves directly from the website.", { [] {
|
if (Platform::Install())
|
||||||
if (Client::Ref().DoInstallation())
|
{
|
||||||
{
|
new InformationMessage("Success", "Installation completed", false);
|
||||||
new InformationMessage("Success", "Installation completed", false);
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
new ErrorMessage("Could not install", "The installation did not complete due to an error");
|
||||||
new ErrorMessage("Could not install", "The installation did not complete due to an error");
|
}
|
||||||
}
|
} });
|
||||||
} });
|
}
|
||||||
#else
|
else
|
||||||
new ErrorMessage("Cannot install", "You cannot install " + String(APPNAME) + " on this platform");
|
{
|
||||||
#endif
|
new InformationMessage("No installation necessary", "You don't need to install " + String(APPNAME) + " on this platform", false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameController::AdjustGridSize(int direction)
|
void GameController::AdjustGridSize(int direction)
|
||||||
@ -727,7 +728,6 @@ void GameController::Tick()
|
|||||||
if(firstTick)
|
if(firstTick)
|
||||||
{
|
{
|
||||||
commandInterface->Init();
|
commandInterface->Init();
|
||||||
#if !defined(MACOSX)
|
|
||||||
if constexpr (INSTALL_CHECK)
|
if constexpr (INSTALL_CHECK)
|
||||||
{
|
{
|
||||||
if (Client::Ref().IsFirstRun())
|
if (Client::Ref().IsFirstRun())
|
||||||
@ -735,7 +735,6 @@ void GameController::Tick()
|
|||||||
Install();
|
Install();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
firstTick = false;
|
firstTick = false;
|
||||||
}
|
}
|
||||||
if (gameModel->SelectNextIdentifier.length())
|
if (gameModel->SelectNextIdentifier.length())
|
||||||
@ -1593,11 +1592,14 @@ void GameController::NotifyUpdateAvailable(Client * sender)
|
|||||||
{
|
{
|
||||||
UpdateInfo info = Client::Ref().GetUpdateInfo();
|
UpdateInfo info = Client::Ref().GetUpdateInfo();
|
||||||
StringBuilder updateMessage;
|
StringBuilder updateMessage;
|
||||||
#ifndef MACOSX
|
if (Platform::CanUpdate())
|
||||||
updateMessage << "Are you sure you want to run the updater? Please save any changes before updating.\n\nCurrent version:\n ";
|
{
|
||||||
#else
|
updateMessage << "Are you sure you want to run the updater? Please save any changes before updating.\n\nCurrent version:\n ";
|
||||||
updateMessage << "Click \"Continue\" to download the latest version from our website.\n\nCurrent version:\n ";
|
}
|
||||||
#endif
|
else
|
||||||
|
{
|
||||||
|
updateMessage << "Click \"Continue\" to download the latest version from our website.\n\nCurrent version:\n ";
|
||||||
|
}
|
||||||
|
|
||||||
if constexpr (SNAPSHOT)
|
if constexpr (SNAPSHOT)
|
||||||
{
|
{
|
||||||
@ -1672,21 +1674,24 @@ void GameController::RemoveNotification(Notification * notification)
|
|||||||
|
|
||||||
void GameController::RunUpdater()
|
void GameController::RunUpdater()
|
||||||
{
|
{
|
||||||
#ifndef MACOSX
|
if (Platform::CanUpdate())
|
||||||
Exit();
|
|
||||||
new UpdateActivity();
|
|
||||||
#else
|
|
||||||
ByteString file;
|
|
||||||
if constexpr (USE_UPDATESERVER)
|
|
||||||
{
|
{
|
||||||
file = ByteString::Build(SCHEME, UPDATESERVER, Client::Ref().GetUpdateInfo().File);
|
Exit();
|
||||||
|
new UpdateActivity();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
file = ByteString::Build(SCHEME, SERVER, Client::Ref().GetUpdateInfo().File);
|
ByteString file;
|
||||||
|
if constexpr (USE_UPDATESERVER)
|
||||||
|
{
|
||||||
|
file = ByteString::Build(SCHEME, UPDATESERVER, Client::Ref().GetUpdateInfo().File);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
file = ByteString::Build(SCHEME, SERVER, Client::Ref().GetUpdateInfo().File);
|
||||||
|
}
|
||||||
|
Platform::OpenURI(file);
|
||||||
}
|
}
|
||||||
Platform::OpenURI(file);
|
|
||||||
#endif // MACOSX
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GameController::GetMouseClickRequired()
|
bool GameController::GetMouseClickRequired()
|
||||||
|
@ -151,4 +151,3 @@ void UpdateActivity::NotifyError(Task * sender)
|
|||||||
|
|
||||||
UpdateActivity::~UpdateActivity() {
|
UpdateActivity::~UpdateActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "Config.h"
|
||||||
class Task;
|
class Task;
|
||||||
class TaskWindow;
|
class TaskWindow;
|
||||||
class UpdateActivity
|
class UpdateActivity
|
||||||
|
@ -3,9 +3,6 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#if !defined(WIN) || defined(__GNUC__)
|
|
||||||
#include <strings.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "Misc.h"
|
#include "Misc.h"
|
||||||
#include "gui/game/GameModel.h"
|
#include "gui/game/GameModel.h"
|
||||||
|
@ -52,17 +52,6 @@
|
|||||||
#include "gui/game/Tool.h"
|
#include "gui/game/Tool.h"
|
||||||
#include "gui/game/Brush.h"
|
#include "gui/game/Brush.h"
|
||||||
|
|
||||||
#ifndef WIN
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#ifdef WIN
|
|
||||||
#include <direct.h>
|
|
||||||
#endif
|
|
||||||
#include <sys/stat.h>
|
|
||||||
}
|
|
||||||
#include "eventcompat.lua.h"
|
#include "eventcompat.lua.h"
|
||||||
|
|
||||||
// idea from mniip, makes things much simpler
|
// idea from mniip, makes things much simpler
|
||||||
|
@ -1,61 +1,17 @@
|
|||||||
#include "LuaSocket.h"
|
#include "LuaSocket.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <algorithm>
|
|
||||||
#ifdef WIN
|
|
||||||
# include <windows.h>
|
|
||||||
# include <float.h>
|
|
||||||
#else
|
|
||||||
# include <sys/time.h>
|
|
||||||
# include <time.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "LuaScriptInterface.h"
|
#include "LuaScriptInterface.h"
|
||||||
#include "Misc.h"
|
#include "Misc.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
namespace LuaSocket
|
namespace LuaSocket
|
||||||
{
|
{
|
||||||
double Now()
|
|
||||||
{
|
|
||||||
#ifdef WIN
|
|
||||||
FILETIME rt;
|
|
||||||
GetSystemTimeAsFileTime(&rt);
|
|
||||||
return (rt.dwLowDateTime + (uint64_t(rt.dwHighDateTime) << 32) - uint64_t(116444736000000000ULL)) / 1e7;
|
|
||||||
#else
|
|
||||||
struct timeval rt;
|
|
||||||
gettimeofday(&rt, (struct timezone *)NULL);
|
|
||||||
return rt.tv_sec + rt.tv_usec / 1e6;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static int GetTime(lua_State *l)
|
static int GetTime(lua_State *l)
|
||||||
{
|
{
|
||||||
lua_pushnumber(l, Now());
|
lua_pushnumber(l, Now());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Timeout(double timeout)
|
|
||||||
{
|
|
||||||
#ifdef WIN
|
|
||||||
if (timeout < 0.0) timeout = 0.0;
|
|
||||||
if (timeout < DBL_MAX / 1000.0) timeout *= 1000.0;
|
|
||||||
if (timeout > INT_MAX) timeout = INT_MAX;
|
|
||||||
::Sleep(int(timeout));
|
|
||||||
#else
|
|
||||||
struct timespec req, rem;
|
|
||||||
if (timeout < 0.0) timeout = 0.0;
|
|
||||||
if (timeout > INT_MAX) timeout = INT_MAX;
|
|
||||||
req.tv_sec = int(timeout);
|
|
||||||
req.tv_nsec = int((timeout - req.tv_sec) * 1000000000);
|
|
||||||
if (req.tv_nsec > 999999999) req.tv_nsec = 999999999;
|
|
||||||
while (nanosleep(&req, &rem))
|
|
||||||
{
|
|
||||||
req.tv_sec = rem.tv_sec;
|
|
||||||
req.tv_nsec = rem.tv_nsec;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static int Sleep(lua_State *l)
|
static int Sleep(lua_State *l)
|
||||||
{
|
{
|
||||||
Timeout(luaL_checknumber(l, 1));
|
Timeout(luaL_checknumber(l, 1));
|
||||||
|
32
src/lua/LuaSocketDefault.cpp
Normal file
32
src/lua/LuaSocketDefault.cpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#include "LuaSocket.h"
|
||||||
|
#include "LuaScriptInterface.h"
|
||||||
|
#include "Misc.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
namespace LuaSocket
|
||||||
|
{
|
||||||
|
double Now()
|
||||||
|
{
|
||||||
|
struct timeval rt;
|
||||||
|
gettimeofday(&rt, (struct timezone *)NULL);
|
||||||
|
return rt.tv_sec + rt.tv_usec / 1e6;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Timeout(double timeout)
|
||||||
|
{
|
||||||
|
struct timespec req, rem;
|
||||||
|
if (timeout < 0.0) timeout = 0.0;
|
||||||
|
if (timeout > INT_MAX) timeout = INT_MAX;
|
||||||
|
req.tv_sec = int(timeout);
|
||||||
|
req.tv_nsec = int((timeout - req.tv_sec) * 1000000000);
|
||||||
|
if (req.tv_nsec > 999999999) req.tv_nsec = 999999999;
|
||||||
|
while (nanosleep(&req, &rem))
|
||||||
|
{
|
||||||
|
req.tv_sec = rem.tv_sec;
|
||||||
|
req.tv_nsec = rem.tv_nsec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,13 +7,6 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#ifdef WIN
|
|
||||||
# include <windows.h>
|
|
||||||
# include <float.h>
|
|
||||||
#else
|
|
||||||
# include <sys/time.h>
|
|
||||||
# include <time.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "LuaScriptInterface.h"
|
#include "LuaScriptInterface.h"
|
||||||
#include "client/http/RequestManager.h"
|
#include "client/http/RequestManager.h"
|
||||||
|
25
src/lua/LuaSocketWindows.cpp
Normal file
25
src/lua/LuaSocketWindows.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include "LuaSocket.h"
|
||||||
|
#include "LuaScriptInterface.h"
|
||||||
|
#include "Misc.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <windows.h>
|
||||||
|
#include <float.h>
|
||||||
|
|
||||||
|
namespace LuaSocket
|
||||||
|
{
|
||||||
|
double Now()
|
||||||
|
{
|
||||||
|
FILETIME rt;
|
||||||
|
GetSystemTimeAsFileTime(&rt);
|
||||||
|
return (rt.dwLowDateTime + (uint64_t(rt.dwHighDateTime) << 32) - uint64_t(116444736000000000ULL)) / 1e7;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Timeout(double timeout)
|
||||||
|
{
|
||||||
|
if (timeout < 0.0) timeout = 0.0;
|
||||||
|
if (timeout < DBL_MAX / 1000.0) timeout *= 1000.0;
|
||||||
|
if (timeout > INT_MAX) timeout = INT_MAX;
|
||||||
|
::Sleep(int(timeout));
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,6 @@
|
|||||||
#include "TPTScriptInterface.h"
|
#include "TPTScriptInterface.h"
|
||||||
|
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#ifdef MACOSX
|
|
||||||
#include <strings.h>
|
|
||||||
#endif
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
@ -314,7 +311,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<String> * words)
|
|||||||
if (newValue < 0 || newValue >= PT_NUM)
|
if (newValue < 0 || newValue >= PT_NUM)
|
||||||
{
|
{
|
||||||
// TODO: add element CAKE to invalidate this
|
// TODO: add element CAKE to invalidate this
|
||||||
if (!strcasecmp(((StringType)value).Value().ToUtf8().c_str(),"cake"))
|
if (((StringType)value).Value().ToUpper() == "CAKE")
|
||||||
throw GeneralException("Cake is a lie, not an element");
|
throw GeneralException("Cake is a lie, not an element");
|
||||||
throw GeneralException("Invalid element");
|
throw GeneralException("Invalid element");
|
||||||
}
|
}
|
||||||
|
@ -10,11 +10,16 @@ luaconsole_files = files(
|
|||||||
'LuaProgressBar.cpp',
|
'LuaProgressBar.cpp',
|
||||||
'LuaScriptInterface.cpp',
|
'LuaScriptInterface.cpp',
|
||||||
'LuaSlider.cpp',
|
'LuaSlider.cpp',
|
||||||
|
'LuaSocket.cpp',
|
||||||
'LuaSmartRef.cpp',
|
'LuaSmartRef.cpp',
|
||||||
'LuaTextbox.cpp',
|
'LuaTextbox.cpp',
|
||||||
'LuaWindow.cpp',
|
'LuaWindow.cpp',
|
||||||
'LuaSocket.cpp',
|
|
||||||
)
|
)
|
||||||
|
if host_platform == 'windows'
|
||||||
|
luaconsole_files += files('LuaSocketWindows.cpp')
|
||||||
|
else
|
||||||
|
luaconsole_files += files('LuaSocketDefault.cpp')
|
||||||
|
endif
|
||||||
if enable_http
|
if enable_http
|
||||||
luaconsole_files += files('LuaSocketTCPHttp.cpp')
|
luaconsole_files += files('LuaSocketTCPHttp.cpp')
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user