mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-14 08:04:52 +01:00
game download feature
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
"files_downloading": "Files Downloading: ",
|
"files_downloading": "Files Downloading: ",
|
||||||
"files_extracting": "Files Extracting: ",
|
"files_extracting": "Files Extracting: ",
|
||||||
"port_help_text": "Ensure this is the Dispatch server port, not the Game server port. This is almost always '443'.",
|
"port_help_text": "Ensure this is the Dispatch server port, not the Game server port. This is almost always '443'.",
|
||||||
"game_help_text": "You do not need to use a seperate copy to play with Grasscutter. This is for either downgrading to 2.6 or if you do not have the game installed."
|
"game_help_text": "You do not need to use a separate copy to play with Grasscutter. This is for either downgrading to 2.6 or if you do not have the game installed."
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"game_exec": "Set Game Executable",
|
"game_exec": "Set Game Executable",
|
||||||
|
|||||||
@@ -13,11 +13,13 @@ interface IProps {
|
|||||||
extensions?: string[]
|
extensions?: string[]
|
||||||
readonly?: boolean
|
readonly?: boolean
|
||||||
placeholder?: string
|
placeholder?: string
|
||||||
|
folder?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IState {
|
interface IState {
|
||||||
value: string
|
value: string
|
||||||
placeholder: string
|
placeholder: string
|
||||||
|
folder: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class DirInput extends React.Component<IProps, IState> {
|
export default class DirInput extends React.Component<IProps, IState> {
|
||||||
@@ -27,6 +29,7 @@ export default class DirInput extends React.Component<IProps, IState> {
|
|||||||
this.state = {
|
this.state = {
|
||||||
value: props.value || '',
|
value: props.value || '',
|
||||||
placeholder: this.props.placeholder || 'Select file or folder...',
|
placeholder: this.props.placeholder || 'Select file or folder...',
|
||||||
|
folder: this.props.folder || false
|
||||||
}
|
}
|
||||||
|
|
||||||
this.handleIconClick = this.handleIconClick.bind(this)
|
this.handleIconClick = this.handleIconClick.bind(this)
|
||||||
@@ -56,11 +59,21 @@ export default class DirInput extends React.Component<IProps, IState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async handleIconClick() {
|
async handleIconClick() {
|
||||||
let path = await open({
|
let path
|
||||||
filters: [
|
|
||||||
{ name: 'Files', extensions: this.props.extensions || ['*'] }
|
if (this.state.folder) {
|
||||||
]
|
path = await open({
|
||||||
})
|
directory: true
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
path = await open({
|
||||||
|
filters: [
|
||||||
|
{ name: 'Files', extensions: this.props.extensions || ['*'] }
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (Array.isArray(path)) path = path[0]
|
if (Array.isArray(path)) path = path[0]
|
||||||
if (!path) return
|
if (!path) return
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ import './Game.css'
|
|||||||
import DirInput from '../common/DirInput'
|
import DirInput from '../common/DirInput'
|
||||||
import BigButton from '../common/BigButton'
|
import BigButton from '../common/BigButton'
|
||||||
import HelpButton from '../common/HelpButton'
|
import HelpButton from '../common/HelpButton'
|
||||||
|
import { unzip } from '../../../utils/zipUtils'
|
||||||
|
|
||||||
|
const GAME_DOWNLOAD = ''
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
closeFn: () => void;
|
closeFn: () => void;
|
||||||
@@ -28,31 +31,49 @@ export default class Downloads extends React.Component<IProps, IState> {
|
|||||||
gameDownloadFolder: '',
|
gameDownloadFolder: '',
|
||||||
dirPlaceholder: ''
|
dirPlaceholder: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.downloadGame = this.downloadGame.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
this.setState({
|
this.setState({
|
||||||
dirPlaceholder: await translate('components.select_folder')
|
dirPlaceholder: await translate('components.select_folder')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
console.log(this.state)
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadGame() {
|
async downloadGame() {
|
||||||
console.log('Download!')
|
const folder = this.state.gameDownloadFolder
|
||||||
|
this.props.downloadManager.addDownload(GAME_DOWNLOAD, folder + '\\game.zip', () =>{
|
||||||
|
unzip(folder + '\\game.zip', folder + '\\', () => {
|
||||||
|
this.setState({
|
||||||
|
gameDownloading: false
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
gameDownloading: true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<Menu heading='Download Game' closeFn={this.props.closeFn} className="GameDownloadMenu">
|
<Menu heading='Download Game' closeFn={this.props.closeFn} className="GameDownloadMenu">
|
||||||
<div className="GameDownload">
|
<div className="GameDownload">
|
||||||
<BigButton id="downloadGameBtn" onClick={this.downloadGame}>Download Game</BigButton>
|
{
|
||||||
|
this.state.gameDownloadFolder !== '' && !this.state.gameDownloading ?
|
||||||
|
<BigButton id="downloadGameBtn" onClick={this.downloadGame}>Download Game</BigButton>
|
||||||
|
: <BigButton id="disabledGameBtn" onClick={() => null} disabled>Download Game</BigButton>
|
||||||
|
}
|
||||||
<HelpButton>
|
<HelpButton>
|
||||||
<Tr text="main.game_help_text" />
|
<Tr text="main.game_help_text" />
|
||||||
</HelpButton>
|
</HelpButton>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="GameDownloadDir">
|
<div className="GameDownloadDir">
|
||||||
<DirInput placeholder={this.state.dirPlaceholder} clearable={false} readonly={false} onChange={(value: string) => this.setState({
|
<DirInput folder placeholder={this.state.dirPlaceholder} clearable={false} readonly={true} onChange={(value: string) => this.setState({
|
||||||
gameDownloading: true,
|
|
||||||
gameDownloadFolder: value
|
gameDownloadFolder: value
|
||||||
})}/>
|
})}/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user