Newer
Older
// This file has only been merged into master because it depended on the Repo Unification Process
// Which caused a lot of merge conflicts, so reducing merge requests made life easier for everybody at the time
"#import libs/utils.inc.src"
"#import libs/file.inc.src"
imports.shellapi.vshell.navigate = function(file, target)
originSteps = file.path.split("/")
targetSteps = file.path.split("/")
// TODO: File navigation
return null
end function
imports.shellapi.vshell.init = function(object)
if typeof(object) == "shell" then object = object.host_computer
type = typeof(object)
if type != "computer" and type != "file" then return null
result = imports.shellapi.constrs.shellui(imports.shellapi.vshell.cmds)
// Add support for command errors
result.transaction = function()
return [self.heart, self.current_path]
end function
result.rollback = function(transaction)
result.heart = transaction[0]
result.current_path = transaction[1]
isFile = typeof(self.heart) == "file"
if not path then
if isFile then return self.heart
return self.heart.File(current_path)
end if
path = imports.file.AbsolutePath(path)
if isFile then
result = imports.vshell.navigate(self.heart, path)
else
result = self.heart.File(path)
end if
if not imports.file.FileAccess(result,"r") then
return
end if
folder = imports.file.GetDirRef(result)
if not imports.file.FileAccess(folder,"r") then
print("Error, unable to access the target's folder")
self.current_path = folder.path
if typeof(self.heart) == "file" then self.heart = result
return result
result.heart = object
// Init the current_path var
if typeof(object) == "file" then path = object.path else path = object.current_path
result.navigate(path)
imports.vshell.init(object).start_terminal()
end function
imports.shellapi.vshell.read = function(shell, params)
if params.len > 0 then return "Parameter required"
file = shell.navigate(params[0])
// TODO: File reading
end function
imports.shellapi.vshell.cmds.help = function(shell, params)
names = ["exit"]
for name in imports.vshell.cmds.values
names.put(name)
end for
print("List of accepted commands:")
print(imports.utils.PrintList(names,imports.file.NEW_LINE))
imports.shellapi.vshell.cmds.cd = function(shell, params)
if params.len == 0 then path = "" else path = params[0]
if not shell.navigate(path).is_folder then return "target is not a folder!"
names = []
for item in file.get_folders
names = item.name+"/"
end for
for item in file.get_files
names = item.name
end for
print("List of folders in: "+file.path)
print(imports.utils.PrintList(names,imports.file.NEW_LINE))
imports.shellapi.vshell.cmds.read = function(shell, params)
result = imports.vshell.read(shell,params)
if typeof(result) != "list" then return result
print(imports.utils.PrintList(result,imports.file.NEW_LINE))
imports.shellapi.vshell.cmds.get = function(shell, params)
result = imports.vshell.read(shell,params)
if typeof(result) != "list" then return result
content = imports.utils.PrintList(result,imports.file.NEW_LINE)
imports.shellapi.vshell.cmds.delete = function(shell, params)
if params.len > 0 then return "Parameter required"
file = shell.navigate(params[0])
if not imports.utils.UserPrompt("Do you *REALLY* want to delete '"+file.path+"' ?") then return "Execution cancelled by user"
if not imports.file.delete(file) then return "Permission defined"