/// <summary> /// 删除模块 /// </summary> /// <param name="name">模块名</param> public static void Remove(string name) { if (!Directory.Exists(moduleDir)) { Console.WriteLine("当前没有安装模块"); return; } string file = moduleDir + name + ".min.js"; if (File.Exists(file)) { if (UserConfig.Exists()) { UserConfig config = UserConfig.Load(); if (config.Modules.ContainsKey(name)) { config.Modules.Remove(name); } config.Save(); } File.Delete(file); } Console.WriteLine("模块删除成功"); }
public Upload(string workDir, Uart uart, string port) { this.workDir = workDir; this.uart = uart; this.port = port; if (UserConfig.Exists()) { this.config = UserConfig.Load(); } }
public DevMode(string workDir, Uart uart, string port) { this.workDir = workDir; this.uart = uart; this.port = port; if (UserConfig.Exists()) { hasUserConfig = true; config = UserConfig.Load(); } }
public static void Write(string port, string board) { Config systemConfig = Config.Load(); UserConfig config = new UserConfig(); if (UserConfig.Exists()) { config = UserConfig.Load(); } if (board != "") { if (systemConfig.Flash.ContainsKey(board)) { if (UserConfig.Exists()) { config.Board = board; config.Save(); } RunEspTool(port, systemConfig.Flash[board]); } else { Console.WriteLine("开发板 [" + board + "] 暂不支持烧写固件"); } } else if (UserConfig.Exists()) { if (config.Flash != "") { RunEspTool(port, config.Flash); } else if (config.Board != "") { if (systemConfig.Flash.ContainsKey(config.Board)) { RunEspTool(port, systemConfig.Flash[config.Board]); } else { Console.WriteLine("开发板 [" + config.Board + "] 暂不支持烧写固件"); } } else { Console.WriteLine("请输入开发板名称"); } } else { Console.WriteLine("请输入开发板名称"); } }
/// <summary> /// 根据用户配置安装全部模块 /// </summary> public static void Install() { if (Directory.Exists(moduleDir) == false) { Directory.CreateDirectory(moduleDir); } if (UserConfig.Exists() == false) { Console.WriteLine("用户配置文件 espjs.json 不存在."); return; } UserConfig config = UserConfig.Load(); foreach (var item in config.Modules) { Add(item.Key, item.Value); } Console.WriteLine("模块安装成功."); }
public static bool TryGetValue(string name, out string value) { value = ""; if (UserConfig.Exists() == false) { Console.WriteLine("用户配置文件 espjs.json 不存在."); return(false); } UserConfig config = UserConfig.Load(); if (config.Scripts.TryGetValue(name, out string v)) { value = v; return(true); } else { Console.WriteLine("未在 espjs.json 中定义脚本[" + name + "]."); return(false); } }
public App(bool runOnce = false) { if (Uart.HasPort()) { port = Uart.GetPort(); } this.runOnce = runOnce; if (!runOnce) { Console.WriteLine("输入help获取帮助信息"); } // 设置工作目录 this.workDir = Directory.GetCurrentDirectory(); string execFile = System.Reflection.Assembly.GetExecutingAssembly().Location; this.execDir = Directory.GetParent(execFile).FullName; // 加载基础配置 this.config = Config.Load(); uart.sp.BaudRate = this.config.BaudRate; // 加载用户配置 if (UserConfig.Exists()) { this.hasUserConfig = true; this.userConfig = UserConfig.Load(); // 设置串口参数 this.uart.sp.BaudRate = this.userConfig.BaudRate; } else { // 设置串口参数 this.uart.sp.BaudRate = config.BaudRate; } }
/// <summary> /// 添加模块 /// </summary> /// <param name="name">模块名</param> /// <param name="url">模块地址</param> /// <returns></returns> public static bool Add(string name, string url) { try { if (url == "") { url = Config.Load().Modules.Replace("[name]", name); } string code = GetWebContent(url); if (!Directory.Exists(moduleDir)) { Directory.CreateDirectory(moduleDir); } File.WriteAllText(moduleDir + name + ".min.js", code); Console.WriteLine("模块" + name + "下载完成"); if (UserConfig.Exists()) { UserConfig config = UserConfig.Load(); if (config.Modules.ContainsKey(name)) { config.Modules[name] = url; } else { config.Modules.Add(name, url); } config.Save(); } return(true); } catch (System.Net.WebException) { Console.WriteLine("模块下载失败, 请检测模块是否存在"); return(false); } }