Skip to content

Commit

Permalink
Make input/output folder args required only in non-GUI mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jose-l-martins committed Dec 5, 2024
1 parent 3cbf654 commit 43e3fce
Showing 1 changed file with 35 additions and 21 deletions.
56 changes: 35 additions & 21 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,23 @@ def process_gsm_folder(input_folder_path: str, output_folder_path: str, progress
all_gsm_gsba_files = glob.glob(os.path.join(input_folder_path, '*.gsba'))
logging.info(f'Processing GSM/.gsba files: {all_gsm_gsba_files}')

progress_info_label['text'] = "Starting to process..."

processing_error_flag = False

if progress_bar:
progress_bar['maximum'] = len(all_gsm_gsba_files)
progress_info_label['text'] = "Starting to process..."

#Restart counter, if "Process Backups" button is pressed again
warning_info_label['text'] = ""
i=0
progress_bar['value'] = 0
progress_label['text'] = f"0% (0/{progress_bar['maximum']})"
#Restart counter, every time "Process Backups" button is pressed again
warning_info_label['text'] = ""
i=0
progress_bar['value'] = 0
progress_label['text'] = f"0% (0/{progress_bar['maximum']})"

previous_backup_processed = None

for i, gsm_gsba_file in enumerate(all_gsm_gsba_files):
if previous_backup_processed:
if progress_bar and previous_backup_processed:
progress_info_label['text'] = f"Finished processing: {previous_backup_processed}\n Now processing: {os.path.basename(gsm_gsba_file)}"

if stop_thread and stop_thread.is_set():
Expand Down Expand Up @@ -182,9 +183,7 @@ def process_gsm_folder(input_folder_path: str, output_folder_path: str, progress


def process_ludusavi_folder(input_folder_path: str, output_folder_path: str, progress_bar=None, stop_thread=None):

progress_info_label['text'] = "Starting to process..."


processing_error_flag = False

# Detect Ludusavi folders, which are folders that have a 'mapping.yaml' file in them
Expand All @@ -200,17 +199,20 @@ def process_ludusavi_folder(input_folder_path: str, output_folder_path: str, pro

if progress_bar:
progress_bar['maximum'] = len(ludusavi_folders)
registry_yaml = None
progress_info_label['text'] = "Starting to process..."
#Restart counter, every time "Process Backups" button is pressed again
warning_info_label['text'] = ""
i=0
progress_bar['value'] = 0
progress_label['text'] = f"0% (0/{progress_bar['maximum']})"

#Restart counter, if "Process Backups" button is pressed again
warning_info_label['text'] = ""
i=0
progress_bar['value'] = 0
progress_label['text'] = f"0% (0/{progress_bar['maximum']})"
previous_backup_processed = None


registry_yaml = None

for i, ludusavi_folder in enumerate(ludusavi_folders):
if previous_backup_processed:
if progress_bar and previous_backup_processed:
progress_info_label['text'] = f"Finished processing: {previous_backup_processed}\n Now processing: {os.path.basename(ludusavi_folder)}"

if stop_thread and stop_thread.is_set():
Expand Down Expand Up @@ -341,13 +343,25 @@ def process_ludusavi_folder(input_folder_path: str, output_folder_path: str, pro

def main():
parser = argparse.ArgumentParser(description='Process GameSave Manager backup files and generate Ludusavi mappings.')

# Create mutually exclusive group for --gui
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--gui', action='store_true', help='Launch the GUI')
group.add_argument('--no-gui', action='store_true', help='Run in command-line mode')

# Add arguments for input and output folder paths
parser.add_argument('--input_folder_path', type=str, help='Path to the folder containing backup files to convert (GSM/.gsba)')
parser.add_argument('--output_folder_path', type=str, help='Path to the output folder where the converted backup folders/files are saved (Ludusavi games backups folders)')
parser.add_argument('--backup_type', type=str, choices=['gsba', 'ludusavi'], help='Type of backup to process. Accepts either "gsba" or "ludusavi"')
parser.add_argument('--backup_type', type=str, choices=['gsba_to_ludusavi', 'ludusavi_to_gsba'], help='Type of backup to process. Accepts either "gsba" or "ludusavi"')
parser.add_argument('--verbose', action='store_true', help='If set, log messages will also be printed to the console')
parser.add_argument('--gui', action='store_true', help='Launch the GUI')

args = parser.parse_args()

# Check if --gui is not set, then input and output folder paths are required
if not args.gui:
if not args.input_folder_path or not args.output_folder_path:
parser.error("--input_folder_path and --output_folder_path are required when not using --gui")

# Configure logging
logging.basicConfig(filename='app.log', filemode='w', format='%(name)s - %(levelname)s - %(message)s', level=logging.DEBUG)

Expand All @@ -364,9 +378,9 @@ def main():
launch_gui()
else:
try:
if args.backup_type == 'gsba':
if args.backup_type == 'gsba_to_ludusavi':
process_gsm_folder(args.input_folder_path, args.output_folder_path)
elif args.backup_type == 'ludusavi':
elif args.backup_type == 'ludusavi_to_gsba':
process_ludusavi_folder(args.input_folder_path, args.output_folder_path)
except Exception as e:
logging.error(f"Error in main: {e}")
Expand Down

0 comments on commit 43e3fce

Please sign in to comment.