Skip to content

Commit 6c8fed4

Browse files
committed
feat: Open gameDir
1 parent 1ceaf89 commit 6c8fed4

File tree

2 files changed

+78
-14
lines changed

2 files changed

+78
-14
lines changed

smcl.py

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import webview
22
from subprocess import run as sp_run, PIPE, Popen, STARTUPINFO, STARTF_USESHOWWINDOW
33
import sys
4-
from os import path, remove, getcwd
4+
from os import path
5+
import os
56
import json
67
from webview import Window
78
from datetime import datetime
89
from locale import getdefaultlocale
910
PATH = path.dirname(path.abspath(__file__))
10-
CWD = getcwd()
11+
CWD = os.getcwd()
1112

1213
SRC_DIR = path.join(PATH, "src")
1314
GUI_MAIN = path.join(SRC_DIR, "main.html")
@@ -64,6 +65,25 @@ def cmcl_waiting(self, cmd):
6465
last_lines.pop(0)
6566

6667
return "".join(last_lines)
68+
def makedirs(self, path_list):
69+
dir_path = path.join(*path_list)
70+
self.log(f"Creating directory: {dir_path}")
71+
os.makedirs(dir_path, exist_ok=True)
72+
73+
def open_file(self, path_list):
74+
file_path = path.join(*path_list)
75+
self.log(f"Opening file: {file_path}")
76+
if not path.exists(file_path):
77+
return False
78+
79+
if os.name == "nt":
80+
os.startfile(file_path)
81+
elif os.name == "darwin":
82+
sp_run(["open", file_path])
83+
else:
84+
sp_run(["xdg-open", file_path])
85+
86+
return True
6787

6888
def set_title(self, title):
6989
self.log(f"New title: {title}")

src/main.html

+56-12
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
:players="players" :aoa="addOfflineAccount"
3333
:account="account"></player-list>
3434
<version-list v-else-if="ui === 'versionList'" :cur-ver="curVer"
35-
@install="installVersion"
36-
@close="changeUI('main')"
35+
@install="installVersion" @install-func="installFunc"
36+
@close="changeUI('main')" :game-dir="gameDir"
3737
:init="init"></version-list>
3838
<text-input v-else-if="ui === 'input'" @finish="input.resolveFunc" @close="goBack" :title="input.title"
3939
:desc="input.desc" :placeholder="input.placeholder"></text-input>
@@ -290,16 +290,40 @@
290290
{{ ver }}
291291
</div>
292292
<div class="float-right">
293-
<button class="btn btn-sm btn-danger" @click="deleteVersion(ver)">
294-
<i class="fa fa-trash"></i>
295-
</button>
293+
<div class="btn-group btn-group-sm" v-if="false">
294+
<button class="btn btn-info" @click="$emit('installFunc', 'forge', ver)">
295+
<i class="fa fa-cloud-download"></i>
296+
Forge
297+
</button>
298+
<button class="btn btn-info" @click="$emit('installFunc', 'fabric', ver)">
299+
<i class="fa fa-cloud-download"></i>
300+
Fabric
301+
</button>
302+
<button class="btn btn-info" @click="$emit('installFunc', 'optifine', ver)">
303+
<i class="fa fa-cloud-download"></i>
304+
OptiFine
305+
</button>
306+
<button class="btn btn-danger" @click="deleteVersion(ver)">
307+
<i class="fa fa-trash"></i>
308+
</button>
309+
</div>
296310
</div>
297311
</div>
298312
</transition-group>
299313
</div>
300314
</transition>
301315

302316
</div>
317+
<div class="btn-group btn-group-sm mt-2">
318+
<button class="btn btn-secondary" @click="openFolder('')">
319+
<i class="fa fa-folder-open"></i>
320+
{{ $t('gameFolder') }}
321+
</button>
322+
<button class="btn btn-secondary" @click="openFolder('saves')">
323+
<i class="fa fa-folder-open"></i>
324+
{{ $t('savesFolder') }}
325+
</button>
326+
</div>
303327
<button class="btn btn-info btn-block mt-2" @click="mode = 'install'">
304328
<i class="fa fa-download"></i>
305329
{{ $t('install') }}
@@ -349,7 +373,7 @@
349373
<script src="./vue-i18n.global.prod.js"></script>
350374
<script type="module">
351375
// TODO: Version
352-
const VERSION = "0.2.0";
376+
const VERSION = "0.3.0";
353377
const { createApp } = Vue;
354378
const { createI18n } = VueI18n;
355379
let api = null;
@@ -660,13 +684,16 @@
660684

661685
// TODO: VersionList
662686
const VersionList = {
663-
emits: ["close", "install"],
687+
emits: ["close", "install", "installFunc"],
664688
props: {
665689
curVer: {
666690
type: String
667691
},
668692
init: {
669693
type: Function
694+
},
695+
gameDir: {
696+
type: String
670697
}
671698
},
672699
components: {
@@ -744,6 +771,13 @@
744771
}
745772
await this.getVersions();
746773
}
774+
},
775+
async openFolder(path) {
776+
const exist = await api.open_file([this.gameDir, path]);
777+
if (!exist) {
778+
await api.makedirs([this.gameDir, path]);
779+
await api.open_file([this.gameDir, path]);
780+
}
747781
}
748782
},
749783
async mounted() {
@@ -763,7 +797,10 @@
763797
oldAlpha: "Old Alpha",
764798
oldBeta: "Old Beta",
765799
deleteConfirm: "Are you sure to delete this version?",
766-
deleteVersion: "Delete Version"
800+
deleteVersion: "Delete Version",
801+
gameFolder: "Game",
802+
savesFolder: "Saves",
803+
fix: "Fix"
767804
},
768805
zh: {
769806
loading: "正在获取已安装的版本...",
@@ -777,7 +814,10 @@
777814
oldAlpha: "远古 Alpha 版",
778815
oldBeta: "远古 Beta 版",
779816
deleteConfirm: "确定要删除这个版本吗?",
780-
deleteVersion: "删除版本"
817+
deleteVersion: "删除版本",
818+
gameFolder: "游戏",
819+
savesFolder: "地图",
820+
fix: "修复"
781821
}
782822
}
783823
}
@@ -811,6 +851,7 @@
811851
handleCmdResult: null,
812852
actionAfterLaunch: null,
813853
downloadSource: 0,
854+
gameDir: "",
814855
input: {
815856
title: "",
816857
desc: "",
@@ -833,9 +874,8 @@
833874
return res;
834875
},
835876

836-
// TODO: installVersion
837877
async installVersion(ver) {
838-
this.startLoading(this.$t("install"), this.$t("installing", { ver }), (result, loading) => {
878+
await this.startLoading(this.$t("install"), this.$t("installing", { ver }), (result, loading) => {
839879
const msg = result.replace(/\u0008/g, "").replace(/\(\d+%\)/g, "");
840880
console.log(msg);
841881
const reg = /\[(\d+)\/(\d+)\]/;
@@ -849,8 +889,11 @@
849889
}
850890
});
851891
const res = await api.cmcl_waiting(["install", ver]);
852-
this.finishLoading();
892+
await this.finishLoading();
853893
},
894+
895+
// TODO: Install xxx
896+
854897

855898
async addOfflineAccount() {
856899
const name = await this.requestInput(
@@ -973,6 +1016,7 @@
9731016
const curVer = this.curVer || this.$t("versionUnselected");
9741017
this.actionAfterLaunch = config.smclActionAfterLaunch;
9751018
this.downloadSource = config.downloadSource;
1019+
this.gameDir = config.gameDir;
9761020
await api.set_title(`SMCL ${VERSION} - Minecraft: ${curVer} - ${this.$t('player')}: ${playerName} - by xuanzhi33`);
9771021
}
9781022
},

0 commit comments

Comments
 (0)