aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Szymon Tomasz Stefanek2015-10-04 02:39:51 +0200
committerGravatar Szymon Tomasz Stefanek2015-10-04 02:39:51 +0200
commitb21ac29e01c8ce3ba5d32d07ab22d2b093bdb03e (patch)
treee4bdac41e546c46ec0d097980ab6d959e00eacbf /src
parentFix #1643 (diff)
downloadKVIrc-b21ac29e01c8ce3ba5d32d07ab22d2b093bdb03e.tar.gz
KVIrc-b21ac29e01c8ce3ba5d32d07ab22d2b093bdb03e.tar.bz2
KVIrc-b21ac29e01c8ce3ba5d32d07ab22d2b093bdb03e.zip
Add package.extractField command to extract binary images from kvirc packages. Will be used in the web site.
Diffstat (limited to 'src')
-rw-r--r--src/kvilib/file/KviFileUtils.cpp12
-rw-r--r--src/kvilib/file/KviFileUtils.h9
-rw-r--r--src/modules/options/OptionsWidget_interfaceFeatures.cpp2
-rw-r--r--src/modules/package/libkvipackage.cpp52
4 files changed, 74 insertions, 1 deletions
diff --git a/src/kvilib/file/KviFileUtils.cpp b/src/kvilib/file/KviFileUtils.cpp
index dff5a742d..dad39c260 100644
--- a/src/kvilib/file/KviFileUtils.cpp
+++ b/src/kvilib/file/KviFileUtils.cpp
@@ -284,6 +284,18 @@ namespace KviFileUtils
return true;
}
+ bool writeFile(const QString & szPath, const QByteArray & oData, bool bAppend)
+ {
+ KviFile f(szPath);
+ if(!f.open(QFile::WriteOnly | (bAppend ? QFile::Append : QFile::Truncate)))
+ return false;
+ if(oData.length() < 1)
+ return true;
+ if(f.write(oData.data(),oData.length()) != ((unsigned int)(oData.length())))
+ return false;
+ return true;
+ }
+
bool writeFile(const QString & szPath, const QString & szData, bool bAppend)
{
KviFile f(szPath);
diff --git a/src/kvilib/file/KviFileUtils.h b/src/kvilib/file/KviFileUtils.h
index 9a900b3a2..052e01011 100644
--- a/src/kvilib/file/KviFileUtils.h
+++ b/src/kvilib/file/KviFileUtils.h
@@ -129,6 +129,15 @@ namespace KviFileUtils
/**
* \brief Writes a complete file (UTF-8 version)
* \param szPath The path to the file
+ * \param oData The data to write
+ * \param bAppend If we want to append data or overwrite
+ * \return bool
+ */
+ KVILIB_API bool writeFile(const QString & szPath, const QByteArray & oData, bool bAppend = false);
+
+ /**
+ * \brief Writes a complete file (UTF-8 version)
+ * \param szPath The path to the file
* \param szData The data to write
* \param bAppend If we want to append data or overwrite
* \return bool
diff --git a/src/modules/options/OptionsWidget_interfaceFeatures.cpp b/src/modules/options/OptionsWidget_interfaceFeatures.cpp
index 0960d8001..5b693b2dc 100644
--- a/src/modules/options/OptionsWidget_interfaceFeatures.cpp
+++ b/src/modules/options/OptionsWidget_interfaceFeatures.cpp
@@ -78,7 +78,7 @@ void OptionsWidget_interfaceFeatures::commit()
if(m_pDisableSplash->isChecked())
{
if(!KviFileUtils::fileExists(szSplashDisableFile))
- KviFileUtils::writeFile(szSplashDisableFile,"");
+ KviFileUtils::writeFile(szSplashDisableFile,QString());
} else {
if(KviFileUtils::fileExists(szSplashDisableFile))
KviFileUtils::removeFile(szSplashDisableFile);
diff --git a/src/modules/package/libkvipackage.cpp b/src/modules/package/libkvipackage.cpp
index 32c5fcaa4..046fed65a 100644
--- a/src/modules/package/libkvipackage.cpp
+++ b/src/modules/package/libkvipackage.cpp
@@ -167,9 +167,61 @@ static bool package_kvs_fnc_info(KviKvsModuleFunctionCall * c)
}
+/*
+ @doc: package.extractfield
+ @type:
+ command
+ @title:
+ package.extractfield
+ @short:
+ Extract a package binary field and save it to a file.
+ @syntax:
+ package.extractfield <package_path> <field_id> <target_file_name>
+ @description:
+ Extracs a package binary metadata field and saves it to the specified file.
+ This is useful to extract images from the packages.
+*/
+static bool package_kvs_cmd_extractField(KviKvsModuleCommandCall * c)
+{
+ QString szPackagePath,szFieldId,szTargetFileName;
+ KVSM_PARAMETERS_BEGIN(c)
+ KVSM_PARAMETER("package_path",KVS_PT_NONEMPTYSTRING,0,szPackagePath)
+ KVSM_PARAMETER("field_id",KVS_PT_NONEMPTYSTRING,0,szFieldId)
+ KVSM_PARAMETER("target_file_name",KVS_PT_NONEMPTYSTRING,0,szTargetFileName)
+ KVSM_PARAMETERS_END(c)
+
+ KviPackageReader r;
+
+ // Unpack addon package into the random tmp dir
+ if(!r.readHeader(szPackagePath))
+ {
+ c->warning(__tr2qs_ctx("Failed to load package file: %1","package").arg(r.lastError()));
+ return true;
+ }
+
+ QByteArray * pField = r.binaryInfoFields()->find(szFieldId);
+
+ if(!pField)
+ {
+ c->warning(__tr2qs_ctx("Package does not contain binary field %1","package").arg(szFieldId));
+ return true;
+ }
+
+ if(!KviFileUtils::writeFile(szTargetFileName,*pField,false))
+ {
+ c->warning(__tr2qs_ctx("Failed to save file %1","package").arg(szTargetFileName));
+ return true;
+ }
+
+ return true;
+}
+
+
static bool package_module_init(KviModule *m)
{
KVSM_REGISTER_FUNCTION(m,"info",package_kvs_fnc_info);
+
+ KVSM_REGISTER_SIMPLE_COMMAND(m,"extractField",package_kvs_cmd_extractField);
return true;
}