mirror of
https://github.com/amwatson/CitraVR.git
synced 2024-09-20 03:11:40 +02:00
delete config.ini if version below 0.4.0 -- use release version as visible version name in About section
This commit is contained in:
parent
c652bbf25f
commit
55078ad93a
5 changed files with 88 additions and 10 deletions
|
@ -221,25 +221,31 @@ fun getGitVersion(): String {
|
|||
var versionName = "0.0"
|
||||
|
||||
try {
|
||||
versionName = ProcessBuilder("git", "describe", "--always", "--long")
|
||||
// First, try to get the most recent tag associated with the current commit
|
||||
versionName = ProcessBuilder("git", "describe", "--tags", "--abbrev=0")
|
||||
.directory(project.rootDir)
|
||||
.redirectOutput(ProcessBuilder.Redirect.PIPE)
|
||||
.redirectError(ProcessBuilder.Redirect.PIPE)
|
||||
.start().inputStream.bufferedReader().use { it.readText() }
|
||||
.trim()
|
||||
.replace(Regex("(-0)?-[^-]+$"), "")
|
||||
|
||||
// If no tags are found, use commit hash
|
||||
if (versionName.isEmpty()) {
|
||||
versionName = ProcessBuilder("git", "describe", "--always", "--long")
|
||||
.directory(project.rootDir)
|
||||
.redirectOutput(ProcessBuilder.Redirect.PIPE)
|
||||
.redirectError(ProcessBuilder.Redirect.PIPE)
|
||||
.start().inputStream.bufferedReader().use { it.readText() }
|
||||
.trim()
|
||||
.replace(Regex("(-0)?-[^-]+$"), "")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
logger.error("Cannot find git, defaulting to dummy version number")
|
||||
}
|
||||
|
||||
if (System.getenv("GITHUB_ACTIONS") != null) {
|
||||
val gitTag = System.getenv("GIT_TAG_NAME")
|
||||
versionName = gitTag ?: versionName
|
||||
}
|
||||
|
||||
return versionName
|
||||
}
|
||||
|
||||
|
||||
fun getGitHash(): String =
|
||||
runGitCommand(ProcessBuilder("git", "rev-parse", "--short", "HEAD")) ?: "dummy-hash"
|
||||
|
||||
|
|
|
@ -9,10 +9,13 @@ import android.app.Application
|
|||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.content.Context
|
||||
import androidx.preference.PreferenceManager
|
||||
import org.citra.citra_emu.utils.DirectoryInitialization
|
||||
import org.citra.citra_emu.utils.DocumentsTree
|
||||
import org.citra.citra_emu.utils.GpuDriverHelper
|
||||
import org.citra.citra_emu.utils.Log
|
||||
import org.citra.citra_emu.utils.PermissionsHandler
|
||||
import org.citra.citra_emu.vr.VRUtils
|
||||
|
||||
class CitraApplication : Application() {
|
||||
private fun createNotificationChannel() {
|
||||
|
@ -44,8 +47,21 @@ class CitraApplication : Application() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun updateLaunchVersionPrefs() {
|
||||
val preferences = PreferenceManager.getDefaultSharedPreferences(applicationContext)
|
||||
val releaseVersionPrev : String = preferences.getString(VRUtils.PREF_RELEASE_VERSION_NAME_LAUNCH_CURRENT, "")!!
|
||||
val releaseVersionCur : String = BuildConfig.VERSION_NAME
|
||||
preferences.edit()
|
||||
.putString(VRUtils.PREF_RELEASE_VERSION_NAME_LAUNCH_PREV, releaseVersionPrev)
|
||||
.putString(VRUtils.PREF_RELEASE_VERSION_NAME_LAUNCH_CURRENT, releaseVersionCur)
|
||||
.apply()
|
||||
Log.info("Version: \"${preferences.getString(VRUtils.PREF_RELEASE_VERSION_NAME_LAUNCH_PREV, "")}\" (prev) -> \"${preferences.getString(
|
||||
VRUtils.PREF_RELEASE_VERSION_NAME_LAUNCH_CURRENT, "")}\" (current)")
|
||||
}
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
updateLaunchVersionPrefs()
|
||||
application = this
|
||||
documentsTree = DocumentsTree()
|
||||
if (PermissionsHandler.hasWriteAccess(applicationContext)) {
|
||||
|
|
|
@ -197,7 +197,11 @@ class Settings {
|
|||
R.string.emulation_toggle_pause
|
||||
)
|
||||
|
||||
const val PREF_FIRST_APP_LAUNCH = "FirstApplicationLaunch"
|
||||
// VR-SPECIFIC:
|
||||
// For CitraVR, change the name of the FirstApplicationLaunch param
|
||||
// so setup is still prompted if user switches from mainline Citra to CitraVR
|
||||
// (preferences are reused)
|
||||
const val PREF_FIRST_APP_LAUNCH = "VR_FirstApplicationLaunch"
|
||||
const val PREF_MATERIAL_YOU = "MaterialYouTheme"
|
||||
const val PREF_THEME_MODE = "ThemeMode"
|
||||
const val PREF_BLACK_BACKGROUNDS = "BlackBackgrounds"
|
||||
|
|
|
@ -35,7 +35,6 @@ import androidx.work.WorkManager
|
|||
import com.google.android.material.color.MaterialColors
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.navigation.NavigationBarView
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.launch
|
||||
import org.citra.citra_emu.R
|
||||
import org.citra.citra_emu.activities.EmulationActivity
|
||||
|
@ -56,6 +55,7 @@ import org.citra.citra_emu.utils.PermissionsHandler
|
|||
import org.citra.citra_emu.utils.ThemeUtil
|
||||
import org.citra.citra_emu.viewmodel.GamesViewModel
|
||||
import org.citra.citra_emu.viewmodel.HomeViewModel
|
||||
import org.citra.citra_emu.vr.VRUtils
|
||||
import org.citra.citra_emu.vr.VrActivity
|
||||
|
||||
class MainActivity : AppCompatActivity(), ThemeProvider {
|
||||
|
@ -82,6 +82,18 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
|||
ThemeUtil.setTheme(this)
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val preferences = PreferenceManager.getDefaultSharedPreferences(applicationContext)
|
||||
val releaseVersionPrev : String = preferences.getString(VRUtils.PREF_RELEASE_VERSION_NAME_LAUNCH_PREV, "")!!
|
||||
val releaseVersionCur : String = preferences.getString(VRUtils.PREF_RELEASE_VERSION_NAME_LAUNCH_CURRENT, "")!!
|
||||
// This means this is a first-time install, an app reinstall wiped app data, or the last app version was below
|
||||
// V0.4.0. In all these cases, we want to wipe the previous config Because the earlier versions may have introduced input issues.
|
||||
if (VRUtils.isReleaseVersion(releaseVersionCur) && VRUtils.hasLowerVersionThan(releaseVersionPrev, VRUtils.createVersionString(0, 4, 0))) {
|
||||
Log.info("New install from prev version \"${releaseVersionPrev}\" needs update. Wiping config.ini")
|
||||
SettingsFile.getSettingsFile(SettingsFile.FILE_NAME_CONFIG)?.delete()
|
||||
}
|
||||
// If this is the first time installing CitraVR s
|
||||
SettingsFile.getSettingsFile(SettingsFile.FILE_NAME_CONFIG)?.delete()
|
||||
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
|
|
|
@ -67,4 +67,44 @@ object VRUtils {
|
|||
else -> -1
|
||||
}
|
||||
}
|
||||
|
||||
const val PREF_RELEASE_VERSION_NAME_LAUNCH_CURRENT = "VR_ReleaseVersionName_LaunchCurrent"
|
||||
const val PREF_RELEASE_VERSION_NAME_LAUNCH_PREV = "VR_ReleaseVersionName_LaunchPrev"
|
||||
|
||||
// release versions are in the form "v\d+\.\d+\.\d+". All other values are build versions
|
||||
fun isReleaseVersion(version: String): Boolean {
|
||||
return version.startsWith("v")
|
||||
}
|
||||
fun getVersionMajor(version: String): Int {
|
||||
return if (isReleaseVersion(version)) version.split(".")[0].removePrefix("v").toInt() else -1
|
||||
}
|
||||
fun getVersionMinor(version: String): Int {
|
||||
return if (isReleaseVersion(version)) version.split(".")[1].toInt() else -1
|
||||
}
|
||||
fun getVersionPatch(version: String): Int {
|
||||
return if (isReleaseVersion(version)) version.split(".")[2].toInt() else -1
|
||||
}
|
||||
|
||||
fun hasLowerVersionThan(versionOrig: String, versionComp: String): Boolean {
|
||||
val majorOrig = getVersionMajor(versionOrig)
|
||||
val majorComp = getVersionMajor(versionComp)
|
||||
if (majorOrig < majorComp) return true
|
||||
if (majorOrig > majorComp) return false
|
||||
|
||||
val minorOrig = getVersionMinor(versionOrig)
|
||||
val minorComp = getVersionMinor(versionComp)
|
||||
if (minorOrig < minorComp) return true
|
||||
if (minorOrig > minorComp) return false
|
||||
|
||||
val patchOrig = getVersionPatch(versionOrig)
|
||||
val patchComp = getVersionPatch(versionComp)
|
||||
if (patchOrig < patchComp) return true
|
||||
if (patchOrig > patchComp) return false
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
fun createVersionString(major: Int, minor: Int, patch: Int): String {
|
||||
return "v$major.$minor.$patch"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue