Skip to content

Commit

Permalink
Fix handling files with spaces in their path
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Oct 27, 2023
1 parent f200dd2 commit b1159cd
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions mod/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from random import randint
from tornado import gen, iostream
from tornado.ioloop import IOLoop, PeriodicCallback
from urllib.parse import quote, unquote
import os, json, socket, time, logging, sys
import shutil

Expand Down Expand Up @@ -233,7 +234,7 @@ def get_all_good_and_bad_pedalboards(ptype):
'broken': False,
'factory': False,
'hasTrialPlugins': False,
'uri': "file://" + DEFAULT_PEDALBOARD,
'uri': "file://" + quote(DEFAULT_PEDALBOARD),
'bundle': DEFAULT_PEDALBOARD,
'title': UNTITLED_PEDALBOARD_NAME,
'version': 0,
Expand Down Expand Up @@ -2139,7 +2140,7 @@ def report_current_state(self, websocket):

# load plugin state if relevant
if crashed and self.pedalboard_path:
self.send_notmodified("state_load {}".format(self.pedalboard_path))
self.send_notmodified("state_load \"{}\"".format(self.pedalboard_path))

# now load plugin parameters and addressings
for instance_id, pluginData in self.plugins.items():
Expand Down Expand Up @@ -2901,7 +2902,7 @@ def preset_save_new(self, instance, name, callback):
break

def add_bundle_callback(ok):
preseturi = "file://%s.ttl" % os.path.join(presetbundle, symbolname)
preseturi = "file://%s.ttl" % quote(os.path.join(presetbundle, symbolname))
pluginData['preset'] = preseturi
os_sync()
callback({
Expand All @@ -2920,7 +2921,7 @@ def host_callback(ok):
rescan_plugin_presets(plugin_uri)
self.add_bundle(presetbundle, add_bundle_callback)

self.send_notmodified("preset_save %d \"%s\" %s %s.ttl" % (instance_id,
self.send_notmodified("preset_save %d \"%s\" \"%s\" %s.ttl" % (instance_id,
name.replace('"','\\"'),
presetbundle,
symbolname), host_callback, datatype='boolean')
Expand All @@ -2939,7 +2940,7 @@ def preset_save_replace(self, instance, olduri, presetbundle, name, callback):
symbolname = symbolify(name)[:32]

def add_bundle_callback(ok):
preseturi = "file://%s.ttl" % os.path.join(presetbundle, symbolname)
preseturi = "file://%s.ttl" % quote(os.path.join(presetbundle, symbolname))
pluginData['preset'] = preseturi
os_sync()
callback({
Expand All @@ -2961,7 +2962,7 @@ def host_callback(ok):
def start(_):
# remove old preset ttl files, without removing the whole dir
if olduri.startswith("file:///"):
oldpath = olduri[7:]
oldpath = unquote(olduri[7:])
if os.path.exists(oldpath):
os.remove(oldpath)
oldpath = os.path.join(os.path.dirname(oldpath), "manifest.ttl")
Expand All @@ -2970,7 +2971,7 @@ def start(_):

rescan_plugin_presets(plugin_uri)
pluginData['preset'] = ""
self.send_notmodified("preset_save %d \"%s\" %s %s.ttl" % (instance_id,
self.send_notmodified("preset_save %d \"%s\" \"%s\" %s.ttl" % (instance_id,
name.replace('"','\\"'),
presetbundle,
symbolname), host_callback, datatype='boolean')
Expand Down Expand Up @@ -3648,7 +3649,7 @@ def load(self, bundlepath, isDefault=False, abort_catcher=None):

if bundlepath:
self.load_pb_snapshots(bundlepath)
self.send_notmodified("state_load {}".format(bundlepath))
self.send_notmodified("state_load \"{}\"".format(bundlepath))
self.addressings.load(bundlepath, instances, skippedPortAddressings, abort_catcher)

if abort_catcher is not None and abort_catcher.get('abort', False):
Expand Down Expand Up @@ -3990,7 +3991,7 @@ def state_saved_cb(ok):
callback(True, bundlepath, newTitle)

# ask host to save any needed extra state
self.send_notmodified("state_save {}".format(bundlepath), state_saved_cb, datatype='boolean')
self.send_notmodified("state_save \"{}\"".format(bundlepath), state_saved_cb, datatype='boolean')

return bundlepath, newTitle

Expand Down Expand Up @@ -5414,7 +5415,7 @@ def rcallback(ok, bundlepath, newTitle):
'broken': False,
'factory': False,
'hasTrialPlugins': False,
'uri': "file://" + bundlepath,
'uri': "file://" + quote(bundlepath),
'bundle': bundlepath,
'title': title,
'version': 0,
Expand Down Expand Up @@ -6171,7 +6172,7 @@ def host_callback(ok):

self.save_state_snapshots(self.pedalboard_path)
self.save_state_mainfile(self.pedalboard_path, self.pedalboard_name, titlesym)
self.send_notmodified("state_save {}".format(self.pedalboard_path), host_callback)
self.send_notmodified("state_save \"{}\"".format(self.pedalboard_path), host_callback)

def hmi_reset_current_pedalboard(self, callback):
logging.debug("hmi reset current pedalboard")
Expand Down

0 comments on commit b1159cd

Please sign in to comment.