Skip to content

Commit f744909

Browse files
committed
reOrganize some codesfix:can't open dosbox in linux
1 parent 5da6522 commit f744909

File tree

8 files changed

+186
-213
lines changed

8 files changed

+186
-213
lines changed

i18n/chs/out/DOSBox.i18n.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

i18n/chs/out/runcode.i18n.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"openemu.msg": "\nMASM/TASM>>打开DOSBox:{0}",
33
"run.msg": "\n{0}({1})>>运行:{2}",
4-
"debug.msg": "\n{0}({1})>>调试:{2}"
4+
"debug.msg": "\n{0}({1})>>调试:{2}",
5+
"runcode.error": "{0}汇编出错,无法运行/调试",
6+
"runcode.warn": "成功汇编链接生成EXE,但是汇编时产生了警告信息({0}warning),可能无法运行/调试,是否继续操作",
7+
"runcode.continue": "继续",
8+
"runcode.stop": ""
59
}

i18n/chs/out/viaplayer.i18n.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "MASM/TASM",
44
"publisher": "xsro",
55
"description": "DOS汇编语言开发环境和语法支持,win下安装即用,自带DOSBox.exe和TASM/MASM工具",
6-
"version": "0.5.0",
6+
"version": "0.5.1-beta.1",
77
"keywords": [
88
"dosbox",
99
"16位",

src/DOSBox.ts

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,33 @@
11
import { Uri, workspace, window, TextDocument, FileType } from 'vscode';
22
import { Config } from './configration';
33
import { exec, ExecOptions } from 'child_process';
4-
import { AssemblerDiag } from './language/diagnose';
5-
import * as nls from 'vscode-nls';
6-
const localize = nls.loadMessageBundle();
74
/**
8-
* A function used when using boxasm.bat
5+
* A function used when using boxasm.bat to run or debug ASM codes in DOSBox
96
* @param conf The config information
107
* @param runOrDebug true for run ASM code,false for debug
11-
* @param doc the source ASM file
12-
* @param diag using its `diag.ErrMsgProcess` to process the assembler's output
138
*/
14-
export function runDosbox2(conf: Config, runOrDebug: boolean, doc: TextDocument, diag: AssemblerDiag) {
9+
export async function runDosbox2(conf: Config, runOrDebug: boolean): Promise<string> {
1510
let fs = workspace.fs;
1611
let src: Uri = Uri.joinPath(conf.extScriptsUri, "./boxasm.bat");
1712
let target: Uri = Uri.joinPath(conf.toolsUri, "./boxasm.bat");
18-
fs.copy(src, target, { overwrite: conf.toolsBuiltin }).then(
19-
() => {
20-
runDosbox(conf, conf.boxasmCommand(runOrDebug), doc).then(
21-
(stdout) => { BOXdiag(conf, diag, doc); }
22-
);
23-
},
24-
(reason) => {
25-
console.log(reason);
26-
runDosbox(conf, conf.boxasmCommand(runOrDebug), doc).then(
27-
(stdout) => { BOXdiag(conf, diag, doc); }
28-
);
29-
}
30-
);
13+
if (!conf.customToolInfo?.hasBoxasm) { await fs.copy(src, target, { overwrite: true }); }
14+
await runDosbox(conf, conf.boxasmCommand(runOrDebug));
15+
let stdout: Uint8Array = await fs.readFile(conf.workloguri)
16+
return stdout.toString();
3117
}
3218
/**open dosbox and do things about it
3319
* @param conf The config information
3420
* @param more The commands needed to exec in dosbox
35-
* @param doc If defined, copy this file to workspace as T.xxx(xxx is the files extension)
21+
* @param doc If defined, copy this file to workspace as T.xxx(xxx is the files extension) using terminal commands
3622
*/
3723
export function runDosbox(conf: Config, more?: string, doc?: TextDocument): Promise<string> {
38-
let filename = doc?.fileName;
39-
let fileext = filename?.substring(filename.lastIndexOf("."), filename.length);
4024
let preCommand: string = "";
4125
let boxcmd: string = '@echo off\n';
42-
boxcmd += `mount c \\\"${conf.path}\\\"\nmount d \\\"${conf.workpath}\\\"\n`;//mount the necessary path
26+
boxcmd += `mount c \\\"${conf.path}\\\"\nmount d \\\"${conf.workUri.fsPath}\\\"\n`;//mount the necessary path
4327
boxcmd += "d:\nset PATH=%%PATH%%;c:\\tasm;c:\\masm\n";//switch to the working space and add path\
4428
if (doc) {
29+
let filename = doc?.fileName;
30+
let fileext = filename?.substring(filename.lastIndexOf("."), filename.length);
4531
boxcmd += `echo Your file has been copied as D:\\T${fileext}\n`;
4632
if (process.platform === 'win32') {
4733
preCommand = `del/Q T*.* & copy "${filename}" "T${fileext}" & `;
@@ -53,31 +39,58 @@ export function runDosbox(conf: Config, more?: string, doc?: TextDocument): Prom
5339
boxcmd += "@echo on";
5440
if (more) { boxcmd += "\n" + more; }//add extra commands
5541
let opt: OPTS = {
56-
cwd: conf.workpath,
42+
cwd: conf.workUri.fsPath,
5743
preOpen: preCommand,
5844
core: conf.OpenDosbox,
5945
boxcmd: boxcmd,
6046
parameter: ' -conf "' + conf.dosboxconfuri.fsPath + '" '
6147
};
6248
return openDosbox(opt);
6349
}
50+
/**
51+
* opendosbox at the Editor's file's folder
52+
* @param conf config
53+
* @param doc the doc
54+
*/
6455
export function BoxOpenCurrentFolder(conf: Config, doc: TextDocument) {
6556
let folderpath: string = Uri.joinPath(doc.uri, '../').fsPath;
6657
let opt: OPTS = {
67-
cwd: conf.workpath,
58+
cwd: conf.workUri.fsPath,
6859
core: conf.OpenDosbox,
6960
boxcmd: `mount e \\\"${folderpath}\\\"\nmount c \\\"${conf.path}\\\"\nset PATH=%%PATH%%;c:\\masm;c:\\tasm\ne:`,
7061
parameter: ' -conf "' + conf.dosboxconfuri.fsPath + '" '
7162
};
7263
openDosbox(opt);
7364
}
65+
/**
66+
* options for open dosbox
67+
*/
7468
interface OPTS {
69+
/**
70+
* the cwd of child_process
71+
*/
7572
cwd: string,
73+
/**
74+
* the core command,usually the command for open dosbox
75+
*/
7676
core: string
77+
/**
78+
* the command exec before the core command
79+
*/
7780
preOpen?: string,
81+
/**
82+
* the parameter for dosbox command
83+
*/
7884
parameter?: string,
85+
/**
86+
* the command need to exec inside dosbox
87+
*/
7988
boxcmd?: string
8089
}
90+
/**
91+
* open DOSBox through child_process
92+
* @param opt options
93+
*/
8194
function openDosbox(opt: OPTS): Promise<string> {
8295
let str = opt.core + opt.parameter;
8396
if (opt.preOpen) {
@@ -97,34 +110,28 @@ function openDosbox(opt: OPTS): Promise<string> {
97110
}
98111
return new Promise(
99112
(resolve, reject) => {
100-
exec(str, execOption, (error: any, stdout: string, stderr: string) => {
113+
let child = exec(str, execOption, (error: any, stdout: string, stderr: string) => {
101114
if (error) {
102115
reject(error);
103116
}
104117
else {
105118
resolve(stdout);
106119
}
107120
});
121+
child.on('exit', (code) => {
122+
if (code !== 0) {
123+
let msg = `Open dosbox Failed\t exitcode${code}\n`;
124+
if (process.platform !== "win32") {
125+
msg += 'PLEASE make sure DOSBox can be opened by terminal command "dosbox"';
126+
}
127+
window.showErrorMessage(msg);
128+
}
129+
130+
})
108131
}
109132
);
110133
}
111-
function BOXdiag(conf: Config, diag: AssemblerDiag, doc: TextDocument): string {
112-
let info: string = ' ', content: string;
113-
if (doc) {
114-
content = doc.getText();
115-
workspace.fs.readFile(conf.workloguri).then(
116-
(text) => {
117-
info = text.toString();
118-
if (diag.ErrMsgProcess(content, info, doc.uri, conf.MASMorTASM) === 0) {
119-
let Errmsgwindow = localize("dosbox.errmsg", '{0} Failed to compile. See the output for more information', conf.MASMorTASM);
120-
window.showErrorMessage(Errmsgwindow);
121-
}
122-
},
123-
() => { console.error('read dosbox mode T.txt FAILED'); }
124-
);
125-
}
126-
return info;
127-
}
134+
128135

129136

130137

src/configration.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface ToolInfo {
99
hasMasm: boolean,
1010
hasTasm: boolean,
1111
}
12-
const inArrays = (data: [string, FileType][], arr: [string, FileType]) => {
12+
export const inArrays = (data: [string, FileType][], arr: [string, FileType]) => {
1313
let ignoreCase = process.platform === "win32";
1414
if (ignoreCase) {
1515
return data.some(e => e[0].toLowerCase() === arr[0] && e[1] === arr[1]);
@@ -32,9 +32,6 @@ async function customToolCheck(path: string): Promise<ToolInfo> {
3232
};
3333
let dir1 = await fs.readDirectory(uri);
3434
console.log(inArrays(dir1, ["boxasm.bat", FileType.File]));
35-
if (inArrays(dir1, ["boxasm.bat", FileType.File])) {
36-
info.hasBoxasm = true;
37-
}
3835
if (inArrays(dir1, ["dosbox", FileType.Directory]) && process.platform === "win32") {
3936
let dir2 = await fs.readDirectory(Uri.joinPath(uri, './dosbox'));
4037
if (inArrays(dir2, ["dosbox.exe", FileType.File])) {
@@ -47,6 +44,7 @@ async function customToolCheck(path: string): Promise<ToolInfo> {
4744
info.hasPlayerasm = true;
4845
}
4946
}
47+
info.hasBoxasm = inArrays(dir1, ["boxasm.bat", FileType.File]);
5048
info.hasMasm = inArrays(dir1, ["masm", FileType.Directory]);
5149
info.hasTasm = inArrays(dir1, ["tasm", FileType.Directory]);
5250
console.log(dir1, info);
@@ -65,19 +63,19 @@ export class Config {
6563
private _BOXrun: string | undefined;
6664
private emulator: string | undefined;
6765
public toolsUri: Uri;
68-
private customToolInfo: ToolInfo | undefined = undefined;
69-
public readonly toolsBuiltin: boolean = false;
66+
public customToolInfo: ToolInfo | undefined = undefined;
7067
public readonly resolution: string | undefined;
7168
public readonly savefirst: boolean | undefined;
7269
public readonly MASMorTASM: string | undefined;
73-
public OpenDosbox: string;
70+
public readonly _console: string | undefined;
7471
constructor(content: ExtensionContext) {
7572
let configuration = workspace.getConfiguration('masmtasm');
7673
this.MASMorTASM = configuration.get('ASM.MASMorTASM');
7774
this.emulator = configuration.get('ASM.emulator');
7875
this.savefirst = configuration.get('ASM.savefirst');
7976
this.resolution = configuration.get('dosbox.CustomResolution');
8077
this._BOXrun = configuration.get('dosbox.run');
78+
this._console = configuration.get("dosbox.console");
8179
this._exturi = content.extensionUri;
8280
//the tools' Uri
8381
let toolpath: string | undefined = configuration.get('ASM.toolspath');
@@ -88,19 +86,25 @@ export class Config {
8886
(reason) => { console.log(reason); this.customToolInfo = undefined; }
8987
);
9088
};
89+
90+
//写dosbox配置信息
91+
this.writeBoxconfig(this);
92+
}
93+
public get OpenDosbox() {
9194
//command for open
9295
let boxUri = Uri.joinPath(this._exturi, './tools/dosbox/dosbox.exe');
9396
if (this.customToolInfo?.hasDosbox) { boxUri = Uri.joinPath(this.customToolInfo.uri, './dosbox/dosbox.exe'); }
94-
let command: string, path = '"' + boxUri.fsPath + '"';
95-
switch (configuration.get("dosbox.console")) {
96-
case "min": command = 'start/min/wait "" ' + path; break;
97-
case "noconsole": command = path + ' -noconsole'; break;
98-
case "normal":
99-
default: command = path;
97+
let command: string = "dosbox";
98+
if (process.platform === "win32") {
99+
let path = '"' + boxUri.fsPath + '"';
100+
switch (this._console) {
101+
case "min": command = 'start/min/wait "" ' + path; break;
102+
case "noconsole": command = path + ' -noconsole'; break;
103+
case "normal":
104+
default: command = path;
105+
}
100106
}
101-
this.OpenDosbox = command;
102-
//写dosbox配置信息
103-
this.writeBoxconfig(this);
107+
return command;
104108
}
105109
/**
106110
* file path of scripts packaged inside
@@ -120,9 +124,8 @@ export class Config {
120124
* file path of the separated space for DOSBox to use
121125
* which will be mounted as `D:` in dosbox
122126
*/
123-
public get workpath(): string {
124-
let path = Uri.joinPath(this._exturi, './scripts/work/').fsPath;
125-
return path;
127+
public get workUri(): Uri {
128+
return Uri.joinPath(this._exturi, './scripts/work/');
126129
}
127130
/**
128131
* file path of the compiler information in the dosbox mode

0 commit comments

Comments
 (0)