diff --git a/BSIPA-ModList/UI/ViewControllers/DownloadProgressViewController.cs b/BSIPA-ModList/UI/ViewControllers/DownloadProgressViewController.cs index b3329d41..ee61bda2 100644 --- a/BSIPA-ModList/UI/ViewControllers/DownloadProgressViewController.cs +++ b/BSIPA-ModList/UI/ViewControllers/DownloadProgressViewController.cs @@ -108,10 +108,12 @@ namespace BSIPA_ModList.UI.ViewControllers _restartGame = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton", new Vector2(ButtonXOffset, -8f), ButtonSize, Restart, "Restart Game"); _restartGame.interactable = DownloadController.Instance.HadUpdates; _restartGame.ToggleWordWrapping(false); - - DownloadController.Instance.OnDownloaderListChanged += Refresh; - DownloadController.Instance.OnDownloadStateChanged += DownloaderStateChanged; } + + DownloadController.Instance.OnDownloaderListChanged += Refresh; + DownloadController.Instance.OnDownloadStateChanged += DownloaderStateChanged; + + DownloaderStateChanged(); } private void Restart() diff --git a/IPA.Injector/Injector.cs b/IPA.Injector/Injector.cs index 3f5bd820..f9a55974 100644 --- a/IPA.Injector/Injector.cs +++ b/IPA.Injector/Injector.cs @@ -59,6 +59,8 @@ namespace IPA.Injector Updates.InstallPendingUpdates(); + LibLoader.SetupAssemblyFilenames(true); + pluginAsyncLoadTask = PluginLoader.LoadTask(); } catch (Exception e) @@ -81,6 +83,7 @@ namespace IPA.Injector if (loadingDone) return; loadingDone = true; AppDomain.CurrentDomain.AssemblyResolve += LibLoader.AssemblyLibLoader; + LibLoader.SetupAssemblyFilenames(true); } private static void InstallBootstrapPatch() diff --git a/IPA.Loader/Loader/LibLoader.cs b/IPA.Loader/Loader/LibLoader.cs index 6b43d335..5ab7588e 100644 --- a/IPA.Loader/Loader/LibLoader.cs +++ b/IPA.Loader/Loader/LibLoader.cs @@ -33,9 +33,9 @@ namespace IPA.Loader internal static string NativeLibraryPath => Path.Combine(LibraryPath, "Native"); internal static Dictionary FilenameLocations; - internal static void SetupAssemblyFilenames() + internal static void SetupAssemblyFilenames(bool force = false) { - if (FilenameLocations == null) + if (FilenameLocations == null || force) { FilenameLocations = new Dictionary(); diff --git a/IPA.Loader/Logging/Printers/GZFilePrinter.cs b/IPA.Loader/Logging/Printers/GZFilePrinter.cs index f4d3e034..6d86709f 100644 --- a/IPA.Loader/Logging/Printers/GZFilePrinter.cs +++ b/IPA.Loader/Logging/Printers/GZFilePrinter.cs @@ -28,7 +28,6 @@ namespace IPA.Logging.Printers /// protected StreamWriter FileWriter; - private GZipStream zstream; private FileStream fstream; /// @@ -37,6 +36,8 @@ namespace IPA.Logging.Printers /// protected abstract FileInfo GetFileInfo(); + private const string latestFormat = "_latest{0}"; + private void InitLog() { try @@ -45,12 +46,19 @@ namespace IPA.Logging.Printers { // first init fileInfo = GetFileInfo(); var ext = fileInfo.Extension; - fileInfo = new FileInfo(fileInfo.FullName + ".gz"); - fileInfo.Create().Close(); - var symlink = new FileInfo(Path.Combine(fileInfo.DirectoryName ?? throw new InvalidOperationException(), $"_latest{ext}.gz")); + var symlink = new FileInfo(Path.Combine(fileInfo.DirectoryName ?? throw new InvalidOperationException(), string.Format(latestFormat, ext))); if (symlink.Exists) symlink.Delete(); + foreach (var file in fileInfo.Directory.EnumerateFiles("*.log", SearchOption.TopDirectoryOnly)) + { + if (file.Extension == ".gz") continue; + + CompressOldLog(file); + } + + fileInfo.Create().Close(); + try { if (!CreateHardLink(symlink.FullName, fileInfo.FullName, IntPtr.Zero)) @@ -73,6 +81,20 @@ namespace IPA.Logging.Printers } } + private static async void CompressOldLog(FileInfo file) + { + Logger.log.Debug($"Compressing log file {file}"); + + var newFile = new FileInfo(file.FullName + ".gz"); + + using (var istream = file.OpenRead()) + using (var ostream = newFile.Create()) + using (var gz = new GZipStream(ostream, CompressionMode.Compress, CompressionLevel.BestCompression, false)) + await istream.CopyToAsync(gz); + + file.Delete(); + } + /// /// Called at the start of any print session. /// @@ -81,11 +103,7 @@ namespace IPA.Logging.Printers InitLog(); fstream = fileInfo.Open(FileMode.Append, FileAccess.Write); - zstream = new GZipStream(fstream, CompressionMode.Compress) - { - FlushMode = FlushType.Full - }; - FileWriter = new StreamWriter(zstream, new UTF8Encoding(false)); + FileWriter = new StreamWriter(fstream, new UTF8Encoding(false)); } /// @@ -94,13 +112,10 @@ namespace IPA.Logging.Printers public sealed override void EndPrint() { FileWriter.Flush(); - zstream.Flush(); fstream.Flush(); FileWriter.Dispose(); - zstream.Dispose(); fstream.Dispose(); FileWriter = null; - zstream = null; fstream = null; } @@ -120,13 +135,10 @@ namespace IPA.Logging.Printers if (disposing) { FileWriter.Flush(); - zstream.Flush(); fstream.Flush(); FileWriter.Close(); - zstream.Close(); fstream.Close(); FileWriter.Dispose(); - zstream.Dispose(); fstream.Dispose(); } } diff --git a/Refs/Assembly-CSharp.dll b/Refs/Assembly-CSharp.dll index 984af28e..e7bd0eb4 100644 Binary files a/Refs/Assembly-CSharp.dll and b/Refs/Assembly-CSharp.dll differ diff --git a/Refs/BeatSaberCustomUI.dll b/Refs/BeatSaberCustomUI.dll index 41662300..d70b6cd5 100644 Binary files a/Refs/BeatSaberCustomUI.dll and b/Refs/BeatSaberCustomUI.dll differ diff --git a/Refs/BeatSaberCustomUI.xml b/Refs/BeatSaberCustomUI.xml index 9ad1b55a..5fbaa627 100644 --- a/Refs/BeatSaberCustomUI.xml +++ b/Refs/BeatSaberCustomUI.xml @@ -129,28 +129,6 @@ The size of the color picker's RectTransform. - - - Creates a custom TextSegmentedControl component. - - Thet transform to parent the new TextSegmentedControl component to. - The position the TextSegmentedControl component should be anchored to. - The size of the TextSegmentedControl component RectTransform. - Callback when the user clicks on one of the segments. - Size of text in segments. - Size of padding in segments. - The newly created TextSegmentedControl component. - - - - Creates a custom IconSegmentedControl component. - - Thet transform to parent the new IconSegmentedControl component to. - The position the IconSegmentedControl component should be anchored to. - The size of the IconSegmentedControl component RectTransform. - Callback when the user clicks on one of the segments. - The newly created IconSegmentedControl component. - The FlowCoordinator that presented this FlowCoordinator diff --git a/Refs/Unity.TextMeshPro.dll b/Refs/Unity.TextMeshPro.dll index f2181825..5d0b3b45 100644 Binary files a/Refs/Unity.TextMeshPro.dll and b/Refs/Unity.TextMeshPro.dll differ