Skip to content

Commit

Permalink
Merge branch 'main' into fix-glo-netplay
Browse files Browse the repository at this point in the history
  • Loading branch information
Aemiii91 authored Jul 4, 2023
2 parents 12e635f + 825d630 commit b96ba12
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 186 deletions.
16 changes: 16 additions & 0 deletions files/20230617/New-MiyooGameListXml.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[xml]$xml = Get-Content 'gamelist.xml'

$nodesToDelete = @('desc', 'rating', 'genre', 'players', 'releasedate', 'developer', 'publisher', 'hash', 'thumbnail', 'genreid')

foreach ($node in $nodesToDelete) {
$xml.SelectNodes("//$node") | ForEach-Object { $_.ParentNode.RemoveChild($_) }
}

$gamesWithoutImage = $xml.SelectNodes("//game[not(image)]")
foreach ($game in $gamesWithoutImage) {
$newImage = $xml.CreateElement('image')
$newImage.InnerText = 'no-img.png'
$game.AppendChild($newImage)
}

$xml.OuterXml | Set-Content 'miyoogamelist.xml'
27 changes: 27 additions & 0 deletions files/20230617/New-MiyooGameListXmlFormatted.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[xml]$xml = Get-Content 'gamelist.xml'

$nodesToDelete = @('desc', 'rating', 'genre', 'players', 'releasedate', 'developer', 'publisher', 'hash', 'thumbnail', 'genreid')

foreach ($node in $nodesToDelete) {
$xml.SelectNodes("//$node") | ForEach-Object { $_.ParentNode.RemoveChild($_) }
}

$gamesWithoutImage = $xml.SelectNodes("//game[not(image)]")
foreach ($game in $gamesWithoutImage) {
$newImage = $xml.CreateElement('image')
$newImage.InnerText = 'no-img.png'
$game.AppendChild($newImage)
}

# Create an XmlWriterSettings object with the proper settings
$settings = New-Object System.Xml.XmlWriterSettings
$settings.Indent = $true
$settings.IndentChars = " "
$settings.NewLineChars = "`r`n"
$settings.NewLineHandling = [System.Xml.NewLineHandling]::Replace

# Create an XmlWriter with the settings and write the XML to it
$writer = [System.Xml.XmlWriter]::Create('miyoogamelist.xml', $settings)
$xml.WriteTo($writer)
$writer.Flush()
$writer.Close()
28 changes: 19 additions & 9 deletions src/common/components/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <string.h>
#include <strings.h>

#include "utils/log.h"
#include "utils/str.h"

#define MAX_NUM_VALUES 100
Expand Down Expand Up @@ -133,14 +134,17 @@ ListItem *list_currentItem(List *list)
return &list->items[list->active_pos];
}

void list_scroll(List *list)
void _list_scroll(List *list, int pos)
{
pos = _list_modulo(pos, list->item_count);
printf_debug("scroll to active: %d\n", pos);

// Scroll up
if (list->active_pos < list->scroll_pos)
list->scroll_pos = list->active_pos;
if (pos < list->scroll_pos)
list->scroll_pos = pos;
// Scroll down
else if (list->active_pos >= list->scroll_pos + list->scroll_height)
list->scroll_pos = list->active_pos - list->scroll_height + 1;
else if (pos >= list->scroll_pos + list->scroll_height)
list->scroll_pos = pos - list->scroll_height + 1;

// No scrolling if not enough items
if (list->item_count <= list->scroll_height)
Expand All @@ -150,6 +154,11 @@ void list_scroll(List *list)
list->scroll_pos = list->item_count - list->scroll_height;
}

void list_scroll(List *list)
{
_list_scroll(list, list->active_pos);
}

bool list_scrollTo(List *list, int active_pos)
{
list->active_pos = _list_modulo(active_pos, list->item_count);
Expand All @@ -176,11 +185,11 @@ bool list_keyUp(List *list, bool key_repeat)

if (_list_did_wraparound(old_pos, list->active_pos, -1)) {
if (list->scroll_pos > 0) {
list->scroll_pos -= 1;
_list_scroll(list, list->scroll_pos - 1);
list->active_pos = old_pos;
}
else {
list->scroll_pos = list->item_count - list->scroll_height;
_list_scroll(list, list->item_count - 1);
}
}
else {
Expand All @@ -207,12 +216,13 @@ bool list_keyDown(List *list, bool key_repeat)
list_ensureVisible(list, 1);

if (_list_did_wraparound(old_pos, list->active_pos, 1)) {
printf_debug("scroll_pos: %d < item_count: %d - scroll_height: %d\n", list->scroll_pos, list->item_count, list->scroll_height);
if (list->scroll_pos < list->item_count - list->scroll_height) {
list->scroll_pos += 1;
_list_scroll(list, list->scroll_pos + list->scroll_height);
list->active_pos = old_pos;
}
else {
list->scroll_pos = 0;
_list_scroll(list, 0);
}
}
else {
Expand Down
2 changes: 1 addition & 1 deletion src/keymon/keymon.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ int main(void)
power_pressed = true;
if (!comboKey_menu && val == REPEAT) {
repeat_power++;
if (repeat_power == 7 && !settings.disable_standby) {
if (repeat_power == 7) {
deepsleep(); // 0.5sec deepsleep
}
else if (repeat_power >= REPEAT_SEC(5)) {
Expand Down
5 changes: 2 additions & 3 deletions src/tweaks/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void network_setSshAuthState(void *pt)

void network_wpsConnect(void *pt)
{
system("sh /mnt/SDCARD/.tmp_update/script/wpsclient.sh");
system("sh " NET_SCRIPT_PATH "/wpsclient.sh");
}

void network_setTzSelectState(void *pt)
Expand All @@ -161,9 +161,8 @@ void network_setTzSelectState(void *pt)

setenv("TZ", utc_str, 1);
tzset();
config_setString(".tz", utc_str);

temp_flag_set("timezone_update", true);
config_setString(".tz", utc_str);
sync();
}

Expand Down
35 changes: 10 additions & 25 deletions static/build/.tmp_update/runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ main() {

# Auto launch
if [ ! -f $sysdir/config/.noAutoStart ]; then
state_change
check_game
state_change check_game
else
rm -f "$sysdir/cmd_to_run.sh" 2> /dev/null
fi
Expand All @@ -99,33 +98,24 @@ main() {
touch /tmp/run_advmenu
fi

state_change
check_switcher
state_change check_switcher
set_startup_tab

# Main runtime loop
while true; do
state_change
check_main_ui

check_networking

state_change
check_game_menu

state_change
check_game

check_networking

state_change
check_switcher
state_change check_main_ui
state_change check_game_menu
state_change check_game
state_change check_switcher
done
}

state_change() {
runifnecessary "keymon" keymon
check_networking
touch /tmp/state_changed
sync
eval "$1"
}

clear_logs() {
Expand Down Expand Up @@ -551,13 +541,11 @@ runifnecessary() {
done
}


start_networking() {
rm $sysdir/config/.hotspotState # dont start hotspot at boot

touch /tmp/network_changed
sync
check_networking
}

check_networking() {
Expand All @@ -573,10 +561,7 @@ check_networking() {
}

check_timezone() {
if [ -f /tmp/timezone_update ]; then
export TZ=$(cat "$sysdir/config/.tz")
rm /tmp/timezone_update
fi
export TZ=$(cat "$sysdir/config/.tz")
}

main
30 changes: 24 additions & 6 deletions static/build/.tmp_update/script/network/update_networking.sh
Original file line number Diff line number Diff line change
Expand Up @@ -367,32 +367,41 @@ check_hotspotstate() {
else
start_hotspot &
fi
fi
fi
}

# This is the fallback!
# We need to check if NTP is enabled and then check the state of tzselect in /.tmp_update/config/tzselect, based on the value we'll pass the TZ via the env var to ntpd and get the time (has to be POSIX)
# This will work but it will not export the TZ var across all opens shells so you may find the hwclock (and clock app, retroarch time etc) are correct but terminal time is not.
# It does set TZ on the tty that Main is running in so this is ok

sync_time() { # Run a sync at startup once, but only if we have internet
if [ -f "$sysdir/config/.ntpState" ]; then
sync_time() {
if [ -f "$sysdir/config/.ntpState" ] && wifi_enabled; then
attempts=0
max_attempts=20

while true; do
if [ ! -f "/tmp/ntp_run_once" ]; then
break
fi

if ping -q -c 1 google.com > /dev/null 2>&1 ; then
get_time
rm /tmp/ntp_run_once
break
fi
sleep 0.5

attempts=$((attempts+1))
if [ $attempts -eq $max_attempts ]; then
log "NTPwait: Ran out of time before we could sync, stopping."
break
fi
sleep 1
done
rm /tmp/ntp_run_once
fi
}

check_ntpstate() { # This function checks if the timezone has changed, we call this in the main loop.
check_ntpstate() { # This function checks if the timezone has changed, we call this in the main loop.
if flag_enabled ntpState && wifi_enabled && [ ! -f "$sysdir/config/.hotspotState" ] ; then
current_tz=$(check_tzid)
get_time
Expand Down Expand Up @@ -449,16 +458,25 @@ print_usage() {

get_time() { # handles 2 types of NTP, instant from an API or longer from a time server, if the instant API check fails it will fallback to the longer ntp
response=$(curl -s http://worldtimeapi.org/api/ip.txt | grep -o 'utc_datetime: [^,]*' | cut -d ' ' -f 2)

if [ -z "$response" ]; then
log "NTP: Failed to get time from worldtimeapi.org, falling back to NTP."
ntpdate -u time.google.com

if [ $? -ne 0 ]; then
log "NTP: Failed to synchronize time using NTPdate, both methods have failed."
fi
else
utc_time=$(echo "$response" | cut -d. -f1 | sed "s/T/ /")
if date -u -s "$utc_time" >/dev/null 2>&1; then
hwclock -w
else
log "NTP: Failed to parse time from worldtimeapi.org, falling back to NTP."
ntpdate -u time.google.com

if [ $? -ne 0 ]; then
log "NTP: Failed to synchronize time using NTPdate, both methods have failed."
fi
fi
fi
}
Expand Down
Loading

0 comments on commit b96ba12

Please sign in to comment.