Add anki21 format and fix multi import bug
This commit is contained in:
1 parent
e676898135
commit
8f789facd7
11 files changed
+214
-167
No files matched your search
+20
-14
@@ -80,10 +80,12 @@ impl NavigatedPage<ImportMessage> for ImportState {
|
||||
Back => {}
|
||||
UpdateFile(path) => {
|
||||
self.path = Some(path);
|
||||
self.import_data = None;
|
||||
return self.load_package();
|
||||
}
|
||||
SelectFile => return Self::select_import_file(),
|
||||
UpdateImport(import) => {
|
||||
self.selected_index = 0;
|
||||
self.import_data = Some(import);
|
||||
}
|
||||
NextGroup => {
|
||||
@@ -129,7 +131,8 @@ impl NavigatedPage<ImportMessage> for ImportState {
|
||||
ImportFinished => {
|
||||
self.progress = None;
|
||||
let group = self
|
||||
.import_data.as_mut()
|
||||
.import_data
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.0
|
||||
.get_mut(self.selected_index)
|
||||
@@ -200,7 +203,9 @@ impl ImportState {
|
||||
|
||||
fn import_button(&self, group: &ImportGroup) -> Element<'_, ImportMessage> {
|
||||
if group.imported {
|
||||
return container(text!("Группа слов успешно импортирована")).padding(HALF_SPACING).align_x(Center)
|
||||
return container(text!("Группа слов успешно импортирована"))
|
||||
.padding(HALF_SPACING)
|
||||
.align_x(Center)
|
||||
.style(success)
|
||||
.width(Fill)
|
||||
.into();
|
||||
@@ -379,15 +384,17 @@ impl ImportState {
|
||||
let file = File::open(path).map_err(|_| ())?;
|
||||
let reader = BufReader::new(file);
|
||||
let mut archive = ZipArchive::new(reader).map_err(|_| ())?;
|
||||
let db_file = archive.by_name("collection.anki2");
|
||||
if let Ok(mut file) = db_file {
|
||||
let temp_file_path = app_data_dir().join("import");
|
||||
let mut temp_file = OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open(&temp_file_path)
|
||||
.map_err(|_| ())?;
|
||||
let temp_file_path = app_data_dir().join("import");
|
||||
let mut temp_file = OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open(&temp_file_path)
|
||||
.map_err(|_| ())?;
|
||||
if let Ok(mut file) = archive.by_name("collection.anki21") {
|
||||
std::io::copy(&mut file, &mut temp_file).map_err(|_| ())?;
|
||||
Ok(())
|
||||
} else if let Ok(mut file) = archive.by_name("collection.anki2") {
|
||||
std::io::copy(&mut file, &mut temp_file).map_err(|_| ())?;
|
||||
Ok(())
|
||||
} else {
|
||||
@@ -476,15 +483,14 @@ impl ImportState {
|
||||
}
|
||||
}
|
||||
|
||||
println!("{word:?}");
|
||||
words_list.push(word);
|
||||
}
|
||||
|
||||
let mut state = state.lock().unwrap();
|
||||
let connection = &mut state.connection;
|
||||
let mut index = 0;
|
||||
let total_len = words_list.len() as f32 / 256.0;
|
||||
for word in &mut words_list.chunks_mut(256) {
|
||||
let total_len = words_list.len() as f32 / 1024.0;
|
||||
for word in &mut words_list.chunks_mut(1024) {
|
||||
add_words(word, connection);
|
||||
index += 1;
|
||||
let mut progress = progress.lock().unwrap();
|
||||
|
||||
Reference in new issue
Block a user