private void SetupIO() { var path = Path.Combine(ExplorerCore.Loader.ExplorerFolder, "Logs"); path = IOUtility.EnsureValidDirectory(path); // clean old log(s) var files = Directory.GetFiles(path); if (files.Length >= 10) { var sorted = files.ToList(); // sort by 'datetime.ToString("u")' will put the oldest ones first sorted.Sort(); for (int i = 0; i < files.Length - 9; i++) { File.Delete(files[i]); } } var fileName = $"UnityExplorer {DateTime.Now:u}.txt"; fileName = IOUtility.EnsureValidFilename(fileName); CurrentStreamPath = Path.Combine(path, fileName); File.WriteAllLines(CurrentStreamPath, Logs.Select(it => it.message).ToArray()); }
private void OnSaveTextureClicked() { if (!TextureRef) { ExplorerCore.LogWarning("Ref Texture is null, maybe it was destroyed?"); return; } if (string.IsNullOrEmpty(textureSavePathInput.Text)) { ExplorerCore.LogWarning("Save path cannot be empty!"); return; } var path = textureSavePathInput.Text; if (!path.EndsWith(".png", StringComparison.InvariantCultureIgnoreCase)) { ExplorerCore.LogWarning("Desired save path must end with '.png'!"); return; } path = IOUtility.EnsureValidDirectory(path); if (File.Exists(path)) { File.Delete(path); } var tex = TextureRef; if (!TextureUtilProvider.IsReadable(tex)) { tex = TextureUtilProvider.ForceReadTexture(tex); } byte[] data = TextureUtilProvider.Instance.EncodeToPNG(tex); File.WriteAllBytes(path, data); if (tex != TextureRef) { // cleanup temp texture if we had to force-read it. GameObject.Destroy(tex); } }
private void OnSaveFileClicked() { if (RealValue == null) { return; } if (string.IsNullOrEmpty(SaveFilePath.Text)) { ExplorerCore.LogWarning("Cannot save an empty file path!"); return; } var path = IOUtility.EnsureValidDirectory(SaveFilePath.Text); if (File.Exists(path)) { File.Delete(path); } File.WriteAllText(path, RealValue); }