Skip to content

Commit 0b78574

Browse files
committed
Fixed missing extension when saving workbooks
1 parent 91c10b0 commit 0b78574

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/windows/workbook/mod.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ mod book;
22
mod exercise;
33
mod wb_editor;
44

5+
use std::io::Read;
6+
57
pub use book::BookWindow as WorkbookWindow;
68
pub use wb_editor::WorkbookEditorWindow;
79

@@ -13,7 +15,7 @@ use eframe::epaint::ColorImage;
1315
#[cfg(not(target_arch = "wasm32"))]
1416
use {
1517
rfd,
16-
std::{fs::File, io::BufReader, io::Write, path::PathBuf},
18+
std::{fs::File, io::Write, path::PathBuf},
1719
log::{debug, error}
1820
};
1921

@@ -194,7 +196,9 @@ pub fn save_workbook(exercises: &Vec<(String, Vec<Exercise>)>) {
194196
.set_directory(&path)
195197
.save_file();
196198

197-
if let Some(f) = file_path {
199+
if let Some(mut f) = file_path {
200+
f.set_extension("wb");
201+
198202
let data = bincode::serialize(&exercises).unwrap();
199203
let mut file = File::create(&f).unwrap();
200204
file.write_all(&data).unwrap();
@@ -248,10 +252,13 @@ pub fn load_workbook() -> Option<Vec<(String, Vec<Exercise>)>> {
248252

249253
match file_path {
250254
Some(f) => {
251-
let file = File::open(&f[0]).expect("File not found");
252-
let reader = BufReader::new(file);
255+
let mut file = File::open(&f[0]).expect("File not found");
256+
let mut reader: Vec<u8> = Vec::new();
257+
file.read_to_end(&mut reader).expect("Could not read file");
258+
259+
253260

254-
match bincode::deserialize_from(reader) {
261+
match bincode::deserialize(&reader) {
255262
Ok(exercises) => {
256263
debug!("Workbook loaded from {:?}", f[0]);
257264
Some(exercises)

0 commit comments

Comments
 (0)