Let the user approve revision updates before proceeding
This commit is contained in:
@@ -42,6 +42,7 @@ type GlobalCtxType = {
|
||||
} | null
|
||||
viewingInfoFromDownloads: boolean
|
||||
version: string | null
|
||||
downloadVersions: (list: string[]) => Promise<void>
|
||||
}
|
||||
|
||||
const GlobalCtx = createContext<GlobalCtxType | null>(null)
|
||||
|
||||
105
src/app/componets/VersionUpdateWarning.tsx
Normal file
105
src/app/componets/VersionUpdateWarning.tsx
Normal file
@@ -0,0 +1,105 @@
|
||||
'use client'
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { useGlobal } from '../GlobalProvider'
|
||||
import { BaseDirectory, exists, remove } from '@tauri-apps/plugin-fs'
|
||||
import { writeVersionsConfig } from '../util/BazookaManager'
|
||||
import { useState } from 'react'
|
||||
|
||||
export default function VersionUpdateWarning () {
|
||||
const [confirmed, setConfirmed] = useState<-1 | 0>(-1)
|
||||
|
||||
const {
|
||||
managingVersion,
|
||||
setDownloadedVersionsConfig,
|
||||
setManagingVersion,
|
||||
setPopupMode,
|
||||
setSelectedVersionList,
|
||||
downloadVersions
|
||||
} = useGlobal()
|
||||
if (!managingVersion) return <p>Error</p>
|
||||
|
||||
return (
|
||||
<>
|
||||
<p className='text-xl text-center'>Warning!</p>
|
||||
<div className='popup-content text-center p-2 relative'>
|
||||
<p className='mb-2'>
|
||||
Before proceeding, please note that any modifications to the
|
||||
installation directory <b>(NOT THE SAVE DATA)</b> will be completely
|
||||
wiped/reset.
|
||||
</p>
|
||||
<p>
|
||||
If you do not want your installation directory wiped just yet, please
|
||||
backup the files to another directory. When you click update, it will
|
||||
be wiped.
|
||||
</p>
|
||||
<p className='my-2'>
|
||||
Updating will have the same effect as clicking the uninstall button
|
||||
then installing again.
|
||||
</p>
|
||||
<p>Revisions are not a frequent thing and rarely ever happen.</p>
|
||||
<div className='flex flex-row gap-2 absolute bottom-2 left-1/2 -translate-x-1/2 w-max'>
|
||||
<button
|
||||
className='button btntheme2'
|
||||
onClick={async () =>
|
||||
invoke('open_folder', {
|
||||
name: managingVersion
|
||||
})
|
||||
}
|
||||
title="Click to browse the game's files."
|
||||
>
|
||||
Open Folder / Installation directory
|
||||
</button>
|
||||
<button
|
||||
className='button btntheme2'
|
||||
onClick={async () => {
|
||||
if (confirmed == -1) {
|
||||
setConfirmed(0)
|
||||
return
|
||||
}
|
||||
|
||||
//change popup to downloads
|
||||
setManagingVersion(null)
|
||||
setPopupMode(1)
|
||||
|
||||
//uninstall
|
||||
setDownloadedVersionsConfig(prev => {
|
||||
if (!prev) return prev
|
||||
const updatedList = Object.fromEntries(
|
||||
Object.entries(prev.list).filter(
|
||||
([k]) => k !== managingVersion
|
||||
)
|
||||
)
|
||||
const updatedConfig = {
|
||||
...prev,
|
||||
list: updatedList
|
||||
}
|
||||
writeVersionsConfig(updatedConfig)
|
||||
return updatedConfig
|
||||
})
|
||||
|
||||
if (
|
||||
await exists('game/' + managingVersion, {
|
||||
baseDir: BaseDirectory.AppLocalData
|
||||
})
|
||||
)
|
||||
await remove('game/' + managingVersion, {
|
||||
baseDir: BaseDirectory.AppLocalData,
|
||||
recursive: true
|
||||
})
|
||||
|
||||
//reinstall
|
||||
setSelectedVersionList([managingVersion])
|
||||
downloadVersions([managingVersion])
|
||||
}}
|
||||
title='Click to update the game'
|
||||
>
|
||||
<span className='text-red-500 font-bold underline'>
|
||||
{confirmed == -1 ? 'Update' : 'Are you sure?'}
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -45,6 +45,21 @@ export default function Installs () {
|
||||
setCategory(-1)
|
||||
}
|
||||
|
||||
const needsRevisionUpdate = (
|
||||
lastRevision: number | undefined,
|
||||
version: string
|
||||
) => {
|
||||
if (!lastRevision) return false
|
||||
return (
|
||||
lastRevision > 0 &&
|
||||
(downloadedVersionsConfig == undefined
|
||||
? 0
|
||||
: downloadedVersionsConfig?.list[version]) /
|
||||
1000 <=
|
||||
lastRevision
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='mx-4 mt-4'>
|
||||
<div className='flex justify-between items-center mb-4'>
|
||||
@@ -203,17 +218,32 @@ export default function Installs () {
|
||||
<div
|
||||
key={entry}
|
||||
className={`downloads-entry ${
|
||||
normalConfig?.settings.useLegacyInteractButtons
|
||||
normalConfig?.settings.useLegacyInteractButtons ||
|
||||
needsRevisionUpdate(
|
||||
getVersionInfo(entry)?.lastRevision,
|
||||
entry
|
||||
)
|
||||
? ''
|
||||
: 'cursor-pointer'
|
||||
}`}
|
||||
title={
|
||||
normalConfig?.settings.useLegacyInteractButtons
|
||||
normalConfig?.settings.useLegacyInteractButtons ||
|
||||
needsRevisionUpdate(
|
||||
getVersionInfo(entry)?.lastRevision,
|
||||
entry
|
||||
)
|
||||
? ''
|
||||
: 'Click to launch game. Right-click to manage this version install'
|
||||
}
|
||||
onClick={async () => {
|
||||
if (normalConfig?.settings.useLegacyInteractButtons) return
|
||||
if (
|
||||
normalConfig?.settings.useLegacyInteractButtons ||
|
||||
needsRevisionUpdate(
|
||||
getVersionInfo(entry)?.lastRevision,
|
||||
entry
|
||||
)
|
||||
)
|
||||
return
|
||||
const verInfo = getVersionInfo(entry)
|
||||
if (verInfo == undefined) return
|
||||
const gameInfo = getGameInfo(verInfo.game)
|
||||
@@ -232,7 +262,14 @@ export default function Installs () {
|
||||
}}
|
||||
onContextMenu={e => {
|
||||
e.preventDefault()
|
||||
if (normalConfig?.settings.useLegacyInteractButtons) return
|
||||
if (
|
||||
normalConfig?.settings.useLegacyInteractButtons ||
|
||||
needsRevisionUpdate(
|
||||
getVersionInfo(entry)?.lastRevision,
|
||||
entry
|
||||
)
|
||||
)
|
||||
return
|
||||
|
||||
setManagingVersion(entry)
|
||||
setPopupMode(2)
|
||||
@@ -242,7 +279,7 @@ export default function Installs () {
|
||||
>
|
||||
<div className='h-18 w-screen relative'>
|
||||
<p className='text-2xl'>
|
||||
{getVersionInfo(entry)?.displayName}
|
||||
{getVersionInfo(entry)?.displayName}{' '}
|
||||
</p>
|
||||
|
||||
<div className='flex gap-2 absolute left-0 bottom-0'>
|
||||
@@ -272,6 +309,19 @@ export default function Installs () {
|
||||
<FontAwesomeIcon icon={faWarning} color='#ffc800' />
|
||||
<p>Uses wine</p>
|
||||
</div>
|
||||
<div
|
||||
className='entry-info-item'
|
||||
onClick={e => e.stopPropagation()}
|
||||
hidden={
|
||||
!needsRevisionUpdate(
|
||||
getVersionInfo(entry)?.lastRevision,
|
||||
entry
|
||||
)
|
||||
}
|
||||
>
|
||||
<FontAwesomeIcon icon={faWarning} color='#ffc800' />
|
||||
<p>Needs revision update!</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className='flex gap-2 absolute right-0 bottom-0'>
|
||||
@@ -284,6 +334,10 @@ export default function Installs () {
|
||||
setShowPopup(true)
|
||||
setFadeOut(false)
|
||||
}}
|
||||
hidden={needsRevisionUpdate(
|
||||
getVersionInfo(entry)?.lastRevision,
|
||||
entry
|
||||
)}
|
||||
title='Click to view version info'
|
||||
>
|
||||
View Info
|
||||
@@ -291,7 +345,11 @@ export default function Installs () {
|
||||
<button
|
||||
className='button'
|
||||
hidden={
|
||||
!normalConfig?.settings.useLegacyInteractButtons
|
||||
!normalConfig?.settings.useLegacyInteractButtons ||
|
||||
needsRevisionUpdate(
|
||||
getVersionInfo(entry)?.lastRevision,
|
||||
entry
|
||||
)
|
||||
}
|
||||
onClick={e => {
|
||||
e.stopPropagation()
|
||||
@@ -326,12 +384,35 @@ export default function Installs () {
|
||||
})
|
||||
}}
|
||||
hidden={
|
||||
!normalConfig?.settings.useLegacyInteractButtons
|
||||
!normalConfig?.settings.useLegacyInteractButtons ||
|
||||
needsRevisionUpdate(
|
||||
getVersionInfo(entry)?.lastRevision,
|
||||
entry
|
||||
)
|
||||
}
|
||||
title='Click to launch game'
|
||||
>
|
||||
Launch
|
||||
</button>
|
||||
<button
|
||||
className='button'
|
||||
onClick={e => {
|
||||
e.stopPropagation()
|
||||
setManagingVersion(entry)
|
||||
setPopupMode(5)
|
||||
setShowPopup(true)
|
||||
setFadeOut(false)
|
||||
}}
|
||||
hidden={
|
||||
!needsRevisionUpdate(
|
||||
getVersionInfo(entry)?.lastRevision,
|
||||
entry
|
||||
)
|
||||
}
|
||||
title='Click to update the game'
|
||||
>
|
||||
Update
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -46,6 +46,7 @@ import {
|
||||
} from '@tauri-apps/plugin-notification'
|
||||
import VersionChangelog from './componets/VersionChangelog'
|
||||
import { BaseDirectory, exists, remove } from '@tauri-apps/plugin-fs'
|
||||
import VersionUpdateWarning from './componets/VersionUpdateWarning'
|
||||
|
||||
const roboto = Roboto({
|
||||
subsets: ['latin']
|
||||
@@ -394,28 +395,26 @@ export default function RootLayout ({
|
||||
if (!serverVersionList || !downloadedVersionsConfig) return
|
||||
revisionCheck.current = true
|
||||
;(async () => {
|
||||
const newConfig = {
|
||||
...downloadedVersionsConfig,
|
||||
list: { ...downloadedVersionsConfig.list }
|
||||
}
|
||||
const versionsToSelect: string[] = []
|
||||
|
||||
for (const [key, value] of Object.entries(
|
||||
downloadedVersionsConfig.list
|
||||
)) {
|
||||
const verInfo = serverVersionList.versions.find(item => item.id === key)
|
||||
|
||||
if (!verInfo || value / 1000 <= verInfo.lastRevision) {
|
||||
delete newConfig.list[key]
|
||||
versionsToSelect.push(key)
|
||||
if (
|
||||
!verInfo ||
|
||||
(verInfo.lastRevision > 0 && value / 1000 <= verInfo.lastRevision)
|
||||
) {
|
||||
if (
|
||||
await exists('game/' + key + '/' + verInfo?.executable, {
|
||||
baseDir: BaseDirectory.AppLocalData
|
||||
})
|
||||
)
|
||||
await remove('game/' + key + '/' + verInfo?.executable, {
|
||||
baseDir: BaseDirectory.AppLocalData,
|
||||
recursive: true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
setDownloadedVersionsConfig(newConfig)
|
||||
writeVersionsConfig(newConfig)
|
||||
setSelectedVersionList(prev => [...prev, ...versionsToSelect])
|
||||
|
||||
await downloadVersions(versionsToSelect)
|
||||
})()
|
||||
}, [serverVersionList, downloadedVersionsConfig, downloadVersions])
|
||||
|
||||
@@ -480,7 +479,8 @@ export default function RootLayout ({
|
||||
setSelectedGame,
|
||||
getVersionsAmountData,
|
||||
viewingInfoFromDownloads,
|
||||
version
|
||||
version,
|
||||
downloadVersions
|
||||
}}
|
||||
>
|
||||
<div
|
||||
@@ -893,6 +893,14 @@ export default function RootLayout ({
|
||||
No version selected
|
||||
</p>
|
||||
)
|
||||
) : popupMode === 5 ? (
|
||||
managingVersion && downloadedVersionsConfig ? (
|
||||
<VersionUpdateWarning />
|
||||
) : (
|
||||
<p className='text-xl text-center'>
|
||||
No version selected
|
||||
</p>
|
||||
)
|
||||
) : null}
|
||||
{popupMode == 0 &&
|
||||
selectedGame &&
|
||||
|
||||
Reference in New Issue
Block a user