public void OnSaveClipClicked() { if (!RefAudioClip) { ExplorerCore.LogWarning("AudioClip is null, maybe it was destroyed?"); return; } if (string.IsNullOrEmpty(savePathInput.Text)) { ExplorerCore.LogWarning("Save path cannot be empty!"); return; } string path = savePathInput.Text; if (!path.EndsWith(".wav", StringComparison.InvariantCultureIgnoreCase)) { path += ".wav"; } path = IOUtility.EnsureValidFilePath(path); if (File.Exists(path)) { File.Delete(path); } SavWav.Save(RefAudioClip, path); }
private void SetupIO() { var fileName = $"UnityExplorer {DateTime.Now:u}.txt"; fileName = IOUtility.EnsureValidFilename(fileName); var path = Path.Combine(ExplorerCore.Loader.ExplorerFolder, "Logs"); CurrentStreamPath = IOUtility.EnsureValidFilePath(Path.Combine(path, fileName)); // 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]); } } File.WriteAllLines(CurrentStreamPath, Logs.Select(it => it.message).ToArray()); }
private void OnSaveTextureClicked() { if (!TextureRef) { ExplorerCore.LogWarning("Texture is null, maybe it was destroyed?"); return; } if (string.IsNullOrEmpty(savePathInput.Text)) { ExplorerCore.LogWarning("Save path cannot be empty!"); return; } string path = savePathInput.Text; if (!path.EndsWith(".png", StringComparison.InvariantCultureIgnoreCase)) { path += ".png"; } path = IOUtility.EnsureValidFilePath(path); if (File.Exists(path)) { File.Delete(path); } Texture2D tex = TextureRef; if (!TextureHelper.IsReadable(tex)) { tex = TextureHelper.ForceReadTexture(tex); } byte[] data = TextureHelper.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.EnsureValidFilePath(SaveFilePath.Text); if (File.Exists(path)) { File.Delete(path); } File.WriteAllText(path, RealValue); }