mirror of
https://github.com/DreamSourceLab/DSView.git
synced 2025-01-23 13:42:55 +08:00
Fix issue of saving/loading file with special characters
This commit is contained in:
parent
e9b7d9aa5d
commit
26d695837e
@ -131,8 +131,7 @@ int main(int argc, char *argv[])
|
|||||||
dir.cd(QApplication::applicationName()) &&
|
dir.cd(QApplication::applicationName()) &&
|
||||||
dir.cd("res")) {
|
dir.cd("res")) {
|
||||||
QString res_dir = dir.absolutePath() + "/";
|
QString res_dir = dir.absolutePath() + "/";
|
||||||
QByteArray str_tmp = res_dir.toLocal8Bit();
|
strcpy(DS_RES_PATH, res_dir.toUtf8().data());
|
||||||
strcpy(DS_RES_PATH, str_tmp.data());
|
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "ERROR: config files don't exist.";
|
qDebug() << "ERROR: config files don't exist.";
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -47,7 +47,7 @@ QString File::format_device_title() const
|
|||||||
|
|
||||||
File* File::create(QString name)
|
File* File::create(QString name)
|
||||||
{
|
{
|
||||||
if (sr_session_load(name.toLocal8Bit().data()) == SR_OK) {
|
if (sr_session_load(name.toUtf8().data()) == SR_OK) {
|
||||||
GSList *devlist = NULL;
|
GSList *devlist = NULL;
|
||||||
sr_session_dev_list(&devlist);
|
sr_session_dev_list(&devlist);
|
||||||
sr_session_destroy();
|
sr_session_destroy();
|
||||||
@ -76,7 +76,7 @@ QJsonArray File::get_decoders()
|
|||||||
QJsonArray dec_array;
|
QJsonArray dec_array;
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
|
|
||||||
archive = zip_open(_path.toLocal8Bit().data(), 0, &ret);
|
archive = zip_open(_path.toUtf8().data(), 0, &ret);
|
||||||
if (archive) {
|
if (archive) {
|
||||||
/* read "decoders" */
|
/* read "decoders" */
|
||||||
if (zip_stat(archive, "decoders", 0, &zs) != -1) {
|
if (zip_stat(archive, "decoders", 0, &zs) != -1) {
|
||||||
@ -108,7 +108,7 @@ QJsonDocument File::get_session()
|
|||||||
QJsonDocument sessionDoc;
|
QJsonDocument sessionDoc;
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
|
|
||||||
archive = zip_open(_path.toLocal8Bit().data(), 0, &ret);
|
archive = zip_open(_path.toUtf8().data(), 0, &ret);
|
||||||
if (archive) {
|
if (archive) {
|
||||||
/* read "decoders" */
|
/* read "decoders" */
|
||||||
if (zip_stat(archive, "session", 0, &zs) != -1) {
|
if (zip_stat(archive, "session", 0, &zs) != -1) {
|
||||||
|
@ -87,7 +87,7 @@ sr_input_format* InputFile::determine_input_file_format(const QString filename)
|
|||||||
|
|
||||||
/* Otherwise, try to find an input module that can handle this file. */
|
/* Otherwise, try to find an input module that can handle this file. */
|
||||||
for (i = 0; inputs[i]; i++) {
|
for (i = 0; inputs[i]; i++) {
|
||||||
if (inputs[i]->format_match(filename.toLocal8Bit().data()))
|
if (inputs[i]->format_match(filename.toUtf8().data()))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ sr_input* InputFile::load_input_file_format(const QString filename,
|
|||||||
throw tr("Failed to load file");
|
throw tr("Failed to load file");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stat(filename.toLocal8Bit().data(), &st) == -1)
|
if (stat(filename.toUtf8().data(), &st) == -1)
|
||||||
throw tr("Failed to load file");
|
throw tr("Failed to load file");
|
||||||
|
|
||||||
/* Initialize the input module. */
|
/* Initialize the input module. */
|
||||||
@ -123,7 +123,7 @@ sr_input* InputFile::load_input_file_format(const QString filename,
|
|||||||
in->format = format;
|
in->format = format;
|
||||||
in->param = NULL;
|
in->param = NULL;
|
||||||
if (in->format->init &&
|
if (in->format->init &&
|
||||||
in->format->init(in, filename.toLocal8Bit().data()) != SR_OK) {
|
in->format->init(in, filename.toUtf8().data()) != SR_OK) {
|
||||||
throw tr("Failed to load file");
|
throw tr("Failed to load file");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ void InputFile::run()
|
|||||||
assert(_input);
|
assert(_input);
|
||||||
assert(_input->format);
|
assert(_input->format);
|
||||||
assert(_input->format->loadfile);
|
assert(_input->format->loadfile);
|
||||||
_input->format->loadfile(_input, _path.toLocal8Bit().data());
|
_input->format->loadfile(_input, _path.toUtf8().data());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // device
|
} // device
|
||||||
|
@ -39,7 +39,7 @@ void SessionFile::use(SigSession *owner)
|
|||||||
{
|
{
|
||||||
assert(!_sdi);
|
assert(!_sdi);
|
||||||
|
|
||||||
if (sr_session_load(_path.toLocal8Bit().data()) != SR_OK)
|
if (sr_session_load(_path.toUtf8().data()) != SR_OK)
|
||||||
throw tr("Failed to open file.\n");
|
throw tr("Failed to open file.\n");
|
||||||
|
|
||||||
GSList *devlist = NULL;
|
GSList *devlist = NULL;
|
||||||
|
@ -478,7 +478,7 @@ void MainWindow::reload()
|
|||||||
void MainWindow::load_file(QString file_name)
|
void MainWindow::load_file(QString file_name)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (strncmp(_session.get_device()->name().toLocal8Bit(), "virtual", 7))
|
if (strncmp(_session.get_device()->name().toUtf8(), "virtual", 7))
|
||||||
session_save();
|
session_save();
|
||||||
_session.set_file(file_name);
|
_session.set_file(file_name);
|
||||||
} catch(QString e) {
|
} catch(QString e) {
|
||||||
@ -540,7 +540,7 @@ void MainWindow::device_detach()
|
|||||||
session_save();
|
session_save();
|
||||||
_view->hide_calibration();
|
_view->hide_calibration();
|
||||||
if (_session.get_device()->dev_inst()->mode != DSO &&
|
if (_session.get_device()->dev_inst()->mode != DSO &&
|
||||||
strncmp(_session.get_device()->name().toLocal8Bit(), "virtual", 7)) {
|
strncmp(_session.get_device()->name().toUtf8(), "virtual", 7)) {
|
||||||
const boost::shared_ptr<data::Snapshot> logic_snapshot(_session.get_snapshot(SR_CHANNEL_LOGIC));
|
const boost::shared_ptr<data::Snapshot> logic_snapshot(_session.get_snapshot(SR_CHANNEL_LOGIC));
|
||||||
assert(logic_snapshot);
|
assert(logic_snapshot);
|
||||||
const boost::shared_ptr<data::Snapshot> analog_snapshot(_session.get_snapshot(SR_CHANNEL_ANALOG));
|
const boost::shared_ptr<data::Snapshot> analog_snapshot(_session.get_snapshot(SR_CHANNEL_ANALOG));
|
||||||
@ -744,7 +744,7 @@ void MainWindow::session_save()
|
|||||||
QString file_name = dir.absolutePath() + "/" +
|
QString file_name = dir.absolutePath() + "/" +
|
||||||
driver_name + mode_name +
|
driver_name + mode_name +
|
||||||
lang_name + ".dsc";
|
lang_name + ".dsc";
|
||||||
if (strncmp(driver_name.toLocal8Bit(), "virtual", 7) &&
|
if (strncmp(driver_name.toUtf8(), "virtual", 7) &&
|
||||||
!file_name.isEmpty()) {
|
!file_name.isEmpty()) {
|
||||||
store_session(file_name);
|
store_session(file_name);
|
||||||
}
|
}
|
||||||
@ -932,7 +932,7 @@ bool MainWindow::load_session_json(QJsonDocument json, bool file_dev)
|
|||||||
|
|
||||||
// check device and mode
|
// check device and mode
|
||||||
const sr_dev_inst *const sdi = _session.get_device()->dev_inst();
|
const sr_dev_inst *const sdi = _session.get_device()->dev_inst();
|
||||||
if ((!file_dev && strcmp(sdi->driver->name, sessionObj["Device"].toString().toLocal8Bit()) != 0) ||
|
if ((!file_dev && strcmp(sdi->driver->name, sessionObj["Device"].toString().toUtf8()) != 0) ||
|
||||||
sdi->mode != sessionObj["DeviceMode"].toDouble()) {
|
sdi->mode != sessionObj["DeviceMode"].toDouble()) {
|
||||||
dialogs::DSMessageBox msg(this);
|
dialogs::DSMessageBox msg(this);
|
||||||
msg.mBox()->setText(tr("Session Error"));
|
msg.mBox()->setText(tr("Session Error"));
|
||||||
@ -1065,7 +1065,7 @@ bool MainWindow::load_session_json(QJsonDocument json, bool file_dev)
|
|||||||
if ((s->get_index() == obj["index"].toDouble()) &&
|
if ((s->get_index() == obj["index"].toDouble()) &&
|
||||||
(s->get_type() == obj["type"].toDouble())) {
|
(s->get_type() == obj["type"].toDouble())) {
|
||||||
s->set_colour(QColor(obj["colour"].toString()));
|
s->set_colour(QColor(obj["colour"].toString()));
|
||||||
s->set_name(g_strdup(obj["name"].toString().toStdString().c_str()));
|
s->set_name(g_strdup(obj["name"].toString().toUtf8().data()));
|
||||||
|
|
||||||
boost::shared_ptr<view::LogicSignal> logicSig;
|
boost::shared_ptr<view::LogicSignal> logicSig;
|
||||||
if ((logicSig = dynamic_pointer_cast<view::LogicSignal>(s))) {
|
if ((logicSig = dynamic_pointer_cast<view::LogicSignal>(s))) {
|
||||||
@ -1095,6 +1095,7 @@ bool MainWindow::load_session_json(QJsonDocument json, bool file_dev)
|
|||||||
// update UI settings
|
// update UI settings
|
||||||
_sampling_bar->update_sample_rate_selector();
|
_sampling_bar->update_sample_rate_selector();
|
||||||
_trigger_widget->device_updated();
|
_trigger_widget->device_updated();
|
||||||
|
_view->header_updated();
|
||||||
|
|
||||||
// load trigger settings
|
// load trigger settings
|
||||||
if (sessionObj.contains("trigger")) {
|
if (sessionObj.contains("trigger")) {
|
||||||
|
@ -182,12 +182,12 @@ bool StoreSession::save_start(QString session_file)
|
|||||||
if (meta_file == NULL) {
|
if (meta_file == NULL) {
|
||||||
_error = tr("Generate temp file failed.");
|
_error = tr("Generate temp file failed.");
|
||||||
} else {
|
} else {
|
||||||
int ret = sr_session_save_init(_file_name.toLocal8Bit().data(),
|
int ret = sr_session_save_init(_file_name.toUtf8().data(),
|
||||||
meta_file.toLocal8Bit().data(),
|
meta_file.toUtf8().data(),
|
||||||
decoders_file.toLocal8Bit().data(),
|
decoders_file.toUtf8().data(),
|
||||||
session_file.toLocal8Bit().data());
|
session_file.toUtf8().data());
|
||||||
if (ret != SR_OK) {
|
if (ret != SR_OK) {
|
||||||
_error = tr("Failed to create zip file. Please check write permission of this path.");
|
_error = tr("Failed to create zip file. Initialization error.");
|
||||||
} else {
|
} else {
|
||||||
_thread = boost::thread(&StoreSession::save_proc, this, snapshot);
|
_thread = boost::thread(&StoreSession::save_proc, this, snapshot);
|
||||||
return !_has_error;
|
return !_has_error;
|
||||||
@ -196,7 +196,7 @@ bool StoreSession::save_start(QString session_file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QFile::remove(_file_name);
|
QFile::remove(_file_name);
|
||||||
_error.clear();
|
//_error.clear();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,7 +239,7 @@ void StoreSession::save_proc(shared_ptr<data::Snapshot> snapshot)
|
|||||||
memset(buf, sample ? 0xff : 0x0, size);
|
memset(buf, sample ? 0xff : 0x0, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret = sr_session_append(_file_name.toLocal8Bit().data(), buf, size,
|
ret = sr_session_append(_file_name.toUtf8().data(), buf, size,
|
||||||
i, ch_index, ch_type, File_Version);
|
i, ch_index, ch_type, File_Version);
|
||||||
if (ret != SR_OK) {
|
if (ret != SR_OK) {
|
||||||
if (!_has_error) {
|
if (!_has_error) {
|
||||||
@ -285,13 +285,13 @@ void StoreSession::save_proc(shared_ptr<data::Snapshot> snapshot)
|
|||||||
memcpy(tmp, buf, buf_end-buf);
|
memcpy(tmp, buf, buf_end-buf);
|
||||||
memcpy(tmp+(buf_end-buf), buf_start, buf+size-buf_end);
|
memcpy(tmp+(buf_end-buf), buf_start, buf+size-buf_end);
|
||||||
}
|
}
|
||||||
ret = sr_session_append(_file_name.toLocal8Bit().data(), tmp, size,
|
ret = sr_session_append(_file_name.toUtf8().data(), tmp, size,
|
||||||
i, 0, ch_type, File_Version);
|
i, 0, ch_type, File_Version);
|
||||||
buf += (size - _unit_count);
|
buf += (size - _unit_count);
|
||||||
if (tmp)
|
if (tmp)
|
||||||
free(tmp);
|
free(tmp);
|
||||||
} else {
|
} else {
|
||||||
ret = sr_session_append(_file_name.toLocal8Bit().data(), buf, size,
|
ret = sr_session_append(_file_name.toUtf8().data(), buf, size,
|
||||||
i, 0, ch_type, File_Version);
|
i, 0, ch_type, File_Version);
|
||||||
buf += size;
|
buf += size;
|
||||||
}
|
}
|
||||||
@ -342,7 +342,7 @@ QString StoreSession::meta_gen(boost::shared_ptr<data::Snapshot> snapshot)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const sr_dev_inst *sdi = _session.get_device()->dev_inst();
|
const sr_dev_inst *sdi = _session.get_device()->dev_inst();
|
||||||
meta = fopen(metafile.toLocal8Bit().data(), "wb");
|
meta = fopen(metafile.toUtf8().data(), "wb");
|
||||||
if (meta == NULL) {
|
if (meta == NULL) {
|
||||||
qDebug() << "Failed to create temp meta file.";
|
qDebug() << "Failed to create temp meta file.";
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -572,7 +572,7 @@ bool StoreSession::export_start()
|
|||||||
while(*supportedModules){
|
while(*supportedModules){
|
||||||
if(*supportedModules == NULL)
|
if(*supportedModules == NULL)
|
||||||
break;
|
break;
|
||||||
if(!strcmp((*supportedModules)->id, _suffix.toLocal8Bit().data())){
|
if(!strcmp((*supportedModules)->id, _suffix.toUtf8().data())){
|
||||||
_outModule = *supportedModules;
|
_outModule = *supportedModules;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -613,7 +613,7 @@ void StoreSession::export_proc(shared_ptr<data::Snapshot> snapshot)
|
|||||||
}
|
}
|
||||||
|
|
||||||
GHashTable *params = g_hash_table_new(g_str_hash, g_str_equal);
|
GHashTable *params = g_hash_table_new(g_str_hash, g_str_equal);
|
||||||
GVariant* filenameGVariant = g_variant_new_bytestring(_file_name.toLocal8Bit().data());
|
GVariant* filenameGVariant = g_variant_new_bytestring(_file_name.toUtf8().data());
|
||||||
g_hash_table_insert(params, (char*)"filename", filenameGVariant);
|
g_hash_table_insert(params, (char*)"filename", filenameGVariant);
|
||||||
GVariant* typeGVariant = g_variant_new_int16(channel_type);
|
GVariant* typeGVariant = g_variant_new_int16(channel_type);
|
||||||
g_hash_table_insert(params, (char*)"type", typeGVariant);
|
g_hash_table_insert(params, (char*)"type", typeGVariant);
|
||||||
@ -999,7 +999,7 @@ void StoreSession::load_decoders(dock::ProtocolDock *widget, QJsonArray dec_arra
|
|||||||
else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT64))
|
else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT64))
|
||||||
new_value = g_variant_new_uint64(options_obj[opt->id].toInt());
|
new_value = g_variant_new_uint64(options_obj[opt->id].toInt());
|
||||||
} else if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("s"))) {
|
} else if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("s"))) {
|
||||||
new_value = g_variant_new_string(options_obj[opt->id].toString().toLocal8Bit().data());
|
new_value = g_variant_new_string(options_obj[opt->id].toString().toUtf8().data());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (new_value != NULL)
|
if (new_value != NULL)
|
||||||
|
@ -287,7 +287,7 @@ bool DsoSignal::load_settings()
|
|||||||
} else {
|
} else {
|
||||||
_bits = DefaultBits;
|
_bits = DefaultBits;
|
||||||
qDebug("Warning: config_get SR_CONF_UNIT_BITS failed, set to %d(default).", DefaultBits);
|
qDebug("Warning: config_get SR_CONF_UNIT_BITS failed, set to %d(default).", DefaultBits);
|
||||||
if (strncmp(_dev_inst->name().toLocal8Bit(), "virtual", 7))
|
if (strncmp(_dev_inst->name().toUtf8().data(), "virtual", 7))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_REF_MIN);
|
gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_REF_MIN);
|
||||||
@ -361,7 +361,7 @@ bool DsoSignal::load_settings()
|
|||||||
g_variant_unref(gvar);
|
g_variant_unref(gvar);
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "ERROR: config_get SR_CONF_TRIGGER_VALUE failed.";
|
qDebug() << "ERROR: config_get SR_CONF_TRIGGER_VALUE failed.";
|
||||||
if (strncmp(_dev_inst->name().toLocal8Bit(), "virtual", 7))
|
if (strncmp(_dev_inst->name().toUtf8().data(), "virtual", 7))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ void Signal::set_name(QString name)
|
|||||||
{
|
{
|
||||||
Trace::set_name(name);
|
Trace::set_name(name);
|
||||||
g_free(_probe->name);
|
g_free(_probe->name);
|
||||||
_probe->name = g_strdup(name.toLocal8Bit().data());
|
_probe->name = g_strdup(name.toUtf8().data());
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::shared_ptr<device::DevInst> Signal::get_device() const
|
boost::shared_ptr<device::DevInst> Signal::get_device() const
|
||||||
|
@ -305,6 +305,9 @@ public slots:
|
|||||||
void set_trig_time();
|
void set_trig_time();
|
||||||
bool trig_time_setted();
|
bool trig_time_setted();
|
||||||
|
|
||||||
|
//
|
||||||
|
void header_updated();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void h_scroll_value_changed(int value);
|
void h_scroll_value_changed(int value);
|
||||||
@ -314,8 +317,6 @@ private slots:
|
|||||||
|
|
||||||
void on_traces_moved();
|
void on_traces_moved();
|
||||||
|
|
||||||
void header_updated();
|
|
||||||
|
|
||||||
void receive_trigger(quint64 trig_pos);
|
void receive_trigger(quint64 trig_pos);
|
||||||
void set_trig_pos(int percent);
|
void set_trig_pos(int percent);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user