mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2026-11-02 01:33:04 +00:00
Fix compile error on some platform
This commit is contained in:
3 files changed
+24
-6
No files matched your search
+16
-2
@@ -8,8 +8,11 @@
|
|||||||
#include <yaml-cpp/yaml.h>
|
#include <yaml-cpp/yaml.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
#include <unistd.h>
|
||||||
#define PATH_SLASH "\\"
|
#define PATH_SLASH "\\"
|
||||||
#else
|
#else
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#define PATH_SLASH "//"
|
#define PATH_SLASH "//"
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
@@ -70,11 +73,13 @@ static inline bool strFind(const std::string &str, const std::string &target)
|
|||||||
return str.find(target) != str.npos;
|
return str.find(target) != str.npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool startsWith(const std::string &hay, const std::string &needle) {
|
static inline bool startsWith(const std::string &hay, const std::string &needle)
|
||||||
|
{
|
||||||
return hay.substr(0, needle.length()) == needle;
|
return hay.substr(0, needle.length()) == needle;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool endsWith(const std::string &hay, const std::string &needle) {
|
static inline bool endsWith(const std::string &hay, const std::string &needle)
|
||||||
|
{
|
||||||
std::string::size_type hl = hay.length(), nl = needle.length();
|
std::string::size_type hl = hay.length(), nl = needle.length();
|
||||||
return hl >= nl && hay.substr(hl - nl, nl) == needle;
|
return hl >= nl && hay.substr(hl - nl, nl) == needle;
|
||||||
}
|
}
|
||||||
@@ -117,6 +122,15 @@ namespace std
|
|||||||
}
|
}
|
||||||
#endif // HAVE_TO_STRING
|
#endif // HAVE_TO_STRING
|
||||||
|
|
||||||
|
static inline int md(const char *path)
|
||||||
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
return mkdir(path);
|
||||||
|
#else
|
||||||
|
return mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||||
|
#endif // _WIN32
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
void StringToWstring(std::wstring& szDst, const std::string &str);
|
void StringToWstring(std::wstring& szDst, const std::string &str);
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|||||||
+1
-1
@@ -1796,7 +1796,7 @@ std::string netchToSSD(std::vector<nodeInfo> &nodes, std::string &group, std::st
|
|||||||
const time_t rawtime = to_int(expiry);
|
const time_t rawtime = to_int(expiry);
|
||||||
char buffer[30];
|
char buffer[30];
|
||||||
struct tm *dt = localtime(&rawtime);
|
struct tm *dt = localtime(&rawtime);
|
||||||
strftime(buffer, sizeof(buffer), "%F %R", dt);
|
strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M", dt);
|
||||||
writer.Key("expiry");
|
writer.Key("expiry");
|
||||||
writer.String(buffer);
|
writer.String(buffer);
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-3
@@ -9,6 +9,10 @@
|
|||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define _stat stat
|
||||||
|
#endif // _WIN32
|
||||||
|
|
||||||
extern bool print_debug_info;
|
extern bool print_debug_info;
|
||||||
|
|
||||||
//std::string user_agent_str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36";
|
//std::string user_agent_str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36";
|
||||||
@@ -89,11 +93,11 @@ std::string webGet(std::string url, std::string proxy, std::string &response_hea
|
|||||||
// cache system
|
// cache system
|
||||||
if(cache_ttl > 0)
|
if(cache_ttl > 0)
|
||||||
{
|
{
|
||||||
mkdir("cache");
|
md("cache");
|
||||||
std::string url_md5 = getMD5(url);
|
std::string url_md5 = getMD5(url);
|
||||||
std::string path = "cache/" + url_md5;
|
std::string path = "cache/" + url_md5;
|
||||||
struct _stat result;
|
struct stat result;
|
||||||
if(_stat(path.data(), &result) == 0)
|
if(stat(path.data(), &result) == 0)
|
||||||
{
|
{
|
||||||
time_t mtime = result.st_mtime, now = time(NULL);
|
time_t mtime = result.st_mtime, now = time(NULL);
|
||||||
if(difftime(now, mtime) <= cache_ttl)
|
if(difftime(now, mtime) <= cache_ttl)
|
||||||
|
|||||||
Reference in new issue
Block a user