You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
254 lines
8.5 KiB
254 lines
8.5 KiB
#include "libublsettings-gtk3.h"
|
|
#include <alpm.h>
|
|
|
|
|
|
struct packages {
|
|
alpm_handle_t *packages_handle;
|
|
int init_status;
|
|
} packages_struct = {};
|
|
|
|
int _yon_packages_get_db(){
|
|
const char *root = "/";
|
|
const char *dbpath = "/var/lib/pacman";
|
|
const char *config_path = "/etc/pacman.conf";
|
|
packages_struct.packages_handle = alpm_initialize(root,dbpath,NULL);
|
|
if (!packages_struct.packages_handle){
|
|
packages_struct.init_status=0;
|
|
return 0;
|
|
}
|
|
int size = 0;
|
|
config_str pacman_config = yon_file_open((char*)config_path,&size);
|
|
char *pacman_config_full = yon_char_parsed_to_string(pacman_config,size,"");
|
|
|
|
GRegex *regex = g_regex_new("^\\[.*\\]$",G_REGEX_MULTILINE,0,NULL);
|
|
GMatchInfo *match = NULL;
|
|
g_regex_match(regex,pacman_config_full,G_REGEX_MATCH_DEFAULT,&match);
|
|
|
|
while (g_match_info_matches(match)){
|
|
char *iter = g_match_info_fetch(match,0);
|
|
if (iter[0]=='['){
|
|
free(yon_char_divide(iter,0));
|
|
yon_char_remove_last_symbol(iter,']');
|
|
}
|
|
if (strcmp(iter,"options")){
|
|
alpm_register_syncdb(packages_struct.packages_handle,iter,ALPM_SIG_USE_DEFAULT);
|
|
}
|
|
g_match_info_next(match,NULL);
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
alpm_list_t *_yon_packages_get_db_list(enum YON_PACKAGES_DB_TYPE type){
|
|
alpm_list_t *db_list = NULL;
|
|
switch(type){
|
|
case YON_PACKAGES_LOCAL:
|
|
alpm_db_t *database = alpm_get_localdb(packages_struct.packages_handle);
|
|
if (!db_list) db_list = alpm_list_append(&db_list,database);
|
|
else alpm_list_append(&db_list,database);
|
|
break;
|
|
|
|
case YON_PACKAGES_SYNC:
|
|
alpm_list_t *sync_db = alpm_get_syncdbs(packages_struct.packages_handle);
|
|
for (alpm_list_t *iter=sync_db;iter;iter=alpm_list_next(iter)){
|
|
alpm_db_t *database = iter->data;
|
|
if (!db_list) db_list = alpm_list_append(&db_list,database);
|
|
else alpm_list_append(&db_list,database);
|
|
}
|
|
break;
|
|
|
|
case YON_PACKAGES_ALL:{
|
|
alpm_list_t *sync_db = alpm_get_syncdbs(packages_struct.packages_handle);
|
|
for (alpm_list_t *iter=sync_db;iter;iter=alpm_list_next(iter)){
|
|
alpm_db_t *database = iter->data;
|
|
if (!db_list) db_list = alpm_list_append(&db_list,database);
|
|
else alpm_list_append(&db_list,database);
|
|
}
|
|
}
|
|
{
|
|
alpm_db_t *database = alpm_get_localdb(packages_struct.packages_handle);
|
|
if (!db_list) db_list = alpm_list_append(&db_list,database);
|
|
else alpm_list_append(&db_list,database);
|
|
}
|
|
break;
|
|
|
|
}
|
|
return db_list;
|
|
}
|
|
|
|
int yon_packages_init(){
|
|
if (packages_struct.packages_handle) return 0;
|
|
|
|
int status = _yon_packages_get_db();
|
|
if (!status) return 0;
|
|
|
|
return 1;
|
|
}
|
|
|
|
|
|
int yon_packages_check_exist(const char *package_name){
|
|
alpm_list_t *sync_db = alpm_get_syncdbs(packages_struct.packages_handle);
|
|
for (alpm_list_t *iter=sync_db;iter;iter=alpm_list_next(iter)){
|
|
alpm_db_t *database = iter->data;
|
|
alpm_pkg_t *package = alpm_db_get_pkg(database,package_name);
|
|
if (package) return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int yon_packages_check_installed(char *package_name){
|
|
alpm_db_t *database = alpm_get_localdb(packages_struct.packages_handle);
|
|
alpm_pkg_t *package = alpm_db_get_pkg(database,package_name);
|
|
if (package) return 1;
|
|
return 0;
|
|
}
|
|
|
|
int yon_packages_check_updates(char *package_name){
|
|
alpm_pkg_t *sync_db_package = NULL;
|
|
alpm_pkg_t *local_db_package = NULL;
|
|
|
|
alpm_list_t *sync_db = alpm_get_syncdbs(packages_struct.packages_handle);
|
|
for (alpm_list_t *iter=sync_db;iter;iter=alpm_list_next(iter)){
|
|
alpm_db_t *database = iter->data;
|
|
alpm_pkg_t *package = alpm_db_get_pkg(database,package_name);
|
|
if (package) sync_db_package = package;
|
|
}
|
|
{
|
|
alpm_db_t *database = alpm_get_localdb(packages_struct.packages_handle);
|
|
alpm_pkg_t *package = alpm_db_get_pkg(database,package_name);
|
|
if (package) local_db_package = package;
|
|
}
|
|
|
|
if (sync_db_package && local_db_package){
|
|
const char *sync_db_package_version = alpm_pkg_get_version(sync_db_package);
|
|
const char *local_db_package_version = alpm_pkg_get_version(sync_db_package);
|
|
if (strcmp(sync_db_package_version,local_db_package_version)) return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
config_str yon_packages_find(enum YON_PACKAGES_DB_TYPE type, const char *search_string, gsize *size){
|
|
(*size)=0;
|
|
if (yon_char_is_empty(search_string)) return NULL;
|
|
|
|
config_str final = NULL;
|
|
|
|
alpm_list_t *databases = _yon_packages_get_db_list(type);
|
|
alpm_list_t *iter = NULL;
|
|
for (iter = databases; iter; iter=iter->next){
|
|
alpm_db_t *database = iter->data;
|
|
alpm_list_t *packages = alpm_db_get_pkgcache(database);
|
|
alpm_list_t *iter2 = NULL;
|
|
for (iter2 = packages; iter2; iter2=iter2->next){
|
|
const char *name = alpm_pkg_get_name(iter2->data);
|
|
if (strstr(name,search_string)){
|
|
yon_char_parsed_add_or_create_if_exists(final,(int*)size,(char*)name);
|
|
}
|
|
}
|
|
}
|
|
return final;
|
|
}
|
|
|
|
char *yon_packages_get_version(enum YON_PACKAGES_DB_TYPE type, const char *package){
|
|
if (yon_char_is_empty(package)) return NULL;
|
|
|
|
alpm_list_t *databases = _yon_packages_get_db_list(type);
|
|
alpm_list_t *iter = NULL;
|
|
for (iter = databases; iter; iter=iter->next){
|
|
alpm_pkg_t *pkg = alpm_db_get_pkg(iter->data,package);
|
|
if (!pkg) continue;
|
|
const char *name = alpm_pkg_get_name(pkg);
|
|
if (!strcmp(name,package)){
|
|
return yon_char_new(alpm_pkg_get_version(pkg));
|
|
}
|
|
}
|
|
}
|
|
|
|
char *yon_packages_get_description(enum YON_PACKAGES_DB_TYPE type, const char *package){
|
|
if (yon_char_is_empty(package)) return NULL;
|
|
|
|
alpm_list_t *databases = _yon_packages_get_db_list(type);
|
|
alpm_list_t *iter = NULL;
|
|
for (iter = databases; iter; iter=iter->next){
|
|
alpm_pkg_t *pkg = alpm_db_get_pkg(iter->data,package);
|
|
if (!pkg) continue;
|
|
const char *name = alpm_pkg_get_name(pkg);
|
|
if (!strcmp(name,package)){
|
|
return yon_char_new(alpm_pkg_get_desc(pkg));
|
|
}
|
|
}
|
|
}
|
|
|
|
config_str yon_packages_get_depends(enum YON_PACKAGES_DB_TYPE type, const char *package, int *size){
|
|
(*size)=0;
|
|
if (yon_char_is_empty(package)) return NULL;
|
|
config_str depends = NULL;
|
|
|
|
alpm_list_t *databases = _yon_packages_get_db_list(type);
|
|
alpm_list_t *iter = NULL, *pkg_iter = NULL;
|
|
for (iter = databases; iter; iter=iter->next){
|
|
alpm_pkg_t *pkg = alpm_db_get_pkg(iter->data,package);
|
|
if (!pkg) continue;
|
|
alpm_list_t *list = alpm_pkg_compute_requiredby(pkg);
|
|
for (pkg_iter = list; pkg_iter; pkg_iter=pkg_iter->next){
|
|
yon_char_parsed_add_or_create_if_exists(depends,size,pkg_iter->data);
|
|
|
|
}
|
|
break;
|
|
}
|
|
|
|
return depends;
|
|
}
|
|
|
|
void yon_packages_update(){
|
|
if (getuid()) return;
|
|
if (packages_struct.packages_handle) alpm_release(packages_struct.packages_handle);
|
|
packages_struct.packages_handle=NULL;
|
|
_yon_packages_get_db();
|
|
}
|
|
|
|
int yon_packages_install(char *package){
|
|
if (!packages_struct.init_status) return 0;
|
|
// char *command = install_package_command(package);
|
|
// yon_terminal_window_launch(NULL,command,"","");
|
|
|
|
yon_packages_update();
|
|
// free(command);
|
|
}
|
|
|
|
int yon_packages_remove(char *package){
|
|
if (!packages_struct.init_status) return 0;
|
|
// char *command = remove_package_command(package);
|
|
// yon_terminal_window_launch(NULL,command,"","");
|
|
|
|
yon_packages_update();
|
|
// free(command);
|
|
}
|
|
|
|
void yon_packages_finish(){
|
|
if (!packages_struct.init_status) return;
|
|
alpm_release(packages_struct.packages_handle);
|
|
}
|
|
|
|
GList *yon_packages_get_all(){
|
|
if (!packages_struct.init_status) return NULL;
|
|
|
|
GList *list = NULL;
|
|
|
|
alpm_list_t *sync_db = alpm_get_syncdbs(packages_struct.packages_handle);
|
|
for (alpm_list_t *iter=sync_db;iter;iter=alpm_list_next(iter)){
|
|
alpm_db_t *database = iter->data;
|
|
alpm_list_t *package_list = alpm_db_get_pkgcache(database);
|
|
for (alpm_list_t *iter = package_list;iter;iter=iter->next){
|
|
const char *cur_name = alpm_pkg_get_name(iter->data);
|
|
if (!list) list = g_list_append(list,yon_char_new(cur_name));
|
|
else if (g_list_append(list,yon_char_new(cur_name))){};
|
|
}
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
int yon_packages_upac_init(){
|
|
|
|
} |