Skip to content

Commit

Permalink
First Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MediaMoots committed Oct 21, 2023
1 parent de7d6ea commit 91c522a
Show file tree
Hide file tree
Showing 3 changed files with 857 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build
dist
*.spec
93 changes: 93 additions & 0 deletions bars_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Written by MediaMoots

import sys
import glob
import PySimpleGUI as sg
from totk_audio_classes import Bars
from tkinter import filedialog as fd

### pyinstaller bars_tool.py --onefile

# Functions
def show_options():
sg.theme('Black')
event, values = sg.Window('TOTK BARS Tool',
[[sg.Text('Options'),
sg.Checkbox(default=False, text='Clear BARS?', size=(20, 3), key='ClrB')],
[sg.Button('Start Tool'), sg.Button('Cancel')]]).read(close=True)

if event == 'Start Tool':
run_bars_tool(values['ClrB'])
else:
sys.exit()

def run_bars_tool(is_clear_bars):
bars_path, bwav_path = get_required_paths()

bars = Bars(bars_path)

if is_clear_bars:
clear_bars(bars)

add_or_replace_bars(bars, bwav_path)

save_bars(bars)

def get_required_paths():
# bars
if len(sys.argv) > 1:
bars_path = sys.argv[1]
else:
bars_path = fd.askopenfilename(title="Open BARS file to use...", filetypes=[
('BARS Files', '*.bars')])

if bars_path == '':
sys.exit()

# bwav
if len(sys.argv) > 2:
bwav_path = sys.argv[2]
else:
bwav_path = fd.askdirectory(
title="Open folder containing BWAV files...")

if bwav_path == '':
sys.exit()

return bars_path, bwav_path

def clear_bars(bars):
bars.asset_count = 0

bars.metas.clear()
bars.meta_offsets.clear()

bars.assets.clear()
bars.asset_offsets.clear()

bars.crc_hashes.clear()

bars.unknown = b''

bars.size = bars.get_size()

def add_or_replace_bars(bars, bwav_path):
for bwav in glob.glob(bwav_path + "/" + "*.bwav"):
bars.add_or_replace_bwav(bwav, True)

def save_bars(bars):
if len(sys.argv) > 3:
bars_out_path = sys.argv[3]
else:
bars_out_path = fd.asksaveasfilename(
title="Select where to save the new BARS file...", filetypes=[('BARS File', '*.bars')])

if bars_out_path == '':
sys.exit()

if bars_out_path is not None:
bars.write(bars_out_path)

# Program Main
if __name__ == '__main__':
show_options()
Loading

0 comments on commit 91c522a

Please sign in to comment.