@@ -66,6 +66,9 @@ export async function activate(context: vscode.ExtensionContext) {
6666 ) ;
6767 const bundle = await fs . readFile ( bundlePath ) ;
6868
69+ const timeStamp = new Date ( ) . getTime ( ) . toString ( ) ;
70+ const logFilename = timeStamp . substr ( timeStamp . length - 5 , 8 ) + '.log' . toUpperCase ( ) ;
71+
6972 let result = "<should-not-return>" ;
7073 const uri = vscode . Uri . joinPath ( seperateSpaceFolder , ( "test" + path . extname ( _uri . fsPath ) ) . toUpperCase ( ) ) ;
7174 await fs . copy ( _uri , uri ) ;
@@ -79,8 +82,6 @@ export async function activate(context: vscode.ExtensionContext) {
7982 'd:' ,
8083 ...action . before
8184 ] ;
82- const timeStamp = new Date ( ) . getTime ( ) . toString ( ) ;
83- const logFilename = timeStamp . substr ( timeStamp . length - 5 , 8 ) + '.log' . toUpperCase ( ) ;
8485 const logUri = vscode . Uri . joinPath ( assemblyToolsFolder , logFilename ) ;
8586 if ( nodefs . existsSync ( logUri . fsPath ) ) {
8687 await fs . delete ( logUri ) ;
@@ -174,8 +175,53 @@ export async function activate(context: vscode.ExtensionContext) {
174175 }
175176
176177 if ( conf . extConf . emulator === conf . DosEmulatorType . msdos ) {
177- const t = api . msdosPlayer ( ) ;
178- t . show ( ) ;
178+ const terminal = api . msdosPlayer ( ) ;
179+
180+ terminal . show ( ) ;
181+ api . dosbox . fromBundle ( bundle , assemblyToolsFolder ) ;
182+ action . before . forEach (
183+ val => {
184+ ( terminal as vscode . Terminal ) . sendText ( val . replace ( 'C:' , assemblyToolsFolder . fsPath ) ) ;
185+ }
186+ ) ;
187+ if ( type === actionType . open ) {
188+ terminal . sendText ( `cd "${ vscode . Uri . joinPath ( _uri , '..' ) . fsPath } "` ) ;
189+ }
190+ else {
191+ terminal . sendText ( `cd "${ folder . fsPath } "` ) ;
192+ function cb ( val : string ) {
193+ const r = val
194+ . replace ( "${file}" , fileInfo . base )
195+ . replace ( "${filename}" , fileInfo . name ) ;
196+ if ( val . startsWith ( '>' ) ) {
197+ return r . replace ( ">" , "" ) ;
198+ } else {
199+ return r + `>> ${ logFilename } \n type ${ logFilename } ` ;
200+ }
201+ }
202+ if ( type === actionType . run ) {
203+ action . run . map ( cb ) . forEach ( val => ( terminal as vscode . Terminal ) . sendText ( val ) ) ;
204+ }
205+ if ( type === actionType . debug ) {
206+ action . debug . map ( cb ) . forEach ( val => ( terminal as vscode . Terminal ) . sendText ( val ) ) ;
207+ }
208+ const logUri = vscode . Uri . joinPath ( folder , logFilename ) ;
209+ const [ hook , promise ] = messageCollector ( ) ;
210+ nodefs . watchFile ( logUri . fsPath , ( ) => {
211+ try {
212+ if ( nodefs . existsSync ( logUri . fsPath ) ) {
213+ const text = nodefs . readFileSync ( logUri . fsPath , { encoding : 'utf-8' } ) ;
214+ hook ( text ) ;
215+ }
216+ }
217+ catch ( e ) {
218+ console . error ( e ) ;
219+ }
220+ } ) ;
221+ //terminal.sendText('exit', true);
222+ result = await promise ;
223+ }
224+
179225 }
180226
181227 const diagnose = diag . process ( result , doc , conf . extConf . asmType ) ;
0 commit comments