@@ -54,7 +54,7 @@ def _regenerate_filter_file():
54
54
f .write ("# If you are editing this file manually, make sure to not use the UI file picker, as the saves done there will overwrite.\n " )
55
55
f .write ("# Examples: https://rclone.org/filtering/#examples\n " )
56
56
f .write ("\n " )
57
-
57
+
58
58
for exclude in excludes :
59
59
f .write (f"- { exclude } " )
60
60
f .write ("\n " )
@@ -63,6 +63,30 @@ def _regenerate_filter_file():
63
63
f .write ("\n " )
64
64
f .write ("- **\n " )
65
65
66
+
67
+ def _get_config ():
68
+ with open (cfg_property_file ) as f :
69
+ lines = f .readlines ()
70
+ lines = list (map (lambda x : x .strip ().split ('=' ), lines ))
71
+ logger .debug ("config %s" , lines )
72
+ return lines
73
+
74
+ def _set_config (key : str , value : str ):
75
+ with open (cfg_property_file , "r" ) as f :
76
+ lines = f .readlines ()
77
+
78
+ with open (cfg_property_file , "w" ) as f :
79
+ found = False
80
+ for line in lines :
81
+ if line .startswith (key + '=' ):
82
+ f .write (f"{ key } ={ value } \n " )
83
+ found = True
84
+ else :
85
+ f .write (line )
86
+
87
+ if not found :
88
+ f .write (f"{ key } ={ value } \n " )
89
+
66
90
class Plugin :
67
91
current_spawn = None
68
92
current_sync = None
@@ -104,8 +128,11 @@ async def get_backend_type(self):
104
128
105
129
async def sync_now (self ):
106
130
logger .debug ("Executing: sync_now()" )
107
- logger .debug ("Running command: %s copy --filter-from %s / backend:decky-cloud-save --copy-links" , rclone_bin , cfg_syncpath_filter_file )
108
- self .current_sync = await asyncio .subprocess .create_subprocess_exec (rclone_bin , * ["copy" , "--filter-from" , cfg_syncpath_filter_file , "/" , "backend:decky-cloud-save" , "--copy-links" ])
131
+
132
+ destination_path = next ((x [1 ] for x in _get_config () if x [0 ] == "destination_directory" ), "decky-cloud-save" )
133
+ logger .debug ("Running command: %s copy --filter-from %s / backend:%s --copy-links" , rclone_bin , cfg_syncpath_filter_file , destination_path )
134
+
135
+ self .current_sync = await asyncio .subprocess .create_subprocess_exec (rclone_bin , * ["copy" , "--filter-from" , cfg_syncpath_filter_file , "/" , f"backend:{ destination_path } " , "--copy-links" ])
109
136
110
137
async def sync_now_probe (self ):
111
138
logger .debug ("Executing: sync_now_probe()" )
@@ -186,29 +213,11 @@ async def remove_syncpath(self, path: str, file: str):
186
213
187
214
async def get_config (self ):
188
215
logger .debug ("Executing: get_config()" )
189
- with open (cfg_property_file ) as f :
190
- lines = f .readlines ()
191
- lines = list (map (lambda x : x .strip ().split ('=' ), lines ))
192
- logger .debug ("config %s" , lines )
193
- return lines
216
+ return _get_config ()
194
217
195
218
async def set_config (self , key : str , value : str ):
196
219
logger .debug ("Executing: set_config(%s, %s)" , key , value )
197
- with open (cfg_property_file , "r" ) as f :
198
- lines = f .readlines ()
199
-
200
- with open (cfg_property_file , "w" ) as f :
201
- found = False
202
- for line in lines :
203
- if line .startswith (key + '=' ):
204
- f .write (f"{ key } ={ value } \n " )
205
- found = True
206
- else :
207
- f .write (line )
208
-
209
- if not found :
210
- f .write (f"{ key } ={ value } \n " )
211
-
220
+ _set_config (key , value )
212
221
213
222
# Asyncio-compatible long-running code, executed in a task when the plugin is loaded
214
223
@@ -228,6 +237,12 @@ async def _main(self):
228
237
if not cfg_property_file .is_file ():
229
238
cfg_property_file .touch ()
230
239
240
+ # Prepopulate config
241
+ config = _get_config ()
242
+ logger .warn (config )
243
+ if not any (e [0 ] == "destination_directory" for e in config ):
244
+ _set_config ("destination_directory" , "decky-cloud-save" )
245
+
231
246
# Function called first during the unload process, utilize this to handle your plugin being removed
232
247
async def _unload (self ):
233
248
await _kill_previous_spawn (self .current_spawn ) # Kills only if exists
0 commit comments