dev
Apex Liu 2021-08-11 17:00:51 +08:00
parent 931d4016e7
commit 0c27a04034
4 changed files with 392 additions and 340 deletions

View File

@ -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;
} }

View File

@ -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.

View File

@ -16,8 +16,8 @@ static void _wstr_replace(ex_wstr& inout_str, const wchar_t* sfrom, const wchar_
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"\\");
@ -28,11 +28,11 @@ wchar_t* ex_fix_path(const wchar_t* in_path)
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());
} }
@ -58,7 +58,7 @@ 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());
} }
@ -67,7 +67,7 @@ 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());
} }
@ -76,7 +76,7 @@ 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());
} }
@ -84,10 +84,10 @@ wchar_t* ex_dirname(const wchar_t* in_filename)
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);
@ -98,7 +98,7 @@ bool ex_dirname(ex_wstr& inout_filename)
} }
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;
@ -111,9 +111,9 @@ bool ex_dirname(ex_wstr& inout_filename)
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;
} }
@ -140,23 +140,54 @@ 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;
@ -172,7 +203,8 @@ EX_BOOL ex_copy_file(const wchar_t* from_file, const wchar_t* to_file) {
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}; char lnk[1024] = {0};
ssize_t lnk_size; ssize_t lnk_size;
if ((lnk_size = readlink(source.c_str(), lnk, 1023)) == -1) if ((lnk_size = readlink(source.c_str(), lnk, 1023)) == -1)
@ -181,27 +213,33 @@ EX_BOOL ex_copy_file(const wchar_t* from_file, const wchar_t* to_file) {
if (symlink(lnk, target.c_str()) == -1) if (symlink(lnk, target.c_str()) == -1)
return EX_FALSE; return EX_FALSE;
} }
else if (S_ISREG(src_stat.st_mode)) { else if (S_ISREG(src_stat.st_mode))
{
int src = -1, dst = -1; int src = -1, dst = -1;
ssize_t rsize = 0; ssize_t rsize = 0;
char buf[1024] = {0}; char buf[1024] = {0};
if ((src = open(source.c_str(), O_RDONLY)) == -1) { if ((src = open(source.c_str(), O_RDONLY)) == -1)
{
close(dst); close(dst);
return EX_FALSE; return EX_FALSE;
} }
if ((dst = creat(target.c_str(), src_stat.st_mode)) == -1) if ((dst = creat(target.c_str(), src_stat.st_mode)) == -1)
return EX_FALSE; return EX_FALSE;
while ((rsize = read(src, buf, 1024))) { while ((rsize = read(src, buf, 1024)))
{
if (rsize == -1 && errno == EINTR) if (rsize == -1 && errno == EINTR)
continue; continue;
if (rsize == -1) { if (rsize == -1)
{
close(src); close(src);
close(dst); close(dst);
return EX_FALSE; return EX_FALSE;
} }
while (write(dst, buf, rsize) == -1) { while (write(dst, buf, rsize) == -1)
if (errno != EINTR) { {
if (errno != EINTR)
{
close(src); close(src);
close(dst); close(dst);
return EX_FALSE; return EX_FALSE;
@ -211,7 +249,8 @@ EX_BOOL ex_copy_file(const wchar_t* from_file, const wchar_t* to_file) {
close(src); close(src);
close(dst); close(dst);
} }
else { else
{
return EX_FALSE; return EX_FALSE;
} }
return EX_TRUE; return EX_TRUE;
@ -225,7 +264,7 @@ 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;
@ -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,16 +374,16 @@ 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);
@ -358,14 +398,14 @@ bool ex_abspath(ex_wstr& inout_path)
} }
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);
@ -394,9 +434,9 @@ bool ex_abspath(ex_wstr& inout_path)
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)
@ -420,7 +460,7 @@ bool ex_path_join(ex_wstr& inout_path, EX_BOOL 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)
@ -452,7 +492,7 @@ wchar_t* ex_path_join(const wchar_t* in_path, EX_BOOL 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)
@ -467,7 +507,7 @@ wchar_t* ex_path_join(const wchar_t* in_path, EX_BOOL auto_abspath, ...)
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());
} }
@ -488,7 +528,7 @@ bool ex_mkdirs(const ex_wstr& in_path)
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;

23
make.sh
View File

@ -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()