Skip to content

Commit e4ecb9d

Browse files
Use sqlite to get rpm package count
1 parent 3c648d8 commit e4ecb9d

File tree

13 files changed

+98
-63
lines changed

13 files changed

+98
-63
lines changed

.github/workflows/pull_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
uses: actions/checkout@v2
1414

1515
- name: install required packages
16-
run: sudo apt-get update && sudo apt-get install -y libpci-dev libvulkan-dev libwayland-dev libxrandr-dev libxcb-randr0-dev libdconf-dev libdbus-1-dev libmagickcore-dev libxfconf-0-dev rpm librpm-dev libzstd-dev
16+
run: sudo apt-get update && sudo apt-get install -y libpci-dev libvulkan-dev libwayland-dev libxrandr-dev libxcb-randr0-dev libdconf-dev libdbus-1-dev libmagickcore-dev libxfconf-0-dev libsqlite3-dev
1717

1818
- name: Initialize CodeQL
1919
uses: github/codeql-action/init@v1

.github/workflows/push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
uses: actions/checkout@v2
1717

1818
- name: install required packages
19-
run: sudo apt-get update && sudo apt-get install -y libpci-dev libvulkan-dev libwayland-dev libxrandr-dev libxcb-randr0-dev libdconf-dev libdbus-1-dev libmagickcore-dev libxfconf-0-dev rpm librpm-dev libzstd-dev
19+
run: sudo apt-get update && sudo apt-get install -y libpci-dev libvulkan-dev libwayland-dev libxrandr-dev libxcb-randr0-dev libdconf-dev libdbus-1-dev libmagickcore-dev libxfconf-0-dev libsqlite3-dev
2020

2121
- name: Initialize CodeQL
2222
uses: github/codeql-action/init@v1

CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ OPTION(ENABLE_GIO "Enable gio-2.0" ON)
2727
OPTION(ENABLE_DCONF "Enable dconf" ON)
2828
OPTION(ENABLE_DBUS "Enable dbus-1" ON)
2929
OPTION(ENABLE_XFCONF "Enable libxfconf-0" ON)
30-
OPTION(ENABLE_RPM "Enable rpm" ON)
30+
OPTION(ENABLE_SQLITE3 "Enable sqlite3" ON)
3131
OPTION(ENABLE_IMAGEMAGICK7 "Enable imagemagick 7" ON)
3232
OPTION(ENABLE_IMAGEMAGICK6 "Enable imagemagick 6" ON)
3333
OPTION(ENABLE_ZLIB "Enable zlib" ON)
@@ -266,12 +266,12 @@ if(ENABLE_XFCONF)
266266
endif()
267267
endif()
268268

269-
if(ENABLE_RPM)
270-
pkg_check_modules(RPM rpm)
271-
if(RPM_FOUND)
272-
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_RPM=1)
269+
if(ENABLE_SQLITE3)
270+
pkg_check_modules(SQLITE3 sqlite3)
271+
if(SQLITE3_FOUND)
272+
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_SQLITE3=1)
273273
else()
274-
message(WARNING "Package librpm not found. Building without support.")
274+
message(WARNING "Package sqlite3 not found. Building without support.")
275275
endif()
276276
endif()
277277

@@ -346,7 +346,7 @@ target_include_directories(libfastfetch
346346
PRIVATE ${DCONF_INCLUDE_DIRS}
347347
PRIVATE ${DBUS_INCLUDE_DIRS}
348348
PRIVATE ${XFCONF_INCLUDE_DIRS}
349-
PRIVATE ${RPM_INCLUDE_DIRS}
349+
PRIVATE ${SQLITE3_INCLUDE_DIRS}
350350
PRIVATE ${IMAGEMAGICK7_INCLUDE_DIRS}
351351
PRIVATE ${IMAGEMAGICK6_INCLUDE_DIRS}
352352
PRIVATE ${ZLIB_INCLUDE_DIRS}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ The following libraries are used if present at runtime:
3333
* [`libZ`](https://www.zlib.net/): Faster image output when using kitty graphics protocol.
3434
* [`libDBus`](https://www.freedesktop.org/wiki/Software/dbus): Needed for detecting current media player and song.
3535
* [`libXFConf`](https://gitlab.xfce.org/xfce/xfconf): Needed for XFWM theme and XFCE Terminal font.
36-
* [`librpm`](http://rpm.org/): Needed for rpm package count.
36+
* [`libsqlite3`](https://www.sqlite.org/index.html): Needed for rpm package count.
3737

3838
## Support status
3939
All categories not listed here should work without needing a specific implementation.

completions/bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ __fastfetch_completion()
231231
"--lib-DConf"
232232
"--lib-DBus"
233233
"--lib-XFConf"
234-
"--lib-RPM"
234+
"--lib-sqlite3"
235235
"--lib-imagemagick"
236236
"--lib-z"
237237
"--lib-chafa"

src/common/init.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static void defaultConfig(FFinstance* instance)
199199
ffStrbufInitA(&instance->config.libDConf, 0);
200200
ffStrbufInitA(&instance->config.libDBus, 0);
201201
ffStrbufInitA(&instance->config.libXFConf, 0);
202-
ffStrbufInitA(&instance->config.librpm, 0);
202+
ffStrbufInitA(&instance->config.libSQLite3, 0);
203203
ffStrbufInitA(&instance->config.libImageMagick, 0);
204204
ffStrbufInitA(&instance->config.libZ, 0);
205205
ffStrbufInitA(&instance->config.libChafa, 0);
@@ -328,8 +328,8 @@ void ffListFeatures()
328328
#ifdef FF_HAVE_XFCONF
329329
"xfconf\n"
330330
#endif
331-
#ifdef FF_HAVE_RPM
332-
"librpm\n"
331+
#ifdef FF_HAVE_SQLITE3
332+
"sqlite3\n"
333333
#endif
334334
""
335335
, stdout);

src/common/settings.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "fastfetch.h"
22

33
#include <pthread.h>
4+
#include <string.h>
45

56
#define FF_LIBRARY_DATA_LOAD_INIT(dataObject, userLibraryName, ...) \
67
static dataObject data; \
@@ -267,6 +268,74 @@ FFvariant ffSettingsGetXFConf(FFinstance* instance, const char* channelName, con
267268
}
268269
#endif //FF_HAVE_XFCONF
269270

271+
#ifdef FF_HAVE_SQLITE3
272+
#include <sqlite3.h>
273+
274+
typedef struct SQLiteData
275+
{
276+
FF_LIBRARY_SYMBOL(sqlite3_open_v2)
277+
FF_LIBRARY_SYMBOL(sqlite3_prepare_v2)
278+
FF_LIBRARY_SYMBOL(sqlite3_step)
279+
FF_LIBRARY_SYMBOL(sqlite3_data_count)
280+
FF_LIBRARY_SYMBOL(sqlite3_column_int)
281+
FF_LIBRARY_SYMBOL(sqlite3_finalize)
282+
FF_LIBRARY_SYMBOL(sqlite3_close)
283+
} SQLiteData;
284+
285+
static const SQLiteData* getSQLiteData(const FFinstance* instance)
286+
{
287+
FF_LIBRARY_DATA_LOAD_INIT(SQLiteData, instance->config.libSQLite3, "libsqlite3.so", 1);
288+
289+
FF_LIBRARY_DATA_LOAD_SYMBOL(sqlite3_open_v2)
290+
FF_LIBRARY_DATA_LOAD_SYMBOL(sqlite3_prepare_v2)
291+
FF_LIBRARY_DATA_LOAD_SYMBOL(sqlite3_step)
292+
FF_LIBRARY_DATA_LOAD_SYMBOL(sqlite3_data_count)
293+
FF_LIBRARY_DATA_LOAD_SYMBOL(sqlite3_column_int)
294+
FF_LIBRARY_DATA_LOAD_SYMBOL(sqlite3_finalize)
295+
FF_LIBRARY_DATA_LOAD_SYMBOL(sqlite3_close)
296+
297+
FF_LIBRARY_DATA_LOAD_RETURN
298+
}
299+
300+
int ffSettingsGetSQLite3Int(FFinstance* instance, const char* dbPath, const char* query)
301+
{
302+
const SQLiteData* data = getSQLiteData(instance);
303+
if(data == NULL)
304+
return 0;
305+
306+
sqlite3* db;
307+
if(data->ffsqlite3_open_v2(dbPath, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK)
308+
return 0;
309+
310+
sqlite3_stmt* stmt;
311+
if(data->ffsqlite3_prepare_v2(db, query, (int) strlen(query), &stmt, NULL) != SQLITE_OK)
312+
{
313+
data->ffsqlite3_close(db);
314+
return 0;
315+
}
316+
317+
if(data->ffsqlite3_step(stmt) != SQLITE_ROW || data->ffsqlite3_data_count(stmt) < 1)
318+
{
319+
data->ffsqlite3_finalize(stmt);
320+
data->ffsqlite3_close(db);
321+
return 0;
322+
}
323+
324+
int result = data->ffsqlite3_column_int(stmt, 0);
325+
326+
data->ffsqlite3_finalize(stmt);
327+
data->ffsqlite3_close(db);
328+
329+
return result;
330+
}
331+
#else //FF_HAVE_SQLITE3
332+
int ffSettingsGetSQLite3Int(FFinstance* instance, const char* dbPath, const char* query)
333+
{
334+
FF_UNUSED(instance, dbPath, query)
335+
return 0;
336+
}
337+
#endif //FF_HAVE_SQLITE3
338+
270339
#ifdef __ANDROID__
271340
#include <sys/system_properties.h>
272341
bool ffSettingsGetAndroidProperty(const char* propName, FFstrbuf* result) {

src/data/config.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@
233233
#--lib-DConf /usr/lib/libdconf.so
234234
#--lib-DBus /usr/lib/libdbus-1.so
235235
#--lib-XFConf /usr/lib/libxfconf-0.so
236-
#--lib-rpm /usr/lib/librpm.so
236+
#--lib-sqlite3 /usr/lib/libsqlite3.so
237237
#--lib-imagemagick /usr/lib/libMagickCore-7.Q16HDRI.so
238238
#--lib-z /usr/lib/libz.so
239239
#--lib-chafa /usr/lib/libchafa.so

src/data/help.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ Library options: Set the path of a library to load
122122
--lib-DConf <path>
123123
--lib-DBus <path>
124124
--lib-XFConf <path>
125-
--lib-RPM <path>
125+
--lib-sqlite3 <path>
126126
--lib-imagemagick <path>
127127
--lib-z <path>
128128
--lib-chafa <path>

src/fastfetch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,8 +991,8 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
991991
optionParseString(key, value, &instance->config.libDBus);
992992
else if(strcasecmp(key, "--lib-XFConf") == 0)
993993
optionParseString(key, value, &instance->config.libXFConf);
994-
else if(strcasecmp(key, "--lib-rpm") == 0)
995-
optionParseString(key, value, &instance->config.librpm);
994+
else if(strcasecmp(key, "--lib-sqlite") == 0 || strcasecmp(key, "--lib-sqlite3") == 0)
995+
optionParseString(key, value, &instance->config.libSQLite3);
996996
else if(strcasecmp(key, "--lib-imagemagick") == 0)
997997
optionParseString(key, value, &instance->config.libImageMagick);
998998
else if(strcasecmp(key, "--lib-z") == 0)

0 commit comments

Comments
 (0)