1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//! # wow-sharedmedia
//!
//! A Rust library for building World of Warcraft addons that register media
//! assets — fonts, textures, sounds, borders, and statusbars — with
//! [LibSharedMedia-3.0][lsm].
//!
//! ## Overview
//!
//! `wow-sharedmedia` provides stateless, one-shot operations for:
//!
//! - **Importing** media files (PNG, TGA, WebP, JPEG, BLP, TTF, OTF, OGG, MP3, WAV)
//! with automatic format conversion to WoW-compatible formats.
//! - **Removing** media entries and their associated files.
//! - **Updating** entry metadata (display key, tags, locale masks).
//! - **Reading** the addon's `data.lua` file into a typed Rust struct.
//!
//! Each operation is atomic: read `data.lua` → modify → write `data.lua`.
//! No in-memory state, no dirty tracking, no separate save/generate/deploy steps.
//!
//! ## Installation
//!
//! ```toml
//! [dependencies]
//! wow-sharedmedia = "0.2"
//! ```
//!
//! ## Quick Start
//!
//! ```no_run
//! use wow_sharedmedia::{ensure_addon_dir, import_media, read_data, ImportOptions, MediaType, DEFAULT_MAX_BACKUPS};
//! use std::path::Path;
//!
//! fn main() -> Result<(), wow_sharedmedia::Error> {
//!
//! // Initialize addon directory (creates data.lua, loader.lua, .toc, media/ subdirs)
//! let addon_dir = Path::new("AddOns/MyMedia");
//! ensure_addon_dir(addon_dir, DEFAULT_MAX_BACKUPS)?;
//!
//! // Import a statusbar texture
//! let source = Path::new("assets/my-statusbar.png");
//! let opts = ImportOptions::new(MediaType::Statusbar, "My Bar", &source);
//! let result = import_media(addon_dir, opts, DEFAULT_MAX_BACKUPS)?;
//! println!("Imported: {} (ID: {})", result.entry.key, result.entry.id);
//!
//! // Read all entries
//! let data = read_data(addon_dir)?;
//! for entry in &data.entries {
//! println!(" {} [{}] → {}", entry.key, entry.media_type, entry.file);
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! ## Addon Directory Structure
//!
//! After `ensure_addon_dir`, the directory layout is driven by the folder
//! name. For a folder named `MyMedia`:
//!
//! ```text
//! MyMedia/
//! ├── MyMedia.toc # WoW addon manifest (auto-generated)
//! ├── data.lua # Media registry (Lua table, single source of truth)
//! ├── loader.lua # LSM registration script (auto-generated)
//! ├── libraries/ # Vendored LibSharedMedia-3.0 dependencies
//! └── media/
//! ├── statusbar/ # TGA texture files
//! ├── background/ # TGA texture files
//! ├── border/ # TGA texture files
//! ├── font/ # TTF/OTF font files
//! └── sound/ # OGG audio files
//! ```
//!
//! If the folder name starts with `!` (e.g. `!!!MyMedia`), the `.toc`
//! file will be `!!!MyMedia.toc` but the in-addon title will strip the
//! leading `!` characters (e.g. `MyMedia`).
//!
//! [wow]: https://worldofwarcraft.blizzard.com
//! [lsm]: https://www.wowace.com/projects/libsharedmedia-3-0/
use Path;
pub use *;
pub use *;
pub use *;
pub use DEFAULT_MAX_BACKUPS;
pub use *;
/// Extract the addon name from its directory path.
///
/// Returns the final component of `addon_dir` as a string slice.
///
/// # Panics
/// Panics if the directory name cannot be determined or is not valid UTF-8.
/// Derive the human-readable addon title from the addon name.
///
/// Strips leading `!` characters. For example, `!!!WindMedia` → `WindMedia`.