fall back to using previously downloaded database.xml if necessary #99

Merged
merged 4 commits into from Aug 7, 2015

Conversation

Projects
None yet
3 participants
Collaborator

neogeographica commented Jul 31, 2015

If unable to download a new database.xml, or if we download something zero-length or otherwise unparseable, then try to use a previously downloaded database.xml.

The main changes here:

  • Fix a bug in DumpInputStream that corrupted the downloaded database.xml file. (Previously this didn't matter since no one used that file... it was written and then ignored.)
  • Change the download-and-parse process so that we don't nuke the existing database.xml file with the downloaded content until we are sure that the downloaded content is both fetch-able and parse-able.
  • If the downloaded content is bad for whatever reason, try using an existing database.xml.
  • If using an existing database.xml, pop up a little info message dialog to let the user know that they may not have the latest and greatest.

Note that because of the first problem above, any existing database.xml files in QuakeInjector installations are likely corrupted. For "offline mode" to work, you need to have used this new version of QuakeInjector at least once to successfully fetch database.xml. (Or get an uncorrupted copy of database.xml from a friend.)

neogeographica added some commits Jul 30, 2015

@neogeographica neogeographica tentative support for using cached database.xml when source is offline
Rearranged the code a bit so that the local database.xml file (if any) is not nuked when trying to download a new one.

Changes look promising, but not ready to merge yet for a few reasons:

- Since Quaddicted is offline, I can't easily test the "download success" case to make sure that it still works. There are ways around that which I can do if necessary (i.e. host a database.xml file on some other webserver).

- I don't have a complete current database.xml file to test as the local/cached version. I've been using a truncated database.xml that I manually repaired.

- Currently the code will just silently revert to using the cached copy if the download fails. It would be nice to pop a warning to tell the user that this is going on. Ideally someone else can help me with the best way to do that. :-)
c2fcb07
@neogeographica neogeographica indentation fixes cf12cd1
@neogeographica neogeographica info dialog if using cached database.xml 4290bda
@neogeographica neogeographica fix corrupted database.xml dump
Bug in DumpInputStream was writing out a bad file.
e672ef9
Collaborator

neogeographica commented Jul 31, 2015

Note that while this partially addresses issue #10, it does NOT disable installing.

If you try to install something and QI can't contact the repository, you'll get the "Couldn't open file! www.quaddicted.com" error dialog. So at least it kind of fails gracefully.

SpiritQuaddicted merged commit 0cfcaab into hrehfeld:master Aug 7, 2015

@hrehfeld hrehfeld commented on the diff Aug 8, 2015

src/de/haukerehfeld/quakeinjector/QuakeInjector.java
+ private BufferedInputStream cachedDatabaseStream() throws IOException {
+ if (cache != null && cache.exists() && cache.canRead()) {
+ try {
+ return new BufferedInputStream(new FileInputStream(cache));
+ }
+ catch (IOException e) {}
+ }
+ throw new IOException("cannot download package database or read local cache");
@hrehfeld

hrehfeld Aug 8, 2015

Owner

Not sure if error msg should have info about download (nitpicking)

neogeographica deleted the neogeographica:offline_database branch Aug 8, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment