save properly creates temp dir with all files
All the audio and bg files are created fine. The servicelist is saved as a json file. Now I just need to compress it and put it into a tar file.
This commit is contained in:
parent
14cac2d13f
commit
3a37118aae
1 changed files with 60 additions and 19 deletions
|
@ -502,6 +502,7 @@ mod service_item_model {
|
||||||
let mut tar = Builder::new(encoder);
|
let mut tar = Builder::new(encoder);
|
||||||
let items = self.service_items();
|
let items = self.service_items();
|
||||||
let mut temp_dir = dirs::data_dir().unwrap();
|
let mut temp_dir = dirs::data_dir().unwrap();
|
||||||
|
temp_dir.push("lumina");
|
||||||
let mut s: String =
|
let mut s: String =
|
||||||
iter::repeat_with(fastrand::alphanumeric)
|
iter::repeat_with(fastrand::alphanumeric)
|
||||||
.take(5)
|
.take(5)
|
||||||
|
@ -512,28 +513,32 @@ mod service_item_model {
|
||||||
Ok(f) => {
|
Ok(f) => {
|
||||||
println!("created_temp_dir: {:?}", &temp_dir)
|
println!("created_temp_dir: {:?}", &temp_dir)
|
||||||
}
|
}
|
||||||
Err(e) => println!("{e}"),
|
Err(e) => println!("temp-dir-error: {e}"),
|
||||||
}
|
}
|
||||||
let mut temp_service_file = temp_dir.clone();
|
let mut temp_service_file = temp_dir.clone();
|
||||||
temp_service_file.push("serviceitems.json");
|
temp_service_file.push("serviceitems.json");
|
||||||
match fs::File::create(&temp_service_file) {
|
|
||||||
Ok(f) => println!("created: {:?}", f),
|
|
||||||
Err(e) => println!("{e}"),
|
|
||||||
}
|
|
||||||
let mut service_json: Vec<Value> = vec![];
|
let mut service_json: Vec<Value> = vec![];
|
||||||
|
|
||||||
for item in items {
|
for item in items {
|
||||||
let text_list = QList_QString::from(&item.text);
|
let text_list = QList_QString::from(&item.text);
|
||||||
let mut text_vec = Vec::<String>::default();
|
let mut text_vec = Vec::<String>::default();
|
||||||
|
|
||||||
let background_path =
|
let background_path = PathBuf::from(
|
||||||
PathBuf::from(item.background.to_string());
|
item.background.to_string().split_off(7),
|
||||||
|
);
|
||||||
|
println!("bg_path: {:?}", background_path);
|
||||||
let flat_background_name =
|
let flat_background_name =
|
||||||
&background_path.file_name();
|
&background_path.file_name();
|
||||||
let flat_background;
|
let flat_background;
|
||||||
match flat_background_name {
|
match flat_background_name {
|
||||||
Some(name) => {
|
Some(name) => {
|
||||||
flat_background = name.to_str().unwrap()
|
println!("bg: {:?}", &name);
|
||||||
|
if name.to_str().unwrap() != "temp" {
|
||||||
|
flat_background =
|
||||||
|
name.to_str().unwrap()
|
||||||
|
} else {
|
||||||
|
flat_background = "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
println!(
|
println!(
|
||||||
|
@ -544,21 +549,28 @@ mod service_item_model {
|
||||||
}
|
}
|
||||||
let mut temp_bg_path = temp_dir.clone();
|
let mut temp_bg_path = temp_dir.clone();
|
||||||
temp_bg_path.push(flat_background);
|
temp_bg_path.push(flat_background);
|
||||||
match fs::copy(&background_path, temp_bg_path) {
|
match fs::copy(&background_path, &temp_bg_path) {
|
||||||
Ok(s) => println!(
|
Ok(s) => println!(
|
||||||
"background-copied: of size: {:?}",
|
"background-copied: of size: {:?}",
|
||||||
s
|
s
|
||||||
),
|
),
|
||||||
Err(e) => println!("{e}"),
|
Err(e) => println!("bg-copy-error: {e}"),
|
||||||
}
|
}
|
||||||
|
|
||||||
let audio_path =
|
let audio_path = PathBuf::from(
|
||||||
PathBuf::from(item.audio.to_string());
|
item.audio.to_string().split_off(7),
|
||||||
|
);
|
||||||
|
println!("audio_path: {:?}", audio_path);
|
||||||
let flat_audio_name = audio_path.file_name();
|
let flat_audio_name = audio_path.file_name();
|
||||||
let flat_audio;
|
let flat_audio;
|
||||||
match flat_audio_name {
|
match flat_audio_name {
|
||||||
Some(name) => {
|
Some(name) => {
|
||||||
flat_audio = name.to_str().unwrap()
|
println!("audio: {:?}", &name);
|
||||||
|
if name.to_str().unwrap() != "temp" {
|
||||||
|
flat_audio = name.to_str().unwrap()
|
||||||
|
} else {
|
||||||
|
flat_audio = "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
println!("save-audio: no audio");
|
println!("save-audio: no audio");
|
||||||
|
@ -571,7 +583,7 @@ mod service_item_model {
|
||||||
Ok(s) => {
|
Ok(s) => {
|
||||||
println!("audio-copied: of size: {:?}", s)
|
println!("audio-copied: of size: {:?}", s)
|
||||||
}
|
}
|
||||||
Err(e) => println!("{e}"),
|
Err(e) => println!("audio-copy-error: {e}"),
|
||||||
}
|
}
|
||||||
|
|
||||||
for (index, line) in text_list.iter().enumerate()
|
for (index, line) in text_list.iter().enumerate()
|
||||||
|
@ -594,11 +606,40 @@ mod service_item_model {
|
||||||
println!("item-json: {item_json}");
|
println!("item-json: {item_json}");
|
||||||
service_json.push(item_json);
|
service_json.push(item_json);
|
||||||
}
|
}
|
||||||
let mut writer =
|
println!("{:?}", &temp_service_file);
|
||||||
io::BufWriter::new(temp_service_file);
|
match fs::File::create(&temp_service_file) {
|
||||||
serde_json::to_writer(writer, &service_json);
|
Ok(o) => println!("created: {:?}", o),
|
||||||
|
Err(e) => println!(
|
||||||
true
|
"error-creating-service-file: {:?}",
|
||||||
|
e
|
||||||
|
),
|
||||||
|
}
|
||||||
|
match fs::File::options()
|
||||||
|
.write(true)
|
||||||
|
.read(true)
|
||||||
|
.open(&temp_service_file)
|
||||||
|
{
|
||||||
|
Ok(service_file) => match serde_json::to_writer(
|
||||||
|
service_file,
|
||||||
|
&service_json,
|
||||||
|
) {
|
||||||
|
Ok(e) => {
|
||||||
|
println!("json: file written");
|
||||||
|
true
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!("json: error: {:?}", e);
|
||||||
|
false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
println!(
|
||||||
|
"json: service_file isn't open: {:?}",
|
||||||
|
e
|
||||||
|
);
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("rust-save-file-failed: {:?}", lfr);
|
println!("rust-save-file-failed: {:?}", lfr);
|
||||||
false
|
false
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue