Initial commit
This commit is contained in:
137
configfile.py
Normal file
137
configfile.py
Normal file
@@ -0,0 +1,137 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
|
||||
from appdirs import user_data_dir
|
||||
from configobj import ConfigObj, flatten_errors, Section
|
||||
from validate import Validator
|
||||
|
||||
from exclude import MAME_EXCLUDE
|
||||
from utils import get_pygame_keydict, get_keys
|
||||
|
||||
CFG = '''ResolutionX = integer(default=1024)
|
||||
ResolutionY = integer(default=768)
|
||||
FullScreen = boolean(default=False)
|
||||
Font = string(default='microsoftsansserif')
|
||||
FontSize = integer(default=13)
|
||||
QuitKeyPresses = integer(min=1,default=3)
|
||||
ScanLines = boolean(default=True)
|
||||
Key_Up = list(default=list('K_UP'))
|
||||
Key_Down = list(default=list('K_DOWN'))
|
||||
Key_PgUp = list(default=list('K_LEFT','K_PAGEUP'))
|
||||
Key_PgDn = list(default=list('K_RIGHT','K_PAGEDOWN'))
|
||||
Key_Home = list(default=list('K_HOME'))
|
||||
Key_End = list(default=list('K_END'))
|
||||
Key_Select = list(default=list('K_RETURN','K_1'))
|
||||
Key_GameInfo = list(default=list('K_5'))
|
||||
Key_GameHistory = list(default=list('K_6'))
|
||||
Key_Popup = list(default=list('K_2'))
|
||||
Key_ShowArtwork = list(default=list())
|
||||
AlwaysChangeSnap = boolean(default=True)
|
||||
HideMature = boolean(default=True)
|
||||
Emulator = string()
|
||||
[__many__]
|
||||
EXE = string()
|
||||
Version = string(default=None)
|
||||
ShowClones = boolean(default=True)
|
||||
Category = string(default='All Games')
|
||||
GameAtTop = integer(min=0,default=0)
|
||||
CurrentGame = integer(min=0,default=0)
|
||||
EmulatorType = option('MAME','MESS','CSV',default='MAME')
|
||||
StatusFilter = list(default=list())
|
||||
Sort = option('Name Asc','Name Dec','Year Asc','Year Dec',default='Name Asc')
|
||||
SnapDir = string(default=None)
|
||||
CSVFile = string(default=None)
|
||||
ArtworkDirs = list(default=list())
|
||||
'''
|
||||
|
||||
appname = 'MFE'
|
||||
appauthor = 'RMJ'
|
||||
|
||||
datadir = user_data_dir(appname, appauthor)
|
||||
datadir = os.getcwd()
|
||||
|
||||
if not os.path.isdir(datadir):
|
||||
os.makedirs(datadir)
|
||||
|
||||
spec = CFG.split('\n')
|
||||
cfg = ConfigObj(
|
||||
os.path.join(datadir, 'mfe.ini'), configspec=spec, encoding='UTF8')
|
||||
|
||||
validator = Validator()
|
||||
result = cfg.validate(validator, copy=True, preserve_errors=True)
|
||||
|
||||
stop = False
|
||||
for entry in flatten_errors(cfg, result):
|
||||
section_list, key, error = entry
|
||||
if key is not None:
|
||||
section_list.append(key)
|
||||
else:
|
||||
section_list.append('[missing section]')
|
||||
section_string = ', '.join(section_list)
|
||||
if error is False:
|
||||
error = 'Missing value or section.'
|
||||
print(section_string, ' = ', error)
|
||||
stop = True
|
||||
|
||||
cfg.write()
|
||||
|
||||
if stop:
|
||||
exit()
|
||||
|
||||
cfg["datadir"] = datadir
|
||||
|
||||
if not os.path.isfile(os.path.join(datadir, 'mame_exclude.txt')):
|
||||
with open(os.path.join(datadir, "mame_exclude.txt"), "wt") as f:
|
||||
f.write(MAME_EXCLUDE)
|
||||
|
||||
keys = get_pygame_keydict()
|
||||
cfg['KeyUp'] = get_keys(keys, cfg['Key_Up'])
|
||||
cfg['KeyDown'] = get_keys(keys, cfg['Key_Down'])
|
||||
cfg['KeyPgUp'] = get_keys(keys, cfg['Key_PgUp'])
|
||||
cfg['KeyPgDn'] = get_keys(keys, cfg['Key_PgDn'])
|
||||
cfg['KeyHome'] = get_keys(keys, cfg['Key_Home'])
|
||||
cfg['KeyEnd'] = get_keys(keys, cfg['Key_End'])
|
||||
cfg['KeySelect'] = get_keys(keys, cfg['Key_Select'])
|
||||
cfg['KeyGameInfo'] = get_keys(keys, cfg['Key_GameInfo'])
|
||||
cfg['KeyGameHistory'] = get_keys(keys, cfg['Key_GameHistory'])
|
||||
cfg['KeyPopup'] = get_keys(keys, cfg['Key_Popup'])
|
||||
cfg['KeyShowArtwork'] = get_keys(keys, cfg['Key_ShowArtwork'])
|
||||
|
||||
|
||||
def config_write():
|
||||
Exclude = [
|
||||
'KeyUp', 'KeyDown', 'KeyPgUp', 'KeyPgDn', 'KeySelect', 'KeyGameInfo',
|
||||
'KeyGameHistory', 'KeyPopup', 'KeyHome', 'KeyEnd', 'KeyShowArtwork',
|
||||
'datadir'
|
||||
]
|
||||
|
||||
t = {}
|
||||
for item in Exclude:
|
||||
t[item] = cfg[item]
|
||||
del cfg[item]
|
||||
|
||||
cfg.write()
|
||||
|
||||
for item in t:
|
||||
cfg[item] = t[item]
|
||||
|
||||
|
||||
def get_emu(option=None):
|
||||
if option:
|
||||
r = cfg[cfg['Emulator']][option]
|
||||
else:
|
||||
r = cfg[cfg['Emulator']]
|
||||
return r
|
||||
|
||||
|
||||
def set_emu(option, data):
|
||||
cfg[cfg['Emulator']][option] = data
|
||||
|
||||
|
||||
def get_emulators():
|
||||
r = []
|
||||
for k in cfg.keys():
|
||||
if isinstance(cfg[k], Section):
|
||||
r.append(k)
|
||||
return r
|
||||
Reference in New Issue
Block a user