Cleanups
This commit is contained in:
11
src/main.py
11
src/main.py
@@ -28,6 +28,7 @@ from .window import CartridgesWindow
|
||||
from .preferences import PreferencesWindow
|
||||
from .toggle_hidden import toggle_hidden
|
||||
from .save_games import save_games
|
||||
from .get_games import get_games
|
||||
from .run_command import run_command
|
||||
from .steam_parser import steam_parser
|
||||
from .heroic_parser import heroic_parser
|
||||
@@ -116,9 +117,8 @@ class CartridgesApplication(Adw.Application):
|
||||
# Launch the game and update the last played value
|
||||
|
||||
game_id = self.win.active_game_id
|
||||
open_file = open(os.path.join(os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "games", game_id + ".json")), "r")
|
||||
data = json.loads(open_file.read())
|
||||
open_file.close()
|
||||
|
||||
data = get_games([game_id])[game_id]
|
||||
data["last_played"] = int(time.time())
|
||||
save_games({game_id : data})
|
||||
|
||||
@@ -145,9 +145,8 @@ class CartridgesApplication(Adw.Application):
|
||||
|
||||
# Add "removed=True" to the game properties so it can be deleted on next init
|
||||
game_id = self.win.active_game_id
|
||||
open_file = open(os.path.join(os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "games", game_id + ".json")), "r")
|
||||
data = json.loads(open_file.read())
|
||||
open_file.close()
|
||||
|
||||
data = get_games([game_id])[game_id]
|
||||
data["removed"] = True
|
||||
save_games({game_id : data})
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
def get_games():
|
||||
def get_games(game_ids=None):
|
||||
import os, json
|
||||
|
||||
games_dir = os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "games")
|
||||
@@ -26,7 +26,14 @@ def get_games():
|
||||
if os.path.exists(games_dir) == False:
|
||||
return {}
|
||||
|
||||
for game in os.listdir(games_dir):
|
||||
if not game_ids:
|
||||
game_files = os.listdir(games_dir)
|
||||
else:
|
||||
game_files = []
|
||||
for game_id in game_ids:
|
||||
game_files.append(game_id + ".json")
|
||||
|
||||
for game in game_files:
|
||||
open_file = open(os.path.join(games_dir, game), "r")
|
||||
data = json.loads(open_file.read())
|
||||
open_file.close()
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
def save_games(games):
|
||||
import os, json
|
||||
|
||||
games_dir = os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "games")
|
||||
existing = []
|
||||
|
||||
|
||||
@@ -385,9 +385,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
game_id = list(self.toasts)[-1]
|
||||
except IndexError:
|
||||
return
|
||||
open_file = open(os.path.join(os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "games", game_id + ".json")), "r")
|
||||
data = json.loads(open_file.read())
|
||||
open_file.close()
|
||||
data = get_games([game_id])[game_id]
|
||||
data.pop("removed")
|
||||
save_games({game_id : data})
|
||||
self.update_games([game_id])
|
||||
|
||||
Reference in New Issue
Block a user