Automation

- MongoDB tied to Grasscutter rather than game
- Grasscutter restarts when changing encryption if it is running
- AIO link updates without needing manual edits
This commit is contained in:
Thoronium
2023-04-02 21:15:25 -06:00
parent 5d6bd72083
commit e834022ca7
8 changed files with 151 additions and 7 deletions

View File

@@ -68,7 +68,6 @@ export class Main extends React.Component<IProps, IState> {
// Emitted for rsa replacing-purposes
listen('game_closed', async () => {
const wasPatched = await getConfigOption('patch_rsa')
const autoService = await getConfigOption('auto_mongodb')
if (wasPatched) {
const unpatched = await unpatchGame()
@@ -77,6 +76,11 @@ export class Main extends React.Component<IProps, IState> {
alert(`Could not unpatch game! (Delete version.dll in your game folder)`)
}
}
})
// Emitted for automatic processes
listen('grasscutter_closed', async () => {
const autoService = await getConfigOption('auto_mongodb')
if (autoService) {
await invoke('stop_service', { service: 'MongoDB' })

View File

@@ -12,8 +12,9 @@ import Plus from '../../resources/icons/plus.svg'
import './ServerLaunchSection.css'
import { dataDir } from '@tauri-apps/api/path'
import { getGameExecutable, getGameVersion } from '../../utils/game'
import { getGameExecutable, getGameVersion, getGrasscutterJar } from '../../utils/game'
import { patchGame, unpatchGame } from '../../utils/rsa'
import { listen } from '@tauri-apps/api/event'
interface IProps {
openExtras: (playGame: () => void) => void
@@ -25,6 +26,7 @@ interface IState {
checkboxLabel: string
ip: string
port: string
launchServer: (proc_name?: string) => void
ipPlaceholder: string
portPlaceholder: string
@@ -54,6 +56,9 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
portHelpText: '',
httpsLabel: '',
httpsEnabled: false,
launchServer: () => {
alert('Error launching grasscutter')
},
swag: false,
akebiSet: false,
migotoSet: false,
@@ -64,6 +69,11 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
this.setIp = this.setIp.bind(this)
this.setPort = this.setPort.bind(this)
this.toggleHttps = this.toggleHttps.bind(this)
this.launchServer = this.launchServer.bind(this)
listen('start_grasscutter', async () => {
this.launchServer()
})
}
async componentDidMount() {
@@ -182,12 +192,20 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
else alert('Game not found! At: ' + (exe || config.game_install_path))
}
async launchServer() {
async launchServer(proc_name?: string) {
if (await invoke('is_grasscutter_running')) {
alert('Grasscutter already running!')
return
}
const config = await getConfig()
if (!config.grasscutter_path) return alert('Grasscutter not installed or set!')
if (config.auto_mongodb) {
const grasscutter_jar = await getGrasscutterJar()
await invoke('enable_grasscutter_watcher', {
process: proc_name || grasscutter_jar,
})
// Check if MongoDB is running and start it if not
await invoke('service_status', { service: 'MongoDB' })
}

View File

@@ -13,8 +13,7 @@ import { invoke } from '@tauri-apps/api'
import { listen } from '@tauri-apps/api/event'
import HelpButton from '../common/HelpButton'
const FULL_BUILD_DOWNLOAD =
'https://cdn.discordapp.com/attachments/615655311960965130/1091457240373919814/GrasscutterCulti3.5.zip'
const FULL_BUILD_DOWNLOAD = 'https://github.com/NotThorny/Grasscutter/releases/download/culti-aio/GrasscutterCulti.zip' // Change to link that can be updated without modifying here
const STABLE_REPO_DOWNLOAD = 'https://github.com/Grasscutters/Grasscutter/archive/refs/heads/stable.zip'
const DEV_REPO_DOWNLOAD = 'https://github.com/Grasscutters/Grasscutter/archive/refs/heads/development.zip'
const STABLE_DOWNLOAD = 'https://nightly.link/Grasscutters/Grasscutter/workflows/build/stable/Grasscutter.zip'

View File

@@ -267,7 +267,11 @@ export default class Options extends React.Component<IProps, IState> {
),
})
alert('Restart Grasscutter to apply encryption settings! If it is already closed, just start as normal.')
// Check if Grasscutter is running, and restart if so to apply changes
if (await invoke('is_grasscutter_running')) {
alert('Automatically restarting Grasscutter to apply encryption changes!')
await invoke('restart_grasscutter')
}
}
async removeRSA() {

View File

@@ -12,6 +12,17 @@ export async function getGameExecutable() {
return pathArr[pathArr.length - 1]
}
export async function getGrasscutterJar() {
const config = await getConfig()
if (!config.grasscutter_path) {
return null
}
const pathArr = config.grasscutter_path.replace(/\\/g, '/').split('/')
return pathArr[pathArr.length - 1]
}
export async function getGameFolder() {
const config = await getConfig()