|
|
|
|
@ -1,5 +1,7 @@
|
|
|
|
|
#include "libublsettings-gtk3.h"
|
|
|
|
|
|
|
|
|
|
#include <alpm.h>
|
|
|
|
|
|
|
|
|
|
#ifdef __GTK_H__
|
|
|
|
|
|
|
|
|
|
// GtkEntry section
|
|
|
|
|
@ -41,171 +43,137 @@
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
struct packages {
|
|
|
|
|
GHashTable *all_list;
|
|
|
|
|
GHashTable *installed_list;
|
|
|
|
|
GHashTable *updates_list;
|
|
|
|
|
alpm_handle_t *packages_handle;
|
|
|
|
|
int init_status;
|
|
|
|
|
} packages_struct;
|
|
|
|
|
GThread *packages_thread = NULL;
|
|
|
|
|
|
|
|
|
|
void *_yon_packages_init(void){
|
|
|
|
|
if (getuid()){
|
|
|
|
|
packages_struct.init_status = 0;
|
|
|
|
|
g_thread_exit(NULL);
|
|
|
|
|
}
|
|
|
|
|
packages_struct.all_list = g_hash_table_new_full(g_str_hash,g_str_equal,free,NULL);
|
|
|
|
|
packages_struct.installed_list = g_hash_table_new_full(g_str_hash,g_str_equal,free,NULL);
|
|
|
|
|
packages_struct.updates_list = g_hash_table_new_full(g_str_hash,g_str_equal,free,NULL);
|
|
|
|
|
|
|
|
|
|
int size;
|
|
|
|
|
int installed_size;
|
|
|
|
|
int updates_size;
|
|
|
|
|
config_str package_list = yon_config_load("pacman -Slq",&size);
|
|
|
|
|
config_str installed = yon_config_load("pacman -Qq",&installed_size);
|
|
|
|
|
config_str updates = yon_config_load("pacman -Qqu",&updates_size);
|
|
|
|
|
|
|
|
|
|
for (int i=0;i<size;i++){
|
|
|
|
|
while(gtk_events_pending()) gtk_main_iteration();
|
|
|
|
|
yon_char_remove_last_symbol(package_list[i],'\n');
|
|
|
|
|
g_hash_table_add(packages_struct.all_list,package_list[i]);
|
|
|
|
|
} 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,"");
|
|
|
|
|
|
|
|
|
|
for (int i=0;i<installed_size;i++){
|
|
|
|
|
while(gtk_events_pending()) gtk_main_iteration();
|
|
|
|
|
yon_char_remove_last_symbol(installed[i],'\n');
|
|
|
|
|
g_hash_table_add(packages_struct.installed_list,installed[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i=0;i<updates_size;i++){
|
|
|
|
|
while(gtk_events_pending()) gtk_main_iteration();
|
|
|
|
|
yon_char_remove_last_symbol(updates[i],'\n');
|
|
|
|
|
g_hash_table_add(packages_struct.updates_list,updates[i]);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
free(package_list);
|
|
|
|
|
free(installed);
|
|
|
|
|
free(updates);
|
|
|
|
|
|
|
|
|
|
if (g_hash_table_size(packages_struct.all_list)&&g_hash_table_size(packages_struct.installed_list)){
|
|
|
|
|
packages_struct.init_status = 1;
|
|
|
|
|
} else {
|
|
|
|
|
packages_struct.init_status = 0;
|
|
|
|
|
}
|
|
|
|
|
g_thread_exit(NULL);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void yon_packages_init(){
|
|
|
|
|
packages_thread = g_thread_new("packages_thread",(GThreadFunc)_yon_packages_init,NULL);
|
|
|
|
|
}
|
|
|
|
|
int yon_packages_init(){
|
|
|
|
|
if (packages_struct.packages_handle) return 0;
|
|
|
|
|
|
|
|
|
|
int status = _yon_packages_get_db();
|
|
|
|
|
if (!status) return 0;
|
|
|
|
|
|
|
|
|
|
int yon_packages_finalize(){
|
|
|
|
|
g_thread_join(packages_thread);
|
|
|
|
|
return packages_struct.init_status;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define install_package_command(target) yon_char_unite("pacman -S ",target,NULL)
|
|
|
|
|
#define remove_package_command(target) yon_char_unite("pacman -R ",target,NULL)
|
|
|
|
|
#define update_package_installed_command(target) yon_char_append("pacman -Qq ",target)
|
|
|
|
|
#define update_package_updated_command(target) yon_char_append("pacman -Qqu ",target)
|
|
|
|
|
|
|
|
|
|
int yon_packages_check_exist(char *package){
|
|
|
|
|
if (!packages_struct.init_status) return 0;
|
|
|
|
|
return g_hash_table_contains(packages_struct.all_list,package);
|
|
|
|
|
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){
|
|
|
|
|
if (!packages_struct.init_status) return 0;
|
|
|
|
|
return g_hash_table_contains(packages_struct.installed_list,package);
|
|
|
|
|
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){
|
|
|
|
|
if (!packages_struct.init_status) return 0;
|
|
|
|
|
return g_hash_table_contains(packages_struct.updates_list,package);
|
|
|
|
|
}
|
|
|
|
|
int yon_packages_check_updates(char *package_name){
|
|
|
|
|
alpm_pkg_t *sync_db_package = NULL;
|
|
|
|
|
alpm_pkg_t *local_db_package = NULL;
|
|
|
|
|
|
|
|
|
|
void yon_packages_update_package_is_installed(char *package){
|
|
|
|
|
if (!packages_struct.init_status) return;
|
|
|
|
|
char *command = update_package_installed_command(package);
|
|
|
|
|
if (!system(command)){
|
|
|
|
|
if (!g_hash_table_contains(packages_struct.installed_list,package)){
|
|
|
|
|
g_hash_table_add(packages_struct.installed_list,yon_char_new(package));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (g_hash_table_contains(packages_struct.installed_list,package)){
|
|
|
|
|
g_hash_table_remove(packages_struct.installed_list,package);
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
free(command);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void yon_packages_update_package_is_updated(char *package){
|
|
|
|
|
if (!packages_struct.init_status) return;
|
|
|
|
|
char *command = update_package_updated_command(package);
|
|
|
|
|
if (!system(command)){
|
|
|
|
|
if (!g_hash_table_contains(packages_struct.updates_list,package)){
|
|
|
|
|
g_hash_table_add(packages_struct.updates_list,yon_char_new(package));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (g_hash_table_contains(packages_struct.updates_list,package)){
|
|
|
|
|
g_hash_table_remove(packages_struct.updates_list,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;
|
|
|
|
|
}
|
|
|
|
|
free(command);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void yon_packages_update_package(char *package){
|
|
|
|
|
if (!packages_struct.init_status) return;
|
|
|
|
|
char *command = update_package_installed_command(package);
|
|
|
|
|
if (!system(command)){
|
|
|
|
|
if (!g_hash_table_contains(packages_struct.installed_list,package)){
|
|
|
|
|
g_hash_table_add(packages_struct.installed_list,yon_char_new(package));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (g_hash_table_contains(packages_struct.installed_list,package)){
|
|
|
|
|
g_hash_table_remove(packages_struct.installed_list,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;
|
|
|
|
|
}
|
|
|
|
|
free(command);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
command = update_package_updated_command(package);
|
|
|
|
|
if (!system(command)){
|
|
|
|
|
if (!g_hash_table_contains(packages_struct.updates_list,package)){
|
|
|
|
|
g_hash_table_add(packages_struct.updates_list,yon_char_new(package));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (g_hash_table_contains(packages_struct.updates_list,package)){
|
|
|
|
|
g_hash_table_remove(packages_struct.updates_list,package);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
free(command);
|
|
|
|
|
void yon_packages_update(){
|
|
|
|
|
if (packages_struct.packages_handle) alpm_release(packages_struct.packages_handle);
|
|
|
|
|
_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,"","");
|
|
|
|
|
// char *command = install_package_command(package);
|
|
|
|
|
// yon_terminal_window_launch(NULL,command,"","");
|
|
|
|
|
|
|
|
|
|
yon_packages_update_package(package);
|
|
|
|
|
free(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,"","");
|
|
|
|
|
// char *command = remove_package_command(package);
|
|
|
|
|
// yon_terminal_window_launch(NULL,command,"","");
|
|
|
|
|
|
|
|
|
|
yon_packages_update_package(package);
|
|
|
|
|
free(command);
|
|
|
|
|
yon_packages_update();
|
|
|
|
|
// free(command);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void yon_packages_finish(){
|
|
|
|
|
if (!packages_struct.init_status) return;
|
|
|
|
|
g_hash_table_unref(packages_struct.all_list);
|
|
|
|
|
g_hash_table_unref(packages_struct.installed_list);
|
|
|
|
|
alpm_release(packages_struct.packages_handle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GList *yon_packages_get_all(){
|
|
|
|
|
if (!packages_struct.init_status) return NULL;
|
|
|
|
|
GList *list = g_hash_table_get_keys(packages_struct.all_list);
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|