|
@@ -1,16 +1,18 @@
|
|
|
+import logging
|
|
|
import os
|
|
|
-from shlex import quote
|
|
|
-
|
|
|
from enum import Enum
|
|
|
+from shlex import quote
|
|
|
|
|
|
from django.conf import settings
|
|
|
from django.core.validators import MaxValueValidator, MinValueValidator
|
|
|
from django.db import models
|
|
|
from django.urls import reverse
|
|
|
-from django_extensions.db.models import TimeStampedModel
|
|
|
from django_extensions.db.fields import AutoSlugField
|
|
|
+from django_extensions.db.models import TimeStampedModel
|
|
|
from emus.utils import ChoiceEnum
|
|
|
|
|
|
+logger = logging.getLogger(__name__)
|
|
|
+
|
|
|
|
|
|
def get_screenshot_upload_path(instance, filename):
|
|
|
return f"{instance.game_system.retropie_slug}/screenshots/{filename}"
|
|
@@ -64,6 +66,7 @@ class StatisticsMixin(models.Model):
|
|
|
return int(100 * avg)
|
|
|
return 0
|
|
|
|
|
|
+
|
|
|
class Genre(BaseModel, StatisticsMixin):
|
|
|
def get_absolute_url(self):
|
|
|
return reverse("games:genre_detail", args=[self.slug])
|
|
@@ -255,6 +258,10 @@ class Game(BaseModel):
|
|
|
if not self.rom_file:
|
|
|
return ""
|
|
|
rom_file = quote(self.rom_file.path)
|
|
|
+ if not os.path.exists(self.retroarch_core_path):
|
|
|
+ logger.info(f"Missing libretro core file at {self.retroarch_core_path}")
|
|
|
+ return f"Libretro core not found at {self.retroarch_core_path}"
|
|
|
+
|
|
|
return f"retroarch -L {self.retroarch_core_path} {rom_file} -v"
|
|
|
|
|
|
def cmd(self, platform="linux"):
|
|
@@ -268,6 +275,7 @@ class Game(BaseModel):
|
|
|
cmd = f"{emulator} --console --fullscreen --nogui {rom_file}"
|
|
|
return cmd
|
|
|
|
|
|
+
|
|
|
class GameCollection(BaseModel):
|
|
|
games = models.ManyToManyField(Game)
|
|
|
game_system = models.ForeignKey(
|
|
@@ -314,7 +322,9 @@ class GameCollection(BaseModel):
|
|
|
|
|
|
file_path = f"/tmp/custom-{self.slug}.cfg"
|
|
|
if not dryrun:
|
|
|
- file_path = os.path.join(settings.COLLECTIONS_DIR, f"custom-{self.slug}.cfg")
|
|
|
+ file_path = os.path.join(
|
|
|
+ settings.COLLECTIONS_DIR, f"custom-{self.slug}.cfg"
|
|
|
+ )
|
|
|
|
|
|
with open(file_path, "w") as outfile:
|
|
|
for game in self.games.all():
|