/// <summary> /// 扫描路径path的媒体文件,将它加入媒体库中;或者如果该文件以及被删除,则通知媒体库移除该文件。 /// 媒体库包括相册、音乐库等,因此该函数可以用于把某个图片文件加入相册。 /// </summary> /// <param name="path">媒体文件路径</param> public void scanFile(string path) { var mimeType = MimeTypes.FromFileOr(path, null); var p = PFiles.Path(path); _scannerConnection.ScanFile(p, mimeType); }
/// <summary> /// 读取在路径path的图片文件并返回一个Image对象。如果文件不存在或者文件无法解码则返回null。 /// </summary> /// <param name="path">图片路径</param> /// <returns></returns> public ImageWrapper read(string path) { path = PFiles.Path(path); var bitmap = BitmapFactory.DecodeFile(path); return(ImageWrapper.OfBitmap(bitmap)); }
/// <summary> /// 读取文本文件path的所有内容并返回。如果文件不存在,则抛出FileNotFoundException。 /// </summary> /// <param name="path">路径</param> /// <param name="encoding">字符编码,可选,默认为utf-8</param> /// <returns></returns> public string read(string path, string encoding = "") { var p = this.path(path); if (string.IsNullOrWhiteSpace(encoding)) { return(PFiles.Read(p)); } return(PFiles.Read(p, encoding)); }
/// <summary> /// 把text写入到文件path中。如果文件存在则覆盖,不存在则创建。 /// </summary> /// <param name="path">路径</param> /// <param name="text">要写入的文本内容</param> /// <param name="encoding">字符编码</param> public void write(string path, string text, string encoding = "") { var p = this.path(path); if (string.IsNullOrWhiteSpace(encoding)) { PFiles.Write(p, text); } else { PFiles.Write(p, text, encoding); } }
/// <summary> /// 把text追加到文件path的末尾。如果文件不存在则创建。 /// </summary> /// <param name="path">路径</param> /// <param name="text">要写入的文本内容</param> /// <param name="encoding">字符编码</param> public void append(string path, string text, string encoding) { var p = this.path(path); if (string.IsNullOrWhiteSpace(encoding)) { PFiles.Append(p, text); } else { PFiles.Append(p, text, encoding); } }
/// <summary> /// 把图片image以PNG格式保存到path中。如果文件不存在会被创建;文件存在会被覆盖。 /// </summary> /// <param name="image">图片</param> /// <param name="path">路径</param> /// <param name="format">图片格式,可选的值为:png,jpeg/jpg,webp</param> /// <param name="quality">图片质量,为0~100的整数值</param> /// <returns></returns> /// <exception cref="Exception"></exception> public bool save(ImageWrapper image, string path, string format, int quality) { var compressFormat = ParseImageFormat(format); if (compressFormat == null) { throw new Exception("unknown format " + format); } var outputStream = new FileStream(PFiles.Path(path), FileMode.CreateNew); return(image.Bitmap.Compress(compressFormat, quality, outputStream)); }
/// <summary> /// 播放音乐文件path。该函数不会显示任何音乐播放界面。如果文件不存在或者文件不是受支持的音乐格式,则抛出UncheckedIOException异常。 /// </summary> /// <param name="path">音乐文件路径。</param> /// <param name="volume">播放音量,为0~1的浮点数,默认为1</param> /// <param name="looping">是否循环播放,如果looping为true则循环播放,默认为false。</param> /// <exception cref="LuaException"></exception> public void playMusic(string path, float volume = 1.0f, bool looping = false) { path = PFiles.Path(path); if (_mediaPlayer == null) { _mediaPlayer = new MediaPlayerWrapper(); } _mediaPlayer.StopAndReset(); try { _mediaPlayer.SetDataSource(path); _mediaPlayer.SetVolume(volume, volume); _mediaPlayer.Looping = looping; _mediaPlayer.Prepare(); } catch (Exception e) { throw new LuaException(e.Message); } _mediaPlayer.Start(); }
/// <summary> /// 列出文件夹path下的满足条件的文件和文件夹的名称的数组。如果不加filter参数,则返回所有文件和文件夹。 /// </summary> /// <param name="path"></param> /// <returns></returns> public string[] listDir(string path, Action <string> action = null) { return(PFiles.ListDir(this.path(path))); }
/// <summary> /// 返回相对路径对应的绝对路径。例如files.path("./1.png"),如果运行这个语句的脚本位于文件夹"/sdcard/脚本/"中,则返回"/sdcard/脚本/1.png"。 /// </summary> /// <param name="relativePath">相对路径</param> /// <returns></returns> public string path(string relativePath) { return(PFiles.path(relativePath)); }
/// <summary> /// 删除文件夹,如果文件夹不为空,则删除该文件夹的所有内容再删除该文件夹,返回是否全部删除成功。 /// </summary> /// <param name="path">路径</param> /// <returns></returns> public bool removeDir(string path) { return(PFiles.RemoveDir(this.path(path))); }
/// <summary> /// 返回SD卡路径。所谓SD卡,即外部存储器。 /// </summary> /// <returns></returns> public string getSdcardPath() { return(PFiles.GetSdcardPath()); }
/// <summary> /// 确保路径path所在的文件夹存在。如果该路径所在文件夹不存在,则创建该文件夹。 /// 例如对于路径"/sdcard/Download/ABC/1.txt",如果/Download/文件夹不存在,则会先创建Download,再创建ABC文件夹。 /// </summary> /// <param name="path">路径</param> /// <returns></returns> public bool ensureDir(string path) { var p = this.path(path); return(PFiles.EnsureDir(p)); }
/// <summary> /// 把bytes追加到文件path的末尾。如果文件不存在则创建。 /// </summary> /// <param name="path">路径</param> /// <param name="bytes">字节数组,要写入的二进制数据</param> public void appendBytes(string path, byte[] bytes) { var p = this.path(path); PFiles.AppendBytes(p, bytes); }
/// <summary> /// 读取文件path的所有内容并返回一个字节数组。如果文件不存在,则抛出FileNotFoundException。 /// </summary> /// <param name="path">路径</param> /// <returns></returns> public byte[] readBytes(string path) { var p = this.path(path); return(PFiles.ReadBytes(p)); }
/// <summary> /// 返回在路径path处的文件是否存在。 /// </summary> /// <param name="path">路径</param> /// <returns></returns> public bool exists(string path) { var p = this.path(path); return(PFiles.Exists(p)); }
/// <summary> /// 重命名文件,并返回是否重命名成功。例如files.rename("/sdcard/1.txt", "2.txt")。 /// </summary> /// <param name="pathFrom">要重命名的原文件路径</param> /// <param name="newName">要重命名的新文件名</param> /// <returns></returns> public bool rename(string pathFrom, string newName) { return(PFiles.Rename(path(pathFrom), newName)); }
/// <summary> /// 重命名文件,不包含拓展名,并返回是否重命名成功。例如files.rename("/sdcard/1.txt", "2")会把"1.txt"重命名为"2.txt"。 /// </summary> /// <param name="pathFrom">要重命名的原文件路径</param> /// <param name="newName">要重命名的新文件名</param> /// <returns></returns> public bool renameWithoutExtension(string pathFrom, string newName) { return(PFiles.RenameWithoutExtension(path(pathFrom), newName)); }
/// <summary> /// 返回路径path是否是文件。 /// </summary> /// <param name="path">路径</param> /// <returns>是否是文件</returns> public bool isFile(string path) { return(PFiles.IsFile(path)); }
/// <summary> /// 移动文件,返回是否移动成功。例如files.move("/sdcard/1.txt", "/sdcard/Download/1.txt")会把1.txt文件从sd卡根目录移动到Download文件夹。 /// </summary> /// <param name="pathFrom">要移动的原文件路径</param> /// <param name="newPath">移动到的文件路径</param> /// <returns></returns> public bool move(string pathFrom, string newPath) { return(PFiles.Move(path(pathFrom), newPath)); }
/// <summary> /// 复制文件,返回是否复制成功。例如files.copy("/sdcard/1.txt", "/sdcard/Download/1.txt")。 /// </summary> /// <param name="pathFrom">要复制的原文件路径</param> /// <param name="pathTo">复制到的文件路径</param> /// <returns></returns> public bool copy(string pathFrom, string pathTo) { return(PFiles.Copy(path(pathFrom), path(pathTo))); }
/// <summary> /// 返回路径path是否是文件夹。 /// </summary> /// <param name="path">路径</param> /// <returns>是否是文件夹</returns> public bool isDir(string path) { return(PFiles.IsDir(path)); }
public void MainPrompt() { bool quitflag = false; while ((!quitflag) && _bbs.Connected) { if (!_bbs.DND_Override) { _bbs.DoNotDisturb = false; } //Show Main Prompt if (!_bbs.ExpertMode) { if (_bbs.TerminalType.Columns() == 40) { _bbs.WriteLine("~l2~c7? ~c1Menu~c2,~c7H~c1elp~c2,~c7B~c1ases~c2,~c7G~c1Files~c2,~c7P~c1Files~c2,~c7Q~c1uit"); } else { _bbs.WriteLine("~l2~c7? ~c1Help~c2, ~c7B~c1ases~c2, ~c7U~c1DBases~c2, ~c7G~c1Files~c2, ~c7P~c1Files~c2, ~c7Q~c1uit"); } } else { _bbs.WriteLine(); } _bbs.CurrentArea = "Main Prompt"; _bbs.Write("~c1Main~c2:~c7"); string command = _bbs.Input(true, false, false, true, 10); if (command.Length > 0) { switch (command.ToString().ToUpper()) { case "?": _bbs.SendFileForTermType("MainMenu", true); break; case "B": MessageBases mb = new MessageBases(_bbs, _dataInterface); mb.Prompt(); break; case "DND": CMD_DND(); break; case "F": CMD_Feedback(); break; case "G": try { GFiles gf = new GFiles(_bbs, _dataInterface); gf.Prompt(); } catch (Exception e) { LoggingAPI.LogEntry("Exception in Main.MainPrompt: " + e); //Log this? } break; case "P": try { PFiles pf = new PFiles(_bbs, _dataInterface); pf.Prompt(); } catch (Exception e) { LoggingAPI.LogEntry("Exception in Main.MainPrompt: " + e); //Log this? } break; case "Q!": quitflag = true; break; case "Q": CMD_Feedback(); _bbs.Write("~l1~c1Leave one-liner?"); if (_bbs.YesNo(true, true)) { _bbs.Gw.AddLine(_bbs.CurrentUser.UserId); } quitflag = true; break; case "SY": if (_dataInterface.GetAccessGroup(_bbs.CurrentUser.AccessLevel).Is_SysOp) { _bbs.Write("~l1~c1Password:~c7"); string sy = _bbs.Input(true, true, false); if (sy.ToUpper() == _bbsConfig.SysopMenuPass.ToUpper()) { _bbs.Sysop_Identified = true; SysOp sys = new SysOp(_bbs, _dataInterface); sys.Prompt(); } else { _bbs.WriteLine("~l1~d2Invalid password. F**k off.~d0~c1"); } } else { _bbs.WriteLine("~l1~d2Unknown command.~d0~c1"); } break; case "UD": case "U": UDBases ud = new UDBases(_bbs, _dataInterface); ud.Prompt(); //break; //UDBases ud = new UDBases(bbs); //ud.Prompt(); break; case "WHO": CMD_Who(); break; case "X": _bbs.ExpertMode = !_bbs.ExpertMode; _bbs.WriteLine("~l1~c1Expert mode is ~c7" + (_bbs.ExpertMode ? "ON" : "OFF") + "~c1."); break; default: //Test multi-part commands if (command.Length > 3 && command.Substring(0, 3).ToUpper() == "OLM") { CMD_OLM(command); } else if (command.Length > 3 && command.Substring(0, 3).ToUpper() == "SLM") { CMD_SLM(command); } else { if (_bbs.Sysop_Identified) { CMD_SysOp(command); } else { _bbs.WriteLine("~l1~d2Unknown command.~d0~c1"); } } break; } } if ((!quitflag) && (!_bbs.DoNotDisturb)) { //Show any received OLMs _bbs.FlushOLMQueue(); } } }
/// <summary> /// 创建一个文件或文件夹并返回是否创建成功。如果文件所在文件夹不存在,则先创建他所在的一系列文件夹。如果文件已经存在,则直接返回false。 /// </summary> /// <param name="path">路径</param> /// <returns></returns> public bool createWithDirs(string path) { var p = this.path(path); return(PFiles.CreateWithDirs(p)); }
/// <summary> /// 返回文件的拓展名。例如files.getExtension("/sdcard/1.txt")返回"txt"。 /// </summary> /// <param name="fileName">路径</param> /// <returns></returns> public string getExtension(string fileName) { return(PFiles.GetExtension(fileName)); }
public static string FromFile(string path) { var ext = PFiles.GetExtension(path); return(string.IsNullOrWhiteSpace(ext) ? "*/*" : MimeTypeMap.Singleton.GetMimeTypeFromExtension(ext)); }
/// <summary> /// 删除文件或空文件夹,返回是否删除成功。 /// </summary> /// <param name="path"></param> /// <returns></returns> public bool remove(string path) { return(PFiles.Remove(path)); }
/// <summary> /// 返回文件的文件名。例如files.getName("/sdcard/1.txt")返回"1.txt"。 /// </summary> /// <param name="filePath">路径</param> /// <returns></returns> public string getName(string filePath) { return(PFiles.GetName(filePath)); }
/// <summary> /// 把bytes写入到文件path中。如果文件存在则覆盖,不存在则创建。 /// </summary> /// <param name="path">路径</param> /// <param name="bytes">字节数组,要写入的二进制数据</param> public void writeBytes(string path, byte[] bytes) { var p = this.path(path); PFiles.WriteBytes(p, bytes); }
/// <summary> /// 返回不含拓展名的文件的文件名。例如files.getName("/sdcard/1.txt")返回"1"。 /// </summary> /// <param name="filePath">路径</param> /// <returns></returns> public string getNameWithoutExtension(string filePath) { return(PFiles.GetNameWithoutExtension(filePath)); }
/// <summary> /// 列出文件夹path下的满足条件的文件和文件夹的名称的数组。如果不加filter参数,则返回所有文件和文件夹。 /// </summary> /// <param name="path"></param> /// <returns></returns> public string[] listDir(string path) { return(PFiles.ListDir(this.path(path))); }