public bool WriteFile(string path, byte[] bytes) { if (bytes == null) { return(false); } try { string dir = Path.GetDirectoryName(path); if (Directory.Exists(dir) == false) { Directory.CreateDirectory(dir); } if (File.Exists(path)) { File.Delete(path); } //File.WriteAllBytes(path, bytes); using (FileStream stream = new FileStream(path, FileMode.Create)) { stream.Write(bytes, 0, bytes.Length); stream.Flush(); stream.Close(); stream.Dispose(); } ZLog.Warning("write file success!!!!" + dir + "---" + path); return(true); } catch (Exception e) { ZLog.Exception(e); return(false); } }
public string ReadText(string path) { try { if (File.Exists(path) == false) { return(""); } return(File.ReadAllText(path)); } catch (Exception e) { ZLog.Exception(e); return(""); } }
public Texture2D ReadTexture(string path, Vector2 size) { try { if (File.Exists(path) == false) { return(null); } byte[] bytes = File.ReadAllBytes(path); Texture2D texture = new Texture2D((int)size.x, (int)size.y); texture.LoadImage(bytes); return(texture); } catch (Exception e) { ZLog.Exception(e); return(null); } }
public bool WriteText(string path, string txt) { try { string dir = Path.GetDirectoryName(path); if (Directory.Exists(dir) == false) { Directory.CreateDirectory(dir); } if (File.Exists(path)) { File.Delete(path); } File.WriteAllText(path, txt); return(true); } catch (Exception e) { ZLog.Exception(e); } return(false); }
public static string GetEXEFile(string directory) { try { if (Directory.Exists(directory) == false) { return(""); } string[] files = Directory.GetFiles(directory, "*.exe"); if (files != null && files.Length > 0) { return(files[0]); } else { string[] directores = Directory.GetDirectories(directory); if (directores != null && directores.Length > 0) { for (int i = 0; i < directores.Length; i++) { string path = GetEXEFile(directores[i]); if (!string.IsNullOrEmpty(path)) { return(path); } } } return(""); } } catch (Exception e) { ZLog.Exception(e); return(""); } }