Skip to content

Commit d9a0bd6

Browse files
authored
Merge pull request #921 from unbelievableflavour/ubisoft-preinstall-step
Added Ubisoft Connect preinstall step
2 parents 1d6ef24 + a642a2f commit d9a0bd6

3 files changed

Lines changed: 77 additions & 0 deletions

File tree

app/src/main/java/app/gamenative/enums/Marker.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ enum class Marker(val fileName: String ) {
1111
PHYSX_INSTALLED(".physx_installed"),
1212
OPENAL_INSTALLED(".openal_installed"),
1313
XNA_INSTALLED(".xna_installed"),
14+
UBISOFT_CONNECT_INSTALLED(".ubisoft_connect_installed"),
1415
}

app/src/main/java/app/gamenative/utils/PreInstallSteps.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ object PreInstallSteps {
3030
OpenALStep,
3131
XnaFrameworkStep,
3232
GogScriptInterpreterStep,
33+
UbisoftConnectStep,
3334
)
3435

3536
private val allMarkers = steps.map { it.marker }.distinct()
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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

Comments
 (0)