Last active
September 27, 2016 10:35
-
-
Save thomasjslone/1a86d614421c6a9cc50eaf60fab16764 to your computer and use it in GitHub Desktop.
Improved vdrive template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Vdrive | |
def initialize | |
@data = '55556157616153565359536061576157595558615856585958565862585659535955586158575860585858575857585858575858841905168455556157' | |
@drive = "v:" | |
@drives = [@drive] | |
@files = [] | |
@directories = [@drive] | |
@kbchars = ["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","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","~","`","!","@","#","$","%","^","&","*","(",")","-","_","=","+","[","]","{","}",";",":","\"","'","\\","/","|","?","<",">",",","."," ","\t","\n"] | |
@chbytes = ["97", "98", "99", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", "120", "121", "122", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "126", "96", "33", "64", "35", "36", "37", "94", "38", "42", "40", "41", "45", "95", "61", "43", "91", "93", "123", "125", "59", "58", "34", "39", "92", "47", "124", "63", "60", "62", "44", "46", "32", "9", "10"] | |
@key = 0 | |
end | |
def load_drive | |
fi = File.open(__FILE__,'r') | |
fc = fi.read.to_s.split("\n") | |
fi.close | |
fimg = denumerize(fc[2].to_s.split("'")[1].to_s) | |
puts "FIMG: " + fimg.to_s | |
encf = fimg.split(':sep:')[0].to_s.split(',') | |
encd = fimg.split(':sep:')[1].to_s.split(',') | |
files = [] | |
directories = [] | |
encf.each { |ef| files << denumerize(ef).chomp.to_s } | |
encd.each { |ed| directories << denumerize(ed).chomp.to_s } | |
@files = files | |
@directories = directories | |
true | |
end | |
def save_drive | |
encf = [] | |
encd = [] | |
@files.each { |f| encf << numerize(f).to_s } | |
@directories.each { |d| encd << numerize(d).to_s } | |
fimg = numerize(encf.join(",") + ":sep:" + encd.join(',').to_s) | |
fi = File.open(__FILE__,"r") | |
fc = fi.read.to_s.split("\n") | |
fi.close | |
fc[2] = "@data = '" + fimg.to_s + "'" | |
fi = File.open(__FILE__,'w') | |
fi.write(fc.join("\n").to_s) | |
fi.close | |
true | |
end | |
def format_drive | |
@files = [] | |
@directories = [] | |
self.save_drive | |
end | |
def measure_drive | |
bytes = 0 | |
@files.each do |fi| | |
bytes += fi.to_s.split('').length | |
end | |
return [@directories.length,@files.length,bytes] | |
end | |
def export_drive | |
encf = [] | |
encd = [] | |
@files.each { |f| encf << numerize(f).to_s } | |
@directories.each { |d| encd << numerize(d).to_s } | |
fimg = numerize(encf.join(",") + ":sep:" + encd.join(',').to_s).to_i * @key.to_i | |
return fimg.to_s | |
end | |
def import_drive(obj) | |
fc = obj.to_s.to_i / @key.to_i | |
fimg = denumerize(fc[2].to_s.split("'")[1].to_s) | |
encf = fimg.split(':sep:')[0].to_s.split(',') | |
encd = fimg.split(':sep:')[1].to_s.split(',') | |
files = [] | |
directories = [] | |
encf.each { |ef| files << denumerize(ef).chomp.to_s } | |
encd.each { |ed| directories << denumerize(ed).chomp.to_s } | |
@files = files | |
@directories = directories | |
true | |
end | |
def write_file(path,content) | |
if file_exist?(path) | |
ind = get_findex(path).to_i | |
file = @files[ind] | |
@files[ind] = file.split("::")[0].to_s + "::" + numerize(content.to_s).to_s | |
return "File was overwritten" | |
else | |
if @directories.include?(path.to_s.split('/')[0..-2].join('/').to_s) | |
@files << path.to_s + "::" + numerize(content.to_s).to_s | |
return "File created and written" | |
else | |
return "Invalid directory in file path" | |
end | |
end | |
end | |
def insert_file(path,pos,content) | |
end | |
def read_file(path) | |
if file_exist?(path) | |
return denumerize(@files[get_findex(path)].split("::")[-1].to_s).to_s | |
else | |
return "Invalid directory or file name" | |
end | |
end | |
def delete_file(path) | |
if file_exist?(path) | |
@files.delete_at(get_findex(path).to_i) | |
true | |
else | |
false | |
end | |
end | |
def rename_file(path,name) | |
if file_exist?(path) | |
fi = @file[get_findex(path)].to_s | |
fc = fi.split('::')[1] | |
fp = fi.split('::')[0].to_s.split("/")[0..-2].join("/").to_s + "/" + name.to_s | |
if file_exist?(fp) == false | |
@file[get_findex(path)] = fp.to_s + "::" + fc.to_s | |
true | |
else | |
false | |
end | |
else | |
false | |
end | |
end | |
def measure_file(path) | |
@file[get_findex(path)].to_s.split('::')[1].to_s.split('').length | |
end | |
def file_exist?(path) | |
found = false | |
ct = 0 | |
@files.each do |fi| | |
if fi.split("::")[0].to_s == path.to_s | |
found = ct.to_i | |
break | |
else | |
ct += 1 | |
end | |
end | |
if found != false | |
return true | |
else | |
return false | |
end | |
end | |
def get_findex(path) | |
found = false | |
ct = 0 | |
@files.each do |fi| | |
if fi.split("::")[0].to_s == path.to_s | |
found = ct.to_i | |
break | |
else | |
ct += 1 | |
end | |
end | |
if found != false | |
return found.to_i | |
else | |
return false | |
end | |
end | |
def directory_exist?(path) | |
if @directories.include?(path) | |
true | |
else | |
false | |
end | |
end | |
def get_dindex(path) | |
if @directories.include?(path) | |
@directories.index(path).to_i | |
else | |
false | |
end | |
end | |
def directory_contents(path) | |
if @directories.include?(path) | |
conts = [] | |
@directories.each do |d| | |
if d.to_s.include?(path) | |
conts << d.to_s | |
end | |
end | |
@files.each do |f| | |
if f.split("::")[0].to_s.include?(path) | |
conts << f.split("::")[0].to_s | |
end | |
end | |
if conts.length == 0 | |
return nil | |
else | |
return conts | |
end | |
else | |
return false | |
end | |
end | |
def make_directory(path) | |
ndir = path.split('/')[-1].to_s | |
if @directories.include?(path.split('/')[0..-2].join('/').to_s) and @directories.include(path.to_s) == false | |
@directories << path.to_s | |
true | |
else | |
false | |
end | |
end | |
def rename_directory(path,name) | |
if @directories.include?(path) | |
if directory_exist?(path.to_s.split('/')[0..-2].join('/').to_s + "/" + name.to_s) == false | |
@directories[get_dindex(path)] = path.to_s.split("/")[0..-2].join('/').to_s + "/" + name.to_s | |
return true | |
else | |
return false | |
end | |
else | |
return "Invalid directory" | |
end | |
end | |
def delete_directory(path) | |
if @directories.include?(path) | |
@directories.delete_at(get_dindex) | |
true | |
else | |
false | |
end | |
end | |
def measure_directory(path) | |
end | |
def numerize(str) | |
ch_inds = [] | |
str.to_s.split("").each { |ch| ch_inds << @chbytes.index(ch.to_s.ord.to_s) } | |
enc = [] | |
ch_inds.each do |ch| | |
code = ch.to_i + 1 | |
if code.to_s.length == 1 | |
code = "0" + code.to_s | |
else | |
code = code.to_s | |
end | |
enc << code.to_s | |
end | |
enc = enc.join("").to_s | |
if enc.to_s[0].to_s == "0" | |
enc = enc[1..-1].to_s | |
end | |
return enc.to_s | |
end | |
def denumerize(str) | |
if str.to_s.length.odd? | |
str = "0" + str.to_s | |
end | |
str_codes = [] | |
i = 0 | |
hold = "" | |
str.to_s.split("").each do |num| | |
if i.to_i == 0 | |
hold << num.to_s | |
i += 1 | |
elsif i.to_i == 1 | |
hold << num.to_s | |
i = 0 | |
str_codes << hold.to_s | |
hold = "" | |
end | |
end | |
str = str_codes | |
str_codes = [] | |
str.each do |c| | |
str_codes << c.to_i - 1 | |
end | |
dec_str = "" | |
str_codes.each { |c| dec_str << @kbchars[c.to_i].to_s } | |
return dec_str.to_s | |
end | |
end | |
$vdr = Vdrive.new() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment