added filesystem abstraction layer and implemented basic filesystem - testing not complete yet, still features missing
Continuous integration / build (push) Has been cancelled
Continuous integration / build (push) Has been cancelled
This commit is contained in:
+17
-12
@@ -1,13 +1,19 @@
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
use egui::TextEdit;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{PROJECT_FOLDER, editors::tags::Tag, util};
|
||||
use crate::{
|
||||
editors::tags::Tag,
|
||||
filesystem::{FILESYSTEM, LegacyFileSystem},
|
||||
util,
|
||||
};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Note {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
|
||||
#[serde(default)]
|
||||
pub content: String,
|
||||
#[serde(default)]
|
||||
@@ -17,12 +23,14 @@ pub struct Note {
|
||||
pub tags: Vec<String>,
|
||||
|
||||
#[serde(skip)]
|
||||
pub id: String,
|
||||
|
||||
#[serde(skip)]
|
||||
#[serde(default = "default_saved")]
|
||||
pub saved: bool,
|
||||
}
|
||||
|
||||
pub fn default_saved() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
impl Default for Note {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
@@ -48,18 +56,15 @@ impl Note {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn save(&mut self) -> std::io::Result<()> {
|
||||
pub fn save(&mut self) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let id = &self.id;
|
||||
let path = PROJECT_FOLDER.join("notes").join(format!("{id}.json"));
|
||||
fs::write(path, serde_json::to_string(&self)?)?;
|
||||
FILESYSTEM.write(Path::new(&format!("notes/{id}.json")), self.clone())?;
|
||||
self.saved = true;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn load(id: &str) -> std::io::Result<Self> {
|
||||
let path = PROJECT_FOLDER.join("notes").join(format!("{id}.json"));
|
||||
let content = fs::read_to_string(path)?;
|
||||
let mut note: Note = serde_json::from_str(&content)?;
|
||||
pub fn load(id: &str) -> Result<Self, Box<dyn std::error::Error>> {
|
||||
let mut note: Self = FILESYSTEM.read(Path::new(&format!("notes/{id}.json")))?;
|
||||
note.id = id.to_string();
|
||||
note.saved = true;
|
||||
Ok(note)
|
||||
|
||||
Reference in New Issue
Block a user