mirror of https://github.com/tp4a/teleport
.tmp.
parent
931d4016e7
commit
0c27a04034
|
@ -325,7 +325,7 @@ void ThrData::_run() {
|
||||||
// 读取一个数据包
|
// 读取一个数据包
|
||||||
//----------------------------------
|
//----------------------------------
|
||||||
if(file_size - file_processed < sizeof(TS_RECORD_PKG)) {
|
if(file_size - file_processed < sizeof(TS_RECORD_PKG)) {
|
||||||
qDebug("invaid tp-rdp-%d.tpd file, filesize=%" PRId64 ", processed=%" PRId64 ", need=%d.", m_file_idx+1, file_size, file_processed, sizeof(TS_RECORD_PKG));
|
qDebug("invalid tp-rdp-%d.tpd file, filesize=%" PRId64 ", processed=%" PRId64 ", need=%d.", m_file_idx+1, file_size, file_processed, sizeof(TS_RECORD_PKG));
|
||||||
_notify_error(QString("%1\ntp-rdp-%2.tpd").arg(LOCAL8BIT("错误的录像数据文件!"), str_fidx));
|
_notify_error(QString("%1\ntp-rdp-%2.tpd").arg(LOCAL8BIT("错误的录像数据文件!"), str_fidx));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -333,14 +333,14 @@ void ThrData::_run() {
|
||||||
TS_RECORD_PKG pkg;
|
TS_RECORD_PKG pkg;
|
||||||
read_len = fdata->read(reinterpret_cast<char*>(&pkg), sizeof(TS_RECORD_PKG));
|
read_len = fdata->read(reinterpret_cast<char*>(&pkg), sizeof(TS_RECORD_PKG));
|
||||||
if(read_len != sizeof(TS_RECORD_PKG)) {
|
if(read_len != sizeof(TS_RECORD_PKG)) {
|
||||||
qDebug("invaid tp-rdp-%d.tpd file, read_len=%" PRId64 " (1).", m_file_idx+1, read_len);
|
qDebug("invalid tp-rdp-%d.tpd file, read_len=%" PRId64 " (1).", m_file_idx+1, read_len);
|
||||||
_notify_error(QString("%1\ntp-rdp-%2.tpd").arg(LOCAL8BIT("错误的录像数据文件!"), str_fidx));
|
_notify_error(QString("%1\ntp-rdp-%2.tpd").arg(LOCAL8BIT("错误的录像数据文件!"), str_fidx));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
file_processed += sizeof(TS_RECORD_PKG);
|
file_processed += sizeof(TS_RECORD_PKG);
|
||||||
|
|
||||||
if(file_size - file_processed < pkg.size) {
|
if(file_size - file_processed < pkg.size) {
|
||||||
qDebug("invaid tp-rdp-%d.tpd file (2).", m_file_idx+1);
|
qDebug("invalid tp-rdp-%d.tpd file (2).", m_file_idx+1);
|
||||||
_notify_error(QString("%1\ntp-rdp-%2.tpd").arg(LOCAL8BIT("错误的录像数据文件!"), str_fidx));
|
_notify_error(QString("%1\ntp-rdp-%2.tpd").arg(LOCAL8BIT("错误的录像数据文件!"), str_fidx));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -351,7 +351,7 @@ void ThrData::_run() {
|
||||||
|
|
||||||
QByteArray pkg_data = fdata->read(pkg.size);
|
QByteArray pkg_data = fdata->read(pkg.size);
|
||||||
if(pkg_data.size() != static_cast<int>(pkg.size)) {
|
if(pkg_data.size() != static_cast<int>(pkg.size)) {
|
||||||
qDebug("invaid tp-rdp-%d.tpd file, read_len=%" PRId64 " (3).", m_file_idx+1, read_len);
|
qDebug("invalid tp-rdp-%d.tpd file, read_len=%" PRId64 " (3).", m_file_idx+1, read_len);
|
||||||
_notify_error(QString("%1\ntp-rdp-%2.tpd").arg(LOCAL8BIT("错误的录像数据文件!"), str_fidx));
|
_notify_error(QString("%1\ntp-rdp-%2.tpd").arg(LOCAL8BIT("错误的录像数据文件!"), str_fidx));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -359,7 +359,7 @@ void ThrData::_run() {
|
||||||
|
|
||||||
UpdateData* dat = _parse(pkg, pkg_data);
|
UpdateData* dat = _parse(pkg, pkg_data);
|
||||||
if(dat == nullptr) {
|
if(dat == nullptr) {
|
||||||
qDebug("invaid tp-rdp-%d.tpd file (4).", m_file_idx+1);
|
qDebug("invalid tp-rdp-%d.tpd file (4).", m_file_idx+1);
|
||||||
_notify_error(QString("%1\ntp-rdp-%2.tpd").arg(LOCAL8BIT("错误的录像数据文件!"), str_fidx));
|
_notify_error(QString("%1\ntp-rdp-%2.tpd").arg(LOCAL8BIT("错误的录像数据文件!"), str_fidx));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -633,7 +633,7 @@ bool ThrData::_load_header() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_hdr.info.ver != 4) {
|
if(m_hdr.info.ver != 4) {
|
||||||
qDebug() << "invaid .tpr file.";
|
qDebug() << "invalid .tpr file.";
|
||||||
_notify_error(QString("%1 %2%3").arg(LOCAL8BIT("不支持的录像文件版本 "), QString(m_hdr.info.ver), LOCAL8BIT("!\n\n此播放器支持录像文件版本 4。")));
|
_notify_error(QString("%1 %2%3").arg(LOCAL8BIT("不支持的录像文件版本 "), QString(m_hdr.info.ver), LOCAL8BIT("!\n\n此播放器支持录像文件版本 4。")));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
// e.g.: "C:/abc/def\\..\\test.txt" => "C:\\abc\\def\\..\\test.txt"
|
// e.g.: "C:/abc/def\\..\\test.txt" => "C:\\abc\\def\\..\\test.txt"
|
||||||
wchar_t* ex_fix_path(const wchar_t* in_path);
|
wchar_t* ex_fix_path(const wchar_t* in_path);
|
||||||
|
|
||||||
wchar_t* ex_exec_file(void); // must use ex_free() to release returned value.
|
wchar_t* ex_exec_file(); // must use ex_free() to release returned value.
|
||||||
EX_BOOL ex_is_abspath(const wchar_t* in_path);
|
EX_BOOL ex_is_abspath(const wchar_t* in_path);
|
||||||
wchar_t* ex_abspath(const wchar_t* in_path); // must use ex_free() to release returned value.
|
wchar_t* ex_abspath(const wchar_t* in_path); // must use ex_free() to release returned value.
|
||||||
wchar_t* ex_dirname(const wchar_t* in_filename); // must use ex_free() to release returned value.
|
wchar_t* ex_dirname(const wchar_t* in_filename); // must use ex_free() to release returned value.
|
||||||
|
@ -19,6 +19,9 @@ wchar_t* ex_dirname(const wchar_t* in_filename); // must use ex_free() to releas
|
||||||
EX_BOOL ex_is_dir_exists(const wchar_t* in_path);
|
EX_BOOL ex_is_dir_exists(const wchar_t* in_path);
|
||||||
EX_BOOL ex_is_file_exists(const wchar_t* in_file);
|
EX_BOOL ex_is_file_exists(const wchar_t* in_file);
|
||||||
|
|
||||||
|
EX_BOOL ex_rename_file(const wchar_t* from_name, const wchar_t* to_name);
|
||||||
|
EX_BOOL ex_remove_file(const wchar_t* file_name);
|
||||||
|
|
||||||
EX_BOOL ex_copy_file(const wchar_t* from_file, const wchar_t* to_file);
|
EX_BOOL ex_copy_file(const wchar_t* from_file, const wchar_t* to_file);
|
||||||
|
|
||||||
// join a path, last param must be NULL.
|
// join a path, last param must be NULL.
|
||||||
|
|
|
@ -4,217 +4,256 @@
|
||||||
|
|
||||||
static void _wstr_replace(ex_wstr& inout_str, const wchar_t* sfrom, const wchar_t* sto)
|
static void _wstr_replace(ex_wstr& inout_str, const wchar_t* sfrom, const wchar_t* sto)
|
||||||
{
|
{
|
||||||
ex_wstr::size_type pos = 0;
|
ex_wstr::size_type pos = 0;
|
||||||
size_t len_from = wcslen(sfrom);
|
size_t len_from = wcslen(sfrom);
|
||||||
size_t len_to = wcslen(sto);
|
size_t len_to = wcslen(sto);
|
||||||
while (ex_wstr::npos != (pos = inout_str.find(sfrom, pos)))
|
while (ex_wstr::npos != (pos = inout_str.find(sfrom, pos)))
|
||||||
{
|
{
|
||||||
inout_str.replace(pos, len_from, sto);
|
inout_str.replace(pos, len_from, sto);
|
||||||
pos += (len_to - len_from + 1);
|
pos += (len_to - len_from + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t* ex_fix_path(const wchar_t* in_path)
|
wchar_t* ex_fix_path(const wchar_t* in_path)
|
||||||
{
|
{
|
||||||
if (NULL == in_path)
|
if (nullptr == in_path)
|
||||||
return NULL;
|
return nullptr;
|
||||||
ex_wstr _path(in_path);
|
ex_wstr _path(in_path);
|
||||||
#ifdef EX_OS_WIN32
|
#ifdef EX_OS_WIN32
|
||||||
_wstr_replace(_path, L"/", L"\\");
|
_wstr_replace(_path, L"/", L"\\");
|
||||||
_wstr_replace(_path, L"\\\\", L"\\");
|
_wstr_replace(_path, L"\\\\", L"\\");
|
||||||
#else
|
#else
|
||||||
_wstr_replace(_path, L"//", L"/");
|
_wstr_replace(_path, L"//", L"/");
|
||||||
#endif
|
#endif
|
||||||
return ex_wcsdup(_path.c_str());
|
return ex_wcsdup(_path.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t* ex_exec_file(void)
|
wchar_t* ex_exec_file()
|
||||||
{
|
{
|
||||||
ex_wstr path;
|
ex_wstr path;
|
||||||
if (!ex_exec_file(path))
|
if (!ex_exec_file(path))
|
||||||
return NULL;
|
return nullptr;
|
||||||
return ex_wcsdup(path.c_str());
|
return ex_wcsdup(path.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
EX_BOOL ex_is_abspath(const wchar_t* in_path)
|
EX_BOOL ex_is_abspath(const wchar_t* in_path)
|
||||||
{
|
{
|
||||||
#ifdef EX_OS_WIN32
|
#ifdef EX_OS_WIN32
|
||||||
if (wcslen(in_path) >= 2)
|
if (wcslen(in_path) >= 2)
|
||||||
{
|
{
|
||||||
if (in_path[1] == L':')
|
if (in_path[1] == L':')
|
||||||
return EX_TRUE;
|
return EX_TRUE;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (wcslen(in_path) >= 1)
|
if (wcslen(in_path) >= 1)
|
||||||
{
|
{
|
||||||
if (in_path[0] == L'/')
|
if (in_path[0] == L'/')
|
||||||
return EX_TRUE;
|
return EX_TRUE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return EX_FALSE;
|
return EX_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t* ex_abspath(const wchar_t* in_path)
|
wchar_t* ex_abspath(const wchar_t* in_path)
|
||||||
{
|
{
|
||||||
ex_wstr tmp(in_path);
|
ex_wstr tmp(in_path);
|
||||||
if (!ex_abspath(tmp))
|
if (!ex_abspath(tmp))
|
||||||
return NULL;
|
return nullptr;
|
||||||
else
|
else
|
||||||
return ex_wcsdup(tmp.c_str());
|
return ex_wcsdup(tmp.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t* ex_abspath_to(const wchar_t* base_abs_path, const wchar_t* relate_path)
|
wchar_t* ex_abspath_to(const wchar_t* base_abs_path, const wchar_t* relate_path)
|
||||||
{
|
{
|
||||||
ex_wstr tmp;
|
ex_wstr tmp;
|
||||||
if (!ex_abspath_to(base_abs_path, relate_path, tmp))
|
if (!ex_abspath_to(base_abs_path, relate_path, tmp))
|
||||||
return NULL;
|
return nullptr;
|
||||||
else
|
else
|
||||||
return ex_wcsdup(tmp.c_str());
|
return ex_wcsdup(tmp.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t* ex_dirname(const wchar_t* in_filename)
|
wchar_t* ex_dirname(const wchar_t* in_filename)
|
||||||
{
|
{
|
||||||
ex_wstr tmp(in_filename);
|
ex_wstr tmp(in_filename);
|
||||||
if (!ex_dirname(tmp))
|
if (!ex_dirname(tmp))
|
||||||
return NULL;
|
return nullptr;
|
||||||
else
|
else
|
||||||
return ex_wcsdup(tmp.c_str());
|
return ex_wcsdup(tmp.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ex_dirname(ex_wstr& inout_filename)
|
bool ex_dirname(ex_wstr& inout_filename)
|
||||||
{
|
{
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
wchar_t *match = NULL;
|
wchar_t* match = nullptr;
|
||||||
|
|
||||||
wchar_t* ret = ex_wcsdup(inout_filename.c_str());
|
wchar_t* ret = ex_wcsdup(inout_filename.c_str());
|
||||||
if (NULL == ret)
|
if (nullptr == ret)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
len = wcslen(ret);
|
len = wcslen(ret);
|
||||||
|
|
||||||
if (ret[len] == EX_SEP)
|
if (ret[len] == EX_SEP)
|
||||||
{
|
{
|
||||||
ret[len] = EX_NULL_END;
|
ret[len] = EX_NULL_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
match = wcsrchr(ret, EX_SEP);
|
match = wcsrchr(ret, EX_SEP);
|
||||||
if (match != NULL)
|
if (match != nullptr)
|
||||||
{
|
{
|
||||||
*match = EX_NULL_END;
|
*match = EX_NULL_END;
|
||||||
inout_filename = ret;
|
inout_filename = ret;
|
||||||
ex_free(ret);
|
ex_free(ret);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ex_free(ret);
|
ex_free(ret);
|
||||||
inout_filename = EX_CURRENT_DIR_STR;
|
inout_filename = EX_CURRENT_DIR_STR;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// ex_free(ret);
|
// ex_free(ret);
|
||||||
// return false;
|
// return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EX_BOOL ex_is_dir_exists(const wchar_t* in_path)
|
EX_BOOL ex_is_dir_exists(const wchar_t* in_path)
|
||||||
{
|
{
|
||||||
#ifdef EX_OS_WIN32
|
#ifdef EX_OS_WIN32
|
||||||
if (!PathFileExists(in_path))
|
if (!PathFileExists(in_path))
|
||||||
return false;
|
return false;
|
||||||
if (!PathIsDirectory(in_path))
|
if (!PathIsDirectory(in_path))
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
struct stat si;
|
struct stat si;
|
||||||
ex_astr _in_path;
|
ex_astr _in_path;
|
||||||
ex_wstr2astr(in_path, _in_path);
|
ex_wstr2astr(in_path, _in_path);
|
||||||
if (0 != stat(_in_path.c_str(), &si))
|
if (0 != stat(_in_path.c_str(), &si))
|
||||||
return false;
|
return false;
|
||||||
if (!S_ISDIR(si.st_mode))
|
if (!S_ISDIR(si.st_mode))
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
EX_BOOL ex_is_file_exists(const wchar_t* in_file)
|
EX_BOOL ex_is_file_exists(const wchar_t* in_file)
|
||||||
{
|
{
|
||||||
#ifdef EX_OS_WIN32
|
#ifdef EX_OS_WIN32
|
||||||
if (!PathFileExists(in_file))
|
if (!PathFileExists(in_file))
|
||||||
return false;
|
return EX_FALSE;
|
||||||
if (PathIsDirectory(in_file))
|
if (PathIsDirectory(in_file))
|
||||||
return false;
|
return EX_FALSE;
|
||||||
#else
|
#else
|
||||||
struct stat si;
|
struct stat si;
|
||||||
ex_astr _in_file;
|
ex_astr _in_file;
|
||||||
ex_wstr2astr(in_file, _in_file);
|
ex_wstr2astr(in_file, _in_file);
|
||||||
if (0 != stat(_in_file.c_str(), &si))
|
if (0 != stat(_in_file.c_str(), &si))
|
||||||
return false;
|
return EX_FALSE;
|
||||||
if (!S_ISREG(si.st_mode))
|
if (!S_ISREG(si.st_mode))
|
||||||
return false;
|
return EX_FALSE;
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return EX_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
EX_BOOL ex_rename_file(const wchar_t* from_name, const wchar_t* to_name)
|
||||||
|
{
|
||||||
|
#ifdef EX_OS_WIN32
|
||||||
|
if(!MoveFile(from_name, to_name))
|
||||||
|
return EX_FALSE;
|
||||||
|
#else
|
||||||
|
ex_astr tmp_from;
|
||||||
|
ex_astr tmp_to;
|
||||||
|
ex_wstr2astr(from_name, tmp_from);
|
||||||
|
ex_wstr2astr(to_name, tmp_to);
|
||||||
|
if (0 != rename(tmp_from.c_str(), tmp_to.c_str()))
|
||||||
|
return EX_FALSE;
|
||||||
|
#endif
|
||||||
|
return EX_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
EX_BOOL ex_remove_file(const wchar_t* file_name)
|
||||||
|
{
|
||||||
|
#ifdef EX_OS_WIN32
|
||||||
|
if(!DeleteFile(file_name))
|
||||||
|
return EX_FALSE;
|
||||||
|
#else
|
||||||
|
ex_astr tmp_file;
|
||||||
|
ex_wstr2astr(file_name, tmp_file);
|
||||||
|
if (0 != unlink(tmp_file.c_str()))
|
||||||
|
return EX_FALSE;
|
||||||
|
#endif
|
||||||
|
return EX_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EX_BOOL ex_copy_file(const wchar_t* from_file, const wchar_t* to_file) {
|
EX_BOOL ex_copy_file(const wchar_t* from_file, const wchar_t* to_file)
|
||||||
|
{
|
||||||
#ifdef EX_OS_WIN32
|
#ifdef EX_OS_WIN32
|
||||||
if (CopyFile(from_file, to_file, TRUE))
|
if (CopyFile(from_file, to_file, TRUE))
|
||||||
return EX_TRUE;
|
return EX_TRUE;
|
||||||
else
|
else
|
||||||
return EX_FALSE;
|
return EX_FALSE;
|
||||||
#else
|
#else
|
||||||
ex_astr source;
|
ex_astr source;
|
||||||
ex_astr target;
|
ex_astr target;
|
||||||
ex_wstr2astr(from_file, source);
|
ex_wstr2astr(from_file, source);
|
||||||
ex_wstr2astr(to_file, target);
|
ex_wstr2astr(to_file, target);
|
||||||
|
|
||||||
struct stat src_stat;
|
struct stat src_stat;
|
||||||
if (lstat(source.c_str(), &src_stat) == -1)
|
if (lstat(source.c_str(), &src_stat) == -1)
|
||||||
return EX_FALSE;
|
return EX_FALSE;
|
||||||
|
|
||||||
if (S_ISLNK(src_stat.st_mode)) {
|
if (S_ISLNK(src_stat.st_mode))
|
||||||
char lnk[1024] = {0};
|
{
|
||||||
ssize_t lnk_size;
|
char lnk[1024] = {0};
|
||||||
if ((lnk_size = readlink(source.c_str(), lnk, 1023)) == -1)
|
ssize_t lnk_size;
|
||||||
return EX_FALSE;
|
if ((lnk_size = readlink(source.c_str(), lnk, 1023)) == -1)
|
||||||
lnk[lnk_size] = '\0';
|
return EX_FALSE;
|
||||||
if (symlink(lnk, target.c_str()) == -1)
|
lnk[lnk_size] = '\0';
|
||||||
return EX_FALSE;
|
if (symlink(lnk, target.c_str()) == -1)
|
||||||
}
|
return EX_FALSE;
|
||||||
else if (S_ISREG(src_stat.st_mode)) {
|
}
|
||||||
int src = -1, dst = -1;
|
else if (S_ISREG(src_stat.st_mode))
|
||||||
ssize_t rsize = 0;
|
{
|
||||||
char buf[1024] = {0};
|
int src = -1, dst = -1;
|
||||||
if ((src = open(source.c_str(), O_RDONLY)) == -1) {
|
ssize_t rsize = 0;
|
||||||
close(dst);
|
char buf[1024] = {0};
|
||||||
return EX_FALSE;
|
if ((src = open(source.c_str(), O_RDONLY)) == -1)
|
||||||
}
|
{
|
||||||
if ((dst = creat(target.c_str(), src_stat.st_mode)) == -1)
|
close(dst);
|
||||||
return EX_FALSE;
|
return EX_FALSE;
|
||||||
|
}
|
||||||
|
if ((dst = creat(target.c_str(), src_stat.st_mode)) == -1)
|
||||||
|
return EX_FALSE;
|
||||||
|
|
||||||
while ((rsize = read(src, buf, 1024))) {
|
while ((rsize = read(src, buf, 1024)))
|
||||||
if (rsize == -1 && errno == EINTR)
|
{
|
||||||
continue;
|
if (rsize == -1 && errno == EINTR)
|
||||||
if (rsize == -1) {
|
continue;
|
||||||
close(src);
|
if (rsize == -1)
|
||||||
close(dst);
|
{
|
||||||
return EX_FALSE;
|
close(src);
|
||||||
}
|
close(dst);
|
||||||
while (write(dst, buf, rsize) == -1) {
|
return EX_FALSE;
|
||||||
if (errno != EINTR) {
|
}
|
||||||
close(src);
|
while (write(dst, buf, rsize) == -1)
|
||||||
close(dst);
|
{
|
||||||
return EX_FALSE;
|
if (errno != EINTR)
|
||||||
}
|
{
|
||||||
}
|
close(src);
|
||||||
}
|
close(dst);
|
||||||
close(src);
|
return EX_FALSE;
|
||||||
close(dst);
|
}
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
return EX_FALSE;
|
close(src);
|
||||||
}
|
close(dst);
|
||||||
return EX_TRUE;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return EX_FALSE;
|
||||||
|
}
|
||||||
|
return EX_TRUE;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,60 +263,60 @@ EX_BOOL ex_copy_file(const wchar_t* from_file, const wchar_t* to_file) {
|
||||||
bool ex_exec_file(ex_wstr& out_filename)
|
bool ex_exec_file(ex_wstr& out_filename)
|
||||||
{
|
{
|
||||||
#ifdef EX_OS_WIN32
|
#ifdef EX_OS_WIN32
|
||||||
wchar_t modulename_w[EX_PATH_MAX];
|
wchar_t modulename_w[EX_PATH_MAX];
|
||||||
if (!GetModuleFileNameW(NULL, modulename_w, EX_PATH_MAX))
|
if (!GetModuleFileNameW(nullptr, modulename_w, EX_PATH_MAX))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
out_filename = modulename_w;
|
out_filename = modulename_w;
|
||||||
return ex_abspath(out_filename);
|
return ex_abspath(out_filename);
|
||||||
|
|
||||||
#elif defined(EX_OS_MACOS)
|
#elif defined(EX_OS_MACOS)
|
||||||
char buffer[EX_PATH_MAX];
|
char buffer[EX_PATH_MAX];
|
||||||
//char out_path[PATH_MAX];
|
//char out_path[PATH_MAX];
|
||||||
uint32_t length = EX_PATH_MAX;
|
uint32_t length = EX_PATH_MAX;
|
||||||
|
|
||||||
memset(buffer, 0, EX_PATH_MAX);
|
memset(buffer, 0, EX_PATH_MAX);
|
||||||
//memset(out_filename, 0, EX_PATH_MAX);
|
//memset(out_filename, 0, EX_PATH_MAX);
|
||||||
|
|
||||||
/* Mac OS X has special function to obtain path to executable.
|
/* Mac OS X has special function to obtain path to executable.
|
||||||
* This may return a symlink.
|
* This may return a symlink.
|
||||||
*/
|
*/
|
||||||
if (_NSGetExecutablePath(buffer, &length) != 0)
|
if (_NSGetExecutablePath(buffer, &length) != 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!ex_astr2wstr(buffer, out_filename))
|
if (!ex_astr2wstr(buffer, out_filename))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
//return ex_abspath(out_filename);
|
//return ex_abspath(out_filename);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
char buffer[EX_PATH_MAX];
|
char buffer[EX_PATH_MAX];
|
||||||
ssize_t result = -1;
|
ssize_t result = -1;
|
||||||
|
|
||||||
memset(buffer, 0, EX_PATH_MAX);
|
memset(buffer, 0, EX_PATH_MAX);
|
||||||
|
|
||||||
// On Linux, FreeBSD, and Solaris, we try these /proc paths first
|
// On Linux, FreeBSD, and Solaris, we try these /proc paths first
|
||||||
#if defined(EX_OS_LINUX)
|
#if defined(EX_OS_LINUX)
|
||||||
result = readlink("/proc/self/exe", buffer, EX_PATH_MAX); // Linux
|
result = readlink("/proc/self/exe", buffer, EX_PATH_MAX); // Linux
|
||||||
#elif defined(EX_OS_FREEBSD)
|
#elif defined(EX_OS_FREEBSD)
|
||||||
result = readlink("/proc/curproc/file", buffer, EX_PATH_MAX); // FreeBSD
|
result = readlink("/proc/curproc/file", buffer, EX_PATH_MAX); // FreeBSD
|
||||||
#else
|
#else
|
||||||
# error not implement.
|
# error not implement.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (-1 != result)
|
if (-1 != result)
|
||||||
{
|
{
|
||||||
/* execfile is not yet zero-terminated. result is the byte count. */
|
/* execfile is not yet zero-terminated. result is the byte count. */
|
||||||
*(buffer + result) = '\0';
|
*(buffer + result) = '\0';
|
||||||
if (!ex_astr2wstr(buffer, out_filename))
|
if (!ex_astr2wstr(buffer, out_filename))
|
||||||
return false;
|
return false;
|
||||||
return ex_abspath(out_filename);
|
return ex_abspath(out_filename);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,7 +324,7 @@ bool ex_exec_file(ex_wstr& out_filename)
|
||||||
// {
|
// {
|
||||||
// #ifdef EX_OS_WIN32
|
// #ifdef EX_OS_WIN32
|
||||||
// wchar_t _tmp[EX_PATH_MAX] = { 0 };
|
// wchar_t _tmp[EX_PATH_MAX] = { 0 };
|
||||||
// if (NULL == _wfullpath(_tmp, inout_path.c_str(), EX_PATH_MAX))
|
// if (nullptr == _wfullpath(_tmp, inout_path.c_str(), EX_PATH_MAX))
|
||||||
// return false;
|
// return false;
|
||||||
// if (!PathFileExists(_tmp))
|
// if (!PathFileExists(_tmp))
|
||||||
// return false;
|
// return false;
|
||||||
|
@ -296,7 +335,7 @@ bool ex_exec_file(ex_wstr& out_filename)
|
||||||
// if (!ex_wstr2astr(inout_path, _path, EX_CODEPAGE_UTF8))
|
// if (!ex_wstr2astr(inout_path, _path, EX_CODEPAGE_UTF8))
|
||||||
// return false;
|
// return false;
|
||||||
// char _tmp[EX_PATH_MAX] = { 0 };
|
// char _tmp[EX_PATH_MAX] = { 0 };
|
||||||
// if (NULL == realpath(_path.c_str(), _tmp))
|
// if (nullptr == realpath(_path.c_str(), _tmp))
|
||||||
// return false;
|
// return false;
|
||||||
// _path = _tmp;
|
// _path = _tmp;
|
||||||
// return ex_astr2wstr(_path, inout_path, EX_CODEPAGE_UTF8);
|
// return ex_astr2wstr(_path, inout_path, EX_CODEPAGE_UTF8);
|
||||||
|
@ -305,24 +344,25 @@ bool ex_exec_file(ex_wstr& out_filename)
|
||||||
|
|
||||||
bool ex_abspath(ex_wstr& inout_path)
|
bool ex_abspath(ex_wstr& inout_path)
|
||||||
{
|
{
|
||||||
wchar_t* _path = NULL;
|
wchar_t* _path = nullptr;
|
||||||
#ifdef EX_OS_UNIX
|
#ifdef EX_OS_UNIX
|
||||||
if(ex_is_abspath(inout_path.c_str()))
|
if (ex_is_abspath(inout_path.c_str()))
|
||||||
{
|
{
|
||||||
_path = ex_fix_path(inout_path.c_str());
|
_path = ex_fix_path(inout_path.c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char sz_cwd[PATH_MAX] = {0};
|
char sz_cwd[PATH_MAX] = {0};
|
||||||
if(NULL == getcwd(sz_cwd, PATH_MAX)) {
|
if (nullptr == getcwd(sz_cwd, PATH_MAX))
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ex_wstr str_cwd;
|
ex_wstr str_cwd;
|
||||||
if(!ex_astr2wstr(sz_cwd, str_cwd))
|
if (!ex_astr2wstr(sz_cwd, str_cwd))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ex_wstr str_abs_path;
|
ex_wstr str_abs_path;
|
||||||
if(!ex_abspath_to(str_cwd, inout_path, str_abs_path))
|
if (!ex_abspath_to(str_cwd, inout_path, str_abs_path))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
_path = ex_wcsdup(str_abs_path.c_str());
|
_path = ex_wcsdup(str_abs_path.c_str());
|
||||||
|
@ -334,191 +374,191 @@ bool ex_abspath(ex_wstr& inout_path)
|
||||||
_path = ex_fix_path(inout_path.c_str());
|
_path = ex_fix_path(inout_path.c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(_path == NULL)
|
if (_path == nullptr)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ex_wstrs paths;
|
ex_wstrs paths;
|
||||||
wchar_t* _str = _path;
|
wchar_t* _str = _path;
|
||||||
wchar_t* _tmp = NULL;
|
wchar_t* _tmp = nullptr;
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
_tmp = wcschr(_str, EX_SEP);
|
_tmp = wcschr(_str, EX_SEP);
|
||||||
if (NULL == _tmp)
|
if (nullptr == _tmp)
|
||||||
{
|
{
|
||||||
if (wcslen(_str) > 0)
|
if (wcslen(_str) > 0)
|
||||||
paths.push_back(_str);
|
paths.push_back(_str);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_tmp[0] = EX_NULL_END;
|
_tmp[0] = EX_NULL_END;
|
||||||
paths.push_back(_str);
|
paths.push_back(_str);
|
||||||
_str = _tmp + 1;
|
_str = _tmp + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ex_free(_path);
|
ex_free(_path);
|
||||||
|
|
||||||
ex_wstrs::iterator it = paths.begin();
|
auto it = paths.begin();
|
||||||
for (; it != paths.end(); )
|
for (; it != paths.end();)
|
||||||
{
|
{
|
||||||
if ((*it) == L"..")
|
if ((*it) == L"..")
|
||||||
{
|
{
|
||||||
if (it == paths.begin())
|
if (it == paths.begin())
|
||||||
return false;
|
return false;
|
||||||
ex_wstrs::iterator it_tmp = it;
|
auto it_tmp = it;
|
||||||
--it_tmp;
|
--it_tmp;
|
||||||
paths.erase(it);
|
paths.erase(it);
|
||||||
paths.erase(it_tmp);
|
paths.erase(it_tmp);
|
||||||
it = paths.begin();
|
it = paths.begin();
|
||||||
}
|
}
|
||||||
else if ((*it) == L".")
|
else if ((*it) == L".")
|
||||||
{
|
{
|
||||||
paths.erase(it);
|
paths.erase(it);
|
||||||
it = paths.begin();
|
it = paths.begin();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inout_path.clear();
|
inout_path.clear();
|
||||||
bool is_first = true;
|
bool is_first = true;
|
||||||
it = paths.begin();
|
it = paths.begin();
|
||||||
for (; it != paths.end(); ++it)
|
for (; it != paths.end(); ++it)
|
||||||
{
|
{
|
||||||
if (is_first)
|
if (is_first)
|
||||||
{
|
{
|
||||||
#ifdef EX_OS_WIN32
|
#ifdef EX_OS_WIN32
|
||||||
if ((*it)[1] != L':')
|
if ((*it)[1] != L':')
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
// if ((*it)[0] != L'/')
|
// if ((*it)[0] != L'/')
|
||||||
#endif
|
#endif
|
||||||
// return false;
|
// return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_first)
|
if (!is_first)
|
||||||
inout_path += EX_SEP_STR;
|
inout_path += EX_SEP_STR;
|
||||||
|
|
||||||
inout_path += (*it);
|
inout_path += (*it);
|
||||||
is_first = false;
|
is_first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ex_path_join(ex_wstr& inout_path, EX_BOOL auto_abspath, ...)
|
bool ex_path_join(ex_wstr& inout_path, EX_BOOL auto_abspath, ...)
|
||||||
{
|
{
|
||||||
wchar_t* tmp;
|
wchar_t* tmp;
|
||||||
|
|
||||||
ex_wstr _path(inout_path);
|
ex_wstr _path(inout_path);
|
||||||
|
|
||||||
va_list argp;
|
va_list argp;
|
||||||
va_start(argp, auto_abspath);
|
va_start(argp, auto_abspath);
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
tmp = va_arg(argp, wchar_t*);
|
tmp = va_arg(argp, wchar_t*);
|
||||||
if (NULL == tmp)
|
if (!tmp)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (_path.length() > 0)
|
if (_path.length() > 0)
|
||||||
{
|
{
|
||||||
if (_path[_path.length() - 1] != EX_SEP)
|
if (_path[_path.length() - 1] != EX_SEP)
|
||||||
_path += EX_SEP_STR;
|
_path += EX_SEP_STR;
|
||||||
}
|
}
|
||||||
|
|
||||||
_path += tmp;
|
_path += tmp;
|
||||||
}
|
}
|
||||||
va_end(argp);
|
va_end(argp);
|
||||||
|
|
||||||
if (auto_abspath)
|
if (auto_abspath)
|
||||||
if (!ex_abspath(_path))
|
if (!ex_abspath(_path))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
inout_path = _path;
|
inout_path = _path;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t* ex_path_join(const wchar_t* in_path, EX_BOOL auto_abspath, ...)
|
wchar_t* ex_path_join(const wchar_t* in_path, EX_BOOL auto_abspath, ...)
|
||||||
{
|
{
|
||||||
wchar_t* tmp;
|
wchar_t* tmp;
|
||||||
|
|
||||||
ex_wstr _path(in_path);
|
ex_wstr _path(in_path);
|
||||||
|
|
||||||
va_list argp;
|
va_list argp;
|
||||||
va_start(argp, auto_abspath);
|
va_start(argp, auto_abspath);
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
tmp = va_arg(argp, wchar_t*);
|
tmp = va_arg(argp, wchar_t*);
|
||||||
if (NULL == tmp)
|
if (!tmp)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (_path.length() > 0)
|
if (_path.length() > 0)
|
||||||
{
|
{
|
||||||
if (_path[_path.length() - 1] != EX_SEP)
|
if (_path[_path.length() - 1] != EX_SEP)
|
||||||
_path += EX_SEP_STR;
|
_path += EX_SEP_STR;
|
||||||
}
|
}
|
||||||
|
|
||||||
_path += tmp;
|
_path += tmp;
|
||||||
}
|
}
|
||||||
va_end(argp);
|
va_end(argp);
|
||||||
|
|
||||||
if (auto_abspath)
|
if (auto_abspath)
|
||||||
if (!ex_abspath(_path))
|
if (!ex_abspath(_path))
|
||||||
return NULL;
|
return nullptr;
|
||||||
|
|
||||||
return ex_wcsdup(_path.c_str());
|
return ex_wcsdup(_path.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ex_abspath_to(const ex_wstr& base_abs_path, const ex_wstr& relate_path, ex_wstr& out_path)
|
bool ex_abspath_to(const ex_wstr& base_abs_path, const ex_wstr& relate_path, ex_wstr& out_path)
|
||||||
{
|
{
|
||||||
out_path = base_abs_path;
|
out_path = base_abs_path;
|
||||||
out_path += EX_SEP_STR;
|
out_path += EX_SEP_STR;
|
||||||
out_path += relate_path;
|
out_path += relate_path;
|
||||||
|
|
||||||
return ex_abspath(out_path);
|
return ex_abspath(out_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ex_mkdirs(const ex_wstr& in_path)
|
bool ex_mkdirs(const ex_wstr& in_path)
|
||||||
{
|
{
|
||||||
if (ex_is_dir_exists(in_path.c_str()))
|
if (ex_is_dir_exists(in_path.c_str()))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
ex_wstr tmp_path(in_path);
|
ex_wstr tmp_path(in_path);
|
||||||
if (!ex_path_join(tmp_path, false, L"..", NULL))
|
if (!ex_path_join(tmp_path, false, L"..", nullptr))
|
||||||
return false;
|
return false;
|
||||||
if (!ex_abspath(tmp_path))
|
if (!ex_abspath(tmp_path))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!ex_mkdirs(tmp_path))
|
if (!ex_mkdirs(tmp_path))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ex_astr _path;
|
ex_astr _path;
|
||||||
#ifdef EX_OS_WIN32
|
#ifdef EX_OS_WIN32
|
||||||
ex_wstr2astr(in_path, _path);
|
ex_wstr2astr(in_path, _path);
|
||||||
if (0 == _mkdir(_path.c_str()))
|
if (0 == _mkdir(_path.c_str()))
|
||||||
return true;
|
return true;
|
||||||
#else
|
#else
|
||||||
ex_wstr2astr(in_path, _path);
|
ex_wstr2astr(in_path, _path);
|
||||||
int status = mkdir(_path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
int status = mkdir(_path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||||
if (0 != status)
|
if (0 != status)
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ex_path_ext_name(const ex_wstr& in_filename, ex_wstr& out_ext)
|
bool ex_path_ext_name(const ex_wstr& in_filename, ex_wstr& out_ext)
|
||||||
{
|
{
|
||||||
ex_wstr::size_type pos_dot = in_filename.rfind(L'.');
|
ex_wstr::size_type pos_dot = in_filename.rfind(L'.');
|
||||||
ex_wstr::size_type pos_sep = in_filename.rfind(EX_SEP);
|
ex_wstr::size_type pos_sep = in_filename.rfind(EX_SEP);
|
||||||
|
|
||||||
if (pos_dot == ex_wstr::npos || pos_dot <= pos_sep)
|
if (pos_dot == ex_wstr::npos || pos_dot <= pos_sep)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
out_ext.assign(in_filename, pos_dot + 1, in_filename.length() - pos_dot - 1);
|
out_ext.assign(in_filename, pos_dot + 1, in_filename.length() - pos_dot - 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
27
make.sh
27
make.sh
|
@ -1,9 +1,16 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
PATH_ROOT=$(cd "$(dirname "$0")"; pwd)
|
PATH_ROOT=$(cd "$(dirname "$0")"; pwd)
|
||||||
#CFG_FILE=config.json
|
|
||||||
|
# =================================================================
|
||||||
|
# Please change the following 2 lines to fit your development
|
||||||
|
# environment if you want to build teleport components for such
|
||||||
|
# platforms.
|
||||||
|
# =================================================================
|
||||||
|
PY_EXEC_WINDOWS="C:\\Program Files(x86)\\python-3.7\\python.exe"
|
||||||
|
PY_EXEC_MACOS="/usr/local/bin/python3"
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
function check_cfg_file
|
function check_cfg_file
|
||||||
{
|
{
|
||||||
|
@ -20,11 +27,13 @@ function build_win
|
||||||
check_cfg_file
|
check_cfg_file
|
||||||
|
|
||||||
# find pyexec from json file
|
# find pyexec from json file
|
||||||
pyexec=$(grep -P '"pyexec":' ./${CFG_FILE} | grep -Po '(?<="pyexec":)([[:space:]]*)"(.*)"')
|
# pyexec=$(grep -P '"pyexec":' ./${CFG_FILE} | grep -Po '(?<="pyexec":)([[:space:]]*)"(.*)"')
|
||||||
# remove left "
|
# remove left "
|
||||||
pyexec=${pyexec#*\"}
|
#pyexec=${pyexec#*\"}
|
||||||
# remove right "
|
# remove right "
|
||||||
pyexec=${pyexec%\"*}
|
#pyexec=${pyexec%\"*}
|
||||||
|
|
||||||
|
pyexec=${PY_EXEC_WINDOWS}
|
||||||
|
|
||||||
# make sure configuration item exists.
|
# make sure configuration item exists.
|
||||||
if [ "${pyexec}-x" = "-x" ] ; then
|
if [ "${pyexec}-x" = "-x" ] ; then
|
||||||
|
@ -96,7 +105,7 @@ function build_macos
|
||||||
{
|
{
|
||||||
check_cfg_file
|
check_cfg_file
|
||||||
|
|
||||||
python3 -B "${PATH_ROOT}/build/build.py" $@
|
${PY_EXEC_MACOS} -B "${PATH_ROOT}/build/build.py" $@
|
||||||
}
|
}
|
||||||
|
|
||||||
function on_error()
|
function on_error()
|
||||||
|
@ -137,13 +146,13 @@ SYS_NAME=${SYS_NAME:0:4} # cut first 4 char.
|
||||||
if [ ${SYS_NAME} = "Linu" ] ; then
|
if [ ${SYS_NAME} = "Linu" ] ; then
|
||||||
export CFG_FILE=config.linux.json
|
export CFG_FILE=config.linux.json
|
||||||
build_linux $@
|
build_linux $@
|
||||||
elif [ ${SYS_NAME} = "Darw" ] ; then
|
elif [ ${SYS_NAME} = "Darw" ] ; then
|
||||||
export CFG_FILE=config.macos.json
|
export CFG_FILE=config.macos.json
|
||||||
build_macos $@
|
build_macos $@
|
||||||
elif [ ${SYS_NAME} == "MSYS" ] ; then
|
elif [ ${SYS_NAME} == "MSYS" ] ; then
|
||||||
export CFG_FILE=config.windows.json
|
export CFG_FILE=config.windows.json
|
||||||
build_win $@
|
build_win $@
|
||||||
else
|
else
|
||||||
on_error_begin "Unsupported platform."
|
on_error_begin "Unsupported platform."
|
||||||
echo "To build teleport on Windows, please read document at:"
|
echo "To build teleport on Windows, please read document at:"
|
||||||
echo " https://docs.tp4a.com/develop/windows"
|
echo " https://docs.tp4a.com/develop/windows"
|
||||||
|
|
Loading…
Reference in New Issue