Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
98 lines (80 loc) · 2.98 KB
/
Copy pathapp.py
File metadata and controls
98 lines (80 loc) · 2.98 KB
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
88
89
90
91
92
93
94
95
96
97
98
from flask import Flask, jsonify, render_template, request, render_template_string
import json
import threading, webbrowser, random
import subprocess
import json
from utils.set_directories import directory_wizard
from flaskwebgui import FlaskUI
import configparser
import glob, os
import requests
from utils.filesystem import get_games, prepare_artwork
from flask_htmx import HTMX
import psutil
# Windows app icon fix (taskbar and taskbar manager)
import ctypes
myappid = u'mycompany.myproduct.subproduct.version' # arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
import logging
import sys
def logging_setup():
logger = logging.getLogger()
logger.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s | %(levelname)s | %(message)s')
stdout_handler = logging.StreamHandler(sys.stdout)
stdout_handler.setLevel(logging.INFO)
stdout_handler.setFormatter(formatter)
file_handler = logging.FileHandler('debug.log')
file_handler.setLevel(logging.INFO)
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
logger.addHandler(stdout_handler)
config = configparser.ConfigParser()
config.read('config.ini')
PCSX2_PATH = config['default']['PCSX2_PATH']
if not PCSX2_PATH:
# directory_wizard('Please navigate to the folder your PCSX2 executable is and select the .exe file', 'PCSX_PATH')
# PCSX2_PATH = config['default']['PCSX2_PATH']
pass
ROMS_FOLDER = config['default']['ROMS_FOLDER']
if not ROMS_FOLDER:
# directory_wizard('Please select the folder your ROMS are in (.iso, .bin, etc.)', 'ROMS_FOLDER')
# ROMS_FOLDER = config['default']['ROMS_FOLDER']
pass
PCSX2_FLAGS = ' --fullscreen --nogui'
def exit_app():
psutil.Process(os.getpid()).terminate()
# logging_setup()
app = Flask(__name__)
htmx = HTMX()
htmx.init_app(app)
ui = FlaskUI(app, maximized=True, idle_interval=4294966, on_exit=exit_app)
games = get_games()
prepare_artwork(games) # prepare artwork for games by copying it to the "covers" directory so that they can be served by Flask.
@app.route('/')
def index():
return render_template('index.html', games = games)
@app.get('/search')
def search():
if htmx:
query = request.args.get('query').casefold()
_games = [game for game in games if query in game['display_name'].casefold()]
return render_template('partial.games.html', games = _games)
@app.route("/api")
def me_api():
return jsonify(games)
@app.route("/run_game", methods=['POST'])
def open_project():
# get json data from request
data = request.get_json()
isoPath = data['game']
isosPath = data['games']
# print(isoPath)
# print(PCSX2_PATH + ' ' + '"' + isoPath + '"' + PCSX2_FLAGS)
subprocess.Popen(PCSX2_PATH + ' ' + '"' + isoPath + '"' + PCSX2_FLAGS)
return render_template('index.html', games = games)
if '__main__' == __name__:
# app.run(debug=True)
# PRODUCTION ONLY ---------
ui.run()
# PRODUCTION ONLY ---------