-
Notifications
You must be signed in to change notification settings - Fork 0
/
Storage.cs
75 lines (74 loc) · 2.68 KB
/
Storage.cs
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
using System;
using System.Diagnostics;
using System.IO;
namespace espjs
{
/// <summary>
/// 设备内部储存管理
/// </summary>
public class Storage
{
public static void Run(Uart uart, string port, string[] args)
{
string cmd = "list";
if (args.Length <= 1)
{
cmd = args[0];
}
else
{
cmd = args[1];
}
switch (cmd)
{
case "ll":
case "ls":
case "dir":
case "list":
uart.SendCode(port, @"(function(){var list=require('Storage').list();console.log(list.join('\n'));})();");
break;
case "free":
uart.SendCode(port, "(_=>{");
uart.SendCode(port, "mem=process.memory();");
uart.SendCode(port, "usage=mem.usage*mem.blocksize + 'B';");
uart.SendCode(port, "total=mem.total*mem.blocksize + 'B';");
uart.SendCode(port, "s=require('Storage').getFree() + 'B';");
uart.SendCode(port, "console.log('storage free: ', s);");
uart.SendCode(port, "console.log('memory used: ' + usage + '/' + total);");
uart.SendCode(port, "})();");
break;
case "clear":
uart.SendCode(port, "require('Storage').eraseAll();E.reboot();");
break;
case "delete":
case "remove":
if (args.Length <= 1)
{
Console.WriteLine("请输入Storage的名称");
return;
}
uart.SendCode(port, "require('Storage').erase('" + args[2] + "')");
break;
case "cat":
case "get":
case "read":
if (args.Length <= 1)
{
Console.WriteLine("请输入Storage的名称");
return;
}
uart.SendCode(port, "console.log(require('Storage').read('" + args[2] + "'))");
break;
case "save":
case "write":
if (args.Length <= 3)
{
Console.WriteLine("Storage的名称或内容不能为空");
return;
}
uart.SendCode(port, "require('Storage').write('" + args[2] + "','" + args[3] + "')");
break;
}
}
}
}