diff --git a/plugins/autofire/autofire_save.lua b/plugins/autofire/autofire_save.lua index 3c6f177ff13..0576a95582d 100644 --- a/plugins/autofire/autofire_save.lua +++ b/plugins/autofire/autofire_save.lua @@ -1,4 +1,3 @@ -local util = require("util") local lib = {} local function get_settings_path() @@ -71,7 +70,7 @@ function lib:save_settings(buttons) local path = get_settings_path() local attr = lfs.attributes(path) if not attr then - util.mkdir_recursive(path) + lfs.mkdir(path) elseif attr.mode ~= 'directory' then return end diff --git a/plugins/boot.lua b/plugins/boot.lua index 0bc32e91b27..8ae3e069755 100644 --- a/plugins/boot.lua +++ b/plugins/boot.lua @@ -1,6 +1,6 @@ -- license:BSD-3-Clause -- copyright-holders:Miodrag Milanovic -_G.lfs = require("lfs") +require('lfs') _G._ = emu.lang_translate _G.emu.plugin = {} -- table to contain plugin interfaces diff --git a/plugins/cheat/init.lua b/plugins/cheat/init.lua index 412bc261030..208efc3585e 100644 --- a/plugins/cheat/init.lua +++ b/plugins/cheat/init.lua @@ -72,7 +72,6 @@ exports.license = "The BSD 3-Clause License" exports.author = { name = "Carl" } local cheat = exports -local util = require("util") function cheat.set_folder(path) cheat.path = path @@ -160,7 +159,7 @@ function cheat.startplugin() local path = emu.subst_env(manager.machine.options.entries.cheatpath:value():match("([^;]+)")) local attr = lfs.attributes(path) if not attr then - util.mkdir_recursive(path) + lfs.mkdir(path) elseif attr.mode ~= "directory" then -- uhhh? return end @@ -168,7 +167,7 @@ function cheat.startplugin() local softpath = path .. "/" .. cheatname:match("([^/]+)") local attr = lfs.attributes(softpath) if not attr then - util.mkdir_recursive(softpath) + lfs.mkdir(softpath) elseif attr.mode ~= "directory" then -- uhhh? return end diff --git a/plugins/console/init.lua b/plugins/console/init.lua index c9811ba2467..388a1ca016b 100644 --- a/plugins/console/init.lua +++ b/plugins/console/init.lua @@ -13,8 +13,6 @@ local history_file = "console_history" local history_fullpath = nil -local util = require("util") - function console.startplugin() local conth = emu.thread() local ln_started = false @@ -300,8 +298,7 @@ end setmetatable(console, { __gc = function () if history_fullpath then - util.create_parent_dirs(history_fullpath) - local ln = require("linenoise") + local ln = require("linenoise") ln.savehistory(history_fullpath) end end}) diff --git a/plugins/data/data_hiscore.lua b/plugins/data/data_hiscore.lua index e6d7d75fdc0..3bf5467fe9e 100644 --- a/plugins/data/data_hiscore.lua +++ b/plugins/data/data_hiscore.lua @@ -1,8 +1,6 @@ -- to use this get the package from http://greatstone.free.fr/hi2txt/ -- extract the hi2txt.zip and place it in your history path -local util = require("util") - local dat = {} local env = {} local output @@ -1208,7 +1206,7 @@ function dat.check(set, softlist) local scrpath = path:match("[^;]*") .. "/" local scrfile = io.open(scrpath .. set .. ".lua", "w+") if not scrfile then - util.mkdir_recursive(scrpath) + lfs.mkdir(scrpath) scrfile = io.open(scrpath .. set .. ".lua", "w+") end if scrfile then diff --git a/plugins/data/database.lua b/plugins/data/database.lua index bd7de2d665d..b868173ce08 100644 --- a/plugins/data/database.lua +++ b/plugins/data/database.lua @@ -1,7 +1,6 @@ local sql = require("lsqlite3") local datfile = {} local db -local util = require("util") local function check_db(msg) if db:errcode() > sql.OK then @@ -13,10 +12,7 @@ do local dbpath = emu.subst_env(mame_manager.ui.options.entries.historypath:value():match("([^;]+)")) db = sql.open(dbpath .. "/history.db") if not db then - local success, err = util.mkdir_recursive(dbpath) - if not success then - emu.print_error("Unable to create parent directories for history database: " .. err) - end + lfs.mkdir(dbpath) db = sql.open(dbpath .. "/history.db") if not db then emu.print_error("Unable to create history.db\n") diff --git a/plugins/hiscore/init.lua b/plugins/hiscore/init.lua index 093737a9eec..2a9687d1547 100644 --- a/plugins/hiscore/init.lua +++ b/plugins/hiscore/init.lua @@ -12,7 +12,6 @@ exports.description = "Hiscore" exports.license = "WTFPL license" exports.author = { name = "borgar@borgar.net" } local hiscore = exports -local util = require("util") local hiscore_plugin_path = "" @@ -172,7 +171,7 @@ function hiscore.startplugin() local output = io.open(get_file_name(), "wb"); if not output then -- attempt to create the directory, and try again - util.mkdir_recursive( hiscore_path ); + lfs.mkdir( hiscore_path ); output = io.open(get_file_name(), "wb"); end emu.print_verbose("hiscore: write_scores output") diff --git a/plugins/portname/init.lua b/plugins/portname/init.lua index 926bf442a45..24cdc50facf 100644 --- a/plugins/portname/init.lua +++ b/plugins/portname/init.lua @@ -25,7 +25,6 @@ exports.license = "The BSD 3-Clause License" exports.author = { name = "Carl" } local portname = exports -local util = require("util") function portname.startplugin() local json = require("json") @@ -130,7 +129,7 @@ function portname.startplugin() local function check_path(path) local attr = lfs.attributes(path) if not attr then - util.mkdir_recursive(path) + lfs.mkdir(path) if not lfs.attributes(path) then manager.machine:popmessage(_("Failed to save input name file")) emu.print_verbose("portname: unable to create path " .. path .. "\n") diff --git a/plugins/timer/init.lua b/plugins/timer/init.lua index 562f3c6a8b1..f0ddabbcf50 100644 --- a/plugins/timer/init.lua +++ b/plugins/timer/init.lua @@ -1,6 +1,6 @@ -- license:BSD-3-Clause -- copyright-holders:Carl -local util = require('util') +require('lfs') local sqlite3 = require('lsqlite3') local exports = {} exports.name = "timer" @@ -44,7 +44,7 @@ function timer.startplugin() save() end timer_started = true - util.mkdir_recursive(dir .. '/timer') + lfs.mkdir(dir .. '/timer') local db = assert(sqlite3.open(timer_db)) local found=false db:exec([[select * from sqlite_master where name='timer';]], function(...) found=true return 0 end) diff --git a/plugins/util.lua b/plugins/util.lua deleted file mode 100644 index 6b2d7f438bf..00000000000 --- a/plugins/util.lua +++ /dev/null @@ -1,55 +0,0 @@ -local lfs = require("lfs") - --- Returns true if dirname is an existing directory, false if not a directory, --- or nil, an error message and a system dependent error code on error. -local function is_dir(dirname) - local ret, err, code = lfs.attributes(dirname, "mode") - if ret == nil then - return ret, err, code - else - return ret == "directory" - end -end - --- Get the directory name for the file. -local function dirname(filename) - if filename == "/" then - return "/" - end - local parent = filename:match("(.*)/.") - if parent then - if parent == "" then - parent = "/" - end - return parent - end - return "." -end - --- Create dir and parents for dir if needed. Returns true on success, --- nil, an error message and a system dependent error code on error. -local function mkdir_recursive(dir) - local ret, err, code = is_dir(dir) - if ret == true then - return true - end - local parent = dirname(dir) - local ret, err, code = mkdir_recursive(parent) - if not ret then - return ret, err, code - end - return lfs.mkdir(dir) -end - --- Create the parents of the file recursively if needed, returns true on success, --- or nil, an error message and a system dependent error code on error. -local function create_parent_dirs(filename) - local parent = dirname(filename) - return mkdir_recursive(parent) -end - -return { - dirname = dirname, - mkdir_recursive = mkdir_recursive, - create_parent_dirs = create_parent_dirs -}