tsk-83: Updated function to generate song filename
This commit is contained in:
15
src/song.rs
15
src/song.rs
@@ -126,7 +126,7 @@ impl Song {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Generates a filename. In order to save a song to the filesystem
|
/// Generates a filename. In order to save a song to the filesystem
|
||||||
pub fn generate_filename(typ: types::MusicTypes, randomize: bool) -> String {
|
pub fn generate_filename(typ: types::MusicTypes, randomize: bool) -> Result<String, std::io::Error> {
|
||||||
let file_extension = match typ {
|
let file_extension = match typ {
|
||||||
types::MusicTypes::DefaultMusicExtension => {
|
types::MusicTypes::DefaultMusicExtension => {
|
||||||
String::from(constants::file_extensions::audio::DEFAULTMUSICEXTENSION)
|
String::from(constants::file_extensions::audio::DEFAULTMUSICEXTENSION)
|
||||||
@@ -140,9 +140,12 @@ pub fn generate_filename(typ: types::MusicTypes, randomize: bool) -> String {
|
|||||||
types::MusicTypes::MPThreeExtension => {
|
types::MusicTypes::MPThreeExtension => {
|
||||||
String::from(constants::file_extensions::audio::MPTHREEEXTENSION)
|
String::from(constants::file_extensions::audio::MPTHREEEXTENSION)
|
||||||
}
|
}
|
||||||
|
types::MusicTypes::None => {
|
||||||
|
return Err(std::io::Error::other("Unsupported MusicTypes"))
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if randomize {
|
let filename: String = if randomize {
|
||||||
let mut filename: String = String::from("track-");
|
let mut filename: String = String::from("track-");
|
||||||
let some_chars: String = String::from("abcdefghij0123456789");
|
let some_chars: String = String::from("abcdefghij0123456789");
|
||||||
let some_chars_length = some_chars.len();
|
let some_chars_length = some_chars.len();
|
||||||
@@ -156,10 +159,12 @@ pub fn generate_filename(typ: types::MusicTypes, randomize: bool) -> String {
|
|||||||
filename.push(c);
|
filename.push(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
filename + &file_extension
|
format!("{filename}{file_extension}")
|
||||||
} else {
|
} else {
|
||||||
"track-output".to_string() + &file_extension
|
format!("track-output{file_extension}")
|
||||||
}
|
};
|
||||||
|
|
||||||
|
Ok(filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// I/O operations for songs
|
/// I/O operations for songs
|
||||||
|
|||||||
Reference in New Issue
Block a user