fixing bug in loading local files

This commit is contained in:
Chris Cochrun 2023-09-20 06:16:08 -05:00
parent 70eadeadb2
commit ae851453f4

View file

@ -685,6 +685,9 @@ mod service_item_model {
match tar.finish() { match tar.finish() {
Ok(i) => { Ok(i) => {
println!("tar-written: {:?}", &lf); println!("tar-written: {:?}", &lf);
fs::remove_dir_all(
&temp_dir,
);
true true
} }
Err(e) => { Err(e) => {
@ -692,18 +695,23 @@ mod service_item_model {
"tar-error: {:?}", "tar-error: {:?}",
e e
); );
fs::remove_dir_all(
&temp_dir,
);
false false
} }
} }
} }
Err(e) => { Err(e) => {
println!("err: {:?}", e); println!("err: {:?}", e);
fs::remove_dir_all(&temp_dir);
false false
} }
} }
} }
Err(e) => { Err(e) => {
println!("json: error: {:?}", e); println!("json: error: {:?}", e);
fs::remove_dir_all(&temp_dir);
false false
} }
} }
@ -713,6 +721,7 @@ mod service_item_model {
"json: service_file isn't open: {:?}", "json: service_file isn't open: {:?}",
e e
); );
fs::remove_dir_all(&temp_dir);
false false
} }
} }
@ -733,6 +742,7 @@ mod service_item_model {
datadir.push("lumina"); datadir.push("lumina");
datadir.push("temp"); datadir.push("temp");
println!("datadir: {:?}", datadir); println!("datadir: {:?}", datadir);
fs::remove_dir_all(&datadir);
fs::create_dir_all(&datadir); fs::create_dir_all(&datadir);
if let Ok(lf) = &lfr { if let Ok(lf) = &lfr {
@ -753,7 +763,7 @@ mod service_item_model {
} }
let mut service_path = datadir.clone(); let mut service_path = datadir.clone();
service_path.push("servicelist.json"); service_path.push("serviceitems.json");
// let mut service_list = // let mut service_list =
// fs::File::open(service_path).unwrap(); // fs::File::open(service_path).unwrap();
@ -780,6 +790,7 @@ mod service_item_model {
let audio_string = let audio_string =
obj.get("audio").unwrap().as_str().unwrap(); obj.get("audio").unwrap().as_str().unwrap();
let mut audio; let mut audio;
println!("audio_on_disk: {audio_string}");
if !Path::new(&audio_string).exists() { if !Path::new(&audio_string).exists() {
println!("#$#$#$#$#$#"); println!("#$#$#$#$#$#");
@ -790,15 +801,27 @@ mod service_item_model {
.unwrap() .unwrap()
.as_str() .as_str()
.unwrap(); .unwrap();
println!("before_audio_str: {:?}", string); if !string.is_empty() {
println!(
"before_audio_str: {:?}",
string
);
let mut audio_path = datadir.clone(); let mut audio_path = datadir.clone();
audio_path.push(string); audio_path.push(string);
// Needed to ensure QML images and mpv will find the audio // Needed to ensure QML images and mpv will find the audio
let mut final_string = let mut final_string = audio_path
audio_path.to_str().unwrap().to_owned(); .to_str()
.unwrap()
.to_owned();
final_string.insert_str(0, "file://"); final_string.insert_str(0, "file://");
audio = QString::from(&final_string); audio = QString::from(&final_string);
println!("after_audio_str: {:?}", string); println!(
"after_audio_str: {:?}",
final_string
);
} else {
audio = QString::default();
}
} else { } else {
audio = QString::from(audio_string); audio = QString::from(audio_string);
} }
@ -809,10 +832,13 @@ mod service_item_model {
.as_str() .as_str()
.unwrap(); .unwrap();
let mut background; let mut background;
println!("background_on_disk: {bgstr}");
let bgpath =
bgstr.strip_prefix("file://").unwrap_or("");
// lets test to see if the background exists on disk. // lets test to see if the background exists on disk.
// if not we can use the flat version // if not we can use the flat version
if !Path::new(&bgstr).exists() { if !Path::new(&bgpath).exists() {
println!("#$#$#$#$#$#"); println!("#$#$#$#$#$#");
println!("The background doesn't exist"); println!("The background doesn't exist");
println!("#$#$#$#$#$#"); println!("#$#$#$#$#$#");
@ -821,6 +847,7 @@ mod service_item_model {
.unwrap() .unwrap()
.as_str() .as_str()
.unwrap(); .unwrap();
if !string.is_empty() {
println!("before_bgstr: {:?}", string); println!("before_bgstr: {:?}", string);
let mut bgpath = datadir.clone(); let mut bgpath = datadir.clone();
bgpath.push(string); bgpath.push(string);
@ -829,7 +856,13 @@ mod service_item_model {
bgpath.to_str().unwrap().to_owned(); bgpath.to_str().unwrap().to_owned();
final_string.insert_str(0, "file://"); final_string.insert_str(0, "file://");
background = QString::from(&final_string); background = QString::from(&final_string);
println!("after_bgstr: {:?}", string); println!(
"after_bgstr: {:?}",
final_string
);
} else {
background = QString::default();
}
} else { } else {
background = QString::from(bgstr); background = QString::from(bgstr);
} }