Add project files

This commit is contained in:
kra-mo
2022-12-26 14:38:37 +01:00
parent e90a79778c
commit f5c1012628
39 changed files with 2588 additions and 0 deletions

103
src/utils/steam_parser.py Normal file
View File

@@ -0,0 +1,103 @@
# steam_parser.py
#
# Copyright 2022 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
def steam_parser(parent_widget, action):
import os, re, time
from gi.repository import Gtk, GLib
from .create_dialog import create_dialog
from .save_cover import save_cover
schema = parent_widget.schema
steam_dir = os.path.expanduser(os.path.join(schema.get_string("steam-location")))
def steam_not_found():
filechooser = Gtk.FileDialog.new()
def set_steam_dir(source, result, _):
try:
schema.set_string("steam-location", filechooser.select_folder_finish(result).get_path())
steam_dir = steam_dir = os.path.join(schema.get_string("steam-location"))
action(None, None)
except GLib.GError:
return
def choose_folder(widget):
filechooser.select_folder(parent_widget, None, None, set_steam_dir, None)
def response(widget, response):
if response == "choose_folder":
choose_folder(widget)
create_dialog(parent_widget, _("Couldn't Import Games"), _("Steam directory cannot be found."), "choose_folder", _("Set Steam Location")).connect("response", response)
if os.path.exists(os.path.join(steam_dir, "steamapps")) == True:
pass
elif os.path.exists(os.path.join(steam_dir, "steam", "steamapps")) == True:
schema.set_string("steam-location", os.path.join(steam_dir, "steam"))
elif os.path.exists(os.path.join(steam_dir, "Steam", "steamapps")) == True:
schema.set_string("steam-location", os.path.join(steam_dir, "Steam"))
else:
steam_not_found()
return {}
steam_dir = os.path.join(schema.get_string("steam-location"))
appmanifests = []
datatypes = ["appid", "name"]
steam_games = {}
current_time = int(time.time())
for file in os.listdir(os.path.join(steam_dir, "steamapps")):
path = os.path.join(steam_dir, "steamapps", file)
if os.path.isfile(path) and "appmanifest" in file:
appmanifests.append(path)
for appmanifest in appmanifests:
values = {}
file = open(appmanifest, "r")
data = file.read()
file.close()
for datatype in datatypes:
value = re.findall("\"" + datatype + "\"\t\t\"(.*)\"\n", data)
values [datatype] = value[0]
values["game_id"] = "steam_" + values["appid"]
if values["game_id"] in parent_widget.games and "removed" not in parent_widget.games[values["game_id"]].keys():
continue
values["executable"] = "xdg-open steam://rungameid/" + values["appid"]
values["hidden"] = False
values["source"] = "steam"
values["added"] = current_time
values["last_played"] = 0
if os.path.isfile(os.path.join(steam_dir, "appcache", "librarycache", values["appid"] + "_library_600x900.jpg")) == True:
values["pixbuf_options"] = save_cover(values, parent_widget, os.path.join(steam_dir, "appcache", "librarycache", values["appid"] + "_library_600x900.jpg"))
steam_games[values["game_id"]] = values
if len(steam_games) == 0:
create_dialog(parent_widget, _("No Games Found"), _("No new games found in Steam library."))
elif len(steam_games) == 1:
create_dialog(parent_widget, _("Steam Games Imported"), _("Successfully imported 1 game."))
elif len(steam_games) > 1:
create_dialog(parent_widget, _("Steam Games Imported"), _("Successfully imported ") + str(len(steam_games)) + _(" games."))
return steam_games