mirror of
https://github.com/Kiritow/OpenComputerScripts.git
synced 2024-03-22 13:10:46 +08:00
grab working directory system changed.
This commit is contained in:
parent
7b09d6ca1f
commit
918fd406ad
39
grab.lua
39
grab.lua
|
@ -9,7 +9,7 @@ local event=require('event')
|
||||||
local term=require('term')
|
local term=require('term')
|
||||||
local args,options=shell.parse(...)
|
local args,options=shell.parse(...)
|
||||||
|
|
||||||
local grab_version="Grab v2.5.0-alpha"
|
local grab_version="Grab v2.5.1-alpha"
|
||||||
local grab_infos={
|
local grab_infos={
|
||||||
version=grab_version,
|
version=grab_version,
|
||||||
grab_options=options
|
grab_options=options
|
||||||
|
@ -324,8 +324,27 @@ local function IsOfficial(tb_package)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local db_dirs={"/etc/grab",".grab","/tmp/.grab"}
|
local grab_dir=''
|
||||||
local db_positions={"/etc/grab/programs.info",".grab/programs.info","/tmp/.grab/programs.info"}
|
|
||||||
|
local function CheckGrabDir()
|
||||||
|
local locations={"/etc/grab","/home/.grab","/tmp/.grab"}
|
||||||
|
for idx,position in ipairs(locations) do
|
||||||
|
if(filesystem.isDirectory(position)) then
|
||||||
|
grab_dir=position
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
local ok=filesystem.makeDirectory(position)
|
||||||
|
if(ok) then grab_dir=position return true end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
if(not CheckGrabDir()) then
|
||||||
|
print("[Error] Grab working directory not usable.")
|
||||||
|
return
|
||||||
|
else
|
||||||
|
print("Grab directory: " .. grab_dir)
|
||||||
|
end
|
||||||
|
|
||||||
local function VerifyDB(this_db)
|
local function VerifyDB(this_db)
|
||||||
for k,t in pairs(this_db) do
|
for k,t in pairs(this_db) do
|
||||||
|
@ -434,10 +453,9 @@ local function ReadDB(read_from_this)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for idx,filename in ipairs(db_positions) do
|
local filename=grab_dir .. "/programs.info"
|
||||||
local a,b=ReadDB(filename)
|
local a,b=ReadDB(filename)
|
||||||
if(a) then return a,b end
|
if(a) then return a,b end
|
||||||
end
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
@ -468,10 +486,7 @@ local function UpdateDB(main_tb,new_tb,checked) -- Change values with same key i
|
||||||
end
|
end
|
||||||
|
|
||||||
local function CreateDB(tb,checked) -- If checked, merging is not allowed.
|
local function CreateDB(tb,checked) -- If checked, merging is not allowed.
|
||||||
for idx,dirname in ipairs(db_dirs) do
|
local filename=grab_dir .. "/programs.info"
|
||||||
filesystem.makeDirectory(dirname) -- buggy
|
|
||||||
end
|
|
||||||
for idx,filename in ipairs(db_positions) do
|
|
||||||
local main_db=ReadDB(filename)
|
local main_db=ReadDB(filename)
|
||||||
if(main_db) then
|
if(main_db) then
|
||||||
if(not UpdateDB(main_db,tb,checked)) then
|
if(not UpdateDB(main_db,tb,checked)) then
|
||||||
|
@ -486,14 +501,10 @@ local function CreateDB(tb,checked) -- If checked, merging is not allowed.
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
if(args[1]=="clear") then
|
if(args[1]=="clear") then
|
||||||
print("Clearing programs info...")
|
print("Clearing programs info...")
|
||||||
for idx,filename in pairs(db_positions) do
|
filesystem.remove(grab_dir .. "/programs.info")
|
||||||
filesystem.remove(filename)
|
|
||||||
end
|
|
||||||
print("Programs info cleaned. You may want to run `grab update` now.")
|
print("Programs info cleaned. You may want to run `grab update` now.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user