| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System.IO;
- using SFB;
- public class FileToolkit
- {
- public static ExtensionFilter extensionFilter = new ExtensionFilter("图像/视频文件", "wmv", "mp4", "avi", "mov", "WMV", "MP4", "AVI", "MOV", "jpg", "png", "JPG", "PNG", "jpeg", "JPEG");
- public static List<ExtensionFilter> GetExtensionFilters()
- {
- List<ExtensionFilter> extensionFilters = new List<ExtensionFilter>();
- extensionFilters.Add(extensionFilter);
- return extensionFilters;
- }
- /// <summary>
- /// 读取本地数据并保存到指定位置
- /// </summary>
- /// <param name="fliePath"></param>
- /// <param name="targetFilePath"></param>
- public static void ReadLocalFileDataAndSaveToTargetPath(string fliePath, string targetFilePath)
- {
- byte[] buffer = GetLoaclFileData(fliePath);
- FileLocalSave(targetFilePath,buffer);
- }
- /// <summary>
- /// 获取本地文件数据
- /// </summary>
- /// <param name="filePath"></param>
- /// <returns></returns>
- public static byte[] GetLoaclFileData(string filePath)
- {
- using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate))
- {
- byte[] buffer = new byte[fs.Length];
- fs.Read(buffer, 0, buffer.Length);
- fs.Close();
- return buffer;
- }
- }
- /// <summary>
- /// 文件本地保存
- /// </summary>
- public static void FileLocalSave(string savePath,byte[] data)
- {
- Debug.Log(data.Length);
- using (FileStream fs = new FileStream(savePath,FileMode.OpenOrCreate,FileAccess.ReadWrite))
- {
- fs.Write(data, 0, data.Length);
- fs.Flush();
- }
- }
- /// <summary>
- /// 删除本地文件
- /// </summary>
- public static void DeleteLocalFile(string filePath)
- {
- if (File.Exists(filePath)) File.Delete(filePath);
- }
- /// <summary>
- /// 本地是否包含文件
- /// </summary>
- public static bool LoaclIsContainFile(string filePath)
- {
- return File.Exists(filePath);
- }
- /// <summary>
- /// 通过WinForm获取上传文件路径
- /// </summary>
- /// <param name="extensions"></param>
- /// <returns></returns>
- public static string[] GetAssetPathsByWinForm(List<ExtensionFilter> extensions)
- {
- string[] paths = StandaloneFileBrowser.OpenFilePanel(" 上传文件", "", extensions.ToArray(), true);
- return paths;
- }
- }
|