public override void SaveLogs(IO.Swagger.Model.Scene scene, IO.Swagger.Model.Project project, string customNotificationTitle = "") { string sceneString = "", projectString = ""; if (SceneManager.Instance.SceneMeta != null) { sceneString = scene.ToJson(); } if (Base.ProjectManager.Instance.ProjectMeta != null) { projectString = project.ToJson(); } string dirname = Application.persistentDataPath + "/Logs/" + DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss"); Directory.CreateDirectory(dirname); StreamWriter sceneFile = File.CreateText(dirname + "/scene.json"); sceneFile.Write(sceneString); sceneFile.Close(); StreamWriter projectFile = File.CreateText(dirname + "/project.json"); projectFile.Write(projectString); projectFile.Close(); StreamWriter logsFile = File.CreateText(dirname + "/logs.txt"); logsFile.WriteLine("Editor version: " + Application.version); if (GameManager.Instance.SystemInfo != null) { logsFile.WriteLine("Server version: " + GameManager.Instance.SystemInfo.Version); } logsFile.WriteLine("Editor API version: " + GameManager.ApiVersion); if (GameManager.Instance.SystemInfo != null) { logsFile.WriteLine("Server API version: " + GameManager.Instance.SystemInfo.ApiVersion); } else { logsFile.WriteLine("Not connected to server"); } logsFile.WriteLine(); foreach (LogEntry log in LogEntries) { logsFile.WriteLine("Timestamp: " + log.TimeStamp.ToString()); logsFile.WriteLine("Type: " + log.LogType.ToString()); logsFile.WriteLine("Message: " + log.LogMessage); if (log.LogType != LogType.Log.ToString()) { logsFile.WriteLine("Stacktrace: " + log.StackTrace); } logsFile.WriteLine(""); } logsFile.Close(); ShowNotification(customNotificationTitle, "Logs saved to directory " + dirname); }
public async override void SaveLogs(IO.Swagger.Model.Scene scene, IO.Swagger.Model.Project project, string customNotificationTitle = "") { string sceneString = "", projectString = ""; if (SceneManager.Instance.SceneMeta != null) { sceneString = scene.ToJson(); } if (Base.ProjectManager.Instance.ProjectMeta != null) { projectString = project.ToJson(); } string dirname = Application.persistentDataPath + "/Logs/" + DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss"); string zipname = Application.persistentDataPath + "/Logs/logs.zip"; Directory.CreateDirectory(dirname); StreamWriter sceneFile = File.CreateText(dirname + "/scene.json"); sceneFile.Write(sceneString); sceneFile.Close(); StreamWriter projectFile = File.CreateText(dirname + "/project.json"); projectFile.Write(projectString); projectFile.Close(); StreamWriter logsFile = File.CreateText(dirname + "/logs.txt"); logsFile.WriteLine("Editor version: " + Application.version); if (GameManager.Instance.SystemInfo != null) { logsFile.WriteLine("Server version: " + GameManager.Instance.SystemInfo.Version); } logsFile.WriteLine("Editor API version: " + GameManager.ApiVersion); if (GameManager.Instance.SystemInfo != null) { logsFile.WriteLine("Server API version: " + GameManager.Instance.SystemInfo.ApiVersion); } else { logsFile.WriteLine("Not connected to server"); } logsFile.WriteLine(); foreach (LogEntry log in LogEntries) { logsFile.WriteLine("Timestamp: " + log.TimeStamp.ToString()); logsFile.WriteLine("Type: " + log.LogType.ToString()); logsFile.WriteLine("Message: " + log.LogMessage); if (log.LogType != LogType.Log.ToString()) { logsFile.WriteLine("Stacktrace: " + log.StackTrace); } logsFile.WriteLine(""); } logsFile.Close(); ShowNotification(customNotificationTitle, "Logs saved to directory " + dirname); string uri = "http://" + WebsocketManager.Instance.GetServerDomain() + ":6799/upload"; try { if (File.Exists(zipname)) { File.Delete(zipname); } ZipFile.CreateFromDirectory(dirname, zipname); FileStream file = new FileStream(zipname, FileMode.Open, FileAccess.Read); HttpContent fileStreamContent = new StreamContent(file); using (MultipartFormDataContent formData = new MultipartFormDataContent()) { formData.Add(fileStreamContent, "files", Path.GetFileName(zipname)); HttpResponseMessage response = await client.PostAsync(uri, formData); if (!response.IsSuccessStatusCode) { Debug.LogError("Error:" + zipname + " not uploaded"); } else { } } } catch (HttpRequestException ex) { Debug.LogError($"Failed to upload logs to {uri}: " + ex.Message); } catch (InvalidOperationException ex) { Debug.LogError($"Failed to upload logs to {uri}: " + ex.Message); } catch (Exception ex) when(ex is ArgumentException || ex is PathTooLongException || ex is DirectoryNotFoundException || ex is IOException) { Debug.LogError("Failed to create zip folder with logs: " + ex.Message); } finally { } }