Skip to content

Commit a0094d6

Browse files
committed
move function
1 parent fbc6b5c commit a0094d6

File tree

2 files changed

+37
-36
lines changed

2 files changed

+37
-36
lines changed

cfg_mgr.lua

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ License: GNU GPL, version 3 or later; http://www.gnu.org/licenses/gpl.html
55
Config management, validation, loading.
66
]]
77

8+
local mp = require('mp')
89
local mpopt = require('mp.options')
910
local msg = require('mp.msg')
1011
local h = require('helpers')
12+
local utils = require('mp.utils')
1113

1214
local min_side_px = 42
1315
local max_side_px = 640
@@ -179,7 +181,42 @@ local function next_profile()
179181
reload_from_disk()
180182
end
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+
182218
local 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.

subs2srs.lua

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ For complete usage guide, see <https://github.com/Ajatt-Tools/mpvacious/blob/mas
3636
]]
3737

3838
local mp = require('mp')
39-
local utils = require('mp.utils')
4039
local OSD = require('osd_styler')
4140
local cfg_mgr = require('cfg_mgr')
4241
local encoder = require('encoder')
@@ -578,40 +577,6 @@ end
578577
------------------------------------------------------------
579578
-- main
580579

581-
local function create_config_file()
582-
local NAME = "subs2srs"
583-
local parent, child = utils.split_path(mp.get_script_directory())
584-
parent, child = utils.split_path(parent:gsub("/$", ""))
585-
586-
local config_filepath = utils.join_path(utils.join_path(parent, "script-opts"), string.format('%s.conf', NAME))
587-
local example_config_filepath = utils.join_path(mp.get_script_directory(), ".github/RELEASE/subs2srs.conf")
588-
589-
local file_info = utils.file_info(config_filepath)
590-
if file_info and file_info.is_file then
591-
print("config already exists")
592-
return
593-
end
594-
595-
local handle = io.open(example_config_filepath, 'r')
596-
if handle == nil then
597-
return
598-
end
599-
600-
local content = handle:read("*a")
601-
handle:close()
602-
603-
handle = io.open(config_filepath, 'w')
604-
if handle == nil then
605-
h.notify(string.format("Couldn't open %s.", config_filepath), "error", 4)
606-
return
607-
end
608-
609-
handle:write(string.format("# Written by %s on %s.\n", NAME, os.date()))
610-
handle:write(content)
611-
handle:close()
612-
h.notify("Settings saved.", "info", 2)
613-
end
614-
615580
local main = (function()
616581
local main_executed = false
617582
return function()
@@ -621,7 +586,6 @@ local main = (function()
621586
main_executed = true
622587
end
623588

624-
create_config_file()
625589
cfg_mgr.init(config, profiles)
626590
ankiconnect.init(config, platform)
627591
forvo.init(config, platform)

0 commit comments

Comments
 (0)