diff --git a/iso/CMakeLists.txt b/iso/CMakeLists.txt --- a/iso/CMakeLists.txt +++ b/iso/CMakeLists.txt @@ -9,6 +9,7 @@ kisofile.cpp qfilehack.cpp kiso.cpp + kisodebug.cpp iso.cpp) add_library(kio_iso MODULE ${kio_iso_PART_SRCS} ${libisofs_SRCS}) diff --git a/iso/kiso.h b/iso/kiso.h --- a/iso/kiso.h +++ b/iso/kiso.h @@ -29,6 +29,7 @@ #include "kisofile.h" #include "kisodirectory.h" +#include "kisodebug.h" /** * @short A class for reading (optionally compressed) iso9660 files. diff --git a/iso/kiso.cpp b/iso/kiso.cpp --- a/iso/kiso.cpp +++ b/iso/kiso.cpp @@ -58,6 +58,7 @@ static int getTracks(const char *fname, int *tracks) { + KISOFUNC; int ret = 0; memset(tracks, 0, 200*sizeof(int)); @@ -105,6 +106,9 @@ KIso::KIso(const QString& filename, const QString & _mimetype) : KArchive(0L) { + KISOFUNC; + KISODEBUG("Starting KIso: " << filename << " - type: " << _mimetype); + m_startsec = -1; m_filename = filename; d = new KIsoPrivate; @@ -156,6 +160,8 @@ void KIso::prepareDevice(const QString & filename, const QString & mimetype, bool forced) { + KISOFUNC; + KISODEBUG("Preparing: " << filename << " - type: " << mimetype << " - using the force: " << forced); /* 'hack' for Qt's false assumption that only S_ISREG is seekable */ if ("inode/blockdevice" == mimetype) setDevice(new QFileHack(filename)); @@ -199,6 +205,7 @@ /* callback function for libisofs */ static int readf(char *buf, unsigned int start, unsigned int len, void *udata) { + KISOFUNC; QIODevice* dev = (static_cast(udata))->device(); @@ -213,6 +220,7 @@ /* callback function for libisofs */ static int mycallb(struct iso_directory_record *idr, void *udata) { + KISOFUNC; KIso *iso = static_cast(udata); QString path, user, group, symlink; @@ -300,6 +308,7 @@ void KIso::addBoot(struct el_torito_boot_descriptor* bootdesc) { + KISOFUNC; int i; long long size; @@ -337,6 +346,7 @@ void KIso::readParams() { + KISOFUNC; KConfig *config; config = new KConfig("kio_isorc"); @@ -349,6 +359,7 @@ bool KIso::openArchive(QIODevice::OpenMode mode) { + KISOFUNC; iso_vol_desc *desc; QString path, uid, gid; QT_STATBUF buf; @@ -450,6 +461,7 @@ bool KIso::closeArchive() { + KISOFUNC; d->dirList.clear(); return true; } diff --git a/iso/kisodebug.h b/iso/kisodebug.h new file mode 100644 --- /dev/null +++ b/iso/kisodebug.h @@ -0,0 +1,62 @@ +/*************************************************************************** + krdebuglogger.h + ------------------ + copyright : (C) 2016 by Rafi Yanai & Shie Erlich + email : krusader@users.sf.net + web site : http://krusader.sourceforge.net + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef KISODEBUG_H +#define KISODEBUG_H + +// QtCore +#include +#include +#include + +#include + +//! A class to manage some aspects of the writing of messages into the krarc debug log file +class KIsoDebug +{ +private: + QString function; //! The name of a function which is going to be written about + static int indentation; //! The indentation that is presently used, it represents how many spaces are going to be used + const static int indentationIncrease; //! The quantity of spaces that are going be added to the indentation when increasing it + static const QString logFile; //! The name of the log file + +public: + KIsoDebug(const QString& argFunction, int line); + ~KIsoDebug(); + static void prepareWriting(QFile &, QTextStream &); +}; + +#ifdef QT_DEBUG + +//! Writes a function name in the krarc debug log, etc. when entering the function and automatically before exiting from it +#define KISOFUNC \ + KIsoDebug functionLogger(__FUNCTION__, __LINE__); + +#define KISODEBUG(X...) do{ \ + QFile file; \ + QTextStream stream; \ + KIsoDebug::prepareWriting(file, stream); \ + stream << __FUNCTION__ << "(" <<__LINE__<< "): "; \ + stream << X << endl; \ + } while(0); +#else +#define KISOFUNC +#define KISODEBUG(X...) qDebug() << X +#endif + +#endif // KISODEBUG_H + diff --git a/iso/kisodebug.cpp b/iso/kisodebug.cpp new file mode 100644 --- /dev/null +++ b/iso/kisodebug.cpp @@ -0,0 +1,56 @@ +/*************************************************************************** + krdebuglogger.cpp + ------------------ + copyright : (C) 2016 by Rafi Yanai & Shie Erlich + email : krusader@users.sf.net + web site : http://krusader.sourceforge.net + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include "kisodebug.h" + +int KIsoDebug::indentation = 1; +const int KIsoDebug::indentationIncrease = 3; +const QString KIsoDebug::logFile = QDir::tempPath() + "/kisodebug"; + +//! This constructor is used inside the KRFUNC macro. For more details: the description of the KRFUNC macro can be seen +KIsoDebug::KIsoDebug(const QString &argFunction, int line) : function(argFunction) +{ + QFile file; + QTextStream stream; + prepareWriting(file, stream); + stream << QString("┏"); // Indicates that a function has been started + stream << function << "(" << line << ")" << endl; + indentation += indentationIncrease; +} + +//! For more information: the description of the KRFUNC macro can be seen +KIsoDebug::~KIsoDebug() +{ + indentation -= indentationIncrease; + QFile file; + QTextStream stream; + prepareWriting(file, stream); + stream << QString("┗"); // Indicates that a function is going to finish + stream << function << endl; +} + +//! Prepares some elements before a writing into the krarc debug log file +void KIsoDebug::prepareWriting(QFile &file, QTextStream &stream) +{ + file.setFileName(logFile); + file.open(QIODevice::WriteOnly | QIODevice::Append); + stream.setDevice(&file); + stream << "Pid:" << (int)getpid(); + // Applies the indentation level to make logs clearer + for (int x = 0; x < indentation; ++x) + stream << " "; +}