Merge pull request #179 from kra-mo/geoffreys-dev-branch
Improvements to game executable + better handling of corrupted log files
This commit is contained in:
@@ -47,8 +47,9 @@ class BottlesSourceIterable(SourceIterable):
|
||||
"added": added_time,
|
||||
"name": entry["name"],
|
||||
"game_id": self.source.game_id_format.format(game_id=entry["id"]),
|
||||
"executable": self.source.executable_format.format(
|
||||
bottle_name=entry["bottle"]["name"], game_name=entry["name"]
|
||||
"executable": self.source.make_executable(
|
||||
bottle_name=entry["bottle"]["name"],
|
||||
game_name=entry["name"],
|
||||
),
|
||||
}
|
||||
game = Game(values)
|
||||
|
||||
@@ -82,9 +82,7 @@ class FlatpakSourceIterable(SourceIterable):
|
||||
"added": added_time,
|
||||
"name": name,
|
||||
"game_id": self.source.game_id_format.format(game_id=flatpak_id),
|
||||
"executable": self.source.executable_format.format(
|
||||
flatpak_id=flatpak_id
|
||||
),
|
||||
"executable": self.source.make_executable(flatpak_id=flatpak_id),
|
||||
}
|
||||
game = Game(values)
|
||||
|
||||
|
||||
@@ -108,9 +108,7 @@ class SubSourceIterable(Iterable):
|
||||
"game_id": self.source.game_id_format.format(
|
||||
service=self.service, game_id=app_name
|
||||
),
|
||||
"executable": self.source.executable_format.format(
|
||||
runner=runner, app_name=app_name
|
||||
),
|
||||
"executable": self.source.make_executable(runner=runner, app_name=app_name),
|
||||
"hidden": self.source_iterable.is_hidden(app_name),
|
||||
}
|
||||
game = Game(values)
|
||||
|
||||
@@ -65,7 +65,7 @@ class ItchSourceIterable(SourceIterable):
|
||||
"source": self.source.source_id,
|
||||
"name": row[1],
|
||||
"game_id": self.source.game_id_format.format(game_id=row[0]),
|
||||
"executable": self.source.executable_format.format(cave_id=row[4]),
|
||||
"executable": self.source.make_executable(cave_id=row[4]),
|
||||
}
|
||||
additional_data = {"online_cover_url": row[3] or row[2]}
|
||||
game = Game(values)
|
||||
|
||||
@@ -28,8 +28,8 @@ from src.game import Game
|
||||
from src.importer.sources.location import Location, LocationSubPath
|
||||
from src.importer.sources.source import (
|
||||
ExecutableFormatSource,
|
||||
SourceIterationResult,
|
||||
SourceIterable,
|
||||
SourceIterationResult,
|
||||
)
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ class LegendarySourceIterable(SourceIterable):
|
||||
"source": self.source.source_id,
|
||||
"name": entry["title"],
|
||||
"game_id": self.source.game_id_format.format(game_id=app_name),
|
||||
"executable": self.source.executable_format.format(app_name=app_name),
|
||||
"executable": self.source.make_executable(app_name=app_name),
|
||||
}
|
||||
data = {}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ class LutrisSourceIterable(SourceIterable):
|
||||
"game_id": self.source.game_id_format.format(
|
||||
runner=row[3], game_id=row[0]
|
||||
),
|
||||
"executable": self.source.executable_format.format(game_id=row[0]),
|
||||
"executable": self.source.make_executable(game_id=row[0]),
|
||||
}
|
||||
game = Game(values)
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ class ExecutableFormatSource(Source):
|
||||
|
||||
def make_executable(self, *args, **kwargs) -> str:
|
||||
"""Use the executable format to"""
|
||||
return self.executable_format.format(args, kwargs)
|
||||
return self.executable_format.format(*args, **kwargs)
|
||||
|
||||
|
||||
# pylint: disable=abstract-method
|
||||
|
||||
@@ -94,7 +94,7 @@ class SteamSourceIterable(SourceIterable):
|
||||
"name": local_data["name"],
|
||||
"source": self.source.source_id,
|
||||
"game_id": self.source.game_id_format.format(game_id=appid),
|
||||
"executable": self.source.executable_format.format(game_id=appid),
|
||||
"executable": self.source.make_executable(game_id=appid),
|
||||
}
|
||||
game = Game(values)
|
||||
|
||||
|
||||
@@ -89,18 +89,24 @@ class SessionFileHandler(StreamHandler):
|
||||
|
||||
# If uncompressed, compress
|
||||
if not path.name.endswith(".xz"):
|
||||
try:
|
||||
with open(path, "r", encoding="utf-8") as original_file:
|
||||
original_data = original_file.read()
|
||||
except UnicodeDecodeError:
|
||||
# If the file is corrupted, throw it away
|
||||
path.unlink()
|
||||
return
|
||||
|
||||
# Compress the file
|
||||
compressed_path = path.with_suffix(path.suffix + ".xz")
|
||||
with (
|
||||
lzma.open(
|
||||
compressed_path,
|
||||
"wt",
|
||||
format=FORMAT_XZ,
|
||||
preset=PRESET_DEFAULT,
|
||||
encoding="utf-8",
|
||||
) as lzma_file,
|
||||
open(path, "r", encoding="utf-8") as original_file,
|
||||
):
|
||||
lzma_file.write(original_file.read())
|
||||
with lzma.open(
|
||||
compressed_path,
|
||||
"wt",
|
||||
format=FORMAT_XZ,
|
||||
preset=PRESET_DEFAULT,
|
||||
encoding="utf-8",
|
||||
) as lzma_file:
|
||||
lzma_file.write(original_data)
|
||||
path.unlink()
|
||||
path = compressed_path
|
||||
|
||||
|
||||
Reference in New Issue
Block a user