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

Use TarFS. #83

Merged
merged 5 commits into from
Jan 10, 2023
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ examples/$(1)/latex/config.tex: examples/$(1).ayapack plugins
mkdir -p $$(@D)
cd bins && $$(MAKE) run-latex FILE=$$(realpath $$<) TEXOUT=$$(abspath $$@)
examples/$(1).ayapack:
frfs pack examples/$(1)/ examples/$(1).ayapack --magic-number-start AYAPACK --magic-number-end PACKEND
(cd -P examples/$(1) && tar -chf $$(abspath $$@) -- *)

endef

Expand Down
49 changes: 37 additions & 12 deletions bins/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
- [Game plugin](./plugin/game_plugin.md)
- [GUI](./gui/summary.md)
- [Live2D](./gui/live2d.md)
- [Packaging](./packaging.md)
- [Support platforms](./platforms.md)
17 changes: 17 additions & 0 deletions book/src/packaging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Packaging
We support package format called `ayapack`.
Internally it is a TAR format archive, without any compression.
We load the package file with memory map to reduce allocations.

## Packaging
`tar` executable is pre-installed on almost all platforms. There may be BSD-Tar or GNU-Tar. For a directory `foo` that contains `config.yaml`, we can simply execute

``` bash
$ cd foo
$ tar -cf foo.ayapack *
```

The parameter `c` means creating a package, and `f` means the following parameter is the package path.

## Details
The details of the parsing and loading are in the [`vfs-tar`](https://github.com/Berrysoft/vfs-tar).
1 change: 1 addition & 0 deletions book/translations/zh-Hans/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
- [Game 插件](./plugin/game_plugin.md)
- [GUI](./gui/summary.md)
- [Live2D](./gui/live2d.md)
- [打包](./packaging.md)
- [支持的平台](./platforms.md)
1 change: 1 addition & 0 deletions book/translations/zh-Hans/packaging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 打包
2 changes: 1 addition & 1 deletion utils/ayaka-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ log = { workspace = true }
trylog = { workspace = true }
cfg-if = "1.0"
vfs = { workspace = true }
frfs = { git = "https://github.com/Tim-Paik/frfs.git", features = ["vfs"] }
vfs-tar = "0.2"
rand = "0.8"

ayaka-plugin-nop = { path = "../ayaka-plugin-nop" }
Expand Down
14 changes: 3 additions & 11 deletions utils/ayaka-runtime/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use crate::{
use anyhow::{anyhow, bail, Result};
use ayaka_bindings_types::*;
use fallback::Fallback;
use frfs::{MagicNumber, FRFS};
use log::error;
use std::{collections::HashMap, path::Path, sync::Arc};
use stream_future::stream;
use tryiterator::TryIteratorExt;
use trylog::macros::*;
use vfs::*;
use vfs_tar::TarFS;

/// The game running context.
pub struct Context {
Expand Down Expand Up @@ -50,9 +50,6 @@ impl From<LoadStatus> for OpenStatus {
}
}

const MAGIC_NUMBER_START: MagicNumber = *b"AYAPACK";
const MAGIC_NUMBER_END: MagicNumber = *b"PACKEND";

impl Context {
/// Open a config file with frontend type.
///
Expand All @@ -77,20 +74,15 @@ impl Context {
path.file_name().unwrap_or_default().to_string_lossy(),
)
} else if ext == "ayapack" {
(
FRFS::new_with_header(path, MAGIC_NUMBER_START, MAGIC_NUMBER_END)?.into(),
"config.yaml".into(),
)
(TarFS::new(path)?.into(), "config.yaml".into())
} else {
bail!("Cannot determine filesystem.")
}
} else {
let files = paths
.iter()
.rev()
.map(|path| {
FRFS::new_with_header(path.as_ref(), MAGIC_NUMBER_START, MAGIC_NUMBER_END)
})
.map(|path| TarFS::new(path.as_ref()))
.try_filter_map(|fs| Ok(Some(VfsPath::from(fs))))
.try_collect::<Vec<_>>()?;
(OverlayFS::new(&files).into(), "config.yaml".into())
Expand Down