export modpack

This commit is contained in:
Tungstend 2023-07-09 21:23:38 +08:00
parent 97ed7153da
commit 504d1ce2e8
9 changed files with 178 additions and 13 deletions

View File

@ -56,7 +56,7 @@ public class ModpackInstaller {
if (executor.getException() instanceof ModpackCompletionException) {
if (executor.getException().getCause() instanceof FileNotFoundException) {
FCLAlertDialog.Builder builder1 = new FCLAlertDialog.Builder(context);
builder1.setAlertLevel(FCLAlertDialog.AlertLevel.INFO);
builder1.setAlertLevel(FCLAlertDialog.AlertLevel.ALERT);
builder1.setCancelable(false);
builder1.setTitle(context.getString(R.string.install_failed));
builder1.setMessage(context.getString(R.string.modpack_type_curse_not_found));

View File

@ -8,18 +8,31 @@ import android.content.res.ColorStateList;
import android.view.View;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatDialog;
import com.tungsten.fcl.R;
import com.tungsten.fcl.setting.Profile;
import com.tungsten.fcl.setting.VersionSetting;
import com.tungsten.fcl.ui.TaskDialog;
import com.tungsten.fcl.util.TaskCancellationAction;
import com.tungsten.fclcore.fakefx.collections.FXCollections;
import com.tungsten.fclcore.fakefx.collections.ObservableList;
import com.tungsten.fclcore.mod.ModAdviser;
import com.tungsten.fclcore.mod.ModpackExportInfo;
import com.tungsten.fclcore.mod.mcbbs.McbbsModpackExportTask;
import com.tungsten.fclcore.mod.multimc.MultiMCInstanceConfiguration;
import com.tungsten.fclcore.mod.multimc.MultiMCModpackExportTask;
import com.tungsten.fclcore.mod.server.ServerModpackExportTask;
import com.tungsten.fclcore.task.Schedulers;
import com.tungsten.fclcore.task.Task;
import com.tungsten.fclcore.task.TaskExecutor;
import com.tungsten.fclcore.task.TaskListener;
import com.tungsten.fclcore.util.Lang;
import com.tungsten.fclcore.util.StringUtils;
import com.tungsten.fclcore.util.io.FileUtils;
import com.tungsten.fcllibrary.component.FCLCheckBoxTreeAdapter;
import com.tungsten.fcllibrary.component.FCLCheckBoxTreeItem;
import com.tungsten.fcllibrary.component.dialog.FCLAlertDialog;
import com.tungsten.fcllibrary.component.theme.ThemeEngine;
import com.tungsten.fcllibrary.component.ui.FCLTempPage;
import com.tungsten.fcllibrary.component.view.FCLButton;
@ -28,6 +41,8 @@ import com.tungsten.fcllibrary.component.view.FCLUILayout;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@ -36,11 +51,10 @@ public class ModpackFileSelectionPage extends FCLTempPage implements View.OnClic
private final Profile profile;
private final String version;
private final String type;
private final ModpackExportInfo.Options options;
private final String modpackType;
private final ModAdviser adviser;
private final ModpackExportInfo exportInfo;
private final File file;
private final File modpackFile;
private FCLCheckBoxTreeItem<String> rootItem;
@ -48,15 +62,14 @@ public class ModpackFileSelectionPage extends FCLTempPage implements View.OnClic
private ListView listView;
private FCLButton next;
public ModpackFileSelectionPage(Context context, int id, FCLUILayout parent, int resId, Profile profile, String version, String type, ModpackExportInfo.Options options, ModAdviser adviser, ModpackExportInfo exportInfo, File file) {
public ModpackFileSelectionPage(Context context, int id, FCLUILayout parent, int resId, Profile profile, String version, String type, ModAdviser adviser, ModpackExportInfo exportInfo, File file) {
super(context, id, parent, resId);
this.profile = profile;
this.version = version;
this.type = type;
this.options = options;
this.modpackType = type;
this.adviser = adviser;
this.exportInfo = exportInfo;
this.file = file;
this.modpackFile = file;
}
@Override
@ -95,8 +108,42 @@ public class ModpackFileSelectionPage extends FCLTempPage implements View.OnClic
private void finish() {
ArrayList<String> list = new ArrayList<>();
getFilesNeeded(rootItem, "minecraft", list);
exportInfo.setWhitelist(list);
TaskDialog taskDialog = new TaskDialog(getContext(), new TaskCancellationAction(AppCompatDialog::dismiss));
taskDialog.setTitle(getContext().getString(R.string.message_doing));
Task<?> task = getExportTask(modpackType, exportInfo, modpackFile);
TaskExecutor executor = task.executor(new TaskListener() {
@Override
public void onStop(boolean success, TaskExecutor executor) {
Schedulers.androidUIThread().execute(() -> {
if (success) {
FCLAlertDialog.Builder builder1 = new FCLAlertDialog.Builder(getContext());
builder1.setAlertLevel(FCLAlertDialog.AlertLevel.INFO);
builder1.setCancelable(false);
builder1.setMessage(getContext().getString(R.string.message_success));
builder1.setNegativeButton(getContext().getString(com.tungsten.fcllibrary.R.string.dialog_positive), () -> ManagePageManager.getInstance().dismissAllTempPagesCreatedByPage(ManagePageManager.PAGE_ID_MANAGE_MANAGE));
builder1.create().show();
} else {
if (executor.getException() == null)
return;
String appendix = StringUtils.getStackTrace(executor.getException());
FCLAlertDialog.Builder builder1 = new FCLAlertDialog.Builder(getContext());
builder1.setAlertLevel(FCLAlertDialog.AlertLevel.ALERT);
builder1.setCancelable(false);
builder1.setTitle(getContext().getString(R.string.message_failed));
builder1.setMessage(appendix);
builder1.setNegativeButton(getContext().getString(com.tungsten.fcllibrary.R.string.dialog_positive), null);
builder1.create().show();
}
});
}
});
taskDialog.setExecutor(executor);
taskDialog.show();
executor.start();
}
private FCLCheckBoxTreeItem<String> getTreeItem(File file, String basePath) {
@ -160,6 +207,120 @@ public class ModpackFileSelectionPage extends FCLTempPage implements View.OnClic
}
}
private Task<?> getExportTask(String modpackType, ModpackExportInfo exportInfo, File modpackFile) {
return new Task<Object>() {
Task<?> exportTask;
@Override
public boolean doPreExecute() {
return true;
}
@Override
public void preExecute() throws Exception {
switch (modpackType) {
case ModpackTypeSelectionPage.MODPACK_TYPE_MCBBS:
exportTask = exportAsMcbbs(exportInfo, modpackFile);
break;
case ModpackTypeSelectionPage.MODPACK_TYPE_MULTIMC:
exportTask = exportAsMultiMC(exportInfo, modpackFile);
break;
case ModpackTypeSelectionPage.MODPACK_TYPE_SERVER:
exportTask = exportAsServer(exportInfo, modpackFile);
break;
default:
throw new IllegalStateException("Unrecognized modpack type " + modpackType);
}
}
@Override
public Collection<Task<?>> getDependents() {
return Collections.singleton(exportTask);
}
@Override
public void execute() throws Exception {
}
};
}
private Task<?> exportAsMcbbs(ModpackExportInfo exportInfo, File modpackFile) {
return new Task<Void>() {
Task<?> dependency = null;
@Override
public void execute() {
dependency = new McbbsModpackExportTask(profile.getRepository(), version, exportInfo, modpackFile);
}
@Override
public Collection<Task<?>> getDependencies() {
return Collections.singleton(dependency);
}
};
}
private Task<?> exportAsMultiMC(ModpackExportInfo exportInfo, File modpackFile) {
return new Task<Void>() {
Task<?> dependency;
@Override
public void execute() {
VersionSetting vs = profile.getVersionSetting(version);
dependency = new MultiMCModpackExportTask(profile.getRepository(), version, exportInfo.getWhitelist(),
new MultiMCInstanceConfiguration(
"OneSix",
exportInfo.getName() + "-" + exportInfo.getVersion(),
null,
Lang.toIntOrNull(vs.getPermSize()),
"",
"",
null,
exportInfo.getDescription(),
null,
exportInfo.getJavaArguments(),
false,
854,
480,
vs.getMaxMemory(),
exportInfo.getMinMemory(),
false,
/* showConsoleOnError */ true,
/* autoCloseConsole */ false,
/* overrideMemory */ true,
/* overrideJavaLocation */ false,
/* overrideJavaArgs */ true,
/* overrideConsole */ true,
/* overrideCommands */ true,
/* overrideWindow */ true
), modpackFile);
}
@Override
public Collection<Task<?>> getDependencies() {
return Collections.singleton(dependency);
}
};
}
private Task<?> exportAsServer(ModpackExportInfo exportInfo, File modpackFile) {
return new Task<Void>() {
Task<?> dependency;
@Override
public void execute() {
dependency = new ServerModpackExportTask(profile.getRepository(), version, exportInfo, modpackFile);
}
@Override
public Collection<Task<?>> getDependencies() {
return Collections.singleton(dependency);
}
};
}
@Override
public Task<?> refresh(Object... param) {
return null;

View File

@ -272,7 +272,7 @@ public class ModpackInfoPage extends FCLTempPage implements View.OnClickListener
)));
}
ModpackFileSelectionPage page = new ModpackFileSelectionPage(getContext(), PageManager.PAGE_ID_TEMP, getParent(), R.layout.page_modpack_file, profile, versionName, type, options, ModAdviser::suggestMod, exportInfo, file);
ModpackFileSelectionPage page = new ModpackFileSelectionPage(getContext(), PageManager.PAGE_ID_TEMP, getParent(), R.layout.page_modpack_file, profile, versionName, type, ModAdviser::suggestMod, exportInfo, file);
ManagePageManager.getInstance().showTempPage(page);
}
}

View File

@ -387,9 +387,11 @@
<string name="menu_settings_show_log">显示日志</string>
<string name="message_cancelled">操作已取消</string>
<string name="message_doing">请耐心等待</string>
<string name="message_downloading">正在下载</string>
<string name="message_error">错误</string>
<string name="message_failed">操作失败</string>
<string name="message_success">已完成</string>
<string name="message_unknown">未知</string>
<string name="message_copy">复制成功!</string>
@ -460,7 +462,7 @@
<string name="modpack_wizard_step_initialization_force_update">强制升级整合包至最新版本(需要自建服务器)</string>
<string name="modpack_wizard_step_initialization_include_launcher">包含启动器</string>
<string name="modpack_wizard_step_initialization_save">选择要导出到的游戏整合包位置</string>
<string name="modpack_wizard_step_initialization_warning">在制作整合包前,请您确认您选择的版本可以正常启动,\n并保证您的 Minecraft 是正式版而非快照版,\n而且不应当将不允许非官方途径传播的 Mod、材质包等纳入整合包。\n整合包会保存您目前的下载源设置</string>
<string name="modpack_wizard_step_initialization_warning">在制作整合包前,请您确认您选择的版本可以正常启动,\n并保证您的 Minecraft 是正式版而非快照版,\n而且不应当将不允许非官方途径传播的 Mod、材质包等纳入整合包。</string>
<string name="modrinth_category_adventure">冒险</string>
<string name="modrinth_category_bukkit">Bukkit</string>

View File

@ -406,9 +406,11 @@
<string name="menu_settings_show_log">Show Log</string>
<string name="message_cancelled">Operation was cancelled</string>
<string name="message_doing">Please wait</string>
<string name="message_downloading">Downloading</string>
<string name="message_error">Error</string>
<string name="message_failed">Operation Failed</string>
<string name="message_success">Operation completed successfully</string>
<string name="message_unknown">Unknown</string>
<string name="message_copy">Copy successfully!</string>
@ -479,7 +481,7 @@
<string name="modpack_wizard_step_initialization_force_update">Force updating the modpack to the latest version (you\'ll need a file-hosting service)</string>
<string name="modpack_wizard_step_initialization_include_launcher">Include the launcher</string>
<string name="modpack_wizard_step_initialization_save">Export to…</string>
<string name="modpack_wizard_step_initialization_warning">Before creating a modpack, please make sure the game launches, and it is a release version instead of a snapshot version. The launcher will save your download settings.\n\nKeep in mind that you are not allowed to add mods and resource packs that are explicitly said not to be distributed or put in a modpack.</string>
<string name="modpack_wizard_step_initialization_warning">Before creating a modpack, please make sure the game launches, and it is a release version instead of a snapshot version.\n\nKeep in mind that you are not allowed to add mods and resource packs that are explicitly said not to be distributed or put in a modpack.</string>
<string name="modrinth_category_adventure">Adventure</string>
<string name="modrinth_category_bukkit">Bukkit</string>

View File

@ -7,11 +7,11 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import com.tungsten.fcl.R;
import com.tungsten.fclcore.fakefx.beans.binding.Bindings;
import com.tungsten.fclcore.fakefx.beans.property.SimpleBooleanProperty;
import com.tungsten.fclcore.fakefx.collections.ObservableList;
import com.tungsten.fclcore.task.Schedulers;
import com.tungsten.fcllibrary.R;
import com.tungsten.fcllibrary.component.view.FCLCheckBox;
import com.tungsten.fcllibrary.component.view.FCLImageButton;
import com.tungsten.fcllibrary.component.view.FCLLinearLayout;