From 9242275aec4325a8e691abe496ea09053e496317 Mon Sep 17 00:00:00 2001 From: otya128 Date: Mon, 5 Dec 2016 21:28:25 +0900 Subject: [PATCH] Add RESULT system variable --- SMILEBASIC/builtinfunctions.d | 20 +++++++++++++++----- SMILEBASIC/compiler.d | 1 + SMILEBASIC/project.d | 20 ++++++++++++++++++++ SMILEBASIC/systemvariable.d | 8 ++++++++ 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/SMILEBASIC/builtinfunctions.d b/SMILEBASIC/builtinfunctions.d index 92e6f08..60f0063 100644 --- a/SMILEBASIC/builtinfunctions.d +++ b/SMILEBASIC/builtinfunctions.d @@ -1457,7 +1457,11 @@ class BuiltinFunction wstring resname = type[0]; wstring projectname = type[1]; wstring filename = type[2]; - if(projectname != "" && projectname != "SYS") + if (!Projects.isValidFileName(filename)) + { + throw new IllegalFunctionCall("LOAD"); + } + if(projectname != "" && projectname.toUpper != "SYS") { throw new IllegalFunctionCall("LOAD"); } @@ -1471,7 +1475,8 @@ class BuiltinFunction { return Value(txt); } - throw new IllegalFunctionCall("LOAD"); + //not exist + return Value(""); } throw new IllegalFunctionCall("LOAD"); } @@ -1482,10 +1487,14 @@ class BuiltinFunction flag.setDefaultValue(0); auto type = Projects.splitResourceName(name); wstring txt; - wstring resname = type[0]; + wstring resname = type[0].toUpper; wstring projectname = type[1]; wstring filename = type[2]; - if(projectname != "" && projectname != "SYS") + if (!Projects.isValidFileName(filename)) + { + throw new IllegalFunctionCall("LOAD"); + } + if(projectname != "" && projectname.toUpper != "SYS") { throw new IllegalFunctionCall("LOAD"); } @@ -1503,7 +1512,8 @@ class BuiltinFunction } if(!p.project.loadFile(projectname, "TXT", filename, txt)) { - throw new IllegalFunctionCall("LOAD"); + //not exist + return; } p.slot[lot].load(txt); return; diff --git a/SMILEBASIC/compiler.d b/SMILEBASIC/compiler.d index beae89e..1f5aaa8 100644 --- a/SMILEBASIC/compiler.d +++ b/SMILEBASIC/compiler.d @@ -226,6 +226,7 @@ class Compiler addSystemVariable("VERSION", new Version()); addSystemVariable("FREEMEM", new FreeMem()); addSystemVariable("TABSTEP", new TabStep()); + addSystemVariable("RESULT", new Result()); } void addSystemVariable(wstring name, SystemVariable var) { diff --git a/SMILEBASIC/project.d b/SMILEBASIC/project.d index ef70adb..b9bf8af 100644 --- a/SMILEBASIC/project.d +++ b/SMILEBASIC/project.d @@ -8,11 +8,19 @@ import std.conv; import std.uni; import std.typecons; import std.range; +enum DialogResult +{ + FAILURE = 0, + SUCCESS = 1, + CANCEL = -1, +} + class Projects { wstring rootPath; wstring projectPath; string projectPathU8; + DialogResult result = DialogResult.FAILURE;//Default value this(wstring root) { rootPath = root; @@ -130,10 +138,14 @@ class Projects bool loadFile(wstring project, wstring type, wstring name, out wstring contents) { contents = ""; + result = DialogResult.FAILURE; if(!isValidProjectName(project)) { return false; } + type = type.toUpper; + //TODO:case-sensitive filesystem... + name = name.toUpper; if(project == "") project = "[DEFAULT]"; if(type != "TXT" && type != "DAT") { @@ -144,6 +156,14 @@ class Projects return false; } auto path = buildPath(projectPath, project, type, name).to!string; + if (!path.exists) + { + //show dialog + return false; + } + + //show dialog + result = DialogResult.SUCCESS; contents = readText(path).to!wstring; return true; } diff --git a/SMILEBASIC/systemvariable.d b/SMILEBASIC/systemvariable.d index 1d64fbd..35f6fa9 100644 --- a/SMILEBASIC/systemvariable.d +++ b/SMILEBASIC/systemvariable.d @@ -108,3 +108,11 @@ class FreeMem : SystemVariable return Value(8327164); } } +class Result : SystemVariable +{ + @property + override Value value() + { + return Value(vm.petitcomputer.project.result); + } +}