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

View File

@ -78,6 +78,8 @@ public final class YggdrasilAuthenticator extends IAuthenticator {
username = JOptionPane.showInputDialog(C.i18n("login.no_charactor")); username = JOptionPane.showInputDialog(C.i18n("login.no_charactor"));
else else
username = selectedProfile.name; username = selectedProfile.name;
if (username == null)
throw new AuthenticationException("No player");
result.setUserName(username); result.setUserName(username);
result.setUserId(selectedProfile == null ? OfflineAuthenticator.getUUIDFromUserName(username) : UUIDTypeAdapter.fromUUID(selectedProfile.id)); 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.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.List; import java.util.List;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.logging.HMCLog;
@ -93,13 +92,15 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
MinecraftVersion mv; MinecraftVersion mv;
try { try {
mv = C.GSON.fromJson(FileUtils.readFileToStringQuietly(mvt), MinecraftVersion.class); mv = C.GSON.fromJson(FileUtils.readFileToStringQuietly(mvt), MinecraftVersion.class);
if (mv == null)
throw new JsonSyntaxException("incorrect version");
} catch (JsonSyntaxException ex) { } catch (JsonSyntaxException ex) {
HMCLog.err("Failed to parse minecraft version json.", ex); HMCLog.err("Failed to parse minecraft version json.", ex);
onFailed(k); onFailed(k);
return; return;
} }
String jarURL = vurl + id + ".jar", hash = null; 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"); GameDownloadInfo gdi = mv.downloads.get("client");
if (gdi != null) { if (gdi != null) {
if (gdi.url != null) if (gdi.url != null)

View File

@ -77,6 +77,8 @@ public class MinecraftModService extends IMinecraftModService {
try { try {
if (!ModInfo.isFileMod(f)) if (!ModInfo.isFileMod(f))
return false; return false;
if (!modCache.containsKey(id))
recacheMods(id);
File modsFolder = service.version().getRunDirectory(id, "mods"); File modsFolder = service.version().getRunDirectory(id, "mods");
if (!modsFolder.exists() && !modsFolder.mkdirs()) if (!modsFolder.exists() && !modsFolder.mkdirs())
HMCLog.warn("Failed to make directories: " + modsFolder); 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); mcVersion = C.GSON.fromJson(FileUtils.readFileToString(jsonFile), MinecraftVersion.class);
if (mcVersion == null) if (mcVersion == null)
throw new GameException("Wrong json format, got 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); 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) { if (MessageBox.Show(C.i18n("launcher.versions_json_not_formatted", id), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) {
service.download().downloadMinecraftVersionJson(id); service.download().downloadMinecraftVersionJson(id);
@ -190,8 +190,9 @@ public class MinecraftVersionManager extends IMinecraftProvider {
@Override @Override
public File getRunDirectory(String id) { public File getRunDirectory(String id) {
if ("version".equals(getVersionById(id).runDir)) if (getVersionById(id) != null)
return versionRoot(id); if ("version".equals(getVersionById(id).runDir))
return versionRoot(id);
return baseDirectory(); return baseDirectory();
} }

View File

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

View File

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