fix: support for older data
This commit is contained in:
parent
321160461b
commit
90ddb63daf
1 changed files with 4 additions and 4 deletions
|
|
@ -61,17 +61,17 @@ struct State {
|
||||||
impl State {
|
impl State {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
let mut state = Self::default();
|
let mut state = Self::default();
|
||||||
if let Ok(file) =
|
if let Ok(str) =
|
||||||
fs::File::open(data!()).inspect_err(|e| eprintln!("failed to open data file: {e}"))
|
fs::read_to_string(data!()).inspect_err(|e| eprintln!("failed to open data file: {e}"))
|
||||||
{
|
{
|
||||||
if let Ok(saved) = ron::de::from_reader::<_, data::Saved>(&file)
|
if let Ok(saved) = ron::de::from_str::<data::Saved>(&str)
|
||||||
.inspect_err(|e| eprintln!("failed to read current version of data file: {e}, trying to restore old version"))
|
.inspect_err(|e| eprintln!("failed to read current version of data file: {e}, trying to restore old version"))
|
||||||
{
|
{
|
||||||
state.table = saved.table;
|
state.table = saved.table;
|
||||||
state.content = widget::text_editor::Content::with_text(&saved.notes);
|
state.content = widget::text_editor::Content::with_text(&saved.notes);
|
||||||
} else {
|
} else {
|
||||||
// try to read it as an older version on error
|
// try to read it as an older version on error
|
||||||
state.table = ron::de::from_reader(&file).unwrap();
|
state.table = ron::de::from_str(&str).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue