Skip to content

Commit 3a94fc5

Browse files
committed
try to make the extension usable in darwin OSusing command open -a DOSBox and offer a configration to change this
1 parent 052ab7a commit 3a94fc5

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

package.json

Lines changed: 5 additions & 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.4-alpha.1",
6+
"version": "0.5.4-alpha.2",
77
"keywords": [
88
"dosbox",
99
"16位",
@@ -170,6 +170,10 @@
170170
"%dosasm.config.boxrun.enum3%"
171171
]
172172
},
173+
"masmtasm.dosbox.command": {
174+
"type": "string",
175+
"description": "If defined the extension will use this command to open dosbox instead of default command"
176+
},
173177
"masmtasm.dosbox.console": {
174178
"type": "string",
175179
"default": "min",

src/DOSBox.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export async function runDosbox2(conf: Config, runOrDebug: boolean): Promise<str
1212
let target: Uri = Uri.joinPath(conf.toolsUri, "./boxasm.bat");
1313
if (!conf.customToolInfo?.hasBoxasm) { await fs.copy(src, target, { overwrite: true }); }
1414
await runDosbox(conf, conf.boxasmCommand(runOrDebug));
15-
let stdout: Uint8Array = await fs.readFile(conf.workloguri)
15+
let stdout: Uint8Array = await fs.readFile(conf.workloguri);
1616
return stdout.toString();
1717
}
1818
/**open dosbox and do things about it
@@ -121,9 +121,7 @@ function openDosbox(opt: OPTS): Promise<string> {
121121
child.on('exit', (code) => {
122122
if (code !== 0) {
123123
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-
}
124+
msg += 'PLEASE make sure DOSBox can be opened by terminal command \n' + str;
127125
window.showErrorMessage(msg);
128126
}
129127
})

src/configration.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,18 @@ function writefile(Uri: Uri, Content: string) {
5858
* class for configurations
5959
*/
6060
export class Config {
61-
private readonly _toolspackaged: boolean = true;//如果打包时没有包含汇编工具(tools)改为false 废弃
62-
private readonly _exturi: Uri;
63-
private _BOXrun: string | undefined;
64-
private emulator: string | undefined;
6561
public toolsUri: Uri;
6662
public customToolInfo: ToolInfo | undefined = undefined;
67-
public readonly resolution: string | undefined;
6863
public readonly savefirst: boolean | undefined;
6964
public readonly MASMorTASM: string | undefined;
70-
public readonly _console: string | undefined;
65+
//
66+
private readonly _toolspackaged: boolean = true;//如果打包时没有包含汇编工具(tools)改为false 废弃
67+
private readonly _exturi: Uri;
68+
private readonly _BOXrun: string | undefined;
69+
private readonly emulator: string | undefined;
70+
private readonly resolution: string | undefined;
71+
private readonly _console: string | undefined;
72+
private readonly _command: string | undefined;
7173
constructor(content: ExtensionContext) {
7274
let configuration = workspace.getConfiguration('masmtasm');
7375
this.MASMorTASM = configuration.get('ASM.MASMorTASM');
@@ -76,6 +78,7 @@ export class Config {
7678
this.resolution = configuration.get('dosbox.CustomResolution');
7779
this._BOXrun = configuration.get('dosbox.run');
7880
this._console = configuration.get("dosbox.console");
81+
this._command = configuration.get("dosbox.command");
7982
this._exturi = content.extensionUri;
8083
//the tools' Uri
8184
let toolpath: string | undefined = configuration.get('ASM.toolspath');
@@ -92,12 +95,20 @@ export class Config {
9295
//写dosbox配置信息
9396
this.writeBoxconfig();
9497
}
98+
/**
99+
* @returns a string can be send to terminal, to open dosbox according to different system and configration
100+
*/
95101
public get OpenDosbox() {
96-
//command for open
97-
let boxUri = Uri.joinPath(this._exturi, './tools/dosbox/dosbox.exe');
98-
if (this.customToolInfo?.hasDosbox) { boxUri = Uri.joinPath(this.customToolInfo.uri, './dosbox/dosbox.exe'); }
102+
//command for open dosbox
99103
let command: string = "dosbox";
104+
//First, use the user-defined command;
105+
if (this._command) {
106+
return this._command + " ";
107+
}
108+
//for windows,using different command according to dosbox's path and the choice of the console window
100109
if (process.platform === "win32") {
110+
let boxUri = Uri.joinPath(this._exturi, './tools/dosbox/dosbox.exe');
111+
if (this.customToolInfo?.hasDosbox) { boxUri = Uri.joinPath(this.customToolInfo.uri, './dosbox/dosbox.exe'); }
101112
let path = '"' + boxUri.fsPath + '"';
102113
switch (this._console) {
103114
case "min": command = 'start/min/wait "" ' + path; break;
@@ -106,10 +117,15 @@ export class Config {
106117
default: command = path;
107118
}
108119
}
120+
//for darwin
121+
else if (process.platform === "darwin") {
122+
command = "open -a DOSBox --args ";
123+
}
124+
//for other system, temporarily use command `dosbox`
109125
return command;
110126
}
111127
/**
112-
* file path of scripts packaged inside
128+
* @return Uri of scripts packaged inside
113129
*/
114130
public get extScriptsUri(): Uri {
115131
let path = Uri.joinPath(this._exturi, './scripts');

0 commit comments

Comments
 (0)