mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-16 17:14:36 +01:00
BREAKING: Migrate to Tauri v2
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import { fs } from '@tauri-apps/api'
|
||||
import {} from '@tauri-apps/api'
|
||||
import { dataDir } from '@tauri-apps/api/path'
|
||||
import * as fs from '@tauri-apps/plugin-fs'
|
||||
|
||||
let configFilePath: string
|
||||
let defaultConfig: Configuration
|
||||
;(async () => {
|
||||
defaultConfig = {
|
||||
toggle_grasscutter: true,
|
||||
game_install_path: 'C:\\Program Files\\Genshin Impact\\Genshin Impact game\\GenshinImpact.exe',
|
||||
game_install_path: 'C:/Program Files/Genshin Impact/Genshin Impact game/GenshinImpact.exe',
|
||||
grasscutter_with_game: false,
|
||||
grasscutter_path: '',
|
||||
java_path: '',
|
||||
@@ -150,7 +151,7 @@ export async function saveProfileConfig(obj: Configuration) {
|
||||
const local = await dataDir()
|
||||
const raw = JSON.stringify(obj)
|
||||
const prevPath = configFilePath
|
||||
configFilePath = local + 'cultivation/configuration.json'
|
||||
configFilePath = local + '/cultivation/configuration.json'
|
||||
await writeConfigFile(raw)
|
||||
|
||||
configFilePath = prevPath
|
||||
@@ -160,34 +161,24 @@ export async function saveNewProfileConfig(obj: Configuration, prof: string) {
|
||||
obj['profile'] = prof
|
||||
const local = await dataDir()
|
||||
const raw = JSON.stringify(obj)
|
||||
configFilePath = local + 'cultivation/profiles/' + obj['profile'] + '.json'
|
||||
configFilePath = local + '/cultivation/profiles/' + obj['profile'] + '.json'
|
||||
|
||||
const file: fs.FsTextFileOption = {
|
||||
path: configFilePath,
|
||||
contents: raw,
|
||||
}
|
||||
|
||||
await fs.writeFile(file)
|
||||
await fs.writeTextFile(configFilePath, raw)
|
||||
}
|
||||
|
||||
async function readConfigFile() {
|
||||
const local = await dataDir()
|
||||
|
||||
if (!configFilePath) {
|
||||
configFilePath = local + 'cultivation/configuration.json'
|
||||
configFilePath = local + '/cultivation/configuration.json'
|
||||
}
|
||||
|
||||
const dataFiles = await fs.readDir(local + 'cultivation')
|
||||
const dataFiles = await fs.readDir(local + '/cultivation')
|
||||
|
||||
// Ensure config exists
|
||||
if (!dataFiles.find((fileOrDir) => fileOrDir?.name === 'configuration.json')) {
|
||||
// Create config file
|
||||
const file: fs.FsTextFileOption = {
|
||||
path: configFilePath,
|
||||
contents: JSON.stringify(defaultConfig),
|
||||
}
|
||||
|
||||
await fs.writeFile(file)
|
||||
await fs.writeTextFile(configFilePath, JSON.stringify(defaultConfig))
|
||||
}
|
||||
|
||||
// Read existing config to get profile name
|
||||
@@ -201,14 +192,14 @@ async function readConfigFile() {
|
||||
} else {
|
||||
pf = 'configuration.json'
|
||||
}
|
||||
configFilePath = local + 'cultivation/' + pf
|
||||
configFilePath = local + '/cultivation/' + pf
|
||||
|
||||
// Ensure Cultivation dir exists
|
||||
const dirs = await fs.readDir(local)
|
||||
|
||||
if (!dirs.find((fileOrDir) => fileOrDir?.name === 'cultivation')) {
|
||||
// Create dir
|
||||
await fs.createDir(local + 'cultivation').catch((e) => console.log(e))
|
||||
await fs.mkdir(local + '/cultivation').catch((e) => console.log(e))
|
||||
}
|
||||
|
||||
const innerDirs = await fs.readDir(local + '/cultivation')
|
||||
@@ -216,7 +207,7 @@ async function readConfigFile() {
|
||||
// Create grasscutter dir for potential installation
|
||||
if (!innerDirs.find((fileOrDir) => fileOrDir?.name === 'grasscutter')) {
|
||||
// Create dir
|
||||
await fs.createDir(local + 'cultivation/grasscutter').catch((e) => console.log(e))
|
||||
await fs.mkdir(local + '/cultivation/grasscutter').catch((e) => console.log(e))
|
||||
}
|
||||
|
||||
// Finally, read the file
|
||||
@@ -225,14 +216,13 @@ async function readConfigFile() {
|
||||
|
||||
async function readDefaultConfigFile() {
|
||||
const local = await dataDir()
|
||||
configFilePath = local + 'cultivation/configuration.json'
|
||||
configFilePath = local + '/cultivation/configuration.json'
|
||||
return await fs.readTextFile(configFilePath)
|
||||
}
|
||||
|
||||
async function writeConfigFile(raw: string) {
|
||||
// All external config functions call readConfigFile, which ensure files exists
|
||||
await fs.writeFile({
|
||||
path: configFilePath,
|
||||
contents: raw,
|
||||
})
|
||||
const encoder = new TextEncoder();
|
||||
const data = encoder.encode(raw)
|
||||
await fs.writeFile(configFilePath, data)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { invoke } from '@tauri-apps/api/tauri'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { listen } from '@tauri-apps/api/event'
|
||||
import { byteToString } from './string'
|
||||
|
||||
@@ -57,7 +57,6 @@ export default class DownloadHandler {
|
||||
|
||||
// Call onFinish callback
|
||||
if (this.downloads[index]?.onFinish) {
|
||||
// @ts-expect-error onFinish is checked for existence before being called
|
||||
this.downloads[index]?.onFinish()
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { invoke } from '@tauri-apps/api'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { basename, dirname, join } from '@tauri-apps/api/path'
|
||||
import { getConfigOption } from './configuration'
|
||||
|
||||
@@ -7,12 +7,12 @@ export const getGrasscutterJar = () => getConfigOption('grasscutter_path')
|
||||
export async function getGameExecutable() {
|
||||
const exe_path = await getConfigOption('game_install_path')
|
||||
return await basename(exe_path)
|
||||
}
|
||||
}
|
||||
|
||||
export async function getGameVersion() {
|
||||
const execPath = await getConfigOption('game_install_path')
|
||||
const rootPath = await dirname(execPath)
|
||||
const baseName = (await basename(execPath, ".exe"))
|
||||
const baseName = await basename(execPath, '.exe')
|
||||
const datapath = await join(rootPath, `${baseName}_Data`)
|
||||
const asbPath = await join(datapath, 'StreamingAssets', 'asb_settings.json')
|
||||
const hasAsb = await invoke<boolean>('dir_exists', { path: asbPath })
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { invoke } from '@tauri-apps/api'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { getConfigOption } from './configuration'
|
||||
|
||||
// Generated with https://transform.tools/json-to-typescript I'm lazy cry about it
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { invoke } from '@tauri-apps/api'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import React from 'react'
|
||||
import { getConfigOption } from './configuration'
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { invoke } from '@tauri-apps/api'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { getConfigOption } from './configuration'
|
||||
|
||||
export async function getModsFolder() {
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import { ReportHandler } from 'web-vitals'
|
||||
|
||||
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
|
||||
if (onPerfEntry && onPerfEntry instanceof Function) {
|
||||
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
|
||||
getCLS(onPerfEntry)
|
||||
getFID(onPerfEntry)
|
||||
getFCP(onPerfEntry)
|
||||
getLCP(onPerfEntry)
|
||||
getTTFB(onPerfEntry)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default reportWebVitals
|
||||
@@ -1,4 +1,4 @@
|
||||
import { invoke } from '@tauri-apps/api'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
// Patch file from: https://github.com/34736384/RSAPatch/
|
||||
|
||||
export async function patchGame(newerGame: boolean, version: string) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { invoke } from '@tauri-apps/api'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
|
||||
export async function toggleEncryption(path: string) {
|
||||
let serverConf
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { invoke } from '@tauri-apps/api'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { dataDir } from '@tauri-apps/api/path'
|
||||
import { convertFileSrc } from '@tauri-apps/api/tauri'
|
||||
import { convertFileSrc } from '@tauri-apps/api/core'
|
||||
import { getConfig, setConfigOption } from './configuration'
|
||||
|
||||
interface Theme {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { invoke } from '@tauri-apps/api'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { listen } from '@tauri-apps/api/event'
|
||||
|
||||
interface UnzipPayload {
|
||||
|
||||
Reference in New Issue
Block a user