ee4469b385
* Blank slate * Added gitignore * Updated gitignore * Added rust code * Added modules * Fixed build issues * rustfmt * Updated models * Added parsers module * Updated utilities module * Updated main.rs * Updated api_parser and song model * Updated icarus_action model * Updated structs in managers module * Updated main.rs * More changes * Saving changes * Added new struct and methods * More changes. Not functional yet * Changed name of the project * Removed cmake workflow * Adding rust workflow * Adding code to the syncers module * Cargo formatting * Continuing work * Adding code to the syncers module * Added dependencies * Adding more code to the syncers module * Added more code to the syncers module It's not 100 percent done yet, I'll work on other modules * Added more code to the managers module * Added code to request a token * Cargo formatting * Adding more code to multi target upload * Adding more multi-target upload code and formatted code * Added more multi-upload code * cargo fmt * Got uploading functional and cargo fmt-ing * Uploading multi target works, but is buggy Not all of the songs are being uploaded * Added single target upload * Single target upload is functional but need to revisit multi-target upload Multi-target upload is broken now. Needs to be revisited * Fixed multi target upload * Can now retrieve songs * Downloading functionality is working * Delete functionality is operational * Updated README * More cleanup * Added test
65 lines
1.5 KiB
Rust
65 lines
1.5 KiB
Rust
use std::default::Default;
|
|
|
|
|
|
pub struct FileManager {
|
|
pub filepath: String,
|
|
pub filebuffer: String,
|
|
pub file_read: bool,
|
|
pub file_buffer_length: i32,
|
|
}
|
|
|
|
impl Default for FileManager {
|
|
fn default() -> Self {
|
|
FileManager {
|
|
filepath: String::new(),
|
|
filebuffer: String::new(),
|
|
file_read: false,
|
|
file_buffer_length: -1
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl FileManager {
|
|
// TODO: Implement
|
|
pub fn init(&mut self) {
|
|
self.read_file()
|
|
}
|
|
|
|
pub fn save_file(&mut self, filepath: &String) {
|
|
if !self.file_read {
|
|
self.read_file();
|
|
}
|
|
|
|
let mut file = File::open(filepath)?;
|
|
let mut buffer = Vec::new();
|
|
file.read_to_end(&mut buffer)?;
|
|
self.file_buffer_length = buffer.len();
|
|
self.filebuffer = String::from_utf8(buffer); // Assuming UTF-8 encoding
|
|
}
|
|
|
|
pub fn modify_file_path(&mut self, file: &String) {
|
|
self.filepath = file;
|
|
}
|
|
|
|
pub fn retrieve_file_buffer(&self) -> String {
|
|
self.filebuffer;
|
|
}
|
|
|
|
pub fn retrieve_file_length(&self) -> i32 {
|
|
self.file_buffer_length;
|
|
}
|
|
|
|
fn read_file(&mut self) -> Vec<u8> {
|
|
let mut file = File::open(self.filepath)?;
|
|
let mut buffer = Vec::new();
|
|
file.read_to_end(&mut buffer)?;
|
|
self.file_buffer_length = buffer.len();
|
|
self.filebuffer = String::from_utf8(buffer); // Assuming UTF-8 encoding
|
|
self.file_read = true;
|
|
|
|
return buffer;
|
|
}
|
|
}
|
|
|