Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log Size Warnings #94

Merged
merged 6 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Latest Changelog

- Added OSC parameter option: 'ToN_MasterChange'
- You can use this parameter to detect when the instance master has changed.
- Updated Simplified Chinese localization (Thank you @Fallen-ice)
- Updated Japanese localization (Thank you @nomlasvrc)
- Updated 'ToN_Item' OSC parameter to include Nicomal & バ亀⁄bakame's contributor items.
- Added a warning for when you're about to parse large log files from VRChat that might slow down the program on first launch.
- Added some log parsing logic improvements.
- Automatic Updates will no longer open the Save Manager program automatically after downloading. This is to prevent more false positives.
- Added some language strings for Update related dialogs.
7 changes: 4 additions & 3 deletions Docs/OSC/OSC_Items.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@
| ID | Item |
| - | - |
| `71` | Wave Coil
| `72` | Shape
| `72` | Shape & ???
| `73` | Overseer Plush
| `74` | Darkheart
| `75` | Knife (SABOTAGE)
| `76` | + Mara
| `77` | + Wispy WISPYYY!!!
| `76` | [Carrot (Mara)](https://terror.moe/items/carrot)
| `77` | [Wispy WISPYYY!!!](https://terror.moe/items/wispy_plush)
| `79` | [Judia (Nicomal)](https://terror.moe/items/judia) & [Memoria (バ亀⁄bakame)](https://terror.moe/items/memoria)
5 changes: 5 additions & 0 deletions Localization/Language/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
"MESSAGE.UPDATE_AVAILABLE.TITLE": "New update available",
"MESSAGE.UPDATE_UNAVAILABLE": "No updates are currently available.",
"MESSAGE.UPDATE_UNAVAILABLE.TITLE": "No updates available",
"MESSAGE.UPDATE_SUCCESS": "Successfully downloaded update: {0}\nOpen 'ToNSaveManager' again to continue...",
"MESSAGE.UPDATE_FAILED": "Automatic update has failed. Try using the file 'update.bat' instead.\nPlease report this error on the GitHub page.",

"MESSAGE.LARGE_LOG_WARNING": "You are about to parse a very large VRChat log file!\nFile Name: {0}\nFile Size: {1}\n\nScanning this log file for save codes will take some extra time.\nWould you like to continue reading this file?",
"MESSAGE.LARGE_LOG_WARNING.TITLE": "PARSING LARGE LOG FILE!",

"MESSAGE.COPY_TO_CLIPBOARD": "Copied to clipboard!\n\nYou can now paste the code in game.",
"MESSAGE.COPY_TO_CLIPBOARD.TITLE": "Copied",
Expand Down
9 changes: 4 additions & 5 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@ internal static class Program

internal static readonly string ProgramDirectory = AppContext.BaseDirectory ?? string.Empty;
internal static readonly string ProgramLocation = Path.Combine(ProgramDirectory, ProgramFile);
internal static readonly string ProgramLocationTemporary = Path.Combine(ProgramDirectory, "__" + ProgramFile);
internal static readonly string ProgramLocationTemporary = Path.Combine(ProgramDirectory, "_" + ProgramFile.ToLowerInvariant() + ".old");
internal static readonly string ProgramLocationTemporaryLegacy = Path.Combine(ProgramDirectory, "__" + ProgramFile);
internal const string ProgramFile = ProgramName + ".exe";

internal static readonly string DataLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ProgramName);
internal static readonly string LegacyDataLocation = Path.Combine(LogWatcher<ToNLogContext>.GetVRChatDataLocation(), ProgramName);

internal static Mutex? AppMutex = new Mutex(true, ProgramName);
internal static void ReleaseMutex()
{
if (AppMutex != null)
{
internal static void ReleaseMutex() {
if (AppMutex != null) {
AppMutex.ReleaseMutex();
AppMutex.Dispose();
AppMutex = null;
Expand Down
41 changes: 16 additions & 25 deletions Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
using System.Runtime.InteropServices;
using ToNSaveManager.Models;
using ICSharpCode.SharpZipLib.Zip;
using ToNSaveManager.Localization;

namespace ToNSaveManager {
internal static class Updater {
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool AllocConsole();

const string POST_UPDATE_ARG = "--clean-update";
static string POST_UPDATE_FILE => Program.ProgramLocationTemporary;
internal static void Start(GitHubRelease release, GitHubRelease.Asset asset) {
AllocConsole();

Expand All @@ -22,7 +23,7 @@ internal static void Start(GitHubRelease release, GitHubRelease.Asset asset) {
if (File.Exists(TempFileLocation))
File.Delete(TempFileLocation);

Console.Write($"Downloading '{asset.name}' . . . ");
Console.WriteLine($"Downloading '{asset.name}' . . . ");

string downloadUrl = asset.browser_download_url;
using (HttpClient client = new HttpClient()) {
Expand All @@ -46,21 +47,19 @@ internal static void Start(GitHubRelease release, GitHubRelease.Asset asset) {
Console.WriteLine("Finishing update . . .");
File.Delete(TempFileLocation); // .zip file cleanup

Console.WriteLine("Update complete, restarting . . .");
Console.WriteLine("Update complete . . .");

Program.ReleaseMutex(); // Release mutex so downloaded app opens properly
// Start new process with --post-update
ProcessStartInfo processInfo = new ProcessStartInfo(Program.ProgramFile, POST_UPDATE_ARG);
Process.Start(processInfo);
// Exit this app

MessageBox.Show(string.Format(LANG.S("MESSAGE.UPDATE_SUCCESS") ?? "Successfully downloaded update: {0}\nOpen 'ToNSaveManager' again to continue...", release.tag_name),
Program.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.Exit();
return;
} catch (Exception ex) {
Logger.Error("Automatic update failed.");
Logger.Error(ex);


MessageBox.Show("Automatic update has failed. Try using the file 'update.bat' instead.\nPlease report this error to on the GitHub page.\n\n" + ex, "Update Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show((LANG.S("MESSAGE.UPDATE_FAILED") ?? "Automatic update has failed. Try using the file 'update.bat' instead.\nPlease report this error to on the GitHub page.") + "\n\n" + ex, "Update Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

if (File.Exists(Program.ProgramLocationTemporary)) {
Expand All @@ -71,23 +70,11 @@ internal static void Start(GitHubRelease release, GitHubRelease.Asset asset) {
const string LEGACY_POST_UPDATE_ARG = "--post-update";
internal static void CheckPostUpdate(string[] args) {
bool updateLegacy = Program.ContainsArg(LEGACY_POST_UPDATE_ARG);
if (!updateLegacy && !Program.ContainsArg(POST_UPDATE_ARG)) return;
bool isPostUpdate = File.Exists(POST_UPDATE_FILE) || Program.ContainsArg("--clean-update");
if (!updateLegacy && !isPostUpdate) return;
Logger.Info("Running post-update cleanup.");

try {
using (Process currentProcess = Process.GetCurrentProcess()) {
Process[] processes = Process.GetProcessesByName(currentProcess.ProcessName);
foreach (Process process in processes) {
using (process) {
if (process.Id != currentProcess.Id) {
Logger.Info("Killing old running process: " + process.Id);
process.Kill();
process.WaitForExit();
}
}
}
}

if (updateLegacy) {
// Run legacy cleanup, old to new transition
Logger.Info("Updated from legacy version, running legacy cleanup...");
Expand Down Expand Up @@ -123,8 +110,12 @@ internal static void CheckPostUpdate(string[] args) {
File.Delete(Program.ProgramLocationTemporary);
}

Logger.Info("Post-update success.");
// MessageBox.Show("Successfully updated to version " + Program.GetVersion(), Program.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
if (File.Exists(Program.ProgramLocationTemporaryLegacy)) {
Logger.Info("Deleting old program files again.");
File.Delete(Program.ProgramLocationTemporaryLegacy);
}

Logger.Info("Post-update success. I always knew.");
} catch (Exception ex) {
Logger.Error("Failed to run post-update.");
Logger.Error(ex);
Expand Down
4 changes: 4 additions & 0 deletions Utils/LogParser/LogContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ public virtual void Drop(string name) {

}

public virtual bool Validate(long position, FileInfo fileInfo) {
return true;
}

/// <summary>
/// Get's a list of players in this room as a string.
/// </summary>
Expand Down
6 changes: 5 additions & 1 deletion Utils/LogParser/LogWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ private void LogTick(object? sender, EventArgs? e)
continue;
}

ParseLog(fileInfo, logContext, sender == null);
if (firstRun && logContext.Authenticated && !logContext.Validate(logContext.Position, fileInfo)) {
logContext.RoomReadPos = logContext.Position = fileInfo.Length;
} else {
ParseLog(fileInfo, logContext, sender == null);
}

if (!logContext.Initialized)
{
Expand Down
30 changes: 30 additions & 0 deletions Utils/LogParser/ToNLogContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using ToNSaveManager.Localization;
using ToNSaveManager.Models;
using ToNSaveManager.Models.Index;
using ToNSaveManager.Utils.API;
Expand Down Expand Up @@ -163,6 +164,35 @@ public void SetRoundResult(ToNRoundResult result) {
Result = result;
}

#region File Size Warnings
const long PLEASE_DONT_SLEEP_ON_VRCHAT = 200_000_000;
private static readonly string[] Units = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };

public override bool Validate(long position, FileInfo fileInfo) {
long remainingSize = fileInfo.Length - position;
if (remainingSize > PLEASE_DONT_SLEEP_ON_VRCHAT) {
DialogResult result = MessageBox.Show(
string.Format(LANG.S("MESSAGE.LARGE_LOG_WARNING") ?? "You are about to parse a very large VRChat log file!\nFile Name: {0}\nFile Size: {1}\n\nParsing this log file will take some extra time.\nWould you like to continue reading this file?", fileInfo.Name, GetReadableFileSize(fileInfo.Length)),
LANG.S("MESSAGE.LARGE_LOG_WARNING.TITLE") ?? "Parsing large log file!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
return result == DialogResult.Yes || result != DialogResult.No;
}

return true;
}

private static string GetReadableFileSize(long size)
{
int unitIndex = 0;
while (size >= 1024) {
size /= 1024;
++unitIndex;
}

string unit = Units[unitIndex];
return string.Format("{0:0.#} {1}", size, unit);
}
#endregion

#region Pickup Parsing
private string? LastItemKey;
public override void Pickup(string name) {
Expand Down
6 changes: 5 additions & 1 deletion Windows/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,10 @@ internal void SetBackupButton(bool enabled) {
private void LogWatcher_OnLine(object? sender, OnLineArgs e) {
DateTime timestamp = e.Timestamp;
ToNLogContext context = e.Context;
#if !DEBUG
if (!context.IsHomeWorld) return; // Don't read logs not from ToN.
#endif

string line = e.Content.Substring(34);

if (HandleSaveCode(line, timestamp, context) ||
Expand Down Expand Up @@ -933,7 +937,7 @@ private bool HandleStatCollection(string line, DateTime timestamp, ToNLogContext

return false;
}
#endregion
#endregion

#region Data
private Entry? RecentData;
Expand Down