summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/Views/LogParser/Index.cshtml
blob: 06d46c9ec3226e9e27bd96b2a7f2cbe4e0780fb4 (plain)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
@using Humanizer
@using StardewModdingAPI.Toolkit.Utilities
@using StardewModdingAPI.Web.Framework
@using StardewModdingAPI.Web.Framework.LogParsing.Models
@model StardewModdingAPI.Web.ViewModels.LogParserModel

@{
    ViewData["Title"] = "SMAPI log parser";
    IDictionary<string, LogModInfo[]> contentPacks = Model.GetContentPacksByMod();
    IDictionary<string, bool> defaultFilters = Enum
        .GetValues(typeof(LogLevel))
        .Cast<LogLevel>()
        .ToDictionary(level => level.ToString().ToLower(), level => level != LogLevel.Trace);

    string curPageUrl = this.Url.PlainAction("Index", "LogParser", new { id = Model.PasteID }, absoluteUrl: true);

    ISet<int> screenIds = new HashSet<int>(Model.ParsedLog?.Messages?.Select(p => p.ScreenId) ?? new int[0]);
}

@section Head {
    @if (Model.PasteID != null)
    {
        <meta name="robots" content="noindex" />
    }
    <link rel="stylesheet" href="~/Content/css/file-upload.css?r=202002" />
    <link rel="stylesheet" href="~/Content/css/log-parser.css?r=202002" />

    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.11" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1" crossorigin="anonymous"></script>
    <script src="~/Content/js/file-upload.js?r=202002"></script>
    <script src="~/Content/js/log-parser.js?r=202002"></script>
    <script>
        $(function() {
            smapi.logParser({
                logStarted: new Date(@this.ForJson(Model.ParsedLog?.Timestamp)),
                showPopup: @this.ForJson(Model.ParsedLog == null),
                showMods: @this.ForJson(Model.ParsedLog?.Mods?.Select(p => Model.GetSlug(p.Name)).Distinct().ToDictionary(slug => slug, slug => true)),
                showSections: @this.ForJson(Enum.GetNames(typeof(LogSection)).ToDictionary(section => section, section => false)),
                showLevels: @this.ForJson(defaultFilters),
                enableFilters: @this.ForJson(!Model.ShowRaw),
                screenIds: @this.ForJson(screenIds)
            }, '@this.Url.PlainAction("Index", "LogParser", values: null)');
        });
    </script>
}

@* upload result banner *@
@if (Model.UploadError != null)
{
    <div class="banner error" v-pre>
        <strong>Oops, the server ran into trouble saving that file.</strong><br />
        <small v-pre>Error details: @Model.UploadError</small>
    </div>
}
else if (Model.ParseError != null)
{
    <div class="banner error" v-pre>
        <strong>Oops, couldn't parse that log. (Make sure you upload the log file, not the console text.)</strong><br />
        Share this URL when asking for help: <code>@curPageUrl</code><br />
        (Or <a href="@this.Url.PlainAction("Index", "LogParser", values: null)">upload a new log</a>.)<br />
        <br />
        <small v-pre>Error details: @Model.ParseError</small>
    </div>
}
else if (Model.ParsedLog?.IsValid == true)
{
    <div class="banner success" v-pre>
        <strong>Share this link to let someone else see the log:</strong> <code>@curPageUrl</code><br />
        (Or <a href="@this.Url.PlainAction("Index", "LogParser", values: null)">upload a new log</a>.)
    </div>
}

@* save warnings *@
@if (Model.UploadWarning != null || Model.Expiry != null)
{
    @if (Model.UploadWarning != null)
    {
        <text>⚠️ @Model.UploadWarning<br /></text>
    }

    <div class="save-metadata" v-pre>
        @if (Model.Expiry != null)
        {
            <text>This log will expire in @((DateTime.UtcNow - Model.Expiry.Value).Humanize()) (<a href="@(this.Url.PlainAction("Index", "LogParser", new { id = this.Model.PasteID, renew = true }))">renew</a>).</text>
        }
    </div>
}

@* upload new log *@
@if (Model.ParsedLog == null)
{
    <h2>Where do I find my SMAPI log?</h2>
    <div>What system do you use?</div>
    <ul id="os-list">
        @foreach (Platform platform in new[] { Platform.Android, Platform.Linux, Platform.Mac, Platform.Windows })
        {
            <li>
                <input type="radio" name="os" value="@platform" id="os-@platform" checked="@(Model.DetectedPlatform == platform)" />
                <label for="os-@platform">@platform</label>
            </li>
        }
    </ul>
    <div data-os="@Platform.Android">
        On Android:
        <ol>
            <li>Open a file app (like My Files or MT Manager).</li>
            <li>Find the <code>StardewValley</code> folder on your internal storage.</li>
            <li>Open the <code>ErrorLogs</code> subfolder.</li>
            <li>The log file is <code>SMAPI-crash.txt</code> if it exists, otherwise <code>SMAPI-latest.txt</code>.</li>
        </ol>
    </div>
    <div data-os="@Platform.Linux">
        On Linux:
        <ol>
            <li>Open the Files app.</li>
            <li>Click the options menu (might be labeled <em>Go</em> or <code>⋮</code>).</li>
            <li>Choose <em>Enter Location</em>.</li>
            <li>Enter this exact text: <pre>~/.config/StardewValley/ErrorLogs</pre></li>
            <li>The log file is <code>SMAPI-crash.txt</code> if it exists, otherwise <code>SMAPI-latest.txt</code>.</li>
        </ol>
    </div>
    <div data-os="@Platform.Mac">
        On macOS:
        <ol>
            <li>Open the Finder app.</li>
            <li>Click <em>Go</em> at the top, then <em>Go to Folder</em>.</li>
            <li>Enter this exact text: <pre>~/.config/StardewValley/ErrorLogs</pre></li>
            <li>The log file is <code>SMAPI-crash.txt</code> if it exists, otherwise <code>SMAPI-latest.txt</code>.</li>
        </ol>
    </div>
    <div data-os="@Platform.Windows">
        On Windows:
        <ol>
            <li>Press the <code>Windows</code> and <code>R</code> buttons at the same time.</li>
            <li>In the 'run' box that appears, enter this exact text: <pre>%appdata%\StardewValley\ErrorLogs</pre></li>
            <li>The log file is <code>SMAPI-crash.txt</code> if it exists, otherwise <code>SMAPI-latest.txt</code>.</li>
        </ol>
    </div>

    <h2>How do I share my log?</h2>
    <form action="@this.Url.PlainAction("PostAsync", "LogParser")" method="post">
        <input id="inputFile" type="file" />
        <ol>
            <li>
                Drag the file onto this textbox <small>(or <a href="#" id="choose-file-link">choose a file</a>)</small>:<br />
                <textarea id="input" name="input" placeholder="paste log here"></textarea>
            </li>
            <li>
                Click this button:<br />
                <input type="submit" id="submit" value="save & parse log" />
            </li>
            <li>On the new page, copy the URL and send it to the person helping you.</li>
        </ol>
    </form>
}

@* parsed log *@
@if (Model.ParsedLog?.IsValid == true)
{
    <div id="output">
        @if (Model.ParsedLog.Mods.Any(mod => mod.HasUpdate))
        {
            <h2>Suggested fixes</h2>
            <ul id="fix-list">
                <li>
                    Consider updating these mods to fix problems:

                    <table id="updates" class="table">
                        @foreach (LogModInfo mod in Model.ParsedLog.Mods.Where(mod => (mod.HasUpdate && mod.ContentPackFor == null) || (contentPacks != null && contentPacks.TryGetValue(mod.Name, out LogModInfo[] contentPackList) && contentPackList.Any(pack => pack.HasUpdate))))
                        {
                            <tr class="mod-entry">
                                <td>
                                    <strong class=@(!mod.HasUpdate ? "hidden" : "")>@mod.Name</strong>
                                    @if (contentPacks != null && contentPacks.TryGetValue(mod.Name, out LogModInfo[] contentPackList))
                                    {
                                        <div class="content-packs">
                                            @foreach (LogModInfo contentPack in contentPackList.Where(pack => pack.HasUpdate))
                                            {
                                                <text>+ @contentPack.Name</text><br />
                                            }
                                        </div>
                                    }
                                </td>
                                <td>
                                    @if (mod.HasUpdate)
                                    {
                                        <a href="@mod.UpdateLink" target="_blank">
                                            @(mod.Version == null ? @mod.UpdateVersion : $"{mod.Version} → {mod.UpdateVersion}")
                                        </a>
                                    }
                                    else
                                    {
                                        <text>&nbsp;</text>
                                    }

                                    @if (contentPacks != null && contentPacks.TryGetValue(mod.Name, out contentPackList))
                                    {
                                        <div>
                                            @foreach (LogModInfo contentPack in contentPackList.Where(pack => pack.HasUpdate))
                                            {
                                                <a href="@contentPack.UpdateLink" target="_blank">@contentPack.Version → @contentPack.UpdateVersion</a><br />
                                            }
                                        </div>
                                    }
                                </td>
                            </tr>
                        }
                    </table>
                </li>
            </ul>
        }

        <h2>Log info</h2>
        <table id="metadata" class="table">
            <caption>Game info:</caption>
            <tr>
                <th>Stardew Valley:</th>
                <td v-pre>@Model.ParsedLog.GameVersion on @Model.ParsedLog.OperatingSystem</td>
            </tr>
            <tr>
                <th>SMAPI:</th>
                <td v-pre>@Model.ParsedLog.ApiVersion</td>
            </tr>
            <tr>
                <th>Folder:</th>
                <td v-pre>@Model.ParsedLog.GamePath</td>
            </tr>
            <tr>
                <th>Log started:</th>
                <td>@Model.ParsedLog.Timestamp.UtcDateTime.ToString("yyyy-MM-dd HH:mm") UTC ({{localTimeStarted}} your time)</td>
            </tr>
        </table>
        <br />
        <table id="mods" class="@(Model.ShowRaw ? "filters-disabled" : null) table">
            <caption>
                Installed mods:
                @if (!Model.ShowRaw)
                {
                    <span class="notice txt"><i>click any mod to filter</i></span>
                    <span class="notice btn txt" v-on:click="showAllMods" v-bind:class="{ invisible: !anyModsHidden }">show all</span>
                    <span class="notice btn txt" v-on:click="hideAllMods" v-bind:class="{ invisible: !anyModsShown || !anyModsHidden }">hide all</span>
                }
            </caption>
            @foreach (var mod in Model.ParsedLog.Mods.Where(p => p.Loaded && p.ContentPackFor == null))
            {
                <tr v-on:click="toggleMod('@Model.GetSlug(mod.Name)')" class="mod-entry" v-bind:class="{ hidden: !showMods['@Model.GetSlug(mod.Name)'] }">
                    <td><input type="checkbox" v-bind:checked="showMods['@Model.GetSlug(mod.Name)']" v-bind:class="{ invisible: !anyModsHidden }" /></td>
                    <td v-pre>
                        <strong>@mod.Name</strong> @mod.Version
                        @if (contentPacks != null && contentPacks.TryGetValue(mod.Name, out LogModInfo[] contentPackList))
                        {
                            <div class="content-packs">
                                @foreach (var contentPack in contentPackList)
                                {
                                    <text>+ @contentPack.Name @contentPack.Version</text><br />
                                }
                            </div>
                        }
                    </td>
                    <td v-pre>
                        @mod.Author
                        @if (contentPacks != null && contentPacks.TryGetValue(mod.Name, out contentPackList))
                        {
                            <div class="content-packs">
                                @foreach (var contentPack in contentPackList)
                                {
                                    <text>+ @contentPack.Author</text><br />
                                }
                            </div>
                        }
                    </td>
                    @if (mod.Errors == 0)
                    {
                        <td v-pre class="color-green">no errors</td>
                    }
                    else if (mod.Errors == 1)
                    {
                        <td v-pre class="color-red">@mod.Errors error</td>
                    }
                    else
                    {
                        <td v-pre class="color-red">@mod.Errors errors</td>
                    }
                </tr>
            }
        </table>

        @if (!Model.ShowRaw)
        {
            <div id="filters">
                Filter messages:
                <span v-bind:class="{ active: showLevels['trace'] }" v-on:click="toggleLevel('trace')">TRACE</span> |
                <span v-bind:class="{ active: showLevels['debug'] }" v-on:click="toggleLevel('debug')">DEBUG</span> |
                <span v-bind:class="{ active: showLevels['info'] }" v-on:click="toggleLevel('info')">INFO</span> |
                <span v-bind:class="{ active: showLevels['alert'] }" v-on:click="toggleLevel('alert')">ALERT</span> |
                <span v-bind:class="{ active: showLevels['warn'] }" v-on:click="toggleLevel('warn')">WARN</span> |
                <span v-bind:class="{ active: showLevels['error'] }" v-on:click="toggleLevel('error')">ERROR</span>
            </div>

            <table id="log">
                @foreach (var message in Model.ParsedLog.Messages)
                {
                    string levelStr = message.Level.ToString().ToLower();
                    string sectionStartClass = message.IsStartOfSection ? "section-start" : null;
                    string sectionFilter = message.Section != null && !message.IsStartOfSection ? $"&& sectionsAllow('{message.Section}')" : null; // filter the message by section if applicable

                    <tr class="mod @levelStr @sectionStartClass"
                        @if (message.IsStartOfSection) { <text> v-on:click="toggleSection('@message.Section')" </text> }
                        v-show="filtersAllow('@Model.GetSlug(message.Mod)', '@levelStr') @sectionFilter">
                        <td v-pre>@message.Time</td>
                        @if (screenIds.Count > 1)
                        {
                            <td v-pre>screen_@message.ScreenId</td>
                        }
                        <td v-pre>@message.Level.ToString().ToUpper()</td>
                        <td v-pre data-title="@message.Mod">@message.Mod</td>
                        <td>
                            <span v-pre class="log-message-text">@message.Text</span>
                            @if (message.IsStartOfSection)
                            {
                                <span class="section-toggle-message">
                                    <template v-if="sectionsAllow('@message.Section')">
                                        This section is shown. Click here to hide it.
                                    </template>
                                    <template v-else>
                                        This section is hidden. Click here to show it.
                                    </template>
                                </span>
                            }
                        </td>
                    </tr>
                    if (message.Repeated > 0)
                    {
                        <tr class="@levelStr mod mod-repeat" v-show="filtersAllow('@Model.GetSlug(message.Mod)', '@levelStr') @sectionFilter">
                            <td colspan="4"></td>
                            <td v-pre><i>repeats [@message.Repeated] times.</i></td>
                        </tr>
                    }
                }
            </table>

            <small><a href="@this.Url.PlainAction("Index", "LogParser", new { id = Model.PasteID, raw = true })">view raw log</a></small>
        }
        else
        {
            <pre v-pre>@Model.ParsedLog.RawText</pre>
            <small><a href="@this.Url.PlainAction("Index", "LogParser", new { id = Model.PasteID })">view parsed log</a></small>
        }
    </div>
}
else if (Model.ParsedLog?.IsValid == false)
{
    <h3>Raw log</h3>
    <pre v-pre>@Model.ParsedLog.RawText</pre>
}