Show home page with Release infos

This commit is contained in:
Nekobit 2023-09-07 22:42:19 -04:00
parent deb2025fbb
commit 47c3ec4d5b
6 changed files with 356 additions and 10 deletions

View File

@ -1,9 +1,10 @@
CC=cc
CFLAGS=`pkg-config --cflags efl ecore elementary`
LDFLAGS=`pkg-config --libs efl ecore elementary`
CFLAGS=`pkg-config --cflags efl ecore elementary` `curl-config --cflags`
LDFLAGS=`pkg-config --libs efl ecore elementary` `curl-config --libs` -lcjson
OBJS=main.o replay.o home.o
minilauncher4slippi: main.o replay.o
$(CC) -o minilauncher4slippi main.o replay.o $(LDFLAGS)
minilauncher4slippi: $(OBJS)
$(CC) -o minilauncher4slippi $(OBJS) $(LDFLAGS)
clean:
rm minilauncher4slippi *.o

180
home.c Normal file
View File

@ -0,0 +1,180 @@
#include <stdio.h>
#include <curl/curl.h>
#include <cjson/cJSON.h>
#include <stdint.h>
#include <md4c-html.h>
#include "replay.h"
Evas_Object* tab_home = NULL;
static Evas_Object* tab_home_scr = NULL;
static Evas_Object* tab_home_content = NULL;
char const* home_url = "https://api.github.com/repos/project-slippi/Ishiiruka/releases";
struct memory_chunk {
char* data;
size_t size;
};
size_t
write_callback(char* ptr, size_t size, size_t nmemb, void* userp)
{
size_t realsize = size * nmemb;
struct memory_chunk* mem = userp;
char *nptr = realloc(mem->data, mem->size + realsize + 1);
if(!nptr) {
/* out of memory! */
printf("not enough memory (realloc returned NULL)\n");
return 0;
}
mem->data = nptr;
memcpy(&(mem->data[mem->size]), ptr, realsize);
mem->size += realsize;
mem->data[mem->size] = 0;
return realsize;
}
int
releases_result(struct memory_chunk chunk)
{
cJSON* json = cJSON_ParseWithLength(chunk.data, chunk.size);
if (!json)
{
fprintf(stderr, "Something happened.\n");
return 1;
}
cJSON* release = NULL;
//cJSON_ArrayForEach(release, json)
int i = 0;
for (cJSON* c = json->child; c->next != NULL; (++i, c = c->next))
{
if (i == 6)
{
Evas_Object* notice = elm_label_add(tab_home_content);
elm_object_text_set(notice, "Older releases are collapsed, click to expand");
elm_box_pack_end(tab_home_content, notice);
evas_object_show(notice);
}
Evas_Object* release_fr = elm_frame_add(tab_home_content);
// Size
evas_object_size_hint_weight_set(release_fr, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(release_fr, EVAS_HINT_FILL, EVAS_HINT_FILL);
// END Size
elm_frame_autocollapse_set(release_fr, EINA_TRUE);
if (i > 5)
elm_frame_collapse_set(release_fr, EINA_TRUE);
elm_box_pack_end(tab_home_content, release_fr);
cJSON* title = cJSON_GetObjectItemCaseSensitive(c, "name");
elm_object_text_set(release_fr, title->valuestring);
evas_object_show(release_fr);
Evas_Object* fr_box = elm_box_add(release_fr);
elm_object_content_set(release_fr, fr_box);
evas_object_show(fr_box);
Evas_Object* content = elm_entry_add(fr_box);
elm_box_pack_end(fr_box, content);
elm_entry_editable_set(content, EINA_FALSE);
evas_object_size_hint_weight_set(content, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(content, EVAS_HINT_FILL, EVAS_HINT_FILL);
/* Get body_html and manipulate it */
cJSON* body = cJSON_GetObjectItemCaseSensitive(c, "body_html");
Eina_Strbuf* body_fmt = eina_strbuf_manage_new(body->valuestring);
eina_strbuf_replace_all(body_fmt, "\n", "<br>");
eina_strbuf_trim(body_fmt);
elm_object_text_set(content, eina_strbuf_string_get(body_fmt));
evas_object_show(content);
free(eina_strbuf_release(body_fmt));
//elm_box_pack_end(tab_home_box, fr_box);
}
return 0;
}
void
_tab_home_make_da_damn_request()
{
char curl_errbuf[CURL_ERROR_SIZE];
int res;
struct memory_chunk data;
data.data = malloc(1);
data.size = 0;
CURL* curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, home_url);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errbuf);
//curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
//curl_easy_setopt(curl, CURLOPT_VERBOSE, 0);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &data);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 5);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "Minilauncher4slippi/1.0");
//application/vnd.github.html+json
struct curl_slist *hs=NULL;
hs = curl_slist_append(hs, "Accept: application/vnd.github.html");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, hs);
res = curl_easy_perform(curl);
if(res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
}
else {
printf("%lu bytes retrieved\n", (unsigned long)data.size);
/* cleanup curl stuff */
releases_result(data);
free(data.data);
}
curl_easy_cleanup(curl);
/* we are done with libcurl, so clean it up */
curl_global_cleanup();
}
void
tab_home_setup(Evas_Object* parent)
{
curl_global_init(CURL_GLOBAL_ALL);
tab_home = elm_box_add(parent); // Scroller
evas_object_size_hint_weight_set(tab_home, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(tab_home, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(tab_home);
tab_home_scr = elm_scroller_add(tab_home);
evas_object_size_hint_weight_set(tab_home_scr, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(tab_home_scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(tab_home, tab_home_scr);
evas_object_show(tab_home_scr);
tab_home_content = elm_box_add(tab_home_scr);
evas_object_size_hint_weight_set(tab_home_content, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(tab_home_content, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(tab_home_content);
elm_object_content_set(tab_home_scr, tab_home_content);
//elm_object_content_set(tab_home, tab_home_box);
//evas_object_show(bt);
//evas_object_show(tab_home_box);
//evas_object_show(tab_home);
_tab_home_make_da_damn_request();
}

14
home.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef HOME_H
#define HOME_H
#define EFL_BETA_API_SUPPORT
#include <Ecore.h>
#include <Efl_Ui.h>
#include <Elementary.h>
extern Evas_Object* tab_home;
void
tab_home_setup(Evas_Object* parent);
#endif /* HOME_H */

49
main.c
View File

@ -4,18 +4,49 @@
#include <Efl_Ui.h>
#include <Elementary.h>
#include "replay.h"
#include "home.h"
int opt_mallocd = -1;
char* game_path = "SSBM.iso";
char* dolphin_emu_file = "./dolphin-emu";
char* dolphin_replay_file = "./slippi-replay";
char* dolphin_emu_file = "slippi-netplay-dolphin";
char* dolphin_replay_file = "slippi-playback-dolphin";
Evas_Object* mainer;
Evas_Object* win;
Evas_Object* _tab_curr;
Evas_Object* tab_home;
//extern Evas_Object* tab_home;
//extern Evas_Object* tab_replays;
Evas_Object* tab_config;
int
parse_config(char* file)
{
FILE* CFG = fopen(file, "r");
if (!CFG)
{
perror("fopen");
return 1;
}
int buf_len = 255;
char buf[buf_len];
char* rdpnt;
for (int i = 0; fgets(buf, buf_len, CFG); ++i) {
if ((rdpnt = strchr(buf, '\n')))
*rdpnt = '\0';
switch (i)
{
case 0: game_path = strdup(buf); break;
case 1: dolphin_emu_file = strdup(buf); break;
case 2: dolphin_replay_file = strdup(buf); break;
}
++opt_mallocd;
}
abort:
fclose(CFG);
return 0;
}
void
_tab_switch_cb(void *_data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
@ -85,9 +116,8 @@ _replays_tab_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_
void
tabs_init()
{
tab_home = elm_button_add(win);
elm_object_text_set(tab_home, "Test button");
evas_object_size_hint_align_set(tab_home, EVAS_HINT_FILL, EVAS_HINT_FILL);
tab_home_setup(mainer);
// BEGIN tab_replays
@ -98,6 +128,8 @@ tabs_init()
EAPI_MAIN int
elm_main(int argc, char **argv)
{
parse_config("minilauncher4slippi.cfg");
/* = win
* |
* \== bx
@ -192,8 +224,13 @@ elm_main(int argc, char **argv)
300 * elm_config_scale_get());
evas_object_show(win);
printf("[Current config] %s, %s, %s\n", game_path, dolphin_emu_file, dolphin_replay_file);
elm_run();
if (opt_mallocd >= 0) free(game_path);
if (opt_mallocd >= 1) free(dolphin_emu_file);
if (opt_mallocd >= 2) free(dolphin_replay_file);
return 0;
}
ELM_MAIN()

3
minilauncher4slippi.cfg Normal file
View File

@ -0,0 +1,3 @@
SSBM.iso
slippi-netplay-dolphin
slippi-playback-dolphin

111
scripts/slippi-install-unix.sh Executable file
View File

@ -0,0 +1,111 @@
#!/bin/sh
CMAKE_FLAGS="-DLINUX_LOCAL_DEV=true"
PLAYBACK_CODES_PATH="./Data/PlaybackGeckoCodes"
DATA_SYS_PATH="./Data/Sys"
PWD_=$(pwd)
THREADS=$(($(nproc)/2))
_ROOT="$0"
_PATH="$1"
_IS_INSTALL="$2"
_INSTALL_LOCATION="$3"
SU="sudo"
if command -v doas > /dev/null
then
SU="doas"
fi
if [ "$_IS_INSTALL" = "install" ]
then
CMAKE_FLAGS="$CMAKE_FLAGS -DINSTALLMODE=true"
#echo $CMAKE_FLAGS
#exit
fi
if [ ! "$_PATH" ]
then
echo "Please specify the path to Ishiiruka, or pass \"git\"."
exit 1
fi
if [ ! "$_INSTALL_LOCATION" ]
then
_INSTALL_LOCATION="/usr/local/bin"
fi
if [ "$_PATH" == "git" ]
then
echo "== Cloning Slippi Ishiiruka..."
git clone --recurse-submodules -j$THREADS https://github.com/project-slippi/Ishiiruka.git work > /dev/null || exit
cd work
else
cd "$_PATH"
fi
echo "NOTE: Build logs are stored in build.log"
build_slippi()
{
BUILD_DIR="$1"
CMAKE_F="$2"
NEW_BIN_NAME="$3"
GLOBAL_CFG_DIR="$4"
mkdir -p "$BUILD_DIR"; cd "$BUILD_DIR"
MSG="Error occured compiling! Check build.log"
DATE=$(date "+%Y-%m-%d %H:%M:%S")
echo ">>>>>> BEGIN BUILD LOG ON $DATE" >> "$PWD_/build.log"
echo ">>> cmake $CMAKE_F .." >> "$PWD_/build.log"
cmake $CMAKE_F .. >> "$PWD_/build.log" 2>&1 || exit 1
echo "== Building $NEW_BIN_NAME"
echo ">>> make -j$THREADS" >> "$PWD_/build.log"
make -j$THREADS >> "$PWD_/build.log" 2>&1 || exit 1
echo ">>>>>> END BUILD LOG ON $DATE" >> "$PWD_/build.log"
cd ..
# Copy the Sys folder in
if [ "$_IS_INSTALL" = "install" ]
then
rm -rf "$HOME/.config/$GLOBAL_CFG_DIR"
echo "== Installing config to \"~/.config/$GLOBAL_CFG_DIR\"..."
cp -r ${DATA_SYS_PATH} "$HOME/.config/$GLOBAL_CFG_DIR"
# ???
cp -r ${DATA_SYS_PATH} "$HOME/.config/$GLOBAL_CFG_DIR/Sys"
else
rm -rf $BUILD_DIR/Binaries/Sys
echo "== Copying config..."
cp -r ${DATA_SYS_PATH} $BUILD_DIR/Binaries
fi
touch $BUILD_DIR/Binaries/portable.txt
if [ "$NEW_BIN_NAME" ]
then
mv $BUILD_DIR/Binaries/dolphin-emu "$BUILD_DIR/Binaries/$NEW_BIN_NAME"
fi
}
#####################################################
# First build the netplay version
build_slippi "build_netplay" "$CMAKE_FLAGS" "slippi-netplay-dolphin" "SlippiOnline"
#####################################################
build_slippi "build_playback" "$CMAKE_FLAGS -DIS_PLAYBACK=true" "slippi-playback-dolphin" "SlippiPlayback"
if [ "$_IS_INSTALL" = "install" ]
then
rm -rf "$HOME/.config/SlippiPlayback/Sys/GameSettings" # Delete netplay codes
cp -r "${PLAYBACK_CODES_PATH}/." "$HOME/.config/SlippiPlayback/Sys/GameSettings"
else
rm -rf "build_playback/Binaries/Sys/GameSettings" # Delete netplay codes
cp -r "${PLAYBACK_CODES_PATH}/." "build_playback/Binaries/Sys/GameSettings"
fi
#####################################################
if [ "$_IS_INSTALL" = "install" ]
then
echo "== Installing to \"$_INSTALL_LOCATION\"..."
${SU} cp "build_netplay/Binaries/slippi-netplay-dolphin" "$_INSTALL_LOCATION"
${SU} cp "build_playback/Binaries/slippi-playback-dolphin" "$_INSTALL_LOCATION"
else
echo "Hint: run \"$_ROOT $_PATH install\" to install."
fi
cd "$PWD_"
exit 0