-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
116 lines (103 loc) · 4.19 KB
/
Program.cs
File metadata and controls
116 lines (103 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using System;
using System.IO;
using System.Collections.Generic;
// using System.Security.Permissions;
using Newtonsoft.Json;
namespace UnityReportUnpacker
{
public class Attachment
{
public string contentType;
public string dataBase64;
public string dataIdentifier;
public string fileName;
public string frameNumber;
public int height;
public int width;
public string name;
}
public class Report
{
public List<Attachment> attachments;
public List<Attachment> screenshots;
public string identifier;
public string summary;
public Attachment thumbnail;
}
public class GenericObject : Dictionary<string, object> {};
class Program
{
static void Main(string[] args)
{
var dirname = Directory.GetCurrentDirectory();
List<string> files = new List<string>(Directory.EnumerateFiles(dirname)).FindAll(x => x.EndsWith("json"));
string jsonString;
Console.WriteLine("FILES "+files.Count);
Report report;
string reportDirname;
string reportDirPath;
string summaryShort;
foreach (var file in files)
{
jsonString = File.ReadAllText(file);
report = JsonConvert.DeserializeObject<Report>(jsonString);
summaryShort = report.summary.Replace(" ","_");
summaryShort = summaryShort.Replace("/","");
summaryShort = summaryShort.Replace("\\","");
if (summaryShort.Length > 20)
{
summaryShort = summaryShort.Substring(0,20);
}
reportDirname = $"{report.identifier}_{summaryShort}";
reportDirPath = Path.Combine(dirname, reportDirname);
if (Directory.Exists(reportDirPath))
{
Directory.Delete(reportDirPath, true);
}
Directory.CreateDirectory(reportDirPath);
// Export attachments.
foreach (var attachment in report.attachments)
{
SaveFile(attachment, reportDirPath, attachment.fileName);
}
// Export screenshots.
foreach (var attachment in report.screenshots)
{
SaveFile(attachment, reportDirPath, attachment.height+"_"+attachment.dataIdentifier+".png");
}
SaveFile(report.thumbnail, reportDirPath, "thumbnail.png");
Console.WriteLine("FILE "+Path.GetFileNameWithoutExtension(file));
// Export sparse report.
GenericObject reportObject = JsonConvert.DeserializeObject<GenericObject>(jsonString);
reportObject["screenshots"] = null;
reportObject["attachments"] = null;
reportObject["thumbnail"] = null;
// Export into separate files.
var separateExports = new string[] {
"clientMetrics", "deviceMetadata",
"events", "measures", "aggregateMetrics",
};
foreach (var export in separateExports)
{
File.WriteAllText(
Path.Combine(reportDirPath, export+".json"),
JsonConvert.SerializeObject(reportObject[export], Formatting.Indented)
);
reportObject[export] = null;
}
File.WriteAllText(
Path.Combine(reportDirPath, "report.json"),
JsonConvert.SerializeObject(reportObject, Formatting.Indented)
);
}
}
static void SaveFile(Attachment attachment, string dir, string name)
{
var bytes = System.Convert.FromBase64String(attachment.dataBase64);
File.WriteAllBytes(
Path.Combine(dir, name),
bytes
);
}
}
}