Skip to content

Commit

Permalink
Added don't update tag
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexMl committed Mar 20, 2016
1 parent 69b372b commit 507a385
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions src/org/util/Updater/Updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* @version 2.3
*/
public class Updater {

/* Constants */
// Remote file's title
private static final String TITLE_VALUE = "name";
Expand All @@ -61,7 +61,7 @@ public class Updater {
// If the local version number contains one of these and the version equals the remote version, force update.
private static final String[] UPDATE_TAG_LOCAL = {"_DEV", "_PRE"};
// If the remote version number contains one of these, don't update.
private static final String[] NO_UPDATE_TAG_REMOTE = {"_DEV"};
private static final String[] NO_UPDATE_TAG_REMOTE = {"_DEV, _1.9"};
// Used for downloading files
private static final int BYTE_SIZE = 1024;
// Config key for api key
Expand Down Expand Up @@ -101,7 +101,7 @@ public class Updater {
private Thread thread;
// Used for determining the outcome of the update process
private Updater.UpdateResult result = Updater.UpdateResult.SUCCESS;

/**
* Gives the developer the result of the update process. Can be obtained by called {@link #getResult()}
*/
Expand Down Expand Up @@ -143,7 +143,7 @@ public enum UpdateResult {
*/
UPDATE_AVAILABLE
}

/**
* Allows the developer to specify the type of update that will be run.
*/
Expand All @@ -161,7 +161,7 @@ public enum UpdateType {
*/
NO_DOWNLOAD
}

/**
* Represents the various release types of a file on BukkitDev.
*/
Expand All @@ -179,7 +179,7 @@ public enum ReleaseType {
*/
RELEASE
}

/**
* Initialize the updater.
*
Expand All @@ -197,7 +197,7 @@ public enum ReleaseType {
public Updater(Plugin plugin, int id, File file, UpdateType type, boolean announce) {
this(plugin, id, file, type, null, announce);
}

/**
* Initialize the updater with the provided callback.
*
Expand All @@ -215,7 +215,7 @@ public Updater(Plugin plugin, int id, File file, UpdateType type, boolean announ
public Updater(Plugin plugin, int id, File file, UpdateType type, UpdateCallback callback) {
this(plugin, id, file, type, callback, false);
}

/**
* Initialize the updater with the provided callback.
*
Expand Down Expand Up @@ -290,7 +290,7 @@ public Updater(Plugin plugin, int id, File file, UpdateType type, UpdateCallback
runUpdater();
}
}

/**
* Get the result of the update process.
*
Expand All @@ -301,7 +301,7 @@ public Updater.UpdateResult getResult() {
this.waitForThread();
return this.result;
}

/**
* Get the latest version's release type.
*
Expand All @@ -319,7 +319,7 @@ public ReleaseType getLatestType() {
}
return null;
}

/**
* Get the latest version's game version (such as "CB 1.2.5-R1.0").
*
Expand All @@ -329,7 +329,7 @@ public String getLatestGameVersion() {
this.waitForThread();
return this.versionGameVersion;
}

/**
* Get the latest version's name (such as "Project v1.0").
*
Expand All @@ -339,7 +339,7 @@ public String getLatestName() {
this.waitForThread();
return this.versionName;
}

/**
* Get the latest version's direct file link.
*
Expand All @@ -349,7 +349,7 @@ public String getLatestFileLink() {
this.waitForThread();
return this.versionLink;
}

/**
* As the result of Updater output depends on the thread's completion, it is necessary to wait for the thread to finish before allowing anyone to check the result.
*/
Expand All @@ -362,7 +362,7 @@ private void waitForThread() {
}
}
}

/**
* Save an update from dev.bukkit.org into the server's update folder.
*
Expand All @@ -386,7 +386,7 @@ private void saveFile(String file) {
this.plugin.getLogger().info("Finished updating.");
}
}

/**
* Download a file and save it to the specified folder.
*/
Expand Down Expand Up @@ -432,7 +432,7 @@ private void downloadFile() {
}
}
}

/**
* Remove possibly leftover files from the update folder.
*/
Expand All @@ -445,7 +445,7 @@ private void deleteOldFiles() {
}
}
}

/**
* Part of Zip-File-Extractor, modified by Gravity for use with Updater.
*
Expand Down Expand Up @@ -491,7 +491,7 @@ private void unzip(String file) {
this.fileIOOrError(fSourceZip, fSourceZip.delete(), false);
}
}

/**
* Find any new files extracted from an update into the plugin's data directory.
*
Expand Down Expand Up @@ -533,7 +533,7 @@ private void moveNewZipFiles(String zipPath) {
File zip = new File(zipPath);
this.fileIOOrError(zip, zip.delete(), false);
}

/**
* Check if the name of a jar is one of the plugins currently installed, used for extracting the correct files out of a zip.
*
Expand All @@ -550,7 +550,7 @@ private boolean pluginExists(String name) {
}
return false;
}

/**
* Check to see if the program should continue by evaluating whether the plugin is already updated, or shouldn't be updated.
*
Expand Down Expand Up @@ -582,7 +582,7 @@ private boolean versionCheck() {
}
return true;
}

/**
* <b>If you wish to run mathematical versioning checks, edit this method.</b>
* <p>
Expand Down Expand Up @@ -610,10 +610,10 @@ public boolean shouldUpdate(String localVersion, String remoteVersion, boolean u
double local = parseVersion(localVersion);
double remote = parseVersion(remoteVersion);
ZvP.getPluginLogger().log(this.getClass(), Level.INFO, "LV=" + local + " : RV=" + remote + " Update? " + (updateTag ? remote >= local : remote > local), true, true);

return updateTag ? remote >= local : remote > local;
}

private double parseVersion(String version) {
// Possibilities: 2.3.7-5_LP
if (version.contains("_")) {
Expand All @@ -622,7 +622,7 @@ private double parseVersion(String version) {
return Double.parseDouble(version.replace(".", "").replace("-", "."));
}
}

/**
* Evaluate whether the version number is marked showing that it should not be updated by this program.
*
Expand All @@ -646,7 +646,7 @@ private boolean hasTag(String version, boolean local) {
}
return false;
}

/**
* Make a connection to the BukkitDev API and request the newest file's details.
*
Expand Down Expand Up @@ -689,7 +689,7 @@ private boolean read() {
return false;
}
}

/**
* Perform a file operation and log any errors if it fails.
*
Expand All @@ -705,7 +705,7 @@ private void fileIOOrError(File file, boolean result, boolean create) {
this.plugin.getLogger().severe("The updater could not " + (create ? "create" : "delete") + " file at: " + file.getAbsolutePath());
}
}

private File[] listFilesOrError(File folder) {
File[] contents = folder.listFiles();
if (contents == null) {
Expand All @@ -715,12 +715,12 @@ private File[] listFilesOrError(File folder) {
return contents;
}
}

/**
* Called on main thread when the Updater has finished working, regardless of result.
*/
public interface UpdateCallback {

/**
* Called when the updater has finished working.
*
Expand All @@ -729,15 +729,15 @@ public interface UpdateCallback {
*/
void onFinish(Updater updater);
}

private class UpdateRunnable implements Runnable {

@Override
public void run() {
runUpdater();
}
}

private void runUpdater() {
if (this.url != null && (this.read() && this.versionCheck())) {
// Obtain the results of the project's file feed
Expand All @@ -754,15 +754,15 @@ private void runUpdater() {
}
if (this.callback != null) {
new BukkitRunnable() {

@Override
public void run() {
runCallback();
}
}.runTask(this.plugin);
}
}

private void runCallback() {
this.callback.onFinish(this);
}
Expand Down

0 comments on commit 507a385

Please sign in to comment.