Fixed lots of bugs

This commit is contained in:
huangyuhui 2016-02-13 18:02:25 +08:00
parent d0c8a95f57
commit 69eaa04ff6
7 changed files with 44 additions and 34 deletions

View File

@ -119,7 +119,6 @@ public final class Main implements Runnable {
public static void main(String[] args) throws IOException {
{
//PluginManager.getServerPlugin();
if (IUpgrader.NOW_UPGRADER.parseArguments(getVersionNumber(), args))
return;
@ -169,6 +168,8 @@ public final class Main implements Runnable {
}
});
}
if (true)
throw new IOException("???");
try {
PluginManager.plugin().showUI();

View File

@ -78,6 +78,8 @@ public final class YggdrasilAuthenticator extends IAuthenticator {
username = JOptionPane.showInputDialog(C.i18n("login.no_charactor"));
else
username = selectedProfile.name;
if (username == null)
throw new AuthenticationException("No player");
result.setUserName(username);
result.setUserId(selectedProfile == null ? OfflineAuthenticator.getUUIDFromUserName(username) : UUIDTypeAdapter.fromUUID(selectedProfile.id));
}

View File

@ -22,7 +22,6 @@ import com.google.gson.JsonSyntaxException;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.logging.HMCLog;
@ -93,13 +92,15 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
MinecraftVersion mv;
try {
mv = C.GSON.fromJson(FileUtils.readFileToStringQuietly(mvt), MinecraftVersion.class);
if (mv == null)
throw new JsonSyntaxException("incorrect version");
} catch (JsonSyntaxException ex) {
HMCLog.err("Failed to parse minecraft version json.", ex);
onFailed(k);
return;
}
String jarURL = vurl + id + ".jar", hash = null;
if (service.getDownloadType().getProvider().isAllowedToUseSelfURL() && mv.downloads != null) {
if (mv != null && mv.downloads != null && service.getDownloadType().getProvider().isAllowedToUseSelfURL()) {
GameDownloadInfo gdi = mv.downloads.get("client");
if (gdi != null) {
if (gdi.url != null)

View File

@ -77,6 +77,8 @@ public class MinecraftModService extends IMinecraftModService {
try {
if (!ModInfo.isFileMod(f))
return false;
if (!modCache.containsKey(id))
recacheMods(id);
File modsFolder = service.version().getRunDirectory(id, "mods");
if (!modsFolder.exists() && !modsFolder.mkdirs())
HMCLog.warn("Failed to make directories: " + modsFolder);

View File

@ -115,7 +115,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
mcVersion = C.GSON.fromJson(FileUtils.readFileToString(jsonFile), MinecraftVersion.class);
if (mcVersion == null)
throw new GameException("Wrong json format, got null.");
} catch (IOException | GameException e) {
} catch (Exception e) {
HMCLog.warn("Found wrong format json, try to fix it.", e);
if (MessageBox.Show(C.i18n("launcher.versions_json_not_formatted", id), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) {
service.download().downloadMinecraftVersionJson(id);
@ -190,8 +190,9 @@ public class MinecraftVersionManager extends IMinecraftProvider {
@Override
public File getRunDirectory(String id) {
if ("version".equals(getVersionById(id).runDir))
return versionRoot(id);
if (getVersionById(id) != null)
if ("version".equals(getVersionById(id).runDir))
return versionRoot(id);
return baseDirectory();
}

View File

@ -504,8 +504,10 @@ public class MainPagePanel extends AnimatedPanel {
final Consumer<String> versionChanged = this::versionChanged;
void versionChanged(String selectedVersion) {
isLoading = true;
((DefaultComboBoxModel) cboVersions.getModel()).setSelectedItem(selectedVersion);
cboVersions.setToolTipText(selectedVersion);
isLoading = false;
}
final Consumer<Profile> onSelectedProfilesChanged = t -> {

View File

@ -101,37 +101,38 @@ public class AppDataUpgrader extends IUpgrader {
@Override
public boolean call(Object sender, final VersionNumber number) {
((UpdateChecker) sender).requestDownloadLink().reg(map -> {
if (map != null && map.containsKey("pack"))
try {
String hash = null;
if (map.containsKey("packsha1"))
hash = map.get("packsha1");
if (TaskWindow.factory().append(new AppDataUpgraderTask(map.get("pack"), number.version, hash)).create()) {
new ProcessBuilder(new String[] { IOUtils.getJavaDir(), "-jar", AppDataUpgraderTask.getSelf(number.version).getAbsolutePath() }).directory(new File(".")).start();
System.exit(0);
}
} catch (IOException ex) {
HMCLog.err("Failed to create upgrader", ex);
}
if (MessageBox.Show(C.i18n("update.newest_version") + number.firstVer + "." + number.secondVer + "." + number.thirdVer + "\n"
+ C.i18n("update.should_open_link"),
MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) {
String url = C.URL_PUBLISH;
if (map != null)
if (map.containsKey(OS.os().checked_name))
url = map.get(OS.os().checked_name);
else if (map.containsKey(OS.UNKOWN.checked_name))
url = map.get(OS.UNKOWN.checked_name);
if (url == null)
url = C.URL_PUBLISH;
try {
java.awt.Desktop.getDesktop().browse(new URI(url));
} catch (URISyntaxException | IOException e) {
HMCLog.warn("Failed to browse uri: " + url, e);
Utils.setClipborad(url);
MessageBox.Show(C.i18n("update.no_browser"));
MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
if (map != null && map.containsKey("pack"))
try {
String hash = null;
if (map.containsKey("packsha1"))
hash = map.get("packsha1");
if (TaskWindow.factory().append(new AppDataUpgraderTask(map.get("pack"), number.version, hash)).create()) {
new ProcessBuilder(new String[] { IOUtils.getJavaDir(), "-jar", AppDataUpgraderTask.getSelf(number.version).getAbsolutePath() }).directory(new File(".")).start();
System.exit(0);
}
} catch (IOException ex) {
HMCLog.err("Failed to create upgrader", ex);
}
else {
String url = C.URL_PUBLISH;
if (map != null)
if (map.containsKey(OS.os().checked_name))
url = map.get(OS.os().checked_name);
else if (map.containsKey(OS.UNKOWN.checked_name))
url = map.get(OS.UNKOWN.checked_name);
if (url == null)
url = C.URL_PUBLISH;
try {
java.awt.Desktop.getDesktop().browse(new URI(url));
} catch (URISyntaxException | IOException e) {
HMCLog.warn("Failed to browse uri: " + url, e);
Utils.setClipborad(url);
MessageBox.Show(C.i18n("update.no_browser"));
}
}
}
}).execute();
return true;
}