allow multiple instances of MrEd-based apps

svn: r239
This commit is contained in:
Matthew Flatt 2005-06-24 20:59:28 +00:00
parent 7b3e3e09f6
commit 1fdc922b5a
4 changed files with 34 additions and 5 deletions

View File

@ -487,6 +487,11 @@ _embedr-sig.ss_ library provides the signature, _compiler:embed^_.
the default is 'console for a MzScheme-based application
and 'windows for a MrEd-based application
_'single-instance?_ (Windows) - a boolean for MrEd-based apps; the
default is #t, which means that the app looks for instances
of itself on startup and merely brings the other instance to
the front; #f means that multiple instances are expected
_'forget-exe?_ (Windows, Mac OS X) - a boolean; #t for a launcher
(see `launcher?' below) does not preserve the original
executable name for `(find-system-path 'exec-file)'; the

View File

@ -91,14 +91,15 @@
exe)))
;; Find the magic point in the binary:
(define (find-cmdline)
(let ([m (regexp-match-positions #"\\[Replace me for EXE hack" (current-input-port))])
(define (find-cmdline what rx)
(let ([m (regexp-match-positions rx (current-input-port))])
(if m
(caar m)
(error
'make-embedding-executable
(format
"can't find cmdline position in executable")))))
"can't find ~a position in executable"
what)))))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -525,11 +526,25 @@
cmdline)])
(if osx?
(finish-osx-mred dest full-cmdline exe keep-exe?)
(let ([cmdpos (with-input-from-file dest-exe find-cmdline)]
(let ([cmdpos (with-input-from-file dest-exe
(lambda () (find-cmdline
"cmdline"
#"\\[Replace me for EXE hack")))]
[anotherpos (and mred?
(eq? 'windows (system-type))
(let ([m (assq 'single-instance? aux)])
(and m (not (cdr m))))
(with-input-from-file dest-exe
(lambda () (find-cmdline
"instance-check"
#"yes, please check for another"))))]
[out (open-output-file dest-exe 'update)])
(dynamic-wind
void
(lambda ()
(when anotherpos
(file-position out anotherpos)
(write-bytes #"no," out))
(if long-cmdline?
;; write cmdline at end:
(file-position out end)

View File

@ -841,6 +841,9 @@ void MrEdMSWSleep(float secs, void *fds)
win_extended_fd_set *r, *w, *e;
DWORD msecs;
if (fds && ((win_extended_fd_set *)fds)->no_sleep)
return;
if (wxCheckMousePosition())
return;

View File

@ -57,6 +57,12 @@ extern "C" { typedef int (*ACTUAL_MAIN_PTR)(int argc, char **argv); }
# define CAST_ACTUAL_MAIN /* empty */
#endif
#ifdef wx_msw
/* Hack: overwrite "y" with "n" in binary to disable checking for another
instance of the same app. */
char *check_for_another = "yes, please check for another";
#endif
#if defined(_IBMR2)
static void dangerdanger(int)
{
@ -650,7 +656,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR ignored
}
/* Check for an existing instance: */
{
if (check_for_another[0] != 'n') {
int alreadyrunning;
HANDLE mutex;