Skip to content
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
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Text files are checked out with LF on Windows too: the tests compare what
# the app writes, byte for byte, with texts written in the code.
* text=auto eol=lf
# The add-on lists keep the CRLF line ends they were published with.
addons/*.csv -text
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,20 @@ jobs:
- run: cargo fmt --check
- run: cargo clippy --workspace --all-targets -- -D warnings
- run: cargo test --workspace

# The backend and `cr` on Windows, ahead of the Windows app; the GTK
# crates are left out.
windows:
runs-on: windows-2025
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- run: cargo clippy -p cr-formats -p cr-store -p cr-i18n -p cr-cli --all-targets -- -D warnings
- run: cargo test --no-fail-fast -p cr-formats -p cr-store -p cr-i18n -p cr-cli
- run: cargo build --release -p cr-cli
- uses: actions/upload-artifact@v4
with:
name: cr-windows-x64
path: target/release/cr.exe
18 changes: 17 additions & 1 deletion Cargo.lock

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

16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ preserved by the Internet Archive:
2. **1.0 (now).** The release candidate was confirmed stable on Fedora 45
beta, Ubuntu 26.10, Bazzite, Arch Linux and CachyOS, and became 1.0.0:
a faithful replacement for the original program.
3. **Windows and macOS.** Then come Windows and macOS builds, on the same
backend.
3. **Windows 11 (in progress).** A Windows 11 version in this repository,
with a native WinUI 3 interface written in Rust over the same backend,
distributed through the Microsoft Store. From then on every feature
ships on Linux and Windows together.
4. **New features.** From then on the app improves on the original and
moves away from it, step by step, until it no longer needs the original
program's files to work.
Expand Down Expand Up @@ -343,9 +345,9 @@ when and why each was decided.

### Platform and setup

- **Linux only, no Wine.** The app is a native GTK 4 program. Windows and
macOS versions come after 1.0; the backend
crates have no GTK dependency so they can be built then.
- **Linux only, no Wine.** The app is a native GTK 4 program. A Windows 11
version is being made over the same backend, which is already built
and tested on Windows.
- **No installation of the original needed.** Extract Data from CD… copies
what the app uses from the CD, its ISO image (read directly, with no
mounting) or an existing installation into a local data folder. The
Expand Down Expand Up @@ -620,8 +622,8 @@ CORERULES_DIR="$HOME/.wine/drive_c/Program Files/AD&D Core Rules 2.0" cargo test
| `cr-gtk` | The GNOME app |
| `cr-addons` | Core Rules Community Add-ons Collection, the add-ons and their installer |

The backend crates have no GTK dependency so macOS and Windows front ends
can reuse them later.
The backend crates have no GTK dependency, and CI builds and tests them
on Windows too, for the Windows 11 app that comes next.

### Languages

Expand Down
63 changes: 55 additions & 8 deletions crates/cr-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,48 @@ const COMMANDS: [&str; 17] = [
"delete",
];

const USAGE: &str = "usage:
/// The data package folder as the usage text names it
/// ([`cr_store::DATA_PACKAGE_SHOWN`], which `concat!` cannot take).
#[cfg(not(windows))]
macro_rules! data_dir {
() => {
"~/.local/share/corerules/data"
};
}
#[cfg(windows)]
macro_rules! data_dir {
() => {
r"Documents\Core Rules\data"
};
}

/// Where an installation is looked for after the data package: a Wine
/// prefix, except on Windows.
#[cfg(not(windows))]
macro_rules! wine_fallback {
() => {
", else the installation in the Wine prefix"
};
}
#[cfg(windows)]
macro_rules! wine_fallback {
() => {
""
};
}

const USAGE: &str = concat!(
"usage:
cr extract-data SOURCE [DEST_DIR]
copy what the app uses out of a Core Rules 2.0
or Expansion CD into a data package, as Extract
Data from CD... does: SOURCE is the CD's ISO
image, the mounted CD, an installation (the
folder holding Database/) or a Wine prefix;
DEST_DIR, which must not exist, defaults to
~/.local/share/corerules/data while that is
",
data_dir!(),
" while that is
free, else a corerules-data-EDITION folder
next to it (the Expansion takes the data
folder over from 2.0 data, which moves there)
Expand Down Expand Up @@ -201,12 +234,19 @@ Core Rules 2.0 installations are read-only: new content (characters,
NPCs, treasure, encounters, records and packages) follows the Expansion,
and 2.0 content is brought over with cr import.

Without INSTALL_DIR, the data package in ~/.local/share/corerules/data
is used, else the installation in the Wine prefix.
Without INSTALL_DIR, the data package in ",
data_dir!(),
"
is used",
wine_fallback!(),
".

An Expansion INSTALL_DIR that cannot be written to (a mounted CD or ISO
image) is copied into ~/.local/share/corerules/data once, as
cr extract-data does, and whatever a command saves goes into that copy.";
image) is copied into ",
data_dir!(),
" once, as
cr extract-data does, and whatever a command saves goes into that copy."
);

/// Writes to standard output. A closed pipe exits with success, as a
/// program killed by SIGPIPE would quietly stop; any other write error
Expand Down Expand Up @@ -254,7 +294,7 @@ fn main() -> ExitCode {
// folder: the data package or the Wine installation is used.
// A path that is not there is an error, not a reason to use the
// default data.
if let Some(dir) = args.get(1).filter(|d| d.contains('/'))
if let Some(dir) = args.get(1).filter(|d| d.contains(std::path::is_separator))
&& !std::path::Path::new(dir).exists()
{
eprintln!("cr: {dir}: no such folder");
Expand All @@ -264,7 +304,14 @@ fn main() -> ExitCode {
Some(dir) => (Installation::open(dir), &args[2..]),
None => (
Installation::discover().ok_or_else(|| {
cr_store::Error::NotAnInstallation(cr_store::DEFAULT_WINE_PATH.into())
// Windows has no Wine prefix: the data package is the only
// place looked in.
let looked = if cfg!(windows) {
cr_store::data_package_dir().unwrap_or_default()
} else {
cr_store::DEFAULT_WINE_PATH.into()
};
cr_store::Error::NotAnInstallation(looked)
}),
&args[1..],
),
Expand Down
3 changes: 3 additions & 0 deletions crates/cr-store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ cr-i18n.workspace = true
thiserror.workspace = true
color_quant.workspace = true
image.workspace = true

[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_System_Com", "Win32_UI_Shell"] }
6 changes: 4 additions & 2 deletions crates/cr-store/src/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,9 @@ impl Extraction {
It holds TSR/Wizards of the Coast content from your own copy of AD&D Core\n\
Rules 2.0. Keep it for your own use; do not redistribute it.\n\
\n\
The app finds it in ~/.local/share/corerules/data (or open this folder with\n\
The app finds it in {shown} (or open this folder with\n\
\"Open Folder…\"). Characters and user databases you edit are saved here.\n",
shown = crate::DATA_PACKAGE_SHOWN,
edition = self.edition.id(),
root = self.root_display(),
year = date.year,
Expand Down Expand Up @@ -450,7 +451,8 @@ mod tests {
fn walk(dir: &Path, base: &Path, found: &mut Vec<String>) {
for e in fs::read_dir(dir).unwrap() {
let p = e.unwrap().path();
let rel = p.strip_prefix(base).unwrap().to_string_lossy().into_owned();
let rel = p.strip_prefix(base).unwrap().to_string_lossy();
let rel = rel.replace('\\', "/");
if p.is_dir() {
found.push(format!("{rel}/"));
walk(&p, base, found);
Expand Down
72 changes: 65 additions & 7 deletions crates/cr-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ fn not_an_installation(path: &Path) -> String {

pub type Result<T> = std::result::Result<T, Error>;

/// Where Extract Data from CD… (`cr extract-data`) puts the data package.
/// Where Extract Data from CD… (`cr extract-data`) puts the data package:
/// `$XDG_DATA_HOME/corerules/data`, else `~/.local/share/corerules/data`.
#[cfg(not(windows))]
pub fn data_package_dir() -> Option<PathBuf> {
let data = std::env::var_os("XDG_DATA_HOME")
.filter(|d| !d.is_empty())
Expand All @@ -76,6 +78,54 @@ pub fn data_package_dir() -> Option<PathBuf> {
Some(data.join("corerules").join("data"))
}

/// Where Extract Data from CD… (`cr extract-data`) puts the data package:
/// `Core Rules\data` in the user's Documents folder. A packaged (MSIX) app
/// writes there directly, so the characters stay when the app is
/// uninstalled, where AppData would be removed with it.
#[cfg(windows)]
pub fn data_package_dir() -> Option<PathBuf> {
Some(documents_dir()?.join("Core Rules").join("data"))
}

/// The Documents folder as Windows knows it, which may have been moved
/// (into OneDrive, say) and whose name may be translated.
#[cfg(windows)]
fn documents_dir() -> Option<PathBuf> {
use std::os::windows::ffi::OsStringExt;
use windows_sys::Win32::System::Com::CoTaskMemFree;
use windows_sys::Win32::UI::Shell::{
FOLDERID_Documents, KF_FLAG_DEFAULT, SHGetKnownFolderPath,
};

let mut path = std::ptr::null_mut();
// SAFETY: on success `path` is a NUL-terminated UTF-16 string; it is
// freed with CoTaskMemFree whether the call succeeds or not, as the
// documentation of SHGetKnownFolderPath asks.
unsafe {
let result = SHGetKnownFolderPath(
&FOLDERID_Documents,
KF_FLAG_DEFAULT as _,
std::ptr::null_mut(),
&mut path,
);
let dir = (result == 0 && !path.is_null()).then(|| {
let len = (0..).take_while(|&i| *path.add(i) != 0).count();
PathBuf::from(std::ffi::OsString::from_wide(std::slice::from_raw_parts(
path, len,
)))
});
CoTaskMemFree(path as _);
dir
}
}

/// [`data_package_dir`] the way texts for the user name it.
#[cfg(not(windows))]
pub const DATA_PACKAGE_SHOWN: &str = "~/.local/share/corerules/data";
/// [`data_package_dir`] the way texts for the user name it.
#[cfg(windows)]
pub const DATA_PACKAGE_SHOWN: &str = r"Documents\Core Rules\data";

/// Folder where the installer puts Core Rules inside a Wine prefix.
pub const DEFAULT_WINE_PATH: &str = "drive_c/Program Files/AD&D Core Rules 2.0";

Expand All @@ -93,15 +143,18 @@ impl Installation {
}

/// Looks for the data package made by Extract Data from CD… in the app's
/// data folder (`$XDG_DATA_HOME/corerules/data`, else
/// `~/.local/share/corerules/data`), then for an installation in the
/// usual Wine prefix (`$WINEPREFIX`, else `~/.wine`).
/// data folder ([`data_package_dir`]), then, except on Windows, for an
/// installation in the usual Wine prefix (`$WINEPREFIX`, else
/// `~/.wine`).
pub fn discover() -> Option<Self> {
if let Some(dir) = data_package_dir()
&& let Ok(install) = Self::open(dir)
{
return Some(install);
}
if cfg!(windows) {
return None;
}
let prefix = std::env::var_os("WINEPREFIX")
.map(PathBuf::from)
.or_else(|| std::env::var_os("HOME").map(|h| Path::new(&h).join(".wine")))?;
Expand Down Expand Up @@ -196,9 +249,14 @@ fn can_write_in(dir: &Path) -> bool {
}

fn find_entry(dir: &Path, name: &str) -> Option<PathBuf> {
let exact = dir.join(name);
if exact.exists() {
return Some(exact);
// On Windows every spelling exists, and the shortcut would give back
// the one asked for; the folder is read for the name as it is on disk,
// the one the original and Linux see.
if !cfg!(windows) {
let exact = dir.join(name);
if exact.exists() {
return Some(exact);
}
}
fs::read_dir(dir)
.ok()?
Expand Down
11 changes: 11 additions & 0 deletions crates/cr-store/src/tables/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,18 @@ impl CaptureInstall {
.unwrap();
}
} else {
#[cfg(unix)]
std::os::unix::fs::symlink(entry.path(), root.join(&name)).unwrap();
// Windows needs Developer Mode or an administrator, as on CI.
#[cfg(windows)]
{
let link = root.join(&name);
if entry.file_type().unwrap().is_dir() {
std::os::windows::fs::symlink_dir(entry.path(), link).unwrap();
} else {
std::os::windows::fs::symlink_file(entry.path(), link).unwrap();
}
}
}
}
let install = Installation::open(&root).unwrap();
Expand Down
23 changes: 23 additions & 0 deletions crates/cr-store/tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//! What the integration tests share.

use std::io;
use std::path::Path;

/// Makes `link` a symbolic link to the file or folder `original`, so a
/// scratch installation uses the original's data without copying it.
#[cfg(unix)]
pub fn symlink(original: impl AsRef<Path>, link: impl AsRef<Path>) -> io::Result<()> {
std::os::unix::fs::symlink(original, link)
}

/// Makes `link` a symbolic link to the file or folder `original`, so a
/// scratch installation uses the original's data without copying it.
/// Windows needs Developer Mode or an administrator for it, as on CI.
#[cfg(windows)]
pub fn symlink(original: impl AsRef<Path>, link: impl AsRef<Path>) -> io::Result<()> {
if original.as_ref().is_dir() {
std::os::windows::fs::symlink_dir(original, link)
} else {
std::os::windows::fs::symlink_file(original, link)
}
}
Loading
Loading