forked from Ivasoft/DSView
update: use zlib
This commit is contained in:
@@ -293,9 +293,6 @@ set(DSView_SOURCES
|
||||
DSView/pv/ui/msgbox.cpp
|
||||
DSView/pv/ui/dscombobox.cpp
|
||||
DSView/pv/dsvdef.cpp
|
||||
DSView/pv/minizip/zip.c
|
||||
DSView/pv/minizip/unzip.c
|
||||
DSView/pv/minizip/ioapi.c
|
||||
DSView/pv/dialogs/applicationpardlg.cpp
|
||||
DSView/pv/dock/keywordlineedit.cpp
|
||||
DSView/pv/dock/searchcombobox.cpp
|
||||
@@ -384,9 +381,6 @@ set(DSView_HEADERS
|
||||
DSView/pv/ui/msgbox.h
|
||||
DSView/pv/ui/dscombobox.h
|
||||
DSView/pv/dsvdef.h
|
||||
DSView/pv/minizip/zip.h
|
||||
DSView/pv/minizip/unzip.h
|
||||
DSView/pv/minizip/ioapi.h
|
||||
DSView/pv/dialogs/applicationpardlg.h
|
||||
DSView/pv/dock/keywordlineedit.h
|
||||
DSView/pv/dock/searchcombobox.h
|
||||
@@ -461,6 +455,26 @@ set(libsigrokdecode4DSL_HEADERS
|
||||
libsigrokdecode4DSL/version.h
|
||||
)
|
||||
|
||||
#===============================================================================
|
||||
#= common source
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
set(common_SOURCES
|
||||
common/minizip/zip.c
|
||||
common/minizip/unzip.c
|
||||
common/minizip/ioapi.c
|
||||
)
|
||||
|
||||
set(common_HEADERS
|
||||
common/minizip/zip.h
|
||||
common/minizip/unzip.h
|
||||
common/minizip/ioapi.h
|
||||
)
|
||||
|
||||
#===============================================================================
|
||||
#= compile config
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
set(DSView_FORMS
|
||||
)
|
||||
|
||||
@@ -491,9 +505,6 @@ if(Qt6Core_FOUND)
|
||||
qt6_add_resources(DSView_RESOURCES_RCC ${DSView_RESOURCES})
|
||||
endif()
|
||||
|
||||
#===============================================================================
|
||||
#= Global Definitions
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
add_definitions(${QT_DEFINITIONS})
|
||||
add_definitions(-Wall -Wextra -Wno-return-type -Wno-ignored-qualifiers)
|
||||
@@ -505,9 +516,6 @@ endif()
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
|
||||
|
||||
#===============================================================================
|
||||
#= Global Include Directories
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
include_directories(
|
||||
./DSView
|
||||
@@ -568,6 +576,7 @@ else()
|
||||
endif()
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
${common_SOURCES}
|
||||
${DSView_SOURCES}
|
||||
${DSView_HEADERS_MOC}
|
||||
${DSView_FORMS_HEADERS}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "minizip/zip.h"
|
||||
#include "../../common/minizip/zip.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
||||
@@ -383,4 +383,5 @@ QString GetDecodeScriptDir()
|
||||
{
|
||||
return dir.absolutePath();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -155,24 +155,7 @@ bool StoreSession::save_start()
|
||||
if (snapshot->empty()) {
|
||||
_error = tr("No data to save.");
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
if (meta_file == NULL) {
|
||||
_error = tr("Generate temp file failed.");
|
||||
} else {
|
||||
int ret = sr_session_save_init(_file_name.toUtf8().data(),
|
||||
meta_file.toUtf8().data(),
|
||||
decoders_file.toUtf8().data(),
|
||||
session_file.toUtf8().data());
|
||||
if (ret != SR_OK) {
|
||||
_error = tr("Failed to create zip file. Initialization error.");
|
||||
} else {
|
||||
_thread = std::thread(&StoreSession::save_proc, this, snapshot);
|
||||
return !_has_error;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
std::string meta_data;
|
||||
std::string decoder_data;
|
||||
@@ -265,9 +248,6 @@ void StoreSession::save_proc(data::Snapshot *snapshot)
|
||||
}
|
||||
}
|
||||
|
||||
// ret = sr_session_append(_file_name.toUtf8().data(), buf, size,
|
||||
// i, ch_index, ch_type, File_Version);
|
||||
|
||||
MakeChunkName(chunk_name, i, ch_index, ch_type, File_Version);
|
||||
ret = m_zipDoc.AddFromBuffer(chunk_name, (const char*)buf, size) ? SR_OK : -1;
|
||||
|
||||
@@ -314,10 +294,7 @@ void StoreSession::save_proc(data::Snapshot *snapshot)
|
||||
} else {
|
||||
memcpy(tmp, buf, buf_end-buf);
|
||||
memcpy(tmp+(buf_end-buf), buf_start, buf+size-buf_end);
|
||||
}
|
||||
|
||||
// ret = sr_session_append(_file_name.toUtf8().data(), tmp, size,
|
||||
// i, 0, ch_type, File_Version);
|
||||
}
|
||||
|
||||
MakeChunkName(chunk_name, i, 0, ch_type, File_Version);
|
||||
ret = m_zipDoc.AddFromBuffer(chunk_name, (const char*)tmp, size) ? SR_OK : -1;
|
||||
@@ -325,10 +302,7 @@ void StoreSession::save_proc(data::Snapshot *snapshot)
|
||||
buf += (size - _unit_count);
|
||||
if (tmp)
|
||||
free(tmp);
|
||||
} else {
|
||||
|
||||
// ret = sr_session_append(_file_name.toUtf8().data(), buf, size,
|
||||
// i, 0, ch_type, File_Version);
|
||||
} else {
|
||||
|
||||
MakeChunkName(chunk_name, i, 0, ch_type, File_Version);
|
||||
ret = m_zipDoc.AddFromBuffer(chunk_name, (const char*)buf, size) ? SR_OK : -1;
|
||||
|
||||
@@ -38,7 +38,6 @@ Requirements
|
||||
- libtool
|
||||
- pkg-config >= 0.22
|
||||
- libglib >= 2.32.0
|
||||
- libzip >= 0.8
|
||||
- libusb-1.0 >= 1.0.9 (optional, used by most drivers)
|
||||
- libftdi >= 0.16 (optional, used by some drivers)
|
||||
- libasound / alsa-lib >= 1.0 (optional, only used by the alsa driver)
|
||||
|
||||
@@ -114,10 +114,8 @@ SR_API int sr_session_datafeed_callback_add(sr_datafeed_callback_t cb,
|
||||
/* Session control */
|
||||
SR_API int sr_session_start(void);
|
||||
SR_API int sr_session_run(void);
|
||||
SR_API int sr_session_stop(void);
|
||||
SR_API int sr_session_save_init(const char *filename, const char *metafile, const char *decfile, const char *sesfile);
|
||||
SR_API int sr_session_append(const char *filename, const unsigned char *buf,
|
||||
uint64_t size, int chunk_num, int index, int type, int version);
|
||||
SR_API int sr_session_stop(void);
|
||||
|
||||
SR_API int sr_session_source_add(int fd, int events, int timeout,
|
||||
sr_receive_data_callback_t cb, const struct sr_dev_inst *sdi);
|
||||
SR_API int sr_session_source_add_pollfd(GPollFD *pollfd, int timeout,
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <sys/time.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "../DSView/pv/minizip/unzip.h"
|
||||
#include "../common/minizip/unzip.h"
|
||||
|
||||
/* Message logging helpers with subsystem-specific prefix string. */
|
||||
#define LOG_PREFIX "virtual-session: "
|
||||
|
||||
@@ -22,12 +22,12 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <zip.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <glib.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include "../common/minizip/unzip.h"
|
||||
#include "config.h" /* Needed for PACKAGE_VERSION and others. */
|
||||
|
||||
/* Message logging helpers with subsystem-specific prefix string. */
|
||||
@@ -54,59 +54,6 @@
|
||||
extern struct sr_session *session;
|
||||
extern SR_PRIV struct sr_dev_driver session_driver;
|
||||
|
||||
/** @private */
|
||||
SR_PRIV int sr_sessionfile_check(const char *filename)
|
||||
{
|
||||
struct stat st;
|
||||
struct zip *archive;
|
||||
struct zip_file *zf;
|
||||
struct zip_stat zs;
|
||||
int version, ret;
|
||||
char s[11];
|
||||
|
||||
if (!filename)
|
||||
return SR_ERR_ARG;
|
||||
|
||||
if (stat(filename, &st) == -1) {
|
||||
sr_err("Couldn't stat %s: %s", filename, strerror(errno));
|
||||
return SR_ERR;
|
||||
}
|
||||
|
||||
if (!(archive = zip_open(filename, 0, &ret)))
|
||||
/* No logging: this can be used just to check if it's
|
||||
* a sigrok session file or not. */
|
||||
return SR_ERR;
|
||||
|
||||
/* check "version" */
|
||||
version = 0;
|
||||
if (!(zf = zip_fopen(archive, "version", 0))) {
|
||||
sr_dbg("Not a sigrok session file: no version found.");
|
||||
return SR_ERR;
|
||||
}
|
||||
if ((ret = zip_fread(zf, s, 10)) == -1)
|
||||
return SR_ERR;
|
||||
zip_fclose(zf);
|
||||
s[ret] = 0;
|
||||
version = strtoull(s, NULL, 10);
|
||||
if (version > 2) {
|
||||
sr_dbg("Cannot handle sigrok session file version %d.", version);
|
||||
return SR_ERR;
|
||||
}
|
||||
sr_spew("Detected sigrok session file version %d.", version);
|
||||
|
||||
/* read "metadata" */
|
||||
if (zip_stat(archive, "metadata", 0, &zs) == -1) {
|
||||
sr_dbg("Not a valid sigrok session file.");
|
||||
return SR_ERR;
|
||||
}
|
||||
|
||||
if ((ret = zip_close(archive)) == -1) {
|
||||
sr_info("error saving session file: %s", zip_strerror(archive));
|
||||
return SR_ERR;
|
||||
}
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the session from the specified filename.
|
||||
@@ -121,9 +68,10 @@ SR_API int sr_session_load(const char *filename)
|
||||
{
|
||||
GKeyFile *kf;
|
||||
GPtrArray *capturefiles;
|
||||
struct zip *archive;
|
||||
struct zip_file *zf;
|
||||
struct zip_stat zs;
|
||||
unzFile archive = NULL;
|
||||
char szFilePath[15];
|
||||
unz_file_info64 fileInfo;
|
||||
|
||||
struct sr_dev_inst *sdi;
|
||||
struct sr_channel *probe;
|
||||
int ret, devcnt, i, j;
|
||||
@@ -136,35 +84,51 @@ SR_API int sr_session_load(const char *filename)
|
||||
int mode = LOGIC;
|
||||
int channel_type = SR_CHANNEL_LOGIC;
|
||||
double tmp_double;
|
||||
int version = 1;
|
||||
int version = 1;
|
||||
|
||||
if (!filename) {
|
||||
sr_err("%s: filename was NULL", __func__);
|
||||
return SR_ERR_ARG;
|
||||
}
|
||||
|
||||
if (!(archive = zip_open(filename, 0, &ret))) {
|
||||
sr_dbg("Failed to open session file: zip error %d", ret);
|
||||
archive = unzOpen64(filename);
|
||||
if (NULL == archive) {
|
||||
sr_err("load zip file error:%s", filename);
|
||||
return SR_ERR;
|
||||
}
|
||||
|
||||
/* read "metadata" */
|
||||
if (zip_stat(archive, "header", 0, &zs) == -1) {
|
||||
sr_dbg("Not a valid DSView data file.");
|
||||
if (unzLocateFile(archive, "header", 0) != UNZ_OK){
|
||||
unzClose(archive);
|
||||
sr_err("unzLocateFile error:'header', %s", filename);
|
||||
return SR_ERR;
|
||||
}
|
||||
}
|
||||
if (unzGetCurrentFileInfo64(archive, &fileInfo, szFilePath,
|
||||
sizeof(szFilePath), NULL, 0, NULL, 0) != UNZ_OK){
|
||||
unzClose(archive);
|
||||
sr_err("unzGetCurrentFileInfo64 error,'header', %s", filename);
|
||||
return SR_ERR;
|
||||
}
|
||||
if(unzOpenCurrentFile(archive) != UNZ_OK){
|
||||
sr_err("cant't open zip inner file:'header',%s", filename);
|
||||
unzClose(archive);
|
||||
return SR_ERR;
|
||||
}
|
||||
|
||||
if (!(metafile = g_try_malloc(zs.size))) {
|
||||
if (!(metafile = g_try_malloc(fileInfo.uncompressed_size))) {
|
||||
sr_err("%s: metafile malloc failed", __func__);
|
||||
return SR_ERR_MALLOC;
|
||||
}
|
||||
|
||||
zf = zip_fopen_index(archive, zs.index, 0);
|
||||
zip_fread(zf, metafile, zs.size);
|
||||
zip_fclose(zf);
|
||||
unzReadCurrentFile(archive, metafile, fileInfo.uncompressed_size);
|
||||
unzCloseCurrentFile(archive);
|
||||
|
||||
if (unzClose(archive) != UNZ_OK){
|
||||
sr_err("close zip archive error:%s", filename);
|
||||
return SR_ERR;
|
||||
}
|
||||
archive = NULL;
|
||||
|
||||
kf = g_key_file_new();
|
||||
if (!g_key_file_load_from_data(kf, metafile, zs.size, 0, NULL)) {
|
||||
if (!g_key_file_load_from_data(kf, metafile, fileInfo.uncompressed_size, 0, NULL)) {
|
||||
sr_dbg("Failed to parse metadata.");
|
||||
return SR_ERR;
|
||||
}
|
||||
@@ -480,159 +444,8 @@ SR_API int sr_session_load(const char *filename)
|
||||
}
|
||||
g_strfreev(sections);
|
||||
g_key_file_free(kf);
|
||||
|
||||
|
||||
if ((ret = zip_close(archive)) == -1) {
|
||||
sr_info("error close session file: %s", zip_strerror(archive));
|
||||
return SR_ERR;
|
||||
}
|
||||
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a saved session file.
|
||||
*
|
||||
* @param filename The name of the filename to save the current session as.
|
||||
* Must not be NULL.
|
||||
* @param samplerate The samplerate to store for this session.
|
||||
* @param channels A NULL-terminated array of strings containing the names
|
||||
* of all the channels active in this session.
|
||||
*
|
||||
* @retval SR_OK Success
|
||||
* @retval SR_ERR_ARG Invalid arguments
|
||||
* @retval SR_ERR Other errors
|
||||
*
|
||||
* @since 0.3.0
|
||||
*/
|
||||
SR_API int sr_session_save_init(const char *filename, const char *metafile, const char *decfile, const char *sesfile)
|
||||
{
|
||||
struct zip *zipfile;
|
||||
struct zip_source *metasrc;
|
||||
int ret;
|
||||
|
||||
if (!filename) {
|
||||
sr_err("%s: filename was NULL", __func__);
|
||||
return SR_ERR_ARG;
|
||||
}
|
||||
|
||||
/* Quietly delete it first, libzip wants replace ops otherwise. */
|
||||
unlink(filename);
|
||||
if (!(zipfile = zip_open(filename, ZIP_CREATE, &ret)))
|
||||
return SR_ERR;
|
||||
|
||||
// meta file
|
||||
if (!(metasrc = zip_source_file(zipfile, metafile, 0, -1))) {
|
||||
unlink(metafile);
|
||||
return SR_ERR;
|
||||
}
|
||||
|
||||
if (zip_add(zipfile, "header", metasrc) == -1) {
|
||||
unlink(metafile);
|
||||
return SR_ERR;
|
||||
}
|
||||
|
||||
// decoders file
|
||||
if (decfile != NULL) {
|
||||
if (!(metasrc = zip_source_file(zipfile, decfile, 0, -1))) {
|
||||
unlink(decfile);
|
||||
return SR_ERR;
|
||||
}
|
||||
|
||||
if (zip_add(zipfile, "decoders", metasrc) == -1) {
|
||||
unlink(decfile);
|
||||
return SR_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
// session file
|
||||
if (sesfile != NULL) {
|
||||
if (!(metasrc = zip_source_file(zipfile, sesfile, 0, -1))) {
|
||||
unlink(sesfile);
|
||||
return SR_ERR;
|
||||
}
|
||||
|
||||
if (zip_add(zipfile, "session", metasrc) == -1) {
|
||||
unlink(sesfile);
|
||||
return SR_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
if ((ret = zip_close(zipfile)) == -1) {
|
||||
sr_info("error saving zipfile: %s", zip_strerror(zipfile));
|
||||
unlink(metafile);
|
||||
if (decfile != NULL)
|
||||
unlink(decfile);
|
||||
return SR_ERR;
|
||||
}
|
||||
|
||||
unlink(metafile);
|
||||
if (decfile != NULL)
|
||||
unlink(decfile);
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append data to an existing session file.
|
||||
*
|
||||
* The session file must have been created with sr_session_save_init()
|
||||
* or sr_session_save() beforehand.
|
||||
*
|
||||
* @param filename The name of the filename to append to. Must not be NULL.
|
||||
* @param buf The data to be appended.
|
||||
* @param size Buffer size.
|
||||
* @param chunk_num chunk number
|
||||
* @param index channel index
|
||||
* @param type channel type
|
||||
*
|
||||
* @retval SR_OK Success
|
||||
* @retval SR_ERR_ARG Invalid arguments
|
||||
* @retval SR_ERR Other errors
|
||||
*
|
||||
* @since 0.3.0
|
||||
*/
|
||||
SR_API int sr_session_append(const char *filename, const unsigned char *buf,
|
||||
uint64_t size, int chunk_num, int index, int type, int version)
|
||||
{
|
||||
struct zip *archive;
|
||||
struct zip_source *logicsrc;
|
||||
int ret;
|
||||
char chunk_name[16], *type_name;
|
||||
|
||||
// if ((ret = sr_sessionfile_check(filename)) != SR_OK)
|
||||
// return ret;
|
||||
if (buf == NULL)
|
||||
goto err;
|
||||
|
||||
if (!(archive = zip_open(filename, 0, &ret)))
|
||||
goto err;
|
||||
|
||||
if (version == 2) {
|
||||
type_name = (type == SR_CHANNEL_LOGIC) ? "L" :
|
||||
(type == SR_CHANNEL_DSO) ? "O" :
|
||||
(type == SR_CHANNEL_ANALOG) ? "A" : "U";
|
||||
snprintf(chunk_name, 15, "%s-%d/%d", type_name, index, chunk_num);
|
||||
} else {
|
||||
snprintf(chunk_name, 15, "data");
|
||||
}
|
||||
|
||||
if (!(logicsrc = zip_source_buffer(archive, buf, size, FALSE))) {
|
||||
goto err;
|
||||
}
|
||||
if (zip_file_add(archive, chunk_name, logicsrc, ZIP_FL_OVERWRITE) == -1) {
|
||||
goto err;
|
||||
}
|
||||
if ((ret = zip_close(archive)) == -1) {
|
||||
sr_info("error saving session file: %s", zip_strerror(archive));
|
||||
goto err;
|
||||
}
|
||||
|
||||
return SR_OK;
|
||||
|
||||
err:
|
||||
unlink(filename);
|
||||
return SR_ERR;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
##
|
||||
## This file is part of the libsigrok project.
|
||||
##
|
||||
## Copyright (C) 2013 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## 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
|
||||
##
|
||||
|
||||
if HAVE_CHECK
|
||||
|
||||
TESTS = check_main
|
||||
|
||||
check_PROGRAMS = ${TESTS}
|
||||
|
||||
check_main_SOURCES = \
|
||||
$(top_builddir)/libsigrok.h \
|
||||
lib.c \
|
||||
lib.h \
|
||||
check_main.c \
|
||||
check_core.c \
|
||||
check_strutil.c \
|
||||
check_driver_all.c
|
||||
|
||||
check_main_CFLAGS = @check_CFLAGS@
|
||||
|
||||
check_main_LDADD = $(top_builddir)/libsigrok4DSL.la @check_LIBS@
|
||||
|
||||
endif
|
||||
Reference in New Issue
Block a user