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

@ -4,217 +4,256 @@
static void _wstr_replace(ex_wstr& inout_str, const wchar_t* sfrom, const wchar_t* sto)
{
ex_wstr::size_type pos = 0;
size_t len_from = wcslen(sfrom);
size_t len_to = wcslen(sto);
while (ex_wstr::npos != (pos = inout_str.find(sfrom, pos)))
{
inout_str.replace(pos, len_from, sto);
pos += (len_to - len_from + 1);
}
ex_wstr::size_type pos = 0;
size_t len_from = wcslen(sfrom);
size_t len_to = wcslen(sto);
while (ex_wstr::npos != (pos = inout_str.find(sfrom, pos)))
{
inout_str.replace(pos, len_from, sto);
pos += (len_to - len_from + 1);
}
}
wchar_t* ex_fix_path(const wchar_t* in_path)
{
if (NULL == in_path)
return NULL;
ex_wstr _path(in_path);
if (nullptr == in_path)
return nullptr;
ex_wstr _path(in_path);
#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
_wstr_replace(_path, L"//", L"/");
_wstr_replace(_path, L"//", L"/");
#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;
if (!ex_exec_file(path))
return NULL;
return ex_wcsdup(path.c_str());
ex_wstr path;
if (!ex_exec_file(path))
return nullptr;
return ex_wcsdup(path.c_str());
}
EX_BOOL ex_is_abspath(const wchar_t* in_path)
{
#ifdef EX_OS_WIN32
if (wcslen(in_path) >= 2)
{
if (in_path[1] == L':')
return EX_TRUE;
}
if (wcslen(in_path) >= 2)
{
if (in_path[1] == L':')
return EX_TRUE;
}
#else
if (wcslen(in_path) >= 1)
{
if (in_path[0] == L'/')
return EX_TRUE;
}
if (wcslen(in_path) >= 1)
{
if (in_path[0] == L'/')
return EX_TRUE;
}
#endif
return EX_FALSE;
return EX_FALSE;
}
wchar_t* ex_abspath(const wchar_t* in_path)
{
ex_wstr tmp(in_path);
if (!ex_abspath(tmp))
return NULL;
else
return ex_wcsdup(tmp.c_str());
ex_wstr tmp(in_path);
if (!ex_abspath(tmp))
return nullptr;
else
return ex_wcsdup(tmp.c_str());
}
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;
else
return ex_wcsdup(tmp.c_str());
ex_wstr tmp;
if (!ex_abspath_to(base_abs_path, relate_path, tmp))
return nullptr;
else
return ex_wcsdup(tmp.c_str());
}
wchar_t* ex_dirname(const wchar_t* in_filename)
{
ex_wstr tmp(in_filename);
if (!ex_dirname(tmp))
return NULL;
else
return ex_wcsdup(tmp.c_str());
ex_wstr tmp(in_filename);
if (!ex_dirname(tmp))
return nullptr;
else
return ex_wcsdup(tmp.c_str());
}
bool ex_dirname(ex_wstr& inout_filename)
{
size_t len = 0;
wchar_t *match = NULL;
size_t len = 0;
wchar_t* match = nullptr;
wchar_t* ret = ex_wcsdup(inout_filename.c_str());
if (NULL == ret)
return false;
wchar_t* ret = ex_wcsdup(inout_filename.c_str());
if (nullptr == ret)
return false;
len = wcslen(ret);
len = wcslen(ret);
if (ret[len] == EX_SEP)
{
ret[len] = EX_NULL_END;
}
if (ret[len] == EX_SEP)
{
ret[len] = EX_NULL_END;
}
match = wcsrchr(ret, EX_SEP);
if (match != NULL)
{
*match = EX_NULL_END;
inout_filename = ret;
ex_free(ret);
return true;
}
else
{
ex_free(ret);
inout_filename = EX_CURRENT_DIR_STR;
return true;
}
//
// ex_free(ret);
// return false;
match = wcsrchr(ret, EX_SEP);
if (match != nullptr)
{
*match = EX_NULL_END;
inout_filename = ret;
ex_free(ret);
return true;
}
else
{
ex_free(ret);
inout_filename = EX_CURRENT_DIR_STR;
return true;
}
//
// ex_free(ret);
// return false;
}
EX_BOOL ex_is_dir_exists(const wchar_t* in_path)
{
#ifdef EX_OS_WIN32
if (!PathFileExists(in_path))
return false;
if (!PathIsDirectory(in_path))
return false;
if (!PathFileExists(in_path))
return false;
if (!PathIsDirectory(in_path))
return false;
#else
struct stat si;
struct stat si;
ex_astr _in_path;
ex_wstr2astr(in_path, _in_path);
if (0 != stat(_in_path.c_str(), &si))
return false;
if (!S_ISDIR(si.st_mode))
return false;
if (0 != stat(_in_path.c_str(), &si))
return false;
if (!S_ISDIR(si.st_mode))
return false;
#endif
return true;
return true;
}
EX_BOOL ex_is_file_exists(const wchar_t* in_file)
{
#ifdef EX_OS_WIN32
if (!PathFileExists(in_file))
return false;
if (PathIsDirectory(in_file))
return false;
if (!PathFileExists(in_file))
return EX_FALSE;
if (PathIsDirectory(in_file))
return EX_FALSE;
#else
struct stat si;
struct stat si;
ex_astr _in_file;
ex_wstr2astr(in_file, _in_file);
if (0 != stat(_in_file.c_str(), &si))
return false;
if (!S_ISREG(si.st_mode))
return false;
if (0 != stat(_in_file.c_str(), &si))
return EX_FALSE;
if (!S_ISREG(si.st_mode))
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;
else
return EX_FALSE;
if (CopyFile(from_file, to_file, TRUE))
return EX_TRUE;
else
return EX_FALSE;
#else
ex_astr source;
ex_astr target;
ex_wstr2astr(from_file, source);
ex_wstr2astr(to_file, target);
ex_astr source;
ex_astr target;
ex_wstr2astr(from_file, source);
ex_wstr2astr(to_file, target);
struct stat src_stat;
if (lstat(source.c_str(), &src_stat) == -1)
return EX_FALSE;
struct stat src_stat;
if (lstat(source.c_str(), &src_stat) == -1)
return EX_FALSE;
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)
return EX_FALSE;
lnk[lnk_size] = '\0';
if (symlink(lnk, target.c_str()) == -1)
return EX_FALSE;
}
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) {
close(dst);
return EX_FALSE;
}
if ((dst = creat(target.c_str(), src_stat.st_mode)) == -1)
return EX_FALSE;
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)
return EX_FALSE;
lnk[lnk_size] = '\0';
if (symlink(lnk, target.c_str()) == -1)
return EX_FALSE;
}
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)
{
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))) {
if (rsize == -1 && errno == EINTR)
continue;
if (rsize == -1) {
close(src);
close(dst);
return EX_FALSE;
}
while (write(dst, buf, rsize) == -1) {
if (errno != EINTR) {
close(src);
close(dst);
return EX_FALSE;
}
}
}
close(src);
close(dst);
}
else {
return EX_FALSE;
}
return EX_TRUE;
while ((rsize = read(src, buf, 1024)))
{
if (rsize == -1 && errno == EINTR)
continue;
if (rsize == -1)
{
close(src);
close(dst);
return EX_FALSE;
}
while (write(dst, buf, rsize) == -1)
{
if (errno != EINTR)
{
close(src);
close(dst);
return EX_FALSE;
}
}
}
close(src);
close(dst);
}
else
{
return EX_FALSE;
}
return EX_TRUE;
#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)
{
#ifdef EX_OS_WIN32
wchar_t modulename_w[EX_PATH_MAX];
if (!GetModuleFileNameW(NULL, modulename_w, EX_PATH_MAX))
return false;
wchar_t modulename_w[EX_PATH_MAX];
if (!GetModuleFileNameW(nullptr, modulename_w, EX_PATH_MAX))
return false;
out_filename = modulename_w;
return ex_abspath(out_filename);
out_filename = modulename_w;
return ex_abspath(out_filename);
#elif defined(EX_OS_MACOS)
char buffer[EX_PATH_MAX];
//char out_path[PATH_MAX];
uint32_t length = EX_PATH_MAX;
char buffer[EX_PATH_MAX];
//char out_path[PATH_MAX];
uint32_t length = EX_PATH_MAX;
memset(buffer, 0, EX_PATH_MAX);
//memset(out_filename, 0, EX_PATH_MAX);
memset(buffer, 0, EX_PATH_MAX);
//memset(out_filename, 0, EX_PATH_MAX);
/* Mac OS X has special function to obtain path to executable.
* This may return a symlink.
*/
if (_NSGetExecutablePath(buffer, &length) != 0)
return false;
/* Mac OS X has special function to obtain path to executable.
* This may return a symlink.
*/
if (_NSGetExecutablePath(buffer, &length) != 0)
return false;
if (!ex_astr2wstr(buffer, out_filename))
return false;
if (!ex_astr2wstr(buffer, out_filename))
return false;
//return ex_abspath(out_filename);
return true;
//return ex_abspath(out_filename);
return true;
#else
char buffer[EX_PATH_MAX];
ssize_t result = -1;
char buffer[EX_PATH_MAX];
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)
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)
result = readlink("/proc/curproc/file", buffer, EX_PATH_MAX); // FreeBSD
result = readlink("/proc/curproc/file", buffer, EX_PATH_MAX); // FreeBSD
#else
# error not implement.
#endif
if (-1 != result)
{
/* execfile is not yet zero-terminated. result is the byte count. */
*(buffer + result) = '\0';
if (!ex_astr2wstr(buffer, out_filename))
return false;
return ex_abspath(out_filename);
}
else
{
return false;
}
if (-1 != result)
{
/* execfile is not yet zero-terminated. result is the byte count. */
*(buffer + result) = '\0';
if (!ex_astr2wstr(buffer, out_filename))
return false;
return ex_abspath(out_filename);
}
else
{
return false;
}
#endif
}
@ -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,24 +344,25 @@ 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()))
if (ex_is_abspath(inout_path.c_str()))
{
_path = ex_fix_path(inout_path.c_str());
}
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;
if(!ex_astr2wstr(sz_cwd, str_cwd))
if (!ex_astr2wstr(sz_cwd, str_cwd))
return false;
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;
_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());
#endif
if(_path == NULL)
if (_path == nullptr)
return false;
ex_wstrs paths;
wchar_t* _str = _path;
wchar_t* _tmp = NULL;
for (;;)
{
_tmp = wcschr(_str, EX_SEP);
if (NULL == _tmp)
{
if (wcslen(_str) > 0)
paths.push_back(_str);
break;
}
else
{
_tmp[0] = EX_NULL_END;
paths.push_back(_str);
_str = _tmp + 1;
}
}
ex_free(_path);
ex_wstrs paths;
wchar_t* _str = _path;
wchar_t* _tmp = nullptr;
for (;;)
{
_tmp = wcschr(_str, EX_SEP);
if (nullptr == _tmp)
{
if (wcslen(_str) > 0)
paths.push_back(_str);
break;
}
else
{
_tmp[0] = EX_NULL_END;
paths.push_back(_str);
_str = _tmp + 1;
}
}
ex_free(_path);
ex_wstrs::iterator it = paths.begin();
for (; it != paths.end(); )
{
if ((*it) == L"..")
{
if (it == paths.begin())
return false;
ex_wstrs::iterator it_tmp = it;
--it_tmp;
paths.erase(it);
paths.erase(it_tmp);
it = paths.begin();
}
else if ((*it) == L".")
{
paths.erase(it);
it = paths.begin();
}
else
{
++it;
}
}
auto it = paths.begin();
for (; it != paths.end();)
{
if ((*it) == L"..")
{
if (it == paths.begin())
return false;
auto it_tmp = it;
--it_tmp;
paths.erase(it);
paths.erase(it_tmp);
it = paths.begin();
}
else if ((*it) == L".")
{
paths.erase(it);
it = paths.begin();
}
else
{
++it;
}
}
inout_path.clear();
bool is_first = true;
it = paths.begin();
for (; it != paths.end(); ++it)
{
if (is_first)
{
inout_path.clear();
bool is_first = true;
it = paths.begin();
for (; it != paths.end(); ++it)
{
if (is_first)
{
#ifdef EX_OS_WIN32
if ((*it)[1] != L':')
return false;
if ((*it)[1] != L':')
return false;
#else
// if ((*it)[0] != L'/')
// if ((*it)[0] != L'/')
#endif
// return false;
}
// return false;
}
if (!is_first)
inout_path += EX_SEP_STR;
if (!is_first)
inout_path += EX_SEP_STR;
inout_path += (*it);
is_first = false;
}
inout_path += (*it);
is_first = false;
}
return true;
return true;
}
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_start(argp, auto_abspath);
for (;;)
{
tmp = va_arg(argp, wchar_t*);
if (NULL == tmp)
break;
va_list argp;
va_start(argp, auto_abspath);
for (;;)
{
tmp = va_arg(argp, wchar_t*);
if (!tmp)
break;
if (_path.length() > 0)
{
if (_path[_path.length() - 1] != EX_SEP)
_path += EX_SEP_STR;
}
if (_path.length() > 0)
{
if (_path[_path.length() - 1] != EX_SEP)
_path += EX_SEP_STR;
}
_path += tmp;
}
va_end(argp);
_path += tmp;
}
va_end(argp);
if (auto_abspath)
if (!ex_abspath(_path))
return false;
if (auto_abspath)
if (!ex_abspath(_path))
return false;
inout_path = _path;
return true;
inout_path = _path;
return true;
}
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_start(argp, auto_abspath);
for (;;)
{
tmp = va_arg(argp, wchar_t*);
if (NULL == tmp)
break;
va_list argp;
va_start(argp, auto_abspath);
for (;;)
{
tmp = va_arg(argp, wchar_t*);
if (!tmp)
break;
if (_path.length() > 0)
{
if (_path[_path.length() - 1] != EX_SEP)
_path += EX_SEP_STR;
}
if (_path.length() > 0)
{
if (_path[_path.length() - 1] != EX_SEP)
_path += EX_SEP_STR;
}
_path += tmp;
}
va_end(argp);
_path += tmp;
}
va_end(argp);
if (auto_abspath)
if (!ex_abspath(_path))
return NULL;
if (auto_abspath)
if (!ex_abspath(_path))
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)
{
out_path = base_abs_path;
out_path += EX_SEP_STR;
out_path += relate_path;
out_path = base_abs_path;
out_path += EX_SEP_STR;
out_path += relate_path;
return ex_abspath(out_path);
return ex_abspath(out_path);
}
bool ex_mkdirs(const ex_wstr& in_path)
{
if (ex_is_dir_exists(in_path.c_str()))
return true;
if (ex_is_dir_exists(in_path.c_str()))
return true;
ex_wstr tmp_path(in_path);
if (!ex_path_join(tmp_path, false, L"..", NULL))
return false;
if (!ex_abspath(tmp_path))
return false;
ex_wstr tmp_path(in_path);
if (!ex_path_join(tmp_path, false, L"..", nullptr))
return false;
if (!ex_abspath(tmp_path))
return false;
if (!ex_mkdirs(tmp_path))
return false;
if (!ex_mkdirs(tmp_path))
return false;
ex_astr _path;
ex_astr _path;
#ifdef EX_OS_WIN32
ex_wstr2astr(in_path, _path);
if (0 == _mkdir(_path.c_str()))
return true;
ex_wstr2astr(in_path, _path);
if (0 == _mkdir(_path.c_str()))
return true;
#else
ex_wstr2astr(in_path, _path);
int status = mkdir(_path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
if (0 != status)
return false;
ex_wstr2astr(in_path, _path);
int status = mkdir(_path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
if (0 != status)
return false;
#endif
return true;
return true;
}
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_sep = in_filename.rfind(EX_SEP);
ex_wstr::size_type pos_dot = in_filename.rfind(L'.');
ex_wstr::size_type pos_sep = in_filename.rfind(EX_SEP);
if (pos_dot == ex_wstr::npos || pos_dot <= pos_sep)
return false;
if (pos_dot == ex_wstr::npos || pos_dot <= pos_sep)
return false;
out_ext.assign(in_filename, pos_dot + 1, in_filename.length() - pos_dot - 1);
return true;
out_ext.assign(in_filename, pos_dot + 1, in_filename.length() - pos_dot - 1);
return true;
}

27
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()
@ -137,13 +146,13 @@ SYS_NAME=${SYS_NAME:0:4} # cut first 4 char.
if [ ${SYS_NAME} = "Linu" ] ; then
export CFG_FILE=config.linux.json
build_linux $@
elif [ ${SYS_NAME} = "Darw" ] ; then
elif [ ${SYS_NAME} = "Darw" ] ; then
export CFG_FILE=config.macos.json
build_macos $@
elif [ ${SYS_NAME} == "MSYS" ] ; then
export CFG_FILE=config.windows.json
build_win $@
else
else
on_error_begin "Unsupported platform."
echo "To build teleport on Windows, please read document at:"
echo " https://docs.tp4a.com/develop/windows"