forked from Ivasoft/DSView
update: install file, and save file name convert
This commit is contained in:
@@ -22,19 +22,21 @@
|
||||
#include "file.h"
|
||||
#include "inputfile.h"
|
||||
#include "sessionfile.h"
|
||||
#include <string.h>
|
||||
|
||||
#include <QFileInfo>
|
||||
|
||||
#include <zip.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
using std::string;
|
||||
#ifdef _WIN32
|
||||
#include <QTextCodec>
|
||||
#endif
|
||||
|
||||
namespace pv {
|
||||
namespace device {
|
||||
|
||||
File::File(QString path) :
|
||||
_path(path)
|
||||
File::File(QString path)
|
||||
:_path(path)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -50,7 +52,10 @@ QString File::format_device_title()
|
||||
|
||||
File* File::create(QString name)
|
||||
{
|
||||
if (sr_session_load(name.toUtf8().data()) == SR_OK) {
|
||||
char f_name[256];
|
||||
File::ConvertFileName(name, f_name, sizeof(f_name));
|
||||
|
||||
if (sr_session_load(f_name) == SR_OK) {
|
||||
GSList *devlist = NULL;
|
||||
sr_session_dev_list(&devlist);
|
||||
sr_session_destroy();
|
||||
@@ -79,7 +84,10 @@ QJsonArray File::get_decoders()
|
||||
QJsonArray dec_array;
|
||||
QJsonParseError error;
|
||||
|
||||
archive = zip_open(_path.toUtf8().data(), 0, &ret);
|
||||
char f_name[256];
|
||||
File::ConvertFileName(_path, f_name, sizeof(f_name));
|
||||
|
||||
archive = zip_open(f_name, 0, &ret);
|
||||
if (archive) {
|
||||
/* read "decoders" */
|
||||
if (zip_stat(archive, "decoders", 0, &zs) != -1) {
|
||||
@@ -111,7 +119,10 @@ QJsonDocument File::get_session()
|
||||
QJsonDocument sessionDoc;
|
||||
QJsonParseError error;
|
||||
|
||||
archive = zip_open(_path.toUtf8().data(), 0, &ret);
|
||||
char f_name[256];
|
||||
File::ConvertFileName(_path, f_name, sizeof(f_name));
|
||||
|
||||
archive = zip_open(f_name, 0, &ret);
|
||||
if (archive) {
|
||||
/* read "decoders" */
|
||||
if (zip_stat(archive, "session", 0, &zs) != -1) {
|
||||
@@ -132,5 +143,29 @@ 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
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
#ifndef DSVIEW_PV_DEVICE_FILE_H
|
||||
#define DSVIEW_PV_DEVICE_FILE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QFile>
|
||||
@@ -43,14 +41,14 @@ public:
|
||||
~File();
|
||||
|
||||
static File* create(QString name);
|
||||
|
||||
QJsonArray get_decoders();
|
||||
|
||||
QJsonDocument get_session();
|
||||
|
||||
public:
|
||||
QString format_device_title();
|
||||
|
||||
static void ConvertFileName(QString fileName, char *out_name, int size);
|
||||
|
||||
protected:
|
||||
const QString _path;
|
||||
};
|
||||
|
||||
@@ -43,7 +43,10 @@ void SessionFile::use(SigSession *owner)
|
||||
release_source();
|
||||
}
|
||||
|
||||
if (sr_session_load(_path.toUtf8().data()) != SR_OK)
|
||||
char f_name[256];
|
||||
File::ConvertFileName(_path, f_name, sizeof(f_name));
|
||||
|
||||
if (sr_session_load(f_name) != SR_OK)
|
||||
throw tr("Failed to open file.\n");
|
||||
|
||||
GSList *devlist = NULL;
|
||||
|
||||
@@ -181,7 +181,7 @@ bool StoreSession::save_start()
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string _filename = getFileName(_file_name);
|
||||
std::string _filename = getFileName();
|
||||
if (m_zipDoc.CreateNew(_filename.c_str(), false))
|
||||
{
|
||||
if ( !m_zipDoc.AddFromBuffer("header", meta_data.c_str(), meta_data.size())
|
||||
@@ -948,7 +948,8 @@ bool StoreSession::json_decoders(QJsonArray &array)
|
||||
auto rows = stack->get_rows_gshow();
|
||||
for (auto i = rows.begin(); i != rows.end(); i++) {
|
||||
pv::data::decode::Row _row = (*i).first;
|
||||
show_obj[_row.title()] = QJsonValue::fromVariant((*i).second);
|
||||
QString kn = _row.title();
|
||||
show_obj[kn] = QJsonValue::fromVariant((*i).second);
|
||||
}
|
||||
dec_obj["show"] = show_obj;
|
||||
|
||||
@@ -1323,14 +1324,15 @@ void StoreSession::MakeChunkName(char *chunk_name, int chunk_num, int index, int
|
||||
}
|
||||
}
|
||||
|
||||
std::string StoreSession::getFileName(QString fileName)
|
||||
std::string StoreSession::getFileName()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
#ifdef _WIN32
|
||||
QTextCodec *code = QTextCodec::codecForName("GB2312");
|
||||
return code->fromUnicode(fileName).data();
|
||||
#else
|
||||
return _file_name.toUtf8().toStdString();
|
||||
if (code != NULL){
|
||||
return code->fromUnicode(_file_name).data();
|
||||
}
|
||||
#endif
|
||||
return _file_name.toUtf8().toStdString();
|
||||
}
|
||||
|
||||
} // pv
|
||||
|
||||
@@ -94,7 +94,7 @@ 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(QString fileName);
|
||||
std:: string getFileName();
|
||||
|
||||
signals:
|
||||
void progress_updated();
|
||||
|
||||
Reference in New Issue
Block a user