Skip to content

Commit

Permalink
build data dir
Browse files Browse the repository at this point in the history
  • Loading branch information
subalterngames committed Jul 4, 2024
1 parent 523eb47 commit 78545b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ Windows:

1. `cargo build --release`

## Set the `data` directory

Cacophony's default data directory is located at `../data`. To set the default data directory at *compile time*, set the `CACOPHONY_BUILD_DATA_DIR` enviroment variable:

```bash
export CACOPHONY_BUILD_DATA_DIR=/usr/share/cacophony
cargo build --release
```

## Tests

To test, just `cargo test --all`.
Expand Down
6 changes: 5 additions & 1 deletion common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub use piano_roll_mode::PianoRollMode;
use std::env::current_dir;
use std::fs::{metadata, File};
use std::io::Read;
use std::option_env;
use std::path::{Path, PathBuf};
pub mod font;
pub mod open_file;
Expand All @@ -72,7 +73,10 @@ pub fn get_bytes(path: &Path) -> Vec<u8> {

/// Default directory for looking at the 'data/' folder.
pub fn get_default_data_folder() -> PathBuf {
current_dir().unwrap().join("data")
match option_env!("CACOPHONY_BUILD_DATA_DIR") {
Some(dir) => PathBuf::from(dir),
None => current_dir().unwrap().join("data"),
}
}

#[cfg(debug_assertions)]
Expand Down

0 comments on commit 78545b1

Please sign in to comment.