Finish mod installing and uninstalling

This commit is contained in:
Lncvrt committed 2026-03-24 18:01:24 -07:00
1 parent ea1c05d2d9
commit 60f9f95be4
6 files changed
+138 -39

No files matched your search

+6 -1
View File
@@ -149,6 +149,7 @@ async fn download(
name: String, name: String,
hash: String, hash: String,
download_type: i8, download_type: i8,
mod_id: String,
) -> String { ) -> String {
println!("[download] Starting download for '{}' from '{}'", name, url); println!("[download] Starting download for '{}' from '{}'", name, url);
let _ = app.emit("download-start", format!("{}", name)); let _ = app.emit("download-start", format!("{}", name));
@@ -464,7 +465,11 @@ async fn download(
app.clone(), app.clone(),
download_zip_path.clone(), download_zip_path.clone(),
if download_type == 2 { if download_type == 2 {
game_path.join(&name).join("BepInEx").join("plugins") game_path
.join(&name)
.join("BepInEx")
.join("plugins")
.join(&mod_id)
} else { } else {
game_path.join(&name) game_path.join(&name)
}, },
+8 -1
View File
@@ -44,7 +44,14 @@ type GlobalCtxType = {
viewingInfoFromDownloads: boolean viewingInfoFromDownloads: boolean
version: string | null version: string | null
downloadVersions: ( downloadVersions: (
list: Array<{ id: string; type: 0 | 1 | 2 }> list: Array<{
id: string
type: 0 | 1 | 2
modDownload?: number
gameId?: number
modId?: number
modVersion?: string
}>
) => Promise<void> ) => Promise<void>
category: number category: number
setCategory: Dispatch<SetStateAction<number>> setCategory: Dispatch<SetStateAction<number>>
+45 -16
View File
@@ -366,7 +366,16 @@ export default function RootLayout ({
}, []) }, [])
const downloadVersions = useCallback( const downloadVersions = useCallback(
async (list: Array<{ id: string; type: 0 | 1 | 2 }>): Promise<void> => { async (
list: Array<{
id: string
type: 0 | 1 | 2
modDownload?: number
gameId?: number
modId?: number
modVersion?: string
}>
): Promise<void> => {
if (list.length === 0) return if (list.length === 0) return
setSelectedVersionList([]) setSelectedVersionList([])
@@ -399,7 +408,11 @@ export default function RootLayout ({
null, null,
null, null,
null, null,
item.type item.type,
item.modDownload ?? null,
item.gameId ?? null,
item.modId ?? null,
item.modVersion ?? null
) )
) )
@@ -444,7 +457,9 @@ export default function RootLayout ({
(downloadInfo.type == 0 (downloadInfo.type == 0
? '?gameId=' + info.id + '&downloadId=' + info.download ? '?gameId=' + info.id + '&downloadId=' + info.download
: '?downloadId=' + : '?downloadId=' +
(downloadInfo.type == 1 ? info.modSupportDownload : '')) (downloadInfo.type == 1
? info.modSupportDownload
: downloadInfo.modDownload))
) )
const signature = downloadInfoRequest.headers.get('x-signature') ?? '' const signature = downloadInfoRequest.headers.get('x-signature') ?? ''
const data = await downloadInfoRequest.json() const data = await downloadInfoRequest.json()
@@ -487,25 +502,39 @@ export default function RootLayout ({
url: data.data.url, url: data.data.url,
name: info.id, name: info.id,
hash: data.data.hash, hash: data.data.hash,
downloadType: downloadInfo.type downloadType: downloadInfo.type,
modId: String(downloadInfo.modId ?? '')
}) })
if (res === '1') { if (res === '1') {
setDownloadProgress(prev => prev.filter(d => d.version !== versionId)) setDownloadProgress(prev => prev.filter(d => d.version !== versionId))
setDownloadedVersionsConfig(prev => { if (downloadInfo.type != 1) {
if (!prev) return prev setDownloadedVersionsConfig(prev => {
if (!prev) return prev
const updated = { const updated =
...prev, downloadInfo.type == 2
list: { ? {
...prev.list, ...prev,
[versionId]: Date.now() mods: {
} ...prev.mods,
} [downloadInfo.modGame! + '-' + downloadInfo.modId!]: {
[downloadInfo.modVersion!]: Date.now()
}
}
}
: {
...prev,
list: {
...prev.list,
[versionId]: Date.now()
}
}
writeVersionsConfig(updated) writeVersionsConfig(updated)
return updated return updated
}) })
}
} else if (res == '0') { } else if (res == '0') {
setDownloadProgress(prev => { setDownloadProgress(prev => {
const i = prev.findIndex(d => d.version === info.id) const i = prev.findIndex(d => d.version === info.id)
+5 -1
View File
@@ -171,7 +171,11 @@ export default function DownloadsPopup () {
</div> </div>
</div> </div>
<p className='text-2xl text-center'> <p className='text-2xl text-center'>
{v.type == 1 ? 'Mod Manager for ' : null}{' '} {v.type == 1
? 'Mod Manager for '
: v.type == 2
? 'Mod for '
: null}{' '}
{getVersionInfo(v.version)?.displayName} {getVersionInfo(v.version)?.displayName}
</p> </p>
<div className='mt-6.25 flex items-center justify-between'> <div className='mt-6.25 flex items-center justify-between'>
+69 -19
View File
@@ -1,6 +1,7 @@
'use client' 'use client'
import { useGlobal } from '@/app/GlobalProvider' import { useGlobal } from '@/app/GlobalProvider'
import { writeVersionsConfig } from '@/lib/BazookaManager'
import { verifySignature } from '@/lib/Util' import { verifySignature } from '@/lib/Util'
import { Mod } from '@/types/Mod' import { Mod } from '@/types/Mod'
import { import {
@@ -10,10 +11,12 @@ import {
faDownload, faDownload,
faGlobe, faGlobe,
faPeopleGroup, faPeopleGroup,
faRefresh faRefresh,
faTrash
} from '@fortawesome/free-solid-svg-icons' } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { message } from '@tauri-apps/plugin-dialog' import { message } from '@tauri-apps/plugin-dialog'
import { BaseDirectory, exists, remove } from '@tauri-apps/plugin-fs'
import { arch, platform } from '@tauri-apps/plugin-os' import { arch, platform } from '@tauri-apps/plugin-os'
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
@@ -23,7 +26,10 @@ export default function ModDownloadsPopup () {
managingVersion, managingVersion,
downloadedVersionsConfig, downloadedVersionsConfig,
showModInfo, showModInfo,
setShowModInfo setShowModInfo,
downloadVersions,
downloadProgress,
setDownloadedVersionsConfig
} = useGlobal() } = useGlobal()
const [mods, setMods] = useState<Mod[] | 0 | 1>(0) const [mods, setMods] = useState<Mod[] | 0 | 1>(0)
@@ -106,16 +112,14 @@ export default function ModDownloadsPopup () {
) : !showModInfo ? ( ) : !showModInfo ? (
<div className='flex flex-col items-center justify-center gap-2 p-2'> <div className='flex flex-col items-center justify-center gap-2 p-2'>
{mods {mods
.filter( .filter(v =>
v => tab == 0
!downloadedVersionsConfig || ? Object.keys(downloadedVersionsConfig?.mods ?? []).includes(
(tab == 0 String(versionInfo?.game + '-' + v.id)
? Object.keys(downloadedVersionsConfig.mods).includes( )
String(v.id) : !Object.keys(downloadedVersionsConfig?.mods ?? []).includes(
) String(versionInfo?.game + '-' + v.id)
: !Object.keys(downloadedVersionsConfig.mods).includes( )
String(v.id)
))
) )
.map(v => { .map(v => {
return ( return (
@@ -181,17 +185,63 @@ export default function ModDownloadsPopup () {
</div> </div>
<div className='flex flex-row h-fit w-full gap-2 justify-center my-2'> <div className='flex flex-row h-fit w-full gap-2 justify-center my-2'>
{Object.keys(downloadedVersionsConfig?.mods ?? []).includes( {Object.keys(downloadedVersionsConfig?.mods ?? []).includes(
String(showModInfo.id) String(versionInfo?.game + '-' + showModInfo.id)
) ? ( ) ? (
<button className='button btntheme2 w-fit'> <button
<FontAwesomeIcon className='button btntheme2 w-fit'
icon={faDownload} disabled={downloadProgress.length != 0}
className='text-green-400' onClick={async () => {
/>{' '} const path =
'game/' +
versionInfo?.id +
'/BepInEx/plugins/' +
showModInfo.id
if (
await exists(path, {
baseDir: BaseDirectory.AppLocalData
})
)
await remove(path, {
baseDir: BaseDirectory.AppLocalData,
recursive: true
})
setDownloadedVersionsConfig(prev => {
if (!prev) return prev
const updatedMods = Object.fromEntries(
Object.entries(prev.mods).filter(
([k]) =>
k !== versionInfo?.game + '-' + showModInfo.id
)
)
const updatedConfig = {
...prev,
mods: updatedMods
}
writeVersionsConfig(updatedConfig)
return updatedConfig
})
}}
>
<FontAwesomeIcon icon={faTrash} className='text-red-400' />{' '}
Uninstall Uninstall
</button> </button>
) : ( ) : (
<button className='button btntheme2 w-fit'> <button
className='button btntheme2 w-fit'
onClick={() => {
downloadVersions([
{
id: managingVersion,
type: 2,
modDownload: showModInfo.latestDownload,
gameId: versionInfo?.game,
modId: showModInfo.id,
modVersion: showModInfo.latestVersion
}
])
}}
disabled={downloadProgress.length != 0}
>
<FontAwesomeIcon <FontAwesomeIcon
icon={faDownload} icon={faDownload}
className='text-green-400' className='text-green-400'
+5 -1
View File
@@ -18,6 +18,10 @@ export class DownloadProgress {
public url: string | null, public url: string | null,
public executable: string | null, public executable: string | null,
public hash: string | null, public hash: string | null,
public type: 0 | 1 | 2 public type: 0 | 1 | 2,
public modDownload: number | null,
public modGame: number | null,
public modId: number | null,
public modVersion: string | null
) {} ) {}
} }