Feat/steam sync (#652)

* Fixed sync path in steam-sync.py

* Fix syntax error

* Make sync folder hidden

* Make sync folder hidden (for real now)

* Added boilr_tag parameter after talk with boilr dev

* BOILR: set branch to retro for testing purposes

* APPDATA: added Steam Sync Warning [skip ci]

* BOILR: updated Cargo.toml

* Update steam-sync.py with real time sync

* Update configurator.sh with steam syncronization

* Update retrodeck.sh with steam syncronization

---------

Co-authored-by: Lx32 <loxenfabula@gmail.com>
This commit is contained in:
XargonWan 2024-02-18 10:48:04 +01:00 committed by GitHub
parent b49828670c
commit f6f6a678b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 147 additions and 43 deletions

View file

@ -1,6 +1,7 @@
debug = false debug = false
config_version = 1 config_version = 1
blacklisted_games = [] blacklisted_games = []
boilr_tag = "retrodeck"
[steamgrid_db] [steamgrid_db]
enabled = true enabled = true

View file

@ -6,6 +6,8 @@ import shlex
import shutil import shutil
import glob import glob
import sys import sys
import time
import hashlib
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
@ -266,8 +268,13 @@ alt_command_list={
"Beetle PCE": "flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_pce_libretro.so" "Beetle PCE": "flatpak run --command=retroarch net.retrodeck.retrodeck -L /var/config/retroarch/cores/mednafen_pce_libretro.so"
} }
def create_shortcut_new(games,rdhome): exit_file="/tmp/retrodeck_steam_sync_exit"
old_games=os.listdir(rdhome+"/sync/") rdhome=""
roms_folder=""
def create_shortcut_new(games):
changes=0
old_games=os.listdir(rdhome+"/.sync/")
for game in games: for game in games:
try: try:
@ -275,8 +282,9 @@ def create_shortcut_new(games,rdhome):
old_games[i]=0 old_games[i]=0
except ValueError: except ValueError:
print(game[0]+" is a new game!") print(game[0]+" is a new game!")
changes=1
path=rdhome+"/sync/"+game[0] path=rdhome+"/.sync/"+game[0]
print("Go to path: "+path) print("Go to path: "+path)
if not os.path.exists(path): if not os.path.exists(path):
os.makedirs(path) os.makedirs(path)
@ -318,33 +326,15 @@ def create_shortcut_new(games,rdhome):
print(old_games) print(old_games)
for game in old_games: for game in old_games:
if game: if game:
shutil.rmtree(rdhome+"/sync/"+game) shutil.rmtree(rdhome+"/.sync/"+game)
changes=1
if changes:
os.system("boilr --no-ui") os.system("boilr --no-ui")
def addToSteam(): def addToSteam(systems):
print("Open RetroDECK config file: {}".format(os.path.expanduser("~/.var/app/net.retrodeck.retrodeck/config/retrodeck/retrodeck.cfg")))
fl=open(os.path.expanduser("~/.var/app/net.retrodeck.retrodeck/config/retrodeck/retrodeck.cfg"),"r")
lines=fl.readlines()
for line in lines:
if "rdhome" in line:
rdhome=line[7:-1]
elif "roms_folder" in line:
roms_folder=line[12:-1]
fl.close()
games=[] games=[]
for system in systems:
command_list_default["pico8"]=command_list_default["pico8"].replace("{GAMEDIR}",roms_folder+"/pico8")
alt_command_list["PICO-8 Splore (Standalone)"]=alt_command_list["PICO-8 Splore (Standalone)"].replace("{GAMEDIR}",roms_folder+"/pico8")
if not os.path.exists(rdhome+"/sync/"):
os.makedirs(rdhome+"/sync/")
if not os.path.exists(os.path.expanduser("~/.var/app/net.retrodeck.retrodeck/config/boilr/sync")):
os.symlink(rdhome+"/sync",os.path.expanduser("~/.var/app/net.retrodeck.retrodeck/config/boilr/sync"))
for system in os.listdir(rdhome+"/gamelists/"):
print("Start parsing system: {}".format(system)) print("Start parsing system: {}".format(system))
f=open(rdhome+"/gamelists/"+system+"/gamelist.xml","r") f=open(rdhome+"/gamelists/"+system+"/gamelist.xml","r")
@ -391,10 +381,76 @@ def addToSteam():
else: else:
games.append([name,alt_command_list[altemulator]+" '"+roms_folder+"/"+system+path[1:]+"'"]) games.append([name,alt_command_list[altemulator]+" '"+roms_folder+"/"+system+path[1:]+"'"])
print(alt_command_list[altemulator]+" '"+roms_folder+"/"+system+path[1:]+"'") print(alt_command_list[altemulator]+" '"+roms_folder+"/"+system+path[1:]+"'")
if not games==[]:
create_shortcut_new(games)
create_shortcut_new(games,rdhome) def start_config():
global rdhome
global roms_folder
global command_list_default
global alt_command_list
if os.path.isfile(exit_file):
os.remove(exit_file)
print("Open RetroDECK config file: {}".format(os.path.expanduser("~/.var/app/net.retrodeck.retrodeck/config/retrodeck/retrodeck.cfg")))
fl=open(os.path.expanduser("~/.var/app/net.retrodeck.retrodeck/config/retrodeck/retrodeck.cfg"),"r")
lines=fl.readlines()
for line in lines:
if "rdhome" in line:
rdhome=line[7:-1]
elif "roms_folder" in line:
roms_folder=line[12:-1]
fl.close()
command_list_default["pico8"]=command_list_default["pico8"].replace("{GAMEDIR}",roms_folder+"/pico8")
alt_command_list["PICO-8 Splore (Standalone)"]=alt_command_list["PICO-8 Splore (Standalone)"].replace("{GAMEDIR}",roms_folder+"/pico8")
if not os.path.exists(rdhome+"/.sync/"):
os.makedirs(rdhome+"/.sync/")
boilr_path=os.path.expanduser("~/.var/app/net.retrodeck.retrodeck/config/boilr/config.toml")
if os.path.isfile(boilr_path):
with open(boilr_path,"r") as f:
data=f.read()
data=re.sub("\"games_folder.*","games_folder = "+rdhome+"/.sync/\"",data)
with open(boilr_path,"w") as f:
f.write(data)
else:
print("Error! BoilR config not initialized.")
if __name__=="__main__": if __name__=="__main__":
addToSteam() start_config()
new_hash={}
for system in os.listdir(rdhome+"/gamelists/"):
new_hash[system]=hashlib.md5(open(rdhome+"/gamelists/"+system+"/gamelist.xml","rb").read()).hexdigest()
running=True
while running:
time.sleep(30)
systems=[]
for system in os.listdir(rdhome+"/gamelists/"):
if not system in systems:
if system in new_hash.keys():
old_hash=new_hash[system]
new_hash[system]=hashlib.md5(open(rdhome+"/gamelists/"+system+"/gamelist.xml","rb").read()).hexdigest()
if not new_hash[system] == old_hash:
print("System {} changed!".format(system))
systems.append(system)
else:
print("System {} not changed!".format(system))
else:
new_hash[system]=hashlib.md5(open(rdhome+"/gamelists/"+system+"/gamelist.xml","rb").read()).hexdigest()
print("System {} added!".format(system))
systems.append(system)
if os.path.isfile(exit_file):
running=False
os.remove(exit_file)
addToSteam(systems)
print("Finish!") print("Finish!")

View file

@ -98,6 +98,7 @@
</ul> </ul>
<p>Issues:</p> <p>Issues:</p>
<ul> <ul>
<li>!!! WARNING !!! Steam Sync is now REPLACING your Standalone BoilR links with RetroDECK's, use it at your own risk!</li>
<li>GZDOOM: the controller for player 2+ is not correctly configured</li> <li>GZDOOM: the controller for player 2+ is not correctly configured</li>
<li>quit_retrodeck function seems to not working correctly</li> <li>quit_retrodeck function seems to not working correctly</li>
<li>MAME (Standalone) paths should be fixed</li> <li>MAME (Standalone) paths should be fixed</li>

View file

@ -459,8 +459,8 @@ modules:
sources: sources:
- type: git - type: git
url: https://github.com/PhilipK/BoilR url: https://github.com/PhilipK/BoilR
commit: b33d965f227fe971fd590cb022f608521b506ef3 branch: retro
- rd-submodules/boilr/cargo-lock.json #- rd-submodules/boilr/cargo-lock.json it's in the repo now, at least on retro branch, check on main later please
# RetroArch - START # RetroArch - START
# https://github.com/flathub/org.libretro.RetroArch # https://github.com/flathub/org.libretro.RetroArch

View file

@ -184,4 +184,12 @@ fi
# Normal Startup # Normal Startup
if [[ $steam_sync == "true" ]]; then
python3 /app/libexec/steam-sync/steam-sync.py &
fi
start_retrodeck start_retrodeck
if [[ $steam_sync == "true" ]]; then
touch /tmp/retrodeck_steam_sync_exit
fi

View file

@ -1151,7 +1151,45 @@ configurator_about_retrodeck_dialog() {
} }
configurator_add_steam() { configurator_add_steam() {
python3 /app/libexec/steam-sync/steam-sync.py if [[ $(get_setting_value $rd_conf "steam_sync" retrodeck "options") == "true" ]]; then
zenity --question \
--no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
--title "RetroDECK Configurator - RetroDECK Steam Syncronization" \
--text="Steam syncronization is current enabled. Do you want to disable it?\n\nThe already added shortcut will not be removed.\n"
if [ $? == 0 ] # User clicked "Yes"
then
disable_steam_sync
else # User clicked "Cancel"
configurator_welcome_dialog
fi
else
zenity --question \
--no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
--title "RetroDECK Configurator - RetroDECK Steam Syncronization" \
--text="Steam syncronization is current disabled. Do you want to enable it?\n\nAll the games marked as favorites will be syncronized with Steam thanks to BoilR.\nRemember to restart Steam each time to see the changes.\n"
if [ $? == 0 ]
then
enable_steam_sync
else
configurator_welcome_dialog
fi
fi
}
enable_steam_sync() {
set_setting_value $rd_conf "steam_sync" "true" retrodeck "options"
zenity --icon-name=net.retrodeck.retrodeck --info --no-wrap --ok-label="OK" \
--window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
--title "RetroDECK Configurator - RetroDECK Steam Syncronization" \
--text="Steam syncronization enabled, restart RetroDECK to get effect."
configurator_welcome_dialog
}
disable_steam_sync() {
set_setting_value $rd_conf "steam_sync" "false" retrodeck "options"
touch /tmp/retrodeck_steam_sync_exit
configurator_welcome_dialog configurator_welcome_dialog
} }