Skip to content

Commit

Permalink
- Add default config
Browse files Browse the repository at this point in the history
- check if gamefolder is actually a folder
- add default icon if icon does not exists or is not defined
  • Loading branch information
nicktelindert committed Aug 4, 2021
1 parent 9a04d0c commit eae825d
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 26 deletions.
72 changes: 46 additions & 26 deletions Crawler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import configparser
import os
from copy import copy
from shutil import copyfile

import gi
gi.require_version("Gtk", "3.0")
Expand All @@ -13,47 +14,66 @@ class Crawler:
games_list = Gtk.ListStore(Pixbuf, str)
games_list_original = Gtk.ListStore(Pixbuf, str)
game_exec = []
base_path = ""

def __init__(self, path):
self.base_path = path
self.assets_dir = os.path.dirname(os.path.realpath(__file__)) + "/assets"

def build_list(self):
path = self.base_path
print("Found game path:" + path)
print("Search directories in " + path)
print(os.listdir(path))
config = configparser.ConfigParser()

for game in os.listdir(path):
game_path = path + '/' + game + '/';
ini_file = game_path + game + '.ini'
cfg_file = game_path + 'dosbox.cfg'
config = configparser.ConfigParser()
config.read(ini_file)
exec_path = config['Gameinfo']['exec']
if not os.path.isfile(cfg_file):
config = configparser.ConfigParser()
with open(cfg_file, 'a') as f:
f.write("[sdl]\n")
f.write("fullscreen = true\n")
f.write("fullresolution = desktop\n")
f.write("output = opengl\n\n")
f.write("[autoexec]\n")
f.write('MOUNT C ' + game_path + "data/\n")
f.write('C:\n')
f.write(exec_path)
f.close()

if (os.path.isfile(ini_file) and os.path.isfile(cfg_file)):
config = configparser.ConfigParser()
config.read(ini_file)
game_name = config['Gameinfo']['name']
print("Found game:" + game_name)
icon_file = game_path + config['Gameinfo']['icon']
exec_cmd = "dosbox -conf " + cfg_file
game_info = GameInfo(game_name, icon_file)
self.game_exec.append([game_name, exec_cmd])

self.games_list.append(game_info.get_row())
self.games_list_original.append(game_info.get_row())
mount_path = game_path + "data"

if self.create_dosbox_config(mount_path, exec_path, cfg_file):
print("Config exists")
if (os.path.isfile(ini_file)):
config.read(ini_file)
game_name = config['Gameinfo']['name']
print("Found game:" + game_name)
icon_file = game_path + config['Gameinfo']['icon']
exec_cmd = "dosbox -conf " + cfg_file
if not os.path.isfile(icon_file):
default_icon = self.assets_dir + '/default_icon.svg'
copyfile(default_icon, icon_file)
game_info = GameInfo(game_name, icon_file)

self.add_game_to_list(game_info)
self.game_exec.append([game_name, exec_cmd])

def get_list(self):
return self.games_list

def create_dosbox_config(self, mount_path, exec_path, cfg_file):
if not os.path.isfile(cfg_file) and os.path.isdir(mount_path):
template = self.assets_dir + '/dosbox.cfg'
copyfile(template, cfg_file)
config = configparser.ConfigParser()
with open(cfg_file, 'a') as f:
f.write("\n\n[autoexec]\n")
f.write('MOUNT C ' + mount_path + "\n")
f.write('C:\n')
f.write(exec_path)
f.close()

return os.path.isfile(cfg_file)


def add_game_to_list(self, game_info):
self.games_list.append(game_info.get_row())
self.games_list_original.append(game_info.get_row())


def get_original_list(self):
return self.games_list_original

Expand Down
3 changes: 3 additions & 0 deletions assets/default_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions assets/dosbox.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[sdl]
fullscreen = true
fullresolution = desktop
output = opengl

[mixer]
nosound=false

[midi]
mpu401=intelligent
mididevice=default

[sblaster]
sbtype=sb16
sbbase=220
irq=7
dma=1
hdma=5
sbmixer=true
oplmode=auto
oplemu=default
oplrate=44100
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def main(self):
win = builder.get_object("mainWindow")
btn_quit = builder.get_object("btn_quit")
self.crawler = Crawler(games_path)
self.crawler.build_list()
self.games_list = self.crawler.get_list()
builder.connect_signals(Handler(Crawler))
icon_list = builder.get_object("game_icons")
Expand Down

0 comments on commit eae825d

Please sign in to comment.