2
0
forked from Ivasoft/DSView

update: Log file path supports unicode string

This commit is contained in:
dreamsourcelabTAI
2022-08-17 14:34:07 +08:00
parent 0df2da582d
commit ef4132e2a7
4 changed files with 31 additions and 13 deletions

View File

@@ -26,14 +26,14 @@
#include <QDir>
#include <QCoreApplication>
#include <QWidget>
#include <string>
#include "devicemanager.h"
#include "sigsession.h"
#include "dsvdef.h"
#include "config/appconfig.h"
#include "log.h"
#include <QTextCodec>
#include <string.h>
#include "utility/path.h"
AppControl::AppControl()
{
@@ -81,16 +81,10 @@ bool AppControl::Init()
}
_session->set_sr_context(sr_ctx);
// firmware resource directory
QString resdir = GetResourceDir();
char res_path[256] = {0};
#ifdef _WIN32
QTextCodec *codec = QTextCodec::codecForName("System");
QByteArray str_tmp = codec->fromUnicode(resdir);
strncpy(res_path, str_tmp.data(), sizeof(res_path) - 1);
#else
strncpy(res_path, resdir.toUtf8().data(), sizeof(res_path) - 1);
#endif
sr_set_firmware_resource_dir(res_path);
std::string res_path = pv::path::ToUnicodePath(resdir);
sr_set_firmware_resource_dir(res_path.c_str());
#if defined(_WIN32) && defined(DEBUG_INFO)
//able run debug with qtcreator

View File

@@ -23,6 +23,8 @@
#include <QString>
#include <QDir>
#include "config/appconfig.h"
#include "utility/path.h"
#include <string>
xlog_writer *dsv_log = nullptr;
static xlog_context *log_ctx = nullptr;
@@ -71,10 +73,12 @@ void dsv_log_enalbe_logfile(bool append)
dsv_info("%s\"%s\"", "Store log to file: ", lf.toUtf8().data());
int ret = xlog_add_receiver_from_file(log_ctx, lf.toUtf8().data(), &log_file_index, append);
std::string log_file = pv::path::ToUnicodePath(lf);
int ret = xlog_add_receiver_from_file(log_ctx, log_file.c_str(), &log_file_index, append);
if (ret != 0){
dsv_err("%s", "Create log file error!");
}
}
}
}

View File

@@ -20,6 +20,9 @@
*/
#include "path.h"
#ifdef _WIN32
#include <QTextCodec>
#endif
namespace pv{
namespace path{
@@ -38,5 +41,20 @@ namespace path{
}
return path;
}
std::string ToUnicodePath(QString path)
{
std::string str;
#ifdef _WIN32
QTextCodec *codec = QTextCodec::codecForName("System");
QByteArray str_tmp = codec->fromUnicode(path);
str = str_tmp.data();
#else
str = path.toUtf8().data();
#endif
return str;
}
}
}

View File

@@ -30,6 +30,8 @@ namespace path{
std::string ConvertPath(QString fileName);
QString GetDirectoryName(QString path);
std::string ToUnicodePath(QString path);
}
}