Skip to content

Commit

Permalink
Added support for downloading all files on the pedal to a directory
Browse files Browse the repository at this point in the history
  • Loading branch information
thammer committed Jun 30, 2024
1 parent 4dc3548 commit 702c06b
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions zoomzt2.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def remove_effect(self, data, name):

return ZT2.build(config)

def download_and_save_file(self, name):
def download_and_save_file(self, name, outname = ""):
data = bytearray(b"")
if self.file_check(name):
data = self.file_download(name)
Expand All @@ -347,14 +347,29 @@ def download_and_save_file(self, name):
print("File \"" + name + "\" was not found on the pedal" )

if data:
outfile = open(name, "wb")
if outname == "":
outname = name
outfile = open(outname, "wb")
if outfile:
outfile.write(data)
outfile.close()
else:
print("Unable to open FILE \"" + name + "\" for writing")
return data

def download_and_save_all_files(self, dirname):
files = []
name = self.file_wild(True)

while name:
files.append(name)
name = self.file_wild(False)

for name in files:
fullname = os.path.join(dirname, name)
print("Downloading file " + name.ljust(12) + " -> " + fullname)
self.download_and_save_file(name, fullname)

def filename(self, packet, name):
# send filename (with different packet headers)
head, tail = os.path.split(name)
Expand Down Expand Up @@ -723,7 +738,10 @@ def main():
parser.add_argument("-S", "--send",
help="Send FLST_SEQ to attached device",
action="store_true", dest="send")

parser.add_argument("--download-all",
help="Download all files on pedal to directory FILE",
action="store_true", dest="downloadall")

zd2 = parser.add_argument_group("ZD2", "Process ZDL2 effect file(s)").add_mutually_exclusive_group()
zd2.add_argument("-I", "--install",
help="Install effect binary to attached device, updating FLST_SEQ",
Expand Down Expand Up @@ -791,7 +809,7 @@ def main():
options.install or options.uninstall or \
options.installonly or options.uninstallonly or \
options.patchdown or options.patchup or \
options.effectdown:
options.effectdown or options.downloadall:
if not pedal.connect(options.midiskip):
sys.exit("Unable to find Pedal")
else:
Expand Down Expand Up @@ -841,14 +859,25 @@ def main():

if options.effectdown:
print("Downloading effect: \"" + options.files[0] + "\"" )
data = pedal.download_and_save_file(options.files[0])
pedal.download_and_save_file(options.files[0])

if options.includezic:
filename, extension = os.path.splitext(options.files[0])
zicfilename = filename + ".ZIC"
print("Downloading icon: \"" + zicfilename + "\"" )
data = pedal.download_and_save_file(zicfilename)
pedal.download_and_save_file(zicfilename)

pedal.disconnect()
exit(0)

if options.downloadall:
dirname = options.files[0]
print("Downloading all files to directory \"" + dirname + "\"" )

if not os.path.exists(dirname):
os.makedirs(dirname)

pedal.download_and_save_all_files(dirname)
pedal.disconnect()
exit(0)

Expand Down

0 comments on commit 702c06b

Please sign in to comment.