Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create app.py #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import os
import tkinter as tk
from tkinter import filedialog, messagebox
import subprocess

# Function to run UnrealPak commands and display the output
def run_unrealpak_command(command):
pak_filename = pak_file_entry.get()
unrealpak_path = unrealpak_entry.get()
output_dir = output_dir_entry.get()

# Ensure the user selects the UnrealPak.exe
if not unrealpak_path:
messagebox.showerror("Error", "Please select UnrealPak.exe")
return

# Ensure the user selects a Pak file
if not pak_filename:
messagebox.showerror("Error", "Please select a Pak file")
return

# If the command is -Extract, the output directory must be provided
if command == "-Extract" and not output_dir:
messagebox.showerror("Error", "Please select an output directory for extraction")
return

# Form the command with or without output directory depending on the command
if command == "-Extract":
full_command = f'"{unrealpak_path}" "{pak_filename}" {command} "{output_dir}"'
else:
full_command = f'"{unrealpak_path}" "{pak_filename}" {command}'

try:
# Execute the command and capture the output
result = subprocess.run(full_command, capture_output=True, text=True, shell=True)
output_text.delete(1.0, tk.END) # Clear previous output
output_text.insert(tk.END, result.stdout) # Display output
if result.stderr:
output_text.insert(tk.END, "\n[Error]:\n" + result.stderr)
except Exception as e:
messagebox.showerror("Error", f"An error occurred while executing the command: {str(e)}")

# Function to choose the Pak file
def choose_pak_file():
file_path = filedialog.askopenfilename(filetypes=[("Pak Files", "*.pak")])
pak_file_entry.delete(0, tk.END)
pak_file_entry.insert(0, file_path)

# Function to choose the output directory
def choose_output_dir():
folder_path = filedialog.askdirectory()
output_dir_entry.delete(0, tk.END)
output_dir_entry.insert(0, folder_path)

# Function to choose the UnrealPak.exe
def choose_unrealpak():
file_path = filedialog.askopenfilename(filetypes=[("Executable Files", "*.exe")])
unrealpak_entry.delete(0, tk.END)
unrealpak_entry.insert(0, file_path)

# Main GUI setup
root = tk.Tk()
root.title("UnrealPak Tool")
root.geometry("600x700")

# Title label
title_label = tk.Label(root, text="UnrealPak Tool", font=("Arial", 16))
title_label.pack(pady=10)

# UnrealPak.exe selection
unrealpak_label = tk.Label(root, text="Select UnrealPak.exe:")
unrealpak_label.pack()
unrealpak_entry = tk.Entry(root, width=50)
unrealpak_entry.pack(pady=5)
choose_unrealpak_button = tk.Button(root, text="Choose UnrealPak.exe", command=choose_unrealpak)
choose_unrealpak_button.pack(pady=5)

# Pak file selection
pak_file_label = tk.Label(root, text="Select Pak file:")
pak_file_label.pack()
pak_file_entry = tk.Entry(root, width=50)
pak_file_entry.pack(pady=5)
choose_pak_button = tk.Button(root, text="Choose Pak File", command=choose_pak_file)
choose_pak_button.pack(pady=5)

# Output directory selection (for -Extract)
output_dir_label = tk.Label(root, text="Select output directory (only for -Extract):")
output_dir_label.pack()
output_dir_entry = tk.Entry(root, width=50)
output_dir_entry.pack(pady=5)
choose_output_button = tk.Button(root, text="Choose Output Directory", command=choose_output_dir)
choose_output_button.pack(pady=5)

# Commands list
commands = [
"-Test",
"-List",
"-List -ExcludeDeleted",
"-Extract",
"-Create",
"-Repack",
"-diff",
"-AuditFiles",
"-WhatsAtOffset",
"-GeneratePIXMappingFile",
]

# Display commands as buttons
for command in commands:
button = tk.Button(root, text=command, width=40, command=lambda cmd=command: run_unrealpak_command(cmd))
button.pack(pady=5)

# Output text box to show command results
output_text = tk.Text(root, height=15, width=70)
output_text.pack(pady=10)

# Run the GUI loop
root.mainloop()