Skip to content

Commit

Permalink
Save installed emulators in an ini file
Browse files Browse the repository at this point in the history
Will be useful later on to get a filtered list of installed emulators
  • Loading branch information
kleidis committed Dec 18, 2024
1 parent 710e60a commit a6dbd24
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
37 changes: 32 additions & 5 deletions configure.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import configparser
import datetime
import os
from init_instances import inst
from win32api import MessageBeep
Expand All @@ -8,12 +9,18 @@ class Configure:
def __init__(self):
self.configDir = os.path.join(os.getenv('APPDATA'), 'Troppical')
self.configFile = os.path.join(self.configDir, 'config.ini')
self.emulatorLsitFile = os.path.join(self.configDir, 'emulator.ini')
self.defaultConfig = {
'Settings': {
'launch_as_admin': 'false',
'default_install_path': os.path.join(os.environ['LOCALAPPDATA'])
}
}
self.emulatorList = {
'': {
'': ''
}
}
self.config = configparser.ConfigParser()
self.currentConfig = self.load_config()

Expand Down Expand Up @@ -45,12 +52,14 @@ def create_default_config(self):
self.config.set(section, key, str(value))
return self.config

def save_config(self):
try:
def save_config(self, emulator=False):
if emulator==True:
with open(self.emulatorLsitFile, 'w') as f:
self.config.write(f)
return
else:
with open(self.configFile, 'w') as f:
self.config.write(f)
except Exception as e:
print(f"Error saving config: {e}")

def get_setting(self, key, section='Settings'):
try:
Expand Down Expand Up @@ -83,4 +92,22 @@ def handle_settings_button_apply(self):
self.apply_settings()
inst.ui.qt_index_switcher(0)

MessageBeep(MB_OK)
MessageBeep(MB_OK)

# Emulator list

def handle_emulator_lst(self, emulator, uninstall=False):
self.config = configparser.ConfigParser()
self.config.read(self.emulatorLsitFile)

for section, values in self.emulatorList.items():
if uninstall==False:
if not self.config.has_section(emulator):
print (f"Adding section {section}")
self.config.add_section(emulator)
for key, value in values.items():
print (f"Adding key {key} with stirng {str(emulator)}")
self.config.set(emulator, "Installed", str(emulator))
else:
self.config.remove_section(emulator)
self.save_config(emulator=True)
8 changes: 8 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ def move_files(self, extractTo):

def installation_complete(self):
self.create_reg() # Create the registry values
if self.installMode == "Install":
inst.config.handle_emulator_lst(self.emulator)

installPath = self.update_reg_result()[0]
inst.bar.extractionProgressBar.setValue(100)
Expand Down Expand Up @@ -423,6 +425,12 @@ def uninstall(self):
if reply == QMessageBox.StandardButton.No:
return
else:
try:
inst.config.handle_emulator_lst(self.emulator, uninstall=True)
except Exception as e:
QMessageBox.critical(inst.ui, "Error", f"Failed to uninstall: {str(e)}")
return
return
for shortcut in [desktopShortcut, startMenuShortcut]:
if os.path.exists(shortcut):
os.remove(shortcut)
Expand Down

0 comments on commit a6dbd24

Please sign in to comment.