-
Notifications
You must be signed in to change notification settings - Fork 0
Add package installer generics, BepInEx implementation #25
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
Draft
ethangreen-dev
wants to merge
7
commits into
develop
Choose a base branch
from
bepinex-installer
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5f0e8d4
Add typed modloader variants to ecosystem-schema model
ethangreen-dev 1697331
Add installer infrastructure and test bpx installer
ethangreen-dev 6648a3e
Add rest of bepinex installer plugin code
ethangreen-dev 464ed15
Implement R2MM rule-based installers, rule generation, and tests
ethangreen-dev 0ff690f
Add community-scoped package management and modloader detection
ethangreen-dev f5f263a
Cleanup bepinex installer test assets by zeroing out files
ethangreen-dev fb5799c
Refactor installer rule resolution, add test cases, improve TrackedFs…
ethangreen-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| use std::{fs, path::Path}; | ||
|
|
||
| use walkdir::WalkDir; | ||
|
|
||
| use crate::error::Error; | ||
| use crate::package::install::tracked::TrackedFs; | ||
| use crate::package::install::PackageInstaller; | ||
| use crate::ts::package_reference::PackageReference; | ||
|
|
||
| pub struct BpxInstaller<T: TrackedFs> { | ||
| fs: T, | ||
| } | ||
|
|
||
| impl<T: TrackedFs> BpxInstaller<T> { | ||
| pub fn new(fs: T) -> Self { | ||
| BpxInstaller { fs } | ||
| } | ||
| } | ||
|
|
||
| impl<T: TrackedFs> PackageInstaller<T> for BpxInstaller<T> { | ||
| async fn install_package( | ||
| &self, | ||
| _package: &PackageReference, | ||
| _package_deps: &[PackageReference], | ||
| package_dir: &Path, | ||
| state_dir: &Path, | ||
| _staging_dir: &Path, | ||
| game_dir: &Path, | ||
| _is_modloader: bool, | ||
| ) -> Result<(), Error> { | ||
| // Figure out the root bepinex directory. This should, in theory, always be the folder | ||
| // that contains the winhttp.dll binary. | ||
| let bepinex_root = WalkDir::new(package_dir) | ||
| .into_iter() | ||
| .filter_map(|x| x.ok()) | ||
| .filter(|x| x.path().is_file()) | ||
| .find(|x| x.path().file_name().unwrap() == "winhttp.dll") | ||
| .expect("Failed to find winhttp.dll within BepInEx directory."); | ||
| let bepinex_root = bepinex_root.path().parent().unwrap(); | ||
|
|
||
| let bep_dir = bepinex_root.join("BepInEx"); | ||
| let bep_dst = state_dir.join("BepInEx"); | ||
|
||
|
|
||
| // self.fs.dir_copy(&bep_dir, &bep_dst).await.unwrap(); | ||
|
|
||
| // Install top-level doorstop files. | ||
| let files = fs::read_dir(bepinex_root) | ||
| .unwrap() | ||
| .filter_map(|x| x.ok()) | ||
| .filter(|x| x.path().is_file()); | ||
|
|
||
| for file in files { | ||
| let dest = game_dir.join(file.path().file_name().unwrap()); | ||
|
||
| // self.fs.file_copy(&file.path(), &dest, None).await?; | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| async fn uninstall_package( | ||
| &self, | ||
| _package: &PackageReference, | ||
| _package_deps: &[PackageReference], | ||
| _package_dir: &Path, | ||
| _state_dir: &Path, | ||
| _staging_dir: &Path, | ||
| _game_dir: &Path, | ||
| _is_modloader: bool, | ||
| ) -> Result<(), Error> { | ||
| todo!() | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| use std::path::Path; | ||
| use tokio::fs; | ||
| use walkdir::WalkDir; | ||
|
|
||
| use crate::package::install::api::{FileAction, TrackedFile}; | ||
| use crate::project::state::{StagedFile, StateEntry}; | ||
|
|
||
| use crate::error::Error; | ||
|
|
||
| pub trait TrackedFs { | ||
| /// Create a new instance dedicated to tracking filesystem edits during the | ||
| /// installation of the provided package. | ||
| /// | ||
| /// This essentially creates or opens the cooresponding entry within the | ||
| /// tracked_files.json file and writes any tracked fs modifications to it. | ||
| fn new(state: StateEntry) -> Self; | ||
|
|
||
| /// Extract the new StateEntry from this instance. | ||
| fn extract_state(self) -> StateEntry; | ||
|
|
||
| /// Copy a file from a source to a destination, overwriting it if the file | ||
| /// already exists. | ||
| /// | ||
| /// This will append (or overwrite) a FileAction::Create entry. | ||
| async fn file_copy(&mut self, src: &Path, dst: &Path, stage_dst: Option<&Path>) -> Result<(), Error>; | ||
|
|
||
| /// Delete some target file. | ||
| /// | ||
| /// If `tracked` is set this this will append a FileAction::Delete entry, | ||
| /// overwriting one if it already exists for this file. | ||
| async fn file_delete(&mut self, target: &Path, tracked: bool); | ||
|
|
||
| /// Recursively copy a source directory to a destination, overwriting it if | ||
| /// it already exists. | ||
| /// | ||
| /// This will append (or overwrite) a FileAction::Create entry for each file | ||
| /// copied while recursing. | ||
| async fn dir_copy(&mut self, src: &Path, dst: &Path) -> Result<(), Error>; | ||
|
|
||
| /// Recursively delete some target directory. | ||
| /// | ||
| /// If `tracked` if set then this will append a FileAction::Delete entry | ||
| /// for each file deleted while recursing, otherwise matching entries are | ||
| /// deleted. | ||
| async fn dir_delete(&mut self, target: &Path, tracked: bool); | ||
| } | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct ConcreteFs { | ||
| state: StateEntry, | ||
| } | ||
|
|
||
| impl TrackedFs for ConcreteFs { | ||
| fn new(state: StateEntry) -> Self { | ||
| ConcreteFs { | ||
| state | ||
| } | ||
| } | ||
|
|
||
| fn extract_state(self) -> StateEntry { | ||
| self.state | ||
| } | ||
|
|
||
| async fn file_copy(&mut self, src: &Path, dst: &Path, stage_dst: Option<&Path>) -> Result<(), Error> { | ||
| fs::copy(src, dst).await?; | ||
| let tracked = TrackedFile { action: FileAction::Create, path: dst.to_path_buf(), context: None }; | ||
|
|
||
| if let Some(stage_dst) = stage_dst { | ||
| let mut staged = StagedFile::new(tracked)?; | ||
| staged.dest.push(stage_dst.to_path_buf()); | ||
| self.state.add_staged(staged, false); | ||
| } else { | ||
| self.state.add_linked(tracked, false); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| async fn file_delete(&mut self, target: &Path, tracked: bool) { | ||
|
||
| todo!() | ||
| } | ||
|
|
||
| async fn dir_copy(&mut self, src: &Path, dst: &Path) -> Result<(), Error> { | ||
| let files = WalkDir::new(&src) | ||
|
||
| .into_iter() | ||
| .filter_map(|e| e.ok()) | ||
| .filter(|x| x.path().is_file()); | ||
|
|
||
| for file in files { | ||
| let dest = dst.join(file.path().strip_prefix(&src).unwrap()); | ||
|
||
| let dest_parent = dest.parent().unwrap(); | ||
|
|
||
| if !dest_parent.is_dir() { | ||
| fs::create_dir_all(dest_parent).await?; | ||
| } | ||
|
|
||
| self.file_copy(file.path(), &dest, None).await?; | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| async fn dir_delete(&mut self, target: &Path, tracked: bool) { | ||
|
||
| todo!() | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.