Even after restoring to the previous version, this function had a slight
bug that would cause a crash on valid .zip files (e.g.
mupdf-thirdparty.zip in kindlepdfviewer make tree). The reason is
because the value of s may be not nil, but the string.match() would
return nil and so string.lower() would get nil as an argument and crash.
So, we have to guard against this carefully.
The FileChooser:choose() method returns only a single argument,
so we can get rid of the second return value in reader.lua and
simplify the code a bit.
1. Usually the error messages from the :open() method are too
long (except for crereader files) and won't be shown.
So, I extract the first 30 bytes from the error message (if there is
one) and show that. But if there is no error message then just display
the generic "Error opening document ". Otherwise, as was currently the
case, the error message is present but is too long and so we get
absolutely nothing, not even a generic one. But in the Debug output we
can show the entire error message as there is no restriction on the
length.
2. Use showInfoMsgWithDelay() instead of InfoMessage:show() followed by
util.sleep().
3. Remove the dependency on keys.lua. This was needed when we were
detecting emulation by comparing the physical value of some KEY_ but now
we use util.isEmulated() so there is no need for it anymore.
1. Make "-d" switch passed to reader.lua enable all debugging
2. Enable debugging for now (development stage) to preserve the current
behaviour. But for the production release I advise to: a) disable it by
not passing "-d" and b) redirect standard output (not just standard
error) of reader.lua to crash.log in kpdf.sh
3. Comment out debug printf()s in pdf.c
Instead of calling lfs.mkdir() to create "./history" and "./screenshots"
at runtime it is easier to create them at package build time.
I hesitated whether to add "./clipboard" to this list but decided
against it as we can perhaps change current directory and then
all the code manipulating clipboard would break, so I left it as is.
Print "Invalid" in the "Unpacked" field for corrupt zip files.
More generally, the FormatSize() function returns the string "Invalid"
if whatever passed to it is not a number.
When I rewrote the function CREReader:ZipContentExt() I lost
the code path leading to "Error unzipping file." message.
This was now restored, plus two required changes:
1. There is no need to surround io.popen() with assert() as it
never fails, not even if the command is non-existent. Besides,
even if it did, crashing the whole viewer just because for
some reason we can't unzip the file is not a good idea.
2. The "while tmp" after tmp=assert() assignment is meaningless.
Even after removing assert() it is still meaningless because io.popen()
can never return nil, oddly enough.
1. Remove assert() around io.popen() as this function never fails, even
when opening a pipe to a non-existent program.
2. Remove the second assert() as well, because it is not wise to fail the whole
application just because we don't know or cannot ascertain the battery
level.
3. Guard against the failure of gasgauge-info (e.g. on emulator where it
does not exist, so, effectively "fails") by checking what we read from
the pipe and return "?" if need be.
1. Use the proper <string.h> header.
2. Typo fixes and whitespace changes.
3. Comment out debug printf() about cache size.
4. Remove obsolete comment(s).
1. Don't build xmltools in the emulator
2. Remove duplicate --disable-desktopfiles
3. Don't build LFS support. The largest DjVu file I have ever published
was a highres facsimile edition of the London Walton Polyglot (1657)
which was a "mere" 1GB in size and I don't think anyone produced
anything bigger. Besides, storing DjVu files >2GB in size (even if
they existed, which I doubt) on a Kindle with only 3GB total storage
space is _exceedingly_ unlikely.
Technically, the only serious problem in this function was the code:
local tmp = assert(io.popen('unzip -l \"'..fname..'\"', "r"))
while tmp do
s = tmp:read("*line")
if i > 3 then tmp:close(); break; end
i = i + 1
end
It is meaningless to evaluate the truth of the return value of assert()
and the above code gives the impression that it relies on the
(undocumented and unreliable) fact that after tmp:close() tmp will be
nil, even though in actual fact it does because it breaks out of the
loop.
However, having looked at the function I saw that the whole thing
can be rewritten in a much simpler way:
local tmp = assert(io.popen('unzip -l \"'..fname..'\" | head -4 | tail -1', "r"))
s = tmp:read("*line")
tmp:close()
1. When executed in the emulator the viewer will crash if you press
Right on any zip file in the filechooser. This is because the assertion
on "df /mnt/us | tail -1" will fail as "/mnt/us" is normally
non-existent.
2. The proper (faster, reliable, portable) way of obtaining the number
of total and free bytes on a filesystem is by using the statvfs(2)
system call via util.df Lua interface, see util.c.
3. Removed the "used" field in the function's return as unused and
unneeded.