Last active
March 24, 2023 21:13
-
-
Save thomasjslone/33a6fc8dacd7ba2ad5283eff05b21f75 to your computer and use it in GitHub Desktop.
latest rubin 1.0.025-7ish major tlc update for executable handeling and event logging * minor security bug not fixed yet see line 65
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VERSION='1.0.025' | |
#begin | |
unless defined?(VERSION); VERSION = "0"; end | |
launch_directory=Dir.getwd; launch_time=Time.now | |
##prompt | |
puts "Welcome to the Rubin System installer. Version "+VERSION.to_s | |
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 { inp=gets.chomp.to_s; if File.directory?(inp.to_s); install_dir=inp.to_s; break;elsif inp.to_s.downcase == "exit"; exit; else; puts "Invalid directory."; 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 | |
#split up package 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 { |d| p=d.split(filenamesep)[0]; di=d.split(filenamesep)[1]; nfile_data<<[p,di] } | |
file_data=nfile_data | |
#proces index | |
f = index_string.split("??")[0].split("?") | |
di = index_string.split("??")[1].split("?") | |
#build dirs | |
Dir.mkdir(dir.to_s+"/rubin") | |
di.each { |p| np=dir+"/"+p; Dir.mkdir(np) } | |
# write files | |
file_data.each { |fd| p=dir.to_s+"/"+fd[0].to_s; f=File.open(p,"w"); f.write(fd[1].to_s); f.close } | |
## write installation_header | |
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] | |
## not a super big worry bit yea we're evaling array strings below, only really an issue for first time installs, | |
old_header=eval(old_header.to_s) ##Dont download from anywhere but official RubinSystem github unless you ctrl+f this file and search 'INSTALLATION_HEADER' and verify it contains an array and not a string of ruby code. | |
## you'll be fine downloading from here this is just a security issue for 3rd party distrobution | |
#a paylaod could be injected into the install header and run on the interpreter to make system calls and write files | |
##this is dangerous above, replace with this code below after we can do a proper test | |
#d = [] ; old_header[1..-2].split(",").each { |i| d << i }; old_header = d ## there should never be non strings in the install header so this is k | |
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 | |
#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/logmonitor.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 ; self.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.025", "2023-03-13 16:09:24 -0700", "thomas", "3n9yj5its"] ;;;;;##INSTALLATION_HEADER above;;;;;;;;;;## init data;;;;;boot_log = []; $debug = false; MAIN = self; BOOT_INIT_TIME=Time.now; INSTANCE=rand(100000);;;;;begin; DEFAULT_GLOBALS=self.global_variables; begin; DEFAULT_CONSTANTS=MAIN.class.constants; rescue; DEFAULT_CONSTANTS = []; end; DEFAULT_METHODS=self.methods;;;;;INIT_RUBY_ENV=[DEFAULT_GLOBALS,DEFAULT_CONSTANTS,DEFAULT_METHODS]; rescue; INIT_RUBY_ENV=[:ERROR]; end;;;;;;;;;;## verify __FILE__ ;;;;;if File.file?(__FILE__); RUBIN_CORE_FILE = __FILE__;;;;;else; raise "BOOT ERROR: __FILE__ is invalid.";;;;;end;;;;;## verify WRITE_ACCESS;;;;;if File.writable?(Dir.getwd) == false; raise "BOOT ERROR: Write access is not permitted."; end;;;;;;;;;;;;;;;## detect DEBUG_FLAG file;;;;;if File.file?(Dir.getwd+"/debug.flag") or File.file?(Dir.getwd+"/data/config/debug.flag"); $debug = true; end;;;;;DEBUG_FLAG=$debug;;;;;;;;;;;;;;;## check HOST_OS;;;;;if $debug == true; puts "Checking system..."; end;;;;;if ENV["OS"].downcase=="windows_nt" and File.directory?("C:/Windows");;;;; HOST_OS="Windows_NT"; if $debug; print "Windows_NT detected."; end;;;;; if File.writable?("C:/"); if $debug; print " Full Write Access."; end;;;;; elsif File.writable?(Dir.getwd); if $debug; print "Limited Write Access"; end;;;;; end;;;;; system("TITLE RubinSystem"+INSTALLATION_HEADER[2].to_s+" Instance: "+INSTANCE.to_s + " @ " + ENV["USERNAME"].to_s+" ; PID "+$$.to_s+" Dir: "+INSTALLATION_HEADER[1].to_s);;;;; ##############################;;;;;elsif File.directory?("/home");;;;; HOST_OS = "linux";;;;; if $debug; print "Linux detected."; end;;;;;else;;;;; HOST_OS="unknown";;;;; if $debug; print "Unknown Host."; end;;;;;end;;;;;##check HOST_RUBY;;;;;if $debug; print " Ruby: "+RUBY_VERSION.to_s+"\n"; end;;;;;;;;;;;;;;;##check host WORKDIR and make sure its install directory, adjust installation_header if rubin has been moved unexpectedly;;;;;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;;;;; if $debug;;;;; puts "System Install dir was recently moved and info had to be updated before startup.";;;;; puts "Restarting in 3 seconds.";;;;; sleep 3.0;;;;; end;;;;; system("start launch.rb");;;;; sleep 0.2;;;;; exit;;;;; else;;;;; if $debug; puts "BOOT CANNOT CONTINUE, INSTALLATION NOT FOUND"; sleep 3.0; end; raise "BOOT FAILED"#exit;;;;; end;;;;;else;$homedir=Dir.getwd;;;;;end;;;;;;;;;;## BOOT CHECK OK, START INIT;;;;;BOOT_TIME=Time.now ;;;;;;;;;;;;;;;## create global coredir links;;;;;$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.;;;;;;;;;;;;;;;msg=Time.now.to_s+" : BOOT SUCCESS.";;;;;f=File.open($homedir+"/bootlog.log","a");f.write(msg+"\n");f.close;;;;;;;;;;if $debug; puts "Loading RubinSystem... Version "+INSTALLATION_HEADER[2].to_s; end;;;;;;;;;;class RubinSystem;;;;; ;;;;; VERSION=INSTALLATION_HEADER[2].to_s ## LAST VERSION UPGRADE 3.1.2023;;;;; ;;;;; def initialize;;;;;;;;;; end;;;;; def startup;;;;; if defined?(@POST_INITIALIZATION); return "false"; end;;;;; ;;;;; @shutdown = false;;;;; ;;;;; ;;;;; @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 = []#Hidden_Internal_Data[0]] ## 0 is installdirs.;;;;;;;;;; @controller = nil; @instance = nil; @install = nil; @host = nil; @ruby = nil; @network = nil ;;;;; ;;;;; @components=[] ;;;;; @loaded_config = [];;;;; @loaded_scripts = [];;;;; @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 = [];;;;; ;;;;; ## move bootllog from homedir 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;;;;; self.writelog("Rubin.startup: ##### SYSTEM STARTUP IS INITIALIZING ###############################################.");;;;; ;;;;; ;;;;; ## come back and rescue the fuck out of this code;;;;; ## enforce default file system, now we read from hidden internal to get default directories, this way installers can set that up along with default_packages ;;;;; ;;;;; begin;dat = eval(File.read(RUBIN_CORE_FILE).split("#H#;#I#;#D"+"#;"+"#D#;#E#;#N#;#I#;#"+"N#;#T#;#E#;"+"#R#;#N#;#W#;#O#;#R#"+";#D#;#A#;#S#;#S#;#H#\n##")[-1]);;;;; dat=dat[0];;;;; dat.each do |f|;;;;; unless File.directory?(@homedir+f);;;;; Dir.mkdir(@homedir+f);;;;; begin self.errorlog("SYSTEM ERROR: Missing directory repaired: "+@homedir+"/"+f.to_s);;;;; rescue;;;;; end;;;;; end;;;;; end;;;;; rescue;self.errorlog("Rubin.startup: Unable to verify COREDIRS.");;;;; end;;;;;;;;;;;;;;; ## setup config data;;;;; @config_names=["LoadClasses","AutoStartApps","Required",;;;;; "SystemShellAutoStart","DebugMode","DaemondDelay","ShowLogWrites",;;;;; "CtrlNetdir","LoadDefinition","EvaluateFileIO","EvaluateFileIOPrint",;;;;; "RubyGems","AutoScripts","ShellSessions","LoadSysdirComponents",;;;;; "StartupShutdownScripts"];;;;; ;;;;; @config_descriptions=["",;;;;; "",;;;;; "",;;;;; "",;;;;; "",;;;;; ""];;;;; ;;;;; @default_config=[true,[],["bundler/inline","open-uri","net/http"],true,true,10,false,"",true,false,false,[],[],true,true,[true,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.;;;;; SYSTEM.writelog "Rubin.startup: Looking for config...";;;;;;;;;; ##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("Rubin.startup: "+str);;;;; if $debug; puts str.to_s; end;;;;; else;;;;; str = "Altconfig could not be found.";;;;; self.errorlog("Rubin.startup: "+str);;;;; if $debug; puts str.to_s; end;;;;; 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;;;;; if $debug; puts str; end;;;;; 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("Rubin.startup: "+str);;;;; if $debug; puts str; end;;;;; else ##config missing, repair and boot with ini defualt config;;;;; self.save_config ; @loaded_config = "config.cfg";;;;; self.writelog("Rubin.startup: Config couldnt be found, generated default config file.");;;;; str = "Config data was missing or corrupted and had to be restored to default.";;;;; if $debug; puts str.to_s; end;;;;; end;;;;; end;;;;; else ##cfgdir is empty;;;;; SYSTEM.writelog("Rubin.startup: Cfgdir is empty, default config file was generated.");;;;; self.save_config ; @loaded_config = "config.cfg";;;;; str = "Config data was missing or corrupted and had to be restored to default.";;;;; if $debug; puts str.to_s; end;;;;; end;;;;; end;;;;;;;;;; ## load SYSTEM CACHE;;;;;;;;;; if File.file?(@datadir+"/cache.dat"); self.load_cache;;;;; else; self.save_cache;;;;; 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("Rubin.startup: aquired required file: "+f.to_s);;;;; end;;;;; if @loaded_files.length > 0;;;;; if @loaded_files.length>0; s = @loaded_files.length.to_s+" "; else; s = ""; end;;;;; if $debug; puts s+"Required files were loaded."; end;;;;; end;;;;; rescue => e;;;;; self.errorlog("Rubin.startup: Exception in required file: "+ e.to_s+"\n"+e.backtrace.join("\n")+"\n");;;;; end;;;;; elsif @config[2].to_s=="false";;;;; ##no files to load chill;;;;; else ## config is invalid type;;;;; self.writelog("Rubin.startup: Config 2 RequiredFiles contained invalid data, it needs to 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;;;;; if $debug; puts "Loading Ruby Gems..."; end;;;;; 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("Rubin.startup: Attempting to install rubygem: "+r) ;;;;; if $debug; puts "Ruby gem is being installed: "+r+" ..."; end;;;;; 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("Rubin.startup: "+msg);;;;;; if $debug; puts msg; end;;;;; end;;;;; else;require r.to_s ; @loaded_files << r;;;;; end;;;;; end;;;;; end ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ## REWRITE THIS ITS CRAP ;;;;; ;;;;; ##load definition/s if configured;;;;; if @config[8].to_s=="true" and File.file?($homedir+"/system/definitions.rb") == true;;;;; begin;;;;; MAIN.instance_eval(File.read(@homedir+"/system/definitions.rb"));;;;; SYSTEM.writelog("Rubin.startup: Applied system definitions.rb file.");;;;; @loaded_files<<"definitions.rb" ; @loaded_definitions << "definitions.rb";;;;; if $debug; puts "Applied definition: definitions.rb"; end;;;;; rescue => e;;;;; msg="Definitions.rb produced an excption.\n"+e.to_s+"\n"+e.backtrace[0..5].join("\n");;;;; self.errorlog("Rubin.startup: "+msg);;;;; if $debug; puts msg.to_s; end;;;;; end;;;;; elsif @config[8].is_a?(Array) and @config[8].length>0;;;;; if $debug; puts "Loading "+@config[8].length.to_s+" definitions..."; end;;;;; @config[8].each do |file|;;;;; begin;;;;; if file.to_s.downcase == "definitions.rb" and File.file?($homedir+"/system/definitions.rb");;;;; MAIN.instance_eval(File.read($homedir+"/system/"+file.to_s)); @loaded_files << file;;;;; elsif File.file?($datadir+"/definitions/"+file.to_s);;;;; MAIN.instance_eval(File.read($datadir+"/definitions/"+file.to_s)); @loaded_files << file;;;;; SYSTEM.writelog("Rubin.startup: Applied definition file: "+file.to_s);;;;; @loaded_definitions<<file.to_s; @loaded_files << file.to_s;;;;; if $debug; puts "Applied definition: "+file.to_s; end;;;;; else;;;;; SYSTEM.errorlog("Rubin.startup: Unable to locate definition file: "+file.to_s);;;;; end;;;;; rescue => e;;;;; msg="Definitions.rb produced an excption.\n"+e.to_s+"\n"+e.backtrace[0..5].join("\n");;;;; self.errorlog("Rubin.startup: "+msg);;;;; if $debug; puts msg.to_s; end;;;;; end;;;;; end;;;;; end;;;;;;;;;;;;;;;;;;;; ##Load class files if configured to.;;;;; if @config[0].to_s == true;;;;; v=self.load_classes;;;;; if v!=0;if $debug; puts "Loaded "+v.to_s+" classes."; end;;;;; else;if $debug; puts "No classes were found.";end;;;;; end;;;;; elsif @config[0].is_a?(Array) and @config[0].length > 0;;;;; v = 0;;;;; @config[0].each do |c|;;;;; p = $homedir+"/class/"+c;;;;; begin; load p;;;;; self.writelog("Rubin.startup: Class File loaded: "+c);;;;; v+=1;;;;; rescue; self.errorlog();;;;; end;;;;; end;;;;; if v > 0 and $debug == true;;;;; puts "Loaded "+v.to_s+" classes.";;;;; 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, :@app_controller, :@shell, :@instance, :@host, :@install, :@controller, :@network,:ruby].each { |c| @embedded_components << c };;;;; ;;;;; @daemond=SystemDaemond.new;;;;; @app_controller = Apps.new;;;;; @shell=SystemShell.new;;;;; @instance = Instance.new;;;;; @host = Host_Manager.new;;;;; @install = Installation_Manager.new;;;;; @controller = Controller.new;;;;; @network = Network_Manager.new();;;;; @ruby = Ruby_Manager.new();;;;;;;;;; ec=[@daemond,@app_controller,@shell,@instance,@host,@install,@controller,@network,@ruby];;;;; ec.each { |c| @embedded_component_objects << c };;;;;;;;;; SYSTEM.writelog("Rubin.startup: "+@embedded_components.length.to_s+" embedded system components were initialized. "+@embedded_components.to_s);;;;;;;;;; #these components will be post initialized further down ;;;;; ;;;;; ############################################################################################################################;;;;; ############################################################################################################################;;;;; ## system component load, load any files in sysdir besides core files.;;;;; ############################################################################################################################;;;;;;;;;; ##load components;;;;; ;;;;; preconstants=self.class.constants;;;;; ;;;;; @sysdir_components=[];;;;; @component_objects=[];;;;; @components=[];;;;; ;;;;; ##load sysdir components if configed;;;;; if @config[14]==true;;;;; ;;;;; 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 @components.length>0;;;;; self.writelog("Rubin.startup: Loading system component files: "[email protected]_s);;;;; @components.each do |c|;;;;; begin;;;;; load @sysdir+"/"+c; @loaded_files << c.to_s;;;;; rescue => e ;if $debug; puts e.to_s; end;;;;; self.errorlog("Rubin.startup: System component load resulted in excpetion: "+c.to_s+" "+e.to_s+" "+e.backtrace.join("\n"));;;;; end;;;;; end ;;;;; end;;;;; ;;;;; postconstants=self.class.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()");;;;; rescue => e;;;;; self.errorlog("Rubin.startup: 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;;;;; if postivs.length>0;;;;; SYSTEM.writelog("Rubin.startup: Initialized "+postivs.length.to_s+" components. "[email protected]_s);;;;; end;;;;; ;;;;; ## why do we do this again? i forgot;;;;; @components.each do |c|;;;;; self.instance_eval("@component_objects << "+c.to_s);;;;; end;;;;;;;;;; if @embedded_components.length > 0;;;;; ic=[];;;;; @embedded_component_objects.each do |c|;;;;; if c.methods.include?(:post_initialize);;;;; c.post_initialize;;;;; ic << c.class.to_s;;;;; end;;;;; @components << ("@"+c.class.to_s.downcase.to_s.split("rubinsystem::")[-1]).to_sym;;;;; end;;;;; SYSTEM.writelog("Rubin.startup: "+ic.length.to_s+" embedded system components were post initialized: "+ic.to_s);;;;; end;;;;; ;;;;; @component_objects.each do |c|;;;;; if c.methods.include?(:post_initialize);;;;; c.post_initialize;;;;; self.writelog("Rubin.startup: System component post initialized: "+c.to_s);;;;; end;;;;; end;;;;; ;;;;; @components.delete(:@nilclass) ## like maybe figure out where thats comming from, eventually.;;;;; end;;;;; ;;;;; if $debug; puts "Initialized "[email protected]_s+" system components."; end;;;;;;;;;; ## FINAL STARTUP CHECKS;;;;; ;;;;; ;;;;; #########################################################################################################################;;;;; #########################################################################################################################;;;;; ## END OF Rubin.startup ;;;;; self.writelog("Rubin.startup: RubinSystem initialization completed.");;;;; return 0 ##0 is our way of knowing it didnt just fail and return a silent exception or something.;;;;; end ## end up startup init process, post init next;;;;; ;;;;; ;;;;; ;;;;; def post_initialization;;;;; unless defined?(@POST_INITIALIZATION) == "instance-variable" ;;;;; @POST_INITIALIZATION = true;;;;; if @config[1].length > 0 ##we have startup apps to run;;;;; msg = "Loading "+@config[1].length.to_s+" startup apps.";;;;; #if $debug; puts msg; end;;;;; self.writelog(msg);;;;; l=@config[1];;;;; l.each do |app|;;;;; if $debug; puts "Running autostart app: "+app.to_s; end;;;;; self.run(app);;;;; end;;;;; end;;;;; ;;;;; self.writelog("Rubin.post_initialize: System startup successfull.");;;;; if $debug; ;;;;; 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.";;;;; end;;;;; ;;;;; scripts = [];;;;; if @config[12] == true;;;;; scripts = Dir.entries($datadir+"/scripts"); scripts.delete("."); scripts.delete("..");;;;; elsif @config[12].is_a?(Array);;;;; if @config.length > 0;;;;; @config[12].each { |s| if File.file?($datadir+"/scritps/"+s.to_s); scripts << s ; end };;;;; end;;;;; elsif @config[12].is_a?(String);;;;; if File.file?($datadir+"/scripts/"+@config[12]); scripts << @config[12]; end;;;;; elsif @config[12] == false or @config[12].to_s == "";;;;; ;;;;; else;;;;; @config[12] = [];;;;; self.save_config(@loaded_config);;;;; SYSTEM.errorlog("Rubin.startup: Config[12] contains invalid data:" +@config[12].to_s[0..20]+". It had to be reset.");;;;; end;;;;; ;;;;; startupscript=false;;;;; if @config[15] == true; startupscript = true;;;;; elsif @config[15].is_a?(Array) == true; if @config[15][0] == true; startupscript = true; end;;;;; end;;;;; if startupscript == true and scripts.include?("startup.rb") == false and File.file?($datadir+"/scripts/startup.rb");;;;; scripts.insert(0,"startup.rb");;;;; elsif startupscript == false and scripts.include?("startup.rb");;;;; scripts.delete_at(scripts.index("startup.rb"));;;;; end;;;;; ;;;;; if scripts.length > 0 ;;;;; self.writelog("Rubin.post_initialize: Prepairing to load "+scripts.length.to_s+" autostart scripts.");;;;; scripts.each { |s| self.runs(s) } ;;;;; end ;;;;; ;;;;; ;;;;; ############################ ;;;;; ## post init finished;;;;; if @config[3].to_s.downcase=="true";;;;; self.writelog("Rubin.post_initialize: Starting system shell.");;;;; if defined?(NOSHELL)==nil;;;;; if $debug; puts "Starting system shell."; end;;;;; 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 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 instance_id; return INSTANCE ; end;;;;; def get_config;return @config;end;;;;; def components;return @components; end;;;;; def loaded_files; return @loaded_files; end;;;;; def components?; c=Dir.entries(@datadir+"/components").entries; c.delete("."); c.delete(".."); return c; end;;;;; def loaded_components?; return @components; end;;;;; def cls; SYSTEM.shell.cls; end;;;;; ;;;;; def show_config;;;;; str=""; cfg=[]; i=0; @config_names.each { |n| cfg << i.to_s+" "+n.to_s+"= "+@config[i].to_s; i += 1 };;;;; str << "Rubin system config: "+@loaded_config.to_s+"\n\n"; str << cfg.join("\n").to_s+"\n"; return str;;;;; end ;;;;; alias :config? :show_config;;;;; ;;;;; def shortcuts?; Dir.entries(@homedir+"/shortcuts")[2..-1] ; 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 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 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 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 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 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";;;;; 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 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?;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ## we wanna do some cache magic, lowlevel a cachedir obj into some methods here;;;;;;;;;;;;;;;;;;;;;;;;; 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("Rubin.cache: Saved system cache data."); return @cache.to_s.length;;;;; rescue;return false;;;;; end;;;;; end;;;;; ;;;;; def clear_cache;;;;; if @cache_locked==false; @cache=[];;;;; self.writelog("Rubin.cache: Cleared all cache data.");;;;; else; self.writelog("Rubin.cach: clear_cache rejected, cache locked.");;;;; end;;;;; 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 shutdown_sequence *args ## seperate restart and shutdownsbehaviours to here;;;;; if @shutdown != false; return false; end; @shutdown = true;;;;; self.writelog("Rubin.shutdown_sequence: System shutdown process has begun.");;;;;;;;;; shutdownscript=false;;;;; if @config[15] == true; shutdownscript = true;;;;; elsif @config[15].is_a?(Array); if @config[15][1] == true; shutdownscript = true; end;;;;; end;;;;; if shutdownscript == true and File.file?($datadir+"/scripts/shutdown.rb");;;;; begin; SYSTEM.instance_eval(File.read($datadir+"/scripts/shutdown.rb"));;;;; rescue => e ; SYSTEM.errorlog("Rubin.shutdown_sequence: Shutdown script produced and exception: "+e.to_s+"\n"+e.backtrace.join("\n"));;;;; end;;;;; end;;;;;;;;;; self.save_config;;;;; self.save_cache;;;;; if @apps.length > 0;;;;; @apps.each {|a| if a[3].defined?(:shutdown); begin; a[3].shutdown; rescue => e;self.writelog("Rubin.shutdown: App shutdown produced an exception: "+e.to_s+" "+e.backtrace.join("\n"));end end } ## do apps only have one thread? thius might be an array of threads;;;;; @apps.each {|a| v = a[-2]; if v.is_a?(Thread); begin; v.kill ; rescue ; end; end} ## do apps only have one thread? thius might be an array of threads;;;;; self.writelog("Rubin.shutdown_squence: Stopped apps.");;;;; end;;;;; if @daemond!= nil; if @daemond.running? ; @daemond.shutdown; self.writelog("Rubin.shutdown_sequence: Stopped daemond."); end; end ;;;;; begin; File.delete(@datadir+"/sys/instance/"+INSTANCE.to_s+".dat"); rescue; end;;;;; self.writelog("Rubin.shutdown_sequence: System is down.");;;;; if args[0]!= true; Thread.new {@shutdown = 30; 30.times{ sleep 1.0; begin; @shutdown -= 1 ;rescue;;end }; exit }; end;;;;; return @shutdown;;;;; end;;;;; ;;;;;;;;;; ;;;;; def shutdown *args;;;;; if @shutdown != false; return false; end;;;;; 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("Rubin.shutdown: System shutdown has been requested.");;;;; self.shutdown_sequence(true);;;;; if $debug; puts "System is ready to shutdown"; end;;;;; if args[0].to_s!="F"; sleep 2.0; end;;;;; 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.writelog("Rubin.restart: Preparing to restart Rubin, System shutdown process has begun. ");;;;; self.shutdown_sequence(true);;;;; if args[0].to_s!="F"; sleep 1.0;end;;;;; self.host.launch_new(@homedir+"/launch.rb");;;;; if args[0].to_s!="F"; sleep 0.1; end;;;;; exit;;;;; end;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;;;;;;; def hard_restart *args;;;;; proceed=false;;;;; if args[0].to_s[0]=="F"; proceed=true;;;;; else; puts "\nAre you sure you want to HARD RESTART Rubin? You may lose data. (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;;;;; #if @apps.length > 0;;;;; # @apps.each {|a| if a[3].defined?(:shutdown); begin; a[3].shutdown; rescue => e;self.writelog("Rubin.shutdown: App shutdown produced an exception: "+e.to_s+" "+e.backtrace.join("\n"));end end } ## do apps only have one thread? thius might be an array of threads;;;;; # @apps.each {|a| v = a[-2]; if v.is_a?(Thread); begin; v.kill ; rescue ; end; end} ## do apps only have one thread? thius might be an array of threads;;;;; # self.writelog("Rubin.restart: Stopped apps.");;;;; #end;;;;; #if @daemond!= nil; if @daemond.running? ; @daemond.shutdown; self.writelog("Rubin.restart: Stopped daemond."); end; end;;;;; begin;File.delete(@datadir+"/sys/instance/"+INSTANCE.to_s+".dat"); rescue;; end;;;;; self.writelog("Rubin.hard_restart: HARD RESTART, about to restart.");;;;; if args[0].to_s!="F"; sleep 1.0;end;;;;; self.host.launch_new(@homedir+"/launch.rb");;;;; if args[0].to_s!="F"; sleep 0.1; end;;;;; exit;;;;; end;;;;; ;;;;; def hard_shutdown *args;;;;; proceed=false;;;;; if args[0].to_s[0]=="F"; proceed=true;;;;; else; puts "\nAre you sure you want to HARD SHUTDOWN Rubin? You may lose data. (Y/N)";;;;; inp=gets.chomp[0].downcase;;;;; if inp=="y";proceed=true;end;;;;; end;;;;; if proceed;;;;; #self.save_config;;;;; #self.save_cache;;;;; #if @apps.length > 0;;;;; # @apps.each {|a| if a[3].defined?(:shutdown); begin; a[3].shutdown; rescue => e;self.writelog("Rubin.shutdown: App shutdown produced an exception: "+e.to_s+" "+e.backtrace.join("\n"));end end } ## do apps only have one thread? thius might be an array of threads;;;;; # @apps.each {|a| v = a[-2]; if v.is_a?(Thread); begin; v.kill ; rescue ; end; end} ## do apps only have one thread? thius might be an array of threads;;;;; # self.writelog("Rubin.restart: Stopped apps.");;;;; #end;;;;; #if @daemond!= nil; if @daemond.running? ; @daemond.shutdown; self.writelog("Rubin.restart: Stopped daemond."); end; end ;;;;; begin; File.delete(@datadir+"/sys/instance/"+INSTANCE.to_s+".dat"); rescue; end;;;;; self.writelog("Rubin.hard_shutdown: HARD SHUTDOWN, about to shutdown.");;;;; if $debug; puts "System is ready to shutdown"; end;;;;; if args[0].to_s!="F"; sleep 2.0; end;;;;; exit;;;;; end;;;;; end;;;;; ;;;;; ;;;;; ######################################################################################################################################################;;;;; ######################################################################################################################################################;;;;; ## Config methods;;;;; ;;;;; ;;;;; def config *args;;;;; old_config=eval(@config.to_s);;;;; ;;;;; if args.length==0 ## RETURN;;;;; 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 [Int];;;;; return @config[args[0].to_i];;;;; ;;;;; elsif args[0].is_a?(Integer) and args.length==2 ## SET [Int]=;;;;; @config[args[0]]=args[1];;;;; ;;;;; ;;;;; elsif args[0].is_a?(String) or args[0].is_a?(Symbol) and @config_names.include?(args[0].to_s) and args.length==1 ## RETURN [Str];;;;; return @config[@config_names.index(args[0].to_s)];;;;; ;;;;; elsif args[0].is_a?(String) or args[0].is_a?(Symbol) and @config_names.include?(args[0].to_s) and args.length==2 ##;;;;; @config[@config_names.index(args[0].to_s)]=args[1];;;;;;;;;; else;return false;;;;; end;;;;; ## detect changes and perform auto response to config changes;;;;; ci = []; i = 0;;;;; old_config.each { |oc| if oc.to_s != @config[i].to_s; ci << i; end; i+=1 };;;;; if ci.include?(0);;;;; end;;;;; if ci.include?(1);;;;; end;;;;; if ci.include?(2);;;;; end;;;;; if ci.include?(3);;;;; end;;;;; if ci.include?(4) ;;;;; if @config[4] == true; $debug = true; else; $debug = false; end;;;;; if @config[4] == true and File.file?(@cfgdir+"/debug.flag") == false; f=File.open(@cfgdir+"/debug.flag","w");f.close; end;;;;; if @config[4] != true and File.file?(@cfgdir+"/debug.flag") == true; File.delete(@cfgdir+"/debug.flag"); end;;;;; if @config[4] != true and File.file?(@homedir+"/debug.flag") == true; File.delete(@homedir+"/debug.flag"); end ## because boot also checks here;;;;; puts "DEBUG flag was changed: "+$debug.to_s;;;;; end;;;;; return true;;;;; end;;;;; ;;;;; ;;;;; 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 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;;;;; ;;;;; 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"; 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;;;;;;;;;; ;;;;; ##################################################################################################################################;;;;; ##################################################################################################################################;;;;; ## general loading methods shortcut,component / app / script ;;;;;;;;;; ;;;;; ## WE NEED TO WRITE A SHORTCUT METHOD FOR USING THE SHORTCUTS DIRECTORY.;;;;; ;;;;; ;;;;; def shortcut(str) ## load ruby files in a new ruby interpreter window;;;;; if str[-3..-1].to_s.downcase!=".rb";str=str.to_s+".rb";end;;;;; if File.exist?(@homedir+"/shortcuts/"+str.to_s+".rb");;;;; odir=Dir.getwd;;;;; Dir.chdir(@homedir+"/shortcuts");;;;; system("start "+str.to_s+".rb");;;;; Dir.chdir(odir);;;;; return true ;;;;; else;return false;;;;; end;;;;; end;;;;;;;;;; ## load the contents of the class dir;;;;; def load_classdir;;;;; self.writelog("Rubin.load_classdir: 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("Rubin.load_classdir: Loaded class: "+i);;;;; rescue => e;;;;; self.errorlog("Rubin.load_classdir: Loading class file failed: "+i+"\n"+e.to_s+"\n"+e.backtrace.join("\n").to_s);;;;; end;;;;; end;;;;; return (n.length);;;;; else;;;;; self.writelog("Rubin.load_classdir: There were no files to load.");;;;; return 0;;;;; end;;;;; end;;;;;;;;;; alias :load_classes :load_classdir;;;;;;;;;;;;;;; ## note: in the longrun, aargs will be unneeded because args[-1] always contains aargs but for now we will leave that for a tlc update;;;;; ## we added options for internal/external and passing args, finnaly the name should have an extension for external only scripts;;;;; def runs *args ## name, *args, external;;;;; if args.length == 0 or args[0].to_s.length == 0; raise "Invalid arguments, requires String, scriptname."; end ;;;;; if args.length > 1; aargs = args[1]; else; aargs = []; end;;;;; if args.length > 2 and args[2] == true; external = true; else; external = false; end;;;;;;;;;; scriptname = args[0].to_s;;;;; s=@datadir+"/scripts/"+scriptname.to_s;;;;; if s.to_s.downcase.end_with?(".rb") == false; s=s+".rb";end;;;;;;;;;; #puts "LAUNCHING: "+s.to_s;;;;; ## adjust this to check if a script is an external (script.ext.rb), for extrenal scripts, ignore arguement val for ext;;;;; if external == false;;;;; begin;str=File.read(s);;;;; self.writelog("Rubin.runs: running file: "+s.split("/")[-1]);;;;; begin; res = self.instance_eval(str) ; @loaded_files << scriptname; @loaded_scripts << scriptname;;;;; rescue => e; self.writelog("Rubin.runs: File produced an exception: "+s.split("/")[-1]+" Error: "+e.to_s+" ; "+e.backtrace.join("\n")); return e;;;;; end;;;;; if res.to_s != ""; return res;;;;; else; return true;;;;; end;;;;; rescue; self.writelog("Rubin.runs: Failed to access file: "+s.to_s); return false;;;;; end;;;;; else;;;;; odir=Dir.getwd; Dir.chdir(@homedir+"/shortcuts");;;;; aargs = aargs.join(" ");;;;; cmd = "start "+s.to_s+" - "+aargs.to_s;;;;; #puts "ABOUT TO MAKE SYSTEM CALL: "+cmd.to_s;;;;; system(cmd);;;;; Dir.chdir(odir);;;;; return true ;;;;; end;;;;; end;;;;; ;;;;;;;;;; ;;;;;;;;;; def run *args ## appname, *args;;;;; if args.length == 0 or args[0].to_s.length==0; raise "Invalid arguments, requires String, appname."; end;;;;; appname = args[0].to_s;;;;; if args.length > 1; aargs = args[1]; else; aargs=[]; end;;;;; ;;;;; #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("Rubin.run: App could not be found: "+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;;;;; ;;;;; self.writelog("Rubin.run: Loading app file: "+path.to_s);;;;; begin; f=File.open(path,"r");source=f.read;f.close;;;;; rescue; self.writelog("Rubin.run: Unable to read app file: "+psth.to_s);;;;; end;;;;; ;;;;; @threads=[];threads=[];@app=nil;@appshell=false;;;;;;;;;; self.writelog("Rubin.run: Running app file: "+appname.to_s+".rb");;;;; begin; self.instance_eval(source); @loaded_files << appname ## APPS run on RUBINSYSTEM context;;;;; rescue => e;;;;; self.writelog("Rubin.run: App eval exception: "+appname.to_s+" Error: "+e.to_s+" : "+e.backtrace.join("\n"));;;;; msg = "App encountered an exception.\n"+e.to_s+"\n"+e.backtrace.join("\n");;;;; self.errorlog(msg);;;;; return msg;;;;; end;;;;; ;;;;; 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;;;;; ## i think we do, comonent apps will probably step in an grap app objects if they actually get made by an app.;;;;; app = [appname,rand(1000000),Time.now.to_s,threads,appobj];;;;; @apps<< app;;;;; ;;;;; ##so soon the @loaded_apps variable will lose importance and become more like @loaded_files, just to keep track of loaded apps and their obj returns.;;;;; @loaded_apps<<[appname,Time.now.to_s];;;;; @threads=[];@app=nil;;;;;;;;;; self.writelog("Rubin.run: App load success: "+appname.to_s);;;;; ;;;;; #start shell for app;;;;; if @appshell.to_s!="false";;;;; self.writelog("Rubin.run: App is opening its self in the system shell.");;;;; self.shell.start(@apps[-1][-1]);;;;; end;;;;; ## return an id for the app if run success;;;;; return app[1];;;;; end;;;;; ;;;;; ;;;;; ################################################################################################################################################# ;;;;; #################################################################################################################################################;;;;; ## ect methods ;;;;; ;;;;;;;;;; def help *args;;;;; if args.length==0;;;;; puts "##################################################################";;;;; puts "## ";;;;; puts "## Welcome to the Rubin system";;;;; 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: "+BOOT_TIME.to_s;;;;; sec=Time.now-BOOT_TIME;;;;; 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;;;;; ;;;;; 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 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 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;;;;;;;;;;;;;;; ##################################################################################################################################################;;;;; ##################################################################################################################################################;;;;; ## SHORTCUT METHODS AND ALIASES;;;;;;;;;; def restart_link; self.restart("F"); end;;;;; def shutdown_link; self.shutdown "F"; end; ;;;;; def hardrestart_link; self.hard_restart("F"); end;;;;; def hardshutdown_link; self.hard_shutdown "F"; end; ;;;;;;;;;; def run_last; self.shell.run_last_session; return "Last shell session will be evaluated."; end;;;;; def rerun; self.shell.evaluate_session(self.shell.session[0..-1]); end;;;;; ;;;;; def spawn;;;;; if HOST_OS == "linux"; return "I havent been coded to do this on linux yet. Try Windows NT.";;;;; elsif HOST_OS == "Windows_NT";;;;; gotodir="C:/users/"+ENV["USERNAME"][0..-2]+"/onedrive/desktop";;;;; install.generate_installer;;;;; f=File.open(@datadir+"/backups/rubin_installer.rb","r"); dat=f.read; f.close;;;;; f=File.open(gotodir+"/rubin_installer.rb","w"); f.write(dat); f.close;;;;; return "The installer was made and put on your desktop.";;;;; else;;;;; return "Cannot proceed on unknown host: "+HOSt_OS.to_s;;;;; end;;;;; end;;;;; ;;;;; def show_shortcut_methods;;;;; str = [];;;;; str << "ss : show this list";;;;; str << "rr : restart('F')";;;;; str << "ee : shutdown('F')";;;;; str << "rt : retry_last_session / shell.run_last_session";;;;; str << "rd : retry_current_session / shell.run_session(current_session) ";;;;; str << "hr : hard_restart('F')";;;;; str << "hs : hard_shutdown('F')";;;;; str << "ii : install.generate_installer (to desktop)";;;;; return str.join("\n")+"\n";;;;; end;;;;;;;;;; alias :ss :show_shortcut_methods;;;;;;;;;; alias :rr :restart_link;;;;; alias :ee :shutdown_link;;;;; alias :rt :run_last;;;;; alias :rd :rerun;;;;; alias :hr :hardrestart_link;;;;; alias :hs :hardshutdown_link;;;;; alias :ii :spawn;;;;;;;;;; ####################################################################################################################################;;;;; ####################################################################################################################################;;;;; ####################################################################################################################################;;;;; ####################################################################################################################################;;;;; ####################################################################################################################################;;;;; ####################################################################################################################################;;;;; ####################################################################################################################################;;;;; ####################################################################################################################################;;;;; ####################################################################################################################################;;;;; ####################################################################################################################################;;;;; ####################################################################################################################################;;;;; ####################################################################################################################################;;;;; ####################################################################################################################################;;;;; ############ ;;;;; ############ ;;;;; ############ ;;;;; ############ ;;;;; ############ ;;;;; ############ 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;;;;; @running = false;;;;; end;;;;; def running?; @running; end;;;;; def post_initialize;;;;; unless defined?(@@DAEMOND_RUNNING);@@DAEMOND_RUNNING=true;;;;; @running=true ;;;;; SYSTEM.writelog "Rubin::Daemond.post_initialize: Preparing to run the daemond." ;;;;; ;;;;; ##################################################;;;;; ##################################################;;;;; ## 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("Rubin::Daemond: 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("Rubin::Daemond: 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;;;;; ;;;;; 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;;;;; ;;;;; @thread_pool=thread_pool ##daemond thread and other system threads.;;;;; @grave_pool=[] ## where dead threads go for fun;;;;; if $debug; puts "System Daemond is now active."; end;;;;; ############################;;;;; 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 shutdown ##special things for shutdown ;;;;; self.kill;;;;; 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;;;;; @mode = ""; @state = "init";;;;; @context=nil;;;;; @cid=nil;;;;; @password_entry_mode=false;;;;; ;;;;; ;;;;; @previous_session= [];;;;; @session=[] ##input log;;;;; @session_history = [];;;;; ;;;;; @context = nil;;;;; @context_history = [];;;;; @cid = 0 ;;;;; @main_loop = false;;;;; ;;;;; @cfgdir=SYSTEM.cfgdir+"/systemshell.cfg";;;;; @logdir=SYSTEM.logdir+"/systemshell.log";;;;; @slogdir=SYSTEM.logdir+"/systemshellstream.log";;;;; if File.file?(@slogdir) == false; f = File.open(@slogdir,"w");f.close; end;;;;; ;;;;; @sesdir = SYSTEM.logdir+"/shellsessionmajor.log";;;;; ;;;;; ;;;;; ;;;;; @default_config = [true,true,false] ;;;;; @sconfig = @default_config ;;;;; @config_names = ["EnableShellLog","EnableShellSessions","SessionsIncludeOutput"];;;;; ;;;;; @session_separator = "#################################################################################################################";;;;; ;;;;; if File.file?(@cfgdir) == false; self.save_config;;;;; else; self.load_config;;;;; end;;;;; if File.file?(@logdir) == false ; f = File.open(@cfgdir,"w");f.close;end;;;;; if File.file?(@sesdir) == false ; f = File.open(@sesdir,"w");f.close;end;;;;; ;;;;; ;;;;; ;;;;; SYSTEM.writelog("Rubin::Shell.initialize: A Shell component was initialized: "+self.to_s+".") ;;;;; end;;;;; ;;;;; def save_config; f = File.open(@cfgdir,"w"); f.write(@config.to_s); f.close; ; return true; end;;;;; ;;;;; def load_config;;;;; f = File.open(@cfgdir,"r");dat=f.read;f.close;;;;; dat = eval(dat);;;;; @config = dat;;;;; return true;;;;; end;;;;; ;;;;; ;;;;; ;;;;; ;;;;; def running?; if @main_loop == true; return true; end; end;;;;; def repl?; if @main_loop == true and @mode.to_s == "repl"; return true; else; return false; end; end;;;;; def mode?; return @mode; end;;;;; def state?; return @state; end ;;;;; def context?; return @context; end;;;;; def context_history; return @context_history; end;;;;; def set_context(c); @context=c; end;;;;; #def previous_session; return @previous_session; end;;;;; ;;;;; ##start / stop REPL shell session;;;;; ;;;;; def start *args;;;;; @mode = "repl"; @state = "starting-repl-session";;;;; @session = []; @context = nil; @cid = 0; @context_history = [];;;;; ;;;;; f=File.open(@sesdir,"r"); dat=f.read; f.close;;;;; if dat.end_with?(@session_separator+"\n") or dat.end_with?(@session_separator);;;;; else;;;;; f=File.open(@sesdir,"a"); f.write(@session_separator+"\n"); f.close;;;;; end;;;;; ;;;;; if args.length>0;self.enter_main_loop(args[0]);;;;; else; self.enter_main_loop;;;;; end;;;;; end;;;;; ;;;;; def stop;;;;; if @main_loop == true;;;;; @main_loop = false;;;;; @state = "inactive";;;;; ;;;;; return true;;;;; else;;;;; return false;;;;; end;;;;; end;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ## REPL;;;;; def enter_main_loop *args;;;;; if args.length==0;context=MAIN;else;context=args[0];end;;;;; @main_loop=true;@cid=0;@context=context;@state="repl-begin";;;;; while @main_loop ########################;;;;; print @context.class.to_s+":"[email protected]_s+"<< ";;;;; @input = gets.chomp;res=nil; @state = "repl-eval";;;;; ses = [Time.stamp,@context.to_s,@input.to_s];;;;; ;;;;; ## process input;;;;; if @input == "exit";@main_loop=false;res="Exiting shell.";;;;; elsif @input[0..8]=="*context=" and @input.to_s.length>9;;;;; begin;@context=instance_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;;;;;;;;;; if SYSTEM.config(:ShellSessions) == true;;;;; @session << ses; @state = "repl-in";;;;; begin; f = File.open(@sesdir,"a"); f.write(ses.to_s+"\n"); f.close;;;;; rescue; SYSTEM.errorlog("Rubin::Shell.enter_main_loop: Failed to log session activity.");;;;; end;;;;; end;;;;; ;;;;; @state="repl-out";;;;; ## send output;;;;; unless res==:NO_RESULT; print @context.class.to_s+":"[email protected]_s+">> "+res.to_s+"\n"; end;;;;; @cid+=1;@password_entry_mode=false;;;;; end; @state="repl-end"; @mode = "" ##this is the end of the loop ##########;;;;; end;;;;;;;;;;;;;;; ## SESSION;;;;; def run_session *args # session, starting_context;;;;; if args[0].is_a?(Array)==false; raise "Input requires an array."; end;;;;;;;;;; old_mode = @mode; @mode = "eval-session"; @state = "session-begin";;;;; old_context = @context; old_cid = @cid; @cid = 0;;;;; ;;;;; if args[0][0].is_a?(Array); session=self.prep_session(args[0]);;;;; elsif args[0].length>0 and args[0][0].is_a?(String);;;;; session = args[0];;;;; else; raise "Invalid arguement: "+args[0].to_s;;;;; end;;;;; ;;;;; if args.length>1; @context = args[1]; else; @context=SYSTEM; end;;;;; if args.length>2 and args[2] == true; prin = true; else; prin = false; end ;;;;; ;;;;; sessionl = [] ;;;;; if @main_loop == true; was_main_loop_true = true; else; was_main_loop_true = @main_loop; @main_loop = true; end;;;;; ;;;;; ;;;;; session.each do |line|;;;;; if @main_loop != true; SYSTEM.writelog("Rubin.shell.evaluate_session: The eval loop BREAK, index:"+session.index(line).to_s+" : "+line.to_s);;;;; break;;;;; end;;;;; ;;;;; ses = [Time.stamp,@context.to_s,line] ;;;;; ;;;;; if prin; print @context.class.to_s+":"[email protected]_s+"<< "; end;;;;; @input = line.to_s; if prin; print line.to_s+"\n"; end;;;;; ;;;;; if line == "exit";@main_loop=false;res="Exiting shell.";;;;; ;;;;; elsif line[0..8]=="*context=" and @input.to_s.length>9;;;;; ;;;;; @state="session-eval";;;;; 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");;;;; SYSTEM.errorlog("Shell passed by an exception: Context: "[email protected]_s+"cid: "[email protected]_s+" :"+e.to_s+"\n"+e.backtrace.join("\n")+"\n" );;;;; end;;;;; ;;;;; end;;;;; @state="session-out";;;;; ;;;;; if @config[1] == true;;;;; sessionl << ses;;;;; f = File.open(@sesdir,"a"); f.write(ses.to_s); f.close;;;;; end;;;;; ;;;;; unless res==:NO_RESULT;;;;; if prin; print @context.class.to_s+":"[email protected]_s+">> "+res.to_s+"\n"; end;;;;; end;;;;; ;;;;; @cid+=1;@password_entry_mode=false;;;;; end;;;;; ;;;;; ;;;;; @cid = old_cid; @context = old_context; @mode = old_mode; @cid = old_cid;;;;; if was_main_loop_true != false ; @main_loop = was_main_loop_true; end;;;;; @state = "inactive";;;;; SYSTEM.writelog("Rubin::Shell.evaluate_session: Session was evaluated and completed, ran "+sessionl.length.to_s+" commands.") ;;;;; return sessionl;;;;; end;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; def cls;;;;; if HOST_OS == "Windows_NT"; system("CLS"); return "The screen was cleared.";;;;; else; return "This method only works on windows.";;;;; end;;;;; end;;;;; ;;;;; ;;;;; ;;;;; def sessions *args;;;;; begin; f = File.open($logdir+"/shellsessionmajor.log","r"); dat=f.read.to_s; f.close;;;;; if dat.length==0; raise "Error: Data file empty."; end;;;;; rescue; raise "Error: Unable to read file: shellsessionmajor.log.";;;;; end;;;;; sessions=[];;;;; raw_sessions = dat.to_s.split(@session_separator);;;;; if raw_sessions.length == 0 ; raise "There were no sessions."; end;;;;; raw_sessions.each do |ch|; session = [];;;;; s = ch.split("\n");;;;; if s.length > 0;;;;; s.each { |c| i = eval(c); if i != nil; session << i; end };;;;; end;;;;; sessions << session;;;;; end ;;;;; if args.length>0 and args[0].is_a?(Integer) or args.length>0 and args[0].is_a?(Range);;;;; r = sessions[args[0]] ;;;;; elsif args.length == 0;;;;; r = sessions;;;;; end;;;;; end;;;;; ;;;;; def prep_session(session);;;;; i = [];;;;; session.each do |s|;;;;; i << s[2];;;;; end;;;;; return i;;;;; end;;;;; ;;;;;;;;;; def wipe_sessions;;;;; begin;;;;; f = File.open($logdir+"/shellsessionmajor.log","w"); f.write(""); f.close;;;;;; f = File.open($logdir+"/shellsessionmajor.log","a"); f.write(@session_separator.to_s+"\n"); f.close;;;;; return true;;;;; rescue; raise "Failed to wipe log files.";;;;; end;;;;; end;;;;; ;;;;; ;;;;; def save_session *args # path, array;;;;; if args.length < 2; raise "Input requires String and Array."; end;;;;; if args[0].is_a?(String) == false or args[1].is_a?(Array) == false; raise "Invalid input."; end;;;;; if File.file?(@datadir+"/"+args[0].to_s);;;;; path = @datadir+"/"+args[0].to_s;;;;; elsif File.file?(args[0].to_s);;;;; path = args[0].to_s;;;;; else; raise "Invalid name or directory.";;;;; end;;;;; if args[1].length == 0 or args[0].length == 0; raise "Invalid input for session."; end;;;;; session = args[1].to_s;;;;; f = File.open(path,"w"); f.write(session); f.close;;;;; return true;;;;; end;;;;; ;;;;; def load_session(path);;;;; if File.file?(path.to_s); vpath = path.to_s;;;;; elsif File.file?(@datadir+"/"+path.to_s); vpath = @datadir+"/"+path.to_s;;;;; else; raise "No such file.";;;;; end;;;;; begin; f = File.open(vpath,"r"); dat = f.read; f.close;;;;; rescue; raise "File read failed.";;;;; end;;;;; session = [];;;;; begin; session = eval(dat);;;;; rescue; raise "File was corrupted.";;;;; end;;;;; return session;;;;; end;;;;;;;;;; def save_current_session *args ## path;;;;; if args[0].is_a?(String) == false; raise "Invalid input."; end;;;;; if File.directory?(args[0].to_s.split("/")[0..-2].join("/"));;;;; path = args[0].to_s;;;;; else; raise "Invalid name or directory.";;;;; end;;;;; session = self.sessions[-1];;;;; if session.length > 0 ;;;;; f = File.open(path,"w"); f.write(session.to_s); f.close;;;;; return true;;;;; else; raise "Session is empty.";;;;; end;;;;; end;;;;; ;;;;; def session; return self.sessions[-1]; end;;;;; def previous_session; return self.sessions[-2]; end;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ## if we use a session wrapper to hold the array, we dont have to worry about screen text multiplication;;;;; class Session;;;;; def initialize *args;;;;; @session = args[0];;;;; if args[1].to_s == "true"; @store_output_mode = true; else; @store_output_mode = false; end;;;;; end;;;;; def get_session; return @session; end;;;;; def get_inputs; ; 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?;;;;; apps = SYSTEM.instance_variable_get("@apps");;;;; if apps.length == 0 ; return [];;;;; else;;;;; names=[];;;;; apps.each { |a| names << [a[0].to_s,a[1].to_s]};;;;; return names;;;;; end;;;;; 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/logmonitor.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("Rubin::Controller.post_initialize: Evalbinding is running, eval: "+SYSTEM.config(9).to_s+", Bound to dir:"+@network_directory.to_s);;;;; if $debug; puts "Controller "+SYSTEM.instance.id.to_s+" binding directory: "+@network_directory.to_s; end;;;;; ;;;;; elsif SYSTEM.config(7).to_s=="" or SYSTEM.config(7) == nil or SYSTEM.config(7).to_s == "false";;;;; @network_directory="";;;;; SYSTEM.writelog("Rubin::Controller.post_initialize: Network directory not set, using fileio dir but not launching eval binding.");;;;; @controller_state = "inactive";;;;; if $debug; puts "Controller binding: turned off"; end;;;;; else;;;;; SYSTEM.errorlog "Rubin::Controller.post_initialize: Network directory was invalid. You can reconfigure it using SYSTEM.config(7,'path')." ;;;;; @controller_state = "failed init";;;;; if $debug; puts "Controller binding: error"; end;;;;; 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;;;;; SYSTEM.writelog("Rubin::Controller.start_main_binding: Created main binding object. Eval: "+SYSTEM.config(9).to_s+ "Dir: "+@network_directory.to_s);;;;; 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 running?; @binding.running?; 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("Rubin::Controller: Directory 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("Rubin::Controller: 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;;;;; ;;;;; if SYSTEM.config(9).to_s == "true"; @eval_allowed=true; else; @eval_allowed = false; 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;;;;; ;;;;; def running?; return @running; end;;;;; ;;;;; def eval?; if self.running? and SYSTEM.config(9) and @eval_allowed; return true; else; return false; end; end;;;;; ;;;;; end;;;;; ;;;;; ;;;;;end;;;;;;;;;; ;;;;; ;;;;; ################################################################################################################################;;;;; ################################################################################################################################;;;;; ##;;;;; ;;;;; class Network_Manager;;;;; ##;;;;; #;;;;; #;;;;; def initialize;;;;; end;;;;; def post_initialize;;;;; end;;;;; ;;;;; ;;;;; def shutdown; ; 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 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 ## end of the massive RubinSystem class;;;;;;;;;;;;;;;SYSTEM=RubinSystem.new ##initialize the class object first;;;;;SYSTEM.startup ##load and initialize resources;;;;;SYSTEM.post_initialization ##run autostart apps/scritps and maybe shell;;;;;;;;;;;;;;;#puts "Rubin has let go of the flow, Press any key to exit..."; gets;;;;;;;;;;#H#;#I#;#D#;#D#;#E#;#N#;#I#;#N#;#T#;#E#;#R#;#N#;#W#;#O#;#R#;#D#;#A#;#S#;#S#;#H#;;;;;##[["/app","/class","/data","/shortcuts","/data/appdata","/data/config","/data/logs","/data/user","/data/definitions","/data/fileio","/data/backups","/data/temp","/data/sys","/data/sys/instance"],[]]#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 LOG VIEWER: "+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/logmonitor.rb#1#::#1#::#0#::#0#::#0#::#0#::#1##check if we are in a rubin directory;;;;;#begin;;;;;;;;;;## refuse to run if launched internnaly.;;;;;if defined?(SYSTEM).to_s != ""; raise "ExternalApp refused to run in non main context: "+self.to_s; end;;;;;;;;;;name = ARGV[1].to_s ## argv is probably already a string at launch;;;;;;;;;;install_dir=Dir.getwd.to_s.downcase.split("/rubin/")[0]+"/rubin";;;;;;;;;;if File.file?(name) == true; logpath = name;;;;;elsif File.file?(install_dir+"/data/logs/"+name) == true;;;;; logpath = install_dir+"/data/logs/"+name;;;;;#elsif File.file?() == true;;;;;#elsif File.file?() == true;;;;;#elsif File.file?() == true;;;;;else; raise "Cannot find file: "+name.to_s;;;;;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;;;;;;;;;;#rescue => e; puts "Exception: "+e.to_s+"\n"+e.backtrace.join("\n"); puts "Press enter to exit."; gets;;;;;#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;;;;;launch_directory=Dir.getwd; launch_time=Time.now;;;;;;;;;;##prompt;;;;;puts "Welcome to the Rubin System installer. Version "+VERSION.to_s;;;;;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 { inp=gets.chomp.to_s; if File.directory?(inp.to_s); install_dir=inp.to_s; break;elsif inp.to_s.downcase == "exit"; exit; else; puts "Invalid directory."; 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;;;;; ;;;;;#split up package 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 { |d| p=d.split(filenamesep)[0]; di=d.split(filenamesep)[1]; nfile_data<<[p,di] };;;;;file_data=nfile_data;;;;; ;;;;;#proces index;;;;;f = index_string.split("??")[0].split("?");;;;;di = index_string.split("??")[1].split("?");;;;;;;;;;;;;;;#build dirs;;;;;Dir.mkdir(dir.to_s+"/rubin");;;;;di.each { |p| np=dir+"/"+p; Dir.mkdir(np) };;;;;;;;;;# write files;;;;;file_data.each { |fd| p=dir.to_s+"/"+fd[0].to_s; f=File.open(p,"w"); f.write(fd[1].to_s); f.close };;;;;;;;;;## write installation_header;;;;;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#1#::#1#::#0#::#0#::#0#::#0#::#0#/rubin/documentation.txt#1#::#1#::#0#::#0#::#0#::#0#::#1# Documentation for Rubin version 1.0 Windows_NT, released Feb 2023.;;;;; RubinSystem 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/components non system component files;;;;; /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 rb file in it besides 'rubin.rb', the 'definitions.rb' or;;;;; 'deamond.rb', will be treated as a system component and loaded, all classes in a component are declared;;;;; then initialized into an instance variable sharing their name. Then if any contain a method named;;;;; :post_initialize it will be called. If its not a component its a core file, rubin is a required core file.;;;;; the other two are optional. daemond.rb contains extra threads for Rubin::Daemond to run, daemond is in the;;;;; limbo area between component and system class but it is not treated as a component because of how it works. ;;;;; ;;;;; The daemond file.;;;;;;;;;; The system daemonds job is to run hardcodded system serviced in addition to the daemond file contents.;;;;;. The daemond class also holds a threadpool that can be used to hold references to threads anywhere in the program.;;;;;;;;;; ;;;;; 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 starting, 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*;;;;; but as for now there are still a small number of dependancies on this file. Time.stamp for example.;;;;;;;;;;;;;;; Apps and app development.;;;;; ;;;;; The app directory stores two types of apps, an app can be a what-ever named rb file, or a folder with;;;;; an rb file inside sharing its name as an entry point, at this point i call it a program. Apps can store data;;;;; and work with it in their install dir but its often better to use /rubin/data/appdata and make a folder;;;;; with the apps name to work with. This dir is called appdatadir.;;;;;;;;;; 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 don't 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.;;;;; ;;;;; After running an app it gets pushed into @apps just to be clear, then returns the instance id. You can;;;;; get the app by using SYSTEM.apps.get("id"). Another thing to note is that if an app includes the method;;;;; :shutdown it will be called by the system during a shutdown event.;;;;;;;;;;;;;;; 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. Class files can be exported into;;;;; a definitions file, and visa versa. Config index 0 = true for load classdir on startup.;;;;;;;;;; ;;;;; 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 can also use the config;;;;; items name instead of its number. i.e. SYSTEM.config(:DebugMode,true). Use SYSTEM.config? to print a readable;;;;; list of config data to the console. Use system.config to get config data. SYSTEM.save_config saves to config.cfg;;;;; by default but can be passed the name of an alternative config file to save as. SYSTEM.load_config works the same.;;;;; There is also an altconfig.cfg file which can contain the name of a config file to run, altconfig.cfg is always;;;;; loaded first if it exists, if not there can be preconfig.cfg files to, they can also have numbers like preconfig9.cfg.;;;;; If there is no altconfig but a preconfig, the lowest numbered one will be loaded and deleted unless preconfiglock flag;;;;; is true.(SYSTEM.lock_preconfig). If no altconfig or preconfig exist and a config file cannot be found, default config;;;;; is loaded and saved as config.cfg.;;;;; Finally note that you can read and write config like this: SYSTEM.write_config("config.cfg",9,true).;;;;;;;;;; ;;;;; System Boot order;;;;;;;;;; 1. check work directory, check system, prepare boot.;;;;; 2. Initialize Rubin_System class object, load config data and cache.;;;;; 3. Check config for ruby gems and install them if they arent already.;;;;; 4. Check definitions and load if configured. ;;;;; 5. Load embedded system components then check sysdir for component files.;;;;; 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. Post Init finished, if flow isnt grabbed its returned to main and the interpreter exits.;;;;; ;;;;; 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.;;;;; 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. The shell saves sessions and you can run the last sessions input again using shell.run_session(shell.sessions[-2]).;;;;; ;;;;;;;;;; Building an app.;;;;; Here is a simple straight forward modle of an app file;;;;;;;;;; ###### App.rb;;;;; class App;;;;; def initialize;;;;; @t=nil;;;;; end;;;;; def post_initialize;;;;; @t1=Thread.new{ 100000.times {rand}};;;;;;;;;; ## SYSTEM.instance_variable_set("@threads",[@t]) ## this is only for when your program does not return flow control to the system until after it closes.;;;;; end;;;;; def shutdown;;;;; end;;;;; end;;;;; @app=App.new;;;;; @app.post_initialize;;;;;;;;;; @threads<<@app.instance_variable_get("@t1") ## this can be trickey to order if your program doesnt run on threads or doesnt return flow control, see above;;;;; ########;;;;;;;;;; @app and @threads are system reserved and are collected for data if they happen to contain any after an app;;;;; file is ran. If you define a method in your app called :shutdown 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, You have the methods apps.get *args "InstanceId";;;;; to get running apps, running an app returns its instance id.;;;;;;;;;;;;;;;;;;;; System Basics:;;;;; ;;;;; You can refer to the keyword cheatsheet file for a list of most important keywords. ;;;;; ;;;;; dir *args gets / sets workdir;;;;; dirs *args returns array of system dirs, return a path if given an integer or the name of a dir, i.e: cfgdir,datadir,appdir;;;;; homedir methods actually exist to access all the system dir paths by name;;;;; @homedir as well as instance variables, and global variables.;;;;;;;;;; config? prints a very readable list of config data.;;;;; config *args get/set config use indexnumber or cfg name then value as args.;;;;; ;;;;; apps?;;;;; scripts?;;;;; shortcuts?;;;;; components?;;;;; definitions?;;;;; ;;;;; run(app);;;;; runs(script);;;;; load_definition(file);;;;; load_component(file);;;;; load_classdir;;;;; import_classdir(name);;;;; export_classdir(name);;;;; ;;;;; restart *args F to skip dialig;;;;; shutdown *args F;;;;;;;;;; instance.pop;;;;; con.members?;;;;; con.request("id","script");;;;; install.size?;;;;; install.generate_installer;;;;; install.generate_package(name);;;;; install.default_build_package ;;;;; install.install_package(name,dir);;;;; host.call(cmd);;;;; ;;;;; shell.start;;;;; shell.stop;;;;; shell.context;;;;; shell.session;;;;; shell.previous_session;;;;; shell.run_last_session;;;;; shell.sessions;;;;; shell.run_session(session);;;;; ;;;;; @loaded_files;;;;; @loaded_config;;;;; config_files?;;;;; save_config *args;;;;; load_config *args;;;;; read_config(name);;;;; write_config(name,index,value);;;;; logs?;;;;; measure_logs;;;;; clean_logs;;;;; read_log(name);;;;; writelog *args String, "", Bool (print to screen);;;;; ;;;;; ;;;;; And remember you have aliases like lm for local_methods, which shows methods made after a class initialized, iv for instance_variables;;;;; and constants to get classes and other objects.;;;;;#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.;;;;;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;;;;;@loaded_system_components;;;;;;;;;;@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.components?;;;;;SYSTEM.load_component(name) bugged cause needs a rewrite from where it was pasted;;;;;;;;;;SYSTEM.logs?;;;;;SYSTEM.measure_logs;;;;;SYSTEM.clean_logs;;;;;SYSTEM.read_log *args String name, Integer index;;;;;;;;;;SYSTEM.config_files?;;;;;SYSTEM.read_config *args String name, Integer index;;;;;SYSTEM.write_config(name,index,value);;;;;;;;;;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.shell;;;;;SYSTEM.shell.start *args Context;;;;;SYSTEM.shell.stop;;;;;SYSTEM.shell.run_session(Array);;;;;SYSTEM.shell.session;;;;;SYSTEM.shell.previous_session;;;;;SYSTEM.shell.run_last_session;;;;;SYSTEM.shell.sessions;;;;;SYSTEM.shell.log;;;;;;;;;;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 installations dir system and core files.;;;;;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.generate_installer Uses the unpackeged_installer.rb script to make an installer from the systems core files.;;;;;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