mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-13 23:54:48 +01:00
extraction
This commit is contained in:
@@ -65,14 +65,18 @@ export default class Downloads extends React.Component<IProps, IState> {
|
||||
|
||||
async downloadGrasscutterStable() {
|
||||
const folder = await this.getGrasscutterFolder()
|
||||
this.props.downloadManager.addDownload(STABLE_DOWNLOAD, folder + '\\grasscutter.zip')
|
||||
this.props.downloadManager.addDownload(STABLE_DOWNLOAD, folder + '\\grasscutter.zip', () =>{
|
||||
unzip(folder + '\\grasscutter.zip', folder + '\\')
|
||||
})
|
||||
|
||||
this.disableButtons()
|
||||
}
|
||||
|
||||
async downloadGrasscutterLatest() {
|
||||
const folder = await this.getGrasscutterFolder()
|
||||
this.props.downloadManager.addDownload(DEV_DOWNLOAD, folder + '\\grasscutter.zip')
|
||||
this.props.downloadManager.addDownload(DEV_DOWNLOAD, folder + '\\grasscutter.zip', () =>{
|
||||
unzip(folder + '\\grasscutter.zip', folder + '\\')
|
||||
})
|
||||
|
||||
this.disableButtons()
|
||||
}
|
||||
@@ -80,7 +84,7 @@ export default class Downloads extends React.Component<IProps, IState> {
|
||||
async downloadResources() {
|
||||
const folder = await this.getGrasscutterFolder()
|
||||
this.props.downloadManager.addDownload(RESOURCES_DOWNLOAD, folder + '\\resources.zip', () => {
|
||||
unzip(folder + '\\resources.zip', 'Grasscutter_Resources-main/Resources/', folder + '/resources')
|
||||
unzip(folder + '\\resources.zip', folder + '\\')
|
||||
})
|
||||
|
||||
this.disableButtons()
|
||||
|
||||
@@ -18,13 +18,13 @@ export default class DownloadHandler {
|
||||
constructor() {
|
||||
this.downloads = []
|
||||
|
||||
listen('download_progress', (...payload) => {
|
||||
listen('download_progress', ({ payload }) => {
|
||||
// @ts-expect-error Payload may be unknown but backend always returns this object
|
||||
const obj: {
|
||||
downloaded: string,
|
||||
total: string,
|
||||
path: string,
|
||||
} = payload[0].payload
|
||||
} = payload
|
||||
|
||||
const index = this.downloads.findIndex(download => download.path === obj.path)
|
||||
this.downloads[index].progress = parseInt(obj.downloaded, 10)
|
||||
@@ -37,9 +37,9 @@ export default class DownloadHandler {
|
||||
this.downloads[index].speed = byteToString(speed) + '/s'
|
||||
})
|
||||
|
||||
listen('download_finished', (...payload) => {
|
||||
listen('download_finished', ({ payload }) => {
|
||||
// Remove from array
|
||||
const filename = payload[0]?.payload
|
||||
const filename = payload
|
||||
|
||||
// set status to finished
|
||||
const index = this.downloads.findIndex(download => download.path === filename)
|
||||
@@ -52,18 +52,31 @@ export default class DownloadHandler {
|
||||
}
|
||||
})
|
||||
|
||||
listen('download_error', (...payload) => {
|
||||
listen('download_error', ({ payload }) => {
|
||||
// @ts-expect-error shut up typescript
|
||||
const errorData: {
|
||||
path: string,
|
||||
error: string,
|
||||
} = payload[0]?.payload
|
||||
} = payload
|
||||
|
||||
// Set download to error
|
||||
const index = this.downloads.findIndex(download => download.path === errorData.path)
|
||||
this.downloads[index].status = 'error'
|
||||
this.downloads[index].error = errorData.error
|
||||
})
|
||||
|
||||
// Extraction events
|
||||
listen('extract_start', ({ payload }) => {
|
||||
// Find the download that is no extracting and set it's status as such
|
||||
const index = this.downloads.findIndex(download => download.path === payload)
|
||||
this.downloads[index].status = 'extracting'
|
||||
})
|
||||
|
||||
listen('extract_end', ({ payload }) => {
|
||||
// Find the download that is no extracting and set it's status as such
|
||||
const index = this.downloads.findIndex(download => download.path === payload)
|
||||
this.downloads[index].status = 'finished'
|
||||
})
|
||||
}
|
||||
|
||||
getDownloads() {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { invoke } from '@tauri-apps/api'
|
||||
|
||||
export function unzip(file: string, zippath: string, dest: string) {
|
||||
export function unzip(file: string, dest: string) {
|
||||
invoke('unzip', {
|
||||
zipfile: file,
|
||||
zippath: zippath,
|
||||
destpath: dest,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user