mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: make logfile_name and dumpfile_name std::string
To avoid memory management woes. These shouldn't be global variables, but let's fix that later. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
64419f2b19
commit
3a1122048b
6 changed files with 23 additions and 27 deletions
|
@ -574,8 +574,8 @@ QString ConfigureDiveComputer::dc_open(device_data_t *data)
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
dc_status_t rc;
|
dc_status_t rc;
|
||||||
|
|
||||||
if (data->libdc_log)
|
if (data->libdc_log && !logfile_name.empty())
|
||||||
fp = subsurface_fopen(logfile_name, "w");
|
fp = subsurface_fopen(logfile_name.c_str(), "w");
|
||||||
|
|
||||||
data->libdc_logfile = fp;
|
data->libdc_logfile = fp;
|
||||||
|
|
||||||
|
|
|
@ -38,11 +38,10 @@
|
||||||
#include "core/version.h"
|
#include "core/version.h"
|
||||||
#include "core/qthelper.h"
|
#include "core/qthelper.h"
|
||||||
#include "core/file.h"
|
#include "core/file.h"
|
||||||
#include <QtGlobal>
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
char *dumpfile_name;
|
std::string dumpfile_name;
|
||||||
char *logfile_name;
|
std::string logfile_name;
|
||||||
const char *progress_bar_text = "";
|
const char *progress_bar_text = "";
|
||||||
void (*progress_callback)(const char *text) = NULL;
|
void (*progress_callback)(const char *text) = NULL;
|
||||||
double progress_bar_fraction = 0.0;
|
double progress_bar_fraction = 0.0;
|
||||||
|
@ -1173,8 +1172,8 @@ static const char *do_device_import(device_data_t *data)
|
||||||
dc_buffer_t *buffer = dc_buffer_new(0);
|
dc_buffer_t *buffer = dc_buffer_new(0);
|
||||||
|
|
||||||
rc = dc_device_dump(device, buffer);
|
rc = dc_device_dump(device, buffer);
|
||||||
if (rc == DC_STATUS_SUCCESS && dumpfile_name) {
|
if (rc == DC_STATUS_SUCCESS && !dumpfile_name.empty()) {
|
||||||
FILE *fp = subsurface_fopen(dumpfile_name, "wb");
|
FILE *fp = subsurface_fopen(dumpfile_name.c_str(), "wb");
|
||||||
if (fp != NULL) {
|
if (fp != NULL) {
|
||||||
fwrite(dc_buffer_get_data(buffer), 1, dc_buffer_get_size(buffer), fp);
|
fwrite(dc_buffer_get_data(buffer), 1, dc_buffer_get_size(buffer), fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
@ -1479,8 +1478,8 @@ const char *do_libdivecomputer_import(device_data_t *data)
|
||||||
data->fingerprint = NULL;
|
data->fingerprint = NULL;
|
||||||
data->fsize = 0;
|
data->fsize = 0;
|
||||||
|
|
||||||
if (data->libdc_log && logfile_name)
|
if (data->libdc_log && !logfile_name.empty())
|
||||||
fp = subsurface_fopen(logfile_name, "w");
|
fp = subsurface_fopen(logfile_name.c_str(), "w");
|
||||||
|
|
||||||
data->libdc_logfile = fp;
|
data->libdc_logfile = fp;
|
||||||
|
|
||||||
|
|
|
@ -62,8 +62,6 @@ extern int import_thread_cancelled;
|
||||||
extern const char *progress_bar_text;
|
extern const char *progress_bar_text;
|
||||||
extern void (*progress_callback)(const char *text);
|
extern void (*progress_callback)(const char *text);
|
||||||
extern double progress_bar_fraction;
|
extern double progress_bar_fraction;
|
||||||
extern char *logfile_name;
|
|
||||||
extern char *dumpfile_name;
|
|
||||||
|
|
||||||
dc_status_t ble_packet_open(dc_iostream_t **iostream, dc_context_t *context, const char* devaddr, void *userdata);
|
dc_status_t ble_packet_open(dc_iostream_t **iostream, dc_context_t *context, const char* devaddr, void *userdata);
|
||||||
dc_status_t rfcomm_stream_open(dc_iostream_t **iostream, dc_context_t *context, const char* devaddr);
|
dc_status_t rfcomm_stream_open(dc_iostream_t **iostream, dc_context_t *context, const char* devaddr);
|
||||||
|
@ -76,6 +74,11 @@ unsigned int get_supported_transports(device_data_t *data);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
extern std::string logfile_name;
|
||||||
|
extern std::string dumpfile_name;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // LIBDIVECOMPUTER_H
|
#endif // LIBDIVECOMPUTER_H
|
||||||
|
|
|
@ -1481,10 +1481,8 @@ void ConfigureDiveComputerDialog::pickLogFile()
|
||||||
filename = fi.absolutePath().append(QDir::separator()).append("subsurface.log");
|
filename = fi.absolutePath().append(QDir::separator()).append("subsurface.log");
|
||||||
logFile = QFileDialog::getSaveFileName(this, tr("Choose file for dive computer download logfile"),
|
logFile = QFileDialog::getSaveFileName(this, tr("Choose file for dive computer download logfile"),
|
||||||
filename, tr("Log files") + " (*.log)");
|
filename, tr("Log files") + " (*.log)");
|
||||||
if (!logFile.isEmpty()) {
|
if (!logFile.isEmpty())
|
||||||
free(logfile_name);
|
logfile_name = logFile.toStdString();
|
||||||
logfile_name = copy_qstring(logFile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BT_SUPPORT
|
#ifdef BT_SUPPORT
|
||||||
|
|
|
@ -466,10 +466,8 @@ void DownloadFromDCWidget::pickLogFile()
|
||||||
QString logfilename = fi.absolutePath().append(QDir::separator()).append("subsurface.log");
|
QString logfilename = fi.absolutePath().append(QDir::separator()).append("subsurface.log");
|
||||||
QString logFile = QFileDialog::getSaveFileName(this, tr("Choose file for dive computer download logfile"),
|
QString logFile = QFileDialog::getSaveFileName(this, tr("Choose file for dive computer download logfile"),
|
||||||
logfilename, tr("Log files") + " (*.log)");
|
logfilename, tr("Log files") + " (*.log)");
|
||||||
if (!logFile.isEmpty()) {
|
if (!logFile.isEmpty())
|
||||||
free(logfile_name);
|
logfile_name = logFile.toStdString();
|
||||||
logfile_name = copy_qstring(logFile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadFromDCWidget::checkDumpFile(int state)
|
void DownloadFromDCWidget::checkDumpFile(int state)
|
||||||
|
@ -491,10 +489,8 @@ void DownloadFromDCWidget::pickDumpFile()
|
||||||
QString dumpfilename = fi.absolutePath().append(QDir::separator()).append("subsurface.bin");
|
QString dumpfilename = fi.absolutePath().append(QDir::separator()).append("subsurface.bin");
|
||||||
QString dumpFile = QFileDialog::getSaveFileName(this, tr("Choose file for dive computer binary dump file"),
|
QString dumpFile = QFileDialog::getSaveFileName(this, tr("Choose file for dive computer binary dump file"),
|
||||||
dumpfilename, tr("Dump files") + " (*.bin)");
|
dumpfilename, tr("Dump files") + " (*.bin)");
|
||||||
if (!dumpFile.isEmpty()) {
|
if (!dumpFile.isEmpty())
|
||||||
free(dumpfile_name);
|
dumpfile_name = dumpFile.toStdString();
|
||||||
dumpfile_name = copy_qstring(dumpFile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadFromDCWidget::reject()
|
void DownloadFromDCWidget::reject()
|
||||||
|
|
|
@ -266,7 +266,7 @@ QMLManager::QMLManager() :
|
||||||
// remove the existing libdivecomputer logfile so we don't copy an old one by mistake
|
// remove the existing libdivecomputer logfile so we don't copy an old one by mistake
|
||||||
QFile libdcLog(libdcLogFileName);
|
QFile libdcLog(libdcLogFileName);
|
||||||
libdcLog.remove();
|
libdcLog.remove();
|
||||||
logfile_name = copy_qstring(libdcLogFileName);
|
logfile_name = libdcLogFileName.toStdString();
|
||||||
} else {
|
} else {
|
||||||
appendTextToLog("No writeable location found, in-memory log only and no libdivecomputer log");
|
appendTextToLog("No writeable location found, in-memory log only and no libdivecomputer log");
|
||||||
}
|
}
|
||||||
|
@ -497,7 +497,7 @@ bool QMLManager::createSupportEmail()
|
||||||
QAndroidJniObject activity = QtAndroid::androidActivity();
|
QAndroidJniObject activity = QtAndroid::androidActivity();
|
||||||
if (activity.isValid()) {
|
if (activity.isValid()) {
|
||||||
QAndroidJniObject applogfilepath = QAndroidJniObject::fromString(appLogFileName);
|
QAndroidJniObject applogfilepath = QAndroidJniObject::fromString(appLogFileName);
|
||||||
QAndroidJniObject libdcfilepath = QAndroidJniObject::fromString(logfile_name);
|
QAndroidJniObject libdcfilepath = QAndroidJniObject::fromString(QString::fromStdString(logfile_name));
|
||||||
bool success = activity.callMethod<jboolean>("supportEmail",
|
bool success = activity.callMethod<jboolean>("supportEmail",
|
||||||
"(Ljava/lang/String;Ljava/lang/String;)Z", // two string arguments, return bool
|
"(Ljava/lang/String;Ljava/lang/String;)Z", // two string arguments, return bool
|
||||||
applogfilepath.object<jstring>(), libdcfilepath.object<jstring>());
|
applogfilepath.object<jstring>(), libdcfilepath.object<jstring>());
|
||||||
|
@ -508,7 +508,7 @@ bool QMLManager::createSupportEmail()
|
||||||
qDebug() << __FUNCTION__ << "failed to share the logFiles via intent, use the fall-back mail body method";
|
qDebug() << __FUNCTION__ << "failed to share the logFiles via intent, use the fall-back mail body method";
|
||||||
#elif defined(Q_OS_IOS)
|
#elif defined(Q_OS_IOS)
|
||||||
// call into objC++ code to share on iOS
|
// call into objC++ code to share on iOS
|
||||||
QString libdcLogFileName(logfile_name);
|
QString libdcLogFileName = QString::fromStdString(logfile_name);
|
||||||
iosshare.supportEmail(appLogFileName, libdcLogFileName);
|
iosshare.supportEmail(appLogFileName, libdcLogFileName);
|
||||||
// Unfortunately I haven't been able to figure out how to wait until the mail was sent
|
// Unfortunately I haven't been able to figure out how to wait until the mail was sent
|
||||||
// so that this could tell us whether this was successful or not
|
// so that this could tell us whether this was successful or not
|
||||||
|
@ -536,7 +536,7 @@ QString QMLManager::getCombinedLogs()
|
||||||
copyString += MessageHandlerModel::self()->logAsString();
|
copyString += MessageHandlerModel::self()->logAsString();
|
||||||
|
|
||||||
// Add heading and append libdivecomputer.log
|
// Add heading and append libdivecomputer.log
|
||||||
QFile f(logfile_name);
|
QFile f(logfile_name.c_str());
|
||||||
if (f.open(QFile::ReadOnly | QFile::Text)) {
|
if (f.open(QFile::ReadOnly | QFile::Text)) {
|
||||||
copyString += "\n\n\n---------- libdivecomputer.log ----------\n";
|
copyString += "\n\n\n---------- libdivecomputer.log ----------\n";
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue