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)) {
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));
return;
}
@ -333,14 +333,14 @@ void ThrData::_run() {
TS_RECORD_PKG pkg;
read_len = fdata->read(reinterpret_cast<char*>(&pkg), 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));
return;
}
file_processed += sizeof(TS_RECORD_PKG);
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));
return;
}
@ -351,7 +351,7 @@ void ThrData::_run() {
QByteArray pkg_data = fdata->read(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));
return;
}
@ -359,7 +359,7 @@ void ThrData::_run() {
UpdateData* dat = _parse(pkg, pkg_data);
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));
return;
}
@ -633,7 +633,7 @@ bool ThrData::_load_header() {
}
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。")));
return false;
}

View File

@ -11,7 +11,7 @@
// 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_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);
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.
@ -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_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);
// 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)
{
if (NULL == in_path)
return NULL;
if (nullptr == in_path)
return nullptr;
ex_wstr _path(in_path);
#ifdef EX_OS_WIN32
_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());
}
wchar_t* ex_exec_file(void)
wchar_t* ex_exec_file()
{
ex_wstr path;
if (!ex_exec_file(path))
return NULL;
return nullptr;
return ex_wcsdup(path.c_str());
}
@ -58,7 +58,7 @@ wchar_t* ex_abspath(const wchar_t* in_path)
{
ex_wstr tmp(in_path);
if (!ex_abspath(tmp))
return NULL;
return nullptr;
else
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;
if (!ex_abspath_to(base_abs_path, relate_path, tmp))
return NULL;
return nullptr;
else
return ex_wcsdup(tmp.c_str());
}
@ -76,7 +76,7 @@ wchar_t* ex_dirname(const wchar_t* in_filename)
{
ex_wstr tmp(in_filename);
if (!ex_dirname(tmp))
return NULL;
return nullptr;
else
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)
{
size_t len = 0;
wchar_t *match = NULL;
wchar_t* match = nullptr;
wchar_t* ret = ex_wcsdup(inout_filename.c_str());
if (NULL == ret)
if (nullptr == ret)
return false;
len = wcslen(ret);
@ -98,7 +98,7 @@ bool ex_dirname(ex_wstr& inout_filename)
}
match = wcsrchr(ret, EX_SEP);
if (match != NULL)
if (match != nullptr)
{
*match = EX_NULL_END;
inout_filename = ret;
@ -140,23 +140,54 @@ EX_BOOL ex_is_file_exists(const wchar_t* in_file)
{
#ifdef EX_OS_WIN32
if (!PathFileExists(in_file))
return false;
return EX_FALSE;
if (PathIsDirectory(in_file))
return false;
return EX_FALSE;
#else
struct stat si;
ex_astr _in_file;
ex_wstr2astr(in_file, _in_file);
if (0 != stat(_in_file.c_str(), &si))
return false;
return EX_FALSE;
if (!S_ISREG(si.st_mode))
return false;
return EX_FALSE;
#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
if (CopyFile(from_file, to_file, 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)
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;
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)
return EX_FALSE;
}
else if (S_ISREG(src_stat.st_mode)) {
else if (S_ISREG(src_stat.st_mode))
{
int src = -1, dst = -1;
ssize_t rsize = 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);
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) {
if (rsize == -1)
{
close(src);
close(dst);
return EX_FALSE;
}
while (write(dst, buf, rsize) == -1) {
if (errno != EINTR) {
while (write(dst, buf, rsize) == -1)
{
if (errno != EINTR)
{
close(src);
close(dst);
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(dst);
}
else {
else
{
return EX_FALSE;
}
return EX_TRUE;
@ -225,7 +264,7 @@ bool ex_exec_file(ex_wstr& out_filename)
{
#ifdef EX_OS_WIN32
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;
out_filename = modulename_w;
@ -285,7 +324,7 @@ bool ex_exec_file(ex_wstr& out_filename)
// {
// #ifdef EX_OS_WIN32
// 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;
// if (!PathFileExists(_tmp))
// return false;
@ -296,7 +335,7 @@ bool ex_exec_file(ex_wstr& out_filename)
// if (!ex_wstr2astr(inout_path, _path, EX_CODEPAGE_UTF8))
// return false;
// char _tmp[EX_PATH_MAX] = { 0 };
// if (NULL == realpath(_path.c_str(), _tmp))
// if (nullptr == realpath(_path.c_str(), _tmp))
// return false;
// _path = _tmp;
// return ex_astr2wstr(_path, inout_path, EX_CODEPAGE_UTF8);
@ -305,7 +344,7 @@ bool ex_exec_file(ex_wstr& out_filename)
bool ex_abspath(ex_wstr& inout_path)
{
wchar_t* _path = NULL;
wchar_t* _path = nullptr;
#ifdef EX_OS_UNIX
if (ex_is_abspath(inout_path.c_str()))
{
@ -314,7 +353,8 @@ bool ex_abspath(ex_wstr& inout_path)
else
{
char sz_cwd[PATH_MAX] = {0};
if(NULL == getcwd(sz_cwd, PATH_MAX)) {
if (nullptr == getcwd(sz_cwd, PATH_MAX))
{
return false;
}
ex_wstr str_cwd;
@ -334,16 +374,16 @@ bool ex_abspath(ex_wstr& inout_path)
_path = ex_fix_path(inout_path.c_str());
#endif
if(_path == NULL)
if (_path == nullptr)
return false;
ex_wstrs paths;
wchar_t* _str = _path;
wchar_t* _tmp = NULL;
wchar_t* _tmp = nullptr;
for (;;)
{
_tmp = wcschr(_str, EX_SEP);
if (NULL == _tmp)
if (nullptr == _tmp)
{
if (wcslen(_str) > 0)
paths.push_back(_str);
@ -358,14 +398,14 @@ bool ex_abspath(ex_wstr& inout_path)
}
ex_free(_path);
ex_wstrs::iterator it = paths.begin();
auto it = paths.begin();
for (; it != paths.end();)
{
if ((*it) == L"..")
{
if (it == paths.begin())
return false;
ex_wstrs::iterator it_tmp = it;
auto it_tmp = it;
--it_tmp;
paths.erase(it);
paths.erase(it_tmp);
@ -420,7 +460,7 @@ bool ex_path_join(ex_wstr& inout_path, EX_BOOL auto_abspath, ...)
for (;;)
{
tmp = va_arg(argp, wchar_t*);
if (NULL == tmp)
if (!tmp)
break;
if (_path.length() > 0)
@ -452,7 +492,7 @@ wchar_t* ex_path_join(const wchar_t* in_path, EX_BOOL auto_abspath, ...)
for (;;)
{
tmp = va_arg(argp, wchar_t*);
if (NULL == tmp)
if (!tmp)
break;
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 (!ex_abspath(_path))
return NULL;
return nullptr;
return ex_wcsdup(_path.c_str());
}
@ -488,7 +528,7 @@ bool ex_mkdirs(const ex_wstr& in_path)
return true;
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;
if (!ex_abspath(tmp_path))
return false;

23
make.sh
View File

@ -1,9 +1,16 @@
#!/bin/bash
set -e
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
{
@ -20,11 +27,13 @@ function build_win
check_cfg_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 "
pyexec=${pyexec#*\"}
#pyexec=${pyexec#*\"}
# remove right "
pyexec=${pyexec%\"*}
#pyexec=${pyexec%\"*}
pyexec=${PY_EXEC_WINDOWS}
# make sure configuration item exists.
if [ "${pyexec}-x" = "-x" ] ; then
@ -96,7 +105,7 @@ function build_macos
{
check_cfg_file
python3 -B "${PATH_ROOT}/build/build.py" $@
${PY_EXEC_MACOS} -B "${PATH_ROOT}/build/build.py" $@
}
function on_error()