shop fix dupe sell names + disk copy cloning
This commit is contained in:
@@ -45,6 +45,13 @@ local page = UI.Page {
|
|||||||
x = 2, ex = -2, y = -4,
|
x = 2, ex = -2, y = -4,
|
||||||
backgroundColor = colors.black,
|
backgroundColor = colors.black,
|
||||||
},
|
},
|
||||||
|
cloneText = UI.Text {
|
||||||
|
x = 2, y = -2,
|
||||||
|
value = 'Clone'
|
||||||
|
},
|
||||||
|
clone = UI.Checkbox {
|
||||||
|
x = 8, y = -2,
|
||||||
|
},
|
||||||
copyButton = UI.Button {
|
copyButton = UI.Button {
|
||||||
x = -7, y = -2,
|
x = -7, y = -2,
|
||||||
text = 'Copy',
|
text = 'Copy',
|
||||||
@@ -52,7 +59,8 @@ local page = UI.Page {
|
|||||||
inactive = true,
|
inactive = true,
|
||||||
},
|
},
|
||||||
warning = UI.Text {
|
warning = UI.Text {
|
||||||
x = 2, ex = -9, y = -2,
|
x = 2, ex = -2, y = -5,
|
||||||
|
align = 'center',
|
||||||
textColor = colors.orange,
|
textColor = colors.orange,
|
||||||
},
|
},
|
||||||
notification = UI.Notification { },
|
notification = UI.Notification { },
|
||||||
@@ -112,23 +120,34 @@ function page:scan()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function page:copy(sdrive, tdrive)
|
function page:copy(sdrive, tdrive)
|
||||||
local totalFiles = 0
|
|
||||||
local throttle = Util.throttle()
|
local throttle = Util.throttle()
|
||||||
|
local sourceFiles, targetFiles = { }, { }
|
||||||
|
|
||||||
local function countFiles(source, target)
|
local function getListing(mountPath, path, files)
|
||||||
if fs.isDir(source) then
|
for _,f in pairs(fs.list(path)) do
|
||||||
for _,f in pairs(fs.list(source)) do
|
local file = fs.combine(path, f)
|
||||||
countFiles(fs.combine(source, f), fs.combine(target, f))
|
if not fs.isReadOnly(file) then
|
||||||
|
files[string.sub(file, #mountPath + 1)] = true
|
||||||
|
if fs.isDir(file) then
|
||||||
|
getListing(mountPath, file, files)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
|
||||||
totalFiles = totalFiles + 1
|
|
||||||
end
|
end
|
||||||
throttle()
|
throttle()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.progress:centeredWrite(1, 'Computing..')
|
||||||
|
self.progress:sync()
|
||||||
|
|
||||||
|
getListing(sdrive.getMountPath(), sdrive.getMountPath(), sourceFiles)
|
||||||
|
getListing(tdrive.getMountPath(), tdrive.getMountPath(), targetFiles)
|
||||||
|
|
||||||
local copied = 0
|
local copied = 0
|
||||||
|
local totalFiles = Util.size(sourceFiles)
|
||||||
|
|
||||||
local function rawCopy(source, target)
|
local function rawCopy(source, target)
|
||||||
if fs.isDir(source) then
|
if fs.isDir(source) then
|
||||||
|
copied = copied + 1
|
||||||
if not fs.exists(target) then
|
if not fs.exists(target) then
|
||||||
fs.makeDir(target)
|
fs.makeDir(target)
|
||||||
end
|
end
|
||||||
@@ -150,12 +169,17 @@ function page:copy(sdrive, tdrive)
|
|||||||
throttle()
|
throttle()
|
||||||
end
|
end
|
||||||
|
|
||||||
self.progress:centeredWrite(1, 'Computing..')
|
local function cleanup()
|
||||||
self.progress:sync()
|
for k in pairs(targetFiles) do
|
||||||
countFiles(sdrive.getMountPath(), tdrive.getMountPath())
|
if not sourceFiles[k] then
|
||||||
|
fs.delete(fs.combine(tdrive.getMountPath(), k))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
self.progress:clear()
|
self.progress:clear()
|
||||||
rawCopy(sdrive.getMountPath(), tdrive.getMountPath())
|
rawCopy(sdrive.getMountPath(), tdrive.getMountPath())
|
||||||
|
cleanup()
|
||||||
self.progress:centeredWrite(1, 'Copy Complete', colors.lime, colors.black)
|
self.progress:centeredWrite(1, 'Copy Complete', colors.lime, colors.black)
|
||||||
self.progress:sync()
|
self.progress:sync()
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
local Config = require('config')
|
local Config = require('config')
|
||||||
|
local Map = require('map')
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
|
|
||||||
local os = _G.os
|
local os = _G.os
|
||||||
@@ -58,6 +59,7 @@ function shopTab:eventHandler(event)
|
|||||||
|
|
||||||
elseif event.type == 'update' then
|
elseif event.type == 'update' then
|
||||||
if self.form:save() then
|
if self.form:save() then
|
||||||
|
Map.removeMatches(config, { name = self.form.values.name })
|
||||||
config[self.item.key] = self.form.values
|
config[self.item.key] = self.form.values
|
||||||
Config.update('shop', config)
|
Config.update('shop', config)
|
||||||
os.queueEvent('shop_refresh')
|
os.queueEvent('shop_refresh')
|
||||||
|
|||||||
Reference in New Issue
Block a user