mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Migrate singleplayer save folders to the new location if they have not already been generated
This commit is contained in:
parent
0e4b31fb63
commit
b9b84d2890
26
Cargo.lock
generated
26
Cargo.lock
generated
@ -52,7 +52,7 @@ dependencies = [
|
||||
"bitflags",
|
||||
"line_drawing",
|
||||
"rusttype 0.7.9",
|
||||
"walkdir",
|
||||
"walkdir 2.3.1",
|
||||
"xdg",
|
||||
"xml-rs",
|
||||
]
|
||||
@ -635,6 +635,15 @@ dependencies = [
|
||||
"url 1.7.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "copy_dir"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e4281031634644843bd2f5aa9c48cf98fc48d6b083bd90bb11becf10deaf8b0"
|
||||
dependencies = [
|
||||
"walkdir 0.1.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "copypasta"
|
||||
version = "0.6.3"
|
||||
@ -774,7 +783,7 @@ dependencies = [
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"tinytemplate",
|
||||
"walkdir",
|
||||
"walkdir 2.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2534,7 +2543,7 @@ dependencies = [
|
||||
"libc",
|
||||
"mio 0.6.22",
|
||||
"mio-extras",
|
||||
"walkdir",
|
||||
"walkdir 2.3.1",
|
||||
"winapi 0.3.8",
|
||||
]
|
||||
|
||||
@ -4734,6 +4743,7 @@ dependencies = [
|
||||
"conrod_core",
|
||||
"conrod_winit",
|
||||
"const-tweaker",
|
||||
"copy_dir",
|
||||
"cpal",
|
||||
"criterion",
|
||||
"crossbeam",
|
||||
@ -4865,6 +4875,16 @@ version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
|
||||
|
||||
[[package]]
|
||||
name = "walkdir"
|
||||
version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c66c0b9792f0a765345452775f3adbd28dde9d33f30d13e5dcc5ae17cf6f3780"
|
||||
dependencies = [
|
||||
"kernel32-sys",
|
||||
"winapi 0.2.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "walkdir"
|
||||
version = "2.3.1"
|
||||
|
@ -51,6 +51,7 @@ backtrace = "0.3.40"
|
||||
bincode = "1.2"
|
||||
chrono = "0.4.9"
|
||||
cpal = "0.11"
|
||||
copy_dir = "0.1.2"
|
||||
crossbeam = "=0.7.2"
|
||||
deunicode = "1.0"
|
||||
# TODO: remove
|
||||
|
@ -10,7 +10,7 @@ use std::{
|
||||
thread::{self, JoinHandle},
|
||||
time::Duration,
|
||||
};
|
||||
use tracing::{info, warn};
|
||||
use tracing::{error, info, warn};
|
||||
|
||||
const TPS: u64 = 30;
|
||||
|
||||
@ -39,6 +39,42 @@ impl Singleplayer {
|
||||
path
|
||||
};
|
||||
|
||||
// Copy saves from old folder if they don't exist in the new location
|
||||
(|| {
|
||||
let new_path = server_data_dir.join("saves");
|
||||
if new_path.exists() {
|
||||
return;
|
||||
}
|
||||
|
||||
let working_dir = std::path::PathBuf::from("saves");
|
||||
let config_dir = directories_next::ProjectDirs::from("net", "veloren", "voxygen")
|
||||
.expect("System's $HOME directory path not found!")
|
||||
.config_dir()
|
||||
.join("saves");
|
||||
let old_path = if working_dir.exists() {
|
||||
working_dir
|
||||
} else if config_dir.exists() {
|
||||
config_dir
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
|
||||
info!(
|
||||
"Saves folder doesn't exist, but there is one in the old saves location, copying \
|
||||
it to the new location"
|
||||
);
|
||||
if let Some(parent) = new_path.parent() {
|
||||
if let Err(e) = std::fs::create_dir_all(parent) {
|
||||
error!(?e, "Could not create folder to hold saves folder.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if let Err(e) = copy_dir::copy_dir(old_path, new_path) {
|
||||
error!(?e, "Failed to copy saves from the old location");
|
||||
}
|
||||
})();
|
||||
|
||||
// Create server
|
||||
let settings = server::Settings::singleplayer(&server_data_dir);
|
||||
let editable_settings = server::EditableSettings::singleplayer(&server_data_dir);
|
||||
|
Loading…
Reference in New Issue
Block a user