Skip to content

Commit

Permalink
Launcher: extract resource
Browse files Browse the repository at this point in the history
  • Loading branch information
glKarin committed Nov 13, 2024
1 parent e7f2348 commit 15bfa8a
Show file tree
Hide file tree
Showing 17 changed files with 641 additions and 77 deletions.
8 changes: 4 additions & 4 deletions Q3E/src/main/java/com/n0n3m4/q3e/Q3EGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

public class Q3EGUI
{
public final static int DIALOG_ERROR = -1;
public final static int DIALOG_ERROR = -1;
public final static int DIALOG_CANCEL = 0;
public final static int DIALOG_YES = 1;
public final static int DIALOG_NO = 2;
public final static int DIALOG_OTHER = 3;
public final static int DIALOG_YES = 1;
public final static int DIALOG_NO = 2;
public final static int DIALOG_OTHER = 3;

private final Activity m_context;

Expand Down
31 changes: 9 additions & 22 deletions Q3E/src/main/java/com/n0n3m4/q3e/Q3EGameHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -426,15 +426,14 @@ private void DumpExtractResourceVersion(String systemVersionPath, String apkVers

public void ExtractTDMGLSLShaderSource()
{
final String destname = Q3EUtils.q3ei.datadir + "/darkmod";
final String versionFile = destname + "/glslprogs/idtech4amm.version";
Q3EPatchResourceManager manager = new Q3EPatchResourceManager(m_context);
final String versionFile = KStr.AppendPath(Q3EUtils.q3ei.datadir, "darkmod", "glslprogs/idtech4amm.version");
final String version = Q3EGlobals.TDM_GLSL_SHADER_VERSION;
final String name = "The Dark Mod GLSL shader source";
final String zip = "pak/darkmod/glprogs.pk4";

boolean overwrite = CheckExtractResourceOverwrite(versionFile, version, name);

if(ExtractZip(zip, destname, overwrite))
if(manager.Fetch(Q3EGlobals.PatchResource.TDM_GLSL_SHADER, overwrite) != null)
{
if (overwrite)
{
Expand All @@ -447,15 +446,14 @@ public void ExtractTDMGLSLShaderSource()

public void ExtractDOOM3BFGHLSLShaderSource()
{
final String destname = Q3EUtils.q3ei.datadir + "/doom3bfg/base";
final String versionFile = destname + "/renderprogs/idtech4amm.version";
Q3EPatchResourceManager manager = new Q3EPatchResourceManager(m_context);
final String versionFile = KStr.AppendPath(Q3EUtils.q3ei.datadir, "doom3bfg/base", "renderprogs/idtech4amm.version");
final String version = Q3EGlobals.RBDOOM3BFG_HLSL_SHADER_VERSION;
final String name = "RBDOOM 3 BFG HLSL shader source";
final String zip = "pak/doom3bfg/renderprogs.pk4";

boolean overwrite = CheckExtractResourceOverwrite(versionFile, version, name);

if(ExtractZip(zip, destname, overwrite))
if(manager.Fetch(Q3EGlobals.PatchResource.DOOM3BFG_HLSL_SHADER, overwrite) != null)
{
if (overwrite)
{
Expand All @@ -468,25 +466,14 @@ public void ExtractDOOM3BFGHLSLShaderSource()

public void ExtractGZDOOMResource()
{
final String destname = Q3EUtils.q3ei.datadir + "/gzdoom";
final String versionFile = destname + "/idtech4amm.version";
Q3EPatchResourceManager manager = new Q3EPatchResourceManager(m_context);
final String versionFile = KStr.AppendPath(Q3EUtils.q3ei.datadir, "gzdoom", "idtech4amm.version");
final String version = Q3EGlobals.GZDOOM_VERSION;
final String name = "GZDOOM game resource";
final String assetFolder = "pak/gzdoom";
final String[] files = {
"brightmaps.pk3",
"game_support.pk3",
"game_widescreen_gfx.pk3",
"gzdoom.pk3",
"lights.pk3",
"soundfonts/gzdoom.sf2",
"fm_banks/GENMIDI.GS.wopl",
"fm_banks/gs-by-papiezak-and-sneakernets.wopn",
};

boolean overwrite = CheckExtractResourceOverwrite(versionFile, version, name);

if(ExtractCopy(assetFolder, destname, overwrite, files))
if(manager.Fetch(Q3EGlobals.PatchResource.GZDOOM_RESOURCE, overwrite) != null)
{
if (overwrite)
{
Expand Down
9 changes: 9 additions & 0 deletions Q3E/src/main/java/com/n0n3m4/q3e/Q3EGlobals.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,15 @@ public final class Q3EGlobals
public static final String GAME_SUBDIR_ETW = "etw";
public static final String GAME_SUBDIR_REALRTCW = "realrtcw";

public enum PatchResource
{
QUAKE4_SABOT,
DOOM3_RIVENSIN_ORIGIANL_LEVELS,
DOOM3BFG_HLSL_SHADER,
TDM_GLSL_SHADER,
GZDOOM_RESOURCE,
}

/*
public static final String[] QUAKE4_MAPS = {
"airdefense1",
Expand Down
98 changes: 98 additions & 0 deletions Q3E/src/main/java/com/n0n3m4/q3e/Q3EInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,20 @@ private void SetupConfigFile()
config_name = ConfigFileName();
}

public static String GetStandaloneDirectory(boolean standalone, String game)
{
String subdir = GetGameStandaloneDirectory(game);
if(standalone)
return subdir;
else if(Q3EGlobals.GAME_TDM.equals(game)
|| Q3EGlobals.GAME_DOOM3BFG.equals(game)
|| Q3EGlobals.GAME_GZDOOM.equals(game)
)
return subdir;
else
return null;
}

private void SetupSubDir()
{
String subdir = GameSubDirectory();
Expand Down Expand Up @@ -821,6 +835,90 @@ else if(Q3EUtils.q3ei.isRealRTCW)
return null;
}

public static String GetGameModPreferenceKey(String name)
{
if(Q3EGlobals.GAME_QUAKE4.equalsIgnoreCase(name))
return Q3EPreference.pref_harm_q4_fs_game;
else if(Q3EGlobals.GAME_PREY.equalsIgnoreCase(name))
return Q3EPreference.pref_harm_prey_fs_game;
else if(Q3EGlobals.GAME_QUAKE2.equalsIgnoreCase(name))
return Q3EPreference.pref_harm_q2_fs_game;
else if(Q3EGlobals.GAME_QUAKE3.equalsIgnoreCase(name))
return Q3EPreference.pref_harm_q3_fs_game;
else if(Q3EGlobals.GAME_RTCW.equalsIgnoreCase(name))
return Q3EPreference.pref_harm_rtcw_fs_game;
else if(Q3EGlobals.GAME_TDM.equalsIgnoreCase(name))
return Q3EPreference.pref_harm_tdm_fs_game;
else if(Q3EGlobals.GAME_QUAKE1.equalsIgnoreCase(name))
return Q3EPreference.pref_harm_q1_fs_game;
else if(Q3EGlobals.GAME_DOOM3BFG.equalsIgnoreCase(name))
return Q3EPreference.pref_harm_d3bfg_fs_game;
else if(Q3EGlobals.GAME_GZDOOM.equalsIgnoreCase(name))
return Q3EPreference.pref_harm_gzdoom_fs_game;
else if(Q3EGlobals.GAME_ETW.equalsIgnoreCase(name))
return Q3EPreference.pref_harm_etw_fs_game;
else if(Q3EGlobals.GAME_REALRTCW.equalsIgnoreCase(name))
return Q3EPreference.pref_harm_realrtcw_fs_game;
else
return Q3EPreference.pref_harm_fs_game;
}

public static String GetEnableModPreferenceKey(String name)
{
if(Q3EGlobals.GAME_QUAKE4.equalsIgnoreCase(name))
return Q3EPreference.pref_harm_q4_user_mod;
else if(Q3EGlobals.GAME_PREY.equalsIgnoreCase(name))
return Q3EPreference.pref_harm_prey_user_mod;
else if(Q3EGlobals.GAME_QUAKE2.equalsIgnoreCase(name))
return Q3EPreference.pref_harm_q2_user_mod;
else if(Q3EGlobals.GAME_QUAKE3.equalsIgnoreCase(name))
return Q3EPreference.pref_harm_q3_user_mod;
else if(Q3EGlobals.GAME_RTCW.equalsIgnoreCase(name))
return Q3EPreference.pref_harm_rtcw_user_mod;
else if(Q3EGlobals.GAME_TDM.equalsIgnoreCase(name))
return Q3EPreference.pref_harm_tdm_user_mod;
else if(Q3EGlobals.GAME_QUAKE1.equalsIgnoreCase(name))
return Q3EPreference.pref_harm_q1_user_mod;
else if(Q3EGlobals.GAME_DOOM3BFG.equalsIgnoreCase(name))
return Q3EPreference.pref_harm_d3bfg_user_mod;
else if(Q3EGlobals.GAME_GZDOOM.equalsIgnoreCase(name))
return Q3EPreference.pref_harm_gzdoom_user_mod;
else if(Q3EGlobals.GAME_ETW.equalsIgnoreCase(name))
return Q3EPreference.pref_harm_etw_user_mod;
else if(Q3EGlobals.GAME_REALRTCW.equalsIgnoreCase(name))
return Q3EPreference.pref_harm_realrtcw_user_mod;
else
return Q3EPreference.pref_harm_user_mod;
}

public static String GetGameBaseDirectory(String name)
{
if(Q3EGlobals.GAME_PREY.equalsIgnoreCase(name))
return Q3EGlobals.GAME_BASE_PREY;
else if(Q3EGlobals.GAME_QUAKE4.equalsIgnoreCase(name))
return Q3EGlobals.GAME_BASE_QUAKE4;
else if(Q3EGlobals.GAME_QUAKE2.equalsIgnoreCase(name))
return Q3EGlobals.GAME_BASE_QUAKE2;
else if(Q3EGlobals.GAME_QUAKE3.equalsIgnoreCase(name))
return Q3EGlobals.GAME_BASE_QUAKE3;
else if(Q3EGlobals.GAME_RTCW.equalsIgnoreCase(name))
return Q3EGlobals.GAME_BASE_RTCW;
else if(Q3EGlobals.GAME_TDM.equalsIgnoreCase(name))
return Q3EGlobals.GAME_BASE_TDM;
else if(Q3EGlobals.GAME_QUAKE1.equalsIgnoreCase(name))
return Q3EGlobals.GAME_BASE_QUAKE1;
else if(Q3EGlobals.GAME_DOOM3BFG.equalsIgnoreCase(name))
return Q3EGlobals.GAME_BASE_DOOM3BFG;
else if(Q3EGlobals.GAME_GZDOOM.equalsIgnoreCase(name))
return Q3EGlobals.GAME_BASE_GZDOOM;
else if(Q3EGlobals.GAME_ETW.equalsIgnoreCase(name))
return Q3EGlobals.GAME_BASE_ETW;
else if(Q3EGlobals.GAME_REALRTCW.equalsIgnoreCase(name))
return Q3EGlobals.GAME_BASE_REALRTCW;
else
return Q3EGlobals.GAME_BASE_DOOM3;
}

public void SetAppStoragePath(Context context)
{
Q3EUtils.q3ei.app_storage_path = Q3EUtils.GetAppStoragePath(context, null);
Expand Down
105 changes: 105 additions & 0 deletions Q3E/src/main/java/com/n0n3m4/q3e/Q3EPatchResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package com.n0n3m4.q3e;

import android.app.Activity;
import android.content.Context;
import android.util.Log;

import com.n0n3m4.q3e.karin.KLog;
import com.n0n3m4.q3e.karin.KStr;

import java.util.Arrays;

public class Q3EPatchResource
{
public static final int COPY_FILE_TO_FILE = 1; // copy assets/patch.pk4 -> dirname/zzz.pk4
public static final int COPY_FILE_TO_DIR = 2; // copy assets/patch.pk4 -> dirname/
public static final int COPY_DIR_FILES_TO_DIR = 3; // copy assets/ :: patch.pk4, other/other.pk4, ... -> dirname/
public static final int EXTRACT_ZIP_TO_DIR = 4; // extract assets/patch.zip -> dirname/

public final Q3EGlobals.PatchResource type;
public final String name;
public final String version;
public final String game;
public final String mod;
public final int extract;
public final String assetPath;
public final String fsPath;
public final String[] assetFiles;

public Q3EPatchResource(Q3EGlobals.PatchResource type, String name, String version, String game, String mod, int extract, String assetPath, String fsPath, String...assetFiles)
{
this.type = type;
this.name = name;
this.version = version;
this.game = game;
this.mod = mod;
this.extract = extract;
this.assetPath = assetPath;
this.fsPath = fsPath;
if(null != assetFiles)
{
this.assetFiles = new String[assetFiles.length];
System.arraycopy(assetFiles, 0, this.assetFiles, 0, assetFiles.length);
}
else
this.assetFiles = null;
}

public String Fetch(Context context, boolean overwrite, String...fsgame)
{
switch(extract)
{
case COPY_FILE_TO_FILE:
return CopyFileToFile(context, overwrite, fsgame);
case COPY_FILE_TO_DIR:
return CopyFileToDir(context, overwrite, fsgame);
case COPY_DIR_FILES_TO_DIR:
return CopyDirFilesToDir(context, overwrite, fsgame);
case EXTRACT_ZIP_TO_DIR:
return ExtractZipToDir(context, overwrite, fsgame);
default:
throw new RuntimeException("Unexcept extract type:" + extract);
}
}

private String MakeOutPath(String...fsgame)
{
String path = Q3EInterface.GetStandaloneDirectory(Q3EUtils.q3ei.standalone, game);
if(null == fsPath)
path = KStr.AppendPath(path, null != fsgame ? fsgame[0] : null);
else if(fsPath.isEmpty())
path = KStr.AppendPath(path, mod);
else
path = KStr.AppendPath(path, fsPath);

return KStr.AppendPath(Q3EUtils.q3ei.datadir, path);
}

private String CopyFileToFile(Context context, boolean overwrite, String...fsgame)
{
String toPath = MakeOutPath(fsgame);
KLog.i(Q3EGlobals.CONST_Q3E_LOG_TAG, "Copying file '%s' to file '%s'", assetPath, toPath);
return Q3EUtils.ExtractCopyFile(context, assetPath, toPath, overwrite) ? toPath : null;
}

private String CopyFileToDir(Context context, boolean overwrite, String...fsgame)
{
String toPath = MakeOutPath(fsgame);
KLog.i(Q3EGlobals.CONST_Q3E_LOG_TAG, "Copying file '%s' to directory '%s/'", assetPath, toPath);
return Q3EUtils.ExtractCopyFile(context, assetPath, toPath + "/", overwrite) ? toPath : null;
}

private String CopyDirFilesToDir(Context context, boolean overwrite, String...fsgame)
{
String toPath = MakeOutPath(fsgame);
KLog.i(Q3EGlobals.CONST_Q3E_LOG_TAG, "Copying directory '%s' files '%s' to directory '%s/'", assetPath, Arrays.toString(assetFiles), toPath);
return Q3EUtils.ExtractCopyDir(context, assetPath, toPath, overwrite, assetFiles) ? toPath : null;
}

private String ExtractZipToDir(Context context, boolean overwrite, String...fsgame)
{
String toPath = MakeOutPath(fsgame);
KLog.i(Q3EGlobals.CONST_Q3E_LOG_TAG, "Extracting zip file '%s' to directory '%s/'", assetPath, toPath);
return Q3EUtils.ExtractZip(context, assetPath, toPath, overwrite) ? toPath : null;
}
}
Loading

0 comments on commit 15bfa8a

Please sign in to comment.