diff --git a/backend-golang/file.go b/backend-golang/file.go index 68f1f1d..7edb128 100644 --- a/backend-golang/file.go +++ b/backend-golang/file.go @@ -39,12 +39,9 @@ func (a *App) ReadJson(fileName string) (any, error) { return data, nil } -func (a *App) FileExists(fileName string) (bool, error) { +func (a *App) FileExists(fileName string) bool { _, err := os.Stat(fileName) - if err == nil { - return true, nil - } - return false, err + return err == nil } type FileInfo struct { diff --git a/frontend/src/_locales/zh-hans/main.json b/frontend/src/_locales/zh-hans/main.json index b708df6..94188cc 100644 --- a/frontend/src/_locales/zh-hans/main.json +++ b/frontend/src/_locales/zh-hans/main.json @@ -59,5 +59,6 @@ "Failed to switch model": "切换模型失败", "Start Converting": "开始转换", "Convert Success": "转换成功", - "Convert Failed": "转换失败" + "Convert Failed": "转换失败", + "Model Not Found": "模型不存在" } \ No newline at end of file diff --git a/frontend/src/pages/Configs.tsx b/frontend/src/pages/Configs.tsx index 8c2afdc..d5ff948 100644 --- a/frontend/src/pages/Configs.tsx +++ b/frontend/src/pages/Configs.tsx @@ -13,7 +13,7 @@ import {Page} from '../components/Page'; import {useNavigate} from 'react-router'; import {RunButton} from '../components/RunButton'; import {updateConfig} from '../apis'; -import {ConvertModel} from '../../wailsjs/go/backend_golang/App'; +import {ConvertModel, FileExists} from '../../wailsjs/go/backend_golang/App'; import manifest from '../../../manifest.json'; import {getStrategy, refreshLocalModels} from '../utils'; import {useTranslation} from 'react-i18next'; @@ -178,17 +178,21 @@ export const Configs: FC = observer(() => { }}/> }/> - { + { const modelPath = `${manifest.localModelDir}/${selectedConfig.modelParameters.modelName}`; - const strategy = getStrategy(selectedConfig); - const newModelPath = modelPath + '-' + strategy.replace(/[> *+]/g, '-'); - toast(t('Start Converting'), {autoClose: 1000, type: 'info'}); - ConvertModel(modelPath, strategy, newModelPath).then(() => { - toast(`${t('Convert Success')} - ${newModelPath}`, {type: 'success'}); - refreshLocalModels({models: commonStore.modelSourceList}); - }).catch(e => { - toast(`${t('Convert Failed')} - ${e}`, {type: 'error'}); - }); + if (await FileExists(modelPath)) { + const strategy = getStrategy(selectedConfig); + const newModelPath = modelPath + '-' + strategy.replace(/[> *+]/g, '-'); + toast(t('Start Converting'), {autoClose: 1000, type: 'info'}); + ConvertModel(modelPath, strategy, newModelPath).then(() => { + toast(`${t('Convert Success')} - ${newModelPath}`, {type: 'success'}); + refreshLocalModels({models: commonStore.modelSourceList}); + }).catch(e => { + toast(`${t('Convert Failed')} - ${e}`, {type: 'error'}); + }); + } else { + toast(`${t('Model Not Found')} - ${modelPath}`, {type: 'error'}); + } }}/> { + FileExists(path).then(exists => { + if (!exists) + DownloadFile(path, url); + }); + }); +} + +export function forceDownloadProgramFiles() { + manifest.programFiles.forEach(({url, path}) => { + DownloadFile(path, url); + }); } \ No newline at end of file diff --git a/manifest.json b/manifest.json index 316ba15..3cf8115 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "localModelDir": "models", "programFiles": [ { - "url": "https://cdn.jsdelivr.net/gh/josstorer/RWKV-Runner/cmd-helper.bat", + "url": "https://raw.githubusercontent.com/josStorer/RWKV-Runner/master/cmd-helper.bat", "path": "cmd-helper.bat" }, {