]> granicus.if.org Git - nethack/commitdiff
bits to allow GUI to run recover under MacOS X
authorkeni <keni>
Tue, 27 Oct 2009 01:12:57 +0000 (01:12 +0000)
committerkeni <keni>
Tue, 27 Oct 2009 01:12:57 +0000 (01:12 +0000)
Will require additional work for 3.5 (shouldn't blindly remove perm_lock
without asking the user; update comments; add standard headers) but I don't
want to lose this code.

win/macosx/NetHackRecover.applescript [new file with mode: 0644]
win/macosx/recover.pl [new file with mode: 0755]

diff --git a/win/macosx/NetHackRecover.applescript b/win/macosx/NetHackRecover.applescript
new file mode 100644 (file)
index 0000000..a58b6ae
--- /dev/null
@@ -0,0 +1,18 @@
+set canceled to false
+try
+       display dialog "Welcome to the NetHack recover program.  Please make sure NetHack is not running before continuing.  Ready?" with title "NetHackRecover"
+on error number -128
+       set canceled to true
+end try
+if not canceled then
+       set hpath to the path to me
+       set mpath to the POSIX path of hpath
+       considering case
+               set lastpos to offset of "/nethackdir" in mpath
+               set lastpos to lastpos + (length of "/nethackdir")
+               set rawpath to (get text 1 through lastpos of mpath) & "/recover.pl"
+               set safepath to the quoted form of rawpath
+       end considering
+       do shell script safepath
+       display dialog result with title "NetHackRecover Output"
+end if
diff --git a/win/macosx/recover.pl b/win/macosx/recover.pl
new file mode 100755 (executable)
index 0000000..a7c2ed6
--- /dev/null
@@ -0,0 +1,45 @@
+#!/usr/bin/perl
+
+# $Id$
+# Wrapper for 3.4.3 recover to be called from Applescript to reset the Qt
+# package after it locks up due to a bug in suspend handling.
+
+# find the right place
+($playground = $0) =~ s!/recover.pl$!!;
+if(! -d $playground){
+       print "Cannot find playground $playground.";
+       exit 0
+}
+if(! -f "$playground/castle.lev"){
+       print "Failed to find playground $playground.";
+       exit 0
+}
+print "Playground is $playground.\n";
+chdir $playground or do {
+       print "Can't get to playground.\n";
+       exit 0
+};
+if(-e 'perm_lock'){
+       print "Attempting to remove perm_lock.\n";
+       $try_perm = 1;
+       unlink 'perm_lock';
+} else {
+       print "Did not find perm_lock (this is OK).\n";
+}
+if(-e 'perm_lock'){
+       print "Failed to remove perm_lock: $!\n";
+       exit 0
+}
+if($try_perm){
+       print "Removed perm_lock.\n";
+}
+
+# run recover, but only if there is something that looks promising
+$uid = $<;
+foreach ( <$uid*.0> ){
+       system ("./recover -d . $_);
+}
+
+print "Done.\n";
+
+exit 0