@@ -5,9 +5,11 @@ License: GNU GPL, version 3 or later; http://www.gnu.org/licenses/gpl.html
55Config management, validation, loading.
66]]
77
8+ local mp = require (' mp' )
89local mpopt = require (' mp.options' )
910local msg = require (' mp.msg' )
1011local h = require (' helpers' )
12+ local utils = require (' mp.utils' )
1113
1214local min_side_px = 42
1315local max_side_px = 640
@@ -179,7 +181,42 @@ local function next_profile()
179181 reload_from_disk ()
180182end
181183
184+ local function create_config_file ()
185+ local name = default_profile_filename
186+ local parent , child = utils .split_path (mp .get_script_directory ())
187+ parent , child = utils .split_path (parent :gsub (" /$" , " " ))
188+
189+ local config_filepath = utils .join_path (utils .join_path (parent , " script-opts" ), string.format (' %s.conf' , name ))
190+ local example_config_filepath = utils .join_path (mp .get_script_directory (), " .github/RELEASE/subs2srs.conf" )
191+
192+ local file_info = utils .file_info (config_filepath )
193+ if file_info and file_info .is_file then
194+ print (" config already exists" )
195+ return
196+ end
197+
198+ local handle = io.open (example_config_filepath , ' r' )
199+ if handle == nil then
200+ return
201+ end
202+
203+ local content = handle :read (" *a" )
204+ handle :close ()
205+
206+ handle = io.open (config_filepath , ' w' )
207+ if handle == nil then
208+ h .notify (string.format (" Couldn't open %s." , config_filepath ), " error" , 4 )
209+ return
210+ end
211+
212+ handle :write (string.format (" # Written by %s on %s.\n " , name , os.date ()))
213+ handle :write (content )
214+ handle :close ()
215+ h .notify (" Settings saved." , " info" , 2 )
216+ end
217+
182218local function init (config_table , profiles_table )
219+ create_config_file ()
183220 self .config , self .profiles = config_table , profiles_table
184221 -- 'subs2srs' is the main profile, it is always loaded. 'active profile' overrides it afterwards.
185222 -- initial state is saved to another table to maintain consistency when cycling through incomplete profiles.
0 commit comments