Created
May 29, 2014 16:50
-
-
Save jtprince/b73425f088ab8f5f24fc to your computer and use it in GitHub Desktop.
Save and load your Risk II (Hasbro Interactive) game with this simple ruby GUI
This file contains 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
require 'Win32API' | |
require 'fileutils' | |
require 'tk' | |
# supposed to hide base window... not working with cygwin ruby | |
getConsoleWindow = Win32API.new("kernel32" , "GetConsoleWindow" , [] , 'L') | |
ptr_to_console = getConsoleWindow.call() | |
wndConsole = Win32API.new( "user32" , "ShowWindow" , ['p' , 'i'] , 'i' ) | |
wndConsole.call( ptr_to_console , 1 ) | |
class String | |
def unix | |
self.gsub(/\\/, '/') | |
end | |
end | |
root = TkRoot.new { title "Risk2 Saver" } | |
MyHomePath = File.join(ENV['HOMEDRIVE'], ENV['HOMEPATH'].unix ) | |
InitDir = ARGV[0] || File.join(MyHomePath, '/Desktop') | |
appdata = ENV['APPDATA'].unix | |
target_dir = File.join(appdata, "../Local/VirtualStore/Program Files/Microprose/Risk II") | |
def save_to_file(target_dir, new_dirname) | |
FileUtils.cp_r target_dir, new_dirname | |
end | |
def load_file(to_load, replace_dir) | |
FileUtils.rm_rf replace_dir | |
FileUtils.cp_r(to_load, replace_dir) | |
end | |
ftypes = [ ["Risk saves", '*risksv'] ] | |
button = TkButton.new(root) do | |
text "Save Current Game" | |
command do | |
file = Tk.getSaveFile(:filetypes => ftypes, :title => "Save Current Game", :initialdir => InitDir, :defaultextension => '.risksv' ) | |
if file && file != "" | |
save_to_file target_dir, file | |
end | |
end | |
end | |
button.pack :padx => 4, :side => 'left' | |
button2 = TkButton.new(root) do | |
text "Load a game" | |
command do | |
file = Tk.chooseDirectory(:title => "Load a Game", :initialdir => InitDir, :mustexist => true ) | |
if file && file != "" && file =~ /\.risksv$/ | |
load_file(file, target_dir) | |
end | |
end | |
end | |
button2.pack :padx => 4, :side => 'right' | |
button3 = TkButton.new(root) do | |
text "close" | |
command do | |
exit | |
end | |
end | |
Tk.mainloop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment