Commit 14b6202e authored by Ozzieisaacs's avatar Ozzieisaacs

Code cosmetics

Fixes func in helper,web
Fixes for pdf reader
fixes for calling from another folder
renamed to calibreweb for importing in python caller script
parent 50973ffb
...@@ -23,7 +23,8 @@ import os ...@@ -23,7 +23,8 @@ import os
# Insert local directories into path # Insert local directories into path
sys.path.append(os.path.join(sys.path[0], 'vendor')) sys.path.append(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'vendor'))
from cps import create_app from cps import create_app
......
...@@ -204,7 +204,7 @@ def view_configuration(): ...@@ -204,7 +204,7 @@ def view_configuration():
content.config_default_role |= constants.ROLE_EDIT_SHELFS content.config_default_role |= constants.ROLE_EDIT_SHELFS
val = 0 val = 0
for key,v in to_save.items(): for key, __ in to_save.items():
if key.startswith('show'): if key.startswith('show'):
val |= int(key[5:]) val |= int(key[5:])
content.config_default_show = val content.config_default_show = val
......
...@@ -23,7 +23,8 @@ import os ...@@ -23,7 +23,8 @@ import os
from collections import namedtuple from collections import namedtuple
BASE_DIR = sys.path[0] # Base dir is parent of current file, necessary if called from different folder
BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)),os.pardir))
STATIC_DIR = os.path.join(BASE_DIR, 'cps', 'static') STATIC_DIR = os.path.join(BASE_DIR, 'cps', 'static')
TEMPLATES_DIR = os.path.join(BASE_DIR, 'cps', 'templates') TEMPLATES_DIR = os.path.join(BASE_DIR, 'cps', 'templates')
TRANSLATIONS_DIR = os.path.join(BASE_DIR, 'cps', 'translations') TRANSLATIONS_DIR = os.path.join(BASE_DIR, 'cps', 'translations')
...@@ -104,9 +105,7 @@ def has_flag(value, bit_flag): ...@@ -104,9 +105,7 @@ def has_flag(value, bit_flag):
return bit_flag == (bit_flag & (value or 0)) return bit_flag == (bit_flag & (value or 0))
""" # :rtype: BookMeta
:rtype: BookMeta
"""
BookMeta = namedtuple('BookMeta', 'file_path, extension, title, author, cover, description, tags, series, ' BookMeta = namedtuple('BookMeta', 'file_path, extension, title, author, cover, description, tags, series, '
'series_id, languages') 'series_id, languages')
......
...@@ -342,7 +342,10 @@ def setup_db(): ...@@ -342,7 +342,10 @@ def setup_db():
try: try:
if not os.path.exists(dbpath): if not os.path.exists(dbpath):
raise raise
engine = create_engine('sqlite:///' + dbpath, echo=False, isolation_level="SERIALIZABLE", connect_args={'check_same_thread': False}) engine = create_engine('sqlite:///' + dbpath,
echo=False,
isolation_level="SERIALIZABLE",
connect_args={'check_same_thread': False})
conn = engine.connect() conn = engine.connect()
except Exception: except Exception:
content = ub.session.query(ub.Settings).first() content = ub.session.query(ub.Settings).first()
......
...@@ -362,42 +362,6 @@ def upload_single_file(request, book, book_id): ...@@ -362,42 +362,6 @@ def upload_single_file(request, book, book_id):
"<a href=\"" + url_for('web.show_book', book_id=book.id) + "\">" + uploadText + "</a>") "<a href=\"" + url_for('web.show_book', book_id=book.id) + "\">" + uploadText + "</a>")
def upload_single_file(request, book, book_id):
if 'btn-upload-cover' in request.files:
requested_file = request.files['btn-upload-cover']
# check for empty request
if requested_file.filename != '':
file_ext = requested_file.filename.rsplit('.', 1)[-1].lower()
filepath = os.path.normpath(os.path.join(config.config_calibre_dir, book.path))
saved_filename = os.path.join(filepath, 'cover.' + file_ext)
# check if file path exists, otherwise create it, copy file to calibre path and delete temp file
if not os.path.exists(filepath):
try:
os.makedirs(filepath)
except OSError:
flash(_(u"Failed to create path for cover %(path)s (Permission denied).", cover=filepath),
category="error")
return redirect(url_for('show_book', book_id=book.id))
try:
requested_file.save(saved_filename)
# im=Image.open(saved_filename)
book.has_cover = 1
except OSError:
flash(_(u"Failed to store cover-file %(cover)s.", cover=saved_filename), category="error")
return redirect(url_for('web.show_book', book_id=book.id))
except IOError:
flash(_(u"Cover-file is not a valid image file" % saved_filename), category="error")
return redirect(url_for('web.show_book', book_id=book.id))
if helper.save_cover(requested_file, book.path) is True:
return True
else:
# ToDo Message not always coorect
flash(_(u"Cover is not a supported imageformat (jpg/png/webp), can't save"), category="error")
return False
return None
def upload_cover(request, book): def upload_cover(request, book):
if 'btn-upload-cover' in request.files: if 'btn-upload-cover' in request.files:
requested_file = request.files['btn-upload-cover'] requested_file = request.files['btn-upload-cover']
...@@ -411,6 +375,7 @@ def upload_cover(request, book): ...@@ -411,6 +375,7 @@ def upload_cover(request, book):
return False return False
return None return None
@editbook.route("/admin/book/<int:book_id>", methods=['GET', 'POST']) @editbook.route("/admin/book/<int:book_id>", methods=['GET', 'POST'])
@login_required_if_no_ano @login_required_if_no_ano
@edit_required @edit_required
......
...@@ -491,12 +491,12 @@ def save_cover_from_filestorage(filepath, saved_filename, img): ...@@ -491,12 +491,12 @@ def save_cover_from_filestorage(filepath, saved_filename, img):
return False return False
try: try:
img.save(os.path.join(filepath, saved_filename)) img.save(os.path.join(filepath, saved_filename))
except OSError:
log.error(u"Failed to store cover-file")
return False
except IOError: except IOError:
log.error(u"Cover-file is not a valid image file") log.error(u"Cover-file is not a valid image file")
return False return False
except OSError:
log.error(u"Failed to store cover-file")
return False
return True return True
...@@ -703,7 +703,7 @@ def fill_indexpage(page, database, db_filter, order, *join): ...@@ -703,7 +703,7 @@ def fill_indexpage(page, database, db_filter, order, *join):
def get_typeahead(database, query, replace=('','')): def get_typeahead(database, query, replace=('','')):
db.session.connection().connection.connection.create_function("lower", 1, lcase) db.session.connection().connection.connection.create_function("lower", 1, lcase)
entries = db.session.query(database).filter(db.func.lower(database.name).ilike("%" + query + "%")).all() entries = db.session.query(database).filter(func.lower(database.name).ilike("%" + query + "%")).all()
json_dumps = json.dumps([dict(name=r.name.replace(*replace)) for r in entries]) json_dumps = json.dumps([dict(name=r.name.replace(*replace)) for r in entries])
return json_dumps return json_dumps
...@@ -713,16 +713,16 @@ def get_search_results(term): ...@@ -713,16 +713,16 @@ def get_search_results(term):
q = list() q = list()
authorterms = re.split("[, ]+", term) authorterms = re.split("[, ]+", term)
for authorterm in authorterms: for authorterm in authorterms:
q.append(db.Books.authors.any(db.func.lower(db.Authors.name).ilike("%" + authorterm + "%"))) q.append(db.Books.authors.any(func.lower(db.Authors.name).ilike("%" + authorterm + "%")))
db.Books.authors.any(db.func.lower(db.Authors.name).ilike("%" + term + "%")) db.Books.authors.any(func.lower(db.Authors.name).ilike("%" + term + "%"))
return db.session.query(db.Books).filter(common_filters()).filter( return db.session.query(db.Books).filter(common_filters()).filter(
or_(db.Books.tags.any(db.func.lower(db.Tags.name).ilike("%" + term + "%")), or_(db.Books.tags.any(func.lower(db.Tags.name).ilike("%" + term + "%")),
db.Books.series.any(db.func.lower(db.Series.name).ilike("%" + term + "%")), db.Books.series.any(func.lower(db.Series.name).ilike("%" + term + "%")),
db.Books.authors.any(and_(*q)), db.Books.authors.any(and_(*q)),
db.Books.publishers.any(db.func.lower(db.Publishers.name).ilike("%" + term + "%")), db.Books.publishers.any(func.lower(db.Publishers.name).ilike("%" + term + "%")),
db.func.lower(db.Books.title).ilike("%" + term + "%") func.lower(db.Books.title).ilike("%" + term + "%")
)).all() )).all()
def get_unique_other_books(library_books, author_books): def get_unique_other_books(library_books, author_books):
......
...@@ -121,5 +121,5 @@ class StderrLogger(object): ...@@ -121,5 +121,5 @@ class StderrLogger(object):
self.buffer = '' self.buffer = ''
else: else:
self.buffer += message self.buffer += message
except: except Exception:
self.logger.debug("Logging Error") self.logger.debug("Logging Error")
...@@ -266,10 +266,10 @@ def delete_shelf(shelf_id): ...@@ -266,10 +266,10 @@ def delete_shelf(shelf_id):
return redirect(url_for('web.index')) return redirect(url_for('web.index'))
# @shelf.route("/shelfdown/<int:shelf_id>") # @shelf.route("/shelfdown/<int:shelf_id>")
@shelf.route("/shelf/<int:shelf_id>", defaults={'type': 1}) @shelf.route("/shelf/<int:shelf_id>", defaults={'shelf_type': 1})
@shelf.route("/shelf/<int:shelf_id>/<int:type>") @shelf.route("/shelf/<int:shelf_id>/<int:shelf_type>")
@login_required @login_required
def show_shelf(type, shelf_id): def show_shelf(shelf_type, shelf_id):
if current_user.is_anonymous: if current_user.is_anonymous:
shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.is_public == 1, ub.Shelf.id == shelf_id).first() shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.is_public == 1, ub.Shelf.id == shelf_id).first()
else: else:
...@@ -280,7 +280,7 @@ def show_shelf(type, shelf_id): ...@@ -280,7 +280,7 @@ def show_shelf(type, shelf_id):
result = list() result = list()
# user is allowed to access shelf # user is allowed to access shelf
if shelf: if shelf:
page = "shelf.html" if type == 1 else 'shelfdown.html' page = "shelf.html" if shelf_type == 1 else 'shelfdown.html'
books_in_shelf = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id).order_by( books_in_shelf = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id).order_by(
ub.BookShelf.order.asc()).all() ub.BookShelf.order.asc()).all()
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Copyright(c) 2011 Google Inc. * Copyright(c) 2011 Google Inc.
*/ */
/* global bitjs */ /* global bitjs, Uint8Array */
var bitjs = bitjs || {}; var bitjs = bitjs || {};
bitjs.archive = bitjs.archive || {}; bitjs.archive = bitjs.archive || {};
...@@ -17,7 +17,7 @@ bitjs.archive = bitjs.archive || {}; ...@@ -17,7 +17,7 @@ bitjs.archive = bitjs.archive || {};
// =========================================================================== // ===========================================================================
// Stolen from Closure because it's the best way to do Java-like inheritance. // Stolen from Closure because it's the best way to do Java-like inheritance.
bitjs.base = function(me, opt_methodName, var_args) { bitjs.base = function(me, optMethodName, varArgs) {
var caller = arguments.callee.caller; var caller = arguments.callee.caller;
if (caller.superClass_) { if (caller.superClass_) {
// This is a constructor. Call the superclass constructor. // This is a constructor. Call the superclass constructor.
...@@ -28,10 +28,10 @@ bitjs.archive = bitjs.archive || {}; ...@@ -28,10 +28,10 @@ bitjs.archive = bitjs.archive || {};
var args = Array.prototype.slice.call(arguments, 2); var args = Array.prototype.slice.call(arguments, 2);
var foundCaller = false; var foundCaller = false;
for (var ctor = me.constructor; ctor; ctor = ctor.superClass_ && ctor.superClass_.constructor) { for (var ctor = me.constructor; ctor; ctor = ctor.superClass_ && ctor.superClass_.constructor) {
if (ctor.prototype[opt_methodName] === caller) { if (ctor.prototype[optMethodName] === caller) {
foundCaller = true; foundCaller = true;
} else if (foundCaller) { } else if (foundCaller) {
return ctor.prototype[opt_methodName].apply(me, args); return ctor.prototype[optMethodName].apply(me, args);
} }
} }
...@@ -39,8 +39,8 @@ bitjs.archive = bitjs.archive || {}; ...@@ -39,8 +39,8 @@ bitjs.archive = bitjs.archive || {};
// then one of two things happened: // then one of two things happened:
// 1) The caller is an instance method. // 1) The caller is an instance method.
// 2) This method was not called by the right caller. // 2) This method was not called by the right caller.
if (me[opt_methodName] === caller) { if (me[optMethodName] === caller) {
return me.constructor.prototype[opt_methodName].apply(me, args); return me.constructor.prototype[optMethodName].apply(me, args);
} else { } else {
throw Error( throw Error(
"goog.base called from a method of one name " + "goog.base called from a method of one name " +
...@@ -49,10 +49,10 @@ bitjs.archive = bitjs.archive || {}; ...@@ -49,10 +49,10 @@ bitjs.archive = bitjs.archive || {};
}; };
bitjs.inherits = function(childCtor, parentCtor) { bitjs.inherits = function(childCtor, parentCtor) {
/** @constructor */ /** @constructor */
function tempCtor() {}; function TempCtor() {}
tempCtor.prototype = parentCtor.prototype; TempCtor.prototype = parentCtor.prototype;
childCtor.superClass_ = parentCtor.prototype; childCtor.superClass_ = parentCtor.prototype;
childCtor.prototype = new tempCtor(); childCtor.prototype = new TempCtor();
childCtor.prototype.constructor = childCtor; childCtor.prototype.constructor = childCtor;
}; };
// =========================================================================== // ===========================================================================
...@@ -188,10 +188,10 @@ bitjs.archive = bitjs.archive || {}; ...@@ -188,10 +188,10 @@ bitjs.archive = bitjs.archive || {};
* Base class for all Unarchivers. * Base class for all Unarchivers.
* *
* @param {ArrayBuffer} arrayBuffer The Array Buffer. * @param {ArrayBuffer} arrayBuffer The Array Buffer.
* @param {string} opt_pathToBitJS Optional string for where the BitJS files are located. * @param {string} optPathToBitJS Optional string for where the BitJS files are located.
* @constructor * @constructor
*/ */
bitjs.archive.Unarchiver = function(arrayBuffer, opt_pathToBitJS) { bitjs.archive.Unarchiver = function(arrayBuffer, optPathToBitJS) {
/** /**
* The ArrayBuffer object. * The ArrayBuffer object.
* @type {ArrayBuffer} * @type {ArrayBuffer}
...@@ -204,7 +204,7 @@ bitjs.archive = bitjs.archive || {}; ...@@ -204,7 +204,7 @@ bitjs.archive = bitjs.archive || {};
* @type {string} * @type {string}
* @private * @private
*/ */
this.pathToBitJS_ = opt_pathToBitJS || "/"; this.pathToBitJS_ = optPathToBitJS || "/";
/** /**
* A map from event type to an array of listeners. * A map from event type to an array of listeners.
...@@ -319,8 +319,8 @@ bitjs.archive = bitjs.archive || {}; ...@@ -319,8 +319,8 @@ bitjs.archive = bitjs.archive || {};
* @extends {bitjs.archive.Unarchiver} * @extends {bitjs.archive.Unarchiver}
* @constructor * @constructor
*/ */
bitjs.archive.Unzipper = function(arrayBuffer, opt_pathToBitJS) { bitjs.archive.Unzipper = function(arrayBuffer, optPathToBitJS) {
bitjs.base(this, arrayBuffer, opt_pathToBitJS); bitjs.base(this, arrayBuffer, optPathToBitJS);
}; };
bitjs.inherits(bitjs.archive.Unzipper, bitjs.archive.Unarchiver); bitjs.inherits(bitjs.archive.Unzipper, bitjs.archive.Unarchiver);
bitjs.archive.Unzipper.prototype.getScriptFileName = function() { bitjs.archive.Unzipper.prototype.getScriptFileName = function() {
...@@ -332,8 +332,8 @@ bitjs.archive = bitjs.archive || {}; ...@@ -332,8 +332,8 @@ bitjs.archive = bitjs.archive || {};
* @extends {bitjs.archive.Unarchiver} * @extends {bitjs.archive.Unarchiver}
* @constructor * @constructor
*/ */
bitjs.archive.Unrarrer = function(arrayBuffer, opt_pathToBitJS) { bitjs.archive.Unrarrer = function(arrayBuffer, optPathToBitJS) {
bitjs.base(this, arrayBuffer, opt_pathToBitJS); bitjs.base(this, arrayBuffer, optPathToBitJS);
}; };
bitjs.inherits(bitjs.archive.Unrarrer, bitjs.archive.Unarchiver); bitjs.inherits(bitjs.archive.Unrarrer, bitjs.archive.Unarchiver);
bitjs.archive.Unrarrer.prototype.getScriptFileName = function() { bitjs.archive.Unrarrer.prototype.getScriptFileName = function() {
...@@ -345,8 +345,8 @@ bitjs.archive = bitjs.archive || {}; ...@@ -345,8 +345,8 @@ bitjs.archive = bitjs.archive || {};
* @extends {bitjs.archive.Unarchiver} * @extends {bitjs.archive.Unarchiver}
* @constructor * @constructor
*/ */
bitjs.archive.Untarrer = function(arrayBuffer, opt_pathToBitJS) { bitjs.archive.Untarrer = function(arrayBuffer, optPathToBitJS) {
bitjs.base(this, arrayBuffer, opt_pathToBitJS); bitjs.base(this, arrayBuffer, optPathToBitJS);
}; };
bitjs.inherits(bitjs.archive.Untarrer, bitjs.archive.Unarchiver); bitjs.inherits(bitjs.archive.Untarrer, bitjs.archive.Unarchiver);
bitjs.archive.Untarrer.prototype.getScriptFileName = function() { bitjs.archive.Untarrer.prototype.getScriptFileName = function() {
...@@ -357,20 +357,19 @@ bitjs.archive = bitjs.archive || {}; ...@@ -357,20 +357,19 @@ bitjs.archive = bitjs.archive || {};
* Factory method that creates an unarchiver based on the byte signature found * Factory method that creates an unarchiver based on the byte signature found
* in the arrayBuffer. * in the arrayBuffer.
* @param {ArrayBuffer} ab * @param {ArrayBuffer} ab
* @param {string=} opt_pathToBitJS Path to the unarchiver script files. * @param {string=} optPathToBitJS Path to the unarchiver script files.
* @return {bitjs.archive.Unarchiver} * @return {bitjs.archive.Unarchiver}
*/ */
bitjs.archive.GetUnarchiver = function(ab, opt_pathToBitJS) { bitjs.archive.GetUnarchiver = function(ab, optPathToBitJS) {
var unarchiver = null; var unarchiver = null;
var pathToBitJS = opt_pathToBitJS || ''; var pathToBitJS = optPathToBitJS || "";
var h = new Uint8Array(ab, 0, 10); var h = new Uint8Array(ab, 0, 10);
if (h[0] == 0x52 && h[1] == 0x61 && h[2] == 0x72 && h[3] == 0x21) { // Rar! if (h[0] === 0x52 && h[1] === 0x61 && h[2] === 0x72 && h[3] === 0x21) { // Rar!
unarchiver = new bitjs.archive.Unrarrer(ab, pathToBitJS); unarchiver = new bitjs.archive.Unrarrer(ab, pathToBitJS);
} else if (h[0] == 80 && h[1] == 75) { // PK (Zip) } else if (h[0] === 80 && h[1] === 75) { // PK (Zip)
unarchiver = new bitjs.archive.Unzipper(ab, pathToBitJS); unarchiver = new bitjs.archive.Unzipper(ab, pathToBitJS);
} else { // Try with tar } else { // Try with tar
console.log('geter');
unarchiver = new bitjs.archive.Untarrer(ab, pathToBitJS); unarchiver = new bitjs.archive.Untarrer(ab, pathToBitJS);
} }
return unarchiver; return unarchiver;
......
...@@ -9,9 +9,12 @@ ...@@ -9,9 +9,12 @@
/** /**
* CRC Implementation. * CRC Implementation.
*/ */
/* global Uint8Array, Uint32Array, bitjs, DataView */
/* exported MAXWINMASK, UnpackFilter */
var CRCTab = new Array(256).fill(0); var CRCTab = new Array(256).fill(0);
function InitCRC() { function initCRC() {
for (var i = 0; i < 256; ++i) { for (var i = 0; i < 256; ++i) {
var c = i; var c = i;
for (var j = 0; j < 8; ++j) { for (var j = 0; j < 8; ++j) {
...@@ -30,8 +33,8 @@ function InitCRC() { ...@@ -30,8 +33,8 @@ function InitCRC() {
* @return {number} * @return {number}
*/ */
function CRC(startCRC, arr) { function CRC(startCRC, arr) {
if (CRCTab[1] == 0) { if (CRCTab[1] === 0) {
InitCRC(); initCRC();
} }
/* /*
...@@ -84,7 +87,7 @@ var MAXWINMASK = (MAXWINSIZE - 1); ...@@ -84,7 +87,7 @@ var MAXWINMASK = (MAXWINSIZE - 1);
/** /**
*/ */
var VM_Commands = { var VmCommands = {
VM_MOV: 0, VM_MOV: 0,
VM_CMP: 1, VM_CMP: 1,
VM_ADD: 2, VM_ADD: 2,
...@@ -141,7 +144,7 @@ var VM_Commands = { ...@@ -141,7 +144,7 @@ var VM_Commands = {
/** /**
*/ */
var VM_StandardFilters = { var VmStandardFilters = {
VMSF_NONE: 0, VMSF_NONE: 0,
VMSF_E8: 1, VMSF_E8: 1,
VMSF_E8E9: 2, VMSF_E8E9: 2,
...@@ -154,7 +157,7 @@ var VM_StandardFilters = { ...@@ -154,7 +157,7 @@ var VM_StandardFilters = {
/** /**
*/ */
var VM_Flags = { var VmFlags = {
VM_FC: 1, VM_FC: 1,
VM_FZ: 2, VM_FZ: 2,
VM_FS: 0x80000000, VM_FS: 0x80000000,
...@@ -162,7 +165,7 @@ var VM_Flags = { ...@@ -162,7 +165,7 @@ var VM_Flags = {
/** /**
*/ */
var VM_OpType = { var VmOpType = {
VM_OPREG: 0, VM_OPREG: 0,
VM_OPINT: 1, VM_OPINT: 1,
VM_OPREGMEM: 2, VM_OPREGMEM: 2,
...@@ -186,15 +189,15 @@ function findKeyForValue(obj, val) { ...@@ -186,15 +189,15 @@ function findKeyForValue(obj, val) {
} }
function getDebugString(obj, val) { function getDebugString(obj, val) {
var s = 'Unknown.'; var s = "Unknown.";
if (obj === VM_Commands) { if (obj === VmCommands) {
s = 'VM_Commands.'; s = "VmCommands.";
} else if (obj === VM_StandardFilters) { } else if (obj === VmStandardFilters) {
s = 'VM_StandardFilters.'; s = "VmStandardFilters.";
} else if (obj === VM_Flags) { } else if (obj === VmFlags) {
s = 'VM_OpType.'; s = "VmOpType.";
} else if (obj === VM_OpType) { } else if (obj === VmOpType) {
s = 'VM_OpType.'; s = "VmOpType.";
} }
return s + findKeyForValue(obj, val); return s + findKeyForValue(obj, val);
...@@ -204,8 +207,8 @@ function getDebugString(obj, val) { ...@@ -204,8 +207,8 @@ function getDebugString(obj, val) {
* @struct * @struct
* @constructor * @constructor
*/ */
var VM_PreparedOperand = function() { var VmPreparedOperand = function() {
/** @type {VM_OpType} */ /** @type {VmOpType} */
this.Type; this.Type;
/** @type {number} */ /** @type {number} */
...@@ -220,58 +223,58 @@ var VM_PreparedOperand = function() { ...@@ -220,58 +223,58 @@ var VM_PreparedOperand = function() {
}; };
/** @return {string} */ /** @return {string} */
VM_PreparedOperand.prototype.toString = function() { VmPreparedOperand.prototype.toString = function() {
if (this.Type === null) { if (this.Type === null) {
return 'Error: Type was null in VM_PreparedOperand'; return "Error: Type was null in VmPreparedOperand";
} }
return '{ ' + return "{ " +
'Type: ' + getDebugString(VM_OpType, this.Type) + "Type: " + getDebugString(VmOpType, this.Type) +
', Data: ' + this.Data + ", Data: " + this.Data +
', Base: ' + this.Base + ", Base: " + this.Base +
' }'; " }";
}; };
/** /**
* @struct * @struct
* @constructor * @constructor
*/ */
var VM_PreparedCommand = function() { var VmPreparedCommand = function() {
/** @type {VM_Commands} */ /** @type {VmCommands} */
this.OpCode; this.OpCode;
/** @type {boolean} */ /** @type {boolean} */
this.ByteMode = false; this.ByteMode = false;
/** @type {VM_PreparedOperand} */ /** @type {VmPreparedOperand} */
this.Op1 = new VM_PreparedOperand(); this.Op1 = new VmPreparedOperand();
/** @type {VM_PreparedOperand} */ /** @type {VmPreparedOperand} */
this.Op2 = new VM_PreparedOperand(); this.Op2 = new VmPreparedOperand();
}; };
/** @return {string} */ /** @return {string} */
VM_PreparedCommand.prototype.toString = function(indent) { VmPreparedCommand.prototype.toString = function(indent) {
if (this.OpCode === null) { if (this.OpCode === null) {
return 'Error: OpCode was null in VM_PreparedCommand'; return "Error: OpCode was null in VmPreparedCommand";
} }
indent = indent || ''; indent = indent || "";
return indent + '{\n' + return indent + "{\n" +
indent + ' OpCode: ' + getDebugString(VM_Commands, this.OpCode) + ',\n' + indent + " OpCode: " + getDebugString(VmCommands, this.OpCode) + ",\n" +
indent + ' ByteMode: ' + this.ByteMode + ',\n' + indent + " ByteMode: " + this.ByteMode + ",\n" +
indent + ' Op1: ' + this.Op1.toString() + ',\n' + indent + " Op1: " + this.Op1.toString() + ",\n" +
indent + ' Op2: ' + this.Op2.toString() + ',\n' + indent + " Op2: " + this.Op2.toString() + ",\n" +
indent + '}'; indent + "}";
}; };
/** /**
* @struct * @struct
* @constructor * @constructor
*/ */
var VM_PreparedProgram = function() { var VmPreparedProgram = function() {
/** @type {Array<VM_PreparedCommand>} */ /** @type {Array<VmPreparedCommand>} */
this.Cmd = []; this.Cmd = [];
/** @type {Array<VM_PreparedCommand>} */ /** @type {Array<VmPreparedCommand>} */
this.AltCmd = null; this.AltCmd = null;
/** @type {Uint8Array} */ /** @type {Uint8Array} */
...@@ -291,14 +294,14 @@ var VM_PreparedProgram = function() { ...@@ -291,14 +294,14 @@ var VM_PreparedProgram = function() {
}; };
/** @return {string} */ /** @return {string} */
VM_PreparedProgram.prototype.toString = function() { VmPreparedProgram.prototype.toString = function() {
var s = '{\n Cmd: [\n'; var s = "{\n Cmd: [\n";
for (var i = 0; i < this.Cmd.length; ++i) { for (var i = 0; i < this.Cmd.length; ++i) {
s += this.Cmd[i].toString(' ') + ',\n'; s += this.Cmd[i].toString(" ") + ",\n";
} }
s += '],\n'; s += "],\n";
// TODO: Dump GlobalData, StaticData, InitR? // TODO: Dump GlobalData, StaticData, InitR?
s += ' }\n'; s += " }\n";
return s; return s;
}; };
...@@ -324,8 +327,8 @@ var UnpackFilter = function() { ...@@ -324,8 +327,8 @@ var UnpackFilter = function() {
/** @type {number} */ /** @type {number} */
this.ParentFilter = null; this.ParentFilter = null;
/** @type {VM_PreparedProgram} */ /** @type {VmPreparedProgram} */
this.Prg = new VM_PreparedProgram(); this.Prg = new VmPreparedProgram();
}; };
var VMCF_OP0 = 0; var VMCF_OP0 = 0;
...@@ -338,7 +341,7 @@ var VMCF_PROC = 16; ...@@ -338,7 +341,7 @@ var VMCF_PROC = 16;
var VMCF_USEFLAGS = 32; var VMCF_USEFLAGS = 32;
var VMCF_CHFLAGS = 64; var VMCF_CHFLAGS = 64;
var VM_CmdFlags = [ var VmCmdFlags = [
/* VM_MOV */ /* VM_MOV */
VMCF_OP2 | VMCF_BYTEMODE, VMCF_OP2 | VMCF_BYTEMODE,
/* VM_CMP */ /* VM_CMP */
...@@ -425,7 +428,7 @@ var VM_CmdFlags = [ ...@@ -425,7 +428,7 @@ var VM_CmdFlags = [
/** /**
* @param {number} length * @param {number} length
* @param {number} crc * @param {number} crc
* @param {VM_StandardFilters} type * @param {VmStandardFilters} type
* @struct * @struct
* @constructor * @constructor
*/ */
...@@ -436,7 +439,7 @@ var StandardFilterSignature = function(length, crc, type) { ...@@ -436,7 +439,7 @@ var StandardFilterSignature = function(length, crc, type) {
/** @type {number} */ /** @type {number} */
this.CRC = crc; this.CRC = crc;
/** @type {VM_StandardFilters} */ /** @type {VmStandardFilters} */
this.Type = type; this.Type = type;
}; };
...@@ -444,13 +447,13 @@ var StandardFilterSignature = function(length, crc, type) { ...@@ -444,13 +447,13 @@ var StandardFilterSignature = function(length, crc, type) {
* @type {Array<StandardFilterSignature>} * @type {Array<StandardFilterSignature>}
*/ */
var StdList = [ var StdList = [
new StandardFilterSignature(53, 0xad576887, VM_StandardFilters.VMSF_E8), new StandardFilterSignature(53, 0xad576887, VmStandardFilters.VMSF_E8),
new StandardFilterSignature(57, 0x3cd7e57e, VM_StandardFilters.VMSF_E8E9), new StandardFilterSignature(57, 0x3cd7e57e, VmStandardFilters.VMSF_E8E9),
new StandardFilterSignature(120, 0x3769893f, VM_StandardFilters.VMSF_ITANIUM), new StandardFilterSignature(120, 0x3769893f, VmStandardFilters.VMSF_ITANIUM),
new StandardFilterSignature(29, 0x0e06077d, VM_StandardFilters.VMSF_DELTA), new StandardFilterSignature(29, 0x0e06077d, VmStandardFilters.VMSF_DELTA),
new StandardFilterSignature(149, 0x1c2c5dc8, VM_StandardFilters.VMSF_RGB), new StandardFilterSignature(149, 0x1c2c5dc8, VmStandardFilters.VMSF_RGB),
new StandardFilterSignature(216, 0xbc85e701, VM_StandardFilters.VMSF_AUDIO), new StandardFilterSignature(216, 0xbc85e701, VmStandardFilters.VMSF_AUDIO),
new StandardFilterSignature(40, 0x46b9c560, VM_StandardFilters.VMSF_UPCASE), new StandardFilterSignature(40, 0x46b9c560, VmStandardFilters.VMSF_UPCASE),
]; ];
/** /**
...@@ -478,33 +481,34 @@ RarVM.prototype.init = function() { ...@@ -478,33 +481,34 @@ RarVM.prototype.init = function() {
/** /**
* @param {Uint8Array} code * @param {Uint8Array} code
* @return {VM_StandardFilters} * @return {VmStandardFilters}
*/ */
RarVM.prototype.isStandardFilter = function(code) { RarVM.prototype.isStandardFilter = function(code) {
var codeCRC = (CRC(0xffffffff, code, code.length) ^ 0xffffffff) >>> 0; var codeCRC = (CRC(0xffffffff, code, code.length) ^ 0xffffffff) >>> 0;
for (var i = 0; i < StdList.length; ++i) { for (var i = 0; i < StdList.length; ++i) {
if (StdList[i].CRC == codeCRC && StdList[i].Length == code.length) if (StdList[i].CRC === codeCRC && StdList[i].Length === code.length) {
return StdList[i].Type; return StdList[i].Type;
} }
}
return VM_StandardFilters.VMSF_NONE; return VmStandardFilters.VMSF_NONE;
}; };
/** /**
* @param {VM_PreparedOperand} op * @param {VmPreparedOperand} op
* @param {boolean} byteMode * @param {boolean} byteMode
* @param {bitjs.io.BitStream} bstream A rtl bit stream. * @param {bitjs.io.BitStream} bstream A rtl bit stream.
*/ */
RarVM.prototype.decodeArg = function(op, byteMode, bstream) { RarVM.prototype.decodeArg = function(op, byteMode, bstream) {
var data = bstream.peekBits(16); var data = bstream.peekBits(16);
if (data & 0x8000) { if (data & 0x8000) {
op.Type = VM_OpType.VM_OPREG; // Operand is register (R[0]..R[7]) op.Type = VmOpType.VM_OPREG; // Operand is register (R[0]..R[7])
bstream.readBits(1); // 1 flag bit and... bstream.readBits(1); // 1 flag bit and...
op.Data = bstream.readBits(3); // ... 3 register number bits op.Data = bstream.readBits(3); // ... 3 register number bits
op.Addr = [this.R_[op.Data]] // TODO &R[Op.Data] // Register address op.Addr = [this.R_[op.Data]]; // TODO &R[Op.Data] // Register address
} else { } else {
if ((data & 0xc000) == 0) { if ((data & 0xc000) === 0) {
op.Type = VM_OpType.VM_OPINT; // Operand is integer op.Type = VmOpType.VM_OPINT; // Operand is integer
bstream.readBits(2); // 2 flag bits bstream.readBits(2); // 2 flag bits
if (byteMode) { if (byteMode) {
op.Data = bstream.readBits(8); // Byte integer. op.Data = bstream.readBits(8); // Byte integer.
...@@ -513,8 +517,8 @@ RarVM.prototype.decodeArg = function(op, byteMode, bstream) { ...@@ -513,8 +517,8 @@ RarVM.prototype.decodeArg = function(op, byteMode, bstream) {
} }
} else { } else {
// Operand is data addressed by register data, base address or both. // Operand is data addressed by register data, base address or both.
op.Type = VM_OpType.VM_OPREGMEM; op.Type = VmOpType.VM_OPREGMEM;
if ((data & 0x2000) == 0) { if ((data & 0x2000) === 0) {
bstream.readBits(3); // 3 flag bits bstream.readBits(3); // 3 flag bits
// Base address is zero, just use the address from register. // Base address is zero, just use the address from register.
op.Data = bstream.readBits(3); // (Data>>10)&7 op.Data = bstream.readBits(3); // (Data>>10)&7
...@@ -522,7 +526,7 @@ RarVM.prototype.decodeArg = function(op, byteMode, bstream) { ...@@ -522,7 +526,7 @@ RarVM.prototype.decodeArg = function(op, byteMode, bstream) {
op.Base = 0; op.Base = 0;
} else { } else {
bstream.readBits(4); // 4 flag bits bstream.readBits(4); // 4 flag bits
if ((data & 0x1000) == 0) { if ((data & 0x1000) === 0) {
// Use both register and base address. // Use both register and base address.
op.Data = bstream.readBits(3); op.Data = bstream.readBits(3);
op.Addr = [this.R_[op.Data]]; // TODO &R[op.Data] op.Addr = [this.R_[op.Data]]; // TODO &R[op.Data]
...@@ -537,7 +541,7 @@ RarVM.prototype.decodeArg = function(op, byteMode, bstream) { ...@@ -537,7 +541,7 @@ RarVM.prototype.decodeArg = function(op, byteMode, bstream) {
}; };
/** /**
* @param {VM_PreparedProgram} prg * @param {VmPreparedProgram} prg
*/ */
RarVM.prototype.execute = function(prg) { RarVM.prototype.execute = function(prg) {
this.R_.set(prg.InitR); this.R_.set(prg.InitR);
...@@ -558,7 +562,7 @@ RarVM.prototype.execute = function(prg) { ...@@ -558,7 +562,7 @@ RarVM.prototype.execute = function(prg) {
var preparedCodes = prg.AltCmd ? prg.AltCmd : prg.Cmd; var preparedCodes = prg.AltCmd ? prg.AltCmd : prg.Cmd;
if (prg.Cmd.length > 0 && !this.executeCode(preparedCodes)) { if (prg.Cmd.length > 0 && !this.executeCode(preparedCodes)) {
// Invalid VM program. Let's replace it with 'return' command. // Invalid VM program. Let's replace it with 'return' command.
preparedCode.OpCode = VM_Commands.VM_RET; preparedCodes.OpCode = VmCommands.VM_RET;
} }
var dataView = new DataView(this.mem_.buffer, VM_GLOBALMEMADDR); var dataView = new DataView(this.mem_.buffer, VM_GLOBALMEMADDR);
...@@ -573,7 +577,7 @@ RarVM.prototype.execute = function(prg) { ...@@ -573,7 +577,7 @@ RarVM.prototype.execute = function(prg) {
var dataSize = Math.min(dataView.getUint32(0x30), var dataSize = Math.min(dataView.getUint32(0x30),
(VM_GLOBALMEMSIZE - VM_FIXEDGLOBALSIZE)); (VM_GLOBALMEMSIZE - VM_FIXEDGLOBALSIZE));
if (dataSize != 0) { if (dataSize !== 0) {
var len = dataSize + VM_FIXEDGLOBALSIZE; var len = dataSize + VM_FIXEDGLOBALSIZE;
prg.GlobalData = new Uint8Array(len); prg.GlobalData = new Uint8Array(len);
prg.GlobalData.set(mem.subarray(VM_GLOBALMEMADDR, VM_GLOBALMEMADDR + len)); prg.GlobalData.set(mem.subarray(VM_GLOBALMEMADDR, VM_GLOBALMEMADDR + len));
...@@ -581,7 +585,7 @@ RarVM.prototype.execute = function(prg) { ...@@ -581,7 +585,7 @@ RarVM.prototype.execute = function(prg) {
}; };
/** /**
* @param {Array<VM_PreparedCommand>} preparedCodes * @param {Array<VmPreparedCommand>} preparedCodes
* @return {boolean} * @return {boolean}
*/ */
RarVM.prototype.executeCode = function(preparedCodes) { RarVM.prototype.executeCode = function(preparedCodes) {
...@@ -591,7 +595,7 @@ RarVM.prototype.executeCode = function(preparedCodes) { ...@@ -591,7 +595,7 @@ RarVM.prototype.executeCode = function(preparedCodes) {
// when a VM_RET is hit? // when a VM_RET is hit?
while (1) { while (1) {
switch (cmd.OpCode) { switch (cmd.OpCode) {
case VM_Commands.VM_RET: case VmCommands.VM_RET:
if (this.R_[7] >= VM_MEMSIZE) { if (this.R_[7] >= VM_MEMSIZE) {
return true; return true;
} }
...@@ -599,12 +603,12 @@ RarVM.prototype.executeCode = function(preparedCodes) { ...@@ -599,12 +603,12 @@ RarVM.prototype.executeCode = function(preparedCodes) {
this.R_[7] += 4; this.R_[7] += 4;
continue; continue;
case VM_Commands.VM_STANDARD: case VmCommands.VM_STANDARD:
this.executeStandardFilter(cmd.Op1.Data); this.executeStandardFilter(cmd.Op1.Data);
break; break;
default: default:
console.error('RarVM OpCode not supported: ' + getDebugString(VM_Commands, cmd.OpCode)); console.error("RarVM OpCode not supported: " + getDebugString(VmCommands, cmd.OpCode));
break; break;
} // switch (cmd.OpCode) } // switch (cmd.OpCode)
codeIndex++; codeIndex++;
...@@ -617,7 +621,7 @@ RarVM.prototype.executeCode = function(preparedCodes) { ...@@ -617,7 +621,7 @@ RarVM.prototype.executeCode = function(preparedCodes) {
*/ */
RarVM.prototype.executeStandardFilter = function(filterType) { RarVM.prototype.executeStandardFilter = function(filterType) {
switch (filterType) { switch (filterType) {
case VM_StandardFilters.VMSF_DELTA: case VmStandardFilters.VMSF_DELTA:
var dataSize = this.R_[4]; var dataSize = this.R_[4];
var channels = this.R_[0]; var channels = this.R_[0];
var srcPos = 0; var srcPos = 0;
...@@ -644,17 +648,19 @@ RarVM.prototype.executeStandardFilter = function(filterType) { ...@@ -644,17 +648,19 @@ RarVM.prototype.executeStandardFilter = function(filterType) {
break; break;
default: default:
console.error('RarVM Standard Filter not supported: ' + getDebugString(VM_StandardFilters, filterType)); console.error("RarVM Standard Filter not supported: " + getDebugString(VmStandardFilters, filterType));
break; break;
} }
}; };
/** /**
* @param {Uint8Array} code * @param {Uint8Array} code
* @param {VM_PreparedProgram} prg * @param {VmPreparedProgram} prg
*/ */
RarVM.prototype.prepare = function(code, prg) { RarVM.prototype.prepare = function(code, prg) {
var codeSize = code.length; var codeSize = code.length;
var i;
var curCmd;
//InitBitInput(); //InitBitInput();
//memcpy(InBuf,Code,Min(CodeSize,BitInput::MAX_SIZE)); //memcpy(InBuf,Code,Min(CodeSize,BitInput::MAX_SIZE));
...@@ -662,7 +668,7 @@ RarVM.prototype.prepare = function(code, prg) { ...@@ -662,7 +668,7 @@ RarVM.prototype.prepare = function(code, prg) {
// Calculate the single byte XOR checksum to check validity of VM code. // Calculate the single byte XOR checksum to check validity of VM code.
var xorSum = 0; var xorSum = 0;
for (var i = 1; i < codeSize; ++i) { for (i = 1; i < codeSize; ++i) {
xorSum ^= code[i]; xorSum ^= code[i];
} }
...@@ -671,20 +677,20 @@ RarVM.prototype.prepare = function(code, prg) { ...@@ -671,20 +677,20 @@ RarVM.prototype.prepare = function(code, prg) {
prg.Cmd = []; // TODO: Is this right? I don't see it being done in rarvm.cpp. prg.Cmd = []; // TODO: Is this right? I don't see it being done in rarvm.cpp.
// VM code is valid if equal. // VM code is valid if equal.
if (xorSum == code[0]) { if (xorSum === code[0]) {
var filterType = this.isStandardFilter(code); var filterType = this.isStandardFilter(code);
if (filterType != VM_StandardFilters.VMSF_NONE) { if (filterType !== VmStandardFilters.VMSF_NONE) {
// VM code is found among standard filters. // VM code is found among standard filters.
var curCmd = new VM_PreparedCommand(); curCmd = new VmPreparedCommand();
prg.Cmd.push(curCmd); prg.Cmd.push(curCmd);
curCmd.OpCode = VM_Commands.VM_STANDARD; curCmd.OpCode = VmCommands.VM_STANDARD;
curCmd.Op1.Data = filterType; curCmd.Op1.Data = filterType;
// TODO: Addr=&CurCmd->Op1.Data // TODO: Addr=&CurCmd->Op1.Data
curCmd.Op1.Addr = [curCmd.Op1.Data]; curCmd.Op1.Addr = [curCmd.Op1.Data];
curCmd.Op2.Addr = [null]; // &CurCmd->Op2.Data; curCmd.Op2.Addr = [null]; // &CurCmd->Op2.Data;
curCmd.Op1.Type = VM_OpType.VM_OPNONE; curCmd.Op1.Type = VmOpType.VM_OPNONE;
curCmd.Op2.Type = VM_OpType.VM_OPNONE; curCmd.Op2.Type = VmOpType.VM_OPNONE;
codeSize = 0; codeSize = 0;
} }
...@@ -696,7 +702,7 @@ RarVM.prototype.prepare = function(code, prg) { ...@@ -696,7 +702,7 @@ RarVM.prototype.prepare = function(code, prg) {
if (dataFlag & 0x8000) { if (dataFlag & 0x8000) {
var dataSize = RarVM.readData(bstream) + 1; var dataSize = RarVM.readData(bstream) + 1;
// TODO: This accesses the byte pointer of the bstream directly. Is that ok? // TODO: This accesses the byte pointer of the bstream directly. Is that ok?
for (var i = 0; i < bstream.bytePtr < codeSize && i < dataSize; ++i) { for (i = 0; i < bstream.bytePtr < codeSize && i < dataSize; ++i) {
// Append a byte to the program's static data. // Append a byte to the program's static data.
var newStaticData = new Uint8Array(prg.StaticData.length + 1); var newStaticData = new Uint8Array(prg.StaticData.length + 1);
newStaticData.set(prg.StaticData); newStaticData.set(prg.StaticData);
...@@ -706,7 +712,7 @@ RarVM.prototype.prepare = function(code, prg) { ...@@ -706,7 +712,7 @@ RarVM.prototype.prepare = function(code, prg) {
} }
while (bstream.bytePtr < codeSize) { while (bstream.bytePtr < codeSize) {
var curCmd = new VM_PreparedCommand(); curCmd = new VmPreparedCommand();
prg.Cmd.push(curCmd); // Prg->Cmd.Add(1) prg.Cmd.push(curCmd); // Prg->Cmd.Add(1)
var flag = bstream.peekBits(1); var flag = bstream.peekBits(1);
if (!flag) { // (Data&0x8000)==0 if (!flag) { // (Data&0x8000)==0
...@@ -715,22 +721,22 @@ RarVM.prototype.prepare = function(code, prg) { ...@@ -715,22 +721,22 @@ RarVM.prototype.prepare = function(code, prg) {
curCmd.OpCode = (bstream.readBits(6) - 24); curCmd.OpCode = (bstream.readBits(6) - 24);
} }
if (VM_CmdFlags[curCmd.OpCode] & VMCF_BYTEMODE) { if (VmCmdFlags[curCmd.OpCode] & VMCF_BYTEMODE) {
curCmd.ByteMode = (bstream.readBits(1) != 0); curCmd.ByteMode = (bstream.readBits(1) !== 0);
} else { } else {
curCmd.ByteMode = 0; curCmd.ByteMode = 0;
} }
curCmd.Op1.Type = VM_OpType.VM_OPNONE; curCmd.Op1.Type = VmOpType.VM_OPNONE;
curCmd.Op2.Type = VM_OpType.VM_OPNONE; curCmd.Op2.Type = VmOpType.VM_OPNONE;
var opNum = (VM_CmdFlags[curCmd.OpCode] & VMCF_OPMASK); var opNum = (VmCmdFlags[curCmd.OpCode] & VMCF_OPMASK);
curCmd.Op1.Addr = null; curCmd.Op1.Addr = null;
curCmd.Op2.Addr = null; curCmd.Op2.Addr = null;
if (opNum > 0) { if (opNum > 0) {
this.decodeArg(curCmd.Op1, curCmd.ByteMode, bstream); // reading the first operand this.decodeArg(curCmd.Op1, curCmd.ByteMode, bstream); // reading the first operand
if (opNum == 2) { if (opNum === 2) {
this.decodeArg(curCmd.Op2, curCmd.ByteMode, bstream); // reading the second operand this.decodeArg(curCmd.Op2, curCmd.ByteMode, bstream); // reading the second operand
} else { } else {
if (curCmd.Op1.Type == VM_OpType.VM_OPINT && (VM_CmdFlags[curCmd.OpCode] & (VMCF_JUMP | VMCF_PROC))) { if (curCmd.Op1.Type === VmOpType.VM_OPINT && (VmCmdFlags[curCmd.OpCode] & (VMCF_JUMP | VMCF_PROC))) {
// Calculating jump distance. // Calculating jump distance.
var distance = curCmd.Op1.Data; var distance = curCmd.Op1.Data;
if (distance >= 256) { if (distance >= 256) {
...@@ -756,26 +762,26 @@ RarVM.prototype.prepare = function(code, prg) { ...@@ -756,26 +762,26 @@ RarVM.prototype.prepare = function(code, prg) {
} // while ((uint)InAddr<CodeSize) } // while ((uint)InAddr<CodeSize)
} // if (XorSum==Code[0]) } // if (XorSum==Code[0])
var curCmd = new VM_PreparedCommand(); curCmd = new VmPreparedCommand();
prg.Cmd.push(curCmd); prg.Cmd.push(curCmd);
curCmd.OpCode = VM_Commands.VM_RET; curCmd.OpCode = VmCommands.VM_RET;
// TODO: Addr=&CurCmd->Op1.Data // TODO: Addr=&CurCmd->Op1.Data
curCmd.Op1.Addr = [curCmd.Op1.Data]; curCmd.Op1.Addr = [curCmd.Op1.Data];
curCmd.Op2.Addr = [curCmd.Op2.Data]; curCmd.Op2.Addr = [curCmd.Op2.Data];
curCmd.Op1.Type = VM_OpType.VM_OPNONE; curCmd.Op1.Type = VmOpType.VM_OPNONE;
curCmd.Op2.Type = VM_OpType.VM_OPNONE; curCmd.Op2.Type = VmOpType.VM_OPNONE;
// If operand 'Addr' field has not been set by DecodeArg calls above, // If operand 'Addr' field has not been set by DecodeArg calls above,
// let's set it to point to operand 'Data' field. It is necessary for // let's set it to point to operand 'Data' field. It is necessary for
// VM_OPINT type operands (usual integers) or maybe if something was // VM_OPINT type operands (usual integers) or maybe if something was
// not set properly for other operands. 'Addr' field is required // not set properly for other operands. 'Addr' field is required
// for quicker addressing of operand data. // for quicker addressing of operand data.
for (var i = 0; i < prg.Cmd.length; ++i) { for (i = 0; i < prg.Cmd.length; ++i) {
var cmd = prg.Cmd[i]; var cmd = prg.Cmd[i];
if (cmd.Op1.Addr == null) { if (cmd.Op1.Addr === null) {
cmd.Op1.Addr = [cmd.Op1.Data]; cmd.Op1.Addr = [cmd.Op1.Data];
} }
if (cmd.Op2.Addr == null) { if (cmd.Op2.Addr === null) {
cmd.Op2.Addr = [cmd.Op2.Data]; cmd.Op2.Addr = [cmd.Op2.Data];
} }
} }
...@@ -833,7 +839,7 @@ RarVM.readData = function(bstream) { ...@@ -833,7 +839,7 @@ RarVM.readData = function(bstream) {
case 1: // 0x4000 case 1: // 0x4000
// 0x3c00 => 0011 1100 0000 0000 // 0x3c00 => 0011 1100 0000 0000
if (bstream.peekBits(4) == 0) { // (Data&0x3c00)==0 if (bstream.peekBits(4) === 0) { // (Data&0x3c00)==0
// Skip the 4 zero bits. // Skip the 4 zero bits.
bstream.readBits(4); bstream.readBits(4);
// Read in the next 8 and pad with 1s to 32 bits. // Read in the next 8 and pad with 1s to 32 bits.
......
...@@ -10,13 +10,14 @@ ...@@ -10,13 +10,14 @@
* *
* http://kthoom.googlecode.com/hg/docs/unrar.html * http://kthoom.googlecode.com/hg/docs/unrar.html
*/ */
/* global bitjs, importScripts */ /* global bitjs, importScripts, RarVM, Uint8Array, UnpackFilter */
/* global VM_FIXEDGLOBALSIZE, VM_GLOBALMEMSIZE, MAXWINMASK, VM_GLOBALMEMADDR, MAXWINSIZE */
// This file expects to be invoked as a Worker (see onmessage below). // This file expects to be invoked as a Worker (see onmessage below).
importScripts('../io/bitstream.js'); importScripts("../io/bitstream.js");
importScripts('../io/bytebuffer.js'); importScripts("../io/bytebuffer.js");
importScripts('archive.js'); importScripts("archive.js");
importScripts('rarvm.js'); importScripts("rarvm.js");
// Progress variables. // Progress variables.
var currentFilename = ""; var currentFilename = "";
...@@ -296,6 +297,12 @@ var rBuffer; ...@@ -296,6 +297,12 @@ var rBuffer;
*/ */
var wBuffer; var wBuffer;
var lowDistRepCount = 0;
var prevLowDist = 0;
var rOldDist = [0, 0, 0, 0];
var lastDist;
var lastLength;
/** /**
* In unpack.cpp, UnpPtr keeps track of what bytes have been unpacked * In unpack.cpp, UnpPtr keeps track of what bytes have been unpacked
...@@ -449,7 +456,7 @@ function rarMakeDecodeTables(BitLength, offset, dec, size) { ...@@ -449,7 +456,7 @@ function rarMakeDecodeTables(BitLength, offset, dec, size) {
TmpPos[I] = DecodePos[I]; TmpPos[I] = DecodePos[I];
} }
for (I = 0; I < size; ++I) { for (I = 0; I < size; ++I) {
if (BitLength[I + offset] != 0) { if (BitLength[I + offset] !== 0) {
DecodeNum[TmpPos[BitLength[offset + I] & 0xF]++] = I; DecodeNum[TmpPos[BitLength[offset + I] & 0xF]++] = I;
} }
} }
...@@ -524,7 +531,7 @@ function unpack20(bstream) { //, Solid) { ...@@ -524,7 +531,7 @@ function unpack20(bstream) { //, Solid) {
if (Distance >= 0x101) { if (Distance >= 0x101) {
Length++; Length++;
if (Distance >= 0x2000) { if (Distance >= 0x2000) {
Length++ Length++;
if (Distance >= 0x40000) { if (Distance >= 0x40000) {
Length++; Length++;
} }
...@@ -611,13 +618,6 @@ function rarReadTables20(bstream) { ...@@ -611,13 +618,6 @@ function rarReadTables20(bstream) {
} }
} }
var lowDistRepCount = 0;
var prevLowDist = 0;
var rOldDist = [0, 0, 0, 0];
var lastDist;
var lastLength;
// ============================================================================================== // // ============================================================================================== //
// Unpack code specific to RarVM // Unpack code specific to RarVM
...@@ -644,7 +644,7 @@ var OldFilterLengths = []; ...@@ -644,7 +644,7 @@ var OldFilterLengths = [];
var LastFilter = 0; var LastFilter = 0;
function InitFilters() { function initFilters() {
OldFilterLengths = []; OldFilterLengths = [];
LastFilter = 0; LastFilter = 0;
Filters = []; Filters = [];
...@@ -658,13 +658,14 @@ function InitFilters() { ...@@ -658,13 +658,14 @@ function InitFilters() {
*/ */
function rarAddVMCode(firstByte, vmCode) { function rarAddVMCode(firstByte, vmCode) {
VM.init(); VM.init();
var i;
var bstream = new bitjs.io.BitStream(vmCode.buffer, true /* rtl */ ); var bstream = new bitjs.io.BitStream(vmCode.buffer, true /* rtl */ );
var filtPos; var filtPos;
if (firstByte & 0x80) { if (firstByte & 0x80) {
filtPos = RarVM.readData(bstream); filtPos = RarVM.readData(bstream);
if (filtPos == 0) { if (filtPos === 0) {
InitFilters(); initFilters();
} else { } else {
filtPos--; filtPos--;
} }
...@@ -677,7 +678,7 @@ function rarAddVMCode(firstByte, vmCode) { ...@@ -677,7 +678,7 @@ function rarAddVMCode(firstByte, vmCode) {
} }
LastFilter = filtPos; LastFilter = filtPos;
var newFilter = (filtPos == Filters.length); var newFilter = (filtPos === Filters.length);
// new filter for PrgStack // new filter for PrgStack
var stackFilter = new UnpackFilter(); var stackFilter = new UnpackFilter();
...@@ -701,10 +702,10 @@ function rarAddVMCode(firstByte, vmCode) { ...@@ -701,10 +702,10 @@ function rarAddVMCode(firstByte, vmCode) {
} }
var emptyCount = 0; var emptyCount = 0;
for (var i = 0; i < PrgStack.length; ++i) { for (i = 0; i < PrgStack.length; ++i) {
PrgStack[i - emptyCount] = PrgStack[i]; PrgStack[i - emptyCount] = PrgStack[i];
if (PrgStack[i] == null) { if (PrgStack[i] === null) {
emptyCount++; emptyCount++;
} }
if (emptyCount > 0) { if (emptyCount > 0) {
...@@ -712,7 +713,7 @@ function rarAddVMCode(firstByte, vmCode) { ...@@ -712,7 +713,7 @@ function rarAddVMCode(firstByte, vmCode) {
} }
} }
if (emptyCount == 0) { if (emptyCount === 0) {
PrgStack.push(null); //PrgStack.Add(1); PrgStack.push(null); //PrgStack.Add(1);
emptyCount = 1; emptyCount = 1;
} }
...@@ -734,12 +735,12 @@ function rarAddVMCode(firstByte, vmCode) { ...@@ -734,12 +735,12 @@ function rarAddVMCode(firstByte, vmCode) {
OldFilterLengths[filtPos] : OldFilterLengths[filtPos] :
0; 0;
} }
stackFilter.NextWindow = (wBuffer.ptr != rBuffer.ptr) && stackFilter.NextWindow = (wBuffer.ptr !== rBuffer.ptr) &&
(((wBuffer.ptr - rBuffer.ptr) & MAXWINMASK) <= blockStart); (((wBuffer.ptr - rBuffer.ptr) & MAXWINMASK) <= blockStart);
OldFilterLengths[filtPos] = stackFilter.BlockLength; OldFilterLengths[filtPos] = stackFilter.BlockLength;
for (var i = 0; i < 7; ++i) { for (i = 0; i < 7; ++i) {
stackFilter.Prg.InitR[i] = 0; stackFilter.Prg.InitR[i] = 0;
} }
stackFilter.Prg.InitR[3] = VM_GLOBALMEMADDR; stackFilter.Prg.InitR[3] = VM_GLOBALMEMADDR;
...@@ -749,7 +750,7 @@ function rarAddVMCode(firstByte, vmCode) { ...@@ -749,7 +750,7 @@ function rarAddVMCode(firstByte, vmCode) {
// set registers to optional parameters if any // set registers to optional parameters if any
if (firstByte & 0x10) { if (firstByte & 0x10) {
var initMask = bstream.readBits(7); var initMask = bstream.readBits(7);
for (var i = 0; i < 7; ++i) { for (i = 0; i < 7; ++i) {
if (initMask & (1 << i)) { if (initMask & (1 << i)) {
stackFilter.Prg.InitR[i] = RarVM.readData(bstream); stackFilter.Prg.InitR[i] = RarVM.readData(bstream);
} }
...@@ -758,11 +759,11 @@ function rarAddVMCode(firstByte, vmCode) { ...@@ -758,11 +759,11 @@ function rarAddVMCode(firstByte, vmCode) {
if (newFilter) { if (newFilter) {
var vmCodeSize = RarVM.readData(bstream); var vmCodeSize = RarVM.readData(bstream);
if (vmCodeSize >= 0x10000 || vmCodeSize == 0) { if (vmCodeSize >= 0x10000 || vmCodeSize === 0) {
return false; return false;
} }
var vmCode = new Uint8Array(vmCodeSize); vmCode = new Uint8Array(vmCodeSize);
for (var i = 0; i < vmCodeSize; ++i) { for (i = 0; i < vmCodeSize; ++i) {
//if (Inp.Overflow(3)) //if (Inp.Overflow(3))
// return(false); // return(false);
vmCode[i] = bstream.readBits(8); vmCode[i] = bstream.readBits(8);
...@@ -775,7 +776,7 @@ function rarAddVMCode(firstByte, vmCode) { ...@@ -775,7 +776,7 @@ function rarAddVMCode(firstByte, vmCode) {
var staticDataSize = filter.Prg.StaticData.length; var staticDataSize = filter.Prg.StaticData.length;
if (staticDataSize > 0 && staticDataSize < VM_GLOBALMEMSIZE) { if (staticDataSize > 0 && staticDataSize < VM_GLOBALMEMSIZE) {
// read statically defined data contained in DB commands // read statically defined data contained in DB commands
for (var i = 0; i < staticDataSize; ++i) { for (i = 0; i < staticDataSize; ++i) {
stackFilter.Prg.StaticData[i] = filter.Prg.StaticData[i]; stackFilter.Prg.StaticData[i] = filter.Prg.StaticData[i];
} }
} }
...@@ -785,14 +786,14 @@ function rarAddVMCode(firstByte, vmCode) { ...@@ -785,14 +786,14 @@ function rarAddVMCode(firstByte, vmCode) {
} }
var globalData = stackFilter.Prg.GlobalData; var globalData = stackFilter.Prg.GlobalData;
for (var i = 0; i < 7; ++i) { for (i = 0; i < 7; ++i) {
VM.setLowEndianValue(globalData, stackFilter.Prg.InitR[i], i * 4); VM.setLowEndianValue(globalData, stackFilter.Prg.InitR[i], i * 4);
} }
VM.setLowEndianValue(globalData, stackFilter.BlockLength, 0x1c); VM.setLowEndianValue(globalData, stackFilter.BlockLength, 0x1c);
VM.setLowEndianValue(globalData, 0, 0x20); VM.setLowEndianValue(globalData, 0, 0x20);
VM.setLowEndianValue(globalData, stackFilter.ExecCount, 0x2c); VM.setLowEndianValue(globalData, stackFilter.ExecCount, 0x2c);
for (var i = 0; i < 16; ++i) { for (i = 0; i < 16; ++i) {
globalData[0x30 + i] = 0; globalData[0x30 + i] = 0;
} }
...@@ -816,7 +817,7 @@ function rarAddVMCode(firstByte, vmCode) { ...@@ -816,7 +817,7 @@ function rarAddVMCode(firstByte, vmCode) {
globalData = newGlobalData; globalData = newGlobalData;
} }
//byte *GlobalData=&StackFilter->Prg.GlobalData[VM_FIXEDGLOBALSIZE]; //byte *GlobalData=&StackFilter->Prg.GlobalData[VM_FIXEDGLOBALSIZE];
for (var i = 0; i < dataSize; ++i) { for (i = 0; i < dataSize; ++i) {
//if (Inp.Overflow(3)) //if (Inp.Overflow(3))
// return(false); // return(false);
globalData[VM_FIXEDGLOBALSIZE + i] = bstream.readBits(8); globalData[VM_FIXEDGLOBALSIZE + i] = bstream.readBits(8);
...@@ -833,9 +834,9 @@ function rarAddVMCode(firstByte, vmCode) { ...@@ -833,9 +834,9 @@ function rarAddVMCode(firstByte, vmCode) {
function rarReadVMCode(bstream) { function rarReadVMCode(bstream) {
var firstByte = bstream.readBits(8); var firstByte = bstream.readBits(8);
var length = (firstByte & 7) + 1; var length = (firstByte & 7) + 1;
if (length == 7) { if (length === 7) {
length = bstream.readBits(8) + 7; length = bstream.readBits(8) + 7;
} else if (length == 8) { } else if (length === 8) {
length = bstream.readBits(16); length = bstream.readBits(16);
} }
...@@ -845,7 +846,7 @@ function rarReadVMCode(bstream) { ...@@ -845,7 +846,7 @@ function rarReadVMCode(bstream) {
// Do something here with checking readbuf. // Do something here with checking readbuf.
vmCode[i] = bstream.readBits(8); vmCode[i] = bstream.readBits(8);
} }
return RarAddVMCode(firstByte, vmCode); return rarAddVMCode(firstByte, vmCode);
} }
/** /**
...@@ -990,10 +991,11 @@ function unpack29(bstream) { ...@@ -990,10 +991,11 @@ function unpack29(bstream) {
*/ */
function rarWriteBuf() { function rarWriteBuf() {
var writeSize = (rBuffer.ptr & MAXWINMASK); var writeSize = (rBuffer.ptr & MAXWINMASK);
var j;
var flt;
for (var i = 0; i < PrgStack.length; ++i) { for (var i = 0; i < PrgStack.length; ++i) {
var flt = PrgStack[i]; flt = PrgStack[i];
if (flt == null) { if (flt === null) {
continue; continue;
} }
...@@ -1004,17 +1006,18 @@ function rarWriteBuf() { ...@@ -1004,17 +1006,18 @@ function rarWriteBuf() {
var blockStart = flt.BlockStart; var blockStart = flt.BlockStart;
var blockLength = flt.BlockLength; var blockLength = flt.BlockLength;
var parentPrg;
// WrittenBorder = wBuffer.ptr // WrittenBorder = wBuffer.ptr
if (((blockStart - wBuffer.ptr) & MAXWINMASK) < writeSize) { if (((blockStart - wBuffer.ptr) & MAXWINMASK) < writeSize) {
if (wBuffer.ptr != blockStart) { if (wBuffer.ptr !== blockStart) {
// Copy blockStart bytes from rBuffer into wBuffer. // Copy blockStart bytes from rBuffer into wBuffer.
rarWriteArea(wBuffer.ptr, blockStart); rarWriteArea(wBuffer.ptr, blockStart);
writeSize = (rBuffer.ptr - wBuffer.ptr) & MAXWINMASK; writeSize = (rBuffer.ptr - wBuffer.ptr) & MAXWINMASK;
} }
if (blockLength <= writeSize) { if (blockLength <= writeSize) {
var blockEnd = (blockStart + blockLength) & MAXWINMASK; var blockEnd = (blockStart + blockLength) & MAXWINMASK;
if (blockStart < blockEnd || blockEnd == 0) { if (blockStart < blockEnd || blockEnd === 0) {
VM.setMemory(0, rBuffer.data.subarray(blockStart, blockStart + blockLength), blockLength); VM.setMemory(0, rBuffer.data.subarray(blockStart, blockStart + blockLength), blockLength);
} else { } else {
var firstPartLength = MAXWINSIZE - blockStart; var firstPartLength = MAXWINSIZE - blockStart;
...@@ -1022,7 +1025,7 @@ function rarWriteBuf() { ...@@ -1022,7 +1025,7 @@ function rarWriteBuf() {
VM.setMemory(firstPartLength, rBuffer.data, blockEnd); VM.setMemory(firstPartLength, rBuffer.data, blockEnd);
} }
var parentPrg = Filters[flt.ParentFilter].Prg; parentPrg = Filters[flt.ParentFilter].Prg;
var prg = flt.Prg; var prg = flt.Prg;
if (parentPrg.GlobalData.length > VM_FIXEDGLOBALSIZE) { if (parentPrg.GlobalData.length > VM_FIXEDGLOBALSIZE) {
...@@ -1031,10 +1034,11 @@ function rarWriteBuf() { ...@@ -1031,10 +1034,11 @@ function rarWriteBuf() {
} }
rarExecuteCode(prg); rarExecuteCode(prg);
var globalDataLen;
if (prg.GlobalData.length > VM_FIXEDGLOBALSIZE) { if (prg.GlobalData.length > VM_FIXEDGLOBALSIZE) {
// Save global data for next script execution. // Save global data for next script execution.
var globalDataLen = prg.GlobalData.length; globalDataLen = prg.GlobalData.length;
if (parentPrg.GlobalData.length < globalDataLen) { if (parentPrg.GlobalData.length < globalDataLen) {
parentPrg.GlobalData = new Uint8Array(globalDataLen); parentPrg.GlobalData = new Uint8Array(globalDataLen);
} }
...@@ -1050,8 +1054,8 @@ function rarWriteBuf() { ...@@ -1050,8 +1054,8 @@ function rarWriteBuf() {
PrgStack[i] = null; PrgStack[i] = null;
while (i + 1 < PrgStack.length) { while (i + 1 < PrgStack.length) {
var nextFilter = PrgStack[i + 1]; var nextFilter = PrgStack[i + 1];
if (nextFilter == null || nextFilter.BlockStart != blockStart || if (nextFilter === null || nextFilter.BlockStart !== blockStart ||
nextFilter.BlockLength != filteredData.length || nextFilter.NextWindow) { nextFilter.BlockLength !== filteredData.length || nextFilter.NextWindow) {
break; break;
} }
...@@ -1059,10 +1063,10 @@ function rarWriteBuf() { ...@@ -1059,10 +1063,10 @@ function rarWriteBuf() {
VM.setMemory(0, filteredData, filteredData.length); VM.setMemory(0, filteredData, filteredData.length);
var parentPrg = Filters[nextFilter.ParentFilter].Prg; parentPrg = Filters[nextFilter.ParentFilter].Prg;
var nextPrg = nextFilter.Prg; var nextPrg = nextFilter.Prg;
var globalDataLen = parentPrg.GlobalData.length; globalDataLen = parentPrg.GlobalData.length;
if (globalDataLen > VM_FIXEDGLOBALSIZE) { if (globalDataLen > VM_FIXEDGLOBALSIZE) {
// Copy global data from previous script execution if any. // Copy global data from previous script execution if any.
nextPrg.GlobalData = new Uint8Array(globalDataLen); nextPrg.GlobalData = new Uint8Array(globalDataLen);
...@@ -1073,7 +1077,7 @@ function rarWriteBuf() { ...@@ -1073,7 +1077,7 @@ function rarWriteBuf() {
if (nextPrg.GlobalData.length > VM_GLOBALMEMSIZE) { if (nextPrg.GlobalData.length > VM_GLOBALMEMSIZE) {
// Save global data for next script execution. // Save global data for next script execution.
var globalDataLen = nextPrg.GlobalData.length; globalDataLen = nextPrg.GlobalData.length;
if (parentPrg.GlobalData.length < globalDataLen) { if (parentPrg.GlobalData.length < globalDataLen) {
parentPrg.GlobalData = new Uint8Array(globalDataLen); parentPrg.GlobalData = new Uint8Array(globalDataLen);
} }
...@@ -1089,15 +1093,14 @@ function rarWriteBuf() { ...@@ -1089,15 +1093,14 @@ function rarWriteBuf() {
PrgStack[i] = null; PrgStack[i] = null;
} // while (i + 1 < PrgStack.length) } // while (i + 1 < PrgStack.length)
for (var j = 0; j < filteredData.length; ++j) { for (j = 0; j < filteredData.length; ++j) {
wBuffer.insertByte(filteredData[j]); wBuffer.insertByte(filteredData[j]);
} }
writeSize = (rBuffer.ptr - wBuffer.ptr) & MAXWINMASK; writeSize = (rBuffer.ptr - wBuffer.ptr) & MAXWINMASK;
} // if (blockLength <= writeSize) } else { // if (blockLength <= writeSize)
else { for (j = i; j < PrgStack.length; ++j) {
for (var j = i; j < PrgStack.length; ++j) { flt = PrgStack[j];
var flt = PrgStack[j]; if (flt !== null && flt.NextWindow) {
if (flt != null && flt.NextWindow) {
flt.NextWindow = false; flt.NextWindow = false;
} }
} }
...@@ -1121,7 +1124,7 @@ function rarWriteBuf() { ...@@ -1121,7 +1124,7 @@ function rarWriteBuf() {
*/ */
function rarWriteArea(startPtr, endPtr) { function rarWriteArea(startPtr, endPtr) {
if (endPtr < startPtr) { if (endPtr < startPtr) {
console.error('endPtr < startPtr, endPtr=' + endPtr + ', startPtr=' + startPtr); console.error("endPtr < startPtr, endPtr=" + endPtr + ", startPtr=" + startPtr);
// rarWriteData(startPtr, -(int)StartPtr & MAXWINMASK); // rarWriteData(startPtr, -(int)StartPtr & MAXWINMASK);
// RarWriteData(0, endPtr); // RarWriteData(0, endPtr);
return; return;
...@@ -1220,8 +1223,8 @@ function rarCopyString(length, distance) { ...@@ -1220,8 +1223,8 @@ function rarCopyString(length, distance) {
function unpack(v) { function unpack(v) {
// TODO: implement what happens when unpVer is < 15 // TODO: implement what happens when unpVer is < 15
var Ver = v.header.unpVer <= 15 ? 15 : v.header.unpVer; var Ver = v.header.unpVer <= 15 ? 15 : v.header.unpVer;
var Solid = v.header.LHD_SOLID; // var Solid = v.header.LHD_SOLID;
var bstream = new bitjs.io.BitStream(v.fileData.buffer, true /* rtl */ , v.fileData.byteOffset, v.fileData.byteLength); var bstream = new bitjs.io.BitStream(v.fileData.buffer, true /* rtl */, v.fileData.byteOffset, v.fileData.byteLength);
rBuffer = new bitjs.io.ByteBuffer(v.header.unpackedSize); rBuffer = new bitjs.io.ByteBuffer(v.header.unpackedSize);
......
...@@ -10,9 +10,11 @@ ...@@ -10,9 +10,11 @@
* TAR format: http://www.gnu.org/software/automake/manual/tar/Standard.html * TAR format: http://www.gnu.org/software/automake/manual/tar/Standard.html
*/ */
/* global bitjs, importScripts, Uint8Array */
// This file expects to be invoked as a Worker (see onmessage below). // This file expects to be invoked as a Worker (see onmessage below).
importScripts('../io/bytestream.js'); importScripts("../io/bytestream.js");
importScripts('archive.js'); importScripts("archive.js");
// Progress variables. // Progress variables.
var currentFilename = ""; var currentFilename = "";
...@@ -21,6 +23,7 @@ var currentBytesUnarchivedInFile = 0; ...@@ -21,6 +23,7 @@ var currentBytesUnarchivedInFile = 0;
var currentBytesUnarchived = 0; var currentBytesUnarchived = 0;
var totalUncompressedBytesInArchive = 0; var totalUncompressedBytesInArchive = 0;
var totalFilesInArchive = 0; var totalFilesInArchive = 0;
var allLocalFiles = [];
// Helper functions. // Helper functions.
var info = function(str) { var info = function(str) {
...@@ -44,7 +47,7 @@ var postProgress = function() { ...@@ -44,7 +47,7 @@ var postProgress = function() {
currentBytesUnarchivedInFile, currentBytesUnarchivedInFile,
currentBytesUnarchived, currentBytesUnarchived,
totalUncompressedBytesInArchive, totalUncompressedBytesInArchive,
totalFilesInArchive, totalFilesInArchive
)); ));
}; };
...@@ -66,7 +69,7 @@ var TarLocalFile = function(bstream) { ...@@ -66,7 +69,7 @@ var TarLocalFile = function(bstream) {
this.linkname = readCleanString(bstream, 100); this.linkname = readCleanString(bstream, 100);
this.maybeMagic = readCleanString(bstream, 6); this.maybeMagic = readCleanString(bstream, 6);
if (this.maybeMagic == "ustar") { if (this.maybeMagic === "ustar") {
this.version = readCleanString(bstream, 2); this.version = readCleanString(bstream, 2);
this.uname = readCleanString(bstream, 32); this.uname = readCleanString(bstream, 32);
this.gname = readCleanString(bstream, 32); this.gname = readCleanString(bstream, 32);
...@@ -103,14 +106,14 @@ var TarLocalFile = function(bstream) { ...@@ -103,14 +106,14 @@ var TarLocalFile = function(bstream) {
} }
// Round up to 512-byte blocks. // Round up to 512-byte blocks.
var remaining = 512 - bytesRead % 512; var remaining = 512 - (bytesRead % 512);
if (remaining > 0 && remaining < 512) { if (remaining > 0 && remaining < 512) {
bstream.readBytes(remaining); bstream.readBytes(remaining);
} }
} else if (this.typeflag == 5) { } else if (this.typeflag == 5) {
info(" This is a directory."); info(" This is a directory.");
} }
} };
var untar = function(arrayBuffer) { var untar = function(arrayBuffer) {
postMessage(new bitjs.archive.UnarchiveStartEvent()); postMessage(new bitjs.archive.UnarchiveStartEvent());
...@@ -125,7 +128,7 @@ var untar = function(arrayBuffer) { ...@@ -125,7 +128,7 @@ var untar = function(arrayBuffer) {
var bstream = new bitjs.io.ByteStream(arrayBuffer); var bstream = new bitjs.io.ByteStream(arrayBuffer);
postProgress(); postProgress();
// While we don't encounter an empty block, keep making TarLocalFiles. // While we don't encounter an empty block, keep making TarLocalFiles.
while (bstream.peekNumber(4) != 0) { while (bstream.peekNumber(4) !== 0) {
var oneLocalFile = new TarLocalFile(bstream); var oneLocalFile = new TarLocalFile(bstream);
if (oneLocalFile && oneLocalFile.isValid) { if (oneLocalFile && oneLocalFile.isValid) {
// If we make it to this point and haven't thrown an error, we have successfully // If we make it to this point and haven't thrown an error, we have successfully
...@@ -159,8 +162,8 @@ onmessage = function(event) { ...@@ -159,8 +162,8 @@ onmessage = function(event) {
// Overrun the buffer. // Overrun the buffer.
// unarchiveState = UnarchiveState.WAITING; // unarchiveState = UnarchiveState.WAITING;
} else { } else {
console.error("Found an error while untarring"); err("Found an error while untarring");
console.log(e); err(e);
throw e; throw e;
} }
} }
......
...@@ -14,10 +14,10 @@ ...@@ -14,10 +14,10 @@
/* global bitjs, importScripts, Uint8Array*/ /* global bitjs, importScripts, Uint8Array*/
// This file expects to be invoked as a Worker (see onmessage below). // This file expects to be invoked as a Worker (see onmessage below).
importScripts('../io/bitstream.js'); importScripts("../io/bitstream.js");
importScripts('../io/bytebuffer.js'); importScripts("../io/bytebuffer.js");
importScripts('../io/bytestream.js'); importScripts("../io/bytestream.js");
importScripts('archive.js'); importScripts("archive.js");
// Progress variables. // Progress variables.
var currentFilename = ""; var currentFilename = "";
...@@ -118,13 +118,11 @@ ZipLocalFile.prototype.unzip = function() { ...@@ -118,13 +118,11 @@ ZipLocalFile.prototype.unzip = function() {
currentBytesUnarchivedInFile = this.compressedSize; currentBytesUnarchivedInFile = this.compressedSize;
currentBytesUnarchived += this.compressedSize; currentBytesUnarchived += this.compressedSize;
this.fileData = zeroCompression(this.fileData, this.uncompressedSize); this.fileData = zeroCompression(this.fileData, this.uncompressedSize);
} } else if (this.compressionMethod === 8) {
// version == 20, compression method == 8 (DEFLATE) // version == 20, compression method == 8 (DEFLATE)
else if (this.compressionMethod === 8) {
info("ZIP v2.0, DEFLATE: " + this.filename + " (" + this.compressedSize + " bytes)"); info("ZIP v2.0, DEFLATE: " + this.filename + " (" + this.compressedSize + " bytes)");
this.fileData = inflate(this.fileData, this.uncompressedSize); this.fileData = inflate(this.fileData, this.uncompressedSize);
} } else {
else {
err("UNSUPPORTED VERSION/FORMAT: ZIP v" + this.version + ", compression method=" + this.compressionMethod + ": " + this.filename + " (" + this.compressedSize + " bytes)"); err("UNSUPPORTED VERSION/FORMAT: ZIP v" + this.version + ", compression method=" + this.compressionMethod + ": " + this.filename + " (" + this.compressedSize + " bytes)");
this.fileData = null; this.fileData = null;
} }
...@@ -497,13 +495,11 @@ function inflateBlockData(bstream, hcLiteralTable, hcDistanceTable, buffer) { ...@@ -497,13 +495,11 @@ function inflateBlockData(bstream, hcLiteralTable, hcDistanceTable, buffer) {
// copy literal byte to output // copy literal byte to output
buffer.insertByte(symbol); buffer.insertByte(symbol);
blockSize++; blockSize++;
} } else {
else {
// end of block reached // end of block reached
if (symbol === 256) { if (symbol === 256) {
break; break;
} } else {
else {
var lengthLookup = LengthLookupTable[symbol - 257], var lengthLookup = LengthLookupTable[symbol - 257],
length = lengthLookup[1] + bstream.readBits(lengthLookup[0]), length = lengthLookup[1] + bstream.readBits(lengthLookup[0]),
distLookup = DistLookupTable[decodeSymbol(bstream, hcDistanceTable)], distLookup = DistLookupTable[decodeSymbol(bstream, hcDistanceTable)],
...@@ -566,7 +562,7 @@ function inflate(compressedData, numDecompressedBytes) { ...@@ -566,7 +562,7 @@ function inflate(compressedData, numDecompressedBytes) {
blockSize = 0; blockSize = 0;
// ++numBlocks; // ++numBlocks;
// no compression // no compression
if (bType == 0) { if (bType === 0) {
// skip remaining bits in this byte // skip remaining bits in this byte
while (bstream.bitPtr !== 0) bstream.readBits(1); while (bstream.bitPtr !== 0) bstream.readBits(1);
var len = bstream.readBits(16); var len = bstream.readBits(16);
...@@ -575,13 +571,11 @@ function inflate(compressedData, numDecompressedBytes) { ...@@ -575,13 +571,11 @@ function inflate(compressedData, numDecompressedBytes) {
if (len > 0) buffer.insertBytes(bstream.readBytes(len)); if (len > 0) buffer.insertBytes(bstream.readBytes(len));
blockSize = len; blockSize = len;
} } else if (bType === 1) {
// fixed Huffman codes // fixed Huffman codes
else if (bType === 1) {
blockSize = inflateBlockData(bstream, getFixedLiteralTable(), getFixedDistanceTable(), buffer); blockSize = inflateBlockData(bstream, getFixedLiteralTable(), getFixedDistanceTable(), buffer);
} } else if (bType === 2) {
// dynamic Huffman codes // dynamic Huffman codes
else if (bType === 2) {
var numLiteralLengthCodes = bstream.readBits(5) + 257; var numLiteralLengthCodes = bstream.readBits(5) + 257;
var numDistanceCodes = bstream.readBits(5) + 1, var numDistanceCodes = bstream.readBits(5) + 1,
numCodeLengthCodes = bstream.readBits(4) + 4; numCodeLengthCodes = bstream.readBits(4) + 4;
......
...@@ -26,7 +26,7 @@ $("#sort_name").click(function() { ...@@ -26,7 +26,7 @@ $("#sort_name").click(function() {
var cnt = $("#second").contents(); var cnt = $("#second").contents();
$("#list").append(cnt); $("#list").append(cnt);
// Count no of elements // Count no of elements
var listItems = $('#list').children(".row"); var listItems = $("#list").children(".row");
var listlength = listItems.length; var listlength = listItems.length;
// check for each element if its Starting character matches // check for each element if its Starting character matches
$(".row").each(function() { $(".row").each(function() {
...@@ -35,8 +35,8 @@ $("#sort_name").click(function() { ...@@ -35,8 +35,8 @@ $("#sort_name").click(function() {
} else { } else {
store = this.attributes["data-id"]; store = this.attributes["data-id"];
} }
$(this).find('a').html(store.value); $(this).find("a").html(store.value);
if($(this).css("display") != "none") { if ($(this).css("display") !== "none") {
count++; count++;
} }
}); });
...@@ -49,7 +49,7 @@ $("#sort_name").click(function() { ...@@ -49,7 +49,7 @@ $("#sort_name").click(function() {
// search for the middle of all visibe elements // search for the middle of all visibe elements
$(".row").each(function() { $(".row").each(function() {
index++; index++;
if($(this).css("display") != "none") { if ($(this).css("display") !== "none") {
middle--; middle--;
if (middle <= 0) { if (middle <= 0) {
return false; return false;
...@@ -67,8 +67,8 @@ $("#desc").click(function() { ...@@ -67,8 +67,8 @@ $("#desc").click(function() {
return; return;
} }
var index = 0; var index = 0;
var list = $('#list'); var list = $("#list");
var second = $('#second'); var second = $("#second");
// var cnt = ; // var cnt = ;
list.append(second.contents()); list.append(second.contents());
var listItems = list.children(".row"); var listItems = list.children(".row");
...@@ -78,13 +78,13 @@ $("#desc").click(function() { ...@@ -78,13 +78,13 @@ $("#desc").click(function() {
// Find count of middle element // Find count of middle element
var count = $(".row:visible").length; var count = $(".row:visible").length;
if (count > 20) { if (count > 20) {
var middle = parseInt(count / 2) + (count % 2); middle = parseInt(count / 2) + (count % 2);
//var middle = parseInt(count / 2) + (count % 2); //var middle = parseInt(count / 2) + (count % 2);
// search for the middle of all visible elements // search for the middle of all visible elements
$(reversed).each(function() { $(reversed).each(function() {
index++; index++;
if($(this).css("display") != "none") { if ($(this).css("display") !== "none") {
middle--; middle--;
if (middle <= 0) { if (middle <= 0) {
return false; return false;
...@@ -93,9 +93,8 @@ $("#desc").click(function() { ...@@ -93,9 +93,8 @@ $("#desc").click(function() {
}); });
list.append(reversed.slice(0, index)); list.append(reversed.slice(0, index));
second.append(reversed.slice(index,elementLength)); second.append(reversed.slice(index, elementLength));
} } else {
else {
list.append(reversed.slice(0, elementLength)); list.append(reversed.slice(0, elementLength));
} }
direction = 0; direction = 0;
...@@ -108,11 +107,11 @@ $("#asc").click(function() { ...@@ -108,11 +107,11 @@ $("#asc").click(function() {
} }
var index = 0; var index = 0;
var list = $("#list"); var list = $("#list");
var second = $('#second'); var second = $("#second");
list.append(second.contents()); list.append(second.contents());
var listItems = list.children(".row"); var listItems = list.children(".row");
reversed = listItems.get().reverse(); var reversed = listItems.get().reverse();
elementLength = reversed.length; var elementLength = reversed.length;
// Find count of middle element // Find count of middle element
var count = $(".row:visible").length; var count = $(".row:visible").length;
...@@ -123,7 +122,7 @@ $("#asc").click(function() { ...@@ -123,7 +122,7 @@ $("#asc").click(function() {
// search for the middle of all visible elements // search for the middle of all visible elements
$(reversed).each(function() { $(reversed).each(function() {
index++; index++;
if($(this).css("display") != "none") { if ($(this).css("display") !== "none") {
middle--; middle--;
if (middle <= 0) { if (middle <= 0) {
return false; return false;
...@@ -134,7 +133,7 @@ $("#asc").click(function() { ...@@ -134,7 +133,7 @@ $("#asc").click(function() {
// middle = parseInt(elementLength / 2) + (elementLength % 2); // middle = parseInt(elementLength / 2) + (elementLength % 2);
list.append(reversed.slice(0, index)); list.append(reversed.slice(0, index));
second.append(reversed.slice(index,elementLength)); second.append(reversed.slice(index, elementLength));
} else { } else {
list.append(reversed.slice(0, elementLength)); list.append(reversed.slice(0, elementLength));
} }
...@@ -145,7 +144,7 @@ $("#all").click(function() { ...@@ -145,7 +144,7 @@ $("#all").click(function() {
var cnt = $("#second").contents(); var cnt = $("#second").contents();
$("#list").append(cnt); $("#list").append(cnt);
// Find count of middle element // Find count of middle element
var listItems = $('#list').children(".row"); var listItems = $("#list").children(".row");
var listlength = listItems.length; var listlength = listItems.length;
var middle = parseInt(listlength / 2) + (listlength % 2); var middle = parseInt(listlength / 2) + (listlength % 2);
// go through all elements and make them visible // go through all elements and make them visible
...@@ -154,7 +153,7 @@ $("#all").click(function() { ...@@ -154,7 +153,7 @@ $("#all").click(function() {
}); });
// Move second half of all elements // Move second half of all elements
if (listlength > 20) { if (listlength > 20) {
$("#second").append(listItems.slice(middle,listlength)); $("#second").append(listItems.slice(middle, listlength));
} }
}); });
...@@ -166,7 +165,7 @@ $(".char").click(function() { ...@@ -166,7 +165,7 @@ $(".char").click(function() {
var cnt = $("#second").contents(); var cnt = $("#second").contents();
$("#list").append(cnt); $("#list").append(cnt);
// Count no of elements // Count no of elements
var listItems = $('#list').children(".row"); var listItems = $("#list").children(".row");
var listlength = listItems.length; var listlength = listItems.length;
// check for each element if its Starting character matches // check for each element if its Starting character matches
$(".row").each(function() { $(".row").each(function() {
...@@ -183,7 +182,7 @@ $(".char").click(function() { ...@@ -183,7 +182,7 @@ $(".char").click(function() {
// search for the middle of all visibe elements // search for the middle of all visibe elements
$(".row").each(function() { $(".row").each(function() {
index++; index++;
if($(this).css("display") != "none") { if ($(this).css("display") !== "none") {
middle--; middle--;
if (middle <= 0) { if (middle <= 0) {
return false; return false;
...@@ -191,6 +190,6 @@ $(".char").click(function() { ...@@ -191,6 +190,6 @@ $(".char").click(function() {
} }
}); });
// Move second half of visible elements // Move second half of visible elements
$("#second").append(listItems.slice(index,listlength)); $("#second").append(listItems.slice(index, listlength));
} }
}); });
...@@ -64,7 +64,7 @@ bitjs.io = bitjs.io || {}; ...@@ -64,7 +64,7 @@ bitjs.io = bitjs.io || {};
return 0; return 0;
} }
var movePointers = movePointers || false; movePointers = movePointers || false;
var bytePtr = this.bytePtr; var bytePtr = this.bytePtr;
var bitPtr = this.bitPtr; var bitPtr = this.bitPtr;
var result = 0; var result = 0;
...@@ -125,7 +125,7 @@ bitjs.io = bitjs.io || {}; ...@@ -125,7 +125,7 @@ bitjs.io = bitjs.io || {};
return 0; return 0;
} }
var movePointers = movePointers || false; movePointers = movePointers || false;
var bytePtr = this.bytePtr; var bytePtr = this.bytePtr;
var bitPtr = this.bitPtr; var bitPtr = this.bitPtr;
var result = 0; var result = 0;
...@@ -197,7 +197,7 @@ bitjs.io = bitjs.io || {}; ...@@ -197,7 +197,7 @@ bitjs.io = bitjs.io || {};
* @return {Uint8Array} The subarray. * @return {Uint8Array} The subarray.
*/ */
bitjs.io.BitStream.prototype.peekBytes = function(n, movePointers) { bitjs.io.BitStream.prototype.peekBytes = function(n, movePointers) {
if (n <= 0 || typeof n != typeof 1) { if (n <= 0 || typeof n !== typeof 1) {
return 0; return 0;
} }
...@@ -322,7 +322,7 @@ bitjs.io = bitjs.io || {}; ...@@ -322,7 +322,7 @@ bitjs.io = bitjs.io || {};
* @return {Uint8Array} The subarray. * @return {Uint8Array} The subarray.
*/ */
bitjs.io.ByteStream.prototype.peekBytes = function(n, movePointers) { bitjs.io.ByteStream.prototype.peekBytes = function(n, movePointers) {
if (n <= 0 || typeof n != typeof 1) { if (n <= 0 || typeof n !== typeof 1) {
return null; return null;
} }
...@@ -352,7 +352,7 @@ bitjs.io = bitjs.io || {}; ...@@ -352,7 +352,7 @@ bitjs.io = bitjs.io || {};
* @return {string} The next n bytes as a string. * @return {string} The next n bytes as a string.
*/ */
bitjs.io.ByteStream.prototype.peekString = function(n) { bitjs.io.ByteStream.prototype.peekString = function(n) {
if (n <= 0 || typeof n != typeof 1) { if (n <= 0 || typeof n !== typeof 1) {
return ""; return "";
} }
......
...@@ -15,7 +15,10 @@ ...@@ -15,7 +15,10 @@
* Typed Arrays: http://www.khronos.org/registry/typedarray/specs/latest/#6 * Typed Arrays: http://www.khronos.org/registry/typedarray/specs/latest/#6
*/ */
/* global screenfull, bitjs */ /* global screenfull, bitjs, Uint8Array, opera */
/* exported init, event */
if (window.opera) { if (window.opera) {
window.console.log = function(str) { window.console.log = function(str) {
opera.postError(str); opera.postError(str);
...@@ -101,12 +104,12 @@ kthoom.setSettings = function() { ...@@ -101,12 +104,12 @@ kthoom.setSettings = function() {
var createURLFromArray = function(array, mimeType) { var createURLFromArray = function(array, mimeType) {
var offset = array.byteOffset; var offset = array.byteOffset;
var len = array.byteLength; var len = array.byteLength;
var url; // var url;
var blob; var blob;
if (mimeType === 'image/xml+svg') { if (mimeType === "image/xml+svg") {
const xmlStr = new TextDecoder('utf-8').decode(array); var xmlStr = new TextDecoder("utf-8").decode(array);
return 'data:image/svg+xml;UTF-8,' + encodeURIComponent(xmlStr); return "data:image/svg+xml;UTF-8," + encodeURIComponent(xmlStr);
} }
// TODO: Move all this browser support testing to a common place // TODO: Move all this browser support testing to a common place
...@@ -140,7 +143,7 @@ kthoom.ImageFile = function(file) { ...@@ -140,7 +143,7 @@ kthoom.ImageFile = function(file) {
var fileExtension = file.filename.split(".").pop().toLowerCase(); var fileExtension = file.filename.split(".").pop().toLowerCase();
this.mimeType = fileExtension === "png" ? "image/png" : this.mimeType = fileExtension === "png" ? "image/png" :
(fileExtension === "jpg" || fileExtension === "jpeg") ? "image/jpeg" : (fileExtension === "jpg" || fileExtension === "jpeg") ? "image/jpeg" :
fileExtension === "gif" ? "image/gif" : fileExtension == 'svg' ? 'image/xml+svg' : undefined; fileExtension === "gif" ? "image/gif" : fileExtension === "svg" ? "image/xml+svg" : undefined;
if ( this.mimeType !== undefined) { if ( this.mimeType !== undefined) {
this.dataURI = createURLFromArray(file.fileData, this.mimeType); this.dataURI = createURLFromArray(file.fileData, this.mimeType);
this.data = file; this.data = file;
...@@ -154,17 +157,18 @@ function initProgressClick() { ...@@ -154,17 +157,18 @@ function initProgressClick() {
currentImage = page; currentImage = page;
updatePage(); updatePage();
}); });
}; }
function loadFromArrayBuffer(ab) { function loadFromArrayBuffer(ab) {
var start = (new Date).getTime(); var start = (new Date).getTime();
var h = new Uint8Array(ab, 0, 10); var h = new Uint8Array(ab, 0, 10);
var pathToBitJS = "../../static/js/archive/"; var pathToBitJS = "../../static/js/archive/";
var lastCompletion = 0;
if (h[0] === 0x52 && h[1] === 0x61 && h[2] === 0x72 && h[3] === 0x21) { //Rar! if (h[0] === 0x52 && h[1] === 0x61 && h[2] === 0x72 && h[3] === 0x21) { //Rar!
unarchiver = new bitjs.archive.Unrarrer(ab, pathToBitJS); unarchiver = new bitjs.archive.Unrarrer(ab, pathToBitJS);
} else if (h[0] === 80 && h[1] === 75) { //PK (Zip) } else if (h[0] === 80 && h[1] === 75) { //PK (Zip)
unarchiver = new bitjs.archive.Unzipper(ab, pathToBitJS); unarchiver = new bitjs.archive.Unzipper(ab, pathToBitJS);
} else if (h[0] == 255 && h[1] == 216) { // JPEG } else if (h[0] === 255 && h[1] === 216) { // JPEG
// ToDo: check // ToDo: check
updateProgress(100); updateProgress(100);
lastCompletion = 100; lastCompletion = 100;
...@@ -180,12 +184,12 @@ function loadFromArrayBuffer(ab) { ...@@ -180,12 +184,12 @@ function loadFromArrayBuffer(ab) {
if (totalImages === 0) { if (totalImages === 0) {
totalImages = e.totalFilesInArchive; totalImages = e.totalFilesInArchive;
} }
updateProgress(percentage *100); updateProgress(percentage * 100);
lastCompletion = percentage * 100; lastCompletion = percentage * 100;
}); });
unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.INFO, unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.INFO,
function(e) { function(e) {
// console.log(e.msg); 77 Enable debug output here // console.log(e.msg); // Enable debug output here
}); });
unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.EXTRACT, unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.EXTRACT,
function(e) { function(e) {
...@@ -211,8 +215,7 @@ function loadFromArrayBuffer(ab) { ...@@ -211,8 +215,7 @@ function loadFromArrayBuffer(ab) {
if (imageFiles.length === currentImage + 1) { if (imageFiles.length === currentImage + 1) {
updatePage(lastCompletion); updatePage(lastCompletion);
} }
} } else {
else {
totalImages--; totalImages--;
} }
} }
...@@ -231,22 +234,22 @@ function loadFromArrayBuffer(ab) { ...@@ -231,22 +234,22 @@ function loadFromArrayBuffer(ab) {
function scrollTocToActive() { function scrollTocToActive() {
// Scroll to the thumbnail in the TOC on page change // Scroll to the thumbnail in the TOC on page change
$('#tocView').stop().animate({ $("#tocView").stop().animate({
scrollTop: $('#tocView a.active').position().top scrollTop: $("#tocView a.active").position().top
}, 200); }, 200);
} }
function updatePage() { function updatePage() {
$('.page').text((currentImage + 1 ) + "/" + totalImages); $(".page").text((currentImage + 1 ) + "/" + totalImages);
// Mark the current page in the TOC // Mark the current page in the TOC
$('#tocView a[data-page]') $("#tocView a[data-page]")
// Remove the currently active thumbnail // Remove the currently active thumbnail
.removeClass('active') .removeClass("active")
// Find the new one // Find the new one
.filter('[data-page='+ (currentImage + 1) +']') .filter("[data-page=" + (currentImage + 1) + "]")
// Set it to active // Set it to active
.addClass('active'); .addClass("active");
scrollTocToActive(); scrollTocToActive();
updateProgress(); updateProgress();
...@@ -270,8 +273,8 @@ function updateProgress(loadPercentage) { ...@@ -270,8 +273,8 @@ function updateProgress(loadPercentage) {
if (loadPercentage === 100) { if (loadPercentage === 100) {
$("#progress") $("#progress")
.removeClass('loading') .removeClass("loading")
.find(".load").text(''); .find(".load").text("");
} }
} }
...@@ -326,7 +329,7 @@ function setImage(url) { ...@@ -326,7 +329,7 @@ function setImage(url) {
xhr.onload = function() { xhr.onload = function() {
$("#mainText").css("display", ""); $("#mainText").css("display", "");
$("#mainText").innerHTML("<iframe style=\"width:100%;height:700px;border:0\" src=\"data:text/html," + escape(xhr.responseText) + "\"></iframe>"); $("#mainText").innerHTML("<iframe style=\"width:100%;height:700px;border:0\" src=\"data:text/html," + escape(xhr.responseText) + "\"></iframe>");
} };
xhr.send(null); xhr.send(null);
} else if (!/(jpg|jpeg|png|gif)$/.test(imageFiles[currentImage].filename) && imageFiles[currentImage].data.uncompressedSize < 10 * 1024) { } else if (!/(jpg|jpeg|png|gif)$/.test(imageFiles[currentImage].filename) && imageFiles[currentImage].data.uncompressedSize < 10 * 1024) {
xhr.open("GET", url, true); xhr.open("GET", url, true);
...@@ -378,17 +381,17 @@ function setImage(url) { ...@@ -378,17 +381,17 @@ function setImage(url) {
function showLeftPage() { function showLeftPage() {
if (settings.direction === 0) { if (settings.direction === 0) {
showPrevPage() showPrevPage();
} else { } else {
showNextPage() showNextPage();
} }
} }
function showRightPage() { function showRightPage() {
if (settings.direction === 0) { if (settings.direction === 0) {
showNextPage() showNextPage();
} else { } else {
showPrevPage() showPrevPage();
} }
} }
...@@ -504,7 +507,7 @@ function keyHandler(evt) { ...@@ -504,7 +507,7 @@ function keyHandler(evt) {
updateScale(false); updateScale(false);
break; break;
case kthoom.Key.SPACE: case kthoom.Key.SPACE:
var container = $('#mainContent'); var container = $("#mainContent");
var atTop = container.scrollTop() === 0; var atTop = container.scrollTop() === 0;
var atBottom = container.scrollTop() >= container[0].scrollHeight - container.height(); var atBottom = container.scrollTop() >= container[0].scrollHeight - container.height();
...@@ -577,9 +580,9 @@ function init(filename) { ...@@ -577,9 +580,9 @@ function init(filename) {
$(this).toggleClass("icon-menu icon-right"); $(this).toggleClass("icon-menu icon-right");
// We need this in a timeout because if we call it during the CSS transition, IE11 shakes the page ¯\_(ツ)_/¯ // We need this in a timeout because if we call it during the CSS transition, IE11 shakes the page ¯\_(ツ)_/¯
setTimeout(function(){ setTimeout(function() {
// Focus on the TOC or the main content area, depending on which is open // Focus on the TOC or the main content area, depending on which is open
$('#main:not(.closed) #mainContent, #sidebar.open #tocView').focus(); $("#main:not(.closed) #mainContent, #sidebar.open #tocView").focus();
scrollTocToActive(); scrollTocToActive();
}, 500); }, 500);
}); });
...@@ -630,7 +633,7 @@ function init(filename) { ...@@ -630,7 +633,7 @@ function init(filename) {
} }
// Focus the scrollable area so that keyboard scrolling work as expected // Focus the scrollable area so that keyboard scrolling work as expected
$('#mainContent').focus(); $("#mainContent").focus();
$("#mainImage").click(function(evt) { $("#mainImage").click(function(evt) {
// Firefox does not support offsetX/Y so we have to manually calculate // Firefox does not support offsetX/Y so we have to manually calculate
......
...@@ -15,18 +15,20 @@ ...@@ -15,18 +15,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/* exported TableActions */
$(function() { $(function() {
$("#domain_submit").click(function(event) { $("#domain_submit").click(function(event) {
event.preventDefault(); event.preventDefault();
$("#domain_add").ajaxForm(); $("#domain_add").ajaxForm();
$(this).closest("form").submit(); $(this).closest("form").submit();
$.ajax({ $.ajax ({
method:"get", method:"get",
url: window.location.pathname + "/../../ajax/domainlist", url: window.location.pathname + "/../../ajax/domainlist",
async: true, async: true,
timeout: 900, timeout: 900,
success:function(data){ success:function(data) {
$("#domain-table").bootstrapTable("load", data); $("#domain-table").bootstrapTable("load", data);
} }
}); });
......
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
this.$modalBar = this.$modal.find(".progress-bar"); this.$modalBar = this.$modal.find(".progress-bar");
// Translate texts // Translate texts
this.$modalTitle.text(this.options.modalTitle) this.$modalTitle.text(this.options.modalTitle);
this.$modalFooter.children("button").text(this.options.modalFooter); this.$modalFooter.children("button").text(this.options.modalFooter);
this.$modal.on("hidden.bs.modal", $.proxy(this.reset, this)); this.$modal.on("hidden.bs.modal", $.proxy(this.reset, this));
...@@ -113,8 +113,7 @@ ...@@ -113,8 +113,7 @@
if (contentType.indexOf("application/json") !== -1) { if (contentType.indexOf("application/json") !== -1) {
var response = $.parseJSON(xhr.responseText); var response = $.parseJSON(xhr.responseText);
url = response.location; url = response.location;
} } else {
else{
url = this.options.redirect_url; url = this.options.redirect_url;
} }
window.location.href = url; window.location.href = url;
...@@ -136,12 +135,10 @@ ...@@ -136,12 +135,10 @@
if (contentType.indexOf("text/plain") !== -1) { if (contentType.indexOf("text/plain") !== -1) {
responseText = "<pre>" + responseText + "</pre>"; responseText = "<pre>" + responseText + "</pre>";
document.write(responseText); document.write(responseText);
} } else {
else {
this.$modalBar.text(responseText); this.$modalBar.text(responseText);
} }
} } else {
else {
this.$modalBar.text(this.options.modalTitleFailed); this.$modalBar.text(this.options.modalTitleFailed);
} }
}, },
......
...@@ -41,7 +41,7 @@ See https://github.com/adobe-type-tools/cmap-resources ...@@ -41,7 +41,7 @@ See https://github.com/adobe-type-tools/cmap-resources
PDFViewerApplicationOptions.set('sidebarViewOnLoad', 0); PDFViewerApplicationOptions.set('sidebarViewOnLoad', 0);
PDFViewerApplicationOptions.set('imageResourcesPath', "{{ url_for('static', filename='css/images/') }}"); PDFViewerApplicationOptions.set('imageResourcesPath', "{{ url_for('static', filename='css/images/') }}");
PDFViewerApplicationOptions.set('workerSrc', "{{ url_for('static', filename='js/libs/pdf.worker.js') }}"); PDFViewerApplicationOptions.set('workerSrc', "{{ url_for('static', filename='js/libs/pdf.worker.js') }}");
PDFViewerApplication.open("{{ url_for('serve_book', book_id=pdffile, book_format='pdf') }}"); PDFViewerApplication.open("{{ url_for('web.serve_book', book_id=pdffile, book_format='pdf') }}");
}); });
</script> </script>
<link rel="resource" type="application/l10n" href="{{ url_for('static', filename='locale/locale.properties') }}"> <link rel="resource" type="application/l10n" href="{{ url_for('static', filename='locale/locale.properties') }}">
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<div class="discover"> <div class="discover">
<h2>{{title}}</h2> <h2>{{title}}</h2>
{% if g.user.role_download() %} {% if g.user.role_download() %}
<a id="shelf_down" href="{{ url_for('shelf.show_shelf', type=2, shelf_id=shelf.id) }}" class="btn btn-primary">{{ _('Download') }} </a> <a id="shelf_down" href="{{ url_for('shelf.show_shelf', shelf_type=2, shelf_id=shelf.id) }}" class="btn btn-primary">{{ _('Download') }} </a>
{% endif %} {% endif %}
{% if g.user.is_authenticated %} {% if g.user.is_authenticated %}
{% if (g.user.role_edit_shelfs() and shelf.is_public ) or not shelf.is_public %} {% if (g.user.role_edit_shelfs() and shelf.is_public ) or not shelf.is_public %}
......
...@@ -419,8 +419,8 @@ def get_matching_tags(): ...@@ -419,8 +419,8 @@ def get_matching_tags():
title_input = request.args.get('book_title') title_input = request.args.get('book_title')
include_tag_inputs = request.args.getlist('include_tag') include_tag_inputs = request.args.getlist('include_tag')
exclude_tag_inputs = request.args.getlist('exclude_tag') exclude_tag_inputs = request.args.getlist('exclude_tag')
q = q.filter(db.Books.authors.any(db.func.lower(db.Authors.name).ilike("%" + author_input + "%")), q = q.filter(db.Books.authors.any(func.lower(db.Authors.name).ilike("%" + author_input + "%")),
db.func.lower(db.Books.title).ilike("%" + title_input + "%")) func.lower(db.Books.title).ilike("%" + title_input + "%"))
if len(include_tag_inputs) > 0: if len(include_tag_inputs) > 0:
for tag in include_tag_inputs: for tag in include_tag_inputs:
q = q.filter(db.Books.tags.any(db.Tags.id == tag)) q = q.filter(db.Books.tags.any(db.Tags.id == tag))
...@@ -858,15 +858,15 @@ def advanced_search(): ...@@ -858,15 +858,15 @@ def advanced_search():
searchterm = " + ".join(filter(None, searchterm)) searchterm = " + ".join(filter(None, searchterm))
q = q.filter() q = q.filter()
if author_name: if author_name:
q = q.filter(db.Books.authors.any(db.func.lower(db.Authors.name).ilike("%" + author_name + "%"))) q = q.filter(db.Books.authors.any(func.lower(db.Authors.name).ilike("%" + author_name + "%")))
if book_title: if book_title:
q = q.filter(db.func.lower(db.Books.title).ilike("%" + book_title + "%")) q = q.filter(func.lower(db.Books.title).ilike("%" + book_title + "%"))
if pub_start: if pub_start:
q = q.filter(db.Books.pubdate >= pub_start) q = q.filter(db.Books.pubdate >= pub_start)
if pub_end: if pub_end:
q = q.filter(db.Books.pubdate <= pub_end) q = q.filter(db.Books.pubdate <= pub_end)
if publisher: if publisher:
q = q.filter(db.Books.publishers.any(db.func.lower(db.Publishers.name).ilike("%" + publisher + "%"))) q = q.filter(db.Books.publishers.any(func.lower(db.Publishers.name).ilike("%" + publisher + "%")))
for tag in include_tag_inputs: for tag in include_tag_inputs:
q = q.filter(db.Books.tags.any(db.Tags.id == tag)) q = q.filter(db.Books.tags.any(db.Tags.id == tag))
for tag in exclude_tag_inputs: for tag in exclude_tag_inputs:
...@@ -889,7 +889,7 @@ def advanced_search(): ...@@ -889,7 +889,7 @@ def advanced_search():
rating_low = int(rating_low) * 2 rating_low = int(rating_low) * 2
q = q.filter(db.Books.ratings.any(db.Ratings.rating >= rating_low)) q = q.filter(db.Books.ratings.any(db.Ratings.rating >= rating_low))
if description: if description:
q = q.filter(db.Books.comments.any(db.func.lower(db.Comments.text).ilike("%" + description + "%"))) q = q.filter(db.Books.comments.any(func.lower(db.Comments.text).ilike("%" + description + "%")))
# search custom culumns # search custom culumns
for c in cc: for c in cc:
...@@ -903,7 +903,7 @@ def advanced_search(): ...@@ -903,7 +903,7 @@ def advanced_search():
db.cc_classes[c.id].value == custom_query)) db.cc_classes[c.id].value == custom_query))
else: else:
q = q.filter(getattr(db.Books, 'custom_column_'+str(c.id)).any( q = q.filter(getattr(db.Books, 'custom_column_'+str(c.id)).any(
db.func.lower(db.cc_classes[c.id].value).ilike("%" + custom_query + "%"))) func.lower(db.cc_classes[c.id].value).ilike("%" + custom_query + "%")))
q = q.all() q = q.all()
ids = list() ids = list()
for element in q: for element in q:
......
...@@ -140,6 +140,7 @@ class emailbase(): ...@@ -140,6 +140,7 @@ class emailbase():
else: else:
raise smtplib.SMTPServerDisconnected('please run connect() first') raise smtplib.SMTPServerDisconnected('please run connect() first')
@classmethod
def _print_debug(self, *args): def _print_debug(self, *args):
log.debug(args) log.debug(args)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
universal = 1 universal = 1
[metadata] [metadata]
name = calibre-web name = calibreweb
version= 0.6.3 version= 0.6.3
url = https://github.com/janeczku/calibre-web url = https://github.com/janeczku/calibre-web
project_urls = project_urls =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment