-
Notifications
You must be signed in to change notification settings - Fork 0
/
Crawler.py
90 lines (72 loc) · 3.05 KB
/
Crawler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import configparser
import os
from copy import copy
from shutil import copyfile
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
from gi.repository.GdkPixbuf import Pixbuf
from GameInfo import GameInfo
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'
print(ini_file)
cfg_file = game_path + 'dosbox.cfg'
config.read(ini_file)
exec_path = config['Gameinfo']['exec']
mount_path = game_path + "c"
if self.create_dosbox_config(mount_path, exec_path, cfg_file):
print("Config exists")
if (os.path.isfile(ini_file)):
config.read(ini_file)
if 'Gameinfo' in config:
game_name = config['Gameinfo']['name']
print("Found game:" + game_name)
if 'icon' in config['Gameinfo']:
icon_file = game_path + config['Gameinfo']['icon']
if not os.path.isfile(icon_file):
icon_file = self.assets_dir + '/default_icon.svg'
else:
icon_file = self.assets_dir + '/default_icon.svg'
exec_cmd = 'dosbox -conf "' + cfg_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
def get_exec(self, name):
for item in self.game_exec:
if item[0] == name:
print(item[0])
return item[1]