|
| 1 | +package app.gamenative.utils |
| 2 | + |
| 3 | +import app.gamenative.data.GameSource |
| 4 | +import app.gamenative.enums.Marker |
| 5 | +import com.winlator.container.Container |
| 6 | +import java.io.File |
| 7 | +import java.nio.file.Files |
| 8 | +import timber.log.Timber |
| 9 | + |
| 10 | +object UbisoftConnectStep : PreInstallStep { |
| 11 | + private const val TAG = "UbisoftConnectStep" |
| 12 | + private const val INSTALLER_NAME = "UbisoftConnectInstaller.exe" |
| 13 | + private const val COMMON_REDIST_SUBDIR = "_CommonRedist/UbisoftConnect" |
| 14 | + private const val WINE_INSTALLER_PATH = "A:\\_CommonRedist\\UbisoftConnect\\UbisoftConnectInstaller.exe" |
| 15 | + |
| 16 | + override val marker: Marker = Marker.UBISOFT_CONNECT_INSTALLED |
| 17 | + |
| 18 | + override fun appliesTo( |
| 19 | + container: Container, |
| 20 | + gameSource: GameSource, |
| 21 | + gameDirPath: String, |
| 22 | + ): Boolean { |
| 23 | + if (MarkerUtils.hasMarker(gameDirPath, Marker.UBISOFT_CONNECT_INSTALLED)) return false |
| 24 | + |
| 25 | + return true |
| 26 | + } |
| 27 | + |
| 28 | + override fun buildCommand( |
| 29 | + container: Container, |
| 30 | + appId: String, |
| 31 | + gameSource: GameSource, |
| 32 | + gameDir: File, |
| 33 | + gameDirPath: String, |
| 34 | + ): String? { |
| 35 | + val rootInstaller = File(gameDir, INSTALLER_NAME) |
| 36 | + val commonRedistDir = File(gameDir, COMMON_REDIST_SUBDIR) |
| 37 | + val commonRedistInstaller = File(commonRedistDir, INSTALLER_NAME) |
| 38 | + |
| 39 | + if (!ensureInstallerAtCommonRedist(rootInstaller, commonRedistDir, commonRedistInstaller)) { |
| 40 | + Timber.tag(TAG).i( |
| 41 | + "Ubisoft Connect installer not present at expected _CommonRedist path for game at %s", |
| 42 | + gameDirPath, |
| 43 | + ) |
| 44 | + return null |
| 45 | + } |
| 46 | + |
| 47 | + val command = "$WINE_INSTALLER_PATH /S" |
| 48 | + Timber.tag(TAG).i("Using Ubisoft Connect installer (silent): %s", command) |
| 49 | + |
| 50 | + return command |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * IMPORTANT: Ubisoft Connect installer cannot be run from the game root directory. |
| 55 | + * Ensures the Ubisoft Connect installer is present at the expected _CommonRedist path. |
| 56 | + * If it's only present in the game root, creates a symlink there first. |
| 57 | + */ |
| 58 | + private fun ensureInstallerAtCommonRedist( |
| 59 | + rootInstaller: File, |
| 60 | + commonRedistDir: File, |
| 61 | + commonRedistInstaller: File, |
| 62 | + ): Boolean { |
| 63 | + if (commonRedistInstaller.isFile) return true |
| 64 | + if (!rootInstaller.isFile) return false |
| 65 | + |
| 66 | + try { |
| 67 | + commonRedistDir.mkdirs() |
| 68 | + Files.createSymbolicLink(commonRedistInstaller.toPath(), rootInstaller.toPath()) |
| 69 | + return commonRedistInstaller.exists() |
| 70 | + } catch (t: Throwable) { |
| 71 | + Timber.tag(TAG).w(t, "Failed creating Ubisoft Connect symlink") |
| 72 | + return false |
| 73 | + } |
| 74 | + } |
| 75 | +} |
0 commit comments