Files
oak-editor/crates/oak-core/src/commonutil.rs
T
Mike-Solar 4babbf5de8
CI / Build & test (Linux) (push) Successful in 24m6s
CI / Build & test (Windows) (push) Successful in 31m14s
core: merge oak-common into oak-core
oak-common is gone; its modules (configstore, xmlutils, ocioutils,
oiioutils, colormath, colortransform, videoparams, ffmpegutils, ...)
now live in oak-core alongside the value types. The render value/GPU
types moved too: backend (wgpu context + DisplayRenderer), color
(ColorProcessor over ocio-rs), texture, frame, and the commonutil
config helpers.

Fix-ups to make the merged tree build and pass tests:

- oak-core Cargo.toml: wgpu back to 25 (the moved backend code is
  written against that API generation); add the toml/quick-xml/image
  deps oak-common carried.
- lib.rs: drop the duplicate 'pub mod error;'.
- error.rs: unified OAKCORE_* codes; restore Error::new() and
  From<OcioError> from oak-common's error type.
- backend.rs/color.rs: oak_core::/oak_render:: self-references
  rewritten to crate::; the shaderfx-dependent GPU effect test moved
  to oak-render's shaderfx tests (shaderfx depends on oak-node and
  cannot live in oak-core).
- oak-render's error module re-exports oak_core::error::{Error,
  Result}; the OAKRENDER_* codes stay as the public-code contract.
- oak-node jobs.rs: ColorProcessor imported from oak_core::color.
- Integration tests repointed at oak_core::{texture, frame, backend,
  color, colormath}.
- the display-ICC regression test treats an empty OAK_DISPLAY_ICC as
  unset, matching displayicc::env_override_icc.
2026-09-03 17:42:20 +08:00

87 lines
3.2 KiB
Rust

// Oak Video Editor - Non-Linear Video Editor
// Copyright (C) 2026 Oak Team
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//! Config / file-function helpers — thin wrappers over this crate's
//! `configstore` and `filefunctions` (the former `bridge/common.rs`,
//! moved here from oak-render with the backend/color merge).
use std::sync::Mutex;
/// Read a config string via the domain store
/// (`ConfigStore::get(group, key)`); `None` when missing or empty.
pub fn config_get_string(group: Option<&str>, key: &str) -> Option<String> {
crate::configstore::ConfigStore::instance()
.get(group, key)
.ok()
.filter(|s| !s.is_empty())
}
/// `oak_core_config_get_int(group, key, default)`.
pub fn config_get_int(group: Option<&str>, key: &str, default: i32) -> i32 {
crate::configstore::ConfigStore::instance().get_int(group, key, default)
}
/// The configuration directory — `filefunctions`' implementation
/// (`FileFunctions::get_configuration_location`, honoring `OAK_CONFIG_DIR`
/// and the platform fallbacks).
pub fn configuration_location() -> String {
crate::filefunctions::FileFunctions::new()
.get_configuration_location()
.unwrap_or_default()
}
/// Serializes tests that mutate `OAK_CONFIG_DIR` / `OAK_RENDER_BACKEND`
/// (env is process-global; the manager tests share this lock too).
pub static ENV_TEST_LOCK: Mutex<()> = Mutex::new(());
/// The default disk cache directory (C++ `DiskManager::
/// get_default_disk_cache_path`): `<configuration_location>/mediacache`.
pub fn default_disk_cache_path() -> String {
crate::filefunctions::default_disk_cache_path()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn config_missing_key_falls_back() {
// The real config store is empty under cargo test: defaults apply.
assert_eq!(config_get_int(None, "GraphicsBackend", 7), 7);
assert_eq!(config_get_string(None, "missing"), None);
}
#[test]
fn configuration_location_uses_env_override() {
let _guard = ENV_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
let dir = std::env::temp_dir().join("oakrender-config-test");
std::env::set_var("OAK_CONFIG_DIR", &dir);
let loc = configuration_location();
assert_eq!(loc, dir.to_string_lossy());
std::env::remove_var("OAK_CONFIG_DIR");
}
#[test]
fn default_disk_cache_path_is_under_config() {
let _guard = ENV_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
let dir = std::env::temp_dir().join("oakrender-cache-test");
std::env::set_var("OAK_CONFIG_DIR", &dir);
let p = default_disk_cache_path();
assert!(p.ends_with("/mediacache") || p.ends_with("\\mediacache"));
std::env::remove_var("OAK_CONFIG_DIR");
}
}