Skip to content

Instantly share code, notes, and snippets.

@jtprince
Created May 29, 2014 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtprince/b73425f088ab8f5f24fc to your computer and use it in GitHub Desktop.
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
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