Merge pull request #172 from vatsal22/Predownloads
Use presource=[resource] to "predownload" resource
This commit is contained in:
@@ -510,12 +510,12 @@ public class Application
|
||||
* discovered later, the caller can use the application base to download a new {@code
|
||||
* getdown.txt} file and try again.
|
||||
*
|
||||
* @return a configured UpdateInterface instance that will be used to configure the update UI.
|
||||
* @return a configured Config instance that contains information from the config file.
|
||||
*
|
||||
* @exception IOException thrown if there is an error reading the file or an error encountered
|
||||
* during its parsing.
|
||||
*/
|
||||
public UpdateInterface init (boolean checkPlatform)
|
||||
public Config init (boolean checkPlatform)
|
||||
throws IOException
|
||||
{
|
||||
Config config = null;
|
||||
@@ -672,6 +672,7 @@ public class Application
|
||||
parseResources(config, "resource", Resource.NORMAL, _resources);
|
||||
parseResources(config, "uresource", Resource.UNPACK, _resources);
|
||||
parseResources(config, "xresource", Resource.EXEC, _resources);
|
||||
parseResources(config, "presource", Resource.PREDOWNLOAD, _resources);
|
||||
|
||||
// parse our auxiliary resource groups
|
||||
for (String auxgroup : config.getList("auxgroups")) {
|
||||
@@ -720,6 +721,15 @@ public class Application
|
||||
_maxConcDownloads = Math.max(1, config.getInt("max_concurrent_downloads",
|
||||
SysProps.threadPoolSize()));
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets various properties using an UpdateInterface based on {@code config}
|
||||
* @param config Information to base the UpdateInterface off
|
||||
* @return a configured UpdateInterface instance that will be used to configure the update UI
|
||||
*/
|
||||
public UpdateInterface initUpdateInterface(Config config) {
|
||||
// parse and return our application config
|
||||
UpdateInterface ui = new UpdateInterface(config);
|
||||
_name = ui.name;
|
||||
@@ -1169,7 +1179,7 @@ public class Application
|
||||
clearValidationMarkers();
|
||||
// if the new copy validates, reinitialize ourselves; otherwise report baffling hoseage
|
||||
if (_digest.validateResource(crsrc, null)) {
|
||||
init(true);
|
||||
initUpdateInterface(init(true));
|
||||
} else {
|
||||
log.warning(CONFIG_FILE + " failed to validate even after redownloading. " +
|
||||
"Blindly forging onward.");
|
||||
|
||||
@@ -35,12 +35,15 @@ public class Resource implements Comparable<Resource>
|
||||
* unpacked resource will first be cleared of files before unpacking. */
|
||||
CLEAN,
|
||||
/** Indicates that the resource should be marked executable. */
|
||||
EXEC
|
||||
EXEC,
|
||||
/** Indicates that the resource should be downloaded before a UI is displayed. */
|
||||
PREDOWNLOAD
|
||||
};
|
||||
|
||||
public static final EnumSet<Attr> NORMAL = EnumSet.noneOf(Attr.class);
|
||||
public static final EnumSet<Attr> UNPACK = EnumSet.of(Attr.UNPACK);
|
||||
public static final EnumSet<Attr> EXEC = EnumSet.of(Attr.EXEC);
|
||||
public static final EnumSet<Attr> PREDOWNLOAD = EnumSet.of(Attr.PREDOWNLOAD);
|
||||
|
||||
/**
|
||||
* Computes the MD5 hash of the supplied file.
|
||||
@@ -201,6 +204,14 @@ public class Resource implements Comparable<Resource>
|
||||
return _attrs.contains(Attr.UNPACK) && !SysProps.noUnpack();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this resource should be predownloaded.
|
||||
*/
|
||||
public boolean shouldPredownload ()
|
||||
{
|
||||
return _attrs.contains(Attr.PREDOWNLOAD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the MD5 hash of this resource's underlying file.
|
||||
* <em>Note:</em> This is both CPU and I/O intensive.
|
||||
@@ -256,15 +267,26 @@ public class Resource implements Comparable<Resource>
|
||||
|
||||
/**
|
||||
* Installs the {@code getLocalNew} version of this resource to {@code getLocal}.
|
||||
* @param validate Validate resource after installing?
|
||||
*/
|
||||
public void install () throws IOException {
|
||||
public void install (boolean validate) throws IOException {
|
||||
File source = getLocalNew(), dest = getLocal();
|
||||
log.info("- " + source);
|
||||
if (!FileUtil.renameTo(source, dest)) {
|
||||
throw new IOException("Failed to rename " + source + " to " + dest);
|
||||
}
|
||||
applyAttrs();
|
||||
markAsValid();
|
||||
|
||||
if (validate){
|
||||
markAsValid();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as calling {@link #install(boolean)} with {@code true}
|
||||
*/
|
||||
public void install () throws IOException {
|
||||
install(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -60,13 +60,13 @@ public class Differ
|
||||
}
|
||||
|
||||
Application oapp = new Application(new EnvConfig(ovdir));
|
||||
oapp.init(false);
|
||||
oapp.initUpdateInterface(oapp.init(false));
|
||||
ArrayList<Resource> orsrcs = new ArrayList<>();
|
||||
orsrcs.addAll(oapp.getCodeResources());
|
||||
orsrcs.addAll(oapp.getResources());
|
||||
|
||||
Application napp = new Application(new EnvConfig(nvdir));
|
||||
napp.init(false);
|
||||
napp.initUpdateInterface(napp.init(false));
|
||||
ArrayList<Resource> nrsrcs = new ArrayList<>();
|
||||
nrsrcs.addAll(napp.getCodeResources());
|
||||
nrsrcs.addAll(napp.getResources());
|
||||
|
||||
@@ -75,7 +75,7 @@ public class Digester
|
||||
|
||||
// create our application and instruct it to parse its business
|
||||
Application app = new Application(new EnvConfig(appdir));
|
||||
app.init(false);
|
||||
app.initUpdateInterface(app.init(false));
|
||||
|
||||
List<Resource> rsrcs = new ArrayList<>();
|
||||
rsrcs.add(app.getConfigResource());
|
||||
|
||||
Reference in New Issue
Block a user