-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathScripts.cs
More file actions
109 lines (104 loc) · 2.51 KB
/
Copy pathScripts.cs
File metadata and controls
109 lines (104 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.IO;
using AlbLib.Texts;
using AlbLib.XLD;
namespace AlbLib.Scripting
{
/// <summary>
/// Core scripting class.
/// </summary>
public static class Scripts
{
/// <summary>
/// Returns script text.
/// </summary>
/// <param name="index">
/// Zero-based script index.
/// </param>
/// <returns>
/// Script.
/// </returns>
public static string GetScript(int index)
{
int subindex, fileindex;
if(!Common.E(index, out fileindex, out subindex))return null;
string file = String.Format(Paths.ScriptsN, fileindex);
if(File.Exists(file))
{
using(FileStream stream = new FileStream(file, FileMode.Open))
{
XLDSubfile subfile = XLDFile.ReadSubfile(stream, subindex);
if(subfile == null)return String.Empty;
byte[] content = subfile.Data;
return TextCore.DefaultEncoding.GetString(content);
}
}else{
return String.Empty;
}
}
/// <summary>
/// Executes script.
/// </summary>
/// <param name="script">
/// The script text to execute.
/// </param>
/// <param name="executor">
/// Virtual machine which executes the script.
/// </param>
/// <returns>
/// True on success. False on failure.
/// </returns>
public static bool RunScript(string script, IScriptExecutor executor)
{
return executor.Execute(script);
}
/// <summary>
/// Executes script.
/// </summary>
/// <param name="index">
/// The script index to execute.
/// </param>
/// <param name="executor">
/// Virtual machine which executes the script.
/// </param>
/// <returns>
/// True on success. False on failure.
/// </returns>
public static bool RunScript(int index, IScriptExecutor executor)
{
return executor.Execute(GetScript(index));
}
/// <summary>
/// Executes script.
/// </summary>
/// <param name="script">
/// The script text to execute.
/// </param>
/// <param name="handler">
/// Delegate which is called.
/// </param>
/// <returns>
/// True on success. False on failure.
/// </returns>
public static bool RunScript(string script, ExecuteHandler handler)
{
return handler(script);
}
/// <summary>
/// Executes script.
/// </summary>
/// <param name="index">
/// The script index to execute.
/// </param>
/// <param name="handler">
/// Delegate which is called.
/// </param>
/// <returns>
/// True on success. False on failure.
/// </returns>
public static bool RunScript(int index, ExecuteHandler handler)
{
return handler(GetScript(index));
}
}
}