Skip to content

Commit 28b4add

Browse files
authored
can now use + to exit to HBMenu
you do have to press it twice.
1 parent c86503b commit 28b4add

1 file changed

Lines changed: 55 additions & 43 deletions

File tree

manager.py

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
activeGame = ""
1313

1414

15+
class ExitToHBMenu(Exception):
16+
pass
17+
18+
1519
# modified AnsiMenu.poll_input to resume marker position.
1620
# I feel like I could have done this in a better way... but this works
1721
def poll_input(self):
@@ -26,6 +30,8 @@ def poll_input(self):
2630

2731
if keys_down & self.KEY_A:
2832
return True
33+
elif keys_down & (1 << 10):
34+
raise ExitToHBMenu
2935
elif keys_down & self.KEY_UP:
3036
if self.selected_idx > 0:
3137
self.selected_idx -= 1
@@ -52,6 +58,7 @@ def removevalue(value): # see if any option owns a value and then remove it
5258
config.remove_section(section)
5359

5460

61+
# todo: maybe move files instead of copying to speed things up. Or maybe add an option to choose.
5562
def copymod(src, dst, filelist=None, primary=True): # making this recursive is causing a lot of trouble
5663
global promptSkip
5764
global selected_mod
@@ -250,48 +257,53 @@ def natural_key(string_): # for natural sorting
250257
originalModFolder = config.get("|options|", "modFolder") # for comparisons
251258
layeredFSFolder = config.get("|options|", "layeredFSFolder")
252259

253-
while True: # todo: maybe add a way to exit to hbmenu
254-
promptSkip = 0
255-
filecount = 0
260+
try:
261+
while True:
262+
promptSkip = 0
263+
filecount = 0
256264

257-
if not os.path.isdir(modFolder):
258-
nx.utils.clear_terminal()
259-
print("Your mods folder \"" + modFolder + "\" doesn't exit\n")
260-
sys.stdout.flush()
261-
AnsiMenu(["Create it?"]).query()
262-
os.mkdir(modFolder)
263-
if (modFolder == originalModFolder) & bool(os.listdir(modFolder)):
264-
gameList = os.listdir(modFolder)
265-
gameList = sorted(gameList, key=natural_key)
266-
nx.utils.clear_terminal()
267-
sys.stdout.flush()
268-
printb(b"Generic Mod Manager" + bytes(" " * 53, "UTF-8") + b"By Seth\n\n") # Main menu
269-
makemenu(gameList, True)
270-
AnsiMenu.selected_idx = 0
271-
elif modFolder == originalModFolder:
272-
nx.utils.clear_terminal()
273-
print("Your mods folder \"" + modFolder + "\" looks empty\n"
274-
"Add some mods to it or change the folder location in " + configFile +
275-
"\n\nThe recommended folder format for mods is:\n"
276-
"\"/ModsFolder/GameName/ModName/TitleID/ModFiles\"\n\n"
277-
"For Example:\n\"/mods/Legend of Zelda/Bowser Hinox/01007EF00011E000/romfs/...\"\n")
278-
sys.stdout.flush()
279-
AnsiMenu(["try again?"]).query()
280-
elif os.listdir(modFolder):
281-
modFolderList = os.listdir(modFolder) # seems to default to time added todo: consider adding new ways to sort
282-
# data = sorted(data, key=str.lower) # alphabetical
265+
if not os.path.isdir(modFolder):
266+
nx.utils.clear_terminal()
267+
print("Your mods folder \"" + modFolder + "\" doesn't exit\n")
268+
sys.stdout.flush()
269+
AnsiMenu(["Create it?"]).query()
270+
os.mkdir(modFolder)
271+
if (modFolder == originalModFolder) & bool(os.listdir(modFolder)):
272+
gameList = os.listdir(modFolder)
273+
gameList = sorted(gameList, key=natural_key)
274+
nx.utils.clear_terminal()
275+
sys.stdout.flush()
276+
printb(b"Generic Mod Manager" + bytes(" " * 53, "UTF-8") + b"By Seth\n\n") # Main menu
277+
makemenu(gameList, True)
278+
AnsiMenu.selected_idx = 0
279+
elif modFolder == originalModFolder:
280+
nx.utils.clear_terminal()
281+
print("Your mods folder \"" + modFolder + "\" looks empty\n"
282+
"Add some mods to it or change the folder location in " + configFile +
283+
"\n\nThe recommended folder format for mods is:\n"
284+
"\"/ModsFolder/GameName/ModName/TitleID/ModFiles\"\n\n"
285+
"For Example:\n\"/mods/Legend of Zelda/Bowser Hinox/01007EF00011E000/romfs/...\"\n")
286+
sys.stdout.flush()
287+
AnsiMenu(["try again?"]).query()
288+
elif os.listdir(modFolder):
289+
modFolderList = os.listdir(modFolder) # seems to default to time added todo: consider adding new ways to sort
290+
# data = sorted(data, key=str.lower) # alphabetical
283291

284-
nx.utils.clear_terminal()
285-
sys.stdout.flush()
286-
printb(b"Generic Mod Manager"+bytes(" "*53, "UTF-8")+b"By Seth\n\n")
287-
printb(bytes(" "*(40-(len(activeGame)//2))+activeGame+"\n"[:80], "UTF-8"))
288-
# printb(b"Warning: Exiting during an operation can cause mod files to be corrupted")
289-
makemenu(modFolderList)
290-
else:
291-
nx.utils.clear_terminal()
292-
print("This game folder, \""+modFolder+"\" doesn't seem to have any mods\n"
293-
"Add some mods to it or change the folder location in "+configFile+"\n")
294-
sys.stdout.flush()
295-
selected_index = AnsiMenu(["[Main Menu]","try again?"]).query()
296-
if selected_index == 0:
297-
modFolder = originalModFolder
292+
nx.utils.clear_terminal()
293+
sys.stdout.flush()
294+
printb(b"Generic Mod Manager"+bytes(" "*53, "UTF-8")+b"By Seth\n\n")
295+
printb(bytes(" "*(40-(len(activeGame)//2))+activeGame+"\n"[:80], "UTF-8"))
296+
# printb(b"Warning: Exiting during an operation can cause mod files to be corrupted")
297+
makemenu(modFolderList)
298+
else:
299+
nx.utils.clear_terminal()
300+
print("This game folder, \""+modFolder+"\" doesn't seem to have any mods\n"
301+
"Add some mods to it or change the folder location in "+configFile+"\n")
302+
sys.stdout.flush()
303+
selected_index = AnsiMenu(["[Main Menu]", "try again?"]).query()
304+
if selected_index == 0:
305+
modFolder = originalModFolder
306+
except ExitToHBMenu:
307+
nx.utils.clear_terminal()
308+
sys.stderr.write("Press + again to exit")
309+
sys.stdout.flush()

0 commit comments

Comments
 (0)