mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-08-03 19:36:53 -04:00
parent
9b5445b686
commit
738000ff39
@ -1,86 +0,0 @@
|
|||||||
/*
|
|
||||||
* Hello Minecraft! Launcher
|
|
||||||
* Copyright (C) 2020 huangyuhui <huanghongxun2008@126.com> and contributors
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package org.jackhuang.hmcl.countly;
|
|
||||||
|
|
||||||
import org.jackhuang.hmcl.util.io.HttpRequest;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import static org.jackhuang.hmcl.util.Pair.pair;
|
|
||||||
|
|
||||||
public class Countly {
|
|
||||||
|
|
||||||
private String deviceId;
|
|
||||||
private String endpoint;
|
|
||||||
private String serverURL;
|
|
||||||
|
|
||||||
public void sendMetric(String metrics) throws IOException {
|
|
||||||
HttpRequest.GET(serverURL + endpoint,
|
|
||||||
pair("begin_session", "1"),
|
|
||||||
pair("session_id", "1"),
|
|
||||||
pair("metrics", metrics),
|
|
||||||
pair("device_id", deviceId),
|
|
||||||
pair("timestamp", Long.toString(System.currentTimeMillis())),
|
|
||||||
pair("tz", Integer.toString(getTimezoneOffset())),
|
|
||||||
pair("hour", Integer.toString(currentHour())),
|
|
||||||
pair("dow", Integer.toString(currentDayOfWeek())),
|
|
||||||
pair("app_key", APP_KEY),
|
|
||||||
pair("sdk_name", "java-native"),
|
|
||||||
pair("sdk_version", "20.11.1"))
|
|
||||||
.getString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int getTimezoneOffset() {
|
|
||||||
return ZonedDateTime.now().getOffset().getTotalSeconds() / 60;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getLocale() {
|
|
||||||
final Locale locale = Locale.getDefault();
|
|
||||||
return locale.getLanguage() + "_" + locale.getCountry();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int currentHour() {
|
|
||||||
return Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int currentDayOfWeek() {
|
|
||||||
int day = Calendar.getInstance().get(Calendar.DAY_OF_WEEK);
|
|
||||||
switch (day) {
|
|
||||||
case Calendar.SUNDAY:
|
|
||||||
return 0;
|
|
||||||
case Calendar.MONDAY:
|
|
||||||
return 1;
|
|
||||||
case Calendar.TUESDAY:
|
|
||||||
return 2;
|
|
||||||
case Calendar.WEDNESDAY:
|
|
||||||
return 3;
|
|
||||||
case Calendar.THURSDAY:
|
|
||||||
return 4;
|
|
||||||
case Calendar.FRIDAY:
|
|
||||||
return 5;
|
|
||||||
case Calendar.SATURDAY:
|
|
||||||
return 6;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String APP_KEY = "";
|
|
||||||
}
|
|
@ -5,14 +5,8 @@ import org.jackhuang.hmcl.util.StringUtils;
|
|||||||
import org.jackhuang.hmcl.util.platform.Architecture;
|
import org.jackhuang.hmcl.util.platform.Architecture;
|
||||||
import org.jackhuang.hmcl.util.platform.OperatingSystem;
|
import org.jackhuang.hmcl.util.platform.OperatingSystem;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static org.jackhuang.hmcl.util.Lang.mapOf;
|
|
||||||
import static org.jackhuang.hmcl.util.Pair.pair;
|
|
||||||
import static org.jackhuang.hmcl.util.logging.Logger.LOG;
|
|
||||||
|
|
||||||
public class CrashReport {
|
public class CrashReport {
|
||||||
|
|
||||||
@ -20,24 +14,16 @@ public class CrashReport {
|
|||||||
private final Throwable throwable;
|
private final Throwable throwable;
|
||||||
private final String stackTrace;
|
private final String stackTrace;
|
||||||
|
|
||||||
private boolean nonFatal;
|
|
||||||
|
|
||||||
public CrashReport(Thread thread, Throwable throwable) {
|
public CrashReport(Thread thread, Throwable throwable) {
|
||||||
this.thread = thread;
|
this.thread = thread;
|
||||||
this.throwable = throwable;
|
this.throwable = throwable;
|
||||||
stackTrace = StringUtils.getStackTrace(throwable);
|
stackTrace = StringUtils.getStackTrace(throwable);
|
||||||
nonFatal = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Throwable getThrowable() {
|
public Throwable getThrowable() {
|
||||||
return this.throwable;
|
return this.throwable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CrashReport setNonFatal() {
|
|
||||||
nonFatal = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean shouldBeReport() {
|
public boolean shouldBeReport() {
|
||||||
if (!stackTrace.contains("org.jackhuang"))
|
if (!stackTrace.contains("org.jackhuang"))
|
||||||
return false;
|
return false;
|
||||||
@ -48,23 +34,6 @@ public class CrashReport {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> getMetrics(long runningTime) {
|
|
||||||
return mapOf(
|
|
||||||
pair("_run", runningTime),
|
|
||||||
pair("_app_version", Metadata.VERSION),
|
|
||||||
pair("_os", OperatingSystem.SYSTEM_NAME),
|
|
||||||
pair("_os_version", OperatingSystem.SYSTEM_VERSION),
|
|
||||||
pair("_disk_current", getDiskAvailable()),
|
|
||||||
pair("_disk_total", getDiskTotal()),
|
|
||||||
pair("_ram_current", getMemoryAvailable()),
|
|
||||||
pair("_ram_total", Runtime.getRuntime().maxMemory() / BYTES_IN_MB),
|
|
||||||
pair("_error", stackTrace),
|
|
||||||
pair("_logs", LOG.getLogs()),
|
|
||||||
pair("_name", throwable.getLocalizedMessage()),
|
|
||||||
pair("_nonfatal", nonFatal)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDisplayText() {
|
public String getDisplayText() {
|
||||||
return "---- Hello Minecraft! Crash Report ----\n" +
|
return "---- Hello Minecraft! Crash Report ----\n" +
|
||||||
" Version: " + Metadata.VERSION + "\n" +
|
" Version: " + Metadata.VERSION + "\n" +
|
||||||
@ -82,29 +51,4 @@ public class CrashReport {
|
|||||||
" JVM Total Memory: " + Runtime.getRuntime().totalMemory() + "\n" +
|
" JVM Total Memory: " + Runtime.getRuntime().totalMemory() + "\n" +
|
||||||
" JVM Free Memory: " + Runtime.getRuntime().freeMemory() + "\n";
|
" JVM Free Memory: " + Runtime.getRuntime().freeMemory() + "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Long BYTES_IN_MB = 1024L * 1024;
|
|
||||||
|
|
||||||
private static long getMemoryAvailable() {
|
|
||||||
Long total = Runtime.getRuntime().totalMemory();
|
|
||||||
Long availMem = Runtime.getRuntime().freeMemory();
|
|
||||||
return (total - availMem) / BYTES_IN_MB;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static long getDiskAvailable() {
|
|
||||||
long total = 0, free = 0;
|
|
||||||
for (File f : File.listRoots()) {
|
|
||||||
total += f.getTotalSpace();
|
|
||||||
free += f.getUsableSpace();
|
|
||||||
}
|
|
||||||
return (total - free) / BYTES_IN_MB;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static long getDiskTotal() {
|
|
||||||
long total = 0;
|
|
||||||
for (File f : File.listRoots()) {
|
|
||||||
total += f.getTotalSpace();
|
|
||||||
}
|
|
||||||
return total / BYTES_IN_MB;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* Hello Minecraft! Launcher
|
|
||||||
* Copyright (C) 2020 huangyuhui <huanghongxun2008@126.com> and contributors
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package org.jackhuang.hmcl.game;
|
|
||||||
|
|
||||||
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
|
||||||
|
|
||||||
public enum LoadingState {
|
|
||||||
DEPENDENCIES("launch.state.dependencies"),
|
|
||||||
MODS("launch.state.modpack"),
|
|
||||||
LOGGING_IN("launch.state.logging_in"),
|
|
||||||
LAUNCHING("launch.state.waiting_launching"),
|
|
||||||
DONE("launch.state.done");
|
|
||||||
|
|
||||||
private final String key;
|
|
||||||
|
|
||||||
LoadingState(String key) {
|
|
||||||
this.key = key;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLocalizedMessage() {
|
|
||||||
return i18n(key);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user