read sound files from folder next to executable if it exists, instead of relying on cwd, otherwise check 2 levels up (works when running from cargo)
This commit is contained in:
parent
ad4a4e2923
commit
3bb155e728
1 changed files with 14 additions and 3 deletions
15
src/main.rs
15
src/main.rs
|
@ -4,10 +4,10 @@ use crossterm::terminal::{self, Clear, ClearType};
|
|||
use crossterm::ExecutableCommand;
|
||||
use rodio::Sink;
|
||||
use rodio::{OutputStream, OutputStreamHandle};
|
||||
use std::fs;
|
||||
use std::io::stdout;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
use std::{env, fs};
|
||||
|
||||
mod sound;
|
||||
use sound::Snoud;
|
||||
|
@ -76,8 +76,19 @@ impl App {
|
|||
}
|
||||
|
||||
fn run(&mut self) {
|
||||
let files: Vec<_> = fs::read_dir("sound")
|
||||
let exe = env::current_exe().unwrap();
|
||||
let files: Vec<_> = fs::read_dir(exe.with_file_name("sound"))
|
||||
.unwrap_or_else(|_err| {
|
||||
// probably running from cargo
|
||||
fs::read_dir(
|
||||
exe.parent()
|
||||
.unwrap()
|
||||
.parent()
|
||||
.unwrap()
|
||||
.with_file_name("sound"),
|
||||
)
|
||||
.unwrap()
|
||||
})
|
||||
.flatten()
|
||||
.filter(|f| f.file_type().unwrap().is_file())
|
||||
.collect();
|
||||
|
|
Loading…
Reference in a new issue