Skip to content

Instantly share code, notes, and snippets.

@thomasjslone
Created May 31, 2023 15:11
Show Gist options
  • Save thomasjslone/3d43730250189cc3bb8db0d6eab32504 to your computer and use it in GitHub Desktop.
Save thomasjslone/3d43730250189cc3bb8db0d6eab32504 to your computer and use it in GitHub Desktop.
most recent ve4sion
VERSION='1.0.30'
## RubinSystem is a ruby app runtime environment. Multi-Instance, bot controller on Mingw Windows Ruby
## ## !! WARNING !! If you did not download this script from github or the official website, DO NOT RUN IT!
## Run this script to install Rubin System, either select the work directory or enter an install location.
## After installing run "launch.rb" and you will get the system shell by default. The shell runs input as
## ruby script on the RubinSystem context. Precede a command with * if you are entering windows scripts
## or host commands, also *context=MAIN changes shell context. The shell does not handle stack errors well
## so IRB is used to catch error messages that crash the shell.
##
## Upon first use, you will get a default system config, use SYSTEM.config? to see what config settings
## you have, another tip is that you have :local_methods to compliment :methods, except :local_methods will
## only return methods that belong to the instance of the object and not any parents.
## Better documentation is underway but struggles to keep up with rapid development.
## email bugs to rubinsystem@gmail.com
#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#::#1#::#1#/rubin/system/daemond.rb?/rubin/system/definitions.rb?/rubin/launch.rb?/rubin/doc.txt?/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/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{};;;;;;;;;;;;;;;;;;;;;;;;;# @launch_system_services_thread = Thread.new {;;;;;# loop do;;;;; # puts SYSTEM.apps.get.to_s;;;;; ;;;;;;;;;;;;;;; # sleep 30.0;;;;;# end;;;;;# }#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;;;;;;;;;;# ALPHABETIC CHARACTERS;;;;;ALPHA= ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];;;;;# ALPHANUMERIC CHARACTERS;;;;;ALPHANUM = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"];;;;;## ASCII CHARACTERS;;;;;CHARS = [] ; c = 0 ; 256.times{ CHARS << c.chr.to_s ; c += 1 };;;;;## SYMBOL CHARACTERS;;;;;;;;;;## 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"];;;;;# RUBY KEYWORDS;;;;;KEYWORDS = ["alias", "and", "begin", "break", "case", "class", "def", "defined?", "do", "else", "elsif", "end", "ensure",;;;;; "false", "for", "if", "in", "module", "next", "nil", "not", "or", "redo", "rescue", "retry" "return", "self",;;;;; "super", "then", "true", "undef", "unless" "until", "when", "while", "yield", "loop"];;;;;# RUBY OPERATORS;;;;;OPERATORS = ["+", "-", "*" ,"/", "%", "**", "==", "!=", ">", ">=", "<", "<=", "<=>", "===", ".eql?", "equal?", "!~",;;;;; "=~", "&", "|", "^", "~", "&&", "||"];;;;;# RUBY DATA TYPES;;;;;DATATYPES = ["Numeric", "Integer", "Float", "BigDecimal", "Rational", "Complex", "String", "Symbol", "Array", "Hash",;;;;; "Range", "Regexp", "Time", "Date", "DateTime", "TrueClass", "FalseClass", "NilClass"];;;;;;;;;;# GLOBAL LINKS TO DATA;;;;;$ALPHA = ALPHA;;;;;$ALPHANUM = ALPHANUM;;;;;$CHARS = CHARS;;;;;$BINARY = BINARY;;;;;$HEX = HEX;;;;;$DAYS = DAYS;;;;;$MONTHS = MONTHS;;;;;$SEASONS = SEASONS;;;;;$KEYWORDS = KEYWORDS;;;;;$OPERATORS = OPERATORS;;;;;$DATATYPES = DATATYPES;;;;;;;;;;;;;;;def benchmarked_load(script);;;;; unless File.file?(script); raise "No such file."; end;;;;; begin;;;;; t1 = Time.now;;;;; load(script);;;;; t2=Time.now;;;;; return t2-t1;;;;; rescue => e; return "Exception: "+e.to_s+"\n"+e.backtrace.join("\n")+"\n";;;;; end;;;;;end;;;;;;;;;;;;;;;def benchmarked_eval(script);;;;; unless script.is_a?(String) and script.to_s.length > 0; raise "Invalid argument, should be String."; end;;;;; begin;;;;; t1 = Time.now;;;;; eval(script.to_s);;;;; t2 = Time.now;;;;; return t2-t1;;;;; rescue => e; return "Exception: "+e.to_s+"\n"+e.backtrace.join("\n")+"\n";;;;; end;;;;;end;;;;;;;;;;;;;;;#####################################################################################################################################################################################;;;;;## 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 gets_eval *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;;;;; ;;;;; ;;;;; ## 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 == 0 ; return 0 ; elsif a == 1 and b == 1 ; return 1 ; else ; return 1 ; 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 ; return 1 ; else ; return 0 ; end ; end;;;;; def _nand(a,b) ; if a == 1 and b == 1 ; return 0 ; else ; return 1 ; end ; end;;;;; def _xor(a,b) ; if a == 0 and b == 0 ; return 0 ; elsif a == 1 and b == 1 ; return 0 ; else ; return 1 ; end ; end;;;;;;;;;;;;;;; ## random alphanumeric string of determined length ;;;;; def rands(length, nonumbers=false);;;;; if length.to_i < 1; raise "Invalid argument."; end;;;;; str = [];;;;; if nonumbers == false; length.times { str<<($ALPHANUM.shuffle)[0] };;;;; else; length.times { str<<($ALPHA.shuffle)[0] } ;;;;; end;;;;; return str.join('');;;;; end;;;;;;;;;;;;;;; def host? ## these are laid out for more complicated checks later;;;;; host = '';;;;; if File.directory?("C:/") and ENV["OS"] == "Windows_NT";;;;; host = "Windows";;;;; elsif File.directory?("/home");;;;; host = "Linux";;;;; else;;;;; host = false;;;;; end;;;;; return host;;;;; end;;;;;;;;;;;;;;; def internet? ## try to URI google;;;;; begin;;;;;; uri = URI.open("http://www.google.com");;;;; cont = uri.read;;;;; if cont.length == 0; raise "No content included in response."; end;;;;; return true;;;;; rescue => e; return e;;;;; end;;;;; end;;;;; ;;;;; ;;;;;}#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{;;;;;;;;;;;;;;;}#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 ## exist in dir should link to File.exist? since it checks both files and dirs;;;;; File.exist?(inp);;;;; end;;;;;;;;;;;;;;; def dir *args ## gets/sets workdir;;;;; 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);;;;; dir = File.join(Dir.getwd, dir) unless File.directory?(dir) ;;;;; cur = nil; rem = [dir];;;;; fi = []; fo = []; ex = [];;;;; until rem.empty?;;;;; cur = rem.shift ;;;;; begin;;;;; Dir.foreach(cur) { |p|;;;;; next if p == '.' || p == '..';;;;; path = File.join(cur, p);;;;; if File.stat(path).file?; fi.push(path);;;;; elsif File.stat(path).directory?; fo.push(path); rem.push(path);;;;; end;;;;; };;;;; rescue; ex.push(cur);;;;; end;;;;; end;;;;; if ex.empty?; return [fi, fo];;;;; else; return [fi, fo, ex];;;;; end;;;;; rescue Errno::ENOTDIR; "Argument is a file.";;;;; rescue Errno::ENOENT; raise "No such directory";;;;; end;;;;;;;;;; ;;;;; def size?(dir);;;;; raise "No such file or directory." unless File.exist?(dir);;;;; raise "#{dir} is a file. size? returns the size of directories, not files." if File.file?(dir);;;;; total_size = 0;;;;; Dir.glob(File.join(dir, '**', '*')).each do |path|;;;;; total_size += File.size(path) if File.file?(path);;;;; end;;;;; total_size;;;;; end;;;;; ;;;;; def empty?(dir);;;;; raise "No such file or directory." unless File.exist?(dir);;;;; raise "#{dir} is a file. empty? returns true for empty directories, not files." if File.file?(dir);;;;; (Dir.entries(dir) - %w[. ..]).empty?;;;;; end;;;;; ;;;;;;;;;;;;;;; def empty!(dir);;;;; failed = [];;;;; Dir.glob("#{dir}/*").each do |path|;;;;; begin;;;;; if File.file?(path); File.delete(path);;;;; elsif File.directory?(path); empty!(path); Dir.delete(path);;;;; end;;;;; rescue => e; failed << [path, "#{e.message}"];;;;; end;;;;; end;;;;; if failed.empty?; return true;;;;; else; return failed;;;;; end;;;;; end;;;;;;;;;;;;;;; def delete!(dir);;;;; if self.empty?(dir); self.delete(dir); return true;;;;; else;;;;; if self.empty!(dir); Dir.delete(dir); return true;;;;; else;return false;;;;; 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;;;;;;;;;;;;;;; def rename(dir, newname);;;;; if File.directory?(dir);;;;; newpath = File.join(File.dirname(dir), newname);;;;; if File.directory?(newpath);;;;; return "Cannot rename because target directory already exists.";;;;; end;;;;; Dir.mkdir(newpath);;;;; Dir.foreach(dir) do |filename|;;;;; next if filename == "." || filename == "..";;;;; filepath = File.join(dir, filename);;;;; newfilepath = File.join(newpath, newname + File.extname(filepath));;;;; File.rename(filepath, newfilepath);;;;; end;;;;; begin;;;;; Dir.delete(dir);;;;; rescue SystemCallError;;;;; # If the directory couldn't be deleted, try to clean it up manually;;;;; Dir.foreach(dir) do |filename|;;;;; next if filename == "." || filename == "..";;;;; filepath = File.join(dir, filename);;;;; File.delete(filepath);;;;; end;;;;; Dir.delete(dir);;;;; end;;;;; return true;;;;; else;;;;; return "No such directory.";;;;; end;;;;; end;;;;;;;;;; ;;;;; def search(dir, name);;;;; unless File.directory?(dir); return "No such directory."; end;;;;; results = Dir.glob(File.join(dir, '**', "*#{name}*"), File::FNM_CASEFOLD);;;;; if results.empty?; return false;;;;; else; return results;;;;; end ;;;;; end;;;;;;;;;;;;;;; def locate(dir, name, case_sensitive = false);;;;; unless File.directory?(dir); return "No such directory."; end;;;;; if case_sensitive; results = Dir.glob(File.join(dir, '**', name)).select { |path| File.basename(path) == name };;;;; else; results = Dir.glob(File.join(dir, '**', "*#{name}*"), File::FNM_CASEFOLD).select { |path| File.basename(path).downcase == name.downcase };;;;; end;;;;; if results.empty?; return false;;;;; else; return results;;;;; end;;;;; end;;;;;;;;;;;;;;; def clones?(directory);;;;; unless File.directory?(directory); raise "No such directory."; end;;;;; files = Dir.glob("#{directory}/*").select { |f| File.file?(f) };;;;; if files.empty?; raise "Target directory is empty."; end;;;;; duplicates = []; hash_to_files = {};;;;; files.each do |file|;;;;; file_contents = File.read(file); file_hash = Digest::SHA256.hexdigest(file_contents);;;;; if hash_to_files.key?(file_hash); duplicates << [file, hash_to_files[file_hash]];;;;; else; hash_to_files[file_hash] = file;;;;; end;;;;; end;;;;; if duplicates.empty?; return false;;;;; else; return duplicates;;;;; 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) == false; raise "No such file."; end;;;;; if File.readable?(path.to_s) == false; raise "File read permission denied by host."; end;;;;; begin; cont = File.read(path.to_s);;;;; rescue; raise "Unable to read file.";;;;; end;;;;; print "\n"+cont.to_s+"\n\n";;;;; if path.to_s.include?("/"); path.split("/")[-1].to_s; else; p = path.to_s; end;;;;; return "File: "+p.to_s+" Location: "+path.to_s;;;;; end;;;;; ;;;;; def make(path);;;;; if path.to_s.include?("/"); dir = path.to_s.split("/")[0..-2].join("/"); name = path.to_s.split("/")[-1];;;;; else; dir = Dir.getwd; name = path.to_s;;;;; end;;;;; if File.directory?(dir) == false; raise "No such dir: "+dir.to_s; end;;;;; if File.directory?(dir+"/"+name) == true; raise "File path is already a dir: "+dir+"/"+name; end;;;;; if File.file?(dir+"/"+name) == true; raise "File already exists."; end;;;;; if File.writable?(dir) == false; raise "File write permission denied by host."; end;;;;; begin; f = File.open(dir+"/"+name,"w"); f.close;;;;; rescue; raise "Unable to write file.";;;;; end;;;;; return true;;;;; end;;;;; ;;;;; def prepend(path,str);;;;; if File.file?(path.to_s) == false; raise "No such file."; end;;;;; if str.to_s.length == 0; raise "Invalid arguments: args[1] \"str\", should be a string of positive length."; end;;;;; if File.writable?(path.to_s) == false; raise "File write permission denied by host."; end;;;;; begin; cont = File.read(path.to_s);;;;; rescue; raise "Unable to read file.";;;;; end;;;;; begin; File.write(str.to_s+cont);;;;; rescue; raise "Unable to write file.";;;;; end;;;;; return true;;;;; end;;;;; ;;;;; def append(path,str);;;;; if File.file?(path.to_s) == false; raise "No such file."; end;;;;; if str.to_s.length == 0; raise "Invalid arguments: args[1] \"str\", should be a string of positive length."; end;;;;; if File.writable?(path.to_s) == false; raise "File write permission denied by host."; end;;;;; begin; cont = File.read(path.to_s);;;;; rescue; raise "Unable to read file.";;;;; end;;;;; begin; File.write(cont+str);;;;; rescue; raise "Unable to write file.";;;;; end;;;;; return true;;;;; end;;;;;;;;;;;;;;; def insert(path,pos,str);;;;; if File.file?(path.to_s) == false; raise "No such file."; end;;;;; if pos.is_a?(Integer) == false; raise "Invalid arguments: args[1] \"pos\", should be Integer."; end;;;;; if str.to_s.length == 0; raise "Invalid arguements: args[2] \"str\", should be String of positive length."; end;;;;; if File.writable?(path.to_s) == false; raise "File write permission denied by host."; end;;;;; begin; cont = File.read(path.to_s);;;;; rescue; raise "Unable to read file.";;;;; end;;;;; cont = cont.split("");;;;; cont.insert(pos,str.to_s);;;;; cont = cont.join("");;;;; begin; File.write(path.to_s, cont);;;;; rescue; raise "Unable to write file.";;;;; end;;;;; return true;;;;; end;;;;; ;;;;; def lines(path) ## WINDOWS LINEBREAKS ONLY;;;;; if File.file?(path.to_s) == false; raise "No such file."; end;;;;; if File.readable?(path.to_s) == false; raise "File read permission denied by host."; end;;;;; begin; cont = File.read(path.to_s);;;;; rescue; raise "Unable to read file.";;;;; end;;;;; return cont.split("\n");;;;; end;;;;; ;;;;; def write_line(path,pos,str);;;;; if File.file?(path.to_s) == false; raise "No such file."; end;;;;; if File.writable?(path.to_s) == false; raise "File write permission denied by host."; end;;;;; if pos.is_a?(Integer) == false and pos.is_a?(Range) == false; raise "Invalid arguemnts: args[1]: \"pos\", should be Integer or Range"; end ;;;;; if str.to_s.length == 0; raise "Invalid arguments: args[2]: \"str\", should be String of positive length."; end;;;;; begin; cont = File.read(path.to_s);;;;; rescue; raise "Unable to read file.";;;;; end;;;;; cont = cont.split("\n");;;;; if pos.is_a?(Integer) == true;;;;; cont[pos] = str.to_s;;;;; else;;;;; pos.each { |i| cont[i] = str.to_s };;;;; end;;;;; cont = cont.join("\n");;;;; begin; File.write(path.to_s, cont);;;;; rescue; raise "Unable to write file.";;;;; end;;;;; return true;;;;; end ;;;;; ;;;;; ;;;;; def insert_line(path,pos,str);;;;; if File.file?(path.to_s) == false; raise "No such file."; end;;;;; if File.writable?(path.to_s) == false; raise "File write permission denied by host."; end;;;;; if pos.is_a?(Integer) == false; raise "Invalid arguemnts: args[1]: \"pos\", should be Integer."; end ;;;;; if str.to_s.length == 0; raise "Invalid arguments: args[2]: \"str\", should be String of positive length."; end;;;;; begin; cont = File.read(path.to_s);;;;; rescue; raise "Unable to read filw.";;;;; end;;;;; cont = cont.split("\n");;;;; cont.insert(pos,str.to_s);;;;; cont = cont.join("\n");;;;; begin; File.write(path.to_s,cont);;;;; rescue; raise "Unable to write file.";;;;; end;;;;; return true;;;;; end ;;;;; ;;;;;;;;;; def delete_line(path,pos);;;;; if File.file?(path.to_s) == false; raise "No such file."; end;;;;; if File.writable?(path.to_s) == false; raise "File write permission denied by host."; end;;;;; if pos.is_a?(Integer) == false and pos.is_a?(Range) == false; raise "Invalid arguemnts: args[1]: \"pos\", should be Integer or Range"; end ;;;;; begin; cont = File.read(path.to_s);;;;; rescue; raise "Unable to read file.";;;;; end ;;;;; cont = cont.split("\n");;;;; if pos.is_a?(Integer) == true;;;;; cont[pos] = "";;;;; else;;;;; pos.each { |i| cont[i] = "" };;;;; end;;;;; cont = cont.join("\n");;;;; begin; File.write(path.to_s, cont);;;;; rescue; raise "Unable to write file.";;;;; end;;;;; return true;;;;; end ;;;;;;;;;;;;;;; def include? *args ## path, str, matchcase;;;;; if File.file?(args[0].to_s) == false; raise "No such file."; end;;;;; if File.readable?(args[0].to_s) == false; raise "File read permission denied by host."; end;;;;; if args[1].to_s.length == 0; raise "Invalid arguments: args[2]: \"str\", should be String of positive length."; end;;;;; begin; cont = File.read(path.to_s);;;;; rescue; raise "Unable to read file.";;;;; end ;;;;; if args[2] != true; cont = cont.downcase; tag = args[1].to_s.downcase;;;;; else; tag = args[2].to_s;;;;; end;;;;; return cont.include?(tag);;;;; end;;;;;;;;;;;;;;; def empty?(path);;;;; if File.file?(args[0].to_s) == false; raise "No such file."; end;;;;; if File.readable?(args[0].to_s) == false; raise "File read permission denied by host."; end;;;;; empty = nil;;;;; begin; if File.size?(path.to_s) > 0; empty = false; else; empty = true; end;;;;; rescue; raise "Unable to read file.";;;;; end;;;;; return empty;;;;; end;;;;;;;;;; def empty!(path);;;;; if File.file?(args[0].to_s) == false; raise "No such file."; end;;;;; if File.writable?(args[0].to_s) == false; raise "File write permission denied by host."; end;;;;; begin; File.write(path.to_s,"");;;;; rescue; raise "Failed to write file.";;;;; end;;;;; return true;;;;; end;;;;; ;;;;;;;;;; def copy *args #path, newpath;;;;; if File.file?(args[0].to_s);;;;; if File.directory?(args[1].to_s);;;;; if File.file?(args[1].to_s + "/" + args[0].to_s.split("/")[-1].to_s) == false;;;;; fi = File.open(args[0].to_s,"rb") ; cont = fi.read.to_s ; fi.close;;;;; fi = File.open(args[1].to_s + "/" + args[0].to_s.split("/")[-1].to_s,"wb") ; fi.write(cont.to_s) ; fi.close;;;;; return true ;;;;; else ; return "Target directory already contains a file with the same name.";;;;; end;;;;; else ; return "Input target directory is invalid.";;;;; end;;;;; else ; return "No such file.";;;;; end ;;;;; end;;;;; ;;;;;;;;;; def move *args #path, newpath;;;;; if File.file?(args[0].to_s) ;;;;; if File.directory?(args[1].to_s);;;;; if File.file?(args[1].to_s + "/" + args[0].to_s.split("/")[-1].to_s) == false;;;;; fi = File.open(args[0].to_s,"rb") ; cont = fi.read.to_s ; fi.close;;;;; fi = File.open(args[1].to_s + "/" + args[0].to_s.split("/")[-1].to_s,"wb") ; fi.write(cont.to_s) ; fi.close;;;;; File.delete(args[0].to_s);;;;; return true ;;;;; else ; return "Target directory already contains a file with the same name.";;;;; end;;;;; else ; return "Input target directory is invalid.";;;;; end;;;;; else ; return "No such file.";;;;; end ;;;;; end ;;;;; ;;;;; ;;;;; def generate_certificate(filepath);;;;; file_size = File.size(filepath) # Get the size of the file;;;;; total = file_size # Iterate over every byte of the file and add its value to the size;;;;; File.open(filepath, "rb") do |file|;;;;; while byte = file.read(1);;;;; total += byte.unpack('C').first;;;;; end;;;;; end;;;;; certificate = total.to_f / file_size # Divide the total by the size of the file to create the certificate;;;;; return certificate.to_s;;;;; 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;;;;; number = self; base = 2; exponent = 2;;;;; while base <= number;;;;; exponent = 2;;;;; while exponent < number;;;;; if base**exponent == number; return [base, exponent]; end;;;;; exponent += 1;;;;; end;;;;; base += 1;;;;; end;;;;; end;;;;;;;;;;;;;;; def factors;;;;; n = self; factor1 = 1; factor2 = n;;;;; (2..Math.sqrt(n)).each do |factor|;;;;; if n % factor == 0;;;;; factor1 = factor;;;;; factor2 = n / factor;;;;; break;;;;; end;;;;; end;;;;; [factor1, factor2];;;;; end;;;;;;;;;; ;;;;; ## if a number upto the sqrt isnt devisable, no number is ;;;;; def prime?;;;;; return false if self <= 1;;;;; (2..Math.sqrt(self)).each do |i|;;;;; return false if self % i == 0;;;;; end;;;;; return true;;;;; end;;;;;;;;;; ;;;;; def surname *args;;;;; if args.length == 0; int=self.to_s ; else; int=args[0].to_s; end;;;;; 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; self.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse; end;;;;; ;;;;;;;;;;};;;;;;;;;;Integer.instance_eval{;;;;;;;;;;};;;;;;;;;;;;;;;#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?;;;;; ;;;;; ##in building it this way, i can take this and make an actual code parser ;;;;; 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 ## self inside the loop will not be the string;;;;; 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 << "" } ## again, in the loop we can only refer to vars;;;;; empty_buffer2=[]; buffer_length.times{ empty_buffer2 << "" } ## im really not sure why but id love to know;;;;; 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 ## in this loop s will be self and tag1 & 2 will point to the buffers we want to work with;;;;; 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 splice(b, e);;;;; # if !b.is_a?(String) || !e.is_a?(String);;;;; # raise "Arguments require String type.";;;;; # elsif b.empty? || e.empty?;;;;; # raise "Arguments cannot be empty.";;;;; # end;;;;; ;;;;; # s_copy = self.dup;;;;; # if s_copy.length <= (b.length + e.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 = Array.new(buffer_length, "");;;;; # empty_buffer = Array.new(buffer_length, "");;;;; # empty_buffer2 = Array.new(buffer_length, "");;;;; ;;;;; # tag1 = empty_buffer;;;;; # b.split('').each do |ch|;;;;; # empty_buffer << ch;;;;; # empty_buffer.delete_at(0);;;;; # end;;;;; ;;;;; # tag2 = empty_buffer2;;;;; # e.split('').each do |ch|;;;;; # empty_buffer2 << ch;;;;; # empty_buffer2.delete_at(0);;;;; # end;;;;; ;;;;; # loop do;;;;; # if s_copy[pos].nil?;;;;; # break;;;;; # end;;;;; ;;;;; # buffer << s_copy[pos];;;;; # buffer.delete_at(0);;;;; ;;;;; # if stack;;;;; # list << s_copy[pos];;;;; # end;;;;; ;;;;; # str = buffer.join('');;;;; # tag = tag1.join('').reverse;;;;; ;;;;; # m = true;;;;; # i = 0;;;;; ;;;;; # tag.split('').each do |ch|;;;;; # if ch != str.reverse[i] && ch != "";;;;; # m = false;;;;; # break;;;;; # end;;;;; ;;;;; # i += 1;;;;; # end;;;;; ;;;;; # if m;;;;; # stack = true;;;;; # end;;;;; ;;;;; # tag = tag2.join('').reverse;;;;; ;;;;; # m = true;;;;; # i = 0;;;;; ;;;;; # tag.split('').each do |ch|;;;;; # if ch != str.reverse[i] && ch != "";;;;; # m = false;;;;; # break;;;;; # end;;;;; ;;;;; # i += 1;;;;; # end;;;;; ;;;;; # if m;;;;; # stack = false;;;;; # end;;;;; ;;;;; # pos += 1;;;;; # end;;;;; ;;;;; # if list.empty?;;;;; # return nil;;;;; # else;;;;; # return list.join('')[0..("-#{e.length + 1}").to_i];;;;; # end ;;;;;# end;;;;;# $str = "hello there<a> asshole</a> fuck you.";;;;; ;;;;; 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;;;;;;;;;;;;;;; def parse_array *args;;;;; if args.length > 0 ; str = args[0];;;;; else; str = self;;;;; end;;;;; if str.to_s == "[]"; return []; end;;;;; ;;;;; str = str.strip.gsub(/^\[|\]$/, '');;;;; elements = []; current_element = ''; nested_level = 0;;;;; ;;;;; str.each_char do |c|;;;;; if c == ',' && nested_level == 0;;;;; elements << current_element.strip;;;;; current_element = '';;;;; else;;;;; current_element += c;;;;; if c == '['; nested_level += 1;;;;; elsif c == ']'; nested_level -= 1;;;;; end;;;;; end;;;;; end;;;;; ;;;;; elements << current_element.strip;;;;; ;;;;; elements.map do |element|;;;;; if element.start_with?('"') && element.end_with?('"');;;;; element.gsub(/^"|"$/, '');;;;; elsif element.start_with?("'") && element.end_with?("'");;;;; element.gsub(/^'|'$/, '');;;;; elsif element =~ /\A\d+\z/;;;;; element.to_i;;;;; elsif element =~ /\A\d+\.\d+\z/;;;;; element.to_f;;;;; elsif element == 'true' || element == 'false';;;;; element == 'true';;;;; elsif element.start_with?('[') && element.end_with?(']');;;;; self.parse_array(element);;;;; elsif element.start_with?('{') && element.end_with?('}');;;;; self.parse_hash(element);;;;; else;;;;; element;;;;; end;;;;; end;;;;; end;;;;;;;;;;;;;;; def parse_hash *args;;;;; if args.length == 0; str = self;;;;; else; str = args[0];;;;; end;;;;; if str.to_s == "{}"; return {}; end;;;;; ;;;;; str = str.strip.gsub(/^\{|\}$/, '');;;;; pairs = []; current_key = ''; current_value = ''; nested_level = 0;;;;;;;;;; str.each_char do |c|;;;;; if c == '>' && nested_level == 0;;;;; current_key = current_value.gsub(/['":]\s*(\w+)\s*['":]?/, '\1'); current_key = current_key.delete(" =");;;;; current_value = '';;;;; elsif c == ',' && nested_level == 0;;;;; pairs << [current_key, current_value.strip];;;;; current_key = '';;;;; current_value = '';;;;; else;;;;; current_value += c;;;;; if c == '{' || c == '[';;;;; nested_level += 1;;;;; elsif c == '}' || c == ']';;;;; nested_level -= 1;;;;; end;;;;; end;;;;; end;;;;;;;;;; pairs << [current_key, current_value.strip];;;;;;;;;; hash = {};;;;; pairs.each do |pair|;;;;; key = pair[0];;;;; value = pair[1];;;;;;;;;; if value.start_with?('{') && value.end_with?('}');;;;; hash[key] = value.parse_hash;;;;; elsif value.start_with?('[') && value.end_with?(']');;;;; hash[key] = value.parse_array;;;;; elsif value == 'true';;;;; hash[key] = true;;;;; elsif value == 'false';;;;; hash[key] = false;;;;; elsif value =~ /\A\d+\z/;;;;; hash[key] = value.to_i;;;;; elsif value =~ /\A\d+\.\d+\z/;;;;; hash[key] = value.to_f;;;;; else;;;;; hash[key] = value.gsub(/^\"|\"$/, '');;;;; end;;;;; end;;;;; ;;;;; return hash;;;;; end;;;;;;;;;;;;;;;;;;;;};;;;;;;;;;String.instance_eval{;;;;; def numerize(str);;;;; 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(str);;;;; chars=[];;;;; str=str.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;;;;;;;;;; ## these copies of parse hash and array exist to allow calls like String.parse_hash "";;;;; ;;;;; def parse_array(str);;;;; if str.to_s == "[]"; return []; end;;;;; str = str.strip.gsub(/^\[|\]$/, '');;;;; elements = []; current_element = ''; nested_level = 0;;;;; ;;;;; str.each_char do |c|;;;;; if c == ',' && nested_level == 0;;;;; elements << current_element.strip;;;;; current_element = '';;;;; else;;;;; current_element += c;;;;; if c == '['; nested_level += 1;;;;; elsif c == ']'; nested_level -= 1;;;;; end;;;;; end;;;;; end;;;;; ;;;;; elements << current_element.strip;;;;; ;;;;; elements.map do |element|;;;;; if element.start_with?('"') && element.end_with?('"');;;;; element.gsub(/^"|"$/, '');;;;; elsif element.start_with?("'") && element.end_with?("'");;;;; element.gsub(/^'|'$/, '');;;;; elsif element =~ /\A\d+\z/;;;;; element.to_i;;;;; elsif element =~ /\A\d+\.\d+\z/;;;;; element.to_f;;;;; elsif element == 'true' || element == 'false';;;;; element == 'true';;;;; elsif element.start_with?('[') && element.end_with?(']');;;;; self.parse_array(element);;;;; elsif element.start_with?('{') && element.end_with?('}');;;;; self.parse_hash(element);;;;; else;;;;; element;;;;; end;;;;; end;;;;; end;;;;;;;;;;;;;;; def parse_hash(str);;;;; if str.to_s == "{}"; return {}; end;;;;; str = args[0].strip.gsub(/^\{|\}$/, '');;;;; pairs = []; current_key = ''; current_value = ''; nested_level = 0;;;;;;;;;; str.each_char do |c|;;;;; if c == '>' && nested_level == 0;;;;; current_key = current_value.gsub(/['":]\s*(\w+)\s*['":]?/, '\1'); current_key = current_key.delete(" =");;;;; current_value = '';;;;; elsif c == ',' && nested_level == 0;;;;; pairs << [current_key, current_value.strip];;;;; current_key = '';;;;; current_value = '';;;;; else;;;;; current_value += c;;;;; if c == '{' || c == '[';;;;; nested_level += 1;;;;; elsif c == '}' || c == ']';;;;; nested_level -= 1;;;;; end;;;;; end;;;;; end;;;;;;;;;; pairs << [current_key, current_value.strip];;;;;;;;;; hash = {};;;;; pairs.each do |pair|;;;;; key = pair[0];;;;; value = pair[1];;;;;;;;;; if value.start_with?('{') && value.end_with?('}');;;;; hash[key] = value.parse_hash;;;;; elsif value.start_with?('[') && value.end_with?(']');;;;; hash[key] = value.parse_array;;;;; elsif value == 'true';;;;; hash[key] = true;;;;; elsif value == 'false';;;;; hash[key] = false;;;;; elsif value =~ /\A\d+\z/;;;;; hash[key] = value.to_i;;;;; elsif value =~ /\A\d+\.\d+\z/;;;;; hash[key] = value.to_f;;;;; else;;;;; hash[key] = value.gsub(/^\"|\"$/, '');;;;; end;;;;; end;;;;; ;;;;; return hash;;;;; end;;;;;;;;;;;;;;;};;;;;;;;;;;;;;;#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);;;;; s = s.to_i;;;;; if s < 60 ; [0, 0, s];;;;; elsif s < 3600 ; [0, s / 60, s % 60];;;;; elsif s < 86400 ; [s / 3600, (s / 60) % 60, s % 60];;;;; else;;;;; days = s / 86400;;;;; hours = (s / 3600) % 24;;;;; minutes = (s / 60) % 60;;;;; seconds = s % 60;;;;; [days, hours, minutes, seconds];;;;; end;;;;; end;;;;;;;;;;;;;;; def stamp(time = Time.now, delimiter = '.');;;;; if time.is_a?(Time);;;;; [time.year.to_s, format("%02d", time.month), format("%02d", time.day),;;;;; format("%02d", time.hour), format("%02d", time.min), format("%02d", time.sec)].join(delimiter);;;;; elsif time.is_a?(String);;;;; t = time.split(delimiter);;;;; Time.new(t[0], t[1], t[2], t[3], t[4], t[5]);;;;; end;;;;; end;;;;;;;;;;};;;;;;;;;;#8#;#3#;#5#;#3#;#1#;#8#;#3#;#5#;#3#;#8#;#5##leval_parser.rb.rb#5#;#6#;#9#;#9#;#4#;#5#;#6#;#7#;#9#;#6#;#4##leval_parser.rb;;;;;## leval_parser.rb v 1.0.2 Linear ruby1.0;;;;;## This parser is designed to run LinearRuby programs from script files (.lrb files).;;;;;## LinearRuby has unimplied rules that can allow programs to run on regular ruby and linear ruby,;;;;;## the rules can be broken but for the most part breaking them doesnt make sense because in ;;;;;## LinearRuby we assume classes are useless and write ruby programs in a linear series of ;;;;;## script blocks that will execute in the order we write them.;;;;;##;;;;;## These script files have a few unimplied rules you are expected to follow to create a proper ;;;;;## linear ruby file:;;;;;## ;;;;;## 1. No classes or glabals are defined, instance variables and constants replace them.;;;;;## 2. The file is composed of blocks of script seperated by '\n\n', so you cannot use it in your code in strings literally, instead use "\n"*2 .;;;;;## 3. 'jumpto' followed by an integer or instance variable jumps program flow to that block in the file, if a second instance variable or expression is included it will be the condition for the jump.;;;;;## 4. when you define methods they are always on main context;;;;;## 5. context is main for every block, the program ends when the counter reaches and runs the last block, or an 'exit' operator is found;;;;;##;;;;;##;;;;;;;;;;# make sure the parser can access main if running outside rubinsystem program.;;;;;if defined?(MAIN) != "constant"; MAIN = self; end;;;;;;;;;;class LinearRubyParser;;;;; def initialize;;;;; @main = MAIN ## link to outside MAIN context;;;;; @state = "init" ## operation state of the parser class;;;;; @level = 0 ## recursion level for :leval also the same as program eval stack level;;;;; @file = nil ## path of current running script;;;;; end;;;;; ;;;;; def main; return @main; end;;;;; def state; return @state; end;;;;; def level; return @level; end;;;;; def file; return @file; end;;;;; ;;;;; ;;;;; #load and eval a LinearRuby file;;;;; def load_file *args ## path, overridecontextwith, passargs;;;;; if File.file?(args[0].to_s) == false; raise "No such file."; end;;;;; if File.readable?(args[0].to_s) == false; raise "File read permission denied by host."; end;;;;; script_path = args[0].to_s ;;;;; if args[1].to_s != ""; context = args[1]; else; context = @main; end;;;;; begin; script = File.read(script_path); @file = script_path;;;;; rescue; raise "Failed to read script file.";;;;; end;;;;; begin; @state = "eval"; @file = "";;;;; return self.leval(script,context,args[2]);;;;; rescue => e; @state = "excep";;;;; raise "Unknown exception state: "+e.to_s+"\n"+e.backtrace.join("\n");;;;; end;;;;; end;;;;; ;;;;; # eval LinearRuby script string;;;;; def leval *args # script, overridecontextwith, passargs;;;;; script = args[0].to_s;;;;; if args.length == 2 and args[1] != ""; context = args[1]; else; context = MAIN; end;;;;; if args.length == 3 and args[2].is_a?(Array); script_args = args[2]; else; script_args = []; end;;;;; running = true;;;;; blocks = script.split("\n\n");;;;; returnval = []; exceptions = []; block = -1;;;;; while running do;;;;; @state = "eval"; @level += 1;;;;; block += 1;;;;; if blocks[block].to_s == ""; running = false; break;;;;; ;;;;; elsif blocks[block].to_s.downcase[0..11] == "dobeforenext";;;;; elsif blocks[block].to_s.downcase[0..9] == "skipnextif";;;;; elsif blocks[block].to_s.downcase[0..7] == "gobackif";;;;; elsif blocks[block].to_s.downcase[0..5] == "jumpto";;;;; ;;;;; if blocks[block].to_s[6..1].delete("\n 0123456789").empty?;;;;; block = ((blocks[block].to_s[6..-1].to_i)-1);;;;; elsif blocks[block].to_s[6..-1].to_s[0] == "@";;;;; begin; var = context.instance_eval(blocks[block].to_s[6..-1]);;;;; if var.is_a?(Integer) == false; raise "Error in file: "+@file.to_s+", block: "+block.to_s+", Invalid jump code, obj is not Integer.; block code: "+blocks[block].to_s; end;;;;; block = var-1;;;;; next;;;;; rescue; raise "Invalid jump code in file:"+@file.to_s+", line: "+block.to_s+"; block: "+"\""+blocks[block].to_s+"\"" ;;;;; end;;;;; end;;;;;;;;;; next;;;;; ;;;;; else;;;;; begin; returnval << context.instance_eval(blocks[block]);;;;; rescue => e; exceptions << e.to_s+"\n"+e.backtrace.join("\n");;;;; end;;;;; end;;;;; end; running = false; @state = "idle"; @level -= 1;;;;; if exceptions == []; return returnval;;;;; else; return [returnval,exceptions];;;;; end;;;;; end;;;;;;;;;;;;;;;;;;;; def parse_file(script);;;;; if File.file?(script) == false; raise "No such file."; end;;;;; script = File.read(script);;;;; self.parse(script);;;;; end;;;;;;;;;;;;;;;# i want to change the names of all variables to be purley alphanumeric in lruby;;;;;# these variable names just cause parsing complexity i dont want when i build the real parser;;;;;;;;;;#[:$-a, :$-p, :$-l, :$@, :$;, :$-F, :$?, :$$, :$&, :$`, :$', :$+, :$=, :$VERBOSE,;;;;;# :$-v, :$stdin, :$stdout, :$>, :$stderr, :$-W, :$DEBUG, :$-w, :$0, :$PROGRAM_NAME,;;;;;# :$-d, :$_, :$~, :$!, :$/, :$,, :$\, :$-0, :$., :$<, :$FILENAME, :$-i, :$*, :$-I, :$:, ;;;;;# :$", :$LOAD_PATH, :$LOADED_FEATURES];;;;;;;;;;## parser needs to be loaded with a default list of ruby;;;;;## classes and globals and their methods so when parsing code they can be recognised;;;;;## apart from defined object calls;;;;;;;;;;;;;;; # parse processes a script with out evaluating it;;;;; def parse(script);;;;; blocks = script.split("\n\n");;;;; stack_keywords = ["def", "if", "case", "class","loop", "while", "for", "begin","{"];;;;; stack_open = [0, 0, 0, 0, 0, 0, 0,0];;;;; last_opened = [];;;;; stack_trace = [] ## keeps track of keywords opened and the ends after them;;;;; line_no = 0;;;;; defined_classes = [];;;;; defined_methods = [];;;;; global_vars = [];;;;; instance_vars = [];;;;; local_vars = [];;;;; statements = [] ## contains an array for each keyword block containing any statements from the block;;;;; unexpected_end = [];;;;; script_ok = true;;;;;;;;;; blocks.each do |block|;;;;; if block.to_s.downcase[0..5] == "jumpto";;;;; # Handle jump statements;;;;; elsif block.to_s == "exit";;;;; # Handle exit statement;;;;; break # done parsing after exit;;;;; else;;;;; lines = block.split(";").join("\n").split("\n");;;;; lines.each do |line| ; line_no += 1;;;;; line = line.gsub(/\s+/, " ");;;;; if line[0] == " "; line = line[1..-1]; end;;;;; ;;;;; if line[0] == "#";;;;; ##comment line;;;;; elsif line[0..3] == "def ";;;;; ;;;;; stack_open[0] += 1;;;;; last_opened << "def"; stack_trace << "def "+line.split(" ")[1..-1].join(" ");;;;; defined_methods << line.split(" ")[1];;;;; elsif line[0..2] == "if ";;;;; stack_open[1] += 1;;;;; last_opened << "if"; stack_trace << "if "+line.split(" ")[1..-1].join(" ");;;;; elsif line[0..4] == "case ";;;;; stack_open[2] += 1;;;;; last_opened << "case"; stack_trace << "case "+line.split(" ")[1..-1].join(" ");;;;; elsif line[0..5] == "class ";;;;; stack_open[3] += 1;;;;; last_opened << "class"; stack_trace << "class "+line.split(" ")[1..-1].join(" ");;;;; defined_classes << line.split(" ")[1] ;;;;; ;;;;; elsif line[0..4] == "loop";;;;; stack_open[4] += 1;;;;; last_opened << "loop"; stack_trace << "loop "+line.split(" ")[1..-1].join(" ");;;;; last_opened << "{"; stack_trace << "loop "+line.split(" ")[1..-1].join(" ");;;;; ;;;;; elsif line =~ /^loop.*\{.*\}\s*$/;;;;; stack_open[4] += 1;;;;; last_opened << "loop";;;;; stack_trace << "loop "+line.split(" ")[1..-1].join(" ");;;;;;;;;; elsif line[0..4] == "while";;;;; stack_open[5] += 1;;;;; last_opened << "while"; stack_trace << "while "+line.split(" ")[1..-1].join(" ");;;;; ;;;;; elsif line[0..2] == "for";;;;; stack_open[6] += 1;;;;; last_opened << "for"; stack_trace << "for "+line.split(" ")[1..-1].join(" ");;;;; ;;;;; elsif line[0..4] == "begin";;;;; stack_open[7] += 1;;;;; last_opened << "begin"; stack_trace << "begin";;;;; elsif line[0..5] == "rescue";;;;; ;;;;; elsif line[0..5] == "else";;;;; ;;;;; elsif line[0..5] == "next";;;;; ;;;;; elsif line[0..5] == "break";;;;;;;;;; elsif line =~ /^@\w+\b\s*==/;;;;; # instance variable with == operator;;;;; elsif line =~ /^@\w+\b\s*\./;;;;; # instance variable with dot operator;;;;; elsif line =~ /^@\w+\b\s*>=/;;;;; # instance variable with >= operator;;;;; elsif line =~ /^@\w+\b\s*<=/;;;;; # instance variable with <= operator;;;;; elsif line =~ /^@\w+\b\s*\+=/;;;;; # instance variable with += operator;;;;; elsif line =~ /^@\w+\b\s*\-=/ ;;;;; # instance variable with -= operator;;;;; elsif line =~ /^@\w+\b\s*=/ # instance variable declaration;;;;; var_name = line.split("=")[0][1..-1] # remove the @ from the var name;;;;; instance_vars << "@"+var_name unless instance_vars.include?("@"+var_name);;;;; ;;;;; elsif line =~ /^\$\w+\b\s*==/;;;;; # global variable with == operator;;;;; elsif line =~ /^\$\w+\b\s*\./;;;;; # global variable with dot operator;;;;; elsif line =~ /^\$\w+\b\s*>=/;;;;; # global variable with >= operator;;;;; elsif line =~ /^\$\w+\b\s*<=/;;;;; # global variable with <= operator;;;;; elsif line =~ /^\$\w+\b\s*\+=/;;;;; # global variable with += operator;;;;; elsif line =~ /^\$\w+\b\s*\-=/ ;;;;; # global variable with -= operator ;;;;; elsif line =~ /^\$\w+\b\s*=/ # global variable declaration;;;;; var_name = line.split("=")[0][1..-1] # remove the $ from the var name;;;;; global_vars << "$"+var_name unless global_vars.include?("$"+var_name);;;;; ;;;;; ;;;;; elsif line =~ /^\w+\b\s*==/;;;;; # instance variable with == operator;;;;; elsif line =~ /^\w+\b\s*\./;;;;; # instance variable with dot operator;;;;; elsif line =~ /^\w+\b\s*>=/;;;;; # instance variable with >= operator;;;;; elsif line =~ /^\w+\b\s*<=/;;;;; # instance variable with <= operator;;;;; elsif line =~ /^\w+\b\s*\+=/;;;;; # instance variable with += operator;;;;; elsif line =~ /^\w+\b\s*\-=/ ;;;;; # instance variable with -= operator;;;;; elsif line =~ /^\w+\b\s*=/ # local variable declaration;;;;; var_name = line.split("=")[0].strip ;;;;; local_vars << var_name unless local_vars.include?(var_name);;;;;;;;;;;;;;;;;;;;;;;;; elsif line.downcase.strip == "end";;;;; # Close the most recent open block;;;;; stack_trace << "end";;;;; if last_opened.any?;;;;; stack_open[stack_keywords.index(last_opened.last)] -= 1;;;;; last_opened.pop;;;;; else; unexpected_end << last_opened[-1].to_s+" @ line "+line_no.to_s;;;;; end;;;;; ;;;;; else;;;;; # Handle other statements ;;;;; ;;;;; end;;;;; end;;;;; ;;;;; # Add a separator to the local variables array between blocks;;;;; local_vars << "" unless local_vars.empty?;;;;; instance_vars << "" unless instance_vars.empty?;;;;; global_vars << "" unless global_vars.empty?;;;;; defined_classes << "" unless defined_classes.empty?;;;;; defined_methods << "" unless defined_methods.empty?;;;;; ;;;;; end;;;;; end;;;;;;;;;; puts "#####################################################################";;;;; puts script.to_s;;;;; puts "#####################################################################";;;;;;;;;; # Check for stack errors;;;;; s=stack_open; s.delete(0);;;;; if s.include?(1);;;;; stack_keywords.each do |k|;;;;; if stack_open[stack_keywords.index(k)] == 1;;;;; puts "ERROR: Stack left open for keyword: "+k.to_s;;;;; script_ok = false;;;;; end;;;;; end;;;;; end ;;;;; if unexpected_end != [];;;;; puts "ERROR: Unexpected 'end' in stack keywords: "+unexpected_end.to_s;;;;; script_ok = false;;;;; end;;;;; defined_classesl = defined_classes; defined_classesl.delete(""); defined_classesl = defined_classesl.length;;;;; defined_methodsl = defined_methods; defined_methodsl.delete(""); defined_methodsl = defined_methodsl.length;;;;; global_varsl = global_vars; global_varsl.delete(""); global_varsl = global_varsl.length ;;;;; instance_varsl = instance_vars; instance_varsl.delete(""); instance_varsl = instance_varsl.length;;;;; local_varsl = local_vars; local_varsl.delete(""); local_varsl = local_varsl.length;;;;; puts "\nParse Results for file: ";;;;; puts "Blocks: "+blocks.length.to_s + " Logical Lines: "+line_no.to_s+"\n";;;;; puts "Size: "+script.to_s.length.to_s+" bytes\n";;;;; puts "";;;;; if defined_classesl > 0;;;;; puts "Defined classes: "+defined_classesl.to_s+": "+defined_classes.join(", ")+"\n";;;;; puts "";;;;; end;;;;; if global_varsl > 0;;;;; puts "Global variables: "+global_varsl.to_s+": "+global_vars.join(", ")+"\n";;;;; puts "";;;;; end;;;;; puts "Defined methods: "+defined_methodsl.to_s+": "+defined_methods.join(", ")+"\n";;;;; puts "";;;;; puts "Instance variables: "+instance_varsl.to_s+": "+instance_vars.join(", ")+"\n";;;;; puts "";;;;; puts "Local variables: "+local_varsl.to_s+": "+local_vars.join(", ")+"\n";;;;; puts "";;;;; puts "Stack trace: "+stack_trace.length.to_s+" :"+stack_trace.to_s+"\n";;;;; puts "";;;;; puts "Script pass: "+script_ok.to_s;;;;; end;;;;;;;;;; ;;;;;end;;;;;;;;;;Parser = LinearRubyParser.new;;;;;$parser = Parser;;;;;;;;;;##require 'openssl';;;;;class Password;;;;; def initialize(string, seed);;;;; @seed = seed;;;;; cipher = OpenSSL::Cipher.new('AES-256-CBC');;;;; cipher.encrypt;;;;; cipher.key = Digest::SHA256.digest(@seed);;;;; @password = cipher.update(string) + cipher.final;;;;; end;;;;; ;;;;; def verify(pass);;;;; cipher = OpenSSL::Cipher.new('AES-256-CBC');;;;; cipher.encrypt;;;;; cipher.key = Digest::SHA256.digest(@seed);;;;; encrypted = cipher.update(pass) + cipher.final;;;;; @password == encrypted;;;;; 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/doc.txt#1#::#1#::#0#::#0#::#0#::#0#::#1#;;;;;;;;;; Documentation for Rubin version 1.0 Mingw released Feb 2023.;;;;; ;;;;; This file is a basic run through of the system.;;;;; To run rubin you can run "launch.rb" from the install directory. Rubin is a class object that sets up;;;;; a ruby environment and runs ruby programs and/or a REPL shell, these programs run inside the Rubin class;;;;; context. Rubin supports multi-instance interaction so multiple Rubin programs can run different apps.;;;;;;;;;; To get started run an installer script and make an installation. Then run /rubin/launch.rb from the install;;;;; you made to enter the shell, then enter 'config?' to see the installations config. 'config(1,true)' will set;;;;; and 'config(1)' will get. Use 'config' to see cfg data value. You can set apps and scripts to run on startup;;;;; and configure included libs and gems, you can turn off the shell and give control to your apps. You can also;;;;; add and modify the definitions.rb file to change the functionality of default ruby objects like String and ;;;;; Integer. When you write apps, their code is a child of the RubinSystem class.;;;;;;;;;;;;;;; Topics:;;;;; System Directories;;;;; System Files & Components;;;;; Apps;;;;; The Class Directory;;;;; About System Config and Features;;;;; Building and running apps.;;;;; Running and configuring multiple instances of Rubin;;;;; ;;;;; 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 intended to be optional however Rubin currently depends on definitions and work is being;;;;; done to move this dependancy only to apps. The daemond.rb file 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 and the fact the service threads are stored there(Threads which control automatic;;;;; app processes). ;;;;; ;;;;; The daemond file.;;;;;;;;;; The system daemonds job is to run hardcodded system services 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.;;;;; For the most part daemond is used to do complicated automatic things with system resources and is not used in;;;;; basic rubin app development.;;;;; ;;;;; 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 and load it, it can also be set to an array 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. You can add definitions to load but for now leave definitions.rb alone;;;;; because some system methods depend on it.;;;;; ;;;;;;;;;; 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. 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. There is also a temp data directory that cleans unused old data periodically.;;;;; /rubin/data/temp;;;;;;;;;; When you run an app using SYSTEM.run "appname", rubin evaluates the file, then looks at two;;;;; reserved variables, @app and @threads which would have been defined in the app file.;;;;; In your file you have the option of setting @app to be the main class of your program, you are;;;;; expected to initialize your app and then run any startup methods from the end of the file otherwise;;;;; you can trigger methods by calling the systems apps.get method and getting the app object.;;;;; Keep in mind you dont have to define @app and your app can just do whatever you want but if you do;;;;; the system will still add an empty app object and an instance id to the apps.get list and the system;;;;; @apps variable. ;;;;;;;;;; ALSO NOTE: If your program/app grabs flow control and doesnt return it from the end of the file, theres no;;;;; point in declaring @app or @threads, if you want to do both thats what the method :post_initialize is for;;;;; rubin checks apps and components for this method and calls it after initializing them, so if you need to;;;;; grab flow control but want to get your app object initialized onto the system before you grab flow control ;;;;; you can include post_initialize in your app and it will be called after the app file is run.;;;;;;;;;; Another thing to note is that if an app includes the method :shutdown it will be called by the system during;;;;; a shutdown event, you can add methods to kill and save your operations here in the case of a forced shutdown.;;;;;;;;;; Run apps with SYSTEM.run "appname";;;;; See apps with SYSTEM.apps?;;;;;;;;;;;;;;;;;;;; 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 more so snippets and code you want to add and test quickly with a project.;;;;;;;;;; ;;;;; 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;;;;; @appdatadir = SYSTEM.appdatadir+"/app";;;;; @logpath = SYSTEM.logdir+"/applog.log";;;;; end;;;;; def post_initialize;;;;; unless File.directory?(@appdatadir); Dir.mkdir(@appdatadir); end;;;;; @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") ## only include this line if your program doesn set @threads;;;;; ########;;;;;;;;;; @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. ;;;;;;;;;; Important methods:;;;;; ;;;;; 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? get apps installed.;;;;; scripts? get scripts;;;;; shortcuts? ;;;;; components? ;;;;; definitions? ;;;;; ;;;;; run(app) run an app;;;;; runs(script) run a 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/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 "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.30", "2023-03-26 00:33:11 -0700", "thomas", "xcg5t5j5b"];;;;;##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;;;;;unless File.writable?(Dir.getwd); 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.;;;;;;;;;;;;;;;boot_log << Time.now.to_s+" : BOOT SUCCESS.\n";;;;;f=File.open($homedir+"/bootlog.log","a");f.write(boot_log[-1]);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 *args ## alt config file;;;;; 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 = [];;;;; ;;;;; if File.file?(@cfgdir+"/"+args[0].to_s) and args.length > 0;;;;; @config_overide = @cfgdir+"/"+args[0].to_s;;;;; else;;;;; @config_overide = false;;;;; end ;;;;; ;;;;; ;;;;; ##this needs to move, fsys enforce needs to be figured out;;;;; ## 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", "fileutils", "win32ole", "fiddle/import", "Win32API"],true,true,10,false,"",true,false,false,["win32api"],[],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...";;;;; ;;;;; if @config_overide != false;;;;; self.load_config(@config_overide);;;;; str = "Loaded overide config: "+@overide_config.to_s;;;;; self.writelog("Rubin.startup: "+str);;;;; if $debug; puts str.to_s; end;;;;; else;;;;; ##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;;;;; 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 was reset. ");;;;; @config[2] = [];;;;; self.save_config(@loaded_config);;;;; end;;;;;;;;;; ##load/install rubygems;;;;; if @config[11].is_a?(Array);;;;; 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|;;;;; v = require r.to_s;;;;; if gemfiles.include?(r)==false and v != true;;;;; 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;;;;; elsif @config[11] == false;;;;; else; self.errorlog("Rubin.startup: Config 11 RubyGems contained an invalid value. It was reset.");;;;; @config[11]=[];;;;; self.save_config(@loaded_config);;;;; 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;;;;; else; self.errorlog("Rubin.startup: Config 8 LoadDefinition contained an invalid value, it was reset.");;;;; @config[8]=true;;;;; self.save_config(@loaded_config);;;;; 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;;;;; else; self.errorlog "Rubin.startup: Config 0 LoadCladdDir contained an invalid value, it was reset.";;;;; @config[8] = true;;;;; self.save_config(@loaded_config);;;;; 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: "+@components.to_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()");;;;; self.writelog "HOLYSHIT COMPONENT MADE";;;;; 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. "+@components.to_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 "+@components.length.to_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;;;;; @startup_time = Time.now;;;;; 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;;;;; ;;;;; } ;;;;; 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) ## config 4 debug;;;;; 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;;;;; ;;;;; ## config files can contain code to run as long as the data array is on the last line;;;;; ## if we want to turn off this feature we can use String.parse_array;;;;; 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;;;;; if args[0].is_a?(String);;;;; 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;;;;; elsif args[0].is_a?(Array);;;;; begin;;;;; f=File.open(@cfgdir+"/"+args[1].to_s,"w"); f.write(args[0].to_s);;;;; ;;;;; rescue;;;;; return false;;;;; end;;;;; else; raise "Invalid arguments.";;;;; 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 '"+@cfgdir.to_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: '"+@cfgdir.to_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: the script can see instance variables like args and aargs;;;;; ## 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 unless debug mode is on;;;;;;;;;; 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]);;;;; @appshell=false;;;;; end;;;;; ## return an id for the app if run success;;;;; return app[1];;;;; end;;;;; ;;;;; ;;;;; ################################################################################################################################################# ;;;;; #################################################################################################################################################;;;;; ## ect methods ;;;;; ;;;;;;;;;; def help *args ## obj, keyword;;;;; p = $datadir+"/RubinManual";;;;; if File.directory?(p) == false; raise "There is no manual dir." end;;;;; if args.length == 1 and args[0].to_s.length > 0; c = ""; k = args[0].to_s;;;;; elsif args.length == 2; c = args[0].class.to_s; k = args[1].to_s;;;;; else; raise "Invalid arguments.";;;;; end;;;;; if c.to_s == ""; else; if c.include?("::"); c = c.split("::").join(";"); end; end;;;;; if k.end_with?("!"); k = k[0..-2].to_s+"e"; end;;;;; if k.end_with?("?"); k = k[0..-2].to_s+"q"; end;;;;; if c.to_s == ""; lookup = k.to_s;;;;; else; lookup = c.to_s+"."+k.to_s;;;;; end;;;;; path = p+"/"+lookup.to_s+".txt" ;;;;; if File.file?(path) == false; raise "Invalid object or keyword."; end;;;;; begin; f=File.open(path,"r"); dat=f.read; f.close;;;;; rescue; raise "Fialed to read help file.";;;;; end;;;;; puts "";;;;; puts dat.to_s;;;;; puts "";;;;; return nil;;;;; 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+":"+@cid.to_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;;;;; elsif @input[0].to_s.downcase=="*";res = system(@input[1..-1]);;;;; 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+":"+@cid.to_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+":"+@cid.to_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: "+@context.to_s+"cid: "+@cid.to_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+":"+@cid.to_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.";;;;; begin;f.close;rescue;;end;;;;; 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;;;;;;;;;;;;;;; ;;;;; ;;;;; 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 *args ;;;;; SYSTEM.host.launch_new(SYSTEM.homedir+"/launch.rb");;;;; ;;;;; end;;;;; ;;;;; ;;;;; def spawn *args;;;;; str = args[0].to_s;;;;; str = "`start ruby \"launch.rb\" - "+str+"`";;;;; eval(str);;;;; 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";;;;; ;;;;; @host_controller = Host_Controller.new ;;;;; ;;;;; end;;;;; ;;;;; def controller; return @host_controller; end;;;;; alias :con :controller;;;;; ;;;;; def request(cmd); return system(cmd.to_s); end;;;;; ;;;;; def call(cmd); self.instance_eval("`"+cmd.to_s+"`"); return nil; 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;;;;; #Image Name, PID, Session Name, Session No., Mem Usage;;;;; str = `TASKLIST /FO CSV`;;;;; procs = [];;;;; str.each_line do |line|;;;;; # Skip the header line;;;;; next if line =~ /^"Image Name"/;;;;;;;;;; # Extract the process information using a regular expression;;;;; match = line.match(/^"(.+?)","(\d+)","(.+?)","(\d+)","(\d+.*?)"/);;;;; if match;;;;; name = match[1];;;;; pid = match[2].to_i;;;;; session_name = match[3];;;;; session_n = match[4].to_i;;;;; mem_usag = match[5].to_i;;;;; procs << [name, pid, session_name, session_n, mem_usag];;;;; end;;;;; end;;;;; 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 print_in_new_window(str);;;;; nstr = "`start ruby -e 'print ARGV[1].to_s;gets' - \""+str.to_s+"\"`";;;;; eval nstr;;;;; end;;;;; ;;;;; def ruby_in_new_window(str);;;;; nstr = "`start ruby -e 'instance_eval ARGV[1].to_s;gets' - \""+str.to_s+"\"`";;;;; eval nstr;;;;; end;;;;; ;;;;; def get_window_title;;;;; get_foreground_window = Win32API.new('user32', 'GetForegroundWindow', [], 'L');;;;; get_window_text = Win32API.new('user32', 'GetWindowText', ['L', 'P', 'L'], 'L');;;;;;;;;; foreground_window = get_foreground_window.call;;;;; window_title = ' ' * 256;;;;; get_window_text.call(foreground_window, window_title, 256);;;;; window_title.strip!;;;;; puts "Active window: #{window_title}";;;;; end ;;;;; ;;;;; ;;;;; def name; return ENV["COMPUTERNAME"]; end;;;;; def user; return ENV["USERNAME"]; end;;;;; ;;;;;;;;;; ;;;;; def installed_programs *args;;;;; folders = [];;;;; if args.length == 0 or args[0].to_s.downcase == "x86";;;;; if File.directory?("C:/Program Files (x86)") == false ; raise "Cannot locate host program files directory."; end;;;;; cont = Dir.entries("C:/Program Files (x86)").reject { |entry| entry == "." || entry == ".." };;;;; cont.each { |c| folders << c };;;;; end;;;;; if args.length == 0 or args[0].to_s.downcase == "x64";;;;; if File.directory?("C:/Program Files") == false ; raise "Cannot locate host program files directory."; end;;;;; cont = Dir.entries("C:/Program Files").reject { |entry| entry == "." || entry == ".." };;;;; cont.each { |c| folders << c };;;;; end;;;;; return folders;;;;; end;;;;; ;;;;; def get_executables *args;;;;; exes = [];;;;; if args.length == 0 or args[0].to_s.downcase == "x86";;;;; Dir.glob("C:/Program Files (x86)/**/*.{exe,EXE}").each do |file|;;;;; exes << file if File.file?(file);;;;; end;;;;; end;;;;; if args.length == 0 or args[0].to_s.downcase == "x64";;;;; Dir.glob("C:/Program Files/**/*.{exe,EXE}").each do |file|;;;;; exes << file if File.file?(file);;;;; end ;;;;; end;;;;; return exes;;;;; end;;;;; ;;;;; ;;;;; def get_executables;;;;; exe_files = [];;;;; Dir.glob("C:/Program Files/**/*.{exe,EXE}").each do |file|;;;;; exe_files << file if File.file?(file);;;;; end;;;;; exe_files;;;;; end;;;;;;;;;; ;;;;; ;;;;; def other_ruby_procs;;;;; wmi = WIN32OLE.connect('winmgmts://');;;;; processes = wmi.ExecQuery('SELECT * FROM Win32_Process WHERE Name = "ruby.exe"');;;;; other_ruby_pids = [];;;;; processes.each do |process|;;;;; pid = process.Properties_('ProcessId').Value;;;;; other_ruby_pids << pid if pid != Process.pid;;;;; end;;;;; other_ruby_pids;;;;; end;;;;; ;;;;; ;;;;;;;;;; class Host_Controller;;;;; def initialize;;;;; @keyboard_keys = {"LEFT_CLICK" => 0x01, # Left mouse button;;;;; "RIGHT_CLICK" => 0x02, # Right mouse button;;;;; "MIDDLE_CLICK" => 0x04, #Middle mouse button (three-button mouse);;;;; "LEFT" => 0x25, #LEFT ARROW key;;;;; "ENTER" => 0x0D, # ENTER key ;;;;; "ESCAPE" => 0x1B, #ESC key;;;;; "UP" => 0x26, #UP ARROW key;;;;; "RIGHT" => 0x27, #RIGHT ARROW key;;;;; "DOWN" => 0x28, #DOWN ARROW key;;;;; "SPACE" => 0x20, #SPACEBAR;;;;; "TAB" => 0x09, #TAB key;;;;; "BACK"=>0x08, #BACKSPACE key;;;;; "CAPITAL" => 0x14, #CAPS LOCK key;;;;; "RETURN" => 0x0D, #ENTER key;;;;; "SHIFT" => 0x10, #SHIFT key;;;;; "CONTROL" => 0x11, #CTRL key;;;;; "ALT" => 0x12, #ALT key;;;;; "END" => 0x23, #END key;;;;; "HOME" => 0x24, #HOME key;;;;; "INSERT" => 0x2D, #INS key;;;;; "NEXT" => 0x22, #PAGE DOWN key;;;;; "PRIOR" => 0x21, #PAGE UP key;;;;; "PAUSE" => 0x13, #PAUSE key;;;;; "SELECT" => 0x29, #SELECT key;;;;; "SNAPSHOT" => 0x2C, #PRINT SCREEN key;;;;; "EXECUTE" => 0x2B, #EXECUTE key;;;;; "PRINT" => 0x2A, #PRINT key;;;;; "DELETE" => 0x2E, #DEL key;;;;; "CANCEL" => 0x03, #Control-break processing;;;;; "CLEAR" => 0x0C, #CLEAR key;;;;; "HELP" => 0x2F, #HELP key;;;;; "XP_BUTTON1"=> 0x05, #Windows 2000/XP: X1 mouse button;;;;; "XP_BUTTON2"=> 0x06, #Windows 2000/XP: X2 mouse button;;;;; "0" => 0x30, #0 key;;;;; "1" => 0x31, #1 key;;;;; "2" => 0x32, #2 key;;;;; "3" => 0x33, #3 key;;;;; "4" => 0x34, #4 key;;;;; "5" => 0x35, #5 key;;;;; "6" => 0x36, #6 key;;;;; "7" => 0x37, #7 key;;;;; "8" => 0x38, #8 key;;;;; "9" => 0x39, #9 key;;;;; "A" => 0x41, #A key;;;;; "B" => 0x42, #B key;;;;; "C" => 0x43, #C key;;;;; "D" => 0x44, #D key;;;;; "E" => 0x45, #E key;;;;; "F" => 0x46, #F key;;;;; "G" => 0x47, #G key;;;;; "H" => 0x48, #H key;;;;; "I" => 0x49, #I key;;;;; "J" => 0x4A, #J key;;;;; "K" => 0x4B, #K key;;;;; "L" => 0x4C, #L key;;;;; "M" => 0x4D, #M key;;;;; "N" => 0x4E, #N key;;;;; "O" => 0x4F, #O key;;;;; "P" => 0x50, #P key;;;;; "Q" => 0x51, #Q key;;;;; "R" => 0x52, #R key;;;;; "S" => 0x53, #S key;;;;; "T" => 0x54, #T key;;;;; "U" => 0x55, #U key;;;;; "V" => 0x56, #V key;;;;; "W" => 0x57, #W key;;;;; "X" => 0x58, #X key;;;;; "Y" => 0x59, #Y key;;;;; "Z" => 0x5A, #Z key;;;;; "." => 0x2E, #. key;;;;; "," => 0x2C, #, key;;;;; "/" => 0x2F, #/ key;;;;; ";" => 0xBA, #; key;;;;; "'" => 0xDE, #' key;;;;; "[" => 0xDB, #[ key;;;;; "]" => 0xDD, #] key;;;;; "-" => 0xBD, #- key;;;;; "=" => 0xBB, #= key;;;;; "`" => 0xC0 #` key;;;;; } ;;;;; end;;;;; ;;;;;;;;;; ;;;;; def switch_windows *args;;;;; if args.length == 0; t = 1;;;;; elsif args[0].is_a?(Integer);;;;; if args[0].to_i > 0 ; t = args[0].to_i;;;;; else; raise "Argument invalid type.";;;;; end;;;;; else; raise "Argument requires Integer.";;;;; end;;;;; if args.length == 0 or args[0].to_s == "1";;;;; Win32API.new('user32', 'keybd_event', ['I', 'I', 'L', 'L'], 'V').call(0x12, 0, 0, 0);;;;; Win32API.new('user32', 'keybd_event', ['I', 'I', 'L', 'L'], 'V').call(0x09, 0, 0, 0);;;;; Win32API.new('user32', 'keybd_event', ['I', 'I', 'L', 'L'], 'V').call(0x09, 0, 0x0002, 0);;;;; Win32API.new('user32', 'keybd_event', ['I', 'I', 'L', 'L'], 'V').call(0x12, 0, 0x0002, 0) ;;;;; else;;;;; Win32API.new('user32', 'keybd_event', ['I', 'I', 'L', 'L'], 'V').call(0x12, 0, 0, 0);;;;; t.times{;;;;; Win32API.new('user32', 'keybd_event', ['I', 'I', 'L', 'L'], 'V').call(0x09, 0, 0, 0);;;;; Win32API.new('user32', 'keybd_event', ['I', 'I', 'L', 'L'], 'V').call(0x09, 0, 0x0002, 0);;;;; };;;;; Win32API.new('user32', 'keybd_event', ['I', 'I', 'L', 'L'], 'V').call(0x12, 0, 0x0002, 0);;;;; end;;;;; end;;;;; ;;;;; def toggle_start_menu;;;;; Win32API.new('user32', 'keybd_event', ['I', 'I', 'L', 'L'], 'V').call(0x5B, 0, 0, 0) # Press the Windows key;;;;; Win32API.new('user32', 'keybd_event', ['I', 'I', 'L', 'L'], 'V').call(0x5B, 0, 0x0002, 0) # Release the Windows key ;;;;; end;;;;; ;;;;; def launch_run_dialog;;;;; Win32API.new('user32', 'keybd_event', ['I', 'I', 'L', 'L'], 'V').call(0x5B, 0, 0, 0) # Press the Windows key;;;;; Win32API.new('user32', 'keybd_event', ['I', 'I', 'L', 'L'], 'V').call(0x52, 0, 0, 0) # Press the R key;;;;; Win32API.new('user32', 'keybd_event', ['I', 'I', 'L', 'L'], 'V').call(0x52, 0, 0x0002, 0) # Release the R key;;;;; Win32API.new('user32', 'keybd_event', ['I', 'I', 'L', 'L'], 'V').call(0x5B, 0, 0x0002, 0) # Release the Windows key;;;;; end;;;;; ;;;;; def type *args;;;;; stream = [];;;;; if args[0].is_a?(Integer); stream << [args[0]];;;;; elsif args[0].is_a?(String); stream << [@keyboard_keys[args[0].to_s.upcase]];;;;; elsif args[0].is_a?(Array);;;;; if args[0][0].is_a?(String);;;;; args[0].each { |a| stream << @keyboard_keys[a.to_s.upcase] };;;;; elsif args[0][0].is_a?(Integer);;;;; args[0].each { |k| if k.to_s != ""; stream << k; end};;;;; else; raise "Invalid argument array.";;;;; end;;;;; else; raise "Invalid Arguments.";;;;; end;;;;;;;;;; if stream.length > 0;;;;; stream.each do |s|;;;;; Win32API.new('user32', 'keybd_event', ['I', 'I', 'L', 'L'], 'V').call(s, 0, 0, 0) # Press the R key;;;;; Win32API.new('user32', 'keybd_event', ['I', 'I', 'L', 'L'], 'V').call(s, 0, 0x0002, 0) # Release the R key;;;;; #sleep 0.010 if we ever have problems with input mixing this might help;;;;; end;;;;; end;;;;; if stream.length > 0; return stream.length;;;;; else; return false;;;;; end;;;;; end;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;;;;;;; ;;;;; 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/doc.txt",;;;;; "/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/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 get_coredirs;;;;; coredirs = [];;;;; 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|;;;;; if File.directory?(SYSTEM.homedir+f);;;;; coredirs << SYSTEM.homedir+f;;;;; end;;;;; end;;;;; rescue;self.errorlog("Rubin::Installation_Manager.m: Unable to verify COREDIRS.");;;;; end;;;;; coredirs;;;;; end;;;;; ;;;;; ;;;;; ;;;;; ;;;;; def snapshot;;;;; Dir.image(SYSTEM.sysdir,SYSTEM.datadir+"/temp","systemfiles");;;;; Dir.image(SYSTEM.cfgdir,SYSTEM.datadir+"/temp","systemfiles");;;;; ;;;;; Dir.image(SYSTEM.appdir,SYSTEM.datadir+"/temp","appfiles");;;;; Dir.image(SYSTEM.classdir,SYSTEM.datadir+"/temp","classfiles");;;;; Dir.image(SYSTEM.datadir+"/definitions",SYSTEM.datadir+"/temp","definitionfiles");;;;; ;;;;; ;;;;; ;;;;; end;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;;end;;;;; ;;;;;;;;;; ################################################################################################################################;;;;; ################################################################################################################################;;;;; ## controller;;;;; ;;;;; ;;;;; class Controller ## virtual network via 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 overide 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";;;;; res=@context.instance_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+":"+@opid.to_s+":"+Time.stamp;;;;; s2="<< "+str.to_s;;;;; s3=">> "+res.to_s;;;;; s4=s1+"\n"+s2+"\n"+s3+"\n";;;;; s5=SYSTEM.instance.id.to_s+":"+@opid.to_s+":"+Time.stamp+": Dir log created. ("+@dir.to_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;;;;; ;;;;; ;;;;; ;;;;; ;;;;; end;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ##########################################################################################################################;;;;;;;;;; class BotController;;;;; def initialize;;;;; @instance = SYSTEM.instance;;;;; @controller = SYSTEM.controller;;;;; @start_time = BOOT_INIT_TIME ;;;;; ;;;;; 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(ARGV[0].to_s) ##load and initialize resources;;;;;SYSTEM.post_initialization ##run autostart apps/scritps and maybe shell;;;;;;;;;;#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.3 pkg 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;;;;;;;;;;;;;;;## RubinSystem is a ruby app runtime environment. Multi-Instance, bot controller on Mingw Windows Ruby;;;;;## ## !! WARNING !! If you did not download this script from github or the official website, DO NOT RUN IT!;;;;;## Run this script to install Rubin System, either select the work directory or enter an install location.;;;;;## After installing run "launch.rb" and you will get the system shell by default. The shell runs input as ;;;;;## ruby script on the RubinSystem context. Precede a command with * if you are entering windows scripts;;;;;## or host commands, also *context=MAIN changes shell context. The shell does not handle stack errors well;;;;;## so IRB is used to catch error messages that crash the shell.;;;;;## ;;;;;## Upon first use, you will get a default system config, use SYSTEM.config? to see what config settings;;;;;## you have, another tip is that you have :local_methods to compliment :methods, except :local_methods will;;;;;## only return methods that belong to the instance of the object and not any parents.;;;;;;;;;;## Better documentation is underway but struggles to keep up with rapid development.;;;;;## email bugs to rubinsystem@gmail.com;;;;;;;;;;#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment