@@ -92,24 +92,25 @@ private ReleaseType getCurrentType() {
9292 return getReleaseType ().get ();
9393 }
9494
95- private String getCurrentTypeName () {
96- return getCurrentType ().getName ();
97- }
98-
9995 private String getLauncherPath () {
100- return "/usr/bin/hmcl-" + getCurrentTypeName ();
96+ return getPackageFiles (). launcherPath ();
10197 }
10298
10399 private String getTargetPath () {
104- return "/usr/share/java/hmcl/" + getAppShFile ().getAsFile (). get (). getName ();
100+ return getPackageFiles ().targetPath ();
105101 }
106102
107103 private String getDesktopFilePath () {
108- return "/usr/share/applications/hmcl-%s.desktop" . formatted ( getCurrentTypeName () );
104+ return getPackageFiles (). desktopFilePath ( );
109105 }
110106
111107 private String getIconTargetPath () {
112- return "/usr/share/icons/hicolor/256x256/apps/hmcl-%s.png" .formatted (getCurrentTypeName ());
108+ return getPackageFiles ().iconTargetPath ();
109+ }
110+
111+ /// Creates the shared Linux package path helper for this task.
112+ private LinuxPackageFiles getPackageFiles () {
113+ return new LinuxPackageFiles (getCurrentType (), getAppShFile ().getAsFile ().get ().getName (), "deb" );
113114 }
114115
115116 /// Ensures parent directories exist in the tar stream before child entries are written.
@@ -168,8 +169,9 @@ public void run() throws IOException {
168169 if (iconBytes .length == 0 )
169170 throw new IOException ("Empty icon file: " + iconFile );
170171
171- byte [] launcherScriptBytes = getLauncherScript ().getBytes (StandardCharsets .UTF_8 );
172- byte [] desktopInfoBytes = getDesktopInfo ().getBytes (StandardCharsets .UTF_8 );
172+ LinuxPackageFiles files = getPackageFiles ();
173+ byte [] launcherScriptBytes = files .launcherScript ().getBytes (StandardCharsets .UTF_8 );
174+ byte [] desktopInfoBytes = files .desktopInfo ().getBytes (StandardCharsets .UTF_8 );
173175
174176 LOGGER .lifecycle ("Creating control.tar.gz" );
175177 var controlData = new ByteArrayOutputStream ();
@@ -234,8 +236,6 @@ private String getControl(long appSize, long launcherScriptSize, long desktopInf
234236 """ .formatted (getCurrentType ().getPackageName (), getVersion ().get (), Math .max (installedSize , 1 )) + "\n " ;
235237 }
236238
237- private static final String COMMON_LAUNCHER_PATH = "/usr/bin/hmcl" ;
238-
239239 /// Registers the channel command into the shared `hmcl` alternatives group.
240240 private String getPostinst () {
241241 return """
@@ -245,7 +245,7 @@ private String getPostinst() {
245245 if [ "$1" = configure ]; then
246246 update-alternatives --install %s hmcl %s %d
247247 fi
248- """ .formatted (COMMON_LAUNCHER_PATH , getLauncherPath (), getCurrentType ().getAlternativesPriority ());
248+ """ .formatted (LinuxPackageFiles . COMMON_LAUNCHER_PATH , getLauncherPath (), getCurrentType ().getAlternativesPriority ());
249249 }
250250
251251 /// Removes the channel command from the shared `hmcl` alternatives group.
@@ -260,41 +260,4 @@ private String getPrerm() {
260260 """ .formatted (getLauncherPath ());
261261 }
262262
263- /// Creates a tiny wrapper that launches the bundled shell script from the user's home directory.
264- private String getLauncherScript () {
265- return """
266- #!/usr/bin/env bash
267- cd "$HOME"
268- if [ -z "${HMCL_USER_HOME:-}" ]; then
269- if [ -z "${XDG_DATA_HOME:-}" ]; then
270- export HMCL_USER_HOME="$HOME/.local/share/hmcl"
271- else
272- export HMCL_USER_HOME="$XDG_DATA_HOME/hmcl"
273- fi
274- fi
275- if [ -z "${HMCL_LOCAL_HOME:-}" ]; then
276- export HMCL_LOCAL_HOME="$HMCL_USER_HOME/local-%s"
277- fi
278- if [ -z "${HMCL_DEPENDENCIES_DIR:-}" ]; then
279- export HMCL_DEPENDENCIES_DIR="$HMCL_USER_HOME/dependencies"
280- fi
281- exec %s "$@"
282- """ .formatted (getCurrentTypeName (), getTargetPath ());
283- }
284-
285- /// Generates the desktop entry that points to the channel-specific launcher command.
286- private String getDesktopInfo () {
287- return """
288- [Desktop Entry]
289- Type=Application
290- Name=%s
291- Comment=Hello Minecraft! Launcher
292- Exec=%s
293- Icon=%s
294- Terminal=false
295- StartupNotify=false
296- Categories=Game;
297- Keywords=mc;minecraft;
298- """ .formatted (getCurrentType ().getDisplayName (), getLauncherPath (), getIconTargetPath ());
299- }
300263}
0 commit comments