1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 18:29:23 +02:00

archive processing has been fixed

This commit is contained in:
Nikolay Pultsin 2010-12-17 04:44:05 +00:00
parent a6c3270553
commit 95849ddc7f
19 changed files with 47 additions and 63 deletions

View file

@ -8,5 +8,5 @@ VR:
NP: NP:
DONE Локализовать все сообщения DONE Локализовать все сообщения
* Отдельная иконка для архивов * Отдельная иконка для архивов
* Архивы в архивах DONE Архивы в архивах
* filesystem: return special result (exception?) if directory is not readable * filesystem: return special result (exception?) if directory is not readable

View file

@ -19,6 +19,6 @@ DONE Highlight current book
* Bug: search with no results clears search results subtree; should not * Bug: search with no results clears search results subtree; should not
* garbage in Boris Akunin, Сказки для идиотов * garbage in Boris Akunin, Сказки для идиотов
* duplicate tags in the same book * duplicate tags in the same book
* Bug: b1.zip (paths in zips?) DONE Bug: b1.zip (paths in zips?)
* Bug: b1.zip, archive inside archive DONE Bug: b1.zip, archive inside archive
* Open the help file if the current book is deleted from library * Open the help file if the current book is deleted from library

View file

@ -60,7 +60,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
private void migrate(Context context) { private void migrate(Context context) {
final int version = myDatabase.getVersion(); final int version = myDatabase.getVersion();
final int currentVersion = 11; final int currentVersion = 12;
if (version >= currentVersion) { if (version >= currentVersion) {
return; return;
} }
@ -91,6 +91,8 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
updateTables9(); updateTables9();
case 10: case 10:
updateTables10(); updateTables10();
case 11:
updateTables11();
} }
myDatabase.setTransactionSuccessful(); myDatabase.setTransactionSuccessful();
myDatabase.endTransaction(); myDatabase.endTransaction();
@ -568,7 +570,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
final String[] parameters = { null }; final String[] parameters = { null };
FileInfo current = null; FileInfo current = null;
for (ZLFile f : fileStack) { for (ZLFile f : fileStack) {
parameters[0] = f.getName(false); parameters[0] = f.getLongName();
final Cursor cursor = myDatabase.rawQuery( final Cursor cursor = myDatabase.rawQuery(
(current == null) ? (current == null) ?
"SELECT file_id,size FROM Files WHERE name = ?" : "SELECT file_id,size FROM Files WHERE name = ?" :
@ -1113,4 +1115,8 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
"CREATE TABLE IF NOT EXISTS Favorites(" + "CREATE TABLE IF NOT EXISTS Favorites(" +
"book_id INTEGER UNIQUE NOT NULL REFERENCES Books(book_id))"); "book_id INTEGER UNIQUE NOT NULL REFERENCES Books(book_id))");
} }
private void updateTables11() {
myDatabase.execSQL("UPDATE Files SET size = size + 1");
}
} }

View file

@ -46,13 +46,7 @@ class ShowBookInfoAction extends FBAction {
final BookModel model = Reader.Model; final BookModel model = Reader.Model;
if (model != null && model.Book != null) { if (model != null && model.Book != null) {
final ZLFile file = model.Book.File; final ZLFile file = model.Book.File;
final ZLFile physicalFile = file.getPhysicalFile(); intent.putExtra(BookInfoActivity.CURRENT_BOOK_PATH_KEY, file.getPath());
if (physicalFile == null || physicalFile == file) {
intent.putExtra(BookInfoActivity.CURRENT_BOOK_PATH_KEY, file.getPath());
} else {
intent.putExtra(BookInfoActivity.CURRENT_BOOK_PATH_KEY, physicalFile.getPath());
intent.putExtra(BookInfoActivity.CURRENT_BOOK_ARCHIVE_ENTRY_KEY, file.getName(false));
}
} }
myBaseActivity.startActivityForResult( myBaseActivity.startActivityForResult(
intent, FBReader.REPAINT_CODE intent, FBReader.REPAINT_CODE

View file

@ -221,9 +221,8 @@ public final class FileManager extends BaseActivity {
if (children.size() == 1) { if (children.size() == 1) {
final ZLFile child = children.get(0); final ZLFile child = children.get(0);
if (child.getPath().endsWith(".fb2")) { if (child.getPath().endsWith(".fb2")) {
final String fileName = file.getName(false);
myFile = child; myFile = child;
myName = fileName.substring(fileName.lastIndexOf('/') + 1); myName = file.getLongName();
mySummary = null; mySummary = null;
return; return;
} }
@ -235,12 +234,7 @@ public final class FileManager extends BaseActivity {
} }
public String getName() { public String getName() {
if (myName != null) { return myName != null ? myName : myFile.getLongName();
return myName;
}
final String fileName = myFile.getName(false);
return fileName.substring(fileName.lastIndexOf('/') + 1);
} }
public String getSummary() { public String getSummary() {

View file

@ -85,7 +85,6 @@ class LanguagePreference extends ZLStringListPreference {
public class BookInfoActivity extends ZLPreferenceActivity { public class BookInfoActivity extends ZLPreferenceActivity {
public static final String CURRENT_BOOK_PATH_KEY = "CurrentBookPath"; public static final String CURRENT_BOOK_PATH_KEY = "CurrentBookPath";
public static final String CURRENT_BOOK_ARCHIVE_ENTRY_KEY = "CurrentArchiveEntryPath";
private Book myBook; private Book myBook;
@ -100,11 +99,7 @@ public class BookInfoActivity extends ZLPreferenceActivity {
} }
final String path = intent.getStringExtra(CURRENT_BOOK_PATH_KEY); final String path = intent.getStringExtra(CURRENT_BOOK_PATH_KEY);
final String archiveEntry = intent.getStringExtra(CURRENT_BOOK_ARCHIVE_ENTRY_KEY); final ZLFile file = ZLFile.createFileByPath(path);
ZLFile file = ZLFile.createFile(null, path);
if (archiveEntry != null) {
file = ZLFile.createFile(file, archiveEntry);
}
myBook = Book.getByFile(file); myBook = Book.getByFile(file);
if (myBook.File.getPhysicalFile() != null) { if (myBook.File.getPhysicalFile() != null) {

View file

@ -136,8 +136,10 @@ public final class FBReaderApp extends ZLApplication {
} }
public void openBook(final Book book, final Bookmark bookmark) { public void openBook(final Book book, final Bookmark bookmark) {
if (bookmark == null & book.File.getPath().equals(Model.Book.File.getPath())) { if (Model != null) {
return; if (bookmark == null & book.File.getPath().equals(Model.Book.File.getPath())) {
return;
}
} }
ZLDialogManager.Instance().wait("loadingBook", new Runnable() { ZLDialogManager.Instance().wait("loadingBook", new Runnable() {
public void run() { public void run() {

View file

@ -215,7 +215,7 @@ class OEBBookReader extends ZLXMLReaderAdapter implements XMLNamespaces {
if ((type != null) && (COVER_IMAGE.equals(type))) { if ((type != null) && (COVER_IMAGE.equals(type))) {
myModelReader.setMainTextModel(); myModelReader.setMainTextModel();
final ZLFile imageFile = ZLFile.createFileByPath(myFilePrefix + href); final ZLFile imageFile = ZLFile.createFileByPath(myFilePrefix + href);
final String imageName = imageFile.getName(false); final String imageName = imageFile.getLongName();
myModelReader.addImageReference(imageName, (short)0); myModelReader.addImageReference(imageName, (short)0);
myModelReader.addImage(imageName, new ZLFileImage(MimeTypes.MIME_IMAGE_AUTO, imageFile)); myModelReader.addImage(imageName, new ZLFileImage(MimeTypes.MIME_IMAGE_AUTO, imageFile));
} }

View file

@ -23,14 +23,9 @@ import org.geometerplus.zlibrary.core.filesystem.ZLFile;
public class MiscUtil { public class MiscUtil {
public static String htmlDirectoryPrefix(ZLFile file) { public static String htmlDirectoryPrefix(ZLFile file) {
String shortName = file.getName(false); String shortName = file.getShortName();
String path = file.getPath(); String path = file.getPath();
int index = -1; return path.substring(0, path.length() - shortName.length());
if ((path.length() > shortName.length()) &&
(path.charAt(path.length() - shortName.length() - 1) == ':')) {
index = shortName.lastIndexOf('/');
}
return path.substring(0, path.length() - shortName.length() + index + 1);
} }
public static String archiveEntryName(String fullPath) { public static String archiveEntryName(String fullPath) {

View file

@ -45,7 +45,7 @@ class XHTMLTagImageAction extends XHTMLTagAction {
if (flag) { if (flag) {
modelReader.endParagraph(); modelReader.endParagraph();
} }
final String imageName = imageFile.getName(false); final String imageName = imageFile.getLongName();
modelReader.addImageReference(imageName, (short)0); modelReader.addImageReference(imageName, (short)0);
modelReader.addImage(imageName, new ZLFileImage(MimeTypes.MIME_IMAGE_AUTO, imageFile)); modelReader.addImage(imageName, new ZLFileImage(MimeTypes.MIME_IMAGE_AUTO, imageFile));
if (flag) { if (flag) {

View file

@ -121,7 +121,9 @@ public class Book {
return false; return false;
} }
if ((myTitle == null) || (myTitle.length() == 0)) { if ((myTitle == null) || (myTitle.length() == 0)) {
setTitle(File.getName(true)); final String fileName = File.getShortName();
final int index = fileName.lastIndexOf('.');
setTitle(index > 0 ? fileName.substring(0, index) : fileName);
} }
final String demoPathPrefix = Paths.BooksDirectoryOption().getValue() + java.io.File.separator + "Demos" + java.io.File.separator; final String demoPathPrefix = Paths.BooksDirectoryOption().getValue() + java.io.File.separator + "Demos" + java.io.File.separator;
if (File.getPath().startsWith(demoPathPrefix)) { if (File.getPath().startsWith(demoPathPrefix)) {

View file

@ -145,7 +145,7 @@ public final class FileInfoSet {
} }
FileInfo info = myInfosByFile.get(file); FileInfo info = myInfosByFile.get(file);
if (info == null) { if (info == null) {
info = get(file.getName(false), get(file.getParent())); info = get(file.getLongName(), get(file.getParent()));
myInfosByFile.put(file, info); myInfosByFile.put(file, info);
} }
return info; return info;

View file

@ -95,7 +95,9 @@ public final class Library {
if (book != null) { if (book != null) {
myBooks.add(book); myBooks.add(book);
} else if (file.isArchive()) { } else if (file.isArchive()) {
System.err.println("ARCHIVE: " + file.getPath());
for (ZLFile entry : fileInfos.archiveEntries(file)) { for (ZLFile entry : fileInfos.archiveEntries(file)) {
System.err.println("ENTRY: " + entry.getPath());
collectBooks(entry, fileInfos, savedBooks, doReadMetaInfo); collectBooks(entry, fileInfos, savedBooks, doReadMetaInfo);
} }
} }

View file

@ -77,7 +77,6 @@ public abstract class ZLArchiveEntryFile extends ZLFile {
protected final ZLFile myParent; protected final ZLFile myParent;
protected final String myName; protected final String myName;
private String myShortName;
protected ZLArchiveEntryFile(ZLFile parent, String name) { protected ZLArchiveEntryFile(ZLFile parent, String name) {
myParent = parent; myParent = parent;
@ -101,17 +100,8 @@ public abstract class ZLArchiveEntryFile extends ZLFile {
} }
@Override @Override
public String getNameWithExtension() { public String getLongName() {
if (myShortName == null) { return myName;
final String name = myName;
final int index = name.lastIndexOf('/');
if (index == -1) {
myShortName = name;
} else {
myShortName = name.substring(index + 1);
}
}
return myShortName;
} }
@Override @Override

View file

@ -35,15 +35,15 @@ public abstract class ZLFile {
int ARCHIVE = 0xff00; int ARCHIVE = 0xff00;
}; };
private String myNameWithoutExtension;
private String myExtension; private String myExtension;
private String myShortName;
protected int myArchiveType; protected int myArchiveType;
private boolean myIsCached; private boolean myIsCached;
protected void init() { protected void init() {
final String name = getNameWithExtension(); final String name = getLongName();
final int index = name.lastIndexOf('.'); final int index = name.lastIndexOf('.');
myNameWithoutExtension = (index != -1) ? name.substring(0, index) : name; myExtension = (index > 0) ? name.substring(index + 1).toLowerCase().intern() : "";
myExtension = (index != -1) ? name.substring(index + 1).toLowerCase().intern() : ""; myShortName = name.substring(name.lastIndexOf('/') + 1);
/* /*
if (lowerCaseName.endsWith(".gz")) { if (lowerCaseName.endsWith(".gz")) {
@ -140,11 +140,12 @@ public abstract class ZLFile {
return (0 != (myArchiveType & ArchiveType.ARCHIVE)); return (0 != (myArchiveType & ArchiveType.ARCHIVE));
} }
protected abstract String getNameWithExtension(); public abstract String getLongName();
public final String getName(boolean hideExtension) {
return hideExtension ? myNameWithoutExtension : getNameWithExtension(); public final String getShortName() {
return myShortName;
} }
public final String getExtension() { public final String getExtension() {
return myExtension; return myExtension;
} }

View file

@ -59,7 +59,7 @@ public final class ZLPhysicalFile extends ZLFile {
} }
@Override @Override
public String getNameWithExtension() { public String getLongName() {
return isDirectory() ? getPath() : myFile.getName(); return isDirectory() ? getPath() : myFile.getName();
} }

View file

@ -37,14 +37,17 @@ public abstract class ZLResourceFile extends ZLFile {
init(); init();
} }
@Override
public String getPath() { public String getPath() {
return myPath; return myPath;
} }
public String getNameWithExtension() { @Override
public String getLongName() {
return myPath.substring(myPath.lastIndexOf('/') + 1); return myPath.substring(myPath.lastIndexOf('/') + 1);
} }
@Override
public ZLPhysicalFile getPhysicalFile() { public ZLPhysicalFile getPhysicalFile() {
return null; return null;
} }

View file

@ -65,7 +65,7 @@ public class ZLLanguageDetector {
public ZLLanguageDetector() { public ZLLanguageDetector() {
for (ZLFile file : ZLLanguageUtil.patternsFile().children()) { for (ZLFile file : ZLLanguageUtil.patternsFile().children()) {
final String name = file.getName(true); final String name = file.getShortName();
final int index = name.indexOf('_'); final int index = name.indexOf('_');
if (index != -1) { if (index != -1) {
final String language = name.substring(0, index); final String language = name.substring(0, index);

View file

@ -64,7 +64,7 @@ public abstract class ZLLanguageUtil {
if (ourLanguageCodes.isEmpty()) { if (ourLanguageCodes.isEmpty()) {
TreeSet<String> codes = new TreeSet<String>(); TreeSet<String> codes = new TreeSet<String>();
for (ZLFile file : patternsFile().children()) { for (ZLFile file : patternsFile().children()) {
String name = file.getName(false); String name = file.getShortName();
final int index = name.indexOf("_"); final int index = name.indexOf("_");
if (index != -1) { if (index != -1) {
String str = name.substring(0, index); String str = name.substring(0, index);