Skip to content

Instantly share code, notes, and snippets.

@thomasjslone
Created March 17, 2023 13:45
Show Gist options
  • Save thomasjslone/571b8d23f5ef1c36f377b7d4a8ad3ae9 to your computer and use it in GitHub Desktop.
Save thomasjslone/571b8d23f5ef1c36f377b7d4a8ad3ae9 to your computer and use it in GitHub Desktop.
tlc revision 19
VERSION='1.0.019'
unless defined?(VERSION); VERSION = "0"; end
puts "Welcome to the Rubin System installer. Version "+VERSION.to_s
launch_directory=Dir.getwd
launch_time=Time.now
puts ""
puts "Dir: "+launch_directory.to_s
puts ""
puts "Would you like to install to this location? (Y/N)"
inp=gets.chomp.to_s[0].downcase
if inp=="y"
install_dir=Dir.getwd.to_s
else
puts "Enter install directory."
install_dir=nil
loop do
inp=gets.chomp.to_s
if File.directory?(inp.to_s); install_dir=inp.to_s; break
else; puts "Invalid directory."
end
end
end
puts "Confirming, you want to install to dir? (Y/N) ; "+install_dir.to_s
inp=gets.chomp.to_s[0].downcase
if inp!="y"; puts "Fine, then stop wasting my time...\nThe program will exist in 3 seconds."; sleep 3.0; exit; end
if File.directory?(install_dir+"/Rubin"); puts "Cannot install here, there is already an installation."; sleep 3.0; exit; end
#load data
dir=install_dir
if File.file?($0); p = $0
elsif File.file?(launch_directory+"/rubin_installer.rb"); p=launch_directory+"/rubin_installer.rb"
else; raise "The installer file cannot locate its self: "+$0.to_s
end
f=File.open(p,"r"); data = f.read ; f.close
#decode data
data=data.split(";;;"+";;").join("\n")
maindatasep="#1#::#1#::#0#::#0#::#0#"+"::#1#::#1#"
filenamesep="#1#::#1#::#0#::#0#::#0#"+"::#0#::#1#"
filesep="#1#::#1#::#0#::#0#::#0#"+"::#0#::#0#"
index_sep="#1#::#0#::#0#::#0#::#0#"+"::#0#::#1#"
data=data.split(maindatasep)[-1]
index_string=data.to_s.split(index_sep)[0].to_s
file_data=data.split(index_sep)[-1]
##process files
file_data=file_data.split(filesep)
nfile_data=[]
file_data.each do |d|
p=d.split(filenamesep)[0]
di=d.split(filenamesep)[1]
nfile_data<<[p,di]
end
file_data=nfile_data
#proces index
f = index_string.split("??")[0].split("?")
di = index_string.split("??")[1].split("?")
Dir.mkdir(dir.to_s+"/rubin")
di.each do |p|
np=dir+"/"+p
Dir.mkdir(np)
end
# create files
file_data.each do |fd|
p=dir.to_s+"/"+fd[0].to_s
f=File.open(p,"w"); f.write(fd[1].to_s); f.close
end
p=dir.to_s+"/rubin/system/rubin.rb"
f=File.open(p,"r"); dat=f.read; f.close
old_header=dat.split("\n")[0].split("INSTALLATION_HEADER=")[-1]
old_header=eval(old_header.to_s)
dat=dat.split("\n")[1..-1].join("\n")
version=old_header[2].to_s ### for now itll be bugged and write the version as the one of the installing party not the packaged, fix later
head=["installed",(dir+"/rubin").split("//").join("/"),version,Time.now.to_s,ENV["USER"].to_s,rand(99999999999999).to_s(36)]
str="INSTALLATION_HEADER="+head.to_s
ndat=str+"\n"+dat
f=File.open(p,"w"); f.write(ndat); f.close
puts "INSTALL SUCCESS!!!"
puts "The program will exit in 2 seconds"
sleep 2.0
exit
## INSTALL PACKAGE BELOW ; VERSION 0.0.0
#1#::#1#::#0#::#0#::#0#::#1#::#1#/rubin/system/daemond.rb?/rubin/system/definitions.rb?/rubin/launch.rb?/rubin/launch irb.cmd?/rubin/launch rubin.cmd?/rubin/system/rubin.rb?/rubin/data/scripts/systemlogmonitor.rb?/rubin/data/scripts/unpackaged_installer_script.rb?/rubin/documentation.txt?/rubin/change log.txt?/rubin/keyword cheetsheet.txt??/rubin/system?/rubin/bin?/rubin/app?/rubin/class?/rubin/data?/rubin/shortcuts?/rubin/data/appdata?/rubin/data/backups?/rubin/data/config?/rubin/data/definitions?/rubin/data/fileio?/rubin/data/logs?/rubin/data/scripts?/rubin/data/components?/rubin/data/sys?/rubin/data/sys/instance?/rubin/data/temp?/rubin/data/user#1#::#0#::#0#::#0#::#0#::#0#::#1#/rubin/system/daemond.rb#1#::#1#::#0#::#0#::#0#::#0#::#1######################################################################;;;;;## Daemond is our Rubin systems background workings.;;;;;## This file is ran in the context of main>Rubin_System>Daemond;;;;;## The Daemond class requires instance variables defined in this file;;;;;## to be of the Thread class.;;;;;##;;;;;##;;;;;##;;;;;;;;;;;;;;;# @example = Thread.new{};;;;;# @example2 = Thread.new{};;;;;#1#::#1#::#0#::#0#::#0#::#0#::#0#/rubin/system/definitions.rb#1#::#1#::#0#::#0#::#0#::#0#::#1##self.rb#5#;#6#;#9#;#9#;#4#;#5#;#6#;#7#;#9#;#6#;#4### self.rb;;;;;## CHARACTERS;;;;;CHARS = [] ; c = 0 ; 256.times{ CHARS << c.chr.to_s ; c += 1 };;;;;## every 8 bit binary number in cardinal order;;;;;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 };;;;;## every hexicdeimal number in order;;;;;HEX = [] ; c = 0 ; 256.times { h = c.to_s(16) ; if h.length == 1 ; h = "0" + h.to_s ; end ; HEX << h ; c += 1 };;;;;## a list of all 8 bit byte codes for the ascii characters;;;;;#BYTES = [] ; HEX.each do |h| ; BYTES << "\\x" + h ; end;;;;;##system/region termonology;;;;;DAYS = ["sunday","monday","tuesday","wednesday","thursday","friday","saturday"];;;;;MONTHS = ["january","february","march","april","may","june","july","august","september","october","november","december"];;;;;SEASONS = ["spring","summer","autum","winter"];;;;;;;;;;$CHARS = CHARS;;;;;$BINARY = BINARY;;;;;$HEX = HEX;;;;;$DAYS = DAYS;;;;;$MONTHS = MONTHS;;;;;$SEASONS = SEASONS;;;;;;;;;;## logic operators by name;;;;;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;;;;;## random string to compliment random number method;;;;;def rands(*int);if int[0].to_i>=2;t=int[0].to_i;else;t=1;end;s='';t.times{s='';s<<rand(255).chr};return s;end;;;;;## figure out what os the interpreter is on;;;;;;;;;;def windows_host?;if ENV["OS"] == "Windows_NT" and File.directory?("C:/");return true;end;end;;;;;;;;;;## was meant to be added to object, ill do it later;;;;;;;;;;;;;;;#####################################################################################################################################################################################;;;;;## this stuff is for objects that need their parent class to have a method or alias name, class or other objects;;;;;## basically the stuff you define here is in the context of every class object;;;;;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;;;;; ;;;;; def eval_input *args ##multiline console input terminated with {end};;;;; lines=[];;;;; if args.length==1;cont=args[0]; else; cont=self; end;;;;; loop do;;;;; line=gets.chomp;;;;; if line.to_s=="{end}"; break;;;;; else; lines << line.to_s;;;;; end;;;;; end;;;;; code=lines.join("\n")+"\n";;;;; begin; res = cont.instance_eval(code);;;;; rescue => e; res=e.to_s+"\n"+e.backtrace.join("\n");;;;; end;;;;; return res;;;;; end;;;;; ;;;;; #come back with a proc arg;;;;; # def benchmark *args;;;;; # s=Time.now;;;;; # begin; self.instance_eval *args;;;;; # rescue => e;return "Exception: \n"+e.to_s+"\n"+e.backtrace[0..1].join("\n");;;;; # end;;;;; # end;;;;; # alias :bm :benchmark;;;;;;;;;; ;;;;;}#8#;#3#;#5#;#3#;#1#;#8#;#3#;#5#;#3#;#8#;#5##array.rb#5#;#6#;#9#;#9#;#4#;#5#;#6#;#7#;#9#;#6#;#4###array.rb;;;;;Array.class_eval{;;;;; def delete_clones;;;;; na=[];;;;; a=self;;;;; a.each { |i| if na.include?(i) == false ; na << i ; end};;;;; return na;;;;; end;;;;;;;;;;;;;;;}#8#;#3#;#5#;#3#;#1#;#8#;#3#;#5#;#3#;#8#;#5##dir.rb#5#;#6#;#9#;#9#;#4#;#5#;#6#;#7#;#9#;#6#;#4##dir.rb;;;;;Dir.instance_eval{;;;;;;;;;; def exist? inp ##i cant believe this isnt already a thing what if i just learned ruby and im like oh the exist? method is in Dir;;;;; File.exist?(inp);;;;; end;;;;;;;;;; def image(dir,dest,fname);;;;; ;;;;; begin;;;;; ;;;;; name=dir.to_s.split("/")[-1];;;;; map=Dir.map(dir.to_s);;;;; files=map[0];;;;; dirs=map[1]#.sort_by {|x| x.length} #might depend on order mapped to be validly creatable in list order;;;;; ;;;;; nd=[];;;;; dirs.each do |d|;;;;; s=d.split("/"+name+"/")[1..-1].join("/"+name+"/");;;;; nd<<s;;;;; end;;;;; dirs=nd;;;;; ;;;;; #make string of all dirs;;;;; datasep="?*?"+"*?";;;;; dir_tree=dirs.join(datasep);;;;; ;;;;; ##read all the files;;;;; file_data=[];;;;; datasep="#4#:::"+"#4#:"+"::#4#:::#4#:::#1#";;;;; files.each do |f|;;;;; fp = f.split("/"+name+"/")[1..-1].join("/"+name+"/") ;;;;; ff=File.open(f,"rb");file_data<<[fp,datasep,ff.read].join('');ff.close;;;;; end;;;;; ;;;;; ##join all the files;;;;; datasep="#7#:::"+"#7#:"+"::#7#:::#7#:::#3#";;;;; file_data=file_data.join(datasep);;;;; ;;;;; #make final image string;;;;; datasep=("#1#:::"+"#1#:::#1#:::#1#:::#1#");;;;; img=file_data+datasep+dir_tree;;;;; ;;;;; #write image file;;;;; path=name+"-image-"+fname.to_s+".dim";;;;; f=File.open(dest+"/"+path,"wb");f.write(img);f.close;;;;; ;;;;; rescue;return false;;;;; end;;;;; ;;;;; return true;;;;; ;;;;; end;;;;; ;;;;; def build_image(path,dest);;;;; if File.file?(path.to_s) and path.to_s.split(".")[-1].downcase=="dim";;;;; if File.dir?(dest.to_s) ;;;;; name=path.to_s.split("-image")[0].split("/")[-1];;;;; f=File.open(path,"rb");img=f.read;f.close;;;;; ;;;;; #split image into filedata and dirs;;;;; datasep="#1#:::"+"#1#:::#1#:::#1#:::#1#";;;;; img=img.split(datasep);;;;; ;;;;; #split apart directory list;;;;; file_data=img[0];;;;; datasep="?*?"+"*?";;;;; dir_tree=img[1].split(datasep);;;;; ;;;;; #split files apart;;;;; datasep="#7#:::"+"#7#:"+"::#7#:::#7#:::#3#";;;;; files=file_data.split(datasep);;;;; ;;;;; #split file data and paths from eachother ;;;;; file_data=[];;;;; datasep="#4#:::"+"#4#:"+"::#4#:::#4#:::#1#";;;;; files.each {|f| file_data<< f.split(datasep)};;;;; ;;;;; $f=file_data;;;;; ;;;;; #make all dirs;;;;; path=dest+"/"+name;;;;; Dir.mkdir(path);;;;; dir_tree.each do |d|;;;;; begin;;;;; Dir.mkdir(path+"/"+d);;;;; rescue;;;;; end;;;;; end;;;;; ;;;;; #make all files;;;;; file_data.each do |fd|;;;;; fpath=path+"/"+fd[0];;;;; f=File.open(fpath,"wb");f.write(fd[1]);f.close;;;;; end;;;;; ;;;;; return true;;;;; ;;;;; else;raise "Destination directory doesnt exist.!";return false;;;;; end;;;;; else;raise "Method arg[0] must be a dim file.";return false;;;;; end;;;;; end ;;;;;;;;;; def dir *args ## Dir.chdir and Dir.getwd are now in the same method, pass no arguement to get directory and a name of a subdirectory, whole directory or even '..' to change directory ;;;;; if args.length==0;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;;;;; else ; raise "No such directory.";;;;; end;;;;; end;;;;; end;;;;; ;;;;; def view *args ## prints directory contents to screen;;;;; 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 size?(dir) ## gets the size of an entire directory;;;;; 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) # deletes everything in a directory before deleting it;;;;; failed=[];;;;; map=Dir.map(dir);;;;; map[0].each {|f| begin;File.delete(f);rescue;failed<<f;end };;;;; dirs=map[1].reverse;;;;; dirs.each do |d|;;;;; begin;Dir.delete(d);;;;; rescue;failed<<d;;;;; end;;;;; end;;;;; if failed.length==0;return true;;;;; else;return failed;;;;; end;;;;; end ;;;;;;;;;; def delete!(dir);;;;; if self.empty!(dir);;;;; Dir.delete(dir);;;;; return true;;;;; else;return false;;;;; end;;;;; end;;;;;;;;;; ;;;;; ##THIS METHOD NEEDS SOME FUCKING TLC COME ON 20 YEAR OLD JACOB!;;;;; ## searches for files with a name or contents specified;;;;; 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) ## copy utility;;;;; 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) ## move utility;;;;; 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;;;;;;;;;; ## rename utility, this ones a bitch to do efficiently dont expect it anytime soon ;;;;; def rename(dir,newname) ;;;;; ;;;;; end;;;;;;;;;;;;;;; ## find a file or folder in directory and return path;;;;; 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;;;;; ;;;;; ## search a directory for duplicate file data and make a list of paths if found;;;;; ## i dont think ive ever tested this pretty sure its broken;;;;; 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;;;;; ;;;;;;;;;; alias :make :mkdir;;;;;};;;;;;;;;;##this is the same context as self but self is usually defined first and these depend on this class so they have to be after it;;;;;def dir *args ; Dir.dir *args ; end;;;;;def viewdir *args ; puts Dir.view *args ; end;;;;;alias :vd :viewdir;;;;;#8#;#3#;#5#;#3#;#1#;#8#;#3#;#5#;#3#;#8#;#5##file.rb#5#;#6#;#9#;#9#;#4#;#5#;#6#;#7#;#9#;#6#;#4##file.rb;;;;;File.instance_eval{;;;;; ;;;;; def view(path);;;;; if File.file?(path.to_s);;;;; begin;;;;; f=File.open(path.to_s,"r");cont=f.read; f.close;;;;; if cont.length == 0;;;;; return "The file is empty.";;;;; else;;;;; print "\n"+cont.to_s+"\n\n";;;;; return "File: "+path.split("/")[-1].to_s+" Location: "+path.to_s;;;;; end;;;;; rescue; raise "Failed to read file: "+path.to_s;;;;; end;;;;; else; raise "No such file: "+path.to_s;;;;; end;;;;; end;;;;; ;;;;; def make(path);f=File.open(path,"wb");f.close;return true;end;;;;;;;;;; def prepend(p,s);;;;; f=File.open(p,"r");d=f.read;f.close;;;;; f=File.open(p,"w");f.write(s+d);f.close;;;;; return s.length;;;;; end;;;;; ;;;;; def append(p,s);;;;; f=File.open(p,"a");f.write(s);f.close;return s.length;;;;; end;;;;; ;;;;; ## insert string at given character index position (0=first character);;;;; 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 lines(p);;;;; return File.read(p).split("\n");;;;; end;;;;;;;;;; # get a paticular line from a file in one call, line can be an integer or valid range of line index numbers;;;;; 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;;;;; ;;;;; #write over a paticular line or lines, like above pos can be a range;;;;; 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;;;;; ;;;;; ##inserts a line at one or more lines, line breaks not allowed..i think...?;;;;; 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;;;;; ;;;;; ## deletes a line FUCK ADD RANGE SUPPORT;;;;; 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 ;;;;;;;;;; ##works like String.include? but the String is a File instead;;;;; 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;;;;; ;;;;; ##delete file contents;;;;; 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;;;;; ;;;;; ## true if file size 0;;;;; 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;;;;; ;;;;; ## copy utility;;;;; 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;;;;; ;;;;; #move utility;;;;; 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 ;;;;; ;;;;; alias :dir? :directory?;;;;;}#8#;#3#;#5#;#3#;#1#;#8#;#3#;#5#;#3#;#8#;#5##integer.rb#5#;#6#;#9#;#9#;#4#;#5#;#6#;#7#;#9#;#6#;#4##integer.rb;;;;;Integer.class_eval{;;;;;;;;;; def exponate ## manually search for the exponate form of the integer;;;;; 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 ## manually search for the factors of the integer and return the first one found;;;;; 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;;;;; };;;;; [f1,f2];;;;; end;;;;; ;;;;; def prime? ## manually check all the numbers below a number to see if only one and its self divide with out remainder.;;;;; n=self;;;;; rv=true;c=1;l=self-1 ;;;;; until c>=l;;;;; c+=1;;;;; if (self.to_f/c.to_f).to_s.split(".")[-1].to_i==0;;;;; rv=false;c=self;;;;; end ;;;;; end;;;;; rv;;;;; end ;;;;; ;;;;; def surname;;;;; int=self.to_s ;;;;; if int.to_s=="0";int="0";;;;; elsif int[-2..-1]=="11" or int[-2..-1] =="12" or int[-2..-1] =="13";;;;; int<<"th";;;;; elsif int[-1]=="1";int<<"st";;;;; elsif int[-1]=="2";int<<"nd";;;;; elsif int[-1]=="3";int<<"rd";;;;; else;int<<"th";;;;; end;;;;; return int;;;;; end;;;;; ;;;;; def commas ##format large numbers with 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;;;;;;;;;;};;;;;;;;;;;;;;;#8#;#3#;#5#;#3#;#1#;#8#;#3#;#5#;#3#;#8#;#5##string.rb#5#;#6#;#9#;#9#;#4#;#5#;#6#;#7#;#9#;#6#;#4##string.rb;;;;;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_binary ##returns a list of the binary byte form of the string from utf8 only(cause ruby);;;;; b = [] ; s = self.to_s.split('');;;;; s.each do |ch|;;;;; b << BINARY[CHARS.index(ch.to_s)] ;;;;; end;;;;; return b.join.to_s;;;;; end;;;;; def from_binary ## works on strings used with .to_b restoring them to ascii characters;;;;; 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 << CHARS[BINARY.index(b.to_s).to_i].to_s;;;;; end;;;;; return str.to_s;;;;; end ;;;;;;;;;; alias :ew? :end_with?;;;;; alias :sw? :start_with?;;;;; ;;;;; def splice(b,e);;;;; if b.is_a?(String) == false or e.is_a?(String) == false; raise "Arguements require String type.";;;;; elsif b.to_s=="" or e.to_s == ""; raise "Arguements cannot be nilstring.";;;;; end;;;;; s=self;;;;; if s.length<=(b.to_s.length+e.to_s.length); raise "Base string is too small."; end;;;;; pos=0; stack = false; list=[];;;;; if b.length > e.length ; buffer_length = b.length; else; buffer_length = e.length; end;;;;; buffer = []; buffer_length.times{ buffer << "" };;;;; empty_buffer=[]; buffer_length.times{ empty_buffer << "" };;;;; empty_buffer2=[]; buffer_length.times{ empty_buffer2 << "" };;;;; tag1=empty_buffer; b.split('').each { |ch| empty_buffer << ch ; empty_buffer.delete_at(0) };;;;; tag2=empty_buffer2; e.split('').each { |ch| empty_buffer2 << ch ; empty_buffer2.delete_at(0) };;;;; loop do;;;;; if s[pos].to_s==""; break; end ;;;;; buffer << s[pos]; buffer.delete_at(0);;;;; if stack; list << s[pos]; end;;;;; str=buffer.join(''); tag = tag1.join('');;;;; m=true; i=0;;;;; tag.reverse.split('').each{ |ch| if ch.to_s!=str.reverse[i].to_s and ch.to_s != ""; m=false; break; end; i+=1 } ;;;;; if m == true; stack = true; end;;;;; tag = tag2.join('');;;;; m=true; i=0;;;;; tag.reverse.split('').each{ |ch| if ch.to_s!=str.reverse[i].to_s and ch.to_s != ""; m=false; break; end; i+=1 } ;;;;; if m == true; stack = false; end;;;;; pos+=1;;;;; end;;;;; if list.length == 0; return nil ##not nilstring so we can tell the difference on return side;;;;; else; return list.join('')[0..("-"+(e.length+1).to_s).to_i];;;;; end ;;;;; end;;;;; ;;;;; def numerize;;;;; str=self; numbers=[];;;;; str.split('').each{ |ch| ;;;;; n = CHARS.index(ch).to_s;;;;; loop do;;;;; if n.to_s.length < 3; n="0"+n;;;;; else; break;;;;; end;;;;; end;;;;; numbers << n;;;;; };;;;; return numbers.join('') ;;;;; end;;;;; ;;;;; def denumerize;;;;; chars=[];;;;; str=self.split('');;;;; loop do;;;;; if str.length == 0; break; end;;;;; chars<<CHARS[str[0..2].join('').to_i];;;;; 3.times{ str.delete_at(0) };;;;; end;;;;; return chars.join('');;;;; end;;;;; ;;;;; alias :sp :split;;;;; ;;;;;};;;;;;;;;;;;;;;#8#;#3#;#5#;#3#;#1#;#8#;#3#;#5#;#3#;#8#;#5##time.rb#5#;#6#;#9#;#9#;#4#;#5#;#6#;#7#;#9#;#6#;#4##time.rb;;;;;Time.class.class.class_eval{;;;;; def parse_seconds(s) ## take a number of second and compound it into a total of days hours minutes and seconds for timer displays and Time arithmetic;;;;; 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.0;;;;; 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.0 / 60.0;;;;; 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.round];;;;; elsif s.to_f >= 86400.0 ## looses accuracy with massive numbers;;;;; days = s.to_f / 60.0 / 60.0 / 24.0;;;;; rem = s.to_i-(days.to_i*86400);;;;; hours = rem.to_f / 60.0 / 60.0;;;;; minutes = ("." + hours.to_s.split(".")[-1].to_s).to_f * 60;;;;; sec = ("." + minutes.to_s.split(".")[-1].to_s).to_f * 60;;;;; [days.to_i ,hours.round, minutes.round ,sec.round];;;;; end;;;;; end ;;;;;;;;;; def stamp *args ##get a timestamp either from current time or given time object, and convert the two back and fourth by passing them as arguements;;;;; 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;;;;;};;;;;#1#::#1#::#0#::#0#::#0#::#0#::#0#/rubin/launch.rb#1#::#1#::#0#::#0#::#0#::#0#::#1###this file should never be anything more than a shortcut;;;;;## shortcuts to this file can have their own window config;;;;;;;;;;load Dir.getwd.to_s+'/system/rubin.rb'#1#::#1#::#0#::#0#::#0#::#0#::#0#/rubin/launch irb.cmd#1#::#1#::#0#::#0#::#0#::#0#::#1#start irb#1#::#1#::#0#::#0#::#0#::#0#::#0#/rubin/launch rubin.cmd#1#::#1#::#0#::#0#::#0#::#0#::#1#start ruby.exe "launch.rb"#1#::#1#::#0#::#0#::#0#::#0#::#0#/rubin/system/rubin.rb#1#::#1#::#0#::#0#::#0#::#0#::#1#INSTALLATION_HEADER=["installed", "D:/rubin", "1.0.019", "2023-03-13 16:09:24 -0700", "thomas", "3n9yj5its"];;;;;##First line will always be the install headder;;;;;;;;;;## requires are now handeled by config loader.;;;;;;;;;;puts "Checking system...";BOOT_INIT_TIME=Time.now;;;;;boot_log=[];;;;;;;;;;##check workdir;;;;;if Dir.getwd.to_s.downcase!=INSTALLATION_HEADER[1].to_s.downcase;;;;; boot_log << "Workdir is not install dir: "+INSTALLATION_HEADER[1].to_s ;;;;; ;;;;; ## the entire install directory has been unexpectedly moved ;;;;; if File.file?(Dir.getwd+"/system/rubin.rb");;;;; ;;;;; ## code to deal with two rubins in the string, on linux the path is the system path to storage then the drive name;;;;; new_homedir = Dir.getwd;;;;; path=new_homedir+"/system/rubin.rb";;;;; data=File.read(path);;;;; header=data.split("\n")[0];;;;; header=header.split("=")[-1];;;;; header = self.instance_eval(header);;;;; header[1]=new_homedir;;;;; header="INSTALLATION_HEADER="+header.to_s;;;;; ndata=header.to_s+"\n"+data.split("\n")[1..-1].join("\n");;;;; f=File.open(path,"w"); f.write(ndata); f.close;;;;; Dir.chdir(new_homedir);;;;; $homedir=new_homedir;;;;; ##now we gotta restart;;;;; puts "System Install dir was recently moved and info had to be updated before startup.";;;;; puts "Restarting in 3 seconds.";;;;; sleep 3.0;;;;; system("start launch.rb");;;;; sleep 0.2;;;;; exit;;;;; else;;;;; puts "BOOT CANNOT CONTINUE, INSTALLATION NOT FOUND"; sleep 3.0; raise "BOOT FAILED"#exit;;;;; end;;;;; ;;;;;else;$homedir=Dir.getwd;;;;;end;;;;;;;;;;if File.writable?($homedir)!= true;;;;; msg=Time.now.to_s+" : ERROR : CRITICAL : Installation directory is not writable per host!";;;;; boot_log << msg;;;;; puts boot_log.join("\n");;;;; ##try to run anyways ## do something about this;;;;;end;;;;;;;;;;## either remove or revise this, we could add a revocery checker right after here;;;;;## make a temporary log to help if we end up needing revocery.;;;;;f=File.open($homedir+"/bootlog.log","w");f.write("\n"+Time.now.to_s+" : Boot initiated.\n"+boot_log.join("\n"));f.close;;;;; ;;;;;## Ensure system file exists.;;;;;if File.exist?(INSTALLATION_HEADER[1]+"/system/rubin.rb")==false;;;;; msg=Time.now.to_s+" : ERROR : CRITICAL : system file can not be located!";;;;; f=File.open($homedir+"/bootlog.log","a");f.write(msg);f.close;;;;; exit ## ABORT BOOT installation not found;;;;;end;;;;;;;;;;## Boot criteria met, proceed;;;;;msg=Time.now.to_s+" : BOOT SUCCESS.";;;;;f=File.open($homedir+"/bootlog.log","a");f.write(msg+"\n");f.close;;;;;puts "Initializing...";;;;;;;;;;## Startup;;;;;BOOTTIME=Time.now ##;;;;;MAIN=self ##Somewhat global reference to this context.;;;;;INSTANCE=rand(100000);;;;;;;;;;$sysdir=$homedir+"/system" ## Rubin system code.;;;;;$appdir = $homedir+"/app" ## App installation files.;;;;;$classdir=$homedir+"/class" ## Classes loaded with ruby, for redefinitions and adding features.;;;;;$datadir=$homedir+"/data" ## General data directory.;;;;;$appdatadir = $homedir+"/data/appdata" ## Apps store data here.;;;;;$cfgdir= $homedir+"/data/config" ## General config directory.;;;;;$logdir = $homedir+"/data/logs" ## General log directory.;;;;;$userdir = $homedir+"/data/user" ##;;;;;$bindir=$homedir+"/bin" ## For host executable files like interpreters and random exes.;;;;;;;;;;;;;;;class RubinSystem;;;;; ;;;;; VERSION=INSTALLATION_HEADER[2].to_s ## LAST VERSION UPGRADE 8-12-2022;;;;; ;;;;; def initialize;;;;;;;;;; end;;;;; def startup;;;;; ;;;;; if defined?(POST_INITIALIZATION); return "false"; end;;;;; ;;;;; @homedir=$homedir;;;;; @sysdir=@homedir+"/system" ;;;;; @appdir = @homedir+"/app" ;;;;; @classdir=@homedir+"/class" ;;;;; @datadir=@homedir+"/data" ;;;;; @appdatadir = @homedir+"/data/appdata";;;;; @cfgdir= @homedir+"/data/config" ;;;;; @logdir = @homedir+"/data/logs" ;;;;; @userdir = @homedir+"/data/user" ;;;;; @bindir=@homedir+"/bin" ;;;;;;;;;;;;;;; @app=nil;@threads=[] ## reserved for system to launch apps ;;;;; ;;;;; @shell=nil ## systemshell is the components classname, fix later;;;;; @daemond=nil ## reserved for main system threadpool;;;;; @definitions=[];;;;; @apps=[] ## list of app objs and threads loaded ;;;;; @cache = [];;;;;;;;;; @controller = nil;;;;; @inatance = nil;;;;; @install = nil;;;;; @host = nil;;;;; @ruby = nil;;;;; @network = nil ;;;;; ;;;;; @components=[] ;;;;; @loaded_config = [];;;;; @loaded_files = [] ## list of every file loaded since runtime.;;;;; @loaded_apps = [] ## list of app loads on system ##revise these too THIS IS SHIT CODE RIGHT HERE;;;;; @loaded_classes = [] ##### @classes is the name of the variable we actually use;;;;; @loaded_definitions = [];;;;; @loaded_apps = [];;;;; @required_files = [];;;;; ;;;;;;;;;; self.writelog("##### SYSTEM STARTED ###############################################.");;;;; ;;;;; ## enforce file system;;;;; ["/app","/class","/data","/shortcuts","/data/appdata","/data/config","/data/logs","/data/user","/data/definitions","/data/fileio","/data/backups"].each do |f|;;;;; unless File.exist?(@homedir+f);;;;; Dir.mkdir(@homedir+f);;;;; begin self.errorlog("SYSTEM ERROR: Missing directory repaired: "+@homedir+"/"+f.to_s);;;;; rescue;;;;; end;;;;; end;;;;; end;;;;; ;;;;; ##Move boot log into major boot log;;;;; if File.exist?(@homedir+"/bootlog.log");;;;; f=File.open(@homedir+"/bootlog.log","r");log=f.read;f.close;;;;; f=File.open(@logdir+"/bootlog.log","a");f.write(log);f.close;;;;; File.delete(@homedir+"/bootlog.log");;;;; else;self.errorlog("Boot log was missing for this boot.");;;;; end;;;;;;;;;; ;;;;; ## setup config data;;;;; @config_names=["LoadClasses","AutoStartApps","Required",;;;;; "SystemShellAutoStart","DebugMode","DaemondDelay","ShowLogWrites",;;;;; "CtrlNetdir","LoadDefinition","EvaluateFileIO","EvaluateFileIOPrint","RubyGems","AutoScripts","ShellSessions"];;;;; ;;;;; @config_descriptions=["",;;;;; "",;;;;; "",;;;;; "",;;;;; "",;;;;; ""];;;;; ;;;;; @default_config=[true,[],["bundler/inline","open-uri","net/http"],true,true,10,false,"",true,false,false,[],[],true];;;;; @config=@default_config;;;;; @loaded_config="";;;;; ;;;;; ##check for preconfig.cfg first then config.cfg if it doesnt exist, preconfig can be stacked by adding a number to its name.;;;;; puts "Loading config data...";;;;;;;;;; ##check for altconfig first, then if none check for preconfig, if none load default config.;;;;; if File.file?(@cfgdir+"/altconfig.cfg");;;;; altconfig=@cfgdir+"/altconfig.cfg";;;;; f=File.open(altconfig,"r"); altconfig=@cfgdir+"/"+f.read; f.close;;;;; if File.file?(altconfig);;;;; v=self.load_config(altconfig); @loaded_config = altconfig;;;;; str = "Loaded alternate config: "+altconfig.to_s;;;;; self.writelog(str);;;;; puts str.to_s;;;;; else;;;;; str = "Altconfig could not be found.";;;;; self.errorlog(str);;;;; puts str.to_s;;;;; end ;;;;; else ## no altconfig ;;;;; ##check for preconfig;;;;; f=Dir.entries(@cfgdir); f.delete("."); f.delete("..");;;;; if f.length>0;;;;; pf=[];;;;; f.each do |ff| ;;;;; if ff.to_s.downcase[0..8]=="preconfig" and ff.to_s.downcase[-4..-1]==".cfg";;;;; pf<<ff;;;;; end ;;;;; end ;;;;; if pf.length>0;;;;; pf=pf.sort;;;;; preconfig=@cfgdir+"/"+pf[0].to_s;;;;; v=self.load_config(preconfig); @loaded_config = preconfig;;;;; n=preconfig.to_s.split("/")[-1];;;;; str = "Loaded preconfig: "+n.to_s;;;;; self.writelog(str);;;;; begin; File.delete(preconfig);;;;; rescue; SYSTEM.errorlog "Startup failed to remove preconfig: "+pf[0].to_s;;;;; end;;;;; puts str;;;;; else ## no preconfig, try to load defualt config;;;;; if File.file?(@cfgdir+"/config.cfg");;;;; v=self.load_config; @loaded_config = "config.cfg";;;;; str = "Loaded default config.";;;;; self.writelog(str);;;;; puts str;;;;; else ##config missing, repair and boot with ini defualt config;;;;; self.save_config ; @loaded_config = "config.cfg";;;;; str = "Config data was missing or corrupted and had to be restored to default.";;;;; puts str.to_s;;;;; end;;;;; end;;;;; else ##cfgdir is empty;;;;; self.save_config ; @loaded_config = "config.cfg";;;;; str = "Config data was missing or corrupted and had to be restored to default.";;;;; puts str.to_s;;;;; end;;;;; end;;;;;;;;;; ##load cache;;;;; ;;;;; begin; f = File.open(@datadir+"/cache.dat","r"); dat=f.read; f.close;;;;; begin; cache = eval(dat);;;;; if @cache != dat;;;;; @cache = cache;;;;; SYSTEM.writelog "Loaded cache. (Size: "[email protected]_s+")";;;;; else;;;;; end;;;;; rescue; self.repair_cache;SYSTEM.errorlog "Cache is corrupted, it had to be repaired.";;;;; end;;;;; rescue; SYSTEM.errorlog "Startup was unable to read cache file.";;;;; end;;;;;;;;;; ##require files;;;;; ;;;;; if @config[2].is_a?(Array);;;;; begin;;;;; @config[2].each do |f|;;;;; require f.to_s ; @loaded_files<<f ; @required_files << f;;;;; self.writelog("aquired required file: "+f.to_s);;;;; end;;;;; if @loaded_files.length > 0;;;;; if @loaded_files.length>9; s = @loaded_files.length.to_s+" "; else; s = ""; end;;;;; puts s+"Required files were loaded.";;;;; end;;;;; rescue => e;;;;; self.errorlog("Required file produced this exception: "+ e.to_s+"\n"+e.backtrace.join("\n")+"\n");;;;; end;;;;; elsif @config.to_s=="false";;;;; else ## config is invalid type;;;;; self.writelog("Config 2 Requied contains invalid data. It will be repaired.");;;;; ##we could save config if its default, we dont want to do that if its pre or alt so do nothing for now;;;;; end;;;;;;;;;; ##load/install rubygems;;;;; if @config[11].length>0;;;;; puts "Loading Ruby Gems...";;;;; required=@config[11];;;;; gems=`gem list`;gems=gems.split("\n");;;;; gemfiles=[];gems.each {|g| gemfiles<<g.split(" (")[0]};;;;; required.each do |r|;;;;; if gemfiles.include?(r)==false;;;;; self.writelog("Attempting to install rubygem: "+r) ;;;;; puts "Ruby gem is being installed: "+r+" ...";;;;; begin;;;;; gemfile do;;;;; source 'https://rubygems.org';;;;; gem r.to_s;;;;; end;;;;; require r.to_s ; @loaded_files << r ; @loaded_gems << r;;;;; rescue;msg="Ruby gem could not be installed: ";;;;; self.errorlog(msg);;;;;; puts msg;;;;; end;;;;; else;require r.to_s ; @loaded_files << r;;;;; end;;;;; end;;;;; end ;;;;; ;;;;; ##load definition/s if configured;;;;; if @config[8].to_s=="true" and File.file?(@homedir+"/system/definitions.rb") == true;;;;; begin;;;;; SYSTEM.instance_eval(File.read(@homedir+"/system/definitions.rb"));;;;; @loaded_files<<"definitions.rb" ; @loaded_definitions << "definitions.rb";;;;; puts "Applied definition: definitions.rb";;;;; rescue => e;;;;; msg="Definitions.rb produced an excption.\n"+e.to_s+"\n"+e.backtrace[0..5].join("\n");;;;; self.errorlog(msg);;;;; puts msg.to_s;;;;; end ;;;;; ;;;;; elsif @config[8].length>0;;;;; puts "Loading "+@config[8].length.to_s+" definitions...";;;;; @config[8].each do |file|;;;;; begin;;;;; SYSTEM.instance_eval(File.read(@datadir+"/definitions/"+file.to_s)); @loaded_files << file;;;;; @loaded_definitions<<file.to_s; @loaded_files << file.to_s;;;;; puts "Applied definition: "+file.to_s;;;;; rescue => e;;;;; msg="Definitions.rb produced an excption.\n"+e.to_s+"\n"+e.backtrace[0..5].join("\n");;;;; self.errorlog(msg);;;;; puts msg.to_s;;;;; end;;;;; end;;;;; end;;;;;;;;;; ##Load class files if configured to.;;;;; if @config[0]==true;;;;; v=self.load_classes;;;;; if v!=0;puts "Loaded "+v.to_s+" classes.";;;;; else;puts "No classes were found.";;;;; end;;;;; end;;;;; ;;;;; ## config and resources loaded, create system components next;;;;; ;;;;; ############################################################################################################################;;;;; ############################################################################################################################;;;;; ## system embedded component initialization # these components dont need to be loaded because they are in rubin system class;;;;; ############################################################################################################################;;;;;;;;;; @embedded_components = [];;;;; @embedded_component_objects = [];;;;; ;;;;; @daemond=SystemDaemond.new;;;;; @embedded_components << :@daemond;;;;; @embedded_component_objects << @daemond;;;;; ;;;;; @shell=SystemShell.new;;;;; @embedded_components << :@shell;;;;; @embedded_component_objects << @shell;;;;; ;;;;; @instance = Instance.new;;;;; @embedded_components << :@instance;;;;; @embedded_component_objects << @instance;;;;; ;;;;; @app_controller = Apps.new;;;;; @embedded_components << :@app_controller;;;;; @embedded_component_objects << @app_controller;;;;; ;;;;; @host = Host_Manager.new;;;;; @embedded_components << :@host;;;;; @embedded_component_objects << @host;;;;; ;;;;; @install = Installation_Manager.new;;;;; @embedded_components << :@install;;;;; @embedded_component_objects << @install;;;;; ;;;;; ;;;;; @controller = Controller.new;;;;; @embedded_components << :@controller;;;;; @embedded_component_objects << @controller;;;;; ;;;;; @network = Network_Manager.new();;;;; @embedded_components << :@network;;;;; @embedded_component_objects << @network;;;;; ;;;;; @ruby = Ruby_Manager.new();;;;; @embedded_components << :@ruby;;;;; @embedded_component_objects << @ruby;;;;; ;;;;; #keep in mind the final startup method will initialize system components and embedded together after everything is loaded;;;;; ;;;;; ############################################################################################################################;;;;; ############################################################################################################################;;;;; ## system component load, load any files in sysdir besides core files.;;;;; ############################################################################################################################;;;;;;;;;; ##load components;;;;; ;;;;; preconstants=self.constants;;;;; ;;;;; @sysdir_components=[];;;;; @component_objects=[];;;;; @components=[];;;;; c=Dir.entries(@sysdir); c.delete("."); c.delete("..");;;;; c.each {|c| unless c.to_s.downcase=="rubin.rb" or c.to_s.downcase=="daemond.rb" or c.to_s.downcase=="definitions.rb";@components<<c; @sysdir_components<<c.to_s;end};;;;; ;;;;; ;;;;; if @sysdir_components.length > 0;;;;; puts "Loading system components: " + @components.length.to_s;;;;; end;;;;; self.writelog("Loading system components: "[email protected]_s);;;;; ;;;;; if @components.length>0;;;;; @components.each do |c|;;;;; begin;;;;; load @sysdir+"/"+c; @loaded_files << c.to_s;;;;; #SYSTEM.instance_eval(dat);;;;; rescue => e ; puts e.to_s;;;;; self.writelog("Exception loading system component: "+c.to_s);;;;; end;;;;; end ;;;;; end;;;;; ;;;;; postconstants=self.constants;;;;; preconstants.each { |c| postconstants.delete(c) };;;;; preivs=self.instance_variables;;;;; ;;;;; ;;;;; postconstants.each { |c|;;;;; ivn="@"+c.downcase.to_s;;;;; begin;;;;; self.instance_eval(ivn.to_s+"="+c.to_s+".new()");;;;; self.writelog("Initialized component: "+c.to_s);;;;; rescue => e;;;;; self.errorlog("Component initialization failed: "+c.to_s+e.to_s+"\n"+e.backtrace.join("\n"));;;;; end;;;;; };;;;; postivs=self.instance_variables;;;;; preivs.each { |iv| postivs.delete(iv) };;;;; @components=postivs;;;;; ;;;;; @components.each do |c|;;;;; self.instance_eval("@component_objects << "+c.to_s);;;;; end;;;;;;;;;; @component_objects.each do |c|;;;;; if c.methods.include?(:post_initialize);;;;; c.post_initialize;;;;; end;;;;; end;;;;; @embedded_component_objects.each do |c|;;;;; if c.methods.include?(:post_initialize);;;;; c.post_initialize;;;;; end;;;;; @components << ("@"+c.class.to_s.downcase.to_s.split("rubinsystem::")[-1]).to_sym;;;;; end;;;;; ;;;;; @components.delete(:@nilclass) ## like maybe figure out where thats comming from, eventually.;;;;; ;;;;; ;;;;;;;;;; #########################################################################################################################;;;;; #########################################################################################################################;;;;; #########################################################################################################################;;;;;;;;;; self.writelog("Initialization finished.");;;;; ;;;;; end ## end up startup init process;;;;; ;;;;; ;;;;; ;;;;;;;;;; def post_initialization;;;;; unless defined?(POST_INITIALIZATION); ;;;;; ;;;;;;;;;; if @config[1].length>0 ##we have startup apps to run;;;;; msg = "Loading "+@config[1].length.to_s+" startup apps.";;;;; self.writelog(msg);;;;; l=@config[1];;;;; l.each do |app|;;;;; puts "Running autostart app: "+app.to_s;;;;; self.run(app);;;;; end;;;;; end;;;;; ;;;;; self.writelog("System startup successfull.");;;;; puts "Startup complete. Instance: "+self.instance.id.to_s+" "+self.to_s;;;;; puts "Started up in "+(Time.now-BOOT_INIT_TIME).to_s[0..3]+" seconds. "+Time.now.to_s.split(" ")[0..1].join(" ")+", Loaded " + @loaded_files.length.to_s+" files.";;;;; ;;;;; ;;;;; ;;;;; ;;;;; if @config[12].length>0;;;;; @config[12].each do |f|;;;;; if File.file?(@datadir+"/scripts/"+f.to_s);;;;; begin ;;;;; str=File.read(@datadir+"/scripts/"+f.to_s);;;;; begin;;;;; self.instance_eval(str);;;;; self.writelog("Autoscript loaded: "+f.to_s);;;;; puts "Autoscript loaded: "+f.to_s;;;;; rescue => e ; self.errorlog("Autoscript produced an exception: "+ e.to_s);;;;; end;;;;; rescue ##unable to read autoscript;;;;; end;;;;; end;;;;; end;;;;; ;;;;; end;;;;; ;;;;; ############################ ;;;;; if @config[3].to_s.downcase=="true";;;;; self.writelog("Starting system shell.");;;;; if defined?(NOSHELL)==nil;;;;; puts "Starting system shell.";;;;; self.shell.start(self);;;;; end;;;;; end;;;;; ;;;;; end;;;;; end;;;;; ;;;;; ##################################################################################################################################;;;;; ##################################################################################################################################;;;;; ## Startup init completed ready to roll;;;;; ;;;;; ;;;;;;;;;; ##############################;;;;; ;;;;; ;;;;; ## create method links to components ;;;;; begin;;;;; def shell;return @shell;end;;;;; def install;return @install; end;;;;; def ruby; return @ruby; end;;;;; def network;return @network; end;;;;; def host;return @host; end;;;;; def instance;return @instance;end;;;;; def controller; return @controller; end;;;;; def apps; return @app_controller; end;;;;; alias :con :controller;;;;; alias :net :network;;;;; rescue; self.errorlog("Rubin was unable to define method links to all loaded components.");;;;; end ;;;;; ;;;;; def components;return @components; end;;;;; ;;;;; def retry_session ; self.shell.run_last_session_flag ; self.restart("F"); end;;;;; alias :rt :retry_session;;;;; ;;;;; def instance_id; return INSTANCE ; end;;;;; ;;;;; ;;;;; def homedir;return @homedir; end;;;;; def sysdir;return @sysdir; end;;;;; def datadir;return @datadir; end;;;;; def appdir;return @appdir; end;;;;; def classdir; return @classdir; end;;;;; def appdatadir;return @appdatadir; end;;;;; def logdir;return @logdir; end;;;;; def cfgdir;return @cfgdir; end ;;;;; ;;;;; def dirs *args;;;;; if args.length==1 and args[0].is_a?(String);;;;; dirname=args[0];;;;; if dirname.to_s.downcase=="homedir";return @homedir;;;;; elsif dirname.to_s.downcase=="sysdir";return @sysdir;;;;; elsif dirname.to_s.downcase=="appdir";return @appdir;;;;; elsif dirname.to_s.downcase=="classdir";return @classdir;;;;; elsif dirname.to_s.downcase=="datadir";return @datadir;;;;; elsif dirname.to_s.downcase=="logdir";return @logdir;;;;; elsif dirname.to_s.downcase=="cfgdir";return @cfgdir;;;;; elsif dirname.to_s.downcase=="appdatadir";return @appdatadir;;;;; else;return false;;;;; end;;;;; else;return ["homedir","sysdir","appdir","classdir","datadir","logdir","cfgdir","appdatadir"];;;;; end;;;;; end;;;;; ;;;;; def cls; SYSTEM.shell.cls; end;;;;;;;;;; def writelog *args# ad option to print;;;;; if File.file?(@logdir+"/systemlog.log")==false;f=File.open(@logdir+"/systemlog.log","w");f.close;end;;;;; ts=Time.now.to_s.split(" ")[0..1].join(".").split(":").join(".").split("-").join(".");;;;; str="\n"+ts+": "+INSTANCE.to_s+": "+args[0].to_s;;;;; f=File.open(@logdir+"/systemlog.log","a");f.write(str);f.close;;;;; begin;;;;; if args[1].to_s.downcase=="true" and @config[6].to_s != "true"; puts "\n"+args[0].to_;;;;; elsif @config[6].to_s == "true";;;;; puts args[0].to_s;;;;; end;;;;; rescue;;;;; end;;;;; end;;;;;;;;;; def errorlog(msg) ;;;;; ts=Time.now.to_s.split(" ")[0..1].join(".").split(":").join(".").split("-").join(".");;;;; str="\n"+ts+": "+INSTANCE.to_s+": "+msg.to_s;;;;; str2="\n"+ts+": "+INSTANCE.to_s+": An error occured: "+msg.to_s;;;;; f=File.open(@logdir+"/errorlog.log","a");f.write(str.to_s);f.close ;;;;; f=File.open(@logdir+"/systemlog.log","a");f.write(str2.to_s);f.close ;;;;; begin;if @config[4].to_s.downcase=="true";puts "ERROR: "+msg.to_s;end;;;;; rescue;puts "ERROR: "+str.to_s;;;;; end;;;;; end ;;;;;;;;;;;;;;; def load_classdir ## load the contents of the class dir;;;;; self.writelog("Searching for classes to load.");;;;; n=Dir.entries(@classdir)[2..-1];;;;; if n.length>0;;;;; @classes=[];;;;; Dir.entries(@classdir)[2..-1].each do |i|;;;;; begin;load @classdir+"/"+i; @classes<<i.to_s ; @loaded_files << i; @loaded_classes << i;;;;; self.writelog("Loaded class: "+i);;;;; rescue => e;;;;; self.errorlog("Loading class file failed: "+i+"\n"+e.to_s+"\n"+e.backtrace.join("\n").to_s);;;;; end;;;;; end;;;;; return (n.length);;;;; else;;;;; self.writelog("Attempted to load system classes but there were none.");;;;; return 0;;;;; end;;;;; end;;;;;;;;;; alias :load_classes :load_classdir;;;;;;;;;; ##this is actually really confusing and needs a new name, it launches a ruby file in a new window, thats all, shortcut files have .lnk and host component will be dealing with that;;;;; def shortcut(str);;;;; if str[-3..-1].to_s.downcase==".rb";str=str[0..-4];end;;;;; if File.exist?(@homedir+"/shortcuts/"+str+".rb");;;;; odir=Dir.getwd;;;;; Dir.chdir(@homedir+"/shortcuts");;;;; system("start "+str.to_s+".rb");;;;; Dir.chdir(odir);;;;; return true;;;;; ;;;;; else;return false;;;;; end;;;;; end;;;;; ;;;;; def shortcuts?;;;;; Dir.entries(@homedir+"/shortcuts")[2..-1] ;;;;; end;;;;; ;;;;; def get_config;return @config;end;;;;;;;;;; def config *args;;;;; if args.length==0;;;;; cfg=[];@config_names.each {|c| cfg << [c,@config[@config_names.index(c)]]};;;;; return cfg;;;;; elsif args[0].is_a?(Integer) and args.length==1;;;;; return @config[args[0].to_i];;;;; elsif args[0].is_a?(Integer) and args.length==2;;;;; @config[args[0]]=args[1];;;;; return true;;;;; elsif args[0].is_a?(String) and @config_names.include?(args[0]) and args.length==1;;;;; return @config[@config_names.index(args[0])];;;;; elsif args[0].is_a?(String) and @config_names.include?(args[0]) and args.length==2;;;;; @config[@config_names.index(args[0])]=args[1];;;;; return true;;;;; else;return false;;;;; end;;;;; end;;;;; ;;;;; def show_config;;;;; str=""; cfg=[]; i=0 ;;;;; @config_names.each do |n|;;;;; cfg << i.to_s+" "+n.to_s+"= "+@config[i].to_s;;;;; i += 1;;;;; end;;;;; str << "Rubin system config: "+@loaded_cfg_file.to_s+"\n\n";;;;; str << cfg.join("\n").to_s+"\n";;;;; return str;;;;; end ;;;;; ;;;;; ##fix this stupid shit later;;;;; alias :config? :show_config;;;;; ;;;;; def load_config *args ## you can pass a filepath to load config from or leave blank to load default;;;;; file=false;;;;; if args.length==0 and File.file?(@cfgdir+"/config.cfg");;;;; file=@cfgdir+"/config.cfg";;;;; elsif File.file?(args[0].to_s) and args[0].to_s[-4..-1].to_s.downcase==".cfg";;;;; file=args[0].to_s;;;;; else;;;;; return false;;;;; end;;;;; f=File.open(file.to_s,"r");cfg=f.read;f.close;;;;; begin;cfg=eval(cfg);@config=cfg;@loaded_config=file.to_s;;;;; return true;;;;; rescue ## CONFIG DATA CORRUPTED ;;;;; self.errorlog("System config load failed due to corruption.");;;;; return "error" ;;;;; end ;;;;; end;;;;; ;;;;; def save_config *args ## you can pass a name to save config as or blank for default;;;;; if args.length==0;;;;; f=File.open(@cfgdir+"/config.cfg","w");f.write(@config.to_s);f.close;;;;; self.writelog("System config saved.");;;;; return true;;;;; elsif args[0].to_s.length>0;;;;; begin;;;;; f=File.open(@cfgdir+"/"+args[0].to_s+".cfg","w");f.write(@config.to_s);f.close;;;;; self.writelog("System config saved as '"+args[0].to_s+"'.cfg.");;;;; return true;;;;; rescue;;;;; return false;;;;; end;;;;; else;;;;; return false;;;;; end;;;;; end;;;;; ;;;;; def repair_config;;;;; self.writelog("System Config data is being repaired.");;;;; begin;;;;; f=File.open(SYSTEM.cfgdir+"/config.cfg","r"); dat=f.read; f.close;;;;; p = SYSTEM.datadir+"/backups/config-corrupted_backup-"+Time.now.to_s.split(" ")[0..1].join(".").split(":").join(".").split("-").join(".")+".cfg.dat";;;;; f=File.open(p,"w"); f.write(dat); f.close;;;;; SYSTEM.writelog("Old config data was backedup to: "+p.to_s);;;;; rescue; SYSTEM.errorlog("Config repair failed to backup old config data.");;;;; end;;;;; @config=@default_config ; @loaded_config = "config.cfg";;;;; self.save_config ;;;;; end;;;;; ;;;;; def rr; self.restart("F"); end;;;;; ;;;;; ;;;;; def shutdown *args;;;;; proceed=false;;;;; if args[0].to_s[0]=="F";;;;; proceed=true;;;;; else;;;;; puts "\nAre you sure you want to shutdown Rubin? Y/N";;;;; inp=gets.chomp[0].downcase;;;;; if inp=="y";proceed=true;end;;;;; end;;;;; if proceed;;;;; self.writelog("System Shutting down.");;;;; ;;;;; self.save_config;;;;; self.save_cache;;;;; ;;;;; #maybe attempt to call the method shutdown for each class if it exists;;;;; #@apps.each {|a| a[0].defined?(shutdown) } ## do apps only have one thread? thius might be an array of threads;;;;; ;;;;; @apps.each {|a| v = a[-2]; if v.is_a?(Thread); v.kill ; end} ## do apps only have one thread? thius might be an array of threads;;;;; ;;;;; self.writelog("Stopped apps.");;;;; @daemond.kill;;;;; self.writelog("Stopped system daemond.");;;;; begin;;;;; File.delete(@datadir+"/sys/instance/"+INSTANCE.to_s+".dat");;;;; rescue;;;;; end;;;;; self.writelog("System is down.");;;;; puts "System is ready to shutdown";;;;; sleep 5.0;;;;; exit;;;;; end;;;;; end;;;;; ;;;;; def restart *args;;;;; proceed=false;;;;; if args[0].to_s[0]=="F";;;;; proceed=true;;;;; else;;;;; puts "\nAre you sure you want to restart Rubin? Y/N";;;;; inp=gets.chomp[0].downcase;;;;; if inp=="y";proceed=true;end;;;;; end;;;;; if proceed==false; return false; end;;;;; ;;;;; self.save_config;;;;; self.save_cache;;;;; @apps.each {|a| v = a[-2]; if v.is_a?(Thread); v.kill ; end} ## do apps only have one thread? thius might be an array of threads;;;;; self.writelog("Stopped apps.");;;;; @daemond.kill;;;;; begin;File.delete(@datadir+"/sys/instance/"+INSTANCE.to_s+".dat"); rescue;; end;;;;; self.writelog("System is down. Prepairing to restart...");;;;; sleep 1.0;;;;; self.host.launch_new(@homedir+"/launch.rb");;;;; sleep 0.1;;;;; exit;;;;; end;;;;; ;;;;; def start; self.instance.pop; end;;;;; ;;;;; def hibernate ; ; end ## aka system snapshop;;;;; def hibwake ; ; end ;;;;; ;;;;; def altconfig?;;;;; if File.file?(@cfgdir+"/altconfig.cfg");;;;; p = @cfgdir+"/altconfig.cfg";;;;; f=File.open(p,"r"); n=f.read; f.close;;;;; p=@cfgdir+"/"+n;;;;; if File.file?(p); return n.to_s;;;;; else; SYSTEM.errorlog "Altcongig check revealed an invalid value: "+n.to_s;;;;; end;;;;; else; return false;;;;; end;;;;; end;;;;; ;;;;; def preconfig?;;;;; cfgs=[];;;;; Dir.entries(@cfgdir)[2..-1].each { |i| if i.to_s.downcase[0..8]=="preconfig"; cfgs << i; end };;;;; if cfgs.length == 0 ; return false;;;;; else; return cfgs;;;;; end;;;;; end;;;;; ;;;;; def save_altconfig *args;;;;; if args.length == 0;;;;; f=File.open(@cfgdir+"/altconfig.cfg","w"); f.write("config.cfg"); f.close;;;;; return true;;;;; else ;;;;; f=File.open(@cfgdir+"/altconfig.cfg","w"); f.write(args[0].to_s); f.close;;;;; return true;;;;; end;;;;; end;;;;;;;;;; def save_preconfig *args ##give a preconfig number or it will be assigned automatically, this can overwrite existing preconfigs;;;;; if args.length!=0; i=args[0].to_i;;;;; else;;;;; cfgs=[];;;;; c = Dir.entries(@cfgdir); c.delete("."); c.delete("..");;;;; c.each { |i| if i.to_s.downcase[0..8]=="preconfig"; puts "ADDING TO NAME: "+i.to_s; cfgs << i; end };;;;;;;;;; if cfgs.length==0; i= -1;;;;; else; i=cfgs[-1].split("preconfig")[1].split(".cfg")[0].to_i;;;;; end;;;;; i +=1;;;;; end;;;;; path=@cfgdir+"/preconfig"+i.to_s+".cfg";;;;; f=File.open(path,"w"); f.write(@config.to_s); f.close;;;;; return i;;;;; end;;;;;;;;;; def remove_altconfig;;;;; if self.altconfig?;;;;; begin; File.delete(@cfgdir+"/altconfig.cfg"); return true;;;;; rescue; self.errorlog("Failed to delete altconfig file."); return false;;;;; end;;;;; else; return false;;;;; end;;;;; end;;;;;;;;;; alias :delete_altcongig :remove_altconfig;;;;; ;;;;; def lock_preconfig;;;;; begin; f=File.open(@cfgdir+"/lock_preconfig.cfg","w");f.write(Time.stamp);f.close;;;;; rescue; raise "Failed to create '"[email protected]_s+"/lock_preconfig.cfg'";;;;; end;;;;; return true;;;;; end;;;;; ;;;;; def unlock_preconfig;;;;; begin;;;;; File.delete(@cfgdir.to_s+"/lock_preconfig.cfg") ;;;;; rescue; raise "Failed to delete: '"[email protected]_s+"/lock_preconfig.cfg'";;;;; end;;;;; return true;;;;; end;;;;; ;;;;; def preconfig_locked?; return File.file?(@cfgdir+"/lock_preconfig.cfg"); end;;;;;;;;;; def create_preconfig *args ## config, integer;;;;; if args[0].is_a?(Array);;;;; if args[0].length != @config.length;;;;; raise "Given config array does not match system config array length.";;;;; end;;;;; else; raise "First arguement must be config array.";;;;; end;;;;; if args.length==1;;;;; cfgs=[];;;;; Dir.entries(@cfgdir)[2..-1].each { |i| if i.to_s.downcase[0..8]=="preconfig"; cfgs << i; end };;;;; i=cfgs.length;;;;; else;;;;; if args[1].is_a?(Integer) == false;;;;; raise "Second arguement is not an integer.";;;;; else;;;;; i=args[1].to_i;;;;; end;;;;; end;;;;; path=@cfgdir+"/preconfig"+i.to_s+".cfg";;;;; f=File.open(path,"w"); f.write(args[0].to_s); f.close;;;;; return i;;;;; end;;;;;;;;;; def remove_preconfig *args;;;;; pcfgs=[];;;;; Dir.entries(@cfgdir)[2..-1].each { |i| if i.to_s.downcase[0..8]=="preconfig"; pcfgs << i; end };;;;; if pcfgs.length == 0 ; return false;;;;; else;;;;; if args.length==0;;;;; begin; File.delete(@cfgdir+"/"+pcfgs[0].to_s);;;;; rescue; raise "Failed to delete file: "+@cfgdir+"/"+pcfgs[0].to_s;;;;; end;;;;; return pcfgs[0].to_s;;;;; elsif args.length == 2 and args[1].is_a?(Integer) == false; raise "Input requires Integer for second argument.";;;;; elsif args.length == 2 and args[1].is_a?(Integer);;;;; begin; File.delete(@cfgdir+"/"+pcfgs[0].to_s);;;;; rescue; raise "Failed to delete file: "+@cfgdir+"/"+pcfgs[0].to_s;;;;; end;;;;; return args[1];;;;; end;;;;; end;;;;; end;;;;; ;;;;; alias :delete_preconfig :remove_preconfig;;;;; ;;;;;;;;;;;;;;;;;;;; def clear_preconfig;;;;; pcfgs=[]; deleted = 0;;;;; Dir.entries(@cfgdir)[2..-1].each { |i| if i.to_s.downcase[0..8]=="preconfig"; pcfgs << i; end };;;;; if pcfgs.length == 0 ; return 0;;;;; else;;;;; pcfgs.each do |p|;;;;; begin; File.delete(@cfgdir+"/"+p); deleted += 1;;;;; rescue; SYSTEM.errorlog("clear_preconfig : failed to delete file: "+@cfgdir+"/"+p);;;;; end;;;;; end;;;;; return deleted;;;;; end ;;;;; end;;;;;;;;;; alias :wipe_preconfig :clear_preconfig;;;;;;;;;;;;;;;;;;;;;;;;; def cache *args;;;;; if args.length==0;return @cache ##get cache - no args;;;;; elsif args.length==1&&args[0].is_a?(Array);@cache=args[0] ##set cache - Array;;;;; elsif args.length==1&&args[0].is_a?(Integer);return @cache[args[0]] ##get index - Integer;;;;; elsif args.length==2&&args[0].is_a?(Integer);@cache[args[0]]=args[1] ##set index - Integer, Object;;;;; end;;;;; end;;;;; ;;;;; def def_objectify_cache ## we may choose to store temp objects in the cache and need to turn them into strings, the name of the objext and reconstruction tag;;;;; end;;;;; ;;;;; def save_cache;;;;; begin;;;;;; f=File.open(@datadir+"/cache.dat","w");f.write(@cache.to_s);f.close;;;;; self.writelog("Saved cache.");;;;; return @cache.to_s.length;;;;; rescue;return false;;;;; end;;;;; end;;;;; ;;;;; def clear_cache;@cache=[];return nil;end;;;;; ;;;;; def load_cache;;;;; if File.exist?(@datadir+"/cache.dat");;;;; f=File.open(@datadir+"/cache.dat","r");c=f.read;f.close;;;;; begin;@cache=eval(c);;;;; self.writelog("Loaded cache.");;;;; return true;;;;; rescue;;;;; f=File.open(@datadir+"/corrupted_cache.dat","w");f.write(c);f.close;;;;; f=File.open(@datadir+"/cache.dat");f.write("");f.close;;;;; self.errorlog("Error: Load cache failed. Back up was made and cache file was wiped.");;;;; return false;;;;; end;;;;; else;;;;; self.errorlog("Error: Load cache failed, cache file is missing.");;;;; return false;;;;; end;;;;; end;;;;; ;;;;; def repair_cache ## right now it just resets, later maybe corrupt data extractor;;;;; self.writelog("System Cache data is being repaired.");;;;; @cache=[];;;;; self.save_cache;;;;; end;;;;; ;;;;; def loaded_files; return @loaded_files; end;;;;; ;;;;; def system_components;;;;; ;;;;; end;;;;; ;;;;; def components?;;;;; c=Dir.entries(@datadir+"/components").entries; c.delete("."); c.delete("..");;;;; return c;;;;; end;;;;; ;;;;; def apps? ##returns an array of apps that are runnable;;;;; apps=[];;;;; i=Dir.entries(@appdir)[2..-1];;;;; i.each do |p|;;;;; if File.file?(@appdir+"/"+p)and p.split(".")[-1].downcase=="rb";;;;; apps << p[0..-4];;;;; end;;;;; if File.exist?(@appdir+"/"+p) and File.exist?(@appdir+"/"+p+"/"+p+".rb");;;;; apps << p;;;;; end;;;;; end;;;;; return apps ;;;;; end;;;;;;;;;; def scripts?;;;;; scripts=[];;;;; Dir.entries(SYSTEM.datadir+"/scripts")[2..-1].each do |i|;;;;; if File.file?(SYSTEM.datadir+"/scripts/"+i.to_s);;;;; if i.to_s.include?(".")==false or i.split(".")[-1].downcase=="rb";;;;; scripts << i;;;;; end;;;;; end;;;;; end;;;;; return scripts;;;;; end;;;;; ;;;;; def clean_logs;;;;; files = []; cleaned = [];;;;; cont=Dir.entries(SYSTEM.logdir); cont.delete("."); cont.delete("..");;;;; if cont.length == 0 ; return nil;;;;; else; cont.each { |c| if c.downcase.end_with?(".log") or c.downcase.end_with?(".txt"); if File.size?(SYSTEM.logdir+"/"+c)>0; files << c; end; end};;;;; end;;;;; if files.length == 0 ; return "There were no logs to clean"; end;;;;; files.each do |f|;;;;; p = SYSTEM.logdir+"/"+f;;;;; begin;;;;; f=File.open(p,"r"); dat=f.read;f.close;;;;; if dat.split("\n").length > 1000;;;;; SYSTEM.writelog "Cleaning log file: "+p.split("/")[-1];;;;; ndat = [];;;;; d=dat.split("\n")[-999..-1];;;;; File.delete(p);;;;; f=File.open(p,"w"); f.write(ndat); f.close;;;;; SYSTEM.writelog "Cleaned log: "+p.split("/")[-1];;;;; cleaned << p.split("/")[-1];;;;; end;;;;; rescue; SYSTEM.errorlog "Log cleaning was unable to open file: "+f.to_s;;;;; end;;;;; end;;;;; SYSTEM.writelog "Log cleaner cleaned "+cleaned.length.to_s+" logs. "+cleaned.to_s;;;;; if cleaned.length == 0 ; return "No logs were cleaned.";;;;; else; return cleaned.length.to_s+" logs were cleaned. ("+cleaned.to_s+")";;;;; end;;;;; end;;;;; ;;;;; ;;;;; def measure_logs;;;;; files = []; ret = [];;;;; cont=Dir.entries(SYSTEM.logdir); cont.delete("."); cont.delete("..");;;;; if cont.length == 0 ; return nil;;;;; else; cont.each { |c| if c.downcase.end_with?(".log") or c.downcase.end_with?(".txt"); files << c; end};;;;; end;;;;; if files.length == 0 ; return [];;;;; else##;;;;; files.each do |f|;;;;; file=File.open(SYSTEM.logdir+"/"+f.to_s,"r"); dat=file.read.to_s; file.close;;;;; lines=dat.split("\n").length;;;;; ret << [f.to_s,"Lines: "+lines.to_s,"Size: "+File.size?(SYSTEM.logdir+"/"+f.to_s).to_s];;;;; end;;;;; return ret;;;;; end;;;;; end;;;;; ;;;;; def read_log *args;;;;; if args[0].to_s == ""; raise "Input requires logpath."; end;;;;; path = args[0];;;;; if File.file?(SYSTEM.logdir+"/"+path) == false and File.file?(SYSTEM.logdir+"/"+path+".log");;;;; path = SYSTEM.logdir+"/"+path+".log";;;;; puts "FIxed path: "+ path.to_s;;;;; elsif File.file?(SYSTEM.logdir+"/"+path);;;;; path = SYSTEM.logdir+"/"+path;;;;; end;;;;; if args[1].is_a?(Integer); index = args[1].to_i;;;;; elsif args[1].is_a?(Range); index = args[1];;;;; else; index = true;;;;; end;;;;; if File.file?(path);;;;; f = File.open(path,"r"); dat = f.read; f.close;;;;; ndat = dat.split("\n");;;;; if index == true; return ndat;;;;; else; return ndat[index];;;;; end;;;;; else; return "No such file: "+args[0].to_s;;;;; end;;;;; end ;;;;; ;;;;; def logs?;;;;; files = [];;;;; cont=Dir.entries(SYSTEM.logdir); cont.delete("."); cont.delete("..");;;;; if cont.length == 0 ; return [];;;;; else; cont.each { |c| if c.downcase.end_with?(".log") or c.downcase.end_with?(".txt"); files << c; end};;;;; end;;;;; if cont.length>0; return files;;;;; else; return [];;;;; end;;;;; end;;;;; ;;;;; def empty_log(path);;;;; if path.to_s == ""; raise "Input requires logpath."; end;;;;; path = args[0];;;;; if File.file?(SYSTEM.logdir+"/"+path) == false and File.file?(SYSTEM.logdir+"/"+path+".log");;;;; path = SYSTEM.logdir+"/"+path+".log";;;;; puts "FIxed path: "+ path.to_s;;;;; elsif File.file?(SYSTEM.logdir+"/"+path);;;;; path = SYSTEM.logdir+"/"+path;;;;; else; raise "Unable to locate log.";;;;; end;;;;; f = File.open(path,"w"); f.write(Time.now.to_s+" Log was emptied.");f.close;;;;; return true;;;;; end;;;;; ;;;;; def log_include?(log,entry);;;;; # return line no. and time and string of complete entry if found;;;;; end;;;;; ;;;;; def config_files?;;;;; files = [];;;;; c = Dir.entries(SYSTEM.cfgdir); c.delete("."); c.delete("..");;;;; c.each { |fp| if fp.downcase.end_with?(".cfg") or fp.downcase.end_with?(".config"); files << fp ; end };;;;; return files;;;;; end;;;;; ;;;;; def read_config *args;;;;; if args[0].to_s == ""; raise "Input requires String"; else; path = args[0].to_s; end;;;;; if File.file?(path); path = path;;;;; elsif File.file?(SYSTEM.cfgdir+"/"+path); path = SYSTEM.cfgdir+"/"+path;;;;; elsif File.file?(SYSTEM.cfgdir+"/"+path+".cfg"); path = SYSTEM.cfgdir+"/"+path+".cfg";;;;; elsif File.file?(SYSTEM.cfgdir+"/"+path+".config"); path = SYSTEM.cfgdir+"/"+path+".config";;;;; else; raise "No such file: "+path;;;;; end;;;;; begin; f = File.open(path,"r"); dat=f.read;;;;; rescue; raise "File read failed: "+ path.to_s;;;;; end;;;;; if dat.length>0;;;;; begin; data = eval(dat);;;;; if args.length == 1; return data;;;;; elsif args.length == 2 and args[1].is_a?(Integer);;;;; return data[args[1]];;;;; elsif args.length == 2 and args[1].is_a?(Range);;;;; return data[args[1]];;;;; else; raise "Invalid arguement, second arguement should be Integer or Range.";;;;; end;;;;; rescue; raise "Config eval failed: "+path.to_s;;;;; end;;;;; else; raise "Config file was empty: "+path.to_s;;;;; end;;;;; end;;;;; ;;;;; def write_config *args;;;;; if args[0].to_s == ""; raise "Input requires String"; else; path = args[0].to_s; end;;;;; if File.file?(path); path = path;;;;; elsif File.file?(SYSTEM.cfgdir+"/"+path); path = SYSTEM.cfgdir+"/"+path;;;;; elsif File.file?(SYSTEM.cfgdir+"/"+path+".cfg"); path = SYSTEM.cfgdir+"/"+path+".cfg";;;;; elsif File.file?(SYSTEM.cfgdir+"/"+path+".config"); path = SYSTEM.cfgdir+"/"+path+".config";;;;; else; raise "No such file: "+path;;;;; end;;;;; if args[1].is_a?(Integer); pos = args[1];;;;; elsif args[1].is_a?(Range); pos = args[1];;;;; else; raise "Invalid input, second arguement requires Integer or Range.";;;;; end;;;;; if args.length == 3; value = args[2];;;;; else; raise "Error, third argument is required.";;;;; end;;;;; if File.file?(path) == false; raise "No such file: "+path.to_s;;;;; end;;;;; begin; f = File.open(path,"r"); dat=f.read;;;;; rescue; raise "File read failed: "+ path.to_s;;;;; end;;;;; begin; data=eval(dat);;;;; rescue; raise "Failed to read config: "+path.to_s;;;;; end;;;;; data[pos]=value;;;;; begin; f = File.open(path,"w"); f.write(data.to_s); f.close; return true;;;;; rescue; raise "File write failed: "+path.to_s;;;;; end;;;;; end;;;;; ;;;;; ;;;;; ;;;;; ##################################################################################################################################;;;;; ## untested 2023.3.15 v1.0.17;;;;; ;;;;; def load_component *args # name, context;;;;; name = args[0].to_s;;;;; if name.length == 0; raise "Input requires String"; end;;;;; ;;;;; if File.file?(@datadir+"/components/"+name);;;;; path = @datadir+"/components/"+name;;;;; elsif File.file?(@datadir+"/components/"+name+".rb");;;;; path = @datadir+"/components/"+name+".rb";;;;; else;;;;; self.errorlog("load_component failed, no such component: "+args[0].to_s);;;;; return false;;;;; end;;;;; ;;;;; if name.downcase.end_with?(".rb"); name = name[0..-4]; end;;;;; ;;;;; ;;;;; if name.split(".").length==2;;;;; @cont = name.split(".")[0];;;;; name = name.split(".")[1];;;;; else;;;;; @cont = self;;;;; end;;;;;;;;;; puts "ABOUT TO LOAD COMPONENT: "+name.to_s+ " onto object: "+ @cont.class.to_s;;;;; ;;;;; ;;;;; ;;;;; ;;;;; self.writelog "Reading component file for eval: "+path.to_s;;;;; begin; f=File.open(path,"r"); source=f.read; f.close;;;;; rescue; self.errorlog("Readfile failed: "+path.to_s); raise "File failed to read.";;;;; end;;;;; ;;;;; ;;;;; precons = @cont.class.constants;;;;; s=precons.length;;;;; ;;;;; puts "PRECONS: "+ @cont.constants.to_s;;;;; self.writelog "Prepairing to evaluate component: "+name.to_s+" on context: "[email protected]_s;;;;; begin; @cont.instance_eval(source.to_s); @loaded_files<<path.to_s.split("/")[-1];;;;; rescue => e; self.errorlog("Component eval resulted in exception: "+e.to_s+"\n"+e.backtrace.join("\n")); raise "Component encountered exception: "+e.to_s+"\n"+e.backtrace.join("\n");;;;; end;;;;; ;;;;; ###### ISSUE SEEMS TO BE HERE, NOT SEEING WHERE THE EVALUATED CONTENT IS GOING BUT IT WASNT TO cont;;;;; ;;;;; postcons = @cont.constants;;;;; precons.each { |pc| postcons.delete(pc) };;;;; [email protected]_variables;;;;; ;;;;; e=postcons.length;;;;; puts "s: "+s.to_s;;;;; puts "e:"+e.to_s;;;;; ;;;;; puts "Components detected: "+postcons.to_s;;;;; ;;;;; postcons.each do |c|;;;;; begin;;;;; s="@"+c.downcase+"="+c.to_s+".new()";;;;; s2="@"+c.downcase;;;;; @cont.instance_eval(s);;;;; self.writelog "Initialized component object: "+s.to_s;;;;; begin; @cont.instance_eval(s2+".post_initialize"); self.writelog "Post Initialized component: "+s2.to_s+ " of object: "[email protected]_s;;;;; rescue;;;;; end;;;;; rescue;;;;; self.errorlog("Component class init failed: "+s.to_s);;;;; end;;;;; end;;;;;;;;;; [email protected]_variables;;;;; preivs.each{ |v| postivs.delete(v) };;;;; ;;;;; if @cont.class==SYSTEM.class;;;;; postivs.each do |i|;;;;; if @cont == self;;;;; @components << i ;;;;; else;;;;; @components << @cont.class.to_s.downcase+"."+i.to_s;;;;; end;;;;; end ;;;;; end;;;;; ;;;;; self.writelog("Component load completed: "+postivs.length.to_s+" objects were added to "[email protected]_s+".");;;;; ;;;;; return postivs;;;;; end;;;;; ;;;;; alias :lc :load_component;;;;; ;;;;; #############################################################################################################################;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; def runs(scriptname) ## a way to control loading scripts from with in the system, not much else use since .load already does this;;;;; s=@datadir+"/scripts/"+scriptname.to_s; if s.to_s.downcase[-3..-1]!=".rb"; s=s+".rb";end;;;;; begin;str=File.read(s);;;;; begin; self.instance_eval(str) ; @loaded_files << scriptname; @loaded_scripts << scripts_name;;;;; rescue => e; return e;;;;; end;;;;; rescue; return false;;;;; end;;;;; end;;;;;;;;;; def run(appname) ## Appname;;;;; #strip file extension if included;;;;; if appname.to_s[-3..-1].to_s.downcase==".rb";appname=appname.to_s[0..-4];;;;; else;appname=appname.to_s;;;;; end;;;;; ##verify app installed;;;;; if apps?.include?(appname)==false;self.errorlog("Attempted to load an invalid app name: "+appname); return "Invalid app name.";end;;;;; ##verify app path;;;;; if File.exist?(@appdir+"/"+appname+".rb");;;;; path=@appdir+"/"+appname+".rb";;;;; elsif File.exist?(@appdir+"/"+appname+"/"+appname+".rb");;;;; path=@appdir+"/"+appname+"/"+appname+".rb";;;;; else;;;;; ;;;;; end;;;;; ;;;;; ##load and evaluate app script;;;;; begin;;;;; ;;;;; self.writelog("Loading app file: "+appname.to_s+".rb");;;;; f=File.open(path,"r");source=f.read;f.close;;;;; @threads=[];threads=[];@app=nil;@appshell=false;;;;; self.instance_eval(source); @loaded_files << appname ## WTF ARE YOU DOING HERE, i cant remember is there was a reason i went with eval but it works for now so.;;;;; ;;;;; if @threads.length>0;;;;; @threads.each {|t| threads << t };;;;; self.writelog("App: "+appname.to_s+" : has loaded threads: "+threads.length.to_s);;;;; end;;;;; ;;;;; if @app!=nil;appobj=@app#self.writelog("App object loaded: "+appname.to_s);;;;; else;appobj=nil ;;;;; end;;;;; ;;;;; ## eventaully decide if we want there to be an entry for apps that do not return an appobj;;;;; @apps<<[appname,rand(1000000),Time.now.to_s,threads,appobj];;;;; ;;;;; @loaded_apps<<[appname,Time.now.to_s];;;;; @threads=[];@app=nil;;;;;;;;;; self.writelog("App load success: "+appname.to_s);;;;; ;;;;; #start shell for app;;;;; if @appshell.to_s!="false";;;;; self.shell.start(@apps[-1][-1]);;;;; end;;;;; ;;;;; ## return an id for the app if run success;;;;; return @apps[-1][1];;;;; ;;;;; rescue => e ; ;;;;; self.writelog("App load failed: "+appname.to_s);;;;; msg = "App encountered an exception.\n"+e.to_s+"\n"+e.backtrace.join("\n");;;;; self.errorlog(msg);;;;; return msg;;;;; ;;;;; end;;;;;;;;;; end;;;;;;;;;; def delete_app(appname); ; end;;;;;;;;;; def export_app(appname); ; end;;;;; ;;;;; def import_app(filepath);;;;; ;;;;; end;;;;; ;;;;; def export_classes *args;;;;; if args[0].to_s == ""; raise ""; else; name = args[0].to_s end;;;;; if name.to_s.length==0;name="untitled-"+Time.now.to_s+"-definitions.rb";;;;; else ;;;;; name=name.to_s;;;;; if name.downcase.end_with?(".rb") == false ; name = name+".rb"; end;;;;; end;;;;; if args.length == 1;;;;; path=@datadir+"/definitions/"+name.to_s;;;;; elsif args.length == 2 and File.directory?(args[1].to_s);;;;; path=args[1].to_s+"/"+name.to_s;;;;; end;;;;; if Dir.entries(@classdir).length>2;;;;; classes=Dir.entries(@classdir)[2..-1];;;;; files=[];;;;; namesep="#5#;#6#;#9#;#9#;#4#"+";#5#;#6#;#7#;#9#;#6#;#4#";;;;; filesep="#8#;#3#;#5#;#3#;#1#"+";#8#;#3#;#5#;#3#;#8#;#5#";;;;; first=[];;;;; classes.each { |c| ;;;;; if c.to_s.downcase=="self.rb";;;;; f=File.open(@classdir+"/"+c,"r");first<<["#"+c,f.read];f.close;;;;; else;f=File.open(@classdir+"/"+c,"r");files<<["#"+c,f.read];f.close ;;;;; end;;;;; };;;;; if first.length >0 ;files.each{|f| first << f};files=first;end;;;;; joined=[];;;;; files.each {|f| joined<< f[0].to_s+namesep+f[1].to_s};;;;; files=joined.join(filesep);;;;; f=File.open(path,"w");f.write(files);f.close;;;;; return true;;;;; else;return "$classdir is empty?";;;;; end;;;;; end;;;;; ;;;;; #import_classes("E:/rubin/data/definitions/ossy.rb");;;;; def import_classes(path);;;;; if path.downcase.end_with?(".rb") == false; path = path+".rb"; end;;;;; if File.file?(path); dir = Dir.getwd; fpath = dir+"/"+path;;;;; elsif File.file?(@classdir+"/"+path);dir = @classdir; fpath = dir+"/"+path;;;;; elsif File.file?(@datadir+"/definitions/"+path); dir = @datadir+"/definitions"; fpath = dir+"/"+path;;;;; else; raise "Unable to locate definitons file.";;;;; end;;;;; c = Dir.entries(dir); c.delete("."); c.delete("..");;;;; if c.length > 0;;;;; f=File.open(fpath,"r");definition=f.read;f.close;;;;; namesep="#5#;#6#;#9#;#9#;#4#"+";#5#;#6#;#7#;#9#;#6#;#4#";;;;; filesep="#8#;#3#;#5#;#3#;#1#"+";#8#;#3#;#5#;#3#;#8#;#5#";;;;; joined_files=definition.split(filesep); files=[];;;;; joined_files.each {|f| files<<f.split(namesep)};;;;; files.each {|f|;;;;; if f.length==0 or f[0].to_s.length == 0; next; end;;;;; nfpath=@classdir+"/"+f[0].to_s[1..-1];;;;; ff=File.open(nfpath,"w");ff.write(f[1].to_s);ff.close;;;;; };;;;; return true;;;;; else;return "Unable to find class files.";;;;; end;;;;; end;;;;; ;;;;; ;;;;; ##this might not even stay, might get moved to install !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ;;;;; def change_homedir(str) ##this should check to see if install headder path matches dir we are changing to;;;;; if File.directory?(str)# and File.writable?(str);;;;; opath=@homedir;;;;; begin;;;;; Dir.chdir(str);;;;; $homedir=str;@homedir=str;;;;; $sysdir=$homedir+"/system"; @sysdir=@homedir+"/system" ;;;;; $appdir = $homedir+"/app"; @appdir = @homedir+"/app" ;;;;; $classdir=$homedir+"/class"; @classdir=@homedir+"/class" ;;;;; $datadir=$homedir+"/data";@datadir=@homedir+"/data" ;;;;; $appdatadir = $homedir+"/data/appdata"; @appdatadir = @homedir+"/data/appdata";;;;; $cfgdir= $homedir+"/data/config"; @cfgdir= @homedir+"/data/config" ;;;;; $logdir = $homedir+"/data/logs"; @logdir = @homedir+"/data/logs" ;;;;; $userdir = $homedir+"/data/user"; @userdir = @homedir+"/data/user" ;;;;; $bindir=$homedir+"/bin"; @bindir=@homedir+"/bin" ;;;;; rescue;Dir.chdir(opath);return false;;;;; end;;;;; return true;;;;; else;return false;;;;; end;;;;; end;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; def replay_last_session;;;;; self.shell.run_last_session;;;;; return "Last shell session will be evaluated.";;;;; end;;;;; ;;;;; alias :rs :replay_last_session;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; def environment?;;;;; names=["Shell","Daemond","Threads","Components","Classes",;;;;; "Definition","Apps Installed","Apps Loaded","Cache File Size"];;;;; entries=[@shell.class.name.to_s,;;;;; @daemond.class.name.to_s,;;;;; @daemond.thread_pool.length,;;;;; @components,;;;;; @loaded_classes,;;;;; @loaded_definitions,;;;;; @installed_apps,;;;;; @loaded_apps,;;;;; @cache.to_s.length];;;;; list=[];;;;; names.each do |n|;;;;; i = names.index(n);;;;; d = [n,entries[i]];;;;; list << d;;;;; end;;;;; return list;;;;; end;;;;; alias :env? :environment?;;;;; ;;;;; ;;;;; def help *args;;;;; if args.length==0;;;;; puts "##################################################################";;;;; puts "## ";;;;; puts "## Welcome to the Rubin system";;;;; puts "## ";;;;; puts "## ";;;;; puts "## ";;;;; puts "## ";;;;; puts "##################################################################";;;;; elsif args.length==1 and args[0].is_a?(String);;;;; found="Object not found in help file.";;;;; begin;;;;; data=File.read(@datadir+"/help_info.txt");;;;; data=eval(data);;;;; if data.length>0;;;;; data.each do |i|;;;;; if i[0].to_s.downcase==args[0].to_s.downcase;;;;; found=i[1].to_s;break;;;;; end;;;;; end;;;;; end;;;;; rescue;found="Help file could not be read, it may be corrupted or missing.";;;;; end;;;;; return found;;;;; else;;;;; return "Pass a method name or object for help info about it.";;;;; end;;;;; end;;;;; ;;;;; ;;;;; ;;;;; def info?;;;;; puts "##############################";;;;; puts " Rubin system version: "+VERSION.to_s;;;;; puts " Ruby Version: "+RUBY_VERSION.to_s;;;;; puts " Rubygems: ";;;;; puts " Host: "+ENV["OS"].to_s;;;;; puts " Definitions loaded: "[email protected]_s;;;;; puts " Classes loaded: "[email protected]_s;;;;; puts " ";;;;; puts " Boot instance: "+INSTANCE.to_s;;;;; puts " Boot time: "+BOOTTIME.to_s;;;;; sec=Time.now-BOOTTIME;;;;; uptime=Time.parse_seconds(sec);;;;; puts " Uptime: "+uptime.join(":").to_s;;;;; puts "";;;;; a=[];;;;; @apps.each { |aa| a << aa[3].class.to_s };;;;; puts " Apps: "[email protected]_s + " "+a.to_s;;;;; puts " Threads: "[email protected]_pool.length.to_s;;;;; puts " Components: "[email protected]_s + " " + @components.to_s;;;;; puts " Debug mode: "+SYSTEM.config(4).to_s;;;;; puts " ";;;;; puts " Install directory: "+INSTALLATION_HEADER[1].to_s;;;;; puts " Installation Id: "+INSTALLATION_HEADER[5].to_s ;;;;; puts " Installation Date: "+INSTALLATION_HEADER[3].to_s;;;;; puts " ";;;;; m=Dir.map(INSTALLATION_HEADER[1].to_s);;;;; size=0;;;;; m[0].each { |f| size+=File.size(f)};;;;; ;;;;; puts " Installation size: "+size.to_i.commas;;;;; puts " Files: "+m[0].length.to_s;;;;; puts " Directories: "+m[1].length.to_s;;;;; puts " ";;;;; puts " Host Identifier: "+@host_manager.get_host_identifier.to_s;;;;; puts "";;;;; internet=false;;;;; begin;;;;; f=URI.open('https://google.com');;;;; f.close;;;;; internet=true;;;;; rescue;;;;; end;;;;; puts " Internet Access: "+internet.to_s;;;;; puts "";;;;; ;;;;; end;;;;;;;;;;;;;;; ####################################################################################################################################;;;;; ####################################################################################################################################;;;;; ####################################################################################################################################;;;;; ####################################################################################################################################;;;;; ####################################################################################################################################;;;;; ####################################################################################################################################;;;;; ####################################################################################################################################;;;;; ############ ;;;;; ############ ;;;;; ############ ;;;;; ############ ;;;;; ############ ;;;;; ############ Components section you blind motherfucker.;;;;; ############ ;;;;; ############ ;;;;; ############ ;;;;; ############ ;;;;; ####################################################################################################################################;;;;; ####################################################################################################################################;;;;; ####################################################################################################################################;;;;; ####################################################################################################################################;;;;; ####################################################################################################################################;;;;; ####################################################################################################################################;;;;; ####################################################################################################################################;;;;; ## Embedded System Components;;;;; ####################################################################################################################################;;;;; ;;;;; class SystemDaemond ##System daemond is where automatic system stuff happens, later we will have different daemond versions and store the code internally;;;;;;;;;; def initialize;;;;; end;;;;;;;;;; ;;;;; def post_initialize;;;;; ;;;;; unless defined?(@@DAEMOND_RUNNING);@@DAEMOND_RUNNING=true;;;;; ;;;;; thread_pool=[];;;;; eval(File.read($sysdir+"/daemond.rb")) ##this file contains the daemond script;;;;; ;;;;; if self.instance_variables.length>0;;;;; self.instance_variables.each { |iv|;;;;; thread_pool<<self.instance_variable_get(iv.to_s);;;;; ;;;;; };;;;; else## this means the daemond file was empty or corrupted or for some whackey reason didnt contain the daemond script;;;;; end;;;;; ;;;;; @running=true;;;;; @thread_pool=thread_pool ##daemond thread and other system threads.;;;;; @grave_pool=[] ## where dead threads go for fun;;;;; ;;;;; ##################################################;;;;; ##################################################;;;;; ## def interal threads and run them automatically;;;;; ;;;;; ;;;;; @daemond=Thread.new{loop do;;;;; ##create instance tag by writing the time in a file to show we are running;;;;; begin;;;;; fp=SYSTEM.datadir+"/sys/instance/"+INSTANCE.to_s+".dat";;;;; f=File.open(fp,"w");f.write(Time.stamp);f.close;;;;; ##scan all instance files and remove any abandoned instances(clicking close with out shutting down or some other abrupt exit);;;;; i=Dir.entries(SYSTEM.datadir+"/sys/instance"); i.delete("."); i.delete("..");;;;; if i.length>0;;;;; i.each do |ii|;;;;; fp=SYSTEM.datadir+"/sys/instance/"+ii;;;;; str=File.read(fp);;;;; if str.length==0;;;;; File.delete(fp) ;;;;; SYSTEM.writelog("Outdated and corrupted instance file removed. ("+ii.to_s+")");;;;; else;;;;; stamp=Time.stamp(str);;;;; sec=Time.now-stamp;;;;; if sec.to_i>15;;;;; File.delete(fp) ;;;;; SYSTEM.writelog("Outdated instance file removed. ("+ii.to_s+" ; "+str.to_s+" )");;;;; end;;;;; end;;;;; ;;;;; end;;;;; end;;;;; rescue;# SYSTEM.errorlog "Instance update thread had a write failure.";;;;; end;;;;; sleep 5;;;;; end};;;;;;;;;; ;;;;; @system_heartbeat=Thread.new{;;;;; $system_heartbeat=0;;;;; loop do;;;;; ##most important few things are done here probably;;;;; $system_heartbeat+=1;;;;; sleep SYSTEM.config(5) #daemond delay default;;;;; end;;;;; };;;;;;;;;; ####################################################;;;;; ##end of internal thread definitions;;;;; end;;;;; ;;;;; def thread_pool; return @thread_pool; end;;;;; ;;;;; def grave_pool; return @grave_pool; end;;;;; ;;;;; def push_thread(thread);;;;; if thread.is_a?(Thread);@thread_pool<<thread;end;;;;; end;;;;; ;;;;; def kill;;;;; if @thread_pool.length>0;;;;; @thread_pool.each { |t| begin ; t.kill ; rescue ;; end };;;;; @thread_pool.each {|t| @grave_pool<<t};;;;; @thread_pool=[];;;;; @running=false;;;;; return true;;;;; else;return false;;;;; end;;;;; end;;;;; ;;;;; def restart;;;;; self.kill;;;;; eval(File.read($sysdir+"/daemond.rb"));;;;; @running=true;;;;; if self.instance_variables.length>0;;;;; instance_variables.each { |iv|;;;;; ;;;;; i=self.instance_variable_get(iv.to_s) ;;;;; if i.is_a?(Thread);;;;; if i.alive?; @thread_pool << i ; end;;;;; end;;;;; };;;;; else## this means the daemond file was empty or corrupted or for some whackey reason didnt contain the daemond script;;;;; end;;;;; return true;;;;; end;;;;; ;;;;; end;;;;; ;;;;; end;;;;; ;;;;; ##################################################################################################################################;;;;; ## Shell;;;;; ;;;;; class SystemShell;;;;; def initialize;;;;; @context=nil;;;;; @context_history=[];;;;; @previous_session= [];;;;; @session=[] ##input log;;;;; @history=[] ## output log;;;;; @cid=nil;;;;; @keep_log=true;;;;; @log=[];;;;; @nolog=false ## use this to not log shell input/output;;;;; ;;;;; if File.exist?($logdir+"/system_shell.log")==false;;;;; f=File.open($logdir+"/system_shell.log","w");f.write("");f.close;;;;; end;;;;; if File.exist?($logdir+"/shellsession.log")==false;;;;; f=File.open($logdir+"/shellsessionmaster.log","w");f.write("");f.close;;;;; end;;;;;;;;;; if File.exist?($logdir+"/shellsession.log")==false;;;;; f=File.open($logdir+"/shellsession.log","w");f.write("");f.close;;;;; else##;;;;; f = File.open($logdir+"/shellsession.log","r"); dat=f.read; f.close;;;;; ndat="#Session####################"+dat.split("\n").join("\n")+"\n";;;;; f = File.open($logdir+"/shellsessionmaster.log","a"); f.write(ndat); f.close;;;;; @previous_session = dat.split("\n"); @previous_session.delete("");;;;; f=File.open($logdir+"/shellsession.log","w"); f.write(""); f.close;;;;; end;;;;; ;;;;; ;;;;; @password_entry_mode=false;;;;; end;;;;; ;;;;; def start *args;;;;; if File.file?($datadir+"/shellreplay.flag") and self.previous_session.length>0;;;;; puts "The shell is prepairing to re-evaluate the previous session.";;;;; begin; File.delete($datadir+"/shellreplay.flag");;;;; rescue; SYSTEM.errorlog "Shell replay session was unable to delete the flag file, you need to delete it manually or the shell will trigger a replay on the next run.";;;;; end;;;;; begin; self.run_last_session; sleep 10.0; self.enter_main_loop(SYSTEM);;;;; rescue; puts "FAILED TO RUN LAST SESSION";;;;; end;;;;; else;;;;; if args.length>0;self.enter_main_loop(args[0]);;;;; else; self.enter_main_loop;;;;; end;;;;; end;;;;; end;;;;; ;;;;; def enter_main_loop *args;;;;; if args.length==0;context=MAIN;else;context=args[0];end;;;;; @main_loop=true;@cid=0;@context=context;;;;; while @main_loop ########################;;;;; print @context.class.to_s+":"[email protected]_s+"<< ";;;;; @input = gets.chomp;res=nil;;;;; if @password_entry_mode == false;;;;; @log<<@context.class.to_s+":"[email protected]_s+"<< "+@input unless @nolog;;;;; f = File.open($logdir+"/system_shell.log","a"); f.write(@log[-1].to_s+"\n"); f.close;;;;; end ;;;;; if @password_entry_mode == false ; @session << @input and SYSTEM.config(13) == true;;;;; begin;f = File.open($logdir+"/shellsession.log","a"); f.write(@input.to_s+"\n"); f.close;;;;; rescue; SYSTEM.errorlog("Shell error failed to write to session");;;;; end;;;;; end;;;;; ;;;;;;;;;; if @input == "exit";@main_loop=false;res="Exiting shell.";;;;; elsif @input[0..8]=="*context=" and @input.to_s.length>9;;;;; begin;@context=eval(@input.to_s);@context_history<<@context;res="Evaluation context has been changed.";;;;; rescue; res = "Unable to change context to: " + @input[8..-1].to_s;;;;; end;;;;; ;;;;; elsif @input.to_s.downcase=="*cls";system("CLS");res=:NO_RESULT;;;;; else ##input isnt a builtin command;;;;; begin;;;;; res = @context.instance_eval(@input);;;;; rescue => e;;;;; res = "Input caused an exception.\n"+e.to_s+"\n"+e.backtrace[0..1].join("\n");;;;; end;;;;; end;;;;; ;;;;; ;;;;; unless res==:NO_RESULT;;;;; print @context.class.to_s+":"[email protected]_s+">> "+res.to_s+"\n";;;;; end;;;;; ;;;;; @log<<@context.class.to_s+":"[email protected]_s+">> "+res.to_s+"\n" unless @nolog;;;;; f = File.open($logdir+"/system_shell.log","a"); f.write(@log[-1].to_s+"\n"); f.close;;;;;;;;;; ;;;;; @cid+=1;@password_entry_mode=false;;;;; end ##this is the end of the loop ##########;;;;; end;;;;; ;;;;; def log; return @log; end;;;;; ;;;;; ;;;;; ;;;;; def stop;;;;; @main_loop=false;;;;; end;;;;; ;;;;; def type_password;;;;; p = gets.chomp;;;;; return p;;;;; end;;;;; ;;;;; def session; return @session; end;;;;; ;;;;; def previous_session; return @previous_session; end;;;;; ;;;;; ;;;;; ;;;;; def evaluate_session(session);;;;; if session.is_a?(Array) == false; raise "Input requires an array."; end;;;;; if @context == nil; @context = SYSTEM; end;;;;; session.each do |line| ;;;;; print @context.class.to_s+":"[email protected]_s+"<< ";;;;; @input = line.to_s; print line.to_s+"\n";;;;; ;;;;; if @input == "exit";@main_loop=false;res="Exiting shell.";;;;; elsif @input[0..8]=="*context=" and @input.to_s.length>9;;;;; begin;@context=eval(@input.to_s);@context_history<<@context;res="Evaluation context has been changed.";;;;; rescue; res = "Unable to change context to: " + @input[8..-1].to_s;;;;; end;;;;; else ##input isnt a builtin command;;;;; begin;;;;; res = @context.instance_eval(line.to_s);;;;; rescue => e;;;;; res = "Input caused an exception.\n"+e.to_s+"\n"+e.backtrace[0..1].join("\n");;;;; end;;;;; end;;;;; ;;;;; unless res==:NO_RESULT;;;;; print @context.class.to_s+":"[email protected]_s+">> "+res.to_s+"\n";;;;; end;;;;; @log<<@context.class.to_s+":"[email protected]_s+">> "+res.to_s+"\n";;;;; @cid+=1;@password_entry_mode=false;;;;; end;;;;; ;;;;; end;;;;; ;;;;; def run_last_session;;;;; if @previous_session.length>0;;;;; previous_session=@previous_session;;;;; last=previous_session[-1].to_s.downcase;;;;; if last == "rr" or last.split(".")[-1][0..6]=="restart";;;;; puts "REMOVED RESTART COMMAND FROM SESSION BEFORE RNNING";;;;; previous_session.delete_at(-1);;;;; end;;;;; ;;;;; self.evaluate_session(previous_session);;;;; return "Running "+@previous_session.length.to_s+" commands.";;;;; else; raise "Previous session is empty.";;;;; end;;;;; end;;;;; ;;;;; ;;;;; ##this probably needs to be moved to rubin in order to work properly;;;;; # def run_last_session_flag;;;;; # begin; f = File.open($datadir+"/shellreplay.flag","w");f.close; return true;;;;; # rescue; raise "Shell flag file coouldnt be written.";;;;; # end;;;;; # end;;;;; ;;;;; ;;;;; def cls; system("CLS"); return "The screen was cleared."; end;;;;; ;;;;; ;;;;; def sessions *args;;;;; begin; f= File.open(SYSTEM.datadir+"/logs/shellsessionmaster.log","r"); dat=f.read; f.close;;;;; rescue; raise "Failed to read session file.";;;;; end;;;;; ;;;;; sessions = [];;;;; ndat = dat.split("#Session####################");;;;; if ndat.length == 0 ; raise "Failed to read session data for shell."; end;;;;; ndat.each { |da| sessions << da.split("\n"); sessions[-1].delete("") };;;;; ;;;;; if args[0].is_a?(Integer);;;;; return sessions[args[0].to_i];;;;; else##;;;;; return sessions;;;;; end;;;;; end;;;;; ;;;;; end;;;;; ;;;;; ################################################################################################################################;;;;; ################################################################################################################################;;;;; ## instance;;;;; ;;;;; class Instance;;;;; def initialize;;;;; @id=INSTANCE;;;;; end;;;;; ;;;;; def locals?;;;;; i=Dir.entries(SYSTEM.datadir+"/sys/instance");;;;; if i.length>0;;;;; l=[];fl=[];;;;; i.each do |f|;;;;; if f.to_s.downcase[-4..-1]==".dat" and f.to_s[0..-5].delete("0123456789").length==0;;;;; l<<f[0..-5];;;;; end;;;;; end;;;;; if l.length>0;;;;; l.each do |ll|;;;;; f=File.read(SYSTEM.datadir+"/sys/instance/"+ll.to_s+".dat");;;;; str=Time.stamp(f);;;;; sec=Time.now-str;;;;; if sec.to_i<30;;;;; fl<<ll;;;;; end;;;;; end;;;;; return fl;;;;; else; return [];;;;; end;;;;; else; return [];;;;; end;;;;; end;;;;; ;;;;; def id ; return INSTANCE ; end;;;;; ;;;;; def pop;;;;; SYSTEM.host.launch_new(SYSTEM.homedir+"/launch.rb");;;;; end;;;;; ;;;;;end;;;;;;;;;; ################################################################################################################################;;;;; ################################################################################################################################;;;;; ## app controller ## eventually we will migrate the load app method here, maybe;;;;; ;;;;; class Apps;;;;; def initialize;;;;; @apps=SYSTEM.instance_variable_get("@apps");;;;; end;;;;; ;;;;; def apps; return @apps; end;;;;;;;;;; def running?; return @apps.length; end;;;;;;;;;; def get *args;;;;; if args[0].is_a?(String);;;;; rapp=false; if @apps.length > 0; @apps.each{ |a| if a[1].to_s==args[0].to_s; rapp = a[-1]; break; end } ; end;;;;; return rapp;;;;; elsif args[0].is_a?(Integer); return @apps[args[0]];;;;; else; return @apps ;;;;; end;;;;; end;;;;; ;;;;; def threads *args;;;;; if args.length == 0 ; return @apps;;;;; elsif args[0].is_a?(String);;;;; rapp=false; if @apps.length > 0; @apps.each{ |a| if a[1].to_s==args[0].to_s; rapp = a[3]; break; end }; end;;;;; return rapp;;;;; elsif args[0].is_a?(Integer); return @apps[args[0]];;;;; end;;;;; end ;;;;; ;;;;; end;;;;; ;;;;; ;;;;; ################################################################################################################################;;;;; ################################################################################################################################;;;;; ##;;;;; ;;;;; class Host_Manager;;;;; def initialize;;;;; ##;;;;; @host="Undetermined.";;;;; ;;;;; ##build windows autostart path;;;;; @auto_start_dir=ENV["HOMEDRIVE"]+"/ProgramData/Microsoft/Windows/Start Menu/Programs/StartUp";;;;; ;;;;; end;;;;; ;;;;; def request(cmd); return system(cmd.to_s); end;;;;; ;;;;; def call(cmd); self.instance_eval("`"+cmd.to_s+"`"); return nil; end;;;;; ;;;;; def launch(path) ## run file in current session;;;;; if File.file?(path);;;;; begin;;;;; Dir.chdir(path.to_s.split("/")[0..-2].join("/"));;;;; n=path.to_s.split("/")[-1];;;;; system(n.to_s);;;;; return true;;;;; rescue; return false;;;;; end;;;;; else;return false;;;;; end;;;;; end;;;;; ;;;;; def launch_new(path) ## run file in new window;;;;; if File.file?(path);;;;; begin;;;;; cdir=Dir.getwd;;;;; Dir.chdir(path.to_s.split("/")[0..-2].join("/"));;;;; n=path.to_s.split("/")[-1];;;;; system("start "+n.to_s);;;;; Dir.chdir(cdir);;;;; return true;;;;; rescue; return false;;;;; end;;;;; else;return false;;;;; end;;;;; end;;;;; ;;;;; def get_host_identifier; return ENV["COMPUTERNAME"]+":"+ENV["OS"]+":"+ENV["platformcode"]+":"+ENV["PROCESSOR_ARCHITECTURE"]+":"+ENV["PROCESSOR_IDENTIFIER"]+":"+ENV["PROCESSOR_REVISION"]; end ;;;;; ;;;;; ## get a list of drives mounted;;;;; def drives;;;;; mounted=[];;;;; ["C:/","D:/","E:/","F:/"].each { |d| if File.directory?(d);mounted<<d;end };;;;; return mounted;;;;; end;;;;; ;;;;; ## figure out which drive host is installed on;;;;; def host_drive;;;;; return ENV["HOMEDRIVE"];;;;; end;;;;; ;;;;; def procs;;;;; str=`TASKLIST`;;;;; procs=[];;;;; str.split("\n")[3..-1].each do |line|;;;;; name=line[0..24].split(" ").join("");;;;; pid=line[26..33].split(" ").join("") ;;;;; session_name=line[35..50].split(" ").join("");;;;; session_n=line[52..62].split(" ").join("");;;;; mem_usag=line[64..75].split(" ").join("");;;;; ;;;;; procs << [name,pid,session_name,session_n,mem_usag];;;;; end;;;;; return procs;;;;; end;;;;; ;;;;; def memory_used;;;;; b=0;;;;; self.procs.each do |p|;;;;; b += p[-1].delete(" ,K").to_i;;;;; end;;;;; return b.commas+" K";;;;; end;;;;; ;;;;; #def memory_installed;;;;; #end;;;;; ;;;;; def name; return ENV["COMPUTERNAME"]; end;;;;; def user; return ENV["USERNAME"]; end;;;;; ;;;;;end;;;;; ;;;;; ################################################################################################################################;;;;; ################################################################################################################################;;;;; ## ##3 fix default packake to not include components;;;;; ;;;;; class Installation_Manager;;;;; def initialize;;;;; @default_index_package=[["/rubin/system/daemond.rb", ## v 1.0.016-17;;;;; "/rubin/system/definitions.rb",;;;;; "/rubin/launch.rb",;;;;; "/rubin/launch irb.cmd",;;;;; "/rubin/launch rubin.cmd",;;;;; "/rubin/system/rubin.rb",;;;;; "/rubin/data/scripts/systemlogmonitor.rb",;;;;; "/rubin/data/scripts/unpackaged_installer_script.rb",;;;;; "/rubin/documentation.txt",;;;;; "/rubin/change log.txt",;;;;; "/rubin/keyword cheetsheet.txt"],;;;;; ["/rubin/system",;;;;; "/rubin/bin",;;;;; "/rubin/app",;;;;; "/rubin/class",;;;;; "/rubin/data",;;;;; "/rubin/shortcuts",;;;;; "/rubin/data/appdata",;;;;; "/rubin/data/backups",;;;;; "/rubin/data/config",;;;;; "/rubin/data/definitions",;;;;; "/rubin/data/fileio",;;;;; "/rubin/data/logs",;;;;; "/rubin/data/scripts",;;;;; "/rubin/data/components",;;;;; "/rubin/data/sys",;;;;; "/rubin/data/sys/instance",;;;;; "/rubin/data/temp",;;;;; "/rubin/data/user"]];;;;; ;;;;; end;;;;; ;;;;; def default_index; return @default_index_package; end;;;;; ;;;;; def id; return INSTALLATION_HEADER[5];;;;; end;;;;; def dir; return INSTALLATION_HEADER[1];;;;; end;;;;; def verify_dir;return INSTALLATION_HEADER[1].to_s.downcase==SYSTEM.homedir.to_s.downcase;;;;; end;;;;; def date; return INSTALLATION_HEADER[3];;;;; end;;;;; def version; return INSTALLATION_HEADER[2];;;;; end;;;;; def verify_installation_files(path);;;;; if path.to_s.downcase.split("/")[-1]=="rubin";;;;; if File.file?(path+"/system/rubin.rb");return true;end;;;;; end;;;;; return false;;;;; end;;;;; ;;;;; def default_build_package;;;;; a=self.default_index[0]; b=self.default_index[1];;;;; self.build_package(a,b);;;;; end;;;;; ;;;;; def make; return self.default_build_package; end;;;;; ;;;;; ## build a source package file from installed version;;;;; def build_package *args #(included_files,included_dir_paths) ;;;;; included_files=args[0];;;;; included_dir_paths=args[1];;;;; files_data=[];;;;; maindatasep="#1#::#1#::#0#::#0#::#0#"+"::#1#::#1#";;;;; filenamesep="#1#::#1#::#0#::#0#::#0#"+"::#0#::#1#";;;;; filesep="#1#::#1#::#0#::#0#::#0#"+"::#0#::#0#";;;;; index_sep="#1#::#0#::#0#::#0#::#0#"+"::#"+"0#::#1#";;;;; ;;;;; ##get index file paths;;;;; index_files=[];;;;; included_files.each do |f|;;;;; p=f.to_s.downcase.split("/rubin/")[-1];;;;; index_files << "/rubin/"+p;;;;; end;;;;; ;;;;; ## locations of actual resources;;;;; nincluded_files=[];;;;; included_files.each do |f|;;;;; p = f.to_s.downcase.split("/rubin/")[-1];;;;; nincluded_files << INSTALLATION_HEADER[1].to_s+"/"+p;;;;; end;;;;; ;;;;; included_files=nincluded_files;;;;; ;;;;; ##get index dir paths ;;;;; index_dirs=[];;;;; included_dir_paths.each do |d|;;;;; p=d.to_s.downcase.split("/rubin/")[-1];;;;; index_dirs << "/rubin/"+p;;;;; end;;;;;;;;;; ##make index string;;;;; index1=index_files.join("?");;;;; index2=index_dirs.join("?");;;;; index=index1+"??"+index2;;;;; ;;;;; ## get data of all the files;;;;; files_data=[];;;;; included_files.each do |f|;;;;; f=File.open(f,"r");files_data << f.read ; f.close;;;;; end;;;;; ;;;;; ##combine files data with their index paths;;;;; nfiles_data=[];;;;; files_data.each do |fd|;;;;; i=files_data.index(fd);;;;; p=index_files[i.to_i];;;;; da=""+p.to_s+filenamesep+fd.to_s;;;;; nfiles_data << da;;;;; end;;;;; ;;;;; ;;;;; filespkg = nfiles_data.join(filesep);;;;; ;;;;; final_data = maindatasep.to_s + index.to_s + index_sep.to_s + filespkg.to_s;;;;; ;;;;; final_data=final_data.split("\n").join(";;"+";;;");;;;; ;;;;; d=SYSTEM.datadir+"/backups/installpackage.txt";;;;; ;;;;; f = File.open(d,"w");f.write(final_data); f.close;;;;; ;;;;; return "Your file was built: "+d.to_s;;;;;;;;;; end;;;;; ;;;;; #install.install_package("E:/Rubin/data/backups/installpackage.txt","C:/Users/14809/Desktop");;;;;;;;;; def install_package(package,dir);;;;; if self.verify_installation_files(dir) == true ; raise "Rubin is already installed there."; end;;;;; if File.file?(package) == false; raise "Input file path is incorrect."; end;;;;; ;;;;; ##load data;;;;; f=File.open(package,"r"); data = f.read ; f.close;;;;; ;;;;; ##decode data;;;;; data=data.split(";;;"+";;").join("\n");;;;; ;;;;; maindatasep="#1#::#1#::#0#::#0#::#0#"+"::#1#::#1#";;;;; filenamesep="#1#::#1#::#0#::#0#::#0#"+"::#0#::#1#";;;;; filesep="#1#::#1#::#0#::#0#::#0#"+"::#0#::#0#";;;;; index_sep="#1#::#0#::#0#::#0#::#0#"+"::#0#::#1#";;;;; ;;;;; data=data.split(maindatasep)[-1];;;;;;;;;; index_string=data.to_s.split(index_sep)[0].to_s;;;;; ;;;;; file_data=data.split(index_sep)[-1];;;;;;;;;; ##process files;;;;; file_data=file_data.split(filesep);;;;; nfile_data=[];;;;; ;;;;; file_data.each do |d|;;;;; p=d.split(filenamesep)[0];;;;; di=d.split(filenamesep)[1];;;;; nfile_data<<[p,di];;;;; end;;;;; ;;;;; file_data=nfile_data;;;;; ;;;;; #proces index;;;;; load "";;;;; f = index_string.split("??")[0].split("?");;;;; di = index_string.split("??")[1].split("?");;;;;;;;;;;;;;; Dir.mkdir(dir.to_s+"/rubin");;;;;;;;;; di.each do |p|;;;;; np=dir+"/"+p;;;;; Dir.mkdir(np);;;;; end;;;;;;;;;; # create files;;;;; ;;;;; file_data.each do |fd|;;;;; p=dir.to_s+"/"+fd[0].to_s;;;;; f=File.open(p,"w"); f.write(fd[1].to_s); f.close;;;;; end;;;;;;;;;; p=dir.to_s+"/rubin/system/rubin.rb";;;;; f=File.open(p,"r"); dat=f.read; f.close;;;;; ;;;;; old_header=dat.split("\n")[0].split("INSTALLATION_HEADER=")[-1];;;;; old_header=eval(old_header.to_s);;;;;;;;;; dat=dat.split("\n")[1..-1].join("\n");;;;;;;;;; version=old_header[2].to_s ### for now itll be bugged and write the version as the one of the installing party not the packaged, fix later;;;;; head=["installed",dir+"/rubin",version,Time.now.to_s,ENV["USER"].to_s,rand(99999999999999).to_s(36)];;;;; str="INSTALLATION_HEADER="+head.to_s;;;;; ;;;;; ndat=str+"\n"+dat;;;;; f=File.open(p,"w"); f.write(ndat); f.close;;;;; return true ;;;;; end;;;;; ;;;;; def size?;;;;; f=Dir.map(self.dir)[0];;;;; s=0;;;;; f.each do |ff|;;;;; i=File.size?(ff);;;;; s += i.to_i;;;;; end;;;;; return s;;;;; end;;;;; ;;;;; def generate_installer;;;;; datadir = SYSTEM.datadir;;;;; self.default_build_package;;;;; if File.file?(datadir+"/backups/installpackage.txt");;;;; if File.file?(datadir+"/scripts/unpackaged_installer_script.rb");;;;; ;;;;; f = File.open(datadir+"/scripts/unpackaged_installer_script.rb","r"); sfile=f.read; f.close;;;;; f = File.open(datadir+"/backups/installpackage.txt","r"); pfile=f.read; f.close;;;;; ;;;;; source = "VERSION='"+VERSION+"'"+sfile.split("\n")[3..-1].join("\n")+"\n"+pfile.to_s;;;;; ;;;;; f = File.open(datadir+"/backups/rubin_installer.rb","w"); f.write(source); f.close;;;;; ;;;;; return "Your file was built: "+datadir+"/backups/rubin_installer.rb";;;;; else; raise "unpackaged_installer_script.rb was missing.";;;;; end;;;;; else; raise "Unable to create and read install package.";;;;; end;;;;; end;;;;; ;;;;; ;;;;; def take_snapshot(name);;;;; ;;;;; end;;;;; ;;;;; def restore_snapshot(name);;;;; ;;;;; end;;;;; ;;;;;end;;;;; ;;;;;;;;;; ################################################################################################################################;;;;; ################################################################################################################################;;;;; ## controller;;;;; ;;;;; ;;;;; class Controller ## virtual network vis shared windows folders;;;;; def initialize;;;;; ;;;;; #right now internal config is ignored and system config is used.;;;;; @config_names=["Network_Directory","Network_Host","UserPriv"];;;;; @default_config=["",""];;;;; @config_data=@default_config;;;;; ;;;;; @logpath=SYSTEM.datadir+"/logs/controller.txt";;;;; ;;;;; @cfgpath=SYSTEM.datadir+"/config/controller.cfg";;;;; if File.file?(@cfgpath) == false; self.save_config;;;;; else; self.load_config;;;;; end;;;;; ;;;;; @controller_state="initialized";;;;; @binding=nil;;;;; @network_directory='' ;;;;; @fileio_directory=SYSTEM.datadir+"/fileio";;;;; @bound=false ;;;;; ;;;;; @dir_cleaner_thread=nil;;;;;;;;;; end;;;;;;;;;; def cleaning?; if @dir_cleaner_thread == nil; return false; else ; return @dir_cleaner_thread.alive?; end; end;;;;;;;;;; def post_initialize ## for system components the loader will check for this method and call it if you defined it;;;;; @controller_state ="post_initialization" ;;;;; if File.directory?(SYSTEM.config(7).to_s);;;;; @network_directory=SYSTEM.config(7).to_s;;;;; self.start_main_binding;;;;; SYSTEM.writelog("Controller bound to dir:"+@network_directory.to_s);;;;; puts "Controller "+SYSTEM.instance.id.to_s+" binding directory: "+@network_directory.to_s;;;;; elsif SYSTEM.config(7).to_s=="" or SYSTEM.config(7) == nil or SYSTEM.config(7).to_s == "false";;;;; @network_directory="";;;;; SYSTEM.writelog("Controller network directory not set, using fileio dir but not launching control binding.");;;;; @controller_state = "inactive";;;;; puts "Controller binding: turned off";;;;; else;;;;; SYSTEM.errorlog "Controller network directory was invalid, you can reconfigure it using SYSTEM.config(7,'path')." ;;;;; @controller_state = "failed init";;;;; puts "Controller binding: error";;;;; end;;;;; return nil;;;;; end;;;;; ;;;;; def start_main_binding;;;;; if @binding != nil; return false; end;;;;; @binding=FileIO_Eval_Binder.new(@network_directory,"eval",true) ## maybe change this to system config 7;;;;; @binding.start;;;;; @bound=true;;;;; if File.file?(@network_directory+"/cleaner.tag") == false ##if you have problems with files not getting deleted just run the cleaner thread manually for now;;;;; self.spawn_dir_cleaner ;;;;; else;;;;; s=File.read(@network_directory+"/cleaner.tag");;;;; if s.to_s==""; str=Time.now-100;;;;; else; str=Time.stamp(s.to_s);;;;; end;;;;; tn=Time.now-str;;;;; if tn.to_i>9;;;;; self.spawn_dir_cleaner;;;;; end;;;;; end;;;;; @controller_state = "running";;;;; return true;;;;; end;;;;; ;;;;; def stop_main_binding;;;;; @binding.stop; @binding=nil; @state="stopped";;;;; end;;;;;;;;;; def spawn_dir_cleaner;;;;; if @dir_cleaner_thread!=nil; return false; end ;;;;; @dir_cleaner_thread=Thread.new{loop do;;;;; begin; f=File.open(@network_directory+"/cleaner.tag","w"); f.write(Time.stamp); f.close; rescue; SYSTEM.errorlog "Controller cleaner thread failed to write tag file." ; end;;;;; begin ;;;;; e=[];;;;; ;;;;; l=Dir.entries(@network_directory); l.delete("."); l.delete("..");;;;; l.each { |v| e << @network_directory+"/"+v.to_s } ;;;;; e.each do |ee|;;;;; if ee.split("/")[-1][0..11]=="fileio_link-";;;;; fp = ee;;;;; begin; str=File.read(fp);;;;; rescue; SYSTEM.errorlog("Controller dir cleaner thread had a read failure so the itteration was skipped."); next;;;;; end;;;;; str2=Time.stamp(str);;;;; tn = Time.now;;;;; sec=tn-str2;;;;; if sec.to_f>9;;;;; i=ee.split("/")[-1][12..-5];;;;; d=ee.split("/")[0..-2].join("/");;;;; fp1=d+"/fileio_input"+i.to_s+".txt";;;;; fp2=d+"/fileio_output"+i.to_s+".txt";;;;; begin ; File.delete(ee) ; rescue ;; end;;;;; begin ; File.delete(fp1) ; rescue ;; end;;;;; begin ; File.delete(fp2) ; rescue ;; end;;;;; SYSTEM.writelog("Fileio deleted an old link: "+fp.to_s);;;;; else;;;;; end ;;;;; end;;;;; end;;;;; rescue; #SYSTEM.errorlog("Controller dir cleaner thread rescued an unknown error.");;;;; end;;;;; sleep 5;;;;; end} ;;;;; end;;;;;;;;;; def binding; return @binding; end;;;;; ;;;;; def members?;;;;; e=Dir.entries(@network_directory);;;;; e.delete("."); e.delete("..");;;;; if e.length == 0 ; return [];;;;; else;;;;; l=[];;;;; e.each do |ee|;;;;; #p = @network_directory + "/" + ee.to_s;;;;; if ee.downcase[0..11] == ("fileio_link-");;;;; l<<ee.split("-")[-1].split(".")[0];;;;; end;;;;; end;;;;; return l;;;;; end;;;;; end;;;;; ;;;;; def write(inst,str);;;;; if members?.include?(inst.to_s);;;;; fp=@network_directory+"/fileio_input"+inst.to_s+".txt";;;;; if File.file?(fp) == true;;;;; begin; File.write(fp,str.to_s); return str.to_s.length;;;;; rescue; raise "Controller failed to write file: "+fp.to_s;;;;; end;;;;; else; raise "Controller fed invalid filepath: "+fp.to_s;;;;; end;;;;; else; raise "Invalid inst passed.";;;;; end;;;;; end;;;;; ;;;;; def read(inst);;;;; fp=@network_directory+"/fileio_output"+inst.to_s+".txt";;;;; begin; str=File.read(fp);;;;;; rescue; raise "Controller read failed: "+fp.to_s; str=false;;;;; File.delete(fp);;;;; end;;;;; return str;;;;; end;;;;; ;;;;; def request(inst,str);;;;; if File.file?(@network_directory+"/fileio_output"+inst.to_s+".txt"); File.delete(@network_directory+"/fileio_output"+inst.to_s+".txt"); end;;;;; if self.write(inst.to_s,str.to_s).is_a?(Integer);;;;; c=0;;;;; res = nil;;;;; loop do;;;;; if c>10; res=nil; break; end;;;;; if File.file?(@network_directory+"/fileio_output"+inst.to_s+".txt");;;;; res=self.read(inst.to_s);;;;; break;;;;; end;;;;; c+=1; sleep 1;;;;; end;;;;; return res;;;;; else; raise "Request failed because Controller.write raised a message.";;;;; end;;;;; end;;;;;;;;;; def input(inst);;;;; if members?.include?(inst.to_s);;;;; fp=@network_directory+"/fileio_input"+inst.to_s+".txt";;;;; print"\n"; str=gets.chomp;;;;; if File.file?(fp) == true;;;;; begin; File.write(fp,str.to_s); return str.to_s.length;;;;; rescue; raise "Controller failed to write file: "+fp.to_s;;;;; end;;;;; else; raise "Controller fed invalid filepath: "+fp.to_s;;;;; end;;;;; else; raise "Invalid inst passed.";;;;; end;;;;; end;;;;;;;;;; def writelog(str);;;;; if str.to_s.length <= 0; return false; end;;;;; if File.file?(@logdir) == false; f=File.open(@logdir,"w"); f.close; end;;;;; ts=Time.now.to_s.split(" ")[0..1].join(".").split(":").join(".").split("-").join(".");;;;; f=File.open(@cfgpath,"a"); f.write(ts+": "+str.to_s);;;;; return true;;;;; end;;;;;;;;;; def save_config;;;;; begin; File.write(@config_data.to_s);;;;; rescue; return false;;;;; end;;;;; return true;;;;; end;;;;; def load_config;;;;; begin; @config_data=eval(File.read(@cfgpath));;;;; rescue; return false;;;;; end;;;;; return true;;;;; end;;;;; ;;;;; def state; return @controller_state; end;;;;;;;;;; def log; return self.binding.log; end;;;;;;;;;; def ndir; return self.binding.ndir; end;;;;; ;;;;; ;;;;;;;;;; class FileIO_Eval_Binder ## rename to control binding;;;;; def initialize(dir,mode,log) ## mode: read / eval;;;;; ;;;;; fp=dir.to_s+"/fileio_input"+SYSTEM.instance.id.to_s+".txt";;;;; fp2=dir.to_s+"/fileio_output"+SYSTEM.instance.id.to_s+".txt" ;;;;; ;;;;; @dir=dir ##bound dir;;;;; @inpath=fp;;;;; @outpath=fp2;;;;; f=File.open(@inpath,"w"); f.close;;;;; ;;;;; if mode.to_s=="eval"; @eval_allowed=true; @mode="eval";;;;; elsif mode.to_s=="read"; @eval_allowed=false; @mode="read";;;;; end;;;;; ;;;;; @eval_idle_delay=1.0;;;;; @eval_delay=0.1;;;;; ;;;;; @log=true ## right now just override until we find a better way to control this;;;;; @private_log=[];;;;;;;;;; @name=rand(100000000000).to_s(36);;;;; @admin=false ;;;;;;;;;; @state='initializing' ;;;;; @running=false;;;;; @thread=nil;;;;; @tracker_thread=nil;;;;;;;;;; @context=SYSTEM ##make this an init arg;;;;; @buffer=[];;;;; ;;;;; @eval_toggle=nil ##;;;;; ;;;;; end;;;;;;;;;; def start;;;;; if @running; return false; end;;;;; @running=true; @state="active"; @opid=0;;;;; ;;;;; if @mode=="eval";;;;; ;;;;; @thread=Thread.new{;;;;; loop do;;;;; if @running == false; break; end;;;;; @state="active";;;;; if File.file?(@inpath) == true;;;;; ;;;;; begin; str=File.read(@inpath) ##this should fix our random and rare error (error: no file ; controler.rb 267);;;;; rescue; next ##the file exists but couldnt be read because its already open in another session, just skip the rest of the loop and continue normally.;;;;; end;;;;; ;;;;; if str.length > 0 and SYSTEM.config(9).to_s.downcase == "true";;;;; ;;;;; @state="working";;;;; begin;File.write(@inpath,"");;;;; rescue;;;;; end;;;;; @buffer<<@opid.to_s+"<< "+str.to_s;;;;; ;;;;; if @eval_allowed != true ; sleep @eval_idle_delay; next ; end;;;;; ;;;;; begin;;;;; @state="evaluating";;;;; [email protected]_eval(str) ;;;;; rescue => e;;;;; res = "EXCEPTION::: " + e.to_s + "\n" + e.backtrace.join("\n");;;;; end;;;;; @state="posting";;;;; begin; File.write(@outpath,res.to_s);;;;; rescue;;;;; end;;;;; sleep @eval_delay;;;;; @buffer << @opid.to_s+">> "+res.to_s;;;;; ;;;;; begin ## may fail, multi instances write to the same file;;;;; s1=SYSTEM.instance.id.to_s+":"[email protected]_s+":"+Time.stamp;;;;; s2="<< "+str.to_s;;;;; s3=">> "+res.to_s;;;;; s4=s1+"\n"+s2+"\n"+s3+"\n";;;;; s5=SYSTEM.instance.id.to_s+":"[email protected]_s+":"+Time.stamp+": Dir log created. ("[email protected]_s+")";;;;; ;;;;; if @log==true ## keep p;;;;; if File.file?(@dir.to_s+"/log.txt") == false;;;;; f=File.open(@dir.to_s+"/log.txt","w"); f.write(s5); f.close;;;;; end;;;;; f=File.open(@dir.to_s+"/log.txt","a"); f.write(s4); f.close;;;;; @private_log << s4;;;;; s5=s4.split(":")[0..-1].join(":");;;;; SYSTEM.writelog("FileIO-Eval: "+s5.to_s[0..-2]);;;;; end;;;;; ;;;;; ##log to system regardless;;;;; #SYSTEM.writelog("FileIO-Eval: "+s5.to_s[0..-2]);;;;; #disabled because above;;;;; ;;;;; ##print fileio if configured;;;;; if SYSTEM.config(10).to_s.downcase == "true";;;;; puts "\nFileIO:"+s4.to_s;;;;; end;;;;; ;;;;; rescue; SYSTEM.errorlog "Controller eval log write failed.";;;;; end;;;;; ;;;;; @opid += 1;;;;; @state="idle"; sleep @eval_idle_delay;;;;; else; @state="idle"; sleep @eval_idle_delay;;;;; end;;;;; else; @state="idle"; sleep @eval_idle_delay;;;;; end;;;;; ;;;;; end;;;;; @running=false; @state="stopped";;;;; };;;;; ;;;;; end;;;;; ;;;;; self.spawn_tracker_thread;;;;; ;;;;; return true;;;;; end;;;;;;;;;; def spawn_tracker_thread;;;;; @tracker_thread=Thread.new{;;;;; loop do;;;;; begin;;;;; if @running==false;;;;; else;;;;; id=SYSTEM.instance.id.to_s;;;;; fp=@dir+"/fileio_link-"+id+".txt";;;;; f=File.open(fp,"w"); f.write(Time.stamp); f.close ;;;;; end;;;;; sleep 5.0;;;;; rescue; ##loop failed;;;;; end ;;;;; end;;;;; };;;;; end;;;;; ;;;;; ;;;;; def stop;;;;; if @running == true;;;;; @thread.kill; @thread=nil;;;;; @tracker_thread.kill; @tracker_thread=nil;;;;; @running=false;;;;; return true;;;;; else; return false;;;;; end;;;;; end;;;;;;;;;;;;;;; def lock; @eval_allowed=false; end;;;;; def unlock; @eval_allowed=true; end;;;;; def mode *args;;;;; if args.length == 0 ; return @mode;;;;; else; @mode = args[0].to_s;;;;; end;;;;; end;;;;; ;;;;; def ndir; return @dir; end;;;;; ;;;;; def log; return @private_log; end;;;;; ;;;;; end;;;;; ;;;;; ;;;;;end;;;;;;;;;; ;;;;; ;;;;; ################################################################################################################################;;;;; ################################################################################################################################;;;;; ##;;;;; ;;;;; class Network_Manager;;;;; def initialize;;;;; end;;;;; def post_initialize;;;;; end;;;;; end;;;;; ;;;;;;;;;; ################################################################################################################################;;;;; ################################################################################################################################;;;;; ##;;;;; ;;;;; class Ruby_Manager;;;;; def initialize;;;;; #@cfgpath=SYSTEM.cfgdir+"/ruby.cfg";;;;; ;;;;; @default_config=[];;;;; @config=@default_config;;;;; #self.load_config;;;;; #@rubydir=self.locate_host_ruby;;;;; ;;;;; end;;;;;;;;;; def rubydir;return @rubydir;end;;;;;;;;;; def load_config;;;;; if File.file?(@cfgpath);;;;; begin;d=File.read(@cfgpath);d=eval(d);@config=d;;;;; rescue;#SYSTEM.errorlog("Ruby Config could not be loaded, it might be corrupted.");;;;; end;;;;; else;#SYSTEM.errorlog("Ruby Config was missing, it had be restored.");;;;; f=File.open(@cfgpath,"w");f.write(@default_config.to_s);f.close;;;;; end ;;;;; end;;;;; ;;;;; def save_config;;;;; ;;;;; end;;;;;;;;;; def insert_based_launcher;;;;; ##copy host rubys irb files and insert a rubin launcher before them so rubin will run before irb;;;;; ##return path to based launcher.;;;;; end;;;;;;;;;; def locate_host_ruby ## recent ruby version update seems to have broken this;;;;;;;;;; return located;;;;; end ;;;;; end;;;;;;;;;; ;;;;; ################################################################################################################################;;;;; ################################################################################################################################;;;;; ################################################################################################################################;;;;; ################################################################################################################################;;;;; ################################################################################################################################;;;;; ################################################################################################################################;;;;; ################################################################################################################################;;;;; ################################################################################################################################;;;;; ;;;;;;;;;;;;;;; ;;;;; ;;;;; ######################################################################################################;;;;; ## end of embedded classes and rubin system class, have a nice day.;;;;;end;;;;;;;;;;;;;;;SYSTEM=RubinSystem.new ##initialize the class object first;;;;;SYSTEM.startup ##initialize resources and load files;;;;;SYSTEM.post_initialization ##run autostart apps and maybe shell;;;;;POST_INITIALIZATION=true ##create a flag to lcok down the startup methods;;;;;##line below might need to be switched on and off in the future;;;;;$system=SYSTEM;;;;;##;##;##;##;##;##;##;##;##;##;##;##;##;##;##;##;##;##;##;##;;;;;##Hidden_Internal_Data=""#1#::#1#::#0#::#0#::#0#::#0#::#0#/rubin/data/scripts/systemlogmonitor.rb#1#::#1#::#0#::#0#::#0#::#0#::#1##RubinSystem log monitor v 1.3, 2023.3.3;;;;;#check if we are in a rubin directory;;;;;if Dir.getwd.to_s.downcase.include?("rubin")==false; raise "Cannot locate the 'Rubin' directory."; end;;;;;#locate installation and log file;;;;;install_dir=Dir.getwd.to_s.downcase.split("/rubin/")[0]+"/rubin";;;;;path=install_dir+"/system/rubin.rb" ;;;;;logpath=install_dir+"/data/logs/systemlog.log";;;;;if File.file?(path) == false; raise "Cannot locate installation."; end;;;;;if File.file?(logpath) == false; "Cannot locate system log."; end;;;;;## get install info and set window title;;;;;begin;;;;;eval(File.read(path).split("\n")[0]);;;;;finger_print=INSTALLATION_HEADER[-1].to_s;;;;;eval(s="`TITLE "+install_dir.to_s+" "+ENV['COMPUTERNAME'].to_s+" "+finger_print+"`");;;;;rescue;`TITLE Rubin system log`;;;;;end;;;;;##prepare screen;;;;;buffer=""; size=0; refresh_delay=1.0;;;;;system("CLS");;;;;## enter file monitoring loop;;;;;loop do;;;;; begin;;;;; s=File.size(logpath);;;;; if s!=size;;;;; size=s;;;;; buffer=File.read(logpath);;;;; system("CLS");;;;; print buffer+"\n";;;;; end;;;;; rescue;;;;; end;;;;; sleep refresh_delay;;;;;end#1#::#1#::#0#::#0#::#0#::#0#::#0#/rubin/data/scripts/unpackaged_installer_script.rb#1#::#1#::#0#::#0#::#0#::#0#::#1###installer version 1.2 pkg v 0.0.0 no package included, paste one into the last line of the file, you can generate one using install.build_package;;;;;## second warning, this file will not work until you add a package to the last line;;;;;#begin;;;;;;;;;;unless defined?(VERSION); VERSION = "0"; end;;;;;;;;;;puts "Welcome to the Rubin System installer. Version "+VERSION.to_s;;;;;;;;;;launch_directory=Dir.getwd;;;;;launch_time=Time.now;;;;;;;;;;puts "";;;;;puts "Dir: "+launch_directory.to_s;;;;;puts "";;;;;puts "Would you like to install to this location? (Y/N)";;;;;;;;;;inp=gets.chomp.to_s[0].downcase;;;;;if inp=="y";;;;; install_dir=Dir.getwd.to_s;;;;;else;;;;; puts "Enter install directory.";;;;; install_dir=nil;;;;; loop do;;;;; inp=gets.chomp.to_s;;;;; if File.directory?(inp.to_s); install_dir=inp.to_s; break;;;;; else; puts "Invalid directory.";;;;; end;;;;; end;;;;;end;;;;;;;;;;puts "Confirming, you want to install to dir? (Y/N) ; "+install_dir.to_s;;;;;;;;;;inp=gets.chomp.to_s[0].downcase;;;;;;;;;;if inp!="y"; puts "Fine, then stop wasting my time...\nThe program will exist in 3 seconds."; sleep 3.0; exit; end;;;;;if File.directory?(install_dir+"/Rubin"); puts "Cannot install here, there is already an installation."; sleep 3.0; exit; end;;;;;;;;;;#load data;;;;;;;;;;dir=install_dir;;;;;;;;;;if File.file?($0); p = $0;;;;;elsif File.file?(launch_directory+"/rubin_installer.rb"); p=launch_directory+"/rubin_installer.rb";;;;;else; raise "The installer file cannot locate its self: "+$0.to_s;;;;;end;;;;;;;;;;;;;;;f=File.open(p,"r"); data = f.read ; f.close;;;;; ;;;;;#decode data;;;;;data=data.split(";;;"+";;").join("\n");;;;; ;;;;;maindatasep="#1#::#1#::#0#::#0#::#0#"+"::#1#::#1#";;;;;filenamesep="#1#::#1#::#0#::#0#::#0#"+"::#0#::#1#";;;;;filesep="#1#::#1#::#0#::#0#::#0#"+"::#0#::#0#";;;;;index_sep="#1#::#0#::#0#::#0#::#0#"+"::#0#::#1#";;;;; ;;;;;data=data.split(maindatasep)[-1];;;;;;;;;;index_string=data.to_s.split(index_sep)[0].to_s;;;;; ;;;;;file_data=data.split(index_sep)[-1];;;;;##process files;;;;; ;;;;; ;;;;;file_data=file_data.split(filesep);;;;; ;;;;;nfile_data=[];;;;; ;;;;;file_data.each do |d|;;;;; p=d.split(filenamesep)[0];;;;; di=d.split(filenamesep)[1];;;;; nfile_data<<[p,di];;;;;end;;;;; ;;;;;file_data=nfile_data;;;;; ;;;;;#proces index;;;;;;;;;;f = index_string.split("??")[0].split("?");;;;;di = index_string.split("??")[1].split("?");;;;;;;;;;;;;;;Dir.mkdir(dir.to_s+"/rubin");;;;;;;;;;di.each do |p|;;;;; np=dir+"/"+p;;;;; Dir.mkdir(np);;;;;end;;;;;;;;;;# create files;;;;; ;;;;;file_data.each do |fd|;;;;; p=dir.to_s+"/"+fd[0].to_s;;;;; f=File.open(p,"w"); f.write(fd[1].to_s); f.close;;;;;end;;;;;;;;;;p=dir.to_s+"/rubin/system/rubin.rb";;;;;f=File.open(p,"r"); dat=f.read; f.close;;;;; ;;;;;old_header=dat.split("\n")[0].split("INSTALLATION_HEADER=")[-1];;;;;old_header=eval(old_header.to_s);;;;;;;;;;dat=dat.split("\n")[1..-1].join("\n");;;;;;;;;;version=old_header[2].to_s ### for now itll be bugged and write the version as the one of the installing party not the packaged, fix later;;;;;head=["installed",(dir+"/rubin").split("//").join("/"),version,Time.now.to_s,ENV["USER"].to_s,rand(99999999999999).to_s(36)];;;;;str="INSTALLATION_HEADER="+head.to_s;;;;;;;;;; ;;;;;ndat=str+"\n"+dat;;;;;f=File.open(p,"w"); f.write(ndat); f.close;;;;;;;;;;puts "INSTALL SUCCESS!!!";;;;;puts "The program will exit in 2 seconds";;;;;sleep 2.0;;;;;exit;;;;;;;;;;## INSTALL PACKAGE BELOW ; VERSION 0.0.0#1#::#1#::#0#::#0#::#0#::#0#::#0#/rubin/documentation.txt#1#::#1#::#0#::#0#::#0#::#0#::#1#Rubin version 1.0 released Feb 2023;;;;;A Ruby environment. [email protected] ;;;;;;;;;;This file is a basic run through of the system.;;;;;To run rubin you can run "launch.rb" from the install directory.;;;;;;;;;; Topics:;;;;; System Directories;;;;; System Files & Components;;;;; Apps;;;;; The Class Directory;;;;; About System Config and Features;;;;; Building and running apps.;;;;;;;;;;System Directories.;;;;;There is a default tree of directories built when rubin installs.;;;;;/rubin/data all kinds of data lives here;;;;;/rubin/app apps and programs ;;;;;/rubin/bin interpreters and other exes;;;;;/rubin/class you can store project files here, they are run automatically on boot;;;;;/rubin/shortcuts meant for lnk files but can run rb files externally(from the caller);;;;;/rubin/system system scripts are stored here;;;;;/rubin/data/appdata apps can store data here;;;;;/rubin/data/backups various copies of stuff can go here, system versions for example;;;;;/rubin/data/config system config is here but any program can store config here;;;;;/rubin/data/definitions definition files compiled with export classes are kept here;;;;;/rubin/data/fileio FileIO_Binding can be set to eval to/from files, lol;;;;;/rubin/data/logs logs go here duh;;;;;/rubin/data/scripts ect script files;;;;;/rubin/data/sys ;;;;;/rubin/data/sys/instance insance data on installation instances running;;;;;/rubin/data/temp a dir that is auto cleaned based on age and access frequency*;;;;;rubin/data/user a dir that is pretty unused for now;;;;;You can access these paths globally with SYSTEM.dirs or SYSTEM.appdatadir / SYSTEM.datadir for example.;;;;;;;;;;System Files and Components;;;;;;;;;; The system directory follows a rule system, any file in it besides 'rubin.rb', the 'definitions.rb' or;;;;; 'deamond.rb', will be treated as a system component and loaded, expected to have at least one main;;;;; class sharing the name of the file, the system will initialize it using instance eval. Components typically;;;;; opperate autonomously of the system and provide inter-functionality of features, such as the ;;;;; dictionary or network manager.;;;;;;;;;; The daemond file.;;;;;;;;;; The system daemond is a class object whos sole job is to run the daemond files contents on main;;;;; context.;;;;;;;;;; The definitions file.;;;;;;;;;; The definitions file is an installer included definition, if config 9 is set to true rubin will look for this;;;;; file when booting, it can also be set to an array and a list of names of files in /rubin/data/definitions.;;;;; Just set to false or [] to just not load any definition files. The purpose of definition files is either to;;;;; redefine classes and or function as large ruby method libraries. They will be really common methods;;;;; that share code across ruby programs.;;;;;Keep note that for now definitions automatically evaluate on Rubin_System class objects context, later it will be configurable so you can run definitions on main and other contexts***********;;;;;;;;;;;;;;; Apps and app development.;;;;; ;;;;; The app directory stores two types of apps, an app can be what ever named rb file, or a folder with;;;;; an rb file inside sharing its name as an entry point, as this point i call it a program. Apps can store data;;;;; and work with it in their install dir but its better to use /rubin/data/appdata and make a folder;;;;; with the apps name to work with.;;;;;;;;;; when you run an app using SYSTEM.run "appname", rubin evaluates the file, then looks at two;;;;; reserved variables, @app and @threads. After evaluating the app those values will be set by the;;;;; app file and carry over after eval when then system continues to check for an app object and threads.;;;;; if it finds them it ads references to them into @thread_pool and @apps.;;;;;;;;;;Apps dont have to return links of them self to the system, it just helps with interconectivity of apps.;;;;;apps are free to have what ever file and folder structure in their install directory and appdata;;;;;;;;;;;;;;;The Class Directory;;;;;;;;;; Also known as classdir, this directory is either configured to load every ruby script or not. You can add files here you want to run every time you run rubin. Files that run here arent intended to contain apps or your main work code but it can if you want, the actual intended purpose of the class directory is to run redefinition of existing objects as well as new ones,;;;;; they can be used to set up common environments for your apps.;;;;;SYSTEM.export_definitions(name) will create a compiled definition file in rubin/data/definitions from every file in the class dir;;;;;SYSTEM.import_definitions(name) will break down a compiled definitions file into your classdir.;;;;;;;;;;About System Config;;;;;;;;;;If you use config, youll get an array of both names and the values. if you use config like this config(1,true);;;;;you can set the value, if you just use config(1) you will get the value back, you cam also use the config;;;;;items name instead of its number.;;;;;;;;;;You also get a method show_config or its alias config? which prints a nice numbered list of config values;;;;;next to their name.;;;;;;;;;;;;;;; System Boot order;;;;;;;;;; 1. check work directory, locate system install dir,change to it if not already there, verify write access;;;;; 2. Initialize Rubin_System class object, load config data;;;;; 3. Check config for ruby gems and install them if they arent already;;;;; 4. Check definitions and load if configured. ;;;;; 5. Load all files in the classdir if configured to.;m;;;;; 6. Rubin_System runs post_init method, runs autostart apps;;;;; 7. Run startup scripts if configured.;;;;; 8. Starts a repl shell if configured. ;;;;; 9. System is up if the flow(of eval) wasnt captured by an app or the system shell flow is returned to the;;;;;caller with nil.;;;;;;;;;;Installing the system and using it for the first time.;;;;;;;;;; When you complete the installer script and open then new rubin installation directory you made,;;;;; you will find the system directories, a launcher and a cmd script to start the users installed ruby irb.;;;;; Assuming you have ruby installed on windows you will have irb. ;;;;;Irb is for catching exceptions the shell could not catch, just load 'launch.rb'. and proceed normally or;;;;;attempt to replicate your error. The shell will catch and error log the majority of exceptions you;;;;;encounter.;;;;;;;;;; Building an app.;;;;; Here is a simple straight forward modle of an app file;;;;;;;;;;###### App.rb;;;;;class App;;;;; def initialize;;;;; self.func;;;;; end;;;;; def func;;;;; @t1=Thread.new{ 100000.times {rand}};;;;; end;;;;;end;;;;;@app=App.new;;;;;@threads<<@app.instance_variable_get("@t1");;;;;########;;;;;;;;;;As you know, @app and @threads are system reserved and are collected for data if they happen to ;;;;;contain any after an app file is ran. This will help the system control apps, threads and apps to interact;;;;;with eachother and the system.;;;;; theres also a shutdown method, if you define one in your app, a system shutdown or restart will check;;;;;to see if its defined for an app and call it if so.;;;;;;;;;; Running apps.;;;;;You can get apps in the appdir by calling apps? and run with run 'appname' no extension or path needed.;;;;;Running apps go into a Rubin_System instance varibale @apps as an array of data;;;;;[appname,instanceid,runtime,appobj,threads];;;;;;;;;;Running apps can either take flow control or run threads and return control to the system shell.;;;;;Apps can evan have their own shell, in oss.rb there is a Shell object class for repl.;;;;;;;;;;;;;;;Configuring the system for various startups.;;;;;;;;;;How system components work and how to make your own.;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#1#::#1#::#0#::#0#::#0#::#0#::#0#/rubin/change log.txt#1#::#1#::#0#::#0#::#0#::#0#::#1#v1.02.0 3.29.2023 - Rubin revision 1.0 phase is complete, all revisions added to 1.0 and the version number is ready to start rolling with future updates.;;;;;v1.019.0 3.17.2023 - Rubin recieved many quality control update, config handeling was improved, component handeling was updated and features were added to shell.;;;;;;;;;;v1.018.0 3.10.2023 - Rubin is in the middle of a "component handeling" overhaul; SYSTEM.load_component is not complete and will not function properly.;;;;; - added componend load method, components load on rubin by default but their name can specify the classobj keyword instance var name they get evaled onto, i.e. notrubin.component.rb;;;;; - Made components in sysdir optional to load, embedded the default ones into rubin class;;;;;;;;;;v1.017.0 3.10.2023 - Moved system components from dir to embedded in rubin class, still treated as components, now you can load components on other contexts too.;;;;;v1.016.0 3.10.2023 - Made required files a config setting, they are loaded before rubygem in config load now.;;;;;v1.015.0 3.4.2023 - Rewrote the config load for system boot. Documentation will follow.;;;;;v1.014.0 3.4.2023 - Updated preconfig handeling, added features.;;;;;v1.001.2 2.10.2023 - App_Controller component was added to system standard components.;;;;;v1.0.011 2.8.2023 - updated standard package, tweaked a few things, made a few improvements;;;;;v1.0.003. 2.1.2023 - Released installer script,installer package, recovery* and online download added*****;;;;;v1.0.002 1.29.2023 - no notes;;;;;r1.0.001 1.29.2023 - divided old rubin application suite out and made the system fresh by cutting out a bunch of un-needed code, next version is releasable :D;;;;;#1#::#1#::#0#::#0#::#0#::#0#::#0#/rubin/keyword cheetsheet.txt#1#::#1#::#0#::#0#::#0#::#0#::#1#;;;;;$system;;;;;;;;;;$homedir;;;;;$sysdir;;;;;$appdir;;;;;$classdir;;;;;$datadir;;;;;$appdatadir;;;;;$cfgdir;;;;;$logdir;;;;;$userdir;;;;;$bindir;;;;;;;;;;@homedir;;;;;@sysdir;;;;;@appdir;;;;;@classdir;;;;;@datadir;;;;;@appdatadir;;;;;@cfgdir;;;;;@logdir;;;;;@userdir;;;;;@bindir;;;;;;;;;;;;;;;@daemond;;;;;@shell;;;;;@instance;;;;;@app_controller;;;;;@host;;;;;@install;;;;;@controller;;;;;@network;;;;;@ruby;;;;;;;;;;@app;;;;;@threads;;;;;;;;;;@apps;;;;;@components;;;;;@embedded_components;;;;;@component_objects;;;;;@embedded_comonent_objects;;;;;;;;;;@definitions;;;;;@classes;;;;;;;;;;@loaded_files;;;;;@loaded_apps;;;;;@loaded_config;;;;;@loaded_scripts;;;;;@loaded_shortcuts;;;;;;;;;;@config;;;;;@default_config;;;;;@config_names;;;;;;;;;;MAIN points to main context;;;;;SYSTEM points to system;;;;; ;;;;;$CHARS / CHARS useful;;;;;$HEX / HEX;;;;;$BINARY / BINARY;;;;;;;;;;SYSTEM._and later add these into main;;;;;SYSTEM._or;;;;;SYSTEM._nand;;;;;SYSTEM._xor;;;;;SYSTEM._nor;;;;;SYSTEM.dir return work dir, sets workdir if passed an arg, args can be local file names instead of full paths.MAIN.vd ;;;;;Dir.viewdir prints the current directory to the screen, can take a path as an arg.;;;;;SYSTEM.vd an alias for Dir.view;;;;;;;;;;;;;;;Object.local_methods Gets the methods defined only in the objects class and not methods from its parent or scope.;;;;;Object.lm Alias for the above.;;;;;Object.gv Alias for global variables;;;;;Object.ivs Alias for instance_variables;;;;;Object.ivg Alias for instance_variable_get;;;;;Object.ivs Alias for instance_variable_set;;;;;Object.iev Alias for instance_eval;;;;;Object.cons Alias for constants;;;;;;;;;;;;;;;SYSTEM.dirs returns a list of system dirs, returns the path if the dir name is passed as an arg;;;;;SYSTEM.homedir returns the installation directory.;;;;;SYSTEM.classdir;;;;;SYSTEM.sysdir;;;;;SYSTEM.datadir;;;;;SYSTEM.appdir;;;;;SYSTEM.appdatadir;;;;;SYSTEM.cfgdir;;;;;SYSTEM.logdir ;;;;;SYSTEM.apps? get a list of apps installed.;;;;;SYSTEM.scripts? get a list of runnable scripts.;;;;;SYSTEM.run run an app;;;;;SYSTEM.runs run a script file;;;;;;;;;;SYSTEM.config? returns a list of config names and values that is more readable. Alias of show_config.;;;;;SYSTEM.config get an array of config names and values.;;;;;SYSTEM.load_config loads default config, can take an arg of config file path;;;;;SYSTEM.save_config saves default cfg file, pass a filepath with name to save cfg as.;;;;;SYSTEM.save_preconfig saves current config as a numbered preconfig, 0 if one doesnt already exist,;;;;; pass an integer to overwrite an existing preconfig.;;;;;SYSTEM.create_preconfig pass a config array to save as a preconfig, pass an integer as the second argument;;;;; to overwrite an existing preconfig.;;;;;SYSTEM.preconfig? Returns list of preconfig file names, or false if there are none.;;;;;SYSTEM.lock_preconfig If preconfig is locked, a preconfig file wont be deleted after it is loaded.;;;;;SYSTEM.unlock_preconfig Removes the 'lock_preconfig.cfg' tag file from the config dir.;;;;;SYSTEM.preconfig_locked? Returns true if there is a 'lock_preconfig.cfg' file in the config dir.;;;;;SYSTEM.save_altconfig Saves default config as an altconfig. You can pass a conffig file name with its extension to set altconfig.;;;;;SYSTEM.altconfig? Returns false if no altconfig exists.;;;;;SYSTEM.remove_altconfig Deletes altconfig.;;;;;SYSTEM.delete_altconfig Alias to the method above.;;;;;;;;;;SYSTEM.load_classes load the classdir, can take an arg for alternate load dir;;;;;SYSTEM.import_classes pass path to a definition file to dissassemble it into individual files.;;;;;SYSTEM.export_classes pass a oath and name of file to export classdir files to.;;;;;;;;;;SYSTEM.ruby ruby component, manages interpreter;;;;;SYSTEM.install install component;;;;;SYSTEM.host host component;;;;;SYSTEM.network network component;;;;;SYSTEM.con controller component;;;;;SYSTEM.dic a dicitonary;;;;;SYSTEM.apps App controller.;;;;;;;;;;SYSTEM.install.dir See the install location.;;;;;SYSTEM.install.default_index Returns an array used for creating installation packages. This will return a basic version of your installation.;;;;;SYSTEM.install.version See rubin version number.;;;;;SYSTEM.install.default_build_package Generate a installpackage.txt in /Rubin/data/backups.;;;;;SYSTEM.install.make Does the same as the method above, just an alias to it.;;;;;SYSTEM.install.id See installation finger print.;;;;;SYSTEM.install.install_package(package,dest) Installs a package.;;;;;SYSTEM.install.build_package Builds a package from a custom input array of files and directories.;;;;;SYSTEM.install.verify_installation_files Checks a directory to see if it apears bootable.;;;;;SYSTEM.install.date Returns install date.;;;;;;;;;;SYSTEM.host.memory_used Get ram used.;;;;;SYSTEM.host.memory_installed **not added yet;;;;;SYSTEM.host.call Run a cmd command;;;;;SYSTEM.host.launch Run a cmd command in this session;;;;;SYSTEM.host.launch_new Create a new session to run cmd command.;;;;;SYSTEM.host.drives Get mounted drives.;;;;;SYSTEM.host.host_drive Get host drive.;;;;;SYSTEM.host.procs Get host processes.;;;;;SYSTEM.host.get_host_identifier Get a string of info about the host hardware and software;;;;;;;;;;SYSTEM.instance.pop Create a new window with a new instance.;;;;;SYSTEM.instance.id Get the instance id.;;;;;SYSTEM.instance.get_local_ids Get the ids of all instances that appear as running from the installation.;;;;;;;;;;SYSTEM.ruby.rubydir Get the hosts ruby installation directory.;;;;;SYSTEM.ruby.locate_host_ruby This has to be run if the ruby installation moves or is updated.;;;;;;;;;;SYSTEM.controller / SYSTEM.con The controller component allows instances to be controlled by network directories.;;;;;;;;;;SYSTEM.con.state Controller state;;;;;SYSTEM.con.dir Controller network directory. Pass an argument to set;;;;;SYSTEM.con.cleaning? *** Check if this controller is cleaning the shared network direcotry.;;;;;SYSTEM.con.write("1234","puts 'hello'") Write script to a controller.;;;;;SYSTEM.con.read("1234") Read output from a controller.;;;;;SYSTEM.con.request("1234","puts 'hello'") Write then wait and read output from controller.;;;;;SYSTEM.con.input("1234") Multi-line gets and sends the string to the controller;;;;;SYSTEM.con.writelog Write to the individual controllers log, all controllers logs are in the network directory;;;;;SYSTEM.con.log Get controllers log.;;;;;**SYSTEM.con.majorlog All controller logs also write here. ;;;;;**SYSTEM.con.majorwritelog;;;;;SYSTEM.con.binding Get the eval binding object in controller.;;;;;SYSTEM.con.members? Get all the controllers bound to the current network directory.;;;;;;;;;;;;;;;;;;;;########### definitions provided medthods;;;;;;;;;;Time.stamp Returns a time stamp, or takes a timestamp and returns a Time class for it, and visa-versa.;;;;;Time.parse_seconds Gets an array of timmer elements [hrs, mins, secs] from an integer of seconds.;;;;;;;;;;Integer.prime?;;;;;Integer.exponate;;;;;Integer.factors;;;;;Integer.commas;;;;;Integer.usrname;;;;;String.splice("","");;;;;;;;;;;;;;;Dir.map;;;;;Dir.image;;;;;Dir.view;;;;;Dir.dir;;;;;Dir.empty?;;;;;Dir.empty!;;;;;Dir.delete;;;;;Dir.move;;;;;Dir.rename;;;;;;;;;;File.make
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment