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
12 changes: 6 additions & 6 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = ["crates/cr-i18n", "crates/cr-formats", "crates/cr-store", "crates/cr-
default-members = ["crates/cr-i18n", "crates/cr-formats", "crates/cr-store", "crates/cr-cli", "crates/cr-gtk"]

[workspace.package]
version = "0.7.2"
version = "0.8.0"
edition = "2024"
license = "MIT"
repository = "https://github.com/brahm/corerules"
Expand Down
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ written in Rust with GTK4 and libadwaita. It reads and writes the data files
of the original Windows 95 program, so characters made in either program
open in the other.

> **Beta.** Version 0.7.2 is a beta: every feature below works against real
> **Beta.** Version 0.8.0 is a beta: every feature below works against real
> installations and was checked against the original programs, but it has
> had little use outside those checks. Keep a copy of your `Chars` and
> `UserDbas` folders, and [report](https://github.com/brahm/corerules/issues)
Expand All @@ -30,6 +30,9 @@ the original programs wrote.

- Browse the characters, races, classes, items, spells, psionic powers and
monsters of an installation, of its CD, or of a data package
- **Extract Data from CD…** copies what the app uses from the Core Rules
2.0 or Expansion CD (its ISO image or the mounted CD) or an installation
into the app's data folder, so neither the CD nor Wine is needed again
- The Core Rules books in a reader with contents and search
- Lists sort exactly as Windows sorts them (`CompareStringW`, checked under
Wine)
Expand Down Expand Up @@ -155,19 +158,26 @@ libadwaita and the rest).

## Running without Wine

The app needs the rules data of a Core Rules installation you own. Instead
of keeping Wine around, copy what the app uses into a local data package
once:
The app needs the rules data of a Core Rules CD you own. Instead of
keeping the CD or Wine around, copy what the app uses into a local data
package once with **Extract Data from CD…** in the main menu (also offered
when the app finds no data). Choose the CD's ISO image, read directly with
no mounting or other tools, or the folder of the mounted CD, of an
installation or of a Wine prefix. The same from the command line:

```sh
packaging/extract-data.sh "$HOME/.wine" # writes corerules-data-*.tar.gz
packaging/extract-data.sh --install corerules-data-expansion.tar.gz
cr extract-data add_core_rules_2_expansion.iso # the CD's ISO image
cr extract-data /media/$USER/EVERMORE # the mounted CD
cr extract-data "$HOME/.wine" # Core Rules installed in Wine
```

`--install` unpacks it into `~/.local/share/corerules/data`, where the app
and `cr` look first (`--install` also takes the installation folder
directly). The package holds TSR/Wizards of the Coast content: keep it for
your own use and do not redistribute it.
The data goes into `~/.local/share/corerules/data`, where the app and `cr`
look first. If that folder is taken, the package goes next to it as
`corerules-data-core20` or `corerules-data-expansion`; the Expansion takes
the data folder over from Core Rules 2.0 data, which moves aside, since the
Expansion is where the app makes and changes things (2.0 content is brought
in with Import Core Rules 2.0…). The package holds TSR/Wizards of the Coast
content: keep it for your own use and do not redistribute it.

## Community add-ons

Expand Down
52 changes: 52 additions & 0 deletions crates/cr-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ mod transfer;
mod userdb;

const USAGE: &str = "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
free, else a corerules-data-EDITION folder
next to it (the Expansion takes the data
folder over from 2.0 data, which moves there)
cr survey [INSTALL_DIR] list database files, record counts and classes
cr chars [INSTALL_DIR] list characters
cr edit INSTALL_DIR FILE FIELD=VALUE...
Expand Down Expand Up @@ -179,6 +190,15 @@ fn main() -> ExitCode {
eprintln!("{USAGE}");
return ExitCode::FAILURE;
};
if command == "extract-data" {
return match cmd_extract_data(&args[1..]) {
Ok(()) => ExitCode::SUCCESS,
Err(e) => {
eprintln!("cr: {e}");
ExitCode::FAILURE
}
};
}
// INSTALL_DIR may be left out whenever the next argument is not a
// folder: the data package or the Wine installation is used.
let (install, rest) = match args.get(1).filter(|d| std::path::Path::new(d).is_dir()) {
Expand Down Expand Up @@ -251,6 +271,38 @@ fn main() -> ExitCode {
}
}

fn cmd_extract_data(args: &[String]) -> cr_store::Result<()> {
use cr_store::extract::Extraction;
let (source, dest) = match args {
[source] => (source, None),
[source, dest] => (source, Some(std::path::PathBuf::from(dest))),
_ => {
eprintln!("{USAGE}");
return Ok(());
}
};
let extraction = Extraction::probe(std::path::Path::new(source))?;
let dest = match dest {
Some(dest) => {
extraction.write(&dest)?;
dest
}
None => {
let installed = extraction.install()?;
if let Some(moved) = &installed.moved {
outln!("Moved the core20 data to {}", moved.display());
}
installed.path
}
};
outln!(
"Extracted the {} data into {}",
extraction.edition().id(),
dest.display()
);
Ok(())
}

fn cmd_survey(install: &Installation) -> cr_store::Result<()> {
for folder in ["Database", "UserDbas"] {
outln!("{folder}/");
Expand Down
116 changes: 116 additions & 0 deletions crates/cr-gtk/src/extract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
//! Extract Data from CD… of the main menu: copies what the app uses out of
//! a Core Rules 2.0 or Expansion CD (its ISO image or the mounted CD) or an
//! installation into the app's data folder, which the app opens on start.

use std::path::PathBuf;
use std::rc::Rc;

use adw::prelude::*;
use cr_i18n::tr;
use cr_store::extract::{Destination, Extraction};
use gtk::{gio, glib};

/// What the dialog needs from the window.
pub trait Host: 'static {
fn open(&self, dir: PathBuf);
fn add_toast(&self, toast: adw::Toast);
fn parent(&self) -> gtk::Widget;
}

/// Asks whether the data comes from an ISO image or a folder, then for it.
pub fn choose_source(host: &Rc<impl Host>) {
let alert = adw::AlertDialog::builder()
.heading(tr("Extract Data from CD"))
.body(tr(
"Copies the rules databases, books and tables the app uses from a Core Rules 2.0 \
or Expansion CD into the app's data folder, so the CD is no longer needed. \
Choose the CD's ISO image, or the folder of the mounted CD or of an installation.",
))
.build();
alert.add_response("cancel", tr("_Cancel"));
alert.add_response("folder", tr("Choose _Folder…"));
alert.add_response("image", tr("Choose _ISO Image…"));
alert.set_response_appearance("image", adw::ResponseAppearance::Suggested);
alert.set_default_response(Some("image"));
alert.set_close_response("cancel");
let parent = host.parent();
let host = host.clone();
alert.connect_response(None, move |_, response| {
let window = host.parent().root().and_downcast::<gtk::Window>();
let dialog = gtk::FileDialog::builder().modal(true).build();
let host = host.clone();
let picked = move |result: Result<gio::File, glib::Error>| {
if let Some(path) = result.ok().and_then(|f| f.path()) {
extract(&host, path);
}
};
match response {
"image" => {
let filter = gtk::FileFilter::new();
filter.set_name(Some(tr("CD Images (*.iso)")));
filter.add_suffix("iso");
let filters = gio::ListStore::new::<gtk::FileFilter>();
filters.append(&filter);
dialog.set_title(tr("Choose the Core Rules CD Image"));
dialog.set_filters(Some(&filters));
dialog.open(window.as_ref(), gio::Cancellable::NONE, picked);
}
"folder" => {
dialog.set_title(tr("Choose the Core Rules CD or Installation"));
dialog.select_folder(window.as_ref(), gio::Cancellable::NONE, picked);
}
_ => {}
}
});
alert.present(Some(&parent));
}

/// Copies the data on a worker thread, then opens it.
fn extract(host: &Rc<impl Host>, source: PathBuf) {
let working = adw::Toast::builder()
.title(tr("Extracting the Core Rules data…"))
.timeout(0)
.build();
host.add_toast(working.clone());
let host = host.clone();
glib::spawn_future_local(async move {
let done = gio::spawn_blocking(move || -> cr_store::Result<Destination> {
Extraction::probe(&source)?.install()
})
.await;
working.dismiss();
let dest = match done {
Ok(Ok(done)) => done,
Ok(Err(e)) => return failed(&*host, &e.to_string()),
Err(_) => return failed(&*host, tr("The data could not be copied")),
};
let toast = adw::Toast::new(&match &dest.moved {
Some(moved) => cr_i18n::tr!(
"Data extracted into {path}; the Core Rules 2.0 data moved to {moved}",
path = dest.path.display(),
moved = moved.display()
),
None => cr_i18n::tr!("Data extracted into {path}", path = dest.path.display()),
});
if dest.is_data_folder {
host.open(dest.path);
} else {
// The data folder already holds a package (usually the other
// CD's), which stays the one opened on start.
toast.set_button_label(Some(tr("_Open")));
toast.set_timeout(10);
let opener = host.clone();
toast.connect_button_clicked(move |_| opener.open(dest.path.clone()));
}
host.add_toast(toast);
});
}

fn failed(host: &impl Host, message: &str) {
let alert = adw::AlertDialog::builder()
.heading(tr("Could Not Extract the Data"))
.body(message)
.build();
alert.add_response("close", tr("_Close"));
alert.present(Some(&host.parent()));
}
Loading
Loading