@@ -3,6 +3,7 @@ import { EventEmitter, Injectable, Output } from '@angular/core';
3
3
import { CommandQueueService } from './commandQueue.service' ;
4
4
import { EmulatorService } from './emulator.service' ;
5
5
import { once } from '../utils/misc' ;
6
+ import { ByondService } from './byond.service' ;
6
7
7
8
@Injectable ( {
8
9
providedIn : 'root' ,
@@ -16,60 +17,66 @@ export class ExecutorService {
16
17
constructor (
17
18
private commandQueue : CommandQueueService ,
18
19
private emulator : EmulatorService ,
20
+ private byondService : ByondService ,
19
21
) { }
20
22
21
23
public async executeImmediate (
22
24
code : string ,
23
25
signal ?: AbortSignal ,
24
26
) : Promise < void > {
25
- const filename = `tmp-${ Date . now ( ) } ` ;
26
- let stageAbort : Function | undefined = undefined ;
27
+ return this . byondService . useActive ( ( path ) => {
28
+ if ( path == null )
29
+ return Promise . reject ( new Error ( 'No active byond version' ) ) ;
27
30
28
- this . reset . emit ( ) ;
29
- const promise = new CancelablePromise < void > ( ( resolve ) => {
30
- resolve ( this . emulator . start ( ) ) ;
31
- } )
32
- . then ( ( ) => {
33
- return this . emulator . sendFile ( filename + '.dme' , code ) ;
34
- } )
35
- . then ( ( ) => {
36
- return this . commandQueue . runProcess (
37
- '/byond/bin/DreamMaker' ,
38
- '/mnt/host/' + filename + '.dme' ,
39
- new Map ( [ [ 'LD_LIBRARY_PATH' , '/byond/bin' ] ] ) ,
40
- ) ;
41
- } )
42
- . then ( ( compiler ) => {
43
- this . output . emit ( '=== Compile stage ===\n' ) ;
44
- compiler . stdout . subscribe ( ( val ) => this . output . emit ( val ) ) ;
45
- stageAbort = compiler . kill ;
46
- return once ( compiler . exit ) ;
47
- } )
48
- . then ( ( ) => {
49
- return this . commandQueue . runProcess (
50
- '/byond/bin/DreamDaemon' ,
51
- `/mnt/host/${ filename } .dmb\0-trusted` ,
52
- new Map ( [ [ 'LD_LIBRARY_PATH' , '/byond/bin' ] ] ) ,
53
- ) ;
54
- } )
55
- . then ( ( server ) => {
56
- this . output . emit ( '\n=== Run stage ===\n' ) ;
57
- server . stderr . subscribe ( ( val ) => this . output . emit ( val ) ) ;
58
- stageAbort = server . kill ;
59
- return once ( server . exit ) ;
60
- } )
61
- . then ( ( ) => {
62
- stageAbort = undefined ;
31
+ const filename = `tmp-${ Date . now ( ) } ` ;
32
+ let stageAbort : Function | undefined = undefined ;
33
+
34
+ this . reset . emit ( ) ;
35
+ const promise = new CancelablePromise < void > ( ( resolve ) => {
36
+ resolve ( this . emulator . start ( ) ) ;
63
37
} )
64
- . finally ( ( ) => {
65
- if ( stageAbort ) stageAbort ( ) ;
66
- this . commandQueue . runProcess (
67
- '/bin/rm' ,
68
- `/mnt/host/${ filename } .dme\0/mnt/host/${ filename } .dmb` ,
69
- ) ;
70
- } , true ) ;
38
+ . then ( ( ) => {
39
+ return this . emulator . sendFile ( filename + '.dme' , code ) ;
40
+ } )
41
+ . then ( ( ) => {
42
+ return this . commandQueue . runProcess (
43
+ path + 'DreamMaker' ,
44
+ '/mnt/host/' + filename + '.dme' ,
45
+ new Map ( [ [ 'LD_LIBRARY_PATH' , path ] ] ) ,
46
+ ) ;
47
+ } )
48
+ . then ( ( compiler ) => {
49
+ this . output . emit ( '=== Compile stage ===\n' ) ;
50
+ compiler . stdout . subscribe ( ( val ) => this . output . emit ( val ) ) ;
51
+ stageAbort = compiler . kill ;
52
+ return once ( compiler . exit ) ;
53
+ } )
54
+ . then ( ( ) => {
55
+ return this . commandQueue . runProcess (
56
+ path + 'DreamDaemon' ,
57
+ `/mnt/host/${ filename } .dmb\0-trusted` ,
58
+ new Map ( [ [ 'LD_LIBRARY_PATH' , path ] ] ) ,
59
+ ) ;
60
+ } )
61
+ . then ( ( server ) => {
62
+ this . output . emit ( '\n=== Run stage ===\n' ) ;
63
+ server . stderr . subscribe ( ( val ) => this . output . emit ( val ) ) ;
64
+ stageAbort = server . kill ;
65
+ return once ( server . exit ) ;
66
+ } )
67
+ . then ( ( ) => {
68
+ stageAbort = undefined ;
69
+ } )
70
+ . finally ( ( ) => {
71
+ if ( stageAbort ) stageAbort ( ) ;
72
+ this . commandQueue . runProcess (
73
+ '/bin/rm' ,
74
+ `/mnt/host/${ filename } .dme\0/mnt/host/${ filename } .dmb` ,
75
+ ) ;
76
+ } , true ) ;
71
77
72
- signal ?. addEventListener ( 'abort' , ( ) => promise . cancel ( ) ) ;
73
- return promise ;
78
+ signal ?. addEventListener ( 'abort' , ( ) => promise . cancel ( ) ) ;
79
+ return promise ;
80
+ } ) ;
74
81
}
75
82
}
0 commit comments