mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-23 03:25:56 +00:00
Client: clear the game cache on Play, remember the friend's server login
- clear_game_cache removes Cache/WDB/<locale>/*.wdb before every Play (own server and friend's), on by default, switch in the client card; nothing else in Cache or Data. - The connection profile keeps the listed realm it was joined through; Play fills that realm's saved account into GlueConfig.json every time. A host typed by hand drops it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
260d10b729
commit
d64fdb51be
16 files changed
+149
No files matched your search
@@ -415,6 +415,38 @@ pub fn install_addon(client: &Path, meta: &Path, source: &Path) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Remove the game's cache of server data (`Cache/WDB/<locale>/*.wdb`: creatures, items, quests, pages). The client
|
||||
/// keeps answers it got from a server; after the server's data changes they show old names and stats until the
|
||||
/// cache is gone. Only `.wdb` files under `Cache/WDB` are removed. Returns how many.
|
||||
pub fn clear_game_cache(client: &Path) -> Result<usize> {
|
||||
if is_running(client) {
|
||||
return Ok(0);
|
||||
}
|
||||
let root = client.join("Cache").join("WDB");
|
||||
let mut removed = 0;
|
||||
let Ok(locales) = fs::read_dir(&root) else {
|
||||
return Ok(0);
|
||||
};
|
||||
for locale in locales.flatten() {
|
||||
if !locale.file_type().is_ok_and(|t| t.is_dir()) {
|
||||
continue;
|
||||
}
|
||||
let Ok(files) = fs::read_dir(locale.path()) else {
|
||||
continue;
|
||||
};
|
||||
for file in files.flatten() {
|
||||
let path = file.path();
|
||||
let is_wdb = path
|
||||
.extension()
|
||||
.is_some_and(|e| e.eq_ignore_ascii_case("wdb"));
|
||||
if is_wdb && file.file_type().is_ok_and(|t| t.is_file()) && fs::remove_file(&path).is_ok() {
|
||||
removed += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(removed)
|
||||
}
|
||||
|
||||
/// Start the game client. The caller is responsible for making sure the server is ready first.
|
||||
pub fn launch(client: &Path) -> Result<u32> {
|
||||
let exe =
|
||||
@@ -613,6 +645,23 @@ pub fn recover_all_realmlist_overrides(meta_roots: &[PathBuf]) -> usize {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn only_the_server_data_cache_is_cleared() {
|
||||
let d = tempfile::tempdir().unwrap();
|
||||
let wdb = d.path().join("Cache/WDB/enUS");
|
||||
fs::create_dir_all(&wdb).unwrap();
|
||||
fs::write(wdb.join("creaturecache.wdb"), b"x").unwrap();
|
||||
fs::write(wdb.join("itemcache.WDB"), b"x").unwrap();
|
||||
fs::write(wdb.join("notes.txt"), b"keep").unwrap();
|
||||
fs::create_dir_all(d.path().join("Data/Retail/Cache")).unwrap();
|
||||
fs::write(d.path().join("Data/Retail/Cache/id-1.bin"), b"keep").unwrap();
|
||||
assert_eq!(clear_game_cache(d.path()).unwrap(), 2);
|
||||
assert!(wdb.join("notes.txt").is_file());
|
||||
assert!(d.path().join("Data/Retail/Cache/id-1.bin").is_file());
|
||||
assert_eq!(clear_game_cache(d.path()).unwrap(), 0);
|
||||
assert_eq!(clear_game_cache(&d.path().join("missing")).unwrap(), 0);
|
||||
}
|
||||
|
||||
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
|
||||
@@ -7,6 +7,10 @@ use std::path::{Path, PathBuf};
|
||||
pub struct Profile {
|
||||
pub host: String,
|
||||
pub client_path: Option<String>,
|
||||
/// The listed server `host` belongs to, when the player joined it through the server list: its account is
|
||||
/// filled into the game's login box at every Play.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub realm: Option<String>,
|
||||
}
|
||||
|
||||
pub fn load(dir: &Path) -> Result<Profile> {
|
||||
@@ -43,12 +47,21 @@ pub fn save(dir: &Path, profile: &Profile) -> Result<()> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn a_profile_from_before_the_realm_field_still_loads() {
|
||||
let d = tempfile::tempdir().unwrap();
|
||||
std::fs::write(d.path().join("connection.json"), br#"{"host":"1.2.3.4","client_path":null}"#).unwrap();
|
||||
let p = load(d.path()).unwrap();
|
||||
assert_eq!((p.host.as_str(), p.realm), ("1.2.3.4", None));
|
||||
}
|
||||
#[test]
|
||||
fn connection_needs_no_server_and_survives_restart() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let profile = Profile {
|
||||
host: "192.168.1.10".into(),
|
||||
client_path: None,
|
||||
realm: None,
|
||||
};
|
||||
save(dir.path(), &profile).unwrap();
|
||||
assert_eq!(load(dir.path()).unwrap().host, profile.host);
|
||||
@@ -70,6 +83,7 @@ mod tests {
|
||||
let profile = Profile {
|
||||
host: "192.168.1.10".into(),
|
||||
client_path: Some(game.to_string_lossy().into()),
|
||||
realm: None,
|
||||
};
|
||||
save(dir.path(), &profile).unwrap();
|
||||
assert!(
|
||||
|
||||
Reference in new issue
Block a user