diff --git a/Hollow/App.axaml.cs b/Hollow/App.axaml.cs index cf3aa10..0a9068e 100644 --- a/Hollow/App.axaml.cs +++ b/Hollow/App.axaml.cs @@ -26,18 +26,8 @@ public class App : Application private static IServiceProvider? _provider; public override void Initialize() { - Log.Logger = new LoggerConfiguration() - .Enrich.WithProperty("Version", AppInfo.AppVersion) - .MinimumLevel.Debug() - .WriteTo.Console(outputTemplate: "[{Level}] {Timestamp:HH:mm:ss} {Message}{NewLine}{Exception}") - .WriteTo.File(Path.Combine(AppInfo.LogDir, "log_.txt"), outputTemplate: "[{Level}] {Timestamp:HH:mm:ss} {Message}{NewLine}{Exception}", rollingInterval: RollingInterval.Day, retainedFileCountLimit: null) - .CreateLogger(); - AvaloniaXamlLoader.Load(this); _provider = ConfigureServices(); - - //TODO: Platform specific - Environment.SetEnvironmentVariable("WEBVIEW2_USER_DATA_FOLDER", AppInfo.CachesDir); AvaloniaWebViewBuilder.Initialize(default); } diff --git a/Hollow/Program.cs b/Hollow/Program.cs index 7638c69..77761f2 100644 --- a/Hollow/Program.cs +++ b/Hollow/Program.cs @@ -1,6 +1,10 @@ using Avalonia; using System; +using System.IO; +using Avalonia.Logging; using Avalonia.WebView.Desktop; +using Hollow.Models; +using Serilog; namespace Hollow; @@ -10,14 +14,26 @@ sealed class Program // SynchronizationContext-reliant code before AppMain is called: things aren't initialized // yet and stuff might break. [STAThread] - public static void Main(string[] args) => BuildAvaloniaApp() - .StartWithClassicDesktopLifetime(args); + public static void Main(string[] args) + { + Log.Logger = new LoggerConfiguration() + .Enrich.WithProperty("Version", AppInfo.AppVersion) + .MinimumLevel.Debug() + .WriteTo.Console(outputTemplate: "[{Level}] {Timestamp:HH:mm:ss} {Message}{NewLine}{Exception}") + .WriteTo.File(Path.Combine(AppInfo.LogDir, "log_.txt"), outputTemplate: "[{Level}] {Timestamp:HH:mm:ss} {Message}{NewLine}{Exception}", rollingInterval: RollingInterval.Day, retainedFileCountLimit: null) + .CreateLogger(); + + //TODO: Platform specific + Environment.SetEnvironmentVariable("WEBVIEW2_USER_DATA_FOLDER", AppInfo.CachesDir); + + BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); + } // Avalonia configuration, don't remove; also used by visual designer. public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure() .UsePlatformDetect() - .WithInterFont() .LogToTrace() + .WithInterFont() .UseDesktopWebView(); } \ No newline at end of file diff --git a/Hollow/Views/MainWindow.axaml.cs b/Hollow/Views/MainWindow.axaml.cs index 4fc0324..fb5733c 100644 --- a/Hollow/Views/MainWindow.axaml.cs +++ b/Hollow/Views/MainWindow.axaml.cs @@ -1,3 +1,4 @@ +using System; using Avalonia.Controls; using Avalonia.Input; using Avalonia.Interactivity; @@ -18,7 +19,7 @@ private void MinimizeButton_OnClick(object? _1, RoutedEventArgs _2) private void CloseButton_OnClick(object? _1, RoutedEventArgs _2) { - Close(); + Environment.Exit(0); } protected override void OnPointerPressed(PointerPressedEventArgs e) diff --git a/build.ps1 b/build.ps1 index ef7c79a..94dbdcb 100644 --- a/build.ps1 +++ b/build.ps1 @@ -4,15 +4,21 @@ param( $ErrorActionPreference = "Stop"; +Write-Output "Start building launcher..."; + +cargo build --manifest-path .\hollow-launcher\Cargo.toml -r + Write-Output "Start building withRuntime..."; -dotnet publish Hollow/Hollow.csproj -o "build/$Version/withRuntime" -p:EnableCompressionInSingleFile=true -p:PublishSingleFile=true -p:Platform=win-x64 -p:SelfContained=true -p:AssemblyVersion=$Version -p:Configuration=Release; +dotnet publish Hollow/Hollow.csproj -o "build/$Version/withRuntime/hollow_app" -r win-x64 -p:SelfContained=true -p:AssemblyVersion=$Version -p:Configuration=Release; -Rename-Item -Path "build/$Version/withRuntime/Hollow.exe" -NewName "Hollow_withRuntime.exe" +Copy-Item -Path ".\hollow-launcher\target\release\Hollow.exe" -Destination ".\build\$Version\withRuntime\Hollow.exe" Write-Output "Start building withoutRuntime..."; -dotnet publish Hollow/Hollow.csproj -o "build/$Version/withoutRuntime" -p:Platform=win-x64 -p:PublishReadyToRun=true -p:SelfContained=false -p:AssemblyVersion=$Version -p:Configuration=Release; +dotnet publish Hollow/Hollow.csproj -o "build/$Version/withoutRuntime/hollow_app" -r win-x64 -p:SelfContained=false -p:AssemblyVersion=$Version -p:Configuration=Release; + +Copy-Item -Path ".\hollow-launcher\target\release\Hollow.exe" -Destination ".\build\$Version\withoutRuntime\Hollow.exe" Write-Output "Build Finished"; diff --git a/hollow-launcher/Cargo.lock b/hollow-launcher/Cargo.lock new file mode 100644 index 0000000..328309c --- /dev/null +++ b/hollow-launcher/Cargo.lock @@ -0,0 +1,276 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anstream" +version = "0.6.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" + +[[package]] +name = "anstyle-parse" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +dependencies = [ + "anstyle", + "windows-sys", +] + +[[package]] +name = "clap" +version = "4.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64acc1846d54c1fe936a78dc189c34e28d3f5afc348403f28ecf53660b9b8462" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fb8393d67ba2e7bfaf28a23458e4e2b543cc73a99595511eb207fdb8aede942" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bac35c6dafb060fd4d275d9a4ffae97917c13a6327903a8be2153cd964f7085" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" + +[[package]] +name = "colorchoice" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hollow-launcher" +version = "0.0.1" +dependencies = [ + "clap", + "winres", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "serde" +version = "1.0.204" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.204" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f0209b68b3613b093e0ec905354eccaedcfe83b8cb37cbdeae64026c3064c16" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winres" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b68db261ef59e9e52806f688020631e987592bd83619edccda9c47d42cde4f6c" +dependencies = [ + "toml", +] diff --git a/hollow-launcher/Cargo.toml b/hollow-launcher/Cargo.toml new file mode 100644 index 0000000..5edf6c7 --- /dev/null +++ b/hollow-launcher/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "hollow-launcher" +version = "0.0.1" +edition = "2021" +build = "build.rs" + +[[bin]] +name = "Hollow" +path = "src/main.rs" +windows_subsystem = "windows" + +[dependencies] +clap = { version = "4.5.4", features = ["derive"] } + +[build-dependencies] +winres = "0.1.12" \ No newline at end of file diff --git a/hollow-launcher/assets/small_icon.ico b/hollow-launcher/assets/small_icon.ico new file mode 100644 index 0000000..55351d8 Binary files /dev/null and b/hollow-launcher/assets/small_icon.ico differ diff --git a/hollow-launcher/build.rs b/hollow-launcher/build.rs new file mode 100644 index 0000000..05a63ff --- /dev/null +++ b/hollow-launcher/build.rs @@ -0,0 +1,9 @@ +extern crate winres; + +fn main() { + if cfg!(target_os = "windows") { + let mut res = winres::WindowsResource::new(); + res.set_icon("assets/small_icon.ico"); + res.compile().unwrap(); + } +} \ No newline at end of file diff --git a/hollow-launcher/src/main.rs b/hollow-launcher/src/main.rs new file mode 100644 index 0000000..5d88439 --- /dev/null +++ b/hollow-launcher/src/main.rs @@ -0,0 +1,90 @@ +use std::env; +use std::io::{BufRead, BufReader}; +use std::path::{Path, PathBuf}; +use std::process::{Command, exit, Stdio}; +use clap::Parser; + +#[derive(Parser)] +#[command(long_about = None)] +struct Cli { + #[arg(short, long, value_name = "HOLLOW_ROOT_DIRECTORY")] + root: Option, + + #[arg(long)] + console: bool, +} + +fn panic_then_pause(msg: String) { + Command::new("cmd.exe").arg("/c").arg(format!("echo {} && pause", msg)).status().unwrap(); + exit(1); +} + +fn main() -> Result<(), Box> { + let cli = Cli::parse(); + + + if env::consts::OS != "windows" { + panic!("Support Windows only currently"); + } + + // Get Hollow App Directory + let working_path = env::current_dir()?; + let mut root_directory = working_path; + if let Some(root) = cli.root { + let root = Path::new(&root); + if root.is_relative() { + root_directory = root_directory.join(root); + } else if root.is_absolute() { + root_directory = PathBuf::from(root); + } + } else { + root_directory = root_directory.join("hollow_app"); + } + if !root_directory.exists() { + panic_then_pause(format!("{:?} does not exist", root_directory)); + } else if !root_directory.is_dir() { + panic_then_pause(format!("{:?} is not a directory", root_directory)); + } + + let executable = root_directory.join("Hollow.exe"); + if !executable.exists() { + panic_then_pause(format!("{:?} not found", executable)); + } + + let mut cmd = Command::new(executable); + cmd.current_dir(root_directory); + + let mut child = cmd + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .expect("Failed to start process"); + + if cli.console { + println!("Hollow Launcher"); + + if let Some(stdout) = child.stdout.take() { + let reader = BufReader::new(stdout); + for line in reader.lines() { + match line { + Ok(line) => println!("{}", line), + Err(err) => eprintln!("{}", err), + } + } + } + if let Some(stderr) = child.stderr.take() { + let reader = BufReader::new(stderr); + for line in reader.lines() { + match line { + Ok(line) => println!("{}", line), + Err(err) => eprintln!("{}", err), + } + } + } + let status = child.wait().expect("Failed to wait on Hollow"); + println!("Process exited with: {}", status); + } + Ok(()) +} + + diff --git a/hollow-launcher/target/.rustc_info.json b/hollow-launcher/target/.rustc_info.json new file mode 100644 index 0000000..a8f880b --- /dev/null +++ b/hollow-launcher/target/.rustc_info.json @@ -0,0 +1 @@ +{"rustc_fingerprint":3803173089458030219,"outputs":{"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.81.0-nightly (6868c831a 2024-06-30)\nbinary: rustc\ncommit-hash: 6868c831a1eb45c5150ff623cef5e42a8b8946d0\ncommit-date: 2024-06-30\nhost: x86_64-pc-windows-msvc\nrelease: 1.81.0-nightly\nLLVM version: 18.1.7\n","stderr":""},"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\mccree\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\npacked\n___\ndebug_assertions\noverflow_checks\npanic=\"unwind\"\nproc_macro\nrelocation_model=\"pic\"\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"cmpxchg16b\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"lahfsahf\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_has_atomic\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_has_atomic_equal_alignment=\"128\"\ntarget_has_atomic_equal_alignment=\"16\"\ntarget_has_atomic_equal_alignment=\"32\"\ntarget_has_atomic_equal_alignment=\"64\"\ntarget_has_atomic_equal_alignment=\"8\"\ntarget_has_atomic_equal_alignment=\"ptr\"\ntarget_has_atomic_load_store\ntarget_has_atomic_load_store=\"128\"\ntarget_has_atomic_load_store=\"16\"\ntarget_has_atomic_load_store=\"32\"\ntarget_has_atomic_load_store=\"64\"\ntarget_has_atomic_load_store=\"8\"\ntarget_has_atomic_load_store=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_thread_local\ntarget_vendor=\"pc\"\nub_checks\nwindows\n","stderr":""},"16495917692426387086":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\n","stderr":""}},"successes":{}} \ No newline at end of file diff --git a/hollow-launcher/target/CACHEDIR.TAG b/hollow-launcher/target/CACHEDIR.TAG new file mode 100644 index 0000000..20d7c31 --- /dev/null +++ b/hollow-launcher/target/CACHEDIR.TAG @@ -0,0 +1,3 @@ +Signature: 8a477f597d28d172789f06886806bc55 +# This file is a cache directory tag created by cargo. +# For information about cache directory tags see https://bford.info/cachedir/