Skip to content

Instantly share code, notes, and snippets.

@thomasjslone
Created November 25, 2017 19:40
Show Gist options
  • Save thomasjslone/c25afdc0244bb3c71ddac7fb2a16724a to your computer and use it in GitHub Desktop.
Save thomasjslone/c25afdc0244bb3c71ddac7fb2a16724a to your computer and use it in GitHub Desktop.
ossy 1404
## Ossy Core - Version 1.4.0.0
## OCT21-2017 - Thomas J. Slone
CORE_VERSION = "1.4.0.3" ; CORE_DATE = "2017.11.22.10.40.21"
CORE_AUTHOR = "Thomas J. Slone" ; CORE_MANUFACTURER = "Tomtech"
CORE_NAME = "Ossy" ; CORE_EDITION = " Another edition. "
CORE_INIT_TIME = Time.now ; CORE_BOOT_LOG = []
MAIN = self
ADMIN = "admin" ; PASSWORD = ""
if ENV["OS"] == "Windows_NT" and File.directory?("C:/") ; OS = "windows"
if File.directory?(Dir.getwd.to_s)
INSTDIR = Dir.getwd.to_s
else
end
elsif ENV.to_a.to_s.downcase.include?("the android project") ; OS = "android"
begin ; d = Dir.entries("/storage")[2].to_s ; rescue ; d = "" ; end
if File.directory?("/storage/" + d.to_s)
INSTDIR = "/storage/" + d.to_s
elsif File.directory?("/mnt/sdcard")
INSTDIR = "/mnt/sdcard"
else ; raise "Ossy cannot find install directory. " + OS.to_s
end
else ; OS = "linux"
INSTDIR = Dir.getwd.to_s
end
Dir.chdir INSTDIR + "/"
if File.file?(INSTDIR + "/config/ossy.cfg")
fi = File.open(INSTDIR+"/config/ossy.cfg","r") ; CONFIG = fi.read.to_s.split("\n") ; fi.close
INSTID = CONFIG[2]
PASSWORD = CONFIG[3]
CFGDIR = INSTDIR + "/config" ; if File.directory?(CFGDIR) == false ; Dir.mkdir(CFGDIR) ; end
DATADIR = INSTDIR + "/data" ; if File.directory?(DATADIR) == false ; Dir.mkdir(DATADIR) ; end
LOGDIR = INSTDIR + "/data/logs" ; if File.directory?(LOGDIR) == false ; Dir.mkdir(LOGDIR) ; end
TEMPDIR = INSTDIR + "/data/temp" ; if File.directory?(TEMPDIR) == false ; Dir.mkdir(TEMPDIR) ; end
APPDATADIR = INSTDIR + "/data/appdata" ; if File.directory?(APPDATADIR) == false ; Dir.mkdir(APPDATADIR) ; end
HOSTDIR = INSTDIR + "/host/" ; if File.directory?(HOSTDIR) == false ; Dir.mkdir(HOSTDIR) ; end
APPDIR = INSTDIR + "/apps/" ; if File.directory?(APPDIR) == false ; Dir.mkdir(APPDIR) ; end
LIBDIR = INSTDIR + "/lib/" ; if File.directory?(LIBDIR) == false ; Dir.mkdir(LIBDIR) ; end
COREDIR = INSTDIR + "/cores/" ; if File.directory?(COREDIR) == false ; Dir.mkdir(COREDIR) ; end
DOCDIR = DATADIR + "/documents" ; if File.directory?(DOCDIR) == false ; Dir.mkdir(DOCDIR) ; end
DDOCDIR = DATADIR + "/documents/doc" ; if File.directory?(DDOCDIR) == false ; Dir.mkdir(DDOCDIR) ; end
AUDDIR = DATADIR + "/audio" ; if File.directory?(AUDDIR) == false ; Dir.mkdir(AUDDIR) ; end
ALRDIR = DATADIR + "/audio/alarms" ; if File.directory?(ALRDIR) == false ; Dir.mkdir(ALRDIR) ; end
RINDIR = DATADIR + "/audio/ringtones" ; if File.directory?(RINDIR) == false ; Dir.mkdir(RINDIR) ; end
SSDIR = DATADIR + "/audio/system sounds" ; if File.directory?(SSDIR) == false ; Dir.mkdir(SSDIR) ; end
IMGDIR = DATADIR + "/images" ; if File.directory?(IMGDIR) == false ; Dir.mkdir(IMGDIR) ; end
GRHDIR = DATADIR + "/images/graphics" ; if File.directory?(GRHDIR) == false ; Dir.mkdir(GRHDIR) ; end
BGDIR = DATADIR + "/images/backgrounds" ; if File.directory?(BGDIR) == false ; Dir.mkdir(BGDIR) ; end
CERTDIR = DATADIR + "/certs" ; if File.directory?(CERTDIR) == false ; Dir.mkdir(CERTDIR) ; end
EXTDIR = DATADIR + "/extensions" ; if File.directory?(EXTDIR) == false ; Dir.mkdir(EXTDIR) ; end
ENCDIR = DATADIR + "/encodings" ; if File.directory?(ENCDIR) == false ; Dir.mkdir(ENCDIR) ; end
FONDIR = DATADIR + "/fonts" ; if File.directory?(FONDIR) == false ; Dir.mkdir(FONDIR) ; end
CURDIR = DATADIR + "/cursors" ; if File.directory?(CURDIR) == false ; Dir.mkdir(CURDIR) ; end
else
puts "Ossy cannon mount to installation directory."
end
CHARACTERS = [] ; c = 0 ; 256.times{ CHARACTERS << c.chr.to_s ; c += 1 }
BINARY = [] ; c = 0 ; 256.times { b = c.to_s(2) ; until b.to_s.length == 8 ; b = "0" + b.to_s ; end ; BINARY << b ; c += 1 }
HEX = [] ; c = 0 ; 256.times { h = c.to_s(16) ; if h.length == 1 ; h = "0" + h.to_s ; end ; HEX << h ; c += 1 }
BYTES = [] ; HEX.each do |h| ; BYTES << "\\x" + h ; end
DAYNAMES = ["sunday","monday","tuesday","wednesday","thursday","friday","saturday"]
MONTHNAMES = ["january","february","march","april","may","june","july","august","september","october","november","december"]
SEASONNAMES = ["spring","summer","autum","winter"]
##;##;##;##;##;##;##;##;##;##
Time.class.class.class_eval{
def parse_seconds(s) ; s = s.to_s.to_f ; if s.to_f < 60.0 ; [0,0,s.to_i] ; elsif s.to_f < 3600.0 and s.to_f >= 60.0 ; minutes = s.to_f / 60.to_f ; sec = ("." + minutes.to_s.split(".")[-1].to_s).to_f * 60 ; [0,minutes.to_i, sec.round] ; elsif s.to_f < 86400.0 and s.to_f >= 3600.0 ; hours = s.to_f / 60.to_f / 60.to_f ; minutes = ("." + hours.to_s.split(".")[-1].to_s).to_f * 60 ; sec = ("." + minutes.to_s.split(".")[-1].to_s).to_f * 60 ; [hours.to_i, minutes.to_i ,sec.to_i] ; else ; s.to_s + "MORE THAN 24 HOURS" ; end ; end
def stamp *args
if args[0] == nil ; t = Time.now ; y = t.year.to_s ; mo = t.month.to_s ; d = t.day.to_s ; h = t.hour.to_s ; mi = t.min.to_s ; s = t.sec.to_s ; if y.length < 4 ; until y.length == 4 ; y = "0" + y ; end ; end ; y = y[0..3] ; if mo.length < 2 ; mo = "0" + mo end ; mo = mo[0..1] ; if d.length < 2 ; d = "0" + d ; end ; d = d[0..1] ; if h.length < 2 ; h = "0" + h ; end ; h = h[0..1] ; if mi.length < 2 ; mi = "0" + mi ; end ; mi = mi[0..1] ; if s.length < 2 ; s = "0" + s ; end ; s = s[0..1] ; [y,mo,d,h,mi,s].join(".")
elsif args[0].is_a? Time ; t = args[0] ; y = t.year.to_s ; mo = t.month.to_s ; da = t.day.to_s ; hr = t.hour.to_s ; mi = t.min.to_s ; se = t.sec.to_s ; if mo.length == 1 ; mo = "0" + mo.to_s ; end ; if da.length == 1 ; da = "0" + da.to_s ; end ; if hr.length == 1 ; hr = "0" + hr.to_s ; end ; if mi.length == 1 ; mi = "0" + mi.to_s ; end ; if se.length == 1 ; se = "0" + se.to_s ; end ; return y.to_s + "." + mo.to_s + "." + da.to_s + "." + hr.to_s + "." + mi.to_s + "." + se.to_s
elsif args[0].is_a? String ; t = args[0].split(".") ; return Time.new(t[0],t[1],t[2],t[3],t[4],t[5])
end
end
def get_timer *args ; return Timer.new *args ; end
class Timer
def initialize *args
if args[0].is_a?(Time) ; @time = args[0]
elsif args[0] == nil ; @time = Time.now
else ; @time = Time.now ; return "Timer takes a time object as an arguement. Time was set to system time."
end
end
def reset ; @time = Time.now ; end
def time ; return Time.parse_seconds((Time.now - @time).to_s.split(".")[0].to_i).join(":") ; end
end
}
def time *args ; Time.stamp *args ; end
##;##;##;##;##;##;##;##;##;##
Dir.instance_eval{
def exist? *args
if args == nil ; return File.exist?(Dir.getwd.to_s)
else
if File.exist?(dir) ; return true
elsif File.exist?(Dir.getwd.to_s + "/" + dir) ; return true
else ; return false
end
end
end
def dir *args
if args[0] == nil ; return Dir.getwd.to_s
elsif args[0].is_a?(String)
if File.directory?(args[0]) ; Dir.chdir(args[0]) ; return Dir.getwd.to_s
elsif File.directory?(Dir.getwd.to_s + "/" + args[0].to_s) ; Dir.chdir(Dir.getwd.to_s + "/" + args[0].to_s) ; return Dir.getwd.to_s
elsif File.file?(args[0].to_s) ; Dir.chdir(args[0].to_s.split("/")[0..-2].join("/").to_s) ; return Dir.getwd.to_s
else ; raise "No such directory."
end
else ; raise "Invalid arguements, use a string to represent a path."
end
end
def view *args
if args[0] == nil
dir = Dir.getwd.to_s
elsif File.directory?(args[0].to_s)
dir = args[0].to_s
elsif File.directory?(Dir.getwd + args[0])
dir = Dir.getwd + args[0]
else
dir = false
end
if dir == false ; raise "No such directory: " + args[0].to_s
else
cont = Dir.entries(dir.to_s) ; cont.delete(".") ; cont.delete("..") ; bt = 0
if cont.length == 0 ; return "Directory is empty"
else
str = [] ; fi = [] ; fo = []
cont.each do |p|
if File.file?(dir.to_s + "/" + p.to_s)
begin ; s = File.size?(dir.to_s + "/" + p.to_s).to_s ; rescue ; s = "" ; end
fi << "File: " + p.to_s + " Size: " + s.to_s
elsif File.directory?(dir.to_s + "/" + p.to_s)
fo << "Dir: " + p.to_s + ""
end
end
str << "Directory: \"" + dir.to_s + "\" Files: " + fi.length.to_s + ", Folders: " + fo.length.to_s
str << "#############################################"
fo.each { |f| str << f.to_s } ; fi.each { |f| str << f.to_s }
str << "#############################################\n"
puts str.join("\n").to_s
end
end
end
def map(dir)
if File.directory?(dir.to_s) or File.directory?(Dir.getwd.to_s + "/" + dir.to_s)
if File.directory?(dir.to_s) ; ; else ; dir = Dir.getwd.to_s + "/" + dir.to_s ; end
cur = nil ; rem = [dir.to_s] ; fi = [] ; fo = [] ; ex = []
until rem.length == 0
cur = rem[0].to_s ; rem.delete_at(0)
begin ; cont = Dir.entries(cur.to_s) ; cont.delete(".") ; cont.delete("..")
if cont.length > 0
cont.each do |p|
if File.file?(cur.to_s + "/" + p.to_s) ; fi << cur.to_s + "/" + p.to_s
elsif File.directory?(cur.to_s + "/" + p.to_s) ; fo << cur.to_s + "/" + p.to_s ; rem << fo[-1]
end
end
end
rescue
ex << cur
end
end
if ex.length == 0 ; return [fi,fo]
else ; return [fi,fo,ex]
end
elsif File.file?(dir.to_s) ; return "Arguement is a file. Dir.map returns arrays of subdirectories and files with in a directory, it does not work on files."
else
raise "No such directory"
end
end
def img(dir)
if File.directory?(dir.to_s)
m = map(dir.to_s)
if m.length == 2
d = []
begin
m[0].each do |f|
fi = File.open(f,"rb") ; d << fi.read.to_s ; fi.close
end
img = [m[0],m[1],d] ; return img
rescue
raise "Directory mapping failed when unreadable file was encountered: " + f.to_s
end
else
raise "Directory contains unreadable subdirectories: " + m[2].join(", ").to_s
end
elsif File.file?(dir.to_s) ; return "Dir.img creates array mappings of folders, not files."
else ; raise "No such directory."
end
end
def size?(dir)
if File.directory?(dir)
m = map(dir)
if m.length == 2
s = m[0].join('').length + m[1].join('').length
if m[0].length > 0
m[0].each do |f|
s += File.size?(f)
end
end
return s
else
raise "Directory can not be measured because it contained unreadable subdirectories: " + m[2].join(", ").to_s
end
elsif File.file?(dir.to_s) ; return File.size?(dir.to_s)
else ; raise "No such file or directory."
end
end
def empty?(dir)
if File.directory?(dir) ; if Dir.entries(dir.to_s).length <= 2 ; return true ; else ; return false ; end
elsif File.file?(dir) ; return File.empty?(dir.to_s)
else ; return "No such file or directory."
end
end
def empty!(dir)
if File.directory?(dir.to_s)
m = Dir.map(dir.to_s?)
if m == [[],[]] ; return "Directory is already empty."
else
df = 0 ; dd = 0 ; db = 0
if m[0].length > 0 ; m[0].each { |f| db += File.size?(f) ; df += 1 ; File.delete(f) } ; end
if m[1].length > 0 ; m[1].each { |d| Dir.delete(d.to_s) ; dd += 1 } ; end
return "Deleted " + df.to_s + " files and " + dd.to_s + " folders. ( " + db.to_s + " bytes )"
end
elsif File.file?(dir.to_s) ; return "Input was a filepath. Dir.empty! deletes the contents from directories, not files. Use File.empty!"
else ; return "No such directory."
end
end
def search *args # dir, tag, filebytes, ignorecase
if args[0].is_a?(String) and File.directory?(args[0].to_s)
if args[1].to_s.length > 0
found_files = []; found_folders = [] ; found_file_pages = [] ; map = Dir.map(args[0].to_s)
if map[1].length > 0
map[1].each do |dir|
if args[3] == true ; d = dir.to_s.downcase ; term = args[1].to_s.downcase
else ; d = dir.to_s ; term = args[1].to_s
end ; if d.to_s.include?(term.to_s) ; found_folders << dir.to_s ; end
end
end
if map[0].length < 0
map[0].each do |path|
if args[3] == true ; p = path.to_s.downcase ; term = args[1].to_s.downcase
else ; p = path.to_s ; term = args[1].to_s
end ; if p.to_s.include?(term.to_s) ; found_files << p.to_s ; end
if args[2] == true
fi = File.open(path.to_s,"r") ; cont = fi.read.to_s ; fi.close
if args[3] == true ; cont = cont.to_s.downcase ; term = args[1].to_s.downcase
else ; cont = cont.to_s ; term = args[1].to_s
end
if cont.to_s.include?(term.to_s)
position = cont.to_s.downcase.split(term.to_s.downcase)[0].to_s.length
found_file_pages << [path.to_s,position.to_i]
end
end
end
end
res = [found_files,found_folders,found_file_pages]
if args[2] == true ; return res
else
if res[0].length == 0 and res[1].length == 0 ; return "No instances of the term were found in the given directory."
else ; return res[0..1]
end
end
else ; return "No search term was given."
end
elsif File.file?(args[0].to_s)
if args[1].to_s.length > 0 ; return File.search(args[0].to_s,args[1].to_s)
else ; return "No search term was given."
end
else ; if args.length == 0 ; return "Enter arguements: (dir, tag)" ; else ; return "No such file or directory." ; end
end
end
def copy(dir,newdir)
if File.directory?(dir)
if File.directory?(newdir.to_s + "/" + dir.to_s.split("/")[-1].to_s) == false
m = Dir.map(dir.to_s)
if m == [[],[]]
Dir.mkdir(newdir.to_s + "/" + dir.to_s.split("/")[-1].to_s)
else ; Dir.mkdir(newdir.to_s + "/" + dir.to_s.split("/")[-1].to_s)
if m[1].length > 0
m[1].each do |d|
nd = newdir.to_s + "/" + d.to_s.split(dir.to_s)[1].to_s
Dir.mkdir(nd.to_s)
end
end
if m[0].length > 0
m[0].each do |p|
fi = File.open(p.to_s,"r") ; cont = fi.read.to_s ; fi.close
np = newdir.to_s + "/" + p.to_s.split(dir.to_s)[1].to_s
fi = File.open(np.to_s,"w") ; fi.write(cont.to_s) ; fi.close
end
end
end
return true
else ; return "Target directory already contains a directory with the same name as the one you're copying."
end
else ; return "No such directory."
end
end
def move(dir,newdir)
if File.directory?(dir)
if File.directory?(newdir)
if File.directory?(newdir.to_s + "/" + dir.to_s.split("/")[-1].to_s) == false
Dir.mkdir(newdir.to_s + "/" + dir.to_s.split("/")[-1].to_s)
img = Dir.img(dir.to_s)
if img == [[],[],[]] ; Dir.delete(dir.to_s) ; return true
else
Dir.copy(dir.to_s,newdir.to_s)
if img[0].length > 0
img[0].each { |f| File.delete(f.to_s) }
end
if img[1].length > 0
img[1].each { |d| Dir.delete(d.to_s) }
end
Dir.delete(dir.to_s)
return true
end
else ; return "Cannot move because target directory already exists."
end
elsif File.file?(newdir) ; return "Target directory is actually an existing file!"
else ; return "Target directory does not exist."
end
elsif File.file?(dir) ; return "Dir.move is for directories only, use File.move for files."
else ; return "No such directory."
end
end
def rename(dir,newname)
end
def delete(dir) ; m = map(dir) ; m[0].each do |f| ; f.to_s ; File.delete(f.to_s) ; end ; m[1].each do |d| ; Dir.delete(d.to_s) ; end ; Dir.delete(dir) ; return true ; end
#def zip(sdir,tdir,name) ; ; end
#def zip!(dir)
alias :create :mkdir
alias :make :mkdir
}
def dir *args ; Dir.dir *args ; end
def viewdir *args ; puts Dir.view *args ; end
alias :vd :viewdir
##;##;##;##;##;##;##;##;##;##
File.instance_eval{
#def read(path) ; ; end
def view(path)
if File.file?(path.to_s)
puts File.read(path.to_s)
else ; return "No such file."
end
end
alias :print :view
def dir?(path) ; return File.directory?(path) ; end
def write *args
if File.file?(args[0].to_s)
if args[1].to_s.length > 0
fi = File.open(args[0].to_s,"w") ; fi.write(args[1].to_s) ; fi.close ; return true
else ; return "No input string was given."
end
elsif File.directory?(args[0].to_s) ; return "Input path is a directory, not a file."
else ; return "No such file."
end
end
def prepend *args # path, str
if File.file?(args[0].to_s)
if args[1].to_s.length > 0
fi = File.open(args[0].to_s,"r") ; cont = fi.read.to_s ; fi.close
fi = File.open(args[0].to_s,"w") ; fi.write(args[1].to_s + cont.to_s) ; fi.close
return true
else ; return "No input string to prepend to file."
end
else ; return "No such file."
end
end
def create *args # name
if File.file?(args[0].to_s) == true ; return "Threre is already a file with this name in the current directory."
elsif File.directory?(args[0].to_s) == true ; return "There is already a subdirectory with this name in the current directory."
else
begin
if args[0].is_a?(String) and args[0].to_s.length > 0
fi = File.open(args[0].to_s,"w") ; fi.write('') ; fi.close ; return true
else ; return "Unable to create file because input name was not a valid string."
end
rescue ; return "Unable to create file due to directory write access permission denial."
end
end
end
def append *args # path, str
if File.file?(args[0].to_s)
if args[1].to_s.length > 0
fi = File.open(args[0].to_s,"r") ; cont = fi.read.to_s ; fi.close
fi = File.open(args[0].to_s,"w") ; fi.write(cont.to_s + args[1].to_s) ; fi.close
return true
else ; return "No input string to append to file."
end
else ; return "No such file."
end
end
def insert *args # path, pos, str
if File.file?(args[0].to_s)
if args[1].is_a?(Integer)
fi = File.open(args[0].to_s,"r") ; cont = fi.read.to_s ; fi.close
cont = cont.split('')
inserted = cont[0..args[1].to_i].join('').to_s + args[2].to_s + cont[(args[1].to_i+1)..-1].join('')
fi = File.open(args[0].to_s,"w") ; fi.write(inserted.to_s) ; fi.close
return true
else ; return "Specified position is not a valid integer."
end
else ; return "No such file."
end
end
def read_line *args # path, line
if File.file?(args[0].to_s)
fi = File.open(args[0].to_s,"r") ; lines = fi.read.to_s.split("\n") ; fi.close ; lines.delete("")
if lines.length > 0
if args[1].is_a?(Integer) or args[1].is_a?(Range)
if args[1].is_a?(Integer)
return line[args[1].to_i].to_s
elsif args[1].is_a?(Range)
return lines[args[1]].join("\n").to_s
end
else ; return "Invalid line index given."
end
else ; return "File is empty so there were no lines to retrieve."
end
else ; return "No such file."
end
end
def write_line *args # path, line, string
if File.file?(args[0].to_s)
if args[1].is_a?(Integer) or args[1].is_a?(Range)
if args[2].is_a?(String) and args[2].to_s.length >= 1
fi = File.open(args[0].to_s,"r") ; cont = file.read.to_s.split("\n") ; fi.close
cont[args[1]] = args[2].to_s
fi = File.open(args[0].to_s,"w") ; fi.write(cont.join("\n").to_s) ; fi.close
return true
else ; return "No input string to write on line."
end
else ; return "Invalid Line specification."
end
else ; return "No such file."
end
end
def insert_line *args # path, line, str
if File.file?(args[0].to_s)
if args[1].is_a?(Integer) or args[1].is_a?(Range)
if args[2].is_a?(String) and args[2].to_s.length >= 1
fi = File.open(args[0].to_s,"r") ; cont = file.read.to_s.split("\n") ; fi.close
d = cont[0..args[1].to_i] ; d << args[2].to_s
#cont[(args[1].to_i+1)..-1].each do |l| ; { d << l } ; end
fi = File.open(args[0].to_s,"w") ; fi.write(d.join("\n").to_s) ; fi.close
return true
else ; return "No input string to write on line."
end
else ; return "Invalid Line specification."
end
else ; return "No such file."
end
end
def delete_line *args # path, line
if File.file?(args[0].to_s)
if args[1].is_a?(Integer)
fi = File.open(args[0].to_s,"r") ; lines = fi.read.to_s.split("\n") ; fi.close
lines.delete_at(args[1])
fi = File.open(args[0].to_s,"w") ; fi.write(lines.join("\n").to_s) ; fi.close
return true
else ; return "Invalid line specification, please enter an integer."
end
else ; return "No such file."
end
end
def get_lines *args # path
if File.file?(args[0].to_s) ; fi = File.open(args[0].to_s,"r") ; cont = fi.read.to_s.split("\n") ; fi.close ; return cont
elsif File.directory?(args[0].to_s) ; return "Input string is a directory, File.get_lines only works on files."
else ; return "No such file."
end
end
def locate *args # dir, name
if File.directory?(args[0].to_s)
found = []
map = Dir.map(args[0].to_s)
if map == [[],[]] ; return "The target directory is empty."
else
if map[0].length > 0
map[0].each do |path|
if path.include?(args[1].to_s) ; found << path.to_s ; end
end
end
if map[1].length > 0
map[1].each do |dir|
if dir.include?(args[1].to_s) ; found << dir.to_s ; end
end
end
end
if found.length == 0 ; return false
else
if found.length == 1 ; return found[0].to_s ; else ; return found ; end
end
else ; return "No such directory."
end
end
def clones? *args # dir
if File.directory?(args[0].to_s)
m = Dir.map(args[0].to_s)
if m == [[],[]] ; return "Target directory is empty."
else
dat = [] ; m[0].each { |f| dat << File.read(f).to_s }
same = []
until dat.length == 0
obj = dat[0].to_s ; dat.delete_at[0] ; path = m[0] ; m.delete_at(0)
if dat.include?(obj.to_s)
same << path.to_s
same << m[dat.index(obj.to_s)].to_s
m[0].delete_at(dat.index(obj.to_s))
dat.delete_at(dat.index(obj.to_s))
end
end
if same.length == 0 ; return false
else ; return same
end
end
else ; return "No such directory."
end
end
def print_lines *args # path, lines
if File.file?(args[0].to_s)
fi = File.open(args[0].to_s,"r") ; lines = fi.read.to_s.split("\n") ; fi.close
if args[1] != nil ; lines = lines[args[1]] ; end
nlines = []
if args[1].is_a?(Integer) ; c = args[0].to_i ; elsif args[1].is_a?(Range) ; c = args[1].to_s.split("..")[0].to_i ; else ; c = 0 ; end
lines.each do |l| ; nlines << c.to_s + " | " + l.to_s ; c += 1 ; end
puts nlines.join("\n").to_s
else ; return "No such file."
end
end
def include? *args
if File.file?(args[0].to_s)
if args[1].to_s.length > 0 ; fi = File.open(args[0].to_s) ; cont = fi.read.to_s ; fi.close ; return cont.to_s.include?(args[1].to_s)
else ; return "No input string."
end
elsif File.directory?(args[0].to_s) ; return "File.include? is for files, not directories."
else ; return "No such file."
end
end
def empty!(path)
if File.file?(path.to_s)
if File.size?(path.to_s) > 0 ; fi = File.open(path.to_s,"w") ; fi.write('') ; fi.close ; return true
else ; return "File is already empty."
end
elsif File.directory?(path.to_s) ; return "File.empty! is for files, not directories, use Dir.empty! if you want to delete all the contents of a directory."
else ; return "No such file."
end
end
def empty?(path)
if File.file?(path.to_s)
fi = File.open(path.to_s,"r") ; cont = fi.read.to_s.split('').length ; fi.close
if cont == 0 ; return true ; else ; return false ; end
elsif File.directory?(path.to_s) ; return "File.empty? is for files, use Dir.empty for directories."
else ; return "No such file."
end
end
def size? *args
if args[0].to_s ; fi = File.open(args[0].to_s,"r") ; cont = fi.read.to_s.split('').length.to_i ; fi.close ; return cont
elsif File.directory?(args[0].to_s) ; return "File.size? is for files, not directories, use Dir.size?."
else ; return "No such file."
end
end
def copy *args #path, newpath
if File.file?(args[0].to_s)
if File.directory?(args[1].to_s)
if File.file?(args[1].to_s + "/" + args[0].to_s.split("/")[-1].to_s) == false
fi = File.open(args[0].to_s,"rb") ; cont = fi.read.to_s ; fi.close
fi = File.open(args[1].to_s + "/" + args[0].to_s.split("/")[-1].to_s,"wb") ; fi.write(cont.to_s) ; fi.close
return true
else ; return "Target directory already contains a file with the same name."
end
else ; return "Input target directory is invalid."
end
else ; return "No such file."
end
end
def move *args #path, newpath
if File.file?(args[0].to_s)
if File.directory?(args[1].to_s)
if File.file?(args[1].to_s + "/" + args[0].to_s.split("/")[-1].to_s) == false
fi = File.open(args[0].to_s,"rb") ; cont = fi.read.to_s ; fi.close
fi = File.open(args[1].to_s + "/" + args[0].to_s.split("/")[-1].to_s,"wb") ; fi.write(cont.to_s) ; fi.close
File.delete(args[0].to_s)
return true
else ; return "Target directory already contains a file with the same name."
end
else ; return "Input target directory is invalid."
end
else ; return "No such file."
end
end
}
##;##;##;##;##;##;##;##;##;##
Array.class_eval{
def syntax
items = []
self.each do |o|
if [Integer,Fixnum,Bignum,Float,Range,Hash].include?(o.class) ; items << o.to_s
elsif o.is_a? String ; items << "\"" + o.to_s + "\""
elsif o.is_a? Symbol ; items << ":" + o.to_s
elsif o == true ; items << "true"
elsif o == false ; items << "false"
elsif o == nil ; items << "nil"
elsif o == [] ; items << "[]"
elsif o.is_a?(Array) ; items << o.to_s
elsif o.is_a?(Method) ; items << ":" + o.to_s
elsif o.is_a?(Class) ; items << o.inspect.to_s
end
end
"[" + items.join(", ").to_s + "]"
end
alias :to_s :syntax
}
##;##;##;##;##;##;##;##;##;##
String.class_eval{
def shuffle ; return self.split('').shuffle.join('').to_s ; end
alias :scramble :shuffle
def base10? ; self.delete("0123456789").empty? ; end
alias :only_numbers? :base10?
def base16? ; self.upcase.delete("0123456789ABCDEF").empty? ; end
alias :only_hex? :base16?
def base36? ; self.upcase.delete("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ").empty? ; end
def only_letters? ; self.upcase.delete("ABCDEFGHIJKLMNOPQRSTUVWXYZ").empty? ; end
def to_b
b = [] ; s = self.to_s.split('')
s.each do |ch|
b << BINARY[CHARACTERS.index(ch.to_s)]
end
return b.join.to_s
end
def from_b
bytes = [] ; s = self.to_s
until s.to_s.length == 0
b = s[0..7].to_s ; s = s[8..-1]
bytes << b.to_s
end
str = ''
bytes.each do |b|
str << CHARACTERS[BINARY.index(b.to_s).to_i].to_s
end
return str.to_s
end
}
##;##;##;##;##;##;##;##;##;##
Bignum.class_eval{
def commas
str = ""
s = self.to_s.split("").reverse ; i=0
s.each do |nc|
if i == 2
i=0 ; str << nc.to_s + ","
else
str << nc.to_s ; i+=1
end
end
if str.to_s[-1].chr.to_s == ","
str = str.reverse.to_s.split("")[1..-1].join("").to_s
else
str = str.reverse.to_s
end
return str.to_s
end
alias :com :commas
}
Fixnum.class_eval{
def commas
str = ""
s = self.to_s.split("").reverse ; i=0
s.each do |nc|
if i == 2
i=0 ; str << nc.to_s + ","
else
str << nc.to_s ; i+=1
end
end
if str.to_s[-1].chr.to_s == ","
str = str.reverse.to_s.split("")[1..-1].join("").to_s
else
str = str.reverse.to_s
end
return str.to_s
end
alias :com :commas
}
Integer.class_eval{
def exponate
n = self ; c=2 ; e=2 ; r = [0,0]
until c > n.to_i
e = 2
until e >= n.to_i ; if c**e == n.to_i ; return [c,e] ; end ; e += 1 ; end
c += 1
end
end
def factors
n = self ; p = [2] ; vn = 2
until vn == n
vn += 1
p << vn
end
p.delete_at(-1)
f1 = 0 ; f2 = 0 ; pd = []
p.each { |pn|
s = n.to_f / pn.to_f
if s.to_s[-2..-1].to_s == ".0"
pd << pn
end
}
pd.each { |p|
if p * p == n
f1, f2 = p, p
else
cd = pd
cd.delete(p)
cd.each { |pr|
if p * pr == n
f1, f2 = p, pr
break
end
}
end
}
return [f1,f2]
end
def prime? ; ; end
alias :exp :exponate ; alias :fac :factors
}
##;##;##;##;##;##;##;##;##;##
Hash.class_eval{
}
##;##;##;##;##;##;##;##;##;##
class Matrix ; def initialize ; ; end ; end
Matrix.class_eval{
}
##;##;##;##;##;##;##;##;##;##
Object.class_eval{
def local_methods ; ms = self.methods ; mets = [] ; ms.each { |m| mets << m.to_s } ; rm = self.class.methods ; self.class.class.methods.each { |m| rm << m.to_s } ; nm = [] ; mets.each { |m| unless rm.include?(m.to_s) ; nm << m.to_s ; end } ; return nm ; end
alias :m :methods ; alias :lm :local_methods
alias :lv :local_variables ; alias :gv :global_variables ; alias :iv :instance_variables
alias :ivs :instance_variable_set ; alias :ivg :instance_variable_get ##dont forget get/set constants and classvariables
alias :iev :instance_eval ; alias :ev :eval
def constants ; MAIN.class.constants ; end ; alias :cn :constants
}
##;##;##;##;##;##;##;##;##;##
##;##;##;##;##;##;##;##;##;##
##;##;##;##;##;##;##;##;##;##
##;##;##;##;##;##;##;##;##;##
class Log
def initialize *args # name of log, directory to store log file, enter nil for no file
if args[0].is_a? String and args[0].to_s.length > 0
@name = args[0].to_s
else
raise "Log must have a name"
end
if args[1].is_a? String and File.directory?(args[1].to_s)
@path = args[1].to_s + "/" + @name.to_s + ".log"
elsif args[1].is_a? String
raise "No such directory"
else
@path = nil
end
@stream = []
if @path != nil
if File.file?(@path)
fi = File.open(@path,"r") ; @stream = fi.read.to_s.split("\n") ; fi.close ; self.write "Log loaded ffrom: " + @path.to_s + "."
else
fi = File.open(@path,"w") ; fi.close ; self.write("Log created with file: " + @path.to_s + ".")
end
else
self.log "Log created."
end
end
def write(str)
if str.length > 0
l = Time.stamp.to_s + " : " + str.to_s ; @stream << l.to_s
if @path != nil ; fi = File.open(@path,"a") ; fi.write(l.to_s + "\n") ; fi.close ; end
return true
else
return false
end
end
def read ; return @stream ; end
def length ; return @stream.length ; end
def clear
@stream = [@stream[0]]
if @path != nil
fi = File.open(@path,"w") ; fi.write(@stream[0].to_s + "\n") ; fi.close
end
return true
end
def empty? ; if @stream.length == 1 ; return true ; else ; return false ; end ; end
alias :w :write
alias :log :write
alias :r :read
end
##;##;##;##;##;##;##;##;##;##
class Password
def initialize *args
if args[0].is_a?(String) and args[0].to_s.length > 0 and args[0].to_s.delete("abcdefghijklmnopqrstuvwxyz0123456789").empty?
@password = args[0].to_s.to_i(36).to_s(2)
else ; raise "Enter a string with only letters and numbers."
end
end
def verify(password) ; if password.to_s.to_i(36).to_s(2) == @password ; return true ; else return false ; end ; end
def change(password,newpassword)
end
def get ; return @password ; end
def set(pw) ; @password = pw ; end
end
##;##;##;##;##;##;##;##;##;##
class Timer
def initialize ; @st = Time.now ; end ; def restart ; @st = Time.now ; end
def time ; return Time.parse_seconds((Time.now - @st).to_s.split(".")[0].to_i).join(":").to_s ; end
end
##;##;##;##;##;##;##;##;##;##
class Taskhost
def initialize
@version = "3.1.2"
import 'timer.rb'
import 'log.rb'
@scopes = [MAIN]
@scope = @scopes[0]
@que = []
@que_thread = nil ; @clean_thread = nil
@doing = []
@taskids = []
@finished = []
@delays = [1.0,1.0] ; @cycles = [0,0]
@running = false ; @start_time = Timer.new
@executing = false ; @cleaning = false
@log = Log.new("Taskhost",LOGDIR)
@instance_id = rand(10000)
if File.file?(INSTDIR + "/config/taskhost_init.rb") ; load INSTDIR + "/config/taskhost_init.rb" ; end
end
def running? ; return @running ; end
def start
@runtime_id = rand(10000)
@start_time = Time.now
if @running == false and @que_thread == nil and @clean_thread == nil
@running = true
@que_thread = Thread.new{ @executing = true
loop do
if @que.length > 0
@que.each do |q|
if Time.now >= q[0]
self.run(q[1].to_s,q[2])
@que.delete(q)
@log.write "QUE EXECUTED: " + Time.stamp.to_s + " Scope: " + q[2].to_s + " Code: " + q[0].to_s.split("\n").join(" ; ").to_s
end
end
end
if @delays[0].is_a?(Float) ; sleep @delays[0].to_f ; end
@cycles[0] += 1
end
@executing = false
}
@clean_thread = Thread.new{ @cleaning = true
loop do
if @doing.length > 0
@doing.each do |t|
if t.alive? == false ; @finished << t ; @log.write "FINISHED: " + Time.stamp.to_s ; @doing.delete(t) ; end
end
end
if @delays[1].is_a?(Float) ; sleep @delays[1].to_f ; end
@cycles[1] += 1
end
@cleaning = false
}
if File.file?(INSTDIR + "/config/taskhost_startup.rb") ; load INSTDIR + "/config/taskhost_startup.rb" ; end
return true
else ; return false
end
end
def stop
if @running == true ; @que_thread.kill ; @que_thread = nil ; @clean_thread.kill ; @clean_thread = nil ; @running = false ; return true
else ; return false
end
end
def que *args # time, code, scope
if args[0].is_a?(Time)
if args[1].is_a?(String)
if Time.now < time ;
@que << [args[0],args[1].to_s,args[2]]
else ; return "Enter a time in the future."
end
else ; return "Enter ruby code."
end
else ; return "Enter a time object"
end
end
def unque(time,ruby_code)
if @que.include?([time,ruby_code.to_s]) ; @que.delete([time,ruby_code.to_s]) ; return true
else ; return false
end
end
def run *args
if args[1] == nil ; s = @scope ; else ; s = args[1] ; end
if args[0].is_a?(String) and args[0].to_s.length > 0
t = Thread.new { s.instance_eval(args[0].to_s) }
id = (rand(10).to_s + rand(10).to_s + rand(10).to_s + rand(10).to_s + rand(10).to_s + rand(10).to_s + rand(10).to_s + rand(10).to_s + rand(10).to_s + rand(10).to_s).to_i.to_s(36)
@doing << t ; @taskids << id ; return id.to_s
else ; return false
end
end
def run_loop *args
if args[1] == nil ; s = @scope ; else ; s = args[1] ; end
if args[0].is_a?(String) and args[0].to_s.length > 0
t = Thread.new{ loop do ; s.instance_eval(args[0].to_s) ; end }
id = (rand(10).to_s + rand(10).to_s + rand(10).to_s + rand(10).to_s + rand(10).to_s + rand(10).to_s + rand(10).to_s + rand(10).to_s + rand(10).to_s + rand(10).to_s).to_i.to_s(36)
@doing << t ; @taskids << id ; return id.to_s
else ; return false
end
end
def run_times *args
if args[1].is_a?(Integer) and args[1].to_i > 0 and args[0].is_a?(String) and args[0].to_s.length > 0
if args[2] == nil ; s = @scope ; else ; s = args[2] ; end
t = Thread.new { args[1].to_i.times { s.instance_eval(args[0].to_s) } }
id = (rand(10).to_s + rand(10).to_s + rand(10).to_s + rand(10).to_s + rand(10).to_s + rand(10).to_s + rand(10).to_s + rand(10).to_s + rand(10).to_s + rand(10).to_s).to_i.to_s(36)
@doing << t ; @taskids << id
return id.to_s
else ; return false
end
end
def kill_task(tid) ; ; end
def kill_all_tasks
if @doing.length > 0 ; @doing.each { |d| d.kill ; @finished << d ; @doing.delete(d) }
else ; return false
end
end
def qued ; return @que ; end
def doing ; return @doing ; end
def finished ; return @finished ; end
def delays? ; return @delays ; end
def set_delays *args ; if args[0].is_a?(Integer) or args[0].is_a?(Float) ; @delays[0] = args[0].to_f ; end ; if args[1].is_a?(Integer) or args[0].is_a?(Float) ; @delays[1] = args[1].to_f ; end ; return @delays ; end
def cycles? ; return @cycles ; end
def executing?
if @que_thread.is_a?(Thread) ; return @que_thread.alive?
else ; return false
end
end
def cleaning?
if @clean_thread.is_a?(Thread) ; return @clean_thread.alive?
else ; return false
end
end
def log ; return @log ; end
def info
str = ["Taskhost Information: "]
str << ""
str << "Host: " + OS.to_s
str << "Runtime ID: " + @runtime_id.to_s
str << "ObjID: " + self.__id__.to_s
str << "Running from: " + INSTDIR.to_s
str << ""
str << "Running: " + @running.to_s + " ( " + self.executing?.to_s + ", " + self.cleaning?.to_s + " )"
str << "Doing: " + @doing.length.commas.to_s
str << "Qued: " + @que.length.commas.to_s
str << "Finished: " + @finished.length.commas.to_s
str << "Cycles: " + @cycles[0].to_s + ", " + @cycles[1].to_s
str << "Delays: " + @delays[0].to_s + ", " + @delays[1].to_s
str << ""
return str.join("\n")
end
def version? ; return @version.to_s ; end
def shutdown
self.stop ; self.kill_all_tasks
File.delete(INSTDIR.to_s + "/config/taskhost_runtime")
return true
end
def add_scope(scope) ; @scopes << scope ; end
def scopes ; return @scopes ; end
def scope *args
if args[0] == nil ; return @scope
else ; @scope = args[0]
end
end
end
##;##;##;##;##;##;##;##;##;##
##;##;##;##;##;##;##;##;##;##
def _and(a,b) ; if a == 1 and b == 1 ; return 1 ; else ; return 0 ; end ; end
def _or(a,b) ; if a == 0 and b == 1 or a == 1 and b == 0 ; return 1 ; else ; return 0 ; end ; end
def _not(a,b) ; if a == 0 and b == 0 ; return 1 ; else ; return 0 ; end ; end
def _nor(a,b) ; if a == 0 and b == 0 or a == 0 and b == 1 or a == 1 and b == 0 ; return 1 ; else ; return 0 ; end ; end
def _nand(a,b) ; if a == 1 and b == 1 or a == 0 and b == 0 ; return 1 ; else ; return 0 ; end ; end
def _xor(a,b) ; if a == 0 and b == 1 or a == 1 and b == 0 or a == 1 and b == 1 ; return 1 ; else return 0 ; end ; end
##;##;##;##;##;##;##;##;##;##
class Evalshell
def initialize *args
@version = "1.7"
unless ENV["OS"] == "Windows_NT" ; raise "This app only runs on windows." ; end
if args[0] == nil ; @scope = self ; else ; @scope = args[0] ; end
if args[1].is_a? String and args[1].to_s.length > 0 ; @name = args[1].to_s ; else ; @name = "untitled session" ; end
import('log.rb')
@log = Log.new(@name.to_s + "_shell-log_",INSTDIR + "/data/logs")
@log.write("Shell Initialized: " + self.to_s + " <ID: " + self.__id__.to_s + " > Scope: " + @scope.to_s + " <ID: " + @scope.__id__.to_s + " > PID: " + $$.to_s + " DIR: " + Dir.getwd.to_s)
@running = false
end
def start *args
if @running == false
if args[0] != nil ; @scope = args[0] ; end
@opid = 0 ; @running = true ; @res = nil
while @running
print @scope.class.to_s + ":" + @opid.to_s + " << "
@inp = gets.chomp.to_s ; @log.write(@scope.class.to_s + "-" + @opid.to_s + " << " + @inp.to_s)
if @inp.to_s == "exit"
print "Are you sure you want to stop the shell? (Y/N) "
if gets.chomp.to_s[0].chr.downcase == "y" ; @shell = false ; @res = "Stopping shell loop..." ; break
else ; @res = "Canceled stopping the shell."
end
elsif @inp.to_s[0..5] == "scope?" ; @res = "Scope: " + @scope.to_s + "<ID:" + @scope.__id__.to_s + ">"
elsif @inp.to_s[0..5] == "scope:"
if @inp.to_s.length > 6
begin ; @scope = @scope.instance_eval(@inp[6..-1]) ; @res = "Scope changed to " + @scope.to_s
rescue => exception
end
else
@res = "Enter the keyword of an object to change scope to."
end
else
if File.file?(INSTDIR + "/data/shortcuts/" + @inp.to_s.downcase + ".lnk")
system("start \"\" \"" + INSTDIR + "\\data\\shortcuts\\" + @inp.to_s + ".lnk\"") ; @res = "Shortcut was executed."
else
begin ; @res = @scope.instance_eval(@inp.to_s)
rescue => exception ; @res = "Exception: " + exception.to_s
end
end
end
@log.write(@scope.class.to_s + ":" + @opid.to_s + " >> " + @res.to_s)
puts @scope.class.to_s + ":" + @opid.to_s + " >> " + @res.to_s
@opid += 1
end
else ; raise "Shell is already running."
end
end
def stop
if @running == true ; @running = false ; return true
else ; return false
end
end
def scope *args ; if args[0] == nil ; return @scope ; else ; @scope = args[0] ; return true ; end ; end
def running? ; return @running ; end
def version ; return @version.to_s ; end ; alias :version? :version
end
##;##;##;##;##;##;##;##;##;##
##;##;##;##;##;##;##;##;##;##
def rands *args ; str = [] ; if args[0].is_a? Integer and args[0].to_i > 0 ; str = [] ; if args[1].is_a? Integer ; base = BASE36CHARACTERS[0..(args[0]-1)] ; else ; base = BASE36CHARACTERS ; end ; if args[1].is_a? Array ; excluded = args[1] ; elsif args[2].is_a? Array ; excluded = args[2] ; else ; excluded = [""] ; end ; args[0].times { c = base.shuffle[0] ; unless excluded.include?(c) ; str << c ; end } ; return str.join('') ; else ; raise "Enter an integer to define the length of the random string." ; end ; end
def lib ; cont = Dir.entries(LIBDIR) ; cont.delete(".") ; cont.delete("..") ; return cont ; end
def import(name) ## load ruby object from library file
if File.file?(LIBDIR + "/" + name.to_s)
load LIBDIR + "/" + name.to_s ; return true
else ; return false
end
end
def apps ; cont = Dir.entries(APPDIR) ; cont.delete(".") ; cont.delete("..") ; return cont ; end
def start(app) ## run ruby app or spawn interpreter and pass app file as peramiter
if File.file?(APPDIR + "/" + app.to_s)
load APPDIR + "/" + app.to_s ; return true
else ; return false
end
end
def os?
if ENV["OS"].to_s == "Windows_NT" ; return "windows"
elsif ENV.to_a.to_s.downcase.include?("andorid") ; return "android"
else ; return "unknown"
end
end
alias :os :os?
def install_core(path)
if core_installed?(path) == false
if File.directory?(path.to_s.split("/")[0..-2].join("/").to_s)
begin ; Dir.mkdir(path) ; rescue ; ; end
end
instdir = path
cfgdir = instdir + "/config" ; if File.directory?(cfgdir) == false ; Dir.mkdir(cfgdir) ; end
datadir = instdir + "/data" ; if File.directory?(datadir) == false ; Dir.mkdir(datadir) ; end
logdir = instdir + "/data/logs" ; if File.directory?(logdir) == false ; Dir.mkdir(logdir) ; end
tempdir = instdir + "/data/temp" ; if File.directory?(tempdir) == false ; Dir.mkdir(tempdir) ; end
appdatadir = instdir + "/data/appdata" ; if File.directory?(appdatadir) == false ; Dir.mkdir(appdatadir) ; end
appdir = instdir + "/apps/" ; if File.directory?(appdir) == false ; Dir.mkdir(appdir) ; end
libdir = instdir + "/lib/" ; if File.directory?(libdir) == false ; Dir.mkdir(libdir) ; end
coredir = instdir + "/cores/" ; if File.directory?(coredir) == false ; Dir.mkdir(coredir) ; end
docdir = instdir + "/data/documents/" ; if File.directory?(docdir) == false ; Dir.mkdir(docdir) ; end
ddocdir = instdir + "/data/documents/doc" ; if File.directory?(ddocdir) == false ; Dir.mkdir(ddocdir) ; end
imgdir = instdir + "/data/images/" ; if File.directory?(imgdir) == false ; Dir.mkdir(imgdir) ; end
grhdir = instdir + "/data/images/graphics" ; if File.directory?(grhdir) == false ; Dir.mkdir(grhdir) ; end
bgdir = instdir + "/data/images/backgrounds" ; if File.directory?(bgdir) == false ; Dir.mkdir(bgdir) ; end
auddir = instdir + "/data/audio/" ; if File.directory?(auddir) == false ; Dir.mkdir(auddir) ; end
alrdir = instdir + "/data/audio/alarms/" ; if File.directory?(alrdir) == false ; Dir.mkdir(alrdir) ; end
rindir = instdir + "/data/audio/ringtones/" ; if File.directory?(rindir) == false ; Dir.mkdir(rindir) ; end
musdir = instdir + "/data/audio/music/" ; if File.directory?(rindir) == false ; Dir.mkdir(rindir) ; end
ssdir = instdir + "/data/audio/system sounds/" ; if File.directory?(ssdir) == false ; Dir.mkdir(ssdir) ; end
dwndir = instdir + "/data/downloads/" ; if File.directory?(dwndir) == false ; Dir.mkdir(dwndir) ; end
encdir = instdir + "/data/encodings/" ; if File.directory?(encdir) == false ; Dir.mkdir(encdir) ; end
extdir = instdir + "/data/extensions/" ; if File.directory?(extdir) == false ; Dir.mkdir(extdir) ; end
curdir = instdir + "/data/cursors/" ; if File.directory?(curdir) == false ; Dir.mkdir(curdir) ; end
fondir = instdir + "/data/fonts/" ; if File.directory?(fondir) == false ; Dir.mkdir(fondir) ; end
certdir = instdir + "/data/certifications/" ; if File.directory?(certdir) == false ; Dir.mkdir(certdir) ; end
File.copy(COREDIR + "/ossy.rb",coredir)
File.copy(INSTDIR + "/ossy.rb",instdir)
File.copy(INSTDIR + "/start.cmd",instdir)
File.copy(DOCDIR + "/doc/keywords.txt",ddocdir)
File.copy(DOCDIR + "/doc/Users Manual.txt",ddocdir)
m = Dir.map(IMGDIR + "/graphics")[0]
if m.length > 0 ; m.each do |f| ; File.copy(f,imgdir + "/graphics") ; end ; end
m = Dir.map(IMGDIR + "/backgrounds")[0]
if m.length > 0 ; m.each do |f| ; File.copy(f,imgdir + "/backgrounds") ; end ; end
m = Dir.map(IMGDIR)[0]
if m.length > 0 ; m.each do |f| ; File.copy(f,imgdir) ; end ; end
m = Dir.map(AUDDIR + "/ringtones")[0]
if m.length > 0 ; m.each do |f| ; File.copy(f,auddir + "/ringtones") ; end ; end
m = Dir.map(AUDDIR + "/alarms")[0]
if m.length > 0 ; m.each do |f| ; File.copy(f,auddir + "/alarms") ; end ; end
m = Dir.map(AUDDIR + "/system sounds")[0]
if m.length > 0 ; m.each do |f| ; File.copy(f,auddir + "/system sounds") ; end ; end
m = Dir.map(AUDDIR)[0]
if m.length > 0 ; m.each do |f| ; File.copy(f,auddir) ; end ; end
m = Dir.map(CERTDIR)[0]
if m.length > 0 ; m.each do |f| ; File.copy(f,certdir) ; end ; end
m = Dir.map(EXTDIR)[0]
if m.length > 0 ; m.each do |f| ; File.copy(f,extdir) ; end ; end
m = Dir.map(ENCDIR)[0]
if m.length > 0 ; m.each do |f| ; File.copy(f,encdir) ; end ; end
m = Dir.map(FONDIR)[0]
if m.length > 0 ; m.each do |f| ; File.copy(f,fondir) ; end ; end
m = Dir.map(CURDIR)[0]
if m.length > 0 ; m.each do |f| ; File.copy(f,curdir) ; end ; end
m = Dir.map(APPDIR)[0]
if m.length > 0 ; m.each do |f| ; File.copy(f,appdir) ; end ; end
m = Dir.map(LIBDIR)[0]
if m.length > 0 ; m.each do |f| ; File.copy(f,libdir) ; end ; end
cfg = [Time.stamp,instdir.to_s.split("/")[-1].to_s]
cfg << rand(1000000).to_s
cfg << ["password".to_s.to_i(36).to_s(2)]
fi = File.open(cfgdir + "/ossy.cfg","w") ; fi.write(cfg.join("\n")) ; fi.close
return "Ossy was installed to " + instdir.to_s
else ; return "Already installed to this directory."
end
end
def verify_password(password) ; if password.to_s.to_i(36).to_s(2) == PASSWORD ; return true ; else ; return false ; end ; end
def uninstall_core *args # dir, deletedata
end
def core_installed?(dir)
if File.directory?(dir)
if File.file?(dir.to_s + "/config/ossy.cfg") and File.file?(dir.to_s + "/ossy.rb") ; return true
else ; return false
end
else ; return "No such directory."
end
end
def system_backup(dir) ## generates a file that can be used to restore a working state to ossy
end
def system_restore(dir,path) ## installs restore file over ossy and removes left over files if keep data is not selected.
end
def install_app(path)
if File.file?(path)
if File.size? > 0
if path.to_s.split(".")[-1].to_s.downcase == "rb"
if File.file?(APPDIR + "/" + path.to_s.split("/")[-1].to_s) == false
File.copy(path.to_s,APPDIR) ; return true
else ; return "Cannot install because another app with the same name is installed."
end
else ; return "File does not have a ruby entension, it cannot be installed."
end
else ; return "File is empty so it was not installed."
end
else ; return "No such file to install."
end
end
def uninstall_app(name)
if File.file?(APPDIR + "/" + name.to_s) ; File.delete(APPDIR + "/" + name.to_s) ; return true
else ; return "No app is installed with that name."
end
end
def install_lib(path)
if File.file?(path)
if File.size? > 0
if path.to_s.split(".")[-1].to_s.downcase == "rb"
if File.file?(LIBDIR + "/" + path.to_s.split("/")[-1].to_s) == false
File.copy(path.to_s,LIBDIR) ; return true
else ; return "Cannot install because another app with the same name is installed."
end
else ; return "File does not have a ruby entension, it cannot be installed."
end
else ; return "File is empty so it was not installed."
end
else ; return "No such file to install."
end
end
def uninstall_lib(name)
if File.file?(LIBDIR + "/" + name.to_s) ; File.delete(LIBDIR + "/" + name.to_s) ; return true
else ; return "No lib file is installed with that name."
end
end
def help *args
if args[0] == nil
fi = File.open(DATADIR + "/documents/doc/keywords.txt","r") ; lines = fi.read.to_s.split("\n") ; fi.close
keys = []
lines.each do |l|
keys << l.to_s.split(" ")[0].to_s.split("(")[0].to_s
end
puts "Manuals:\n - " + keys.join("\n - ").to_s + "\n"
elsif args[0].to_s.downcase == "help"
puts "Welcome to the help function, just calling help returns a list of keywords."
puts "You can pass an arguement to lookup a keyword, to search help content use 'queery'"
elsif args[0].is_a?(String)
str = args[0].to_s
fi = File.open(DATADIR + "/documents/doc/keywords.txt","r") ; lines = fi.read.to_s.split("\n") ; fi.close
key = nil
lines.each do |l|
if str.to_s == l.to_s.split(" ")[0].to_s.split("(")[0].to_s
key = l.to_s.split(" `")[1].to_s.split(";").join("\n").to_s
end
end
if key == nil ; return "No help manual found."
else ; puts key.to_s
end
end
end
def queery *args # term, ignorecase
if args[0] == nil ; return ".queery is used to search through help content for terms. Provide a string as an arguement."
elsif args[1].is_a?(String)
if args[0].length > 0 ;
term = args[0].to_s
else ; return "No input was given for a queery term."
end
end
end
def env
puts "Environment Info: "
puts ""
fi = File.open(CFGDIR + "/ossy.cfg","r") ; id = fi.read.to_s.split("\n")[3].to_s ; fi.close
fi = File.open(CFGDIR + "/ossy.cfg","r") ; date = fi.read.to_s.split("\n")[0].to_s ; fi.close
puts "INSTALL ID: " + id.to_s
puts "INSTALL TIME: " + date.to_s
puts "SYSTEM TIME: " + Time.stamp.to_s
puts "BOOT TIME: " + Time.stamp(BOOT_TIME).to_s
puts "UPTIME: " + Time.parse_seconds((Time.now-BOOT_TIME).to_s.split(".")[0].to_i).join(":")
puts "HOST: " + OS.to_s
puts "DIR: " + Dir.getwd.to_s
puts "INSTDIR: " + INSTDIR.to_s
puts "RUBY INTERPRETER: " + RUBY_VERSION.to_s
puts "CORE: " + CORE_EDITION.to_s
puts "VERSION: " + CORE_VERSION.to_s
puts "BOOT CONFIG: " + CFGDIR.to_s + "/ossy.cfg"
puts "PROCESS ID: " + $$.to_s
puts "MAIN " + MAIN.__id__.to_s
end
CORE_BOOT_TIME = Time.now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment