IEnumerator DownloadImage(string url, Image image) { Debug.Log("downloading new image:" + url.GetHashCode()); //url转换HD5作为名字 WWW www = new WWW(url); yield return(www); Texture2D tex2d = www.texture; //将图片保存至缓存路径 byte[] pngData = tex2d.EncodeToPNG(); File.WriteAllBytes(PathTools.Combine(Application.persistentDataPath, url.GetHashCode().ToString()), pngData); Sprite m_sprite = Sprite.Create(tex2d, new Rect(0, 0, tex2d.width, tex2d.height), new Vector2(0, 0)); image.sprite = m_sprite; if (this.isSetNative) { image.SetNativeSize(); } }
public IEnumerable <DirectoryEntry> Read() { FindPosition position = InitialPosition; HierarchicalRomFileTable tab = ParentFileSystem.FileTable; if (Mode.HasFlag(OpenDirectoryMode.Directories)) { while (tab.FindNextDirectory(ref position, out string name)) { yield return(new DirectoryEntry(name, PathTools.Combine(FullPath, name), DirectoryEntryType.Directory, 0)); } } if (Mode.HasFlag(OpenDirectoryMode.Files)) { while (tab.FindNextFile(ref position, out RomFileInfo info, out string name)) { yield return(new DirectoryEntry(name, PathTools.Combine(FullPath, name), DirectoryEntryType.File, info.Length)); } } }
private void ExecuteInstall(IStream io, params string[] tokens) { var id = tokens[2]; installed.TryGetValue(id, out var dto); AssertTools.True(dto == null, "Daemon {0} already installed", id); AssertTools.True(Regex.IsMatch(id, "[a-zA_Z][a-zA_Z0-9_]*"), "Invalid id {0}", id); var exe = tokens[3]; AssertTools.True(PathTools.IsChildPath(root, exe), "Invalid path {0}", exe); dto = new DaemonDto { Id = id, Path = tokens[3], Args = DaemonProcess.MakeCli(tokens, 4), }; var path = PathTools.Combine(root, dto.Path); AssertTools.True(File.Exists(path), "File {0} not found", dto.Path); Database.Save(database, dto); io.WriteLine("Daemon {0} installed as {1}", id, dto.Info("Path|Args")); ReloadDatabase(); }
static void Main(string[] args) { ProgramTools.Setup(); var config = new Config(); //args will always log to stderr because trace flag not loaded yet ExecutableTools.LogArgs(new StderrWriteLine(), args, (arg) => { ConfigTools.SetProperty(config, arg); }); AssertTools.NotEmpty(config.EndPoint, "Missing EndPoint"); AssertTools.NotEmpty(config.Root, "Missing Root"); if (!config.Daemon) { Logger.TRACE = new StderrWriteLine(); } var uri = string.Format("http://{0}/", config.EndPoint); var http = new HttpListener(); http.Prefixes.Add(uri); http.Start(); var accepter = new Runner(new Runner.Args { ThreadName = "Accepter" }); var handler = new Runner(new Runner.Args { ThreadName = "Handler" }); accepter.Run(() => { while (http.IsListening) { var ctx = http.GetContext(); handler.Run(() => { var request = ctx.Request; var response = ctx.Response; var pass = true; var file = ctx.Request.RawUrl.Substring(1); //remove leading / if (!PathTools.IsChildPath(config.Root, file)) { pass = false; } var path = PathTools.Combine(config.Root, file); Logger.Trace("File {0} {1}", file, path); if (!File.Exists(path)) { pass = false; } if (ctx.Request.HttpMethod != "GET") { pass = false; } if (pass) { var fi = new FileInfo(path); var fs = new FileStream(path, FileMode.Open, FileAccess.Read); ctx.Response.StatusCode = (int)HttpStatusCode.OK; ctx.Response.ContentLength64 = fi.Length; ctx.Response.ContentType = "application/octet-stream"; var data = new byte[1024]; var count = fs.Read(data, 0, data.Length); while (count > 0) { ctx.Response.OutputStream.Write(data, 0, count); count = fs.Read(data, 0, data.Length); } } else { ctx.Response.StatusCode = (int)HttpStatusCode.NotFound; ctx.Response.ContentLength64 = 0; } ctx.Response.Close(); }); } }); Stdio.SetStatus("Listeninig on {0}", uri); using (var disposer = new Disposer()) { disposer.Push(handler); disposer.Push(accepter); disposer.Push(http.Stop); var line = Stdio.ReadLine(); while (line != null) { line = Stdio.ReadLine(); } } Logger.Trace("Stdin closed"); Environment.Exit(0); }
/// <summary> /// Read contents of a directory /// </summary> /// <param name="uncDirectoryPath">Path of the directory</param> /// <param name="results">Select to return file, directories, or both</param> /// <param name="pattern">Search pattern. Uses Win32 native filtering.</param> /// <param name="searchOption"> /// <see cref="SearchOption" /> /// </param> /// <param name="enumerateOptions">The enumeration options for exception handling</param> /// <returns>Collection of files</returns> public static IEnumerable <FileDetail> EnumerateFiles(String uncDirectoryPath, ResultType results, String pattern = "*", SearchOption searchOption = SearchOption.TopDirectoryOnly, SuppressExceptions enumerateOptions = SuppressExceptions.None) { // Match for start of search string currentPath = PathTools.Combine(uncDirectoryPath, pattern); // Find First file var win32FindData = new Win32FindData(); int win32Error; using (var fileHandle = FindFirstFileManaged(currentPath, win32FindData, out win32Error)) { // Take care of invalid handles if (fileHandle.IsInvalid && EnumerationHandleInvalidFileHandle(uncDirectoryPath, enumerateOptions, win32Error)) { yield return(null); } // evaluate results do { // Ignore . and .. directories if (IsSystemDirectoryEntry(win32FindData)) { continue; } // Create hit for current search result var resultPath = PathTools.Combine(uncDirectoryPath, win32FindData.cFileName); // Check for Directory if (ContainsFileAttribute(win32FindData.dwFileAttributes, FileAttributes.Directory)) { if (results == ResultType.DirectoriesOnly || results == ResultType.FilesAndDirectories) { yield return(new FileDetail(resultPath, win32FindData)); } // SubFolders? if (searchOption == SearchOption.AllDirectories) { // check for sym link (always ignored in this copy) if (SymbolicLink.IsSymLink(win32FindData)) { continue; } foreach (var match in EnumerateFiles(resultPath, results, pattern, searchOption, enumerateOptions)) { yield return(match); } } } else { if (results == ResultType.FilesOnly || results == ResultType.FilesAndDirectories) { yield return(new FileDetail(resultPath, win32FindData)); } } // Create new FindData object for next result win32FindData = new Win32FindData(); } // Search for next entry while (Win32SafeNativeMethods.FindNextFile(fileHandle, win32FindData)); } }
/// <summary> /// Search Exection /// </summary> /// <param name="uncDirectoryPath">Start directory path</param> /// <param name="pattern">Search pattern. Uses Win32 native filtering.</param> /// <param name="searchOption"> /// <see cref="SearchOption" /> /// </param> /// <param name="enumerateOptions">The enumeration options for exception handling</param> /// <param name="pathFormatReturn">Specifies the type of path to return.</param> /// <param name="filterType"> /// <see cref="FileOrDirectory" /> /// </param> /// <returns>Collection of path</returns> static IEnumerable <String> FindPaths(String uncDirectoryPath, String pattern = "*", SearchOption searchOption = SearchOption.TopDirectoryOnly, FileOrDirectory?filterType = null, SuppressExceptions enumerateOptions = SuppressExceptions.None, UncOrRegular pathFormatReturn = UncOrRegular.Regular) { // Result Container var results = new List <String>(); // Match for start of search string currentPath = PathTools.Combine(uncDirectoryPath, pattern); // Find First file var win32FindData = new Win32FindData(); int win32Error; using (var fileHandle = FindFirstSafeFileHandle(currentPath, win32FindData, out win32Error)) { // Take care of invalid handles if (fileHandle.IsInvalid && EnumerationHandleInvalidFileHandle(uncDirectoryPath, enumerateOptions, win32Error)) { return(new List <String>()); } do { // Ignore . and .. directories if (IsSystemDirectoryEntry(win32FindData)) { continue; } // Create hit for current search result string resultPath = PathTools.Combine(uncDirectoryPath, win32FindData.cFileName); // if it's a file, add to the collection if (!ContainsFileAttribute(win32FindData.dwFileAttributes, FileAttributes.Directory)) { if (filterType == null || ((FileOrDirectory)filterType == FileOrDirectory.File)) { // It's a file results.Add(FormatPathByType(pathFormatReturn, resultPath)); } } else { // It's a directory // Check for search searchFocus directories if (filterType != null && ((FileOrDirectory)filterType == FileOrDirectory.Directory)) { results.Add(FormatPathByType(pathFormatReturn, resultPath)); } // SubFolders?! if (searchOption == SearchOption.AllDirectories) { var r = new List <String>(FindPaths(resultPath, pattern, searchOption, filterType, enumerateOptions)); if (r.Count > 0) { results.AddRange(r); } } } // Create new FindData object for next result win32FindData = new Win32FindData(); } // Search for next entry while (Win32SafeNativeMethods.FindNextFile(fileHandle, win32FindData)); } // Return result; return(results); }
/// <summary> /// Checks to see if a directory specified relative to the Unity data dir is included in the path so far. /// It checks using both forward-slashed and backslashed versions of the Unity data dir. /// </summary> /// <param name="relativePortion">Directory relative to the Unity data dir</param> /// <returns>true if the given directory is included in the path so far</returns> private bool IsRelativeDirIncludedInPath(string relativePortion) { return(IsIncludedInPath(PathTools.Combine(UnityDataDir, relativePortion)) || IsIncludedInPath(PathTools.Combine(UnityDataDirBackslashed, relativePortion))); }
/// <summary> /// If a directory specified relative to the Unity data dir is not yet in the PATH, add it. /// </summary> /// <param name="dirComponents">Components of a directory name relative to the Unity data dir.</param> private void ConditionallyAddRelativeDir(List <string> dirComponents) { ConditionallyAddRelativeDir(PathTools.Combine(dirComponents)); }
internal static string Combine(List <String> components) { return(PathTools.Combine(components.ToArray())); }
/// <summary> /// 初始化 /// </summary> static public void Init() { SetPath(); string md5filelist = "md5filelist.txt"; string dataPath = assetsUpdatePath; //Util.DataPath; //数据目录 string resPath = PathTools.AppContentPath(); //Util.AppContentPath(); //游戏包资源目录 string localMD5BakFilePath = PathTools.Combine(dataPath, "/md5filelist.txt.bak"); string infile = PathTools.Combine(resPath, "md5filelist.txt"); string outfile = PathTools.Combine(dataPath, "md5filelist.txt"); Debug.Log(infile); if (PathTools.ExistsPersistentPath("md5filelist.txt")) { Debug.LogWarning("非首次启动!"); } else { Debug.LogWarning("首次启动!"); if (!Directory.Exists(dataPath)) { Directory.CreateDirectory(dataPath); } Debug.LogErrorFormat("localMD5BakFilePath {0} {1}", localMD5BakFilePath, File.Exists(localMD5BakFilePath)); if (File.Exists(localMD5BakFilePath)) { Debug.LogErrorFormat("本地列表文件 bak 存在!{0}", localMD5BakFilePath); File.Delete(localMD5BakFilePath); } if (File.Exists(localMD5BakFilePath)) { Debug.LogErrorFormat("本地列表文件 bak 删除成功!{0}", localMD5BakFilePath); } string message = "正在解包文件:>md5filelist.txt"; if (Application.platform == RuntimePlatform.Android) { WWW www = new WWW(infile); while (true) { if (www.isDone || !string.IsNullOrEmpty(www.error)) { System.Threading.Thread.Sleep(50); if (!string.IsNullOrEmpty(www.error)) { Debug.LogError(www.error); } else { File.WriteAllBytes(outfile, www.bytes); Debug.LogWarning(">>" + outfile); } break; } } } else { File.Copy(infile, outfile, true); } } string path = PathTools.Combine(PathTools.PersistentDataPath(), md5filelist); Debug.LogWarningFormat("热更新步骤 1 【初始化拷贝】完成!{0} {1}", path, System.IO.File.Exists(path)); }