From 19556f2d26d77252873cc3d0d5556cf56743e894 Mon Sep 17 00:00:00 2001 From: TJhost Date: Sun, 13 Sep 2026 19:33:09 -0400 Subject: [PATCH] Relocate app data and package build output Adds a new `AppPaths` helper and moves runtime/user-generated files (`init.config`, `custom_set.txt`, cache, WebView2 data) into `%LocalAppData%\Lithium` with readable fallback to portable files. WebView2 initialization now sets a loader DLL path, uses an explicit user data folder, and surfaces runtime-missing errors. The build/publish pipeline is updated to emit a clean `Build\` layout with dependencies under `lib\`, remove duplicate root DLL/docs, and align probing/runtime settings for net48 x64 output. Supporting updates include ignore rules for build/runtime artifacts, refreshed agent build/release docs, and endpoint URL/domain updates. --- .gitignore | 14 ++++++++++ AGENTS.md | 28 +++++++++++++------ Lithium/A1/App.config | 17 +++++++----- Lithium/A1/packages.config | 1 - Lithium/AppPaths.cs | 55 ++++++++++++++++++++++++++++++++++++++ Lithium/ConfigLoader.cs | 5 ++-- Lithium/Lithium.csproj | 47 ++++++++++++++++++++------------ Lithium/MainWindow.xaml.cs | 42 ++++++++++++++++++++++------- Lithium/OperatorSets.cs | 16 +++++------ 9 files changed, 172 insertions(+), 53 deletions(-) create mode 100644 Lithium/AppPaths.cs diff --git a/.gitignore b/.gitignore index 2fa7d59..ae476ab 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,9 @@ mono_crash.* # Build results +[Bb]in/ +[Oo]bj/ +[Bb]uild/ [Dd]ebug/ [Dd]ebugPublic/ [Rr]elease/ @@ -228,6 +231,17 @@ _pkginfo.txt # but keep track of directories ending in .cache !?*.[Cc]ache/ +# Runtime-generated application data +*.exe.WebView2/ + +# Local release archives +*.7z +*.zip + +# Local Claude Code and VS Code settings +.claude/ +.vscode/ + # Others ClientBin/ ~$* diff --git a/AGENTS.md b/AGENTS.md index 9a9ab9e..ac80d6f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -3,15 +3,24 @@ ## Prerequisites - Git remote: `https://git.scpsmp.site/JJ/Lithium.git` - Auth: OAuth token stored in Windows Credential Manager (via git) -- MSBuild: `& "C:\Program Files\Microsoft Visual Studio\18\Community\MSBuild\Current\Bin\MSBuild.exe"` +- Visual Studio 2022 or newer with the .NET desktop development workload +- NuGet package restore enabled +- .NET Framework 4.8 Developer Pack for building +- Microsoft Edge WebView2 Runtime for the Website tab at runtime ## Build ```powershell # Kill running process first Stop-Process -Name "Lithium" -ErrorAction SilentlyContinue -# Compile Release build -& "C:\Program Files\Microsoft Visual Studio\2022\Community\Msbuild\Current\Bin\MSBuild.exe" /t:rebuild /p:Configuration=Release /p:Platform="x64" +# Locate MSBuild, restore packages, and compile the Release build +$msbuild = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe | Select-Object -First 1 +& $msbuild Lithium.sln /t:Restore,Rebuild /p:Configuration=Release /p:Platform="x64" + +# Create the clean file-deployment layout under Build\. +& $msbuild Lithium\Lithium.csproj /t:Publish /p:Configuration=Release /p:Platform="x64" + +# Keep Lithium.exe, Lithium.exe.config, and the complete lib directory together. ``` ## Stage & Commit @@ -44,9 +53,12 @@ git push origin $version $cred = "protocol=https`nhost=git.scpsmp.site`n`n" | git credential fill $token = ($cred -split "`n" | Where-Object { $_ -like "password=*" }) -replace "password=","" -# 7z build output (x64/Release) -$archivePath = "D:\Lithium\Lithium-$version.7z" -& "C:\Program Files\7-Zip\7z.exe" a -mx=9 "$archivePath" "D:\Lithium\Lithium\bin\x64\Release\*" +# Archive the published x64 Release output; run from anywhere inside the repository +$repoRoot = (git rev-parse --show-toplevel).Trim() +$archivePath = Join-Path $repoRoot "Lithium-$version.7z" +$releaseOutput = Join-Path $repoRoot "Build\*" +$sevenZip = (Get-Command 7z.exe -ErrorAction Stop).Source +& $sevenZip a -mx=9 "$archivePath" "$releaseOutput" # Create release via Gitea API $body = @" @@ -63,7 +75,7 @@ curl.exe -s -X POST "https://git.scpsmp.site/api/v1/repos/JJ/Lithium/releases/$r ## Post-Release Cleanup ```powershell # Delete the local archive after successful upload -Remove-Item -LiteralPath "D:\Lithium\Lithium-$version.7z" -Force +Remove-Item -LiteralPath "$archivePath" -Force Remove-Item -LiteralPath "$env:TEMP\release.json" -Force ``` @@ -72,4 +84,4 @@ Remove-Item -LiteralPath "$env:TEMP\release.json" -Force - Tag naming scheme: `0.01`, `0.02`, `0.03`, etc. (not `v1.0.0`) - Release naming scheme: `0.XX @ Lithium` - Use PATCH to edit existing release tag via API if you mess up the tag name -- 7-Zip located at `C:\Program Files\NVIDIA Corporation\NVIDIA app\7z.exe` (or `C:\Program Files\7-Zip\7z.exe` if installed separately) +- Add `7z.exe` to `PATH` before running the release archive command diff --git a/Lithium/A1/App.config b/Lithium/A1/App.config index d81d8e6..bf8f9d3 100644 --- a/Lithium/A1/App.config +++ b/Lithium/A1/App.config @@ -1,8 +1,11 @@ - + - - - - - - \ No newline at end of file + + + + + + + + + diff --git a/Lithium/A1/packages.config b/Lithium/A1/packages.config index fdda007..d1ffec1 100644 --- a/Lithium/A1/packages.config +++ b/Lithium/A1/packages.config @@ -7,7 +7,6 @@ - diff --git a/Lithium/AppPaths.cs b/Lithium/AppPaths.cs new file mode 100644 index 0000000..a2cf55f --- /dev/null +++ b/Lithium/AppPaths.cs @@ -0,0 +1,55 @@ +using System; +using System.IO; +using System.Runtime.InteropServices; + +namespace Lua +{ + internal static class AppPaths + { + private const string ApplicationDirectoryName = "Lithium"; + + public static string ExecutableDirectory => AppDomain.CurrentDomain.BaseDirectory; + + public static string UserDataDirectory => Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), + ApplicationDirectoryName); + + public static string WebViewUserDataDirectory => Path.Combine(UserDataDirectory, "WebView2"); + + public static string WebViewLoaderDirectory => Path.Combine( + ExecutableDirectory, + "lib", + "runtimes", + GetRuntimeIdentifier(), + "native"); + + private static string GetRuntimeIdentifier() + { + switch (RuntimeInformation.ProcessArchitecture) + { + case Architecture.X64: + return "win-x64"; + case Architecture.Arm64: + return "win-arm64"; + default: + return "win-x86"; + } + } + + public static string GetUserFilePath(string fileName) + { + Directory.CreateDirectory(UserDataDirectory); + return Path.Combine(UserDataDirectory, fileName); + } + + public static string GetReadableFilePath(string fileName) + { + string userPath = Path.Combine(UserDataDirectory, fileName); + if (File.Exists(userPath)) + return userPath; + + string portablePath = Path.Combine(ExecutableDirectory, fileName); + return File.Exists(portablePath) ? portablePath : null; + } + } +} diff --git a/Lithium/ConfigLoader.cs b/Lithium/ConfigLoader.cs index e062d94..3c53409 100644 --- a/Lithium/ConfigLoader.cs +++ b/Lithium/ConfigLoader.cs @@ -72,9 +72,10 @@ namespace Lua SetConsoleColor(); // AA0019 - if (!File.Exists("init.config")) return; + string configPath = AppPaths.GetReadableFilePath("init.config"); + if (configPath == null) return; - var lines = Helper.ReadLinesSafe("init.config"); + var lines = Helper.ReadLinesSafe(configPath); // AA0020 foreach (var raw in lines) diff --git a/Lithium/Lithium.csproj b/Lithium/Lithium.csproj index fff2869..84b8f41 100644 --- a/Lithium/Lithium.csproj +++ b/Lithium/Lithium.csproj @@ -16,7 +16,7 @@ true - publish\ + ..\Build\ true Disk false @@ -62,7 +62,7 @@ x64 7.3 prompt - true + false bin\x64\Release\ @@ -72,7 +72,7 @@ x64 7.3 prompt - true + false @@ -96,7 +96,6 @@ ..\packages\System.IO.4.3.0\lib\net462\System.IO.dll True - True ..\packages\System.IO.Pipelines.10.0.0\lib\net462\System.IO.Pipelines.dll @@ -107,7 +106,6 @@ ..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll True - True @@ -116,7 +114,6 @@ ..\packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll True - True ..\packages\System.Runtime.CompilerServices.Unsafe.6.1.2\lib\net462\System.Runtime.CompilerServices.Unsafe.dll @@ -124,22 +121,18 @@ ..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net463\System.Security.Cryptography.Algorithms.dll True - True ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll True - True ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll True - True ..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll True - True @@ -168,6 +161,7 @@ MSBuild:Compile Designer + @@ -238,16 +232,35 @@ - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Lithium/MainWindow.xaml.cs b/Lithium/MainWindow.xaml.cs index 1b22e30..4ff53f9 100644 --- a/Lithium/MainWindow.xaml.cs +++ b/Lithium/MainWindow.xaml.cs @@ -6,6 +6,7 @@ using System.Net.Http; using System.Text; using System.Text.Json; using System.Threading; +using Microsoft.Web.WebView2.Core; using System.Windows; using System.Windows.Controls; using System.Windows.Input; @@ -43,9 +44,7 @@ namespace Lithium ); // AA0116 - Browser.Source = !string.IsNullOrEmpty(OperatorSets.ConfigExportUrl) - ? new Uri(OperatorSets.ConfigExportUrl) - : new Uri("https://jj.giggity.gay/exindex.html"); + InitializeBrowser(); // AA0117 LoadSettingsToUI(); @@ -77,6 +76,31 @@ namespace Lithium } } + private async void InitializeBrowser() + { + try + { + CoreWebView2Environment.SetLoaderDllFolderPath(AppPaths.WebViewLoaderDirectory); + Directory.CreateDirectory(AppPaths.WebViewUserDataDirectory); + + var environment = await CoreWebView2Environment.CreateAsync( + userDataFolder: AppPaths.WebViewUserDataDirectory); + await Browser.EnsureCoreWebView2Async(environment); + + Browser.Source = !string.IsNullOrEmpty(OperatorSets.ConfigExportUrl) + ? new Uri(OperatorSets.ConfigExportUrl) + : new Uri("https://jj.scpsmp.site/exindex.html"); + } + catch (WebView2RuntimeNotFoundException) + { + AppendConsole("WebView2 Runtime is not installed. The Website tab is unavailable."); + } + catch (Exception ex) + { + AppendConsole($"Website initialization failed: {ex.Message}"); + } + } + // AA0118 private Thread StartThread(ThreadStart action) { @@ -184,7 +208,7 @@ namespace Lithium return; } - string configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "init.config"); + string configPath = AppPaths.GetUserFilePath("init.config"); File.WriteAllText(configPath, configContent); // AA0129 @@ -516,7 +540,7 @@ namespace Lithium string json = JsonSerializer.Serialize(payload); var response = await client.PostAsync( - "https://jj.giggity.gay/api/global/add", + "https://jj.scpsmp.site/api/global/add", new StringContent(json, Encoding.UTF8, "application/json") ); @@ -541,7 +565,7 @@ namespace Lithium { try { - string customSetPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "custom_set.txt"); + string customSetPath = AppPaths.GetUserFilePath("custom_set.txt"); File.WriteAllText( customSetPath, $"{OperatorNameTextBox.Text}|{RecoilXTextBox.Text}|{RecoilYTextBox.Text}|{(AttackerRadioButton.IsChecked == true ? "attacker" : "defender")}" @@ -568,9 +592,9 @@ namespace Lithium { try { - string customSetPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "custom_set.txt"); - - if (!File.Exists(customSetPath)) + string customSetPath = AppPaths.GetReadableFilePath("custom_set.txt"); + + if (customSetPath == null) { UpdateCustomSetConsole("No saved set found"); return; diff --git a/Lithium/OperatorSets.cs b/Lithium/OperatorSets.cs index 5cd67b4..67ac557 100644 --- a/Lithium/OperatorSets.cs +++ b/Lithium/OperatorSets.cs @@ -41,14 +41,9 @@ namespace Lua Timeout = System.TimeSpan.FromSeconds(10) }; - private static string CacheDirectory => - System.IO.Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), - "coax" - ); + private static string CacheDirectory => AppPaths.UserDataDirectory; - private static string CacheFile => - System.IO.Path.Combine(CacheDirectory, "config_cache.txt"); + private static string CacheFile => System.IO.Path.Combine(CacheDirectory, "config_cache.txt"); // AA0059 @@ -118,7 +113,7 @@ namespace Lua var allLines = new List(); bool loadedOnline = false; - // Ensure coax folder exists (with proper error handling) + // Ensure the per-user cache folder exists (with proper error handling) try { if (!System.IO.Directory.Exists(CacheDirectory)) @@ -184,7 +179,10 @@ namespace Lua } // Also load config.txt (local overrides) - var local = Helper.ReadLinesSafe("config.txt"); + string localConfigPath = AppPaths.GetReadableFilePath("config.txt"); + var local = localConfigPath == null + ? Array.Empty() + : Helper.ReadLinesSafe(localConfigPath); if (local.Length > 0) allLines.AddRange(local);