This commit is contained in:
huangyuhui
2017-02-19 16:30:27 +08:00
parent fa5ff14ff1
commit 445367532a
18 changed files with 86 additions and 151 deletions

View File

@@ -15,25 +15,16 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
buildscript {
repositories {
mavenCentral();
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.1.0'
}
}
}
import java.util.jar.JarFile
import java.util.jar.Pack200
import java.util.zip.GZIPOutputStream
import java.security.MessageDigest
plugins {
//id "edu.sc.seis.macAppBundle" version "2.1.6"
//id "me.tatarka.retrolambda" version "3.5.0"
id "me.tatarka.retrolambda" version "3.5.0"
id 'edu.sc.seis.launch4j' version '2.3.0'
}
apply plugin: 'me.tatarka.retrolambda'
import java.util.jar.JarOutputStream
import java.util.zip.ZipEntry
import java.util.zip.ZipFile
@@ -61,7 +52,7 @@ version = mavenVersion
String mavenArtifactId = name
task generateSources(type: Copy) {
task generateSources(type: Sync) {
from 'src/main/java'
into "$buildDir/generated-src"
filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [
@@ -71,19 +62,6 @@ task generateSources(type: Copy) {
compileJava.setSource "$buildDir/generated-src"
compileJava.dependsOn generateSources
/*task macAppCompressed(type: Zip, dependsOn: createApp) {
archiveName "HMCL-$mavenVersion-MacOSApp.zip"
include '**'
destinationDir file("$buildDir/libs/")
from "$buildDir/macApp"
}
macAppBundle {
mainClassName = mainClass
icon = "src/main/icon.icns"
javaProperties.put("apple.laf.useScreenMenuBar", "true")
}*/
configurations {
coreCompile.extendsFrom compile
coreRuntime.extendsFrom runtime
@@ -124,7 +102,7 @@ launch4j {
icon = new File(project.buildDir, '../icon.ico').absolutePath
version = mavenVersion
downloadUrl = 'http://java.com/download'
copyright = "Copyright(c) 2013-2015 huangyuhui."
copyright = "Copyright(c) 2013-2017 huangyuhui."
jar = new File(project.buildDir, 'libs/' + mavenGroupId + '-' + mavenVersion + '.jar').absolutePath
outfile = mavenGroupId + '-' + mavenVersion + '.exe'
@@ -137,6 +115,51 @@ processResources {
}
}
task makeExecutable(dependsOn: jar) << {
ext {
jar.classifier = ''
makeExecutableinjar = jar.archivePath
jar.classifier = ''
makeExecutableoutjar = jar.archivePath
jar.classifier = ''
}
def loc = new File(project.buildDir, "libs/" + makeExecutableoutjar.getName().substring(0, makeExecutableoutjar.getName().length()-4)+".exe")
def fos = new FileOutputStream(loc)
def is = new FileInputStream(new File(project.buildDir, '../HMCLauncher.exe'))
int read
def bytes = new byte[8192]
while((read = is.read(bytes)) != -1)
fos.write(bytes, 0, read);
is.close()
is = new FileInputStream(makeExecutableinjar)
while((read = is.read(bytes)) != -1)
fos.write(bytes, 0, read);
is.close()
fos.close()
}
task makePackGZ(dependsOn: jar) << {
ext {
jar.classifier = ''
makeExecutableinjar = jar.archivePath
jar.classifier = ''
makeExecutableoutjar = jar.archivePath
jar.classifier = ''
}
def loc = new File(project.buildDir, "libs/" + makeExecutableoutjar.getName().substring(0, makeExecutableoutjar.getName().length()-4)+".pack.gz")
def os = new GZIPOutputStream(new FileOutputStream(loc))
Pack200.newPacker().pack new JarFile(makeExecutableinjar), os
os.close()
def messageDigest = MessageDigest.getInstance("SHA1")
loc.eachByte 1024 * 1024, { byte[] buf, int bytesRead ->
messageDigest.update(buf, 0, bytesRead);
}
def sha1Hex = new BigInteger(1, messageDigest.digest()).toString(16).padLeft(40, '0')
def fileEx = new File(project.buildDir, "libs/" + makeExecutableoutjar.getName().substring(0, makeExecutableoutjar.getName().length()-4)+".pack.gz.sha1")
if (!fileEx.exists()) fileEx.createNewFile()
fileEx.append sha1Hex
}
build.dependsOn makeExecutable
build.dependsOn makePackGZ
//build.dependsOn macAppCompressed
build.dependsOn makePackGZ

View File

@@ -141,7 +141,7 @@ public final class Main implements Runnable {
Thread.setDefaultUncaughtExceptionHandler(new CrashReporter(true));
try {
File file = new File("hmcl.log");
File file = new File("hmcl.log").getAbsoluteFile();
if (!file.exists() && !file.createNewFile())
LOGGER.log(Level.WARNING, "Failed to create log file {0}", file);
Configuration.DEFAULT.appenders.add(new ConsoleAppender("File", new DefaultLayout(), true, new FileOutputStream(file), true));

View File

@@ -44,7 +44,7 @@ public final class Settings {
public static final String DEFAULT_PROFILE = "Default";
public static final String HOME_PROFILE = "Home";
public static final File SETTINGS_FILE = new File("hmcl.json");
public static final File SETTINGS_FILE = new File("hmcl.json").getAbsoluteFile();
private static final Config SETTINGS;
public static final UpdateChecker UPDATE_CHECKER = new UpdateChecker(HMCLApi.HMCL_VERSION, "hmcl");

View File

@@ -988,7 +988,7 @@ public final class GameSettingsPanel extends RepaintPage implements DropTargetLi
}// </editor-fold>//GEN-END:initComponents
private void btnIncludeMinecraftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIncludeMinecraftActionPerformed
JSystemFileChooser fc = new JSystemFileChooser(new File("."));
JSystemFileChooser fc = new JSystemFileChooser(new File("").getAbsoluteFile());
fc.setFileSelectionMode(JSystemFileChooser.DIRECTORIES_ONLY);
if (fc.showOpenDialog(this) == JSystemFileChooser.APPROVE_OPTION) {
File newGameDir = fc.getSelectedFile();

View File

@@ -121,13 +121,13 @@ public class ModpackWizard extends WizardBranchController {
s.setDownloadType(Settings.getInstance().getDownloadType());
engine.putTextFile(C.GSON.toJson(s), "hmcl.json");
engine.putFile(modpack, "modpack.zip");
File bg = new File("bg");
File bg = new File("bg").getAbsoluteFile();
if (bg.isDirectory())
engine.putDirectory(bg);
bg = new File("background.png");
bg = new File("background.png").getAbsoluteFile();
if (bg.isFile())
engine.putFile(bg, "background.png");
bg = new File("background.jpg");
bg = new File("background.jpg").getAbsoluteFile();
if (bg.isFile())
engine.putFile(bg, "background.jpg");
for (URL u : Utils.getURL())

View File

@@ -67,7 +67,7 @@ public class HMCLMinecraftService extends IMinecraftService {
if (!checkingModpack) {
checkingModpack = true;
if (version().getVersionCount() == 0) {
File modpack = new File("modpack.zip");
File modpack = new File("modpack.zip").getAbsoluteFile();
if (modpack.exists())
SwingUtilities.invokeLater(() -> {
if (TaskWindow.factory().execute(ModpackManager.install(MainFrame.INSTANCE, modpack, this, null)))

View File

@@ -109,7 +109,7 @@ public class AppDataUpgrader extends IUpgrader {
if (map.containsKey("packsha1"))
hash = map.get("packsha1");
if (TaskWindow.factory().append(new AppDataUpgraderTask(map.get("pack"), version.version, hash)).execute()) {
new ProcessBuilder(new String[] { IOUtils.getJavaDir(), "-jar", AppDataUpgraderTask.getSelf(version.version).getAbsolutePath() }).directory(new File(".")).start();
new ProcessBuilder(new String[] { IOUtils.getJavaDir(), "-jar", AppDataUpgraderTask.getSelf(version.version).getAbsolutePath() }).directory(new File("").getAbsoluteFile()).start();
System.exit(0);
}
} catch (IOException ex) {

View File

@@ -50,7 +50,7 @@ public class NewFileUpgrader extends IUpgrader {
File newf = new File(FileUtils.getName(str));
if (TaskWindow.factory().append(new FileDownloadTask(str, newf)).execute()) {
try {
new ProcessBuilder(new String[] { newf.getCanonicalPath(), "--removeOldLauncher", IOUtils.getRealPath() }).directory(new File(".")).start();
new ProcessBuilder(new String[] { newf.getCanonicalPath(), "--removeOldLauncher", IOUtils.getRealPath() }).directory(new File("").getAbsoluteFile()).start();
} catch (IOException ex) {
HMCLog.err("Failed to start new app", ex);
}