forked from Ivasoft/DSView
update: file path convert for c api on windows
This commit is contained in:
@@ -297,6 +297,8 @@ set(DSView_SOURCES
|
||||
DSView/pv/dock/keywordlineedit.cpp
|
||||
DSView/pv/dock/searchcombobox.cpp
|
||||
DSView/pv/dialogs/decoderoptionsdlg.cpp
|
||||
DSView/pv/utility/encoding.cpp
|
||||
DSView/pv/utility/path.cpp
|
||||
)
|
||||
|
||||
set(DSView_HEADERS
|
||||
@@ -385,6 +387,8 @@ set(DSView_HEADERS
|
||||
DSView/pv/dock/keywordlineedit.h
|
||||
DSView/pv/dock/searchcombobox.h
|
||||
DSView/pv/dialogs/decoderoptionsdlg.h
|
||||
DSView/pv/utility/encoding.h
|
||||
DSView/pv/utility/path.h
|
||||
)
|
||||
|
||||
#===============================================================================
|
||||
|
||||
@@ -22,15 +22,11 @@
|
||||
#include "file.h"
|
||||
#include "inputfile.h"
|
||||
#include "sessionfile.h"
|
||||
#include <string.h>
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <zip.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <QTextCodec>
|
||||
#endif
|
||||
#include "../utility/path.h"
|
||||
|
||||
namespace pv {
|
||||
namespace device {
|
||||
@@ -51,11 +47,10 @@ QString File::format_device_title()
|
||||
}
|
||||
|
||||
File* File::create(QString name)
|
||||
{
|
||||
char f_name[256];
|
||||
File::ConvertFileName(name, f_name, sizeof(f_name));
|
||||
{
|
||||
auto f_name = path::ConvertPath(name);
|
||||
|
||||
if (sr_session_load(f_name) == SR_OK) {
|
||||
if (sr_session_load(f_name.c_str()) == SR_OK) {
|
||||
GSList *devlist = NULL;
|
||||
sr_session_dev_list(&devlist);
|
||||
sr_session_destroy();
|
||||
@@ -84,10 +79,9 @@ QJsonArray File::get_decoders()
|
||||
QJsonArray dec_array;
|
||||
QJsonParseError error;
|
||||
|
||||
char f_name[256];
|
||||
File::ConvertFileName(_path, f_name, sizeof(f_name));
|
||||
auto f_name = path::ConvertPath(_path);
|
||||
|
||||
archive = zip_open(f_name, 0, &ret);
|
||||
archive = zip_open(f_name.c_str(), 0, &ret);
|
||||
if (archive) {
|
||||
/* read "decoders" */
|
||||
if (zip_stat(archive, "decoders", 0, &zs) != -1) {
|
||||
@@ -119,10 +113,9 @@ QJsonDocument File::get_session()
|
||||
QJsonDocument sessionDoc;
|
||||
QJsonParseError error;
|
||||
|
||||
char f_name[256];
|
||||
File::ConvertFileName(_path, f_name, sizeof(f_name));
|
||||
auto f_name = path::ConvertPath(_path);
|
||||
|
||||
archive = zip_open(f_name, 0, &ret);
|
||||
archive = zip_open(f_name.c_str(), 0, &ret);
|
||||
if (archive) {
|
||||
/* read "decoders" */
|
||||
if (zip_stat(archive, "session", 0, &zs) != -1) {
|
||||
@@ -143,29 +136,5 @@ QJsonDocument File::get_session()
|
||||
return sessionDoc;
|
||||
}
|
||||
|
||||
void File::ConvertFileName(QString fileName, char *out_name, int size)
|
||||
{
|
||||
assert(out_name);
|
||||
assert(size > 0);
|
||||
memset(out_name, 0, size);
|
||||
|
||||
char *src = NULL;
|
||||
#ifdef _WIN32
|
||||
QTextCodec *code = QTextCodec::codecForName("GB2312");
|
||||
if (code != NULL){
|
||||
src = code->fromUnicode(fileName).data();
|
||||
}
|
||||
#endif
|
||||
if (src == NULL){
|
||||
src = fileName.toUtf8().data();
|
||||
}
|
||||
|
||||
int len = strlen(src);
|
||||
if (len >= size){
|
||||
assert(false);
|
||||
}
|
||||
strcpy(out_name, src);
|
||||
}
|
||||
|
||||
} // device
|
||||
} // pv
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QFile>
|
||||
#include <string.h>
|
||||
|
||||
#include "devinst.h"
|
||||
|
||||
@@ -47,8 +48,6 @@ public:
|
||||
public:
|
||||
QString format_device_title();
|
||||
|
||||
static void ConvertFileName(QString fileName, char *out_name, int size);
|
||||
|
||||
protected:
|
||||
const QString _path;
|
||||
};
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "sessionfile.h"
|
||||
#include <assert.h>
|
||||
#include "../utility/path.h"
|
||||
|
||||
namespace pv {
|
||||
namespace device {
|
||||
@@ -43,10 +44,9 @@ void SessionFile::use(SigSession *owner)
|
||||
release_source();
|
||||
}
|
||||
|
||||
char f_name[256];
|
||||
File::ConvertFileName(_path, f_name, sizeof(f_name));
|
||||
auto f_name = path::ConvertPath(_path);
|
||||
|
||||
if (sr_session_load(f_name) != SR_OK)
|
||||
if (sr_session_load(f_name.c_str()) != SR_OK)
|
||||
throw tr("Failed to open file.\n");
|
||||
|
||||
GSList *devlist = NULL;
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
|
||||
#include "../config/appconfig.h"
|
||||
#include "../dsvdef.h"
|
||||
#include "../utility/encoding.h"
|
||||
|
||||
namespace pv {
|
||||
namespace dialogs {
|
||||
@@ -86,7 +87,7 @@ About::About(QWidget *parent) :
|
||||
if (news.open(QIODevice::ReadOnly)) {
|
||||
|
||||
QTextStream stream(&news);
|
||||
app::set_utf8(stream);
|
||||
encoding::set_utf8(stream);
|
||||
|
||||
QString line;
|
||||
while (!stream.atEnd()){
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "../data/decodermodel.h"
|
||||
#include "../config/appconfig.h"
|
||||
#include "../dsvdef.h"
|
||||
#include "../utility/encoding.h"
|
||||
|
||||
using namespace boost;
|
||||
using namespace std;
|
||||
@@ -149,7 +150,7 @@ void ProtocolExp::accept()
|
||||
QFile file(file_name);
|
||||
file.open(QIODevice::WriteOnly | QIODevice::Text);
|
||||
QTextStream out(&file);
|
||||
app::set_utf8(out);
|
||||
encoding::set_utf8(out);
|
||||
//out.setGenerateByteOrderMark(true); // UTF-8 without BOM
|
||||
|
||||
QFuture<void> future;
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "dsvdef.h"
|
||||
#include "dsvdef.h"
|
||||
#include <string.h>
|
||||
|
||||
#ifdef DS_DEBUG_TRACE
|
||||
@@ -29,14 +29,6 @@
|
||||
}
|
||||
#endif
|
||||
|
||||
#include <QTextStream>
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
#include <QStringConverter>
|
||||
#else
|
||||
#include <QTextCodec>
|
||||
#endif
|
||||
|
||||
namespace DecoderDataFormat
|
||||
{
|
||||
int Parse(const char *name){
|
||||
@@ -58,16 +50,3 @@ namespace DecoderDataFormat
|
||||
return (int)hex;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace app
|
||||
{
|
||||
void set_utf8(QTextStream &stream){
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
stream.setEncoding(QStringConverter::Utf8);
|
||||
#else
|
||||
QTextCodec *code=QTextCodec::codecForName("UTF-8");
|
||||
stream.setCodec(code);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "../config.h"
|
||||
#include <QString>
|
||||
|
||||
#define countof(x) (sizeof(x)/sizeof(x[0]))
|
||||
|
||||
@@ -43,9 +42,7 @@ enum View_type {
|
||||
#else
|
||||
#define ds_debug(x)
|
||||
#endif
|
||||
|
||||
class QWidget;
|
||||
class QTextStream;
|
||||
|
||||
|
||||
#define DESTROY_OBJECT(p) if((p)){delete (p); p = NULL;}
|
||||
#define DESTROY_QT_OBJECT(p) if((p)){((p))->deleteLater(); p = NULL;}
|
||||
@@ -68,9 +65,3 @@ namespace DecoderDataFormat
|
||||
|
||||
int Parse(const char *name);
|
||||
}
|
||||
|
||||
namespace app
|
||||
{
|
||||
void set_utf8(QTextStream &stream);
|
||||
}
|
||||
|
||||
|
||||
@@ -93,6 +93,7 @@
|
||||
#include "appcontrol.h"
|
||||
#include "dsvdef.h"
|
||||
#include "appcontrol.h"
|
||||
#include "utility/encoding.h"
|
||||
|
||||
#define BASE_SESSION_VERSION 2
|
||||
|
||||
@@ -1260,7 +1261,7 @@ bool MainWindow::on_store_session(QString name)
|
||||
}
|
||||
|
||||
QTextStream outStream(&sessionFile);
|
||||
app::set_utf8(outStream);
|
||||
encoding::set_utf8(outStream);
|
||||
|
||||
QJsonObject sessionVar;
|
||||
if (!gen_session_json(sessionVar))
|
||||
|
||||
@@ -59,6 +59,8 @@
|
||||
#include "libsigrokdecode.h"
|
||||
#include "config/appconfig.h"
|
||||
#include "dsvdef.h"
|
||||
#include "utility/encoding.h"
|
||||
#include "utility/path.h"
|
||||
|
||||
|
||||
namespace pv {
|
||||
@@ -181,13 +183,15 @@ bool StoreSession::save_start()
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string _filename = getFileName();
|
||||
auto _filename = path::ConvertPath(_file_name);
|
||||
|
||||
if (m_zipDoc.CreateNew(_filename.c_str(), false))
|
||||
{
|
||||
if ( !m_zipDoc.AddFromBuffer("header", meta_data.c_str(), meta_data.size())
|
||||
|| !m_zipDoc.AddFromBuffer("decoders", decoder_data.c_str(), decoder_data.size())
|
||||
|| !m_zipDoc.AddFromBuffer("session", session_data.c_str(), session_data.size())
|
||||
){
|
||||
)
|
||||
{
|
||||
_has_error = true;
|
||||
_error = m_zipDoc.GetError();
|
||||
}
|
||||
@@ -673,7 +677,7 @@ void StoreSession::export_proc(data::Snapshot *snapshot)
|
||||
QFile file(_file_name);
|
||||
file.open(QIODevice::WriteOnly | QIODevice::Text);
|
||||
QTextStream out(&file);
|
||||
app::set_utf8(out);
|
||||
encoding::set_utf8(out);
|
||||
//out.setGenerateByteOrderMark(true); // UTF-8 without BOM
|
||||
|
||||
// Meta
|
||||
@@ -1324,15 +1328,4 @@ void StoreSession::MakeChunkName(char *chunk_name, int chunk_num, int index, int
|
||||
}
|
||||
}
|
||||
|
||||
std::string StoreSession::getFileName()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
QTextCodec *code = QTextCodec::codecForName("GB2312");
|
||||
if (code != NULL){
|
||||
return code->fromUnicode(_file_name).data();
|
||||
}
|
||||
#endif
|
||||
return _file_name.toUtf8().toStdString();
|
||||
}
|
||||
|
||||
} // pv
|
||||
|
||||
@@ -94,7 +94,6 @@ private:
|
||||
QList<QString> getSuportedExportFormats();
|
||||
double get_integer(GVariant * var);
|
||||
void MakeChunkName(char *chunk_name, int chunk_num, int index, int type, int version);
|
||||
std:: string getFileName();
|
||||
|
||||
signals:
|
||||
void progress_updated();
|
||||
|
||||
42
DSView/pv/utility/encoding.cpp
Normal file
42
DSView/pv/utility/encoding.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* This file is part of the DSView project.
|
||||
* DSView is based on PulseView.
|
||||
*
|
||||
* Copyright (C) 2022 DreamSourceLab <support@dreamsourcelab.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "encoding.h"
|
||||
|
||||
#include <QTextStream>
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
#include <QStringConverter>
|
||||
#else
|
||||
#include <QTextCodec>
|
||||
#endif
|
||||
|
||||
namespace pv::encoding
|
||||
{
|
||||
void set_utf8(QTextStream &stream)
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
stream.setEncoding(QStringConverter::Utf8);
|
||||
#else
|
||||
QTextCodec *code = QTextCodec::codecForName("UTF-8");
|
||||
stream.setCodec(code);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
32
DSView/pv/utility/encoding.h
Normal file
32
DSView/pv/utility/encoding.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of the DSView project.
|
||||
* DSView is based on PulseView.
|
||||
*
|
||||
* Copyright (C) 2022 DreamSourceLab <support@dreamsourcelab.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef UTILITY_ENCODING_H
|
||||
#define UTILITY_ENCODING_H
|
||||
|
||||
class QTextStream;
|
||||
|
||||
namespace pv::encoding
|
||||
{
|
||||
void set_utf8(QTextStream &stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
41
DSView/pv/utility/path.cpp
Normal file
41
DSView/pv/utility/path.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of the DSView project.
|
||||
* DSView is based on PulseView.
|
||||
*
|
||||
* Copyright (C) 2022 DreamSourceLab <support@dreamsourcelab.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "path.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <QTextCodec>
|
||||
#endif
|
||||
|
||||
namespace pv::path
|
||||
{
|
||||
std::string ConvertPath(QString fileName)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
QTextCodec *code = QTextCodec::codecForName("GB2312");
|
||||
if (code != NULL)
|
||||
{
|
||||
return code->fromUnicode(fileName).data();
|
||||
}
|
||||
#endif
|
||||
return fileName.toUtf8().toStdString();
|
||||
}
|
||||
}
|
||||
33
DSView/pv/utility/path.h
Normal file
33
DSView/pv/utility/path.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This file is part of the DSView project.
|
||||
* DSView is based on PulseView.
|
||||
*
|
||||
* Copyright (C) 2022 DreamSourceLab <support@dreamsourcelab.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef UTILITY_PATH_H
|
||||
#define UTILITY_PATH_H
|
||||
|
||||
#include <string>
|
||||
#include <QString>
|
||||
|
||||
namespace pv::path
|
||||
{
|
||||
std::string ConvertPath(QString fileName);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user