Skip to content

Commit

Permalink
Larger Commit than I intended
Browse files Browse the repository at this point in the history
- Moved Main Window GUI Code to main_window.c/h
- Crudely Include Steam games that are not included yet and download
images for them.
- Command line arguments
- Create Config Directory if not already created.
- Save Config variables (but No way to change them in program yet) as
part of creating new config directory.
  • Loading branch information
iguessthislldo committed Mar 26, 2018
1 parent ad482ff commit aad4cbd
Show file tree
Hide file tree
Showing 9 changed files with 388 additions and 166 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
banner_launcher
debug_config
105 changes: 105 additions & 0 deletions Entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
#include <string.h>

#include "launcher.h"
#include "main_window.h"
#include "Entry.h"
#include "util.h"
#include "steam.h"

Entry * Entry_new() {
return calloc(sizeof(Entry), 1);
Expand Down Expand Up @@ -124,6 +126,61 @@ Entries * Entries_clear_container(GtkContainer * container, Entries * entries) {
}
}

bool Entries_load(Entries * entries, const gchar * path) {
bool error = false;
if (debug) printf("Loading Entries from %s\n", path);
GKeyFile * ini = g_key_file_new();
if (g_key_file_load_from_file(
ini, path, G_KEY_FILE_NONE, NULL
)) {
gsize num_groups;
gchar ** groups = g_key_file_get_groups(ini, &num_groups);
if (!num_groups || strcmp("meta", groups[0])) {
error = true;
}
next_id = g_key_file_get_integer(ini, groups[0], "next_id", NULL);
for (gsize i = 1; i < num_groups; i++) {
Entry * entry = Entry_new();

// id
entry->id = g_strdup(groups[i]);

// name
Entry_set_name(entry,
g_key_file_get_string(ini, groups[i], "name", NULL)
);
entry->count = g_key_file_get_integer(ini, groups[i], "count", NULL);

// image_path
entry->image_path = g_key_file_get_string(ini, groups[i], "image", NULL);

// Run Information
if (g_key_file_has_key(ini, groups[i], "exec", NULL)) {
entry->exec = g_key_file_get_value(ini, groups[i], "exec", NULL);
}
if (g_key_file_has_key(ini, groups[i], "cd", NULL)) {
entry->cd = g_key_file_get_value(ini, groups[i], "cd", NULL);
}
if (g_key_file_has_key(ini, groups[i], "steam_id", NULL)) {
entry->steam_id = g_key_file_get_value(
ini, groups[i], "steam_id", NULL
);
}

if (debug) {
printf(" %s: \"%s\"\n",
groups[i], entry->name
);
}
Entries_append(entries, entry);
}
} else {
error = true;
}
g_key_file_free(ini);
return error;
}

Entries * Entries_filter(Entries * entries, const char * filter) {
char * uc_filter = g_utf8_strup(filter, -1);
Entries * filtered = Entries_new();
Expand Down Expand Up @@ -204,3 +261,51 @@ void Entries_sort(Entries * entries) {

free(roster);
}

void Entries_insert_steam() {
for (Node * snode = steam_entries->head; snode; snode = snode->next) {
bool found = false;
for (Node * n = all_entries->head; n; n = n->next) {
if (n->entry->steam_id == snode->entry->steam_id) {
found = true;
break;
}
}
if (!found) {
Entry * entry = snode->entry;
Entries_append(all_entries, entry);

// Take care of id and file name
char id[64];
unsigned id_len = sprintf(&id[0], "%u", next_id++);
entry->id = g_strdup(&id[0]);
char * image_name = malloc(id_len + 5);
sprintf(image_name, "%s.jpg", entry->id);
entry->image_path = g_strdup(image_name);
char * header_path = g_build_filename(
banners_dir,
image_name,
NULL);

// Build URL
unsigned steam_id_len = strlen(entry->steam_id);
char * steam_header_url = malloc(
steam_header_url_head_len +
steam_header_url_tail_len +
steam_id_len + 1
);
sprintf(steam_header_url, "%s%s%s",
steam_header_url_head,
entry->steam_id,
steam_header_url_tail
);

// Download
printf("%s -> %s\n", steam_header_url, header_path);
download(NULL, update_bar, steam_header_url, header_path);
free(steam_header_url);
g_free(header_path);
}
}
}

10 changes: 10 additions & 0 deletions Entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ void Entries_delete(Entries * entries);
*/
void Entries_delete_all(Entries * entries);

/*
* Load Entries from ini file
*/
bool Entries_load(Entries * entries, const gchar * path);

/*
* Return new entry list with entries that start with *filter* ignoring case.
*/
Expand All @@ -114,4 +119,9 @@ Entries * Entries_clear_container(GtkContainer * container, Entries * entries);
*/
void Entries_sort(Entries * entries);

/*
* Include Steam Entries
*/
void Entries_insert_steam();

#endif
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ EXEC=banner_launcher

all: $(EXEC)

$(EXEC): launcher.c Entry.c steam.c util.c
$(EXEC): launcher.c Entry.c steam.c util.c main_window.c
gcc -g `pkg-config --cflags gtk+-3.0` -o $@ $^ -lcurl `pkg-config --libs gtk+-3.0`

install: $(EXEC)
cp $(EXEC) /usr/local/bin
chmod +x /usr/local/bin/$(EXEC)

uninstall:
rm -f /usr/local/bin/$(EXEC)

clean:
rm -f $(EXEC)
rm -fr debug_config
Loading

0 comments on commit aad4cbd

Please sign in to comment.