Cleanup: Remove backwards-compatible code
Since we aren't interested in backwards compatibility this early in development, let's remove those code chunks to keep the code shorter.
This commit is contained in:
@@ -30,7 +30,6 @@ cartridges_sources = [
|
|||||||
'utils/get_cover.py',
|
'utils/get_cover.py',
|
||||||
'utils/save_games.py',
|
'utils/save_games.py',
|
||||||
'utils/save_cover.py',
|
'utils/save_cover.py',
|
||||||
'utils/game_data_to_json.py',
|
|
||||||
'utils/toggle_hidden.py',
|
'utils/toggle_hidden.py',
|
||||||
'utils/create_dialog.py',
|
'utils/create_dialog.py',
|
||||||
'utils/create_details_window.py'
|
'utils/create_details_window.py'
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
# game_data_to_json.py
|
|
||||||
#
|
|
||||||
# Copyright 2022-2023 kramo
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
def game_data_to_json(data):
|
|
||||||
return json.dumps(data, indent=4, sort_keys=True)
|
|
||||||
@@ -19,9 +19,6 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import shlex
|
|
||||||
|
|
||||||
from .game_data_to_json import game_data_to_json
|
|
||||||
|
|
||||||
|
|
||||||
def get_games(game_ids=None):
|
def get_games(game_ids=None):
|
||||||
@@ -42,28 +39,8 @@ def get_games(game_ids=None):
|
|||||||
game_files = os.listdir(games_dir)
|
game_files = os.listdir(games_dir)
|
||||||
|
|
||||||
for game in game_files:
|
for game in game_files:
|
||||||
with open(os.path.join(games_dir, game), "r+") as open_file:
|
with open(os.path.join(games_dir, game), "r") as open_file:
|
||||||
data = json.loads(open_file.read())
|
data = json.loads(open_file.read())
|
||||||
|
|
||||||
# Convert any outdated JSON values to our newest data format.
|
|
||||||
needs_rewrite = False
|
|
||||||
if "executable" in data and isinstance(data["executable"], str):
|
|
||||||
needs_rewrite = True
|
|
||||||
try:
|
|
||||||
# Use shell parsing to determine what the individual components are.
|
|
||||||
executable_split = shlex.split(
|
|
||||||
data["executable"], comments=False, posix=True
|
|
||||||
)
|
|
||||||
except:
|
|
||||||
# Fallback: Split once at earliest space (1 part if no spaces, else 2 parts).
|
|
||||||
executable_split = data["executable"].split(" ", 1)
|
|
||||||
data["executable"] = executable_split
|
|
||||||
|
|
||||||
if needs_rewrite:
|
|
||||||
open_file.seek(0)
|
|
||||||
open_file.truncate()
|
|
||||||
open_file.write(game_data_to_json(data))
|
|
||||||
|
|
||||||
open_file.close()
|
open_file.close()
|
||||||
|
|
||||||
games[data["game_id"]] = data
|
games[data["game_id"]] = data
|
||||||
|
|||||||
@@ -26,33 +26,16 @@ from gi.repository import Gio
|
|||||||
|
|
||||||
|
|
||||||
def run_command(executable):
|
def run_command(executable):
|
||||||
use_shell = False
|
# The host environment vars are automatically passed through by Popen.
|
||||||
if not use_shell:
|
subprocess.Popen(
|
||||||
# The host environment is automatically passed through by Popen.
|
["flatpak-spawn", "--host", *executable] # Flatpak
|
||||||
subprocess.Popen(
|
if os.getenv("FLATPAK_ID") == "hu.kramo.Cartridges"
|
||||||
["flatpak-spawn", "--host", *executable] # Flatpak
|
else executable # Windows
|
||||||
if os.getenv("FLATPAK_ID") == "hu.kramo.Cartridges"
|
if os.name == "nt"
|
||||||
else executable # Windows
|
else executable, # Linux/Others
|
||||||
if os.name == "nt"
|
shell=False, # If true, the extra arguments would incorrectly be given to the shell instead.
|
||||||
else executable, # Linux/Others
|
start_new_session=True,
|
||||||
shell=False, # If true, the extra arguments would incorrectly be given to the shell instead.
|
creationflags=subprocess.CREATE_NEW_PROCESS_GROUP if os.name == "nt" else 0,
|
||||||
start_new_session=True,
|
)
|
||||||
creationflags=subprocess.CREATE_NEW_PROCESS_GROUP if os.name == "nt" else 0,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
# When launching as a shell, we must pass 1 string with the exact command
|
|
||||||
# line exactly as we would type it in a shell (with escaped arguments).
|
|
||||||
subprocess.Popen(
|
|
||||||
shlex.join(
|
|
||||||
["flatpak-spawn", "--host", *executable] # Flatpak
|
|
||||||
if os.getenv("FLATPAK_ID") == "hu.kramo.Cartridges"
|
|
||||||
else executable # Windows
|
|
||||||
if os.name == "nt"
|
|
||||||
else executable # Linux/Others
|
|
||||||
),
|
|
||||||
shell=True,
|
|
||||||
start_new_session=True,
|
|
||||||
creationflags=subprocess.CREATE_NEW_PROCESS_GROUP if os.name == "nt" else 0,
|
|
||||||
)
|
|
||||||
if Gio.Settings.new("hu.kramo.Cartridges").get_boolean("exit-after-launch"):
|
if Gio.Settings.new("hu.kramo.Cartridges").get_boolean("exit-after-launch"):
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|||||||
@@ -20,8 +20,6 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from .game_data_to_json import game_data_to_json
|
|
||||||
|
|
||||||
|
|
||||||
def save_games(games):
|
def save_games(games):
|
||||||
games_dir = os.path.join(
|
games_dir = os.path.join(
|
||||||
@@ -36,5 +34,5 @@ def save_games(games):
|
|||||||
|
|
||||||
for game in games:
|
for game in games:
|
||||||
with open(os.path.join(games_dir, f"{game}.json"), "w") as open_file:
|
with open(os.path.join(games_dir, f"{game}.json"), "w") as open_file:
|
||||||
open_file.write(game_data_to_json(games[game]))
|
open_file.write(json.dumps(games[game], indent=4, sort_keys=True))
|
||||||
open_file.close()
|
open_file.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user