2
* Copyright (C) 2012 Jacek Sieka, arnetheduck on gmail point com
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
#ifndef LUA_PLUGIN_UTIL_H
20
#define LUA_PLUGIN_UTIL_H
23
# define PATH_SEPARATOR '\\'
24
# define PATH_SEPARATOR_STR "\\"
26
# define PATH_SEPARATOR '/'
27
# define PATH_SEPARATOR_STR "/"
28
# include <sys/stat.h>
33
# define snprintf _snprintf
34
# define snwprintf _snwprintf
37
# define stricmp strcasecmp
38
# define strnicmp strncasecmp
40
# error No supported compiler found
48
static void initialize(DCUtilsPtr coreUtils, DCConfigPtr coreConfig, DCLogPtr coreLogger) {
54
static string toString(uint16_t val) {
56
snprintf(buf, sizeof(buf), "%u", (unsigned int)val);
60
static string toString(int32_t val) {
62
snprintf(buf, sizeof(buf), "%d", val);
66
static bool fileExists(const string& aFile) {
68
DWORD attr = GetFileAttributesA(aFile.c_str());
69
return (attr != 0xFFFFFFFF);
72
return (stat(aFile.c_str(), &fi) == 0);
76
static string formatBytes(double val);
78
// Make BCDC's Lua user commands work... hopefully
79
static string ucLuaConvert(const string& str, bool isAdc);
82
static string getPath(PathType type) {
83
return config->get_path(type);
86
static void logMessage(const string& message) {
87
logger->log(message.c_str());
90
static void setConfig(const char* name, const char* value);
91
static void setConfig(const char* name, const string& value) { setConfig(name, value.c_str()); }
92
static void setConfig(const char* name, bool state) { setConfig(name, string(state ? "1" : "0")); }
94
static string getConfig(const char *name);
95
static bool getBoolConfig(const char* name);
97
static ConfigValuePtr getCoreConfig(const char* name);
98
static void freeCoreConfig(ConfigValuePtr val) { config->release(val); }
100
static string fromUtf8(const string& str);
101
static string toUtf8(const string& str);
104
static DCUtilsPtr utils;
105
static DCConfigPtr config;
106
static DCLogPtr logger;
109
#define SETTING(k) Util::getConfig(#k)
110
#define BOOLSETTING(k) (Util::getBoolConfig(#k))
112
#endif // LUA_PLUGIN_UTIL_H