Created
March 10, 2016 06:23
-
-
Save jtprince/20697698e08d695263b7 to your computer and use it in GitHub Desktop.
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
# Very simple tk application to save progress on Microprose's Risk II game | |
# (written many years ago) | |
# | |
# Create a bat file to run, like this: | |
# ----save_risk.bat---- | |
# c:\cygwin\bin\rubyw /home/john/risk2_saver.rb c:/Users/john/Desktop/RISK_SAVES | |
require 'Win32API' | |
require 'fileutils' | |
require 'tk' | |
FU = FileUtils | |
# 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) | |
FU.cp_r target_dir, new_dirname | |
end | |
def load_file(to_load, replace_dir) | |
FU.rm_rf replace_dir | |
FU.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 ) | |
#file = Tk.chooseDirectory(:filetypes => ftypes, :title => "Load a Game", :initialdir => InitDir, :defaultextension => '.risk_save' ) | |
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 | |
#button3.pack :side => 'bottom', :pady => 15, :fill => 'y', :anchor => 's' | |
Tk.mainloop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment