mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
Support importing AnkiDroid's legacy backups
They were missing the media map, and were not importable by the desktop.
This commit is contained in:
parent
98715e593a
commit
934f582804
1 changed files with 9 additions and 1 deletions
|
@ -22,6 +22,7 @@ use prost::Message;
|
||||||
use sha1::Digest;
|
use sha1::Digest;
|
||||||
use sha1::Sha1;
|
use sha1::Sha1;
|
||||||
use zip::read::ZipFile;
|
use zip::read::ZipFile;
|
||||||
|
use zip::result::ZipError;
|
||||||
use zip::ZipArchive;
|
use zip::ZipArchive;
|
||||||
use zstd::stream::copy_decode;
|
use zstd::stream::copy_decode;
|
||||||
use zstd::stream::raw::Encoder as RawEncoder;
|
use zstd::stream::raw::Encoder as RawEncoder;
|
||||||
|
@ -160,7 +161,14 @@ pub(super) fn safe_normalized_file_name(name: &str) -> Result<Cow<str>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_media_list_data(archive: &mut ZipArchive<File>, meta: &Meta) -> Result<Vec<u8>> {
|
fn get_media_list_data(archive: &mut ZipArchive<File>, meta: &Meta) -> Result<Vec<u8>> {
|
||||||
let mut file = archive.by_name("media")?;
|
let mut file = match archive.by_name("media") {
|
||||||
|
Ok(file) => file,
|
||||||
|
Err(ZipError::FileNotFound) => {
|
||||||
|
// Older AnkiDroid versions wrote colpkg files without a media map
|
||||||
|
return Ok(b"{}".to_vec());
|
||||||
|
}
|
||||||
|
err => err?,
|
||||||
|
};
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
if meta.zstd_compressed() {
|
if meta.zstd_compressed() {
|
||||||
copy_decode(file, &mut buf)?;
|
copy_decode(file, &mut buf)?;
|
||||||
|
|
Loading…
Reference in a new issue