'use client' import { faArrowUpRightFromSquare, faHardDrive } from '@fortawesome/free-solid-svg-icons' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { useGlobal } from '@/providers/GlobalProvider' import { invoke } from '@tauri-apps/api/core' import { useEffect, useState } from 'react' import prettyBytes from 'pretty-bytes' import { BaseDirectory, exists, remove } from '@tauri-apps/plugin-fs' import { openFolder } from '@/lib/util' export default function ManageVersionPopup () { const { versionsList, serverVersionList, managingVersion, viewingInfoFromDownloads, setManagingVersion, closePopup, setPopupMode, setSelectedVersionList, downloadVersions, versions, customDataLocation } = useGlobal() const [versionSize, setVersionSize] = useState(0) useEffect(() => { if (viewingInfoFromDownloads) return invoke('folder_size', { version: managingVersion }).then(size => { setVersionSize(Number(size)) }) }, [managingVersion, setVersionSize, viewingInfoFromDownloads]) if (!managingVersion) return null const versionInfo = serverVersionList?.versions.find( vf => vf.id == managingVersion ) return ( <>

Viewing {versionInfo?.displayName}

{!viewingInfoFromDownloads && (

Installed{' '} {new Intl.DateTimeFormat(undefined).format( versionsList[managingVersion] ?? 0 )}

)} {versionInfo && ( <> {versionInfo.releaseDate != 0 && (

Released{' '} {new Intl.DateTimeFormat(undefined).format( versionInfo?.releaseDate ? versionInfo.releaseDate * 1000 : 0 )}

)} {versionInfo.changelog && (
setPopupMode(4)} >

View Changelog

)} )}
{!viewingInfoFromDownloads && (

Size on disk:{' '} {prettyBytes(versionSize, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}

openFolder(managingVersion)} title="Click to browse the game's files." > Open Folder
{ closePopup() await versions?.set( 'list', Object.fromEntries( Object.entries(versionsList).filter( ([k]) => k !== managingVersion ) ) ) if ( await exists( (customDataLocation ? customDataLocation + '/' : null) + 'game/' + managingVersion, { baseDir: customDataLocation ? undefined : BaseDirectory.AppLocalData } ) ) await remove( (customDataLocation ? customDataLocation + '/' : null) + 'game/' + managingVersion, { baseDir: customDataLocation ? undefined : BaseDirectory.AppLocalData, recursive: true } ) }} title='Click to uninstall this game. This will NOT remove any progress or any save files.' > Uninstall
{ //change popup to downloads setManagingVersion(null) setPopupMode(1) //uninstall await versions?.set( 'list', Object.fromEntries( Object.entries(versionsList).filter( ([k]) => k !== managingVersion ) ) ) if ( await exists( (customDataLocation ? customDataLocation + '/' : null) + 'game/' + managingVersion, { baseDir: customDataLocation ? undefined : BaseDirectory.AppLocalData } ) ) await remove( (customDataLocation ? customDataLocation + '/' : null) + 'game/' + managingVersion, { baseDir: customDataLocation ? undefined : BaseDirectory.AppLocalData, recursive: true } ) //reinstall setSelectedVersionList([managingVersion]) downloadVersions([ { id: managingVersion, type: 0 } ]) }} title="Click to reinstall this game. This will NOT remove any progress or any save files. This WILL uninstall any modifications to the game's executable files." > Reinstall
)}
) }