Grey Hack
Không đủ lượt đánh giá
Create a backup of your scripts
Bởi troglodyt
Just some simple code snippets to backup your scripts to your real life PC.
   
Giải thưởng
Yêu thích
Đã yêu thích
Bỏ thích
Backup your script files
I never understood why there isn't a convenient way to backup your script file.
All your work gone in an update or a hacking mishap!
So I worked out two little scripts which make it easier to copy / paste your scripts to / from your real life PC.

Warning: Backing up your scripts as text only works if you don't use "\n" in your code. Use "char(10)" instead! Else you get strange torn strings in your code because File.get_content does not distnguish between "\n" as a string and a line end!

zip.src
comp = get_shell.host_computer sdir = comp.File("/home/trog/Scripts") scripts = comp.File("/home/trog/scripts.txt") if not scripts then comp.touch("/home/trog", "scripts.txt") scripts = comp.File("/home/trog/scripts.txt") end if if not scripts then exit("Can not open /home/trog/scripts.txt!") s = "" for f in sdir.get_files if not f.is_binary and not f.is_folder then s = s + "@"*5 + f.path + char(10) + f.get_content + char(10) + "@"*10 + char(10) end if end for scripts.set_content(s)


unzip.src
comp = get_shell.host_computer scripts = comp.File("/home/trog/scripts.txt") if not scripts then exit("Can not open /home/trog/scripts.txt!") s = scripts.get_content.split(char(10)) while s.len > 0 line = s.pull //print(">"+line) while line.indexOf("@"*5) != 0 line = s.pull if s.len == 0 then exit("Done.") //print(">>"+line) end while //print(line) fpth = line[5:] //print("Write to file: " + fpth + "...") fn = fpth[fpth.lastIndexOf("/")+1:] pth = fpth[:fpth.lastIndexOf("/")] cont = [] line = s.pull while s.len > 0 and line.indexOf("@"*10) != 0 cont.push(line) line = s.pull end while sdir = comp.File(pth) if not sdir then comp.create_folder(pth[:pth.lastIndexOf("/")], pth[pth.lastIndexOf("/")+1:]) sdir = comp.File(pth) if not sdir then exit("Can't create " + pth + " folder!") end if r = comp.touch(pth, fn) if r != 1 then print("ERROR: Can't create file " + fpth + "! " + r) else f = comp.File(fpth) if f then f.set_content(cont.join(char(10))) print("Created file " + fpth + ".") else print("ERROR: Can't open file " + fpth + "!") end if end if end while

HTH
How to use. Details for new players
To make backup:

- Change the path in the scripts (/home/trog/Scripts) to match the location where your scripts are.
- Compile the zip.src and unzip.src with the code editor (play button).
- In a terminal, execute zip
- All your scripts should be bundled together in a file "scripts.txt" in the current directory.
- Open the file. CTRL-A then CTRL-C to copy its content to the clip board.
- Open notepad on your real life PC and CTRL-V
- Save it where ever
- Do the same procedure for the "unzip.src" file (Only needed once)



Restore a backup:

- Open your script file on the real live PC
- Open the notepad in game
- Copy & Paste the bundled scripts
- Save as "scripts.txt"
- In a terminal run "build unzip.src /home/<your-user-name>"
- In terminal run "unzip"
- All your scripts should be restored


Recompiling your scripts:

- Use the below script to recompile all scripts to the /bin folder.

buildall.src
//command: build buildSrc = function(pathSource, programPath, fn) print("Building " + pathSource + "...") comp = get_shell.host_computer fileSource = comp.File(pathSource) folderDest = comp.File(programPath) if fileSource == null then exit("build: can't find "+ pathSource) if folderDest == null then exit("build: can't find " + programPath) //f = comp.File(programPath + "/" + fn) //if f then f.delete output = get_shell.build(fileSource.path, folderDest.path) if output.len != 0 then print(output); end if end function comp = get_shell.host_computer sdir = comp.File("/home/trog/Scripts") if not sdir then exit("Can not open /home/trog/Scripts.txt!") for f in sdir.get_files if not f.is_binary and not f.is_folder then buildSrc(f.path, "/bin", f.name) end if end for
3 bình luận
{F.S.L} ΕΤΑGαmerPC 2 Thg06 @ 4:09pm 
ctrl a, ctrl c in codeeditor.exe then just open vscode and make a .src file then download greybel-js extension then paste easy done even code highlighting. heck you can even just copy paste into notepad or something like that. no need for all these scripts :openfile:
Isco 1 Thg09, 2021 @ 3:57pm 
This is nice but why not simply just copy paste the script and edit it in notepad.You know theres color syntax for grey script (its a plugin).
Coyote 26 Thg02, 2021 @ 12:50am 
This is a great workaround! Thanks mate :steamthumbsup::duke: