From 996a7cc03eaadbd84fe8377eb8e3b6c402e72528 Mon Sep 17 00:00:00 2001 From: claude-bot Date: Wed, 15 Jul 2026 23:21:46 +0900 Subject: [PATCH] =?UTF-8?q?feat(installer):=20v0.4.0=20=E2=80=94=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=EC=A0=9C=EA=B1=B0=EA=B8=B0,=20=EC=BB=A4?= =?UTF-8?q?=EC=8A=A4=ED=85=80=20=ED=8F=B4=EB=8D=94=EB=AA=85,=20=ED=8F=AC?= =?UTF-8?q?=ED=8A=B8=ED=8F=AC=EC=9B=8C=EB=94=A9=20=EA=B0=9C=ED=8E=B8,=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84/=EA=B0=9C=EB=B0=9C=EC=9E=90=EC=9A=A9=20?= =?UTF-8?q?=ED=91=9C=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 음악퀴즈 파일제거 도구 신규 추가: 동의 → 휴지통/완전삭제 선택 → 커스텀 폴더 (현재값 + 기본 .mc_custom) 전체, 데스크톱 바로가기, gameDir 가 해당 폴더인 마인크래프트 런처 프로필 정리. - MC_CUSTOM_DIR .env 로 커스텀 게임 폴더 이름 유동화(.mc_custom 기본). 렌더러 사전에도 실제 폴더명 반영. - 간편포트포워딩: 실행 중 UPnP 매핑 유지, 창 닫힘/종료 시 자동 제거(activePort 추적). - 개발자용 빌드는 창/헤더 제목 앞에 (개발자용) 표기, exe 이름에도 반영. - exe 이름 변경: 음악퀴즈 간편설치기 / 음악퀴즈 리소스팩설치기 / 간편포트포워딩. - README 및 .env 템플릿 갱신, 버전 0.3.23 → 0.4.0. Co-Authored-By: Claude Opus 4.7 --- .env.build.example | 8 + .env.example | 6 + README.md | 39 ++++- electron-builder-dev.yml | 4 +- electron-builder-pf.yml | 4 +- electron-builder-rp-dev.yml | 4 +- electron-builder-rp.yml | 4 +- electron-builder-uninstall.yml | 38 +++++ electron-builder.yml | 4 +- installer-uninstall/index.html | 22 +++ installer-uninstall/renderer.js | 209 +++++++++++++++++++++++ locales/installer-uninstall/ko-kr.json | 63 +++++++ package.json | 6 +- src/installer-pf/main.ts | 31 ++++ src/installer-rp/main.ts | 22 ++- src/installer-uninstall/main.ts | 224 +++++++++++++++++++++++++ src/installer-uninstall/preload.ts | 43 +++++ src/installer/main.ts | 25 ++- src/shared/i18n.ts | 4 +- src/shared/paths.ts | 38 ++++- tsconfig.installer-uninstall.json | 4 + 21 files changed, 776 insertions(+), 26 deletions(-) create mode 100644 electron-builder-uninstall.yml create mode 100644 installer-uninstall/index.html create mode 100644 installer-uninstall/renderer.js create mode 100644 locales/installer-uninstall/ko-kr.json create mode 100644 src/installer-uninstall/main.ts create mode 100644 src/installer-uninstall/preload.ts create mode 100644 tsconfig.installer-uninstall.json diff --git a/.env.build.example b/.env.build.example index e95183a..701b91d 100644 --- a/.env.build.example +++ b/.env.build.example @@ -31,6 +31,14 @@ SITE_BASE_URL=https://mq.example.com # 특별히 다른 경로를 쓰고 싶을 때만 아래를 풀어서 우선 적용시키세요. # MANIFEST_URL=https://mq.example.com/manifest.json +# ----- 커스텀 게임 폴더 이름 ----- + +# 음악퀴즈 전용 게임/캐시 폴더의 이름. %APPDATA% 바로 아래에 이 이름으로 생성됩니다. +# 비워두면 기본값 `.mc_custom` 을 사용합니다. 경로 구분자(/ \)와 `..` 는 무시됩니다. +# 설치기·리소스팩설치기·파일제거기가 모두 이 값을 공유하므로, 값을 바꾸면 +# 세 exe 를 같은 값으로 다시 빌드해야 서로 같은 폴더를 가리킵니다. +# MC_CUSTOM_DIR=.mc_custom + # ----- 리소스팩 설치기 ----- # yt-dlp 동시 다운로드 수(1~8). 비워두면 CPU 코어 수로 자동 결정. diff --git a/.env.example b/.env.example index 3d92e1f..e6be7c6 100644 --- a/.env.example +++ b/.env.example @@ -27,6 +27,12 @@ SITE_BASE_URL=http://127.0.0.1:3000 # 특별히 다른 경로를 쓰고 싶을 때만 아래를 풀어서 우선 적용시키세요. # MANIFEST_URL=http://127.0.0.1:3000/manifest.json +# ----- 커스텀 게임 폴더 이름 ----- + +# 음악퀴즈 전용 게임/캐시 폴더의 이름. %APPDATA% 바로 아래에 이 이름으로 생성됩니다. +# 비워두면 기본값 `.mc_custom` 을 사용합니다. 경로 구분자(/ \)와 `..` 는 무시됩니다. +# MC_CUSTOM_DIR=.mc_custom + # ----- 리소스팩 설치기 ----- # yt-dlp 동시 다운로드 수(1~8). 비워두면 CPU 코어 수로 자동 결정. diff --git a/README.md b/README.md index 528998a..70cdca7 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ - **관리 사이트** — 음악퀴즈 정보(JSON)와 음악·사진 목록, 데이터팩 출력을 한 곳에서 운영. - **음악퀴즈 간편설치기 (`.exe`)** — `manifest.json` 기반으로 사용자가 마인크래프트 본체·서버·모드를 자동 설치. - **리소스팩 간편설치기 (`.exe`)** — 음악퀴즈 음악·표지를 yt-dlp 로 받아 painting variant 텍스처 리소스팩으로 패키징. +- **간편포트포워딩 (`.exe`)** — 원하는 포트를 입력해 UPnP 로 개방. 프로그램을 켜 두는 동안만 열려 있고 창을 닫으면 자동으로 닫힙니다. +- **음악퀴즈 파일제거 (`.exe`)** — 설치기들이 만든 게임 폴더·캐시와 런처 프로필을 휴지통 이동 또는 완전 삭제로 한 번에 정리. --- @@ -15,7 +17,9 @@ | `src/server/` | 음악퀴즈 관리 웹사이트 (Express + EJS) | `bun start` 또는 `npm start` | | `src/installer/` | 음악퀴즈 간편설치기 (Electron) | `npm run installer` | | `src/installer-rp/` | 리소스팩 간편설치기 (Electron) | `npm run installer:rp` | -| `src/shared/` | 두 설치기와 서버가 공유하는 타입·스토어 | — | +| `src/installer-pf/` | 간편포트포워딩 도구 (Electron) | `npm run installer:pf` | +| `src/installer-uninstall/` | 음악퀴즈 파일제거 도구 (Electron) | `npm run installer:uninstall` | +| `src/shared/` | 설치기들과 서버가 공유하는 타입·스토어 | — | | `views/` | EJS 템플릿 (관리 사이트) | — | | `manifest/` | 음악퀴즈별 정의 JSON | — | | `file/list/` | 음악퀴즈별 음악·사진 목록 JSON | — | @@ -43,6 +47,8 @@ 이렇게 분리해 두면 사용자가 평소 쓰던 마인크래프트와 음악퀴즈 설정이 섞이지 않고, 음악퀴즈만 삭제해도 본체에는 영향이 없습니다. +> **폴더 이름 바꾸기.** 기본값은 `.mc_custom` 이지만 `.env` / `.env.build` 의 `MC_CUSTOM_DIR` 로 다른 이름을 지정할 수 있습니다. 설치기·리소스팩설치기·파일제거기가 모두 이 값을 공유하므로, 값을 바꾸면 세 exe 를 같은 값으로 다시 빌드해야 서로 같은 폴더를 가리킵니다. (경로 구분자 `/ \` 와 `..` 는 무시되어 항상 `%APPDATA%` 바로 아래 단일 폴더가 됩니다.) + --- ## 빠른 시작 @@ -65,8 +71,17 @@ npm run installer # 3) 리소스팩 간편설치기를 Electron 으로 실행해 보기 npm run installer:rp -# 4) 음악퀴즈 간편설치기 윈도우 .exe 빌드 -npm run dist:win +# 4) 간편포트포워딩 / 파일제거 도구 실행해 보기 +npm run installer:pf +npm run installer:uninstall + +# 5) 윈도우 .exe 빌드 (개별) +npm run dist:win # 음악퀴즈 간편설치기 +npm run dist:win:rp # 음악퀴즈 리소스팩설치기 +npm run dist:win:pf # 간편포트포워딩 +npm run dist:win:uninstall # 음악퀴즈 파일제거 +npm run dist:win:dev # (개발자용) 음악퀴즈 간편설치기 +npm run dist:win:rp:dev # (개발자용) 음악퀴즈 리소스팩설치기 ``` 리소스팩 설치기는 `yt-dlp` 가 필요합니다. 자동 다운로드되지만, 막혀 있는 환경이라면 [`docs/yt-dlp-setup.md`](docs/yt-dlp-setup.md) 참고. @@ -155,9 +170,13 @@ minecraft_launcher/ │ ├─ server/ Express + EJS 관리 사이트 │ ├─ installer/ 음악퀴즈 간편설치기 (Electron 메인 + preload) │ ├─ installer-rp/ 리소스팩 간편설치기 (Electron 메인 + 음악/이미지 파이프라인) +│ ├─ installer-pf/ 간편포트포워딩 도구 (Electron 메인 + preload) +│ ├─ installer-uninstall/ 음악퀴즈 파일제거 도구 (Electron 메인 + preload) │ └─ shared/ 공용 타입, 매니페스트 스토어, mojang/upnp 유틸 ├─ installer/ 음악퀴즈 설치기 렌더러(HTML/CSS/JS) ├─ installer-rp/ 리소스팩 설치기 렌더러(HTML/CSS/JS) +├─ installer-pf/ 간편포트포워딩 렌더러(HTML/JS) +├─ installer-uninstall/ 파일제거 렌더러(HTML/JS) ├─ views/ 관리 사이트 EJS 템플릿 ├─ public/ 관리 사이트 정적 파일(styles.css 등) ├─ manifest/ 음악퀴즈 JSON 정의 (운영자가 편집) @@ -172,18 +191,24 @@ minecraft_launcher/ ├─ manifest.json 사이트 루트 매니페스트 (자동 관리) ├─ account.json 관리자 계정 (절대 외부 노출 금지) ├─ package.json -└─ tsconfig.{,server,installer,installer-rp}.json +└─ tsconfig.{,server,installer,installer-rp,installer-pf,installer-uninstall}.json ``` --- ## 빌드 산출물 / 배포 -| 산출물 | 빌드 명령 | 비고 | +| 산출물(파일명) | 빌드 명령 | 비고 | | --- | --- | --- | | 관리 사이트 (Node 실행) | `npm start` | systemd 등으로 띄우기. 외부 도메인이 manifest 의 base URL 이 됩니다. | -| 음악퀴즈 간편설치기 `.exe` | `npm run dist:win` | `electron-builder.yml` 설정 사용. | -| 리소스팩 간편설치기 `.exe` | `tsconfig.installer-rp.json` 빌드 후 `electron-builder` 수동 패키징 | | +| `음악퀴즈 간편설치기-<버전>.exe` | `npm run dist:win` | `electron-builder.yml`. | +| `음악퀴즈 리소스팩설치기-<버전>.exe` | `npm run dist:win:rp` | `electron-builder-rp.yml`. | +| `간편포트포워딩-<버전>.exe` | `npm run dist:win:pf` | `electron-builder-pf.yml`. | +| `음악퀴즈 파일제거-<버전>.exe` | `npm run dist:win:uninstall` | `electron-builder-uninstall.yml`. | +| `(개발자용) 음악퀴즈 간편설치기-<버전>.exe` | `npm run dist:win:dev` | 비공개(public=false) 팩만 노출. 제목 앞에 `(개발자용)` 표시. | +| `(개발자용) 음악퀴즈 리소스팩설치기-<버전>.exe` | `npm run dist:win:rp:dev` | 상동. | + +빌드 결과물은 `release/` 폴더에 생성됩니다(포터블 exe). --- diff --git a/electron-builder-dev.yml b/electron-builder-dev.yml index 844c159..dc1910b 100644 --- a/electron-builder-dev.yml +++ b/electron-builder-dev.yml @@ -29,7 +29,7 @@ extraResources: - "**/*" win: target: portable - artifactName: MusicQuizInstaller-Dev-${version}-Portable.${ext} + artifactName: (개발자용) 음악퀴즈 간편설치기-${version}.${ext} icon: build/icon.ico portable: - artifactName: MusicQuizInstaller-Dev-${version}-Portable.${ext} + artifactName: (개발자용) 음악퀴즈 간편설치기-${version}.${ext} diff --git a/electron-builder-pf.yml b/electron-builder-pf.yml index e7856c2..eb0d97c 100644 --- a/electron-builder-pf.yml +++ b/electron-builder-pf.yml @@ -27,7 +27,7 @@ extraResources: - "**/*" win: target: portable - artifactName: 마인크래프트간편포트포워딩-${version}-Portable.${ext} + artifactName: 간편포트포워딩-${version}.${ext} icon: build/icon.ico portable: - artifactName: 마인크래프트간편포트포워딩-${version}-Portable.${ext} + artifactName: 간편포트포워딩-${version}.${ext} diff --git a/electron-builder-rp-dev.yml b/electron-builder-rp-dev.yml index f39fefd..6e10cd7 100644 --- a/electron-builder-rp-dev.yml +++ b/electron-builder-rp-dev.yml @@ -29,7 +29,7 @@ extraResources: - "**/*" win: target: portable - artifactName: MusicQuizResourcepackInstaller-Dev-${version}-Portable.${ext} + artifactName: (개발자용) 음악퀴즈 리소스팩설치기-${version}.${ext} icon: build/icon.ico portable: - artifactName: MusicQuizResourcepackInstaller-Dev-${version}-Portable.${ext} + artifactName: (개발자용) 음악퀴즈 리소스팩설치기-${version}.${ext} diff --git a/electron-builder-rp.yml b/electron-builder-rp.yml index 0e3da7d..75abef2 100644 --- a/electron-builder-rp.yml +++ b/electron-builder-rp.yml @@ -35,7 +35,7 @@ extraResources: - "**/*" win: target: portable - artifactName: ${productName}-${version}-Portable.${ext} + artifactName: 음악퀴즈 리소스팩설치기-${version}.${ext} icon: build/icon.ico portable: - artifactName: ${productName}-${version}-Portable.${ext} + artifactName: 음악퀴즈 리소스팩설치기-${version}.${ext} diff --git a/electron-builder-uninstall.yml b/electron-builder-uninstall.yml new file mode 100644 index 0000000..bd5bcb6 --- /dev/null +++ b/electron-builder-uninstall.yml @@ -0,0 +1,38 @@ +appId: kr.tkrmagid.musicquiz.uninstall +productName: 음악퀴즈 파일제거 +# 루트 package.json 의 "main" 은 메인 설치기를 가리키므로, 패키지된 앱이 +# 파일제거 도구를 진입점으로 쓰도록 빌드 시 main 을 덮어쓴다. +extraMetadata: + main: dist/installer-uninstall/main.js +directories: + output: release + buildResources: build +files: + - dist/installer-uninstall/** + - dist/shared/** + - installer-uninstall/** + # index.html 은 메인 설치기와 동일한 styles.css 를 공유함 + # (``). 그 한 파일만 명시적으로 포함. + - installer/styles.css + - build/icon.* + - package.json + # 이 도구는 sharp(이미지 처리)를 쓰지 않으므로 통째로 제외해 exe 크기를 줄인다. + - "!node_modules/sharp/**" + - "!node_modules/@img/**" +# MC_CUSTOM_DIR 을 커스텀으로 빌드했다면 파일제거기도 같은 폴더를 가리켜야 하므로 +# `.env.build` 를 함께 배포한다. i18n 사전(locales/installer-uninstall/ko-kr.json)도 함께. +extraResources: + - from: . + to: . + filter: + - .env.build + - from: locales + to: locales + filter: + - "**/*" +win: + target: portable + artifactName: 음악퀴즈 파일제거-${version}.${ext} + icon: build/icon.ico +portable: + artifactName: 음악퀴즈 파일제거-${version}.${ext} diff --git a/electron-builder.yml b/electron-builder.yml index 47135ac..58acbf6 100644 --- a/electron-builder.yml +++ b/electron-builder.yml @@ -32,7 +32,7 @@ extraResources: - "**/*" win: target: portable - artifactName: ${productName}-${version}-Portable.${ext} + artifactName: 음악퀴즈 간편설치기-${version}.${ext} icon: build/icon.ico portable: - artifactName: ${productName}-${version}-Portable.${ext} + artifactName: 음악퀴즈 간편설치기-${version}.${ext} diff --git a/installer-uninstall/index.html b/installer-uninstall/index.html new file mode 100644 index 0000000..3484b9f --- /dev/null +++ b/installer-uninstall/index.html @@ -0,0 +1,22 @@ + + + + + 음악퀴즈 파일제거 + + + +
+

음악퀴즈 파일제거

+
+ +
+ + + + + + diff --git a/installer-uninstall/renderer.js b/installer-uninstall/renderer.js new file mode 100644 index 0000000..d4f129f --- /dev/null +++ b/installer-uninstall/renderer.js @@ -0,0 +1,209 @@ +'use strict' + +const api = window.uninstaller + +let I18N = {} + +function tt(key, params) { + var parts = String(key).split('.') + var cur = I18N + for (var i = 0; i < parts.length; i++) { + if (cur && typeof cur === 'object' && parts[i] in cur) { + cur = cur[parts[i]] + } else { + return key + } + } + if (typeof cur !== 'string') return key + if (!params) return cur + return cur.replace(/\{\{\s*(\w+)\s*\}\}/g, function (_m, name) { + return name in params ? String(params[name]) : '{{' + name + '}}' + }) +} + +function escapeHtml(s) { + return String(s).replace(/[&<>"']/g, function (c) { + return c === '&' ? '&' : c === '<' ? '<' : c === '>' ? '>' : c === '"' ? '"' : ''' + }) +} + +const pageHost = document.getElementById('pageHost') +const logViewer = document.getElementById('logViewer') +const logBody = document.getElementById('logBody') +const logToggle = document.getElementById('logToggle') + +logToggle.addEventListener('click', function () { + logViewer.classList.toggle('collapsed') + if (logViewer.classList.contains('collapsed')) { + logViewer.style.height = '36px' + logToggle.textContent = tt('logViewer.expand') + } else { + logViewer.style.height = '' + logToggle.textContent = tt('logViewer.collapse') + } +}) + +api.onLog(function (line) { + logViewer.hidden = false + logBody.textContent += line + '\n' + logBody.scrollTop = logBody.scrollHeight +}) + +function applyStaticI18n() { + document.title = tt('app.title') + var h1 = document.querySelector('.appHeader h1') + if (h1) h1.textContent = tt('app.title') + var logH2 = logViewer.querySelector('header h2') + if (logH2) logH2.textContent = tt('logViewer.heading') + logToggle.textContent = tt('logViewer.collapse') +} + +// ── 1단계: 삭제 동의 ────────────────────────────── +function renderConfirm() { + pageHost.innerHTML = + '
' + + '

' + escapeHtml(tt('confirm.heading')) + '

' + + '

' + escapeHtml(tt('confirm.question')) + '

' + + '

' + escapeHtml(tt('confirm.detail')) + '

' + + '

' + + escapeHtml(tt('confirm.loadingPreview')) + '

' + + '
' + + ' ' + + ' ' + + '
' + + '
' + + var agreeBtn = document.getElementById('agreeBtn') + var cancelBtn = document.getElementById('cancelBtn') + var previewBox = document.getElementById('previewBox') + + cancelBtn.addEventListener('click', function () { api.quit() }) + + api.preview().then(function (p) { + var existingDirs = p.existingDirs || [] + var items = [] + if (existingDirs.length) { + for (var d = 0; d < existingDirs.length; d++) { + items.push(tt('confirm.itemCustomDir', { path: existingDirs[d] })) + } + } else { + var first = (p.allTargetDirs && p.allTargetDirs[0]) || '' + items.push(tt('confirm.itemCustomDirMissing', { path: first })) + } + if (p.shortcutExists) items.push(tt('confirm.itemShortcut')) + if (p.launcherProfiles && p.launcherProfiles.length) { + items.push(tt('confirm.itemProfiles', { names: p.launcherProfiles.join(', ') })) + } + var nothing = !existingDirs.length && !p.shortcutExists && (!p.launcherProfiles || !p.launcherProfiles.length) + var html = '

' + escapeHtml(tt('confirm.previewTitle')) + '

' + if (nothing) html += '

' + escapeHtml(tt('confirm.nothingFound')) + '

' + previewBox.innerHTML = html + agreeBtn.disabled = false + agreeBtn.addEventListener('click', function () { renderChoose(p) }) + }).catch(function (err) { + previewBox.innerHTML = '

' + + escapeHtml(tt('confirm.previewFail', { message: (err && err.message) || String(err) })) + '

' + agreeBtn.disabled = false + agreeBtn.addEventListener('click', function () { renderChoose({ existingDirs: [], allTargetDirs: [], shortcutExists: false, launcherProfiles: [] }) }) + }) +} + +// ── 2단계: 삭제 방식 선택 ───────────────────────── +function renderChoose(preview) { + pageHost.innerHTML = + '
' + + '

' + escapeHtml(tt('choose.heading')) + '

' + + '

' + escapeHtml(tt('choose.intro')) + '

' + + '
' + + ' ' + + ' ' + + '
' + + '
' + + ' ' + + '
' + + '
' + + '
' + + var trashBtn = document.getElementById('trashBtn') + var permBtn = document.getElementById('permBtn') + var backBtn = document.getElementById('backBtn') + var runState = document.getElementById('runState') + + backBtn.addEventListener('click', function () { renderConfirm() }) + + function runMode(mode) { + var warn = mode === 'permanent' ? tt('choose.confirmPermanent') : tt('choose.confirmTrash') + if (!window.confirm(warn)) return + trashBtn.disabled = true + permBtn.disabled = true + backBtn.disabled = true + runState.innerHTML = '

' + escapeHtml(tt('choose.running')) + '

' + api.run(mode).then(function (result) { + renderResult(result, mode) + }).catch(function (err) { + runState.innerHTML = '

' + + escapeHtml(tt('choose.error', { message: (err && err.message) || String(err) })) + '

' + trashBtn.disabled = false + permBtn.disabled = false + backBtn.disabled = false + }) + } + + trashBtn.addEventListener('click', function () { runMode('trash') }) + permBtn.addEventListener('click', function () { runMode('permanent') }) +} + +// ── 3단계: 결과 ────────────────────────────────── +function renderResult(result, mode) { + var total = (result.removed ? result.removed.length : 0) + (result.profilesRemoved ? result.profilesRemoved.length : 0) + var hasErr = result.errors && result.errors.length + var cls = hasErr ? 'error' : 'done' + var badge = hasErr ? tt('result.badgePartial') : tt('result.badgeOk') + + var lines = '' + if (result.removed && result.removed.length) { + lines += '

' + escapeHtml(tt('result.removedTitle')) + '

' + } + if (result.profilesRemoved && result.profilesRemoved.length) { + lines += '

' + escapeHtml(tt('result.profilesTitle')) + '

' + } + if (hasErr) { + lines += '

' + escapeHtml(tt('result.errorsTitle')) + '

' + } + if (total === 0 && !hasErr) { + lines += '

' + escapeHtml(tt('result.nothing')) + '

' + } + + pageHost.innerHTML = + '
' + + '
' + + '
' + escapeHtml(badge) + ' ' + + ' ' + escapeHtml(tt(mode === 'permanent' ? 'mode.permanent' : 'mode.trash')) + '
' + + lines + + '

' + escapeHtml(tt('result.note')) + '

' + + '
' + + '
' + + ' ' + + '
' + + '
' + + document.getElementById('quitBtn').addEventListener('click', function () { api.quit() }) +} + +;(async function () { + try { I18N = (await api.loadLocale()) || {} } catch (_) { I18N = {} } + applyStaticI18n() + renderConfirm() +})() diff --git a/locales/installer-uninstall/ko-kr.json b/locales/installer-uninstall/ko-kr.json new file mode 100644 index 0000000..a9bf50c --- /dev/null +++ b/locales/installer-uninstall/ko-kr.json @@ -0,0 +1,63 @@ +{ + "app": { + "title": "음악퀴즈 파일제거" + }, + "logViewer": { + "heading": "로그", + "collapse": "접기", + "expand": "펼치기" + }, + "mode": { + "trash": "휴지통으로 이동", + "permanent": "컴퓨터에서 완전 삭제" + }, + "confirm": { + "heading": "음악퀴즈 파일제거", + "question": "음악퀴즈 간편설치기로 설치한 내용들과, 음악퀴즈 관련된 내용을 전부 삭제하시겠습니까?", + "detail": "음악퀴즈 간편설치기·리소스팩설치기가 만든 게임 폴더와 캐시, 마인크래프트 런처의 음악퀴즈 프로필을 정리합니다. 평소 쓰던 .minecraft 본체는 건드리지 않습니다.", + "loadingPreview": "삭제 대상을 확인하는 중…", + "previewTitle": "삭제 대상", + "itemCustomDir": "음악퀴즈 전용 폴더: {{path}}", + "itemCustomDirMissing": "음악퀴즈 전용 폴더가 없음(이미 삭제됨): {{path}}", + "itemShortcut": "바탕화면의 'MusicQuiz Server' 바로가기", + "itemProfiles": "마인크래프트 런처 프로필: {{names}}", + "nothingFound": "삭제할 음악퀴즈 관련 항목을 찾지 못했습니다. 이미 정리된 상태일 수 있습니다.", + "previewFail": "삭제 대상 확인 실패: {{message}}", + "agreeBtn": "동의하고 계속", + "cancelBtn": "취소(종료)" + }, + "choose": { + "heading": "삭제 방식 선택", + "intro": "삭제 방식을 선택하세요.", + "trashTitle": "휴지통으로 이동", + "trashDesc": "휴지통으로 옮깁니다. 실수했을 때 되돌릴 수 있습니다.", + "permTitle": "컴퓨터에서 완전 삭제", + "permDesc": "휴지통을 거치지 않고 즉시 완전히 지웁니다. 되돌릴 수 없습니다.", + "backBtn": "뒤로", + "confirmTrash": "선택한 음악퀴즈 관련 항목을 휴지통으로 이동합니다. 계속하시겠습니까?", + "confirmPermanent": "선택한 음악퀴즈 관련 항목을 컴퓨터에서 완전히 삭제합니다. 되돌릴 수 없습니다. 계속하시겠습니까?", + "running": "삭제하는 중…", + "error": "삭제 중 오류: {{message}}" + }, + "result": { + "badgeOk": "완료", + "badgePartial": "일부 실패", + "removedTitle": "삭제한 항목", + "profilesTitle": "제거한 런처 프로필", + "errorsTitle": "삭제하지 못한 항목", + "nothing": "삭제할 항목이 없었습니다.", + "note": "직접 지정한 위치에 서버를 설치했다면 그 폴더는 위치를 알 수 없어 자동 삭제되지 않습니다. 필요하면 직접 삭제하세요.", + "quitBtn": "종료" + }, + "log": { + "start": "삭제 시작 ({{mode}})", + "removedDir": "폴더 제거: {{path}}", + "removedShortcut": "바로가기 제거: {{path}}", + "removedProfile": "런처 프로필 제거: {{name}}", + "removeFail": "제거 실패: {{path}} — {{message}}", + "customDirMissing": "음악퀴즈 폴더가 이미 없음: {{path}}", + "launcherParseFail": "launcher_profiles.json 을 읽지 못함: {{path}}", + "launcherWriteFail": "launcher_profiles.json 갱신 실패: {{message}}", + "done": "정리 완료 — 총 {{count}}개 항목 처리" + } +} diff --git a/package.json b/package.json index 468bb09..9b526d9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minecraft-music-quiz-installer", - "version": "0.3.23", + "version": "0.4.0", "description": "마인크래프트 음악퀴즈 간편설치기 + 관리 사이트", "main": "dist/installer/main.js", "scripts": { @@ -10,13 +10,15 @@ "installer": "tsc -p tsconfig.installer.json && electron .", "installer:rp": "tsc -p tsconfig.installer-rp.json && electron dist/installer-rp/main.js", "installer:pf": "tsc -p tsconfig.installer-pf.json && electron dist/installer-pf/main.js", + "installer:uninstall": "tsc -p tsconfig.installer-uninstall.json && electron dist/installer-uninstall/main.js", "preinstall:sharp-win32": "npm install --no-save --force @img/sharp-win32-x64@0.34.5", "build:launcher-icon": "node scripts/build-launcher-icon.cjs", "dist:win": "npm run preinstall:sharp-win32 && npm run build:launcher-icon && tsc -p tsconfig.installer.json && electron-builder --win --config electron-builder.yml", "dist:win:rp": "npm run preinstall:sharp-win32 && tsc -p tsconfig.installer-rp.json && electron-builder --win --config electron-builder-rp.yml", "dist:win:pf": "tsc -p tsconfig.installer-pf.json && electron-builder --win --config electron-builder-pf.yml", "dist:win:dev": "npm run preinstall:sharp-win32 && npm run build:launcher-icon && tsc -p tsconfig.installer.json && electron-builder --win --config electron-builder-dev.yml", - "dist:win:rp:dev": "npm run preinstall:sharp-win32 && tsc -p tsconfig.installer-rp.json && electron-builder --win --config electron-builder-rp-dev.yml" + "dist:win:rp:dev": "npm run preinstall:sharp-win32 && tsc -p tsconfig.installer-rp.json && electron-builder --win --config electron-builder-rp-dev.yml", + "dist:win:uninstall": "tsc -p tsconfig.installer-uninstall.json && electron-builder --win --config electron-builder-uninstall.yml" }, "dependencies": { "@types/archiver": "^7.0.0", diff --git a/src/installer-pf/main.ts b/src/installer-pf/main.ts index 36df5ee..19cf0c6 100644 --- a/src/installer-pf/main.ts +++ b/src/installer-pf/main.ts @@ -16,6 +16,13 @@ const localeDict = i18n.dict let mainWindow: BrowserWindow | null = null +// 이 도구가 UPnP 로 직접 열어둔 포트. 앱이 살아 있는 동안 매핑을 유지하고, +// 창을 닫거나 종료할 때 이 포트의 매핑을 제거한다(사용자가 라우터에 직접 만든 +// 영구 규칙으로 이미 열려 있던 preForwarded 포트는 우리 것이 아니므로 추적하지 않음). +let activePort: number | null = null +// before-quit 재진입 가드. 매핑 정리를 마친 뒤에만 실제 종료로 넘어가게 한다. +let cleanupDone = false + function createMainWindow(): void { const iconPath = path.join(__dirname, '..', '..', 'build', process.platform === 'win32' ? 'icon.ico' : 'icon.png') mainWindow = new BrowserWindow({ @@ -355,6 +362,13 @@ ipcMain.handle('pf:open', async (_event, portInput: number): Promise => { const port = Number.isFinite(portInput) && portInput > 0 && portInput < 65536 ? Math.floor(portInput) : 25565 sendLog(t('log.closeTry', { port })) await removeUpnpMapping(port) + if (activePort === port) activePort = null }) ipcMain.handle('pf:quit', async () => { @@ -432,6 +449,20 @@ app.whenReady().then(() => { }) }) +// 창을 닫거나 종료할 때, 이 도구가 열어둔 UPnP 매핑을 제거한 뒤 실제 종료로 넘어간다. +// removeUpnpMapping 은 비동기라 before-quit 을 한 번 막고(cleanup) 끝나면 다시 quit 한다. +app.on('before-quit', (event) => { + if (cleanupDone || activePort === null) return + event.preventDefault() + const port = activePort + activePort = null + sendLog(t('log.closeTry', { port })) + void removeUpnpMapping(port).finally(() => { + cleanupDone = true + app.quit() + }) +}) + app.on('window-all-closed', () => { app.quit() }) diff --git a/src/installer-rp/main.ts b/src/installer-rp/main.ts index e307bed..f4ed91a 100644 --- a/src/installer-rp/main.ts +++ b/src/installer-rp/main.ts @@ -9,7 +9,7 @@ import { URL } from 'node:url' import type { ChildProcess } from 'node:child_process' import type { Manifest, PackDefinition, PackList } from '../shared/types.js' import { normalizePackDefinition } from '../shared/store.js' -import { getAppDataDir, getMcCustomDir } from '../shared/paths.js' +import { getAppDataDir, getMcCustomDir, withCustomDirName } from '../shared/paths.js' import { loadEnv, getManifestUrl } from '../shared/env.js' import { loadComponentI18n } from '../shared/i18n.js' import { resolveAudience, isPackVisibleForAudience, type Audience } from '../shared/audience.js' @@ -273,7 +273,25 @@ ipcMain.handle('rp:packs:select', async (_event, packKey: string) => { sendLog(t('log.selectedPack', { key: packKey })) }) -ipcMain.handle('rp:i18n:dict', () => localeDict) +// 개발자용 빌드(musicQuizAudience=developer)면 렌더러에 넘기는 사전의 제목 앞에 +// "(개발자용) " 을 붙여, 창 제목/헤더에 개발자용임을 표시한다. +function dictForRenderer(): Record { + // 커스텀 폴더명을 UI 문구에 반영. + const base = withCustomDirName(localeDict) + if (getAudience() !== 'developer') return base + const prefix = '(개발자용) ' + const appBlock = (base.app ?? {}) as Record + const title = appBlock.title + return { + ...base, + app: { + ...appBlock, + title: typeof title === 'string' && !title.startsWith(prefix) ? prefix + title : title + } + } +} + +ipcMain.handle('rp:i18n:dict', () => dictForRenderer()) // ── IPC: 약관 다운로드 ────────────────────────────── // v0.3.4~ : 사이트에서 임의 kind 가 만들어질 수 있으니 5종 화이트리스트 대신 diff --git a/src/installer-uninstall/main.ts b/src/installer-uninstall/main.ts new file mode 100644 index 0000000..4bffc4c --- /dev/null +++ b/src/installer-uninstall/main.ts @@ -0,0 +1,224 @@ +import { app, BrowserWindow, ipcMain, shell } from 'electron' +import path from 'node:path' +import fs from 'node:fs' +import fsp from 'node:fs/promises' +import { loadEnv } from '../shared/env.js' +import { getAppDataDir, getMcCustomDir } from '../shared/paths.js' +import { loadComponentI18n } from '../shared/i18n.js' + +// 음악퀴즈 파일제거 도구. 음악퀴즈 간편설치기 / 리소스팩설치기가 만든 데이터를 +// 한 번에 정리한다. (설치기 exe 자체는 사용자가 임의 위치에 둔 포터블이라 +// 위치를 알 수 없어 삭제 대상에서 제외) +loadEnv() + +const i18n = loadComponentI18n('installer-uninstall') +const t = i18n.t +const localeDict = i18n.dict + +let mainWindow: BrowserWindow | null = null + +function createMainWindow(): void { + const iconPath = path.join(__dirname, '..', '..', 'build', process.platform === 'win32' ? 'icon.ico' : 'icon.png') + mainWindow = new BrowserWindow({ + width: 720, + height: 620, + icon: iconPath, + webPreferences: { + preload: path.join(__dirname, 'preload.js'), + contextIsolation: true, + nodeIntegration: false + } + }) + mainWindow.removeMenu() + void mainWindow.loadFile(path.join(__dirname, '..', '..', 'installer-uninstall', 'index.html')) +} + +function sendLog(line: string): void { + if (!mainWindow || mainWindow.isDestroyed()) return + const stamped = `[${new Date().toLocaleTimeString('ko-KR', { hour12: false })}] ${line}` + mainWindow.webContents.send('log', stamped) +} + +/** 마인크래프트 런처 프로필 파일 경로. */ +function launcherProfilesPath(): string { + return path.join(getAppDataDir(), '.minecraft', 'launcher_profiles.json') +} + +/** 데스크톱에 설치기가 만든 서버 실행 바로가기 경로. */ +function serverShortcutPath(): string { + return path.join(app.getPath('desktop'), 'MusicQuiz Server.lnk') +} + +/** 기본 폴더 이름(.mc_custom) 경로. MC_CUSTOM_DIR 을 바꿔 빌드해도, 예전 기본 폴더가 남아 있을 수 있으므로 함께 지운다. */ +function defaultCustomDir(): string { + return path.join(getAppDataDir(), '.mc_custom') +} + +/** 삭제 대상 커스텀 폴더 후보(현재 설정값 + 기본 .mc_custom)를 대소문자 무시로 중복 제거. */ +function targetCustomDirs(): string[] { + const seen = new Set() + const out: string[] = [] + for (const dir of [getMcCustomDir(), defaultCustomDir()]) { + const key = path.resolve(dir).toLowerCase() + if (!seen.has(key)) { + seen.add(key) + out.push(dir) + } + } + return out +} + +/** 두 경로가 같은 폴더거나, a 가 b 하위인지(대소문자 무시 — Windows 파일계). */ +function isSameOrInside(child: string, parent: string): boolean { + const c = path.resolve(child).replace(/[\\/]+$/, '').toLowerCase() + const p = path.resolve(parent).replace(/[\\/]+$/, '').toLowerCase() + return c === p || c.startsWith(p + path.sep.toLowerCase()) || c.startsWith(p + '/') +} + +interface UninstallPreview { + existingDirs: string[] + allTargetDirs: string[] + shortcutExists: boolean + launcherProfiles: string[] +} + +/** 삭제 전 미리보기: 실제로 존재하는 대상만 추려 렌더러에 보여준다. */ +ipcMain.handle('uninstall:preview', async (): Promise => { + const allTargetDirs = targetCustomDirs() + const existingDirs = allTargetDirs.filter((d) => fs.existsSync(d)) + const shortcutExists = fs.existsSync(serverShortcutPath()) + const launcherProfiles = findMusicQuizProfiles(allTargetDirs) + return { existingDirs, allTargetDirs, shortcutExists, launcherProfiles } +}) + +/** launcher_profiles.json 에서 gameDir 가 커스텀 폴더(또는 그 하위)인 프로필 이름 목록. */ +function findMusicQuizProfiles(customDirs: string[]): string[] { + const file = launcherProfilesPath() + if (!fs.existsSync(file)) return [] + try { + const json = JSON.parse(fs.readFileSync(file, 'utf8')) as { + profiles?: Record + } + const profiles = json.profiles ?? {} + const names: string[] = [] + for (const [key, prof] of Object.entries(profiles)) { + const gameDir = typeof prof?.gameDir === 'string' ? prof.gameDir : '' + if (gameDir && customDirs.some((d) => isSameOrInside(gameDir, d))) { + names.push(typeof prof?.name === 'string' && prof.name ? prof.name : key) + } + } + return names + } catch { + return [] + } +} + +interface UninstallResult { + removed: string[] + profilesRemoved: string[] + errors: string[] +} + +/** 하나의 파일/폴더를 mode 에 따라 휴지통 이동 또는 완전 삭제. */ +async function removeOne(target: string, mode: 'trash' | 'permanent'): Promise { + if (mode === 'trash') { + await shell.trashItem(target) + } else { + await fsp.rm(target, { recursive: true, force: true }) + } +} + +/** launcher_profiles.json 에서 음악퀴즈 프로필만 제거하고 나머지는 보존. */ +async function cleanLauncherProfiles(customDirs: string[]): Promise { + const file = launcherProfilesPath() + if (!fs.existsSync(file)) return [] + let json: { profiles?: Record } + try { + json = JSON.parse(await fsp.readFile(file, 'utf8')) + } catch { + sendLog(t('log.launcherParseFail', { path: file })) + return [] + } + const profiles = json.profiles ?? {} + const removed: string[] = [] + for (const [key, prof] of Object.entries(profiles)) { + const gameDir = typeof prof?.gameDir === 'string' ? prof.gameDir : '' + if (gameDir && customDirs.some((d) => isSameOrInside(gameDir, d))) { + removed.push(typeof prof?.name === 'string' && prof.name ? prof.name : key) + delete profiles[key] + } + } + if (removed.length > 0) { + json.profiles = profiles + await fsp.writeFile(file, `${JSON.stringify(json, null, 2)}\n`, 'utf8') + } + return removed +} + +ipcMain.handle('uninstall:run', async (_event, modeInput: unknown): Promise => { + const mode: 'trash' | 'permanent' = modeInput === 'permanent' ? 'permanent' : 'trash' + const customDirs = targetCustomDirs() + const removed: string[] = [] + const errors: string[] = [] + + sendLog(t('log.start', { mode: t(mode === 'trash' ? 'mode.trash' : 'mode.permanent') })) + + // 1) 커스텀 게임/캐시 폴더 통째로(현재 설정값 + 기본 .mc_custom). + for (const customDir of customDirs) { + if (fs.existsSync(customDir)) { + try { + await removeOne(customDir, mode) + removed.push(customDir) + sendLog(t('log.removedDir', { path: customDir })) + } catch (err) { + const msg = (err as Error).message + errors.push(`${customDir}: ${msg}`) + sendLog(t('log.removeFail', { path: customDir, message: msg })) + } + } else { + sendLog(t('log.customDirMissing', { path: customDir })) + } + } + + // 2) 데스크톱 서버 실행 바로가기. + const shortcut = serverShortcutPath() + if (fs.existsSync(shortcut)) { + try { + await removeOne(shortcut, mode) + removed.push(shortcut) + sendLog(t('log.removedShortcut', { path: shortcut })) + } catch (err) { + const msg = (err as Error).message + errors.push(`${shortcut}: ${msg}`) + sendLog(t('log.removeFail', { path: shortcut, message: msg })) + } + } + + // 3) 마인크래프트 런처 프로필에서 음악퀴즈 설정 제거. + let profilesRemoved: string[] = [] + try { + profilesRemoved = await cleanLauncherProfiles(customDirs) + for (const name of profilesRemoved) sendLog(t('log.removedProfile', { name })) + } catch (err) { + const msg = (err as Error).message + errors.push(`launcher_profiles.json: ${msg}`) + sendLog(t('log.launcherWriteFail', { message: msg })) + } + + sendLog(t('log.done', { count: removed.length + profilesRemoved.length })) + return { removed, profilesRemoved, errors } +}) + +ipcMain.handle('uninstall:i18n:dict', () => localeDict) +ipcMain.handle('uninstall:quit', () => app.quit()) + +app.whenReady().then(() => { + createMainWindow() + app.on('activate', () => { + if (BrowserWindow.getAllWindows().length === 0) createMainWindow() + }) +}) + +app.on('window-all-closed', () => { + app.quit() +}) diff --git a/src/installer-uninstall/preload.ts b/src/installer-uninstall/preload.ts new file mode 100644 index 0000000..8a415ae --- /dev/null +++ b/src/installer-uninstall/preload.ts @@ -0,0 +1,43 @@ +import { contextBridge, ipcRenderer } from 'electron' + +interface UninstallPreview { + customDir: string + customDirExists: boolean + shortcutExists: boolean + launcherProfiles: string[] +} + +interface UninstallResult { + removed: string[] + profilesRemoved: string[] + errors: string[] +} + +const api = { + /** i18n 사전을 렌더러에 전달. */ + loadLocale: (): Promise> => ipcRenderer.invoke('uninstall:i18n:dict'), + + /** 삭제 전, 실제로 존재하는 대상 미리보기. */ + preview: (): Promise => ipcRenderer.invoke('uninstall:preview'), + + /** 삭제 실행. mode: 'trash'(휴지통) | 'permanent'(완전 삭제). */ + run: (mode: 'trash' | 'permanent'): Promise => ipcRenderer.invoke('uninstall:run', mode), + + /** 프로그램 종료. */ + quit: (): Promise => ipcRenderer.invoke('uninstall:quit'), + + /** 로그 스트림 구독. */ + onLog: (handler: (line: string) => void): (() => void) => { + const listener = (_event: unknown, line: string) => handler(line) + ipcRenderer.on('log', listener) + return () => ipcRenderer.removeListener('log', listener) + } +} + +contextBridge.exposeInMainWorld('uninstaller', api) + +declare global { + interface Window { + uninstaller: typeof api + } +} diff --git a/src/installer/main.ts b/src/installer/main.ts index 87a7ca3..c86d8b8 100644 --- a/src/installer/main.ts +++ b/src/installer/main.ts @@ -20,6 +20,7 @@ import type { } from './types.js' import type { Manifest, PackDefinition } from '../shared/types.js' import { normalizePackDefinition } from '../shared/store.js' +import { getMcCustomDirName, withCustomDirName } from '../shared/paths.js' import { loadEnv, getManifestUrl } from '../shared/env.js' import { loadComponentI18n } from '../shared/i18n.js' import { resolveAudience, isPackVisibleForAudience, type Audience } from '../shared/audience.js' @@ -1044,7 +1045,7 @@ function sleep(ms: number): Promise { ipcMain.handle('client:install', async (_event, payload: ClientInstallPayload) => { const pack = state.packs.get(payload.packKey) if (!pack) throw new Error(t('errors.packNotFound2')) - const customRoot = path.join(getAppDataDir(), '.mc_custom') + const customRoot = path.join(getAppDataDir(), getMcCustomDirName()) await fsp.mkdir(path.join(customRoot, 'mods'), { recursive: true }) await fsp.mkdir(path.join(customRoot, 'resourcepacks'), { recursive: true }) @@ -1587,7 +1588,27 @@ ipcMain.handle('finish:startLauncher', async () => { sendLog(t('log.launcherAllFail')) }) -ipcMain.handle('i18n:dict', () => localeDict) +// 개발자용 빌드(musicQuizAudience=developer)면 렌더러에 넘기는 사전의 제목 앞에 +// "(개발자용) " 을 붙여, 창 제목/헤더에 개발자용임을 표시한다. +function dictForRenderer(): Record { + // 커스텀 폴더명을 UI 문구에 반영. + const base = withCustomDirName(localeDict) + if (getAudience() !== 'developer') return base + const prefix = '(개발자용) ' + const appBlock = (base.app ?? {}) as Record + const withPrefix = (v: unknown): unknown => + typeof v === 'string' && !v.startsWith(prefix) ? prefix + v : v + return { + ...base, + app: { + ...appBlock, + browserTitle: withPrefix(appBlock.browserTitle), + headerTitle: withPrefix(appBlock.headerTitle) + } + } +} + +ipcMain.handle('i18n:dict', () => dictForRenderer()) ipcMain.handle('app:quit', () => { // 모든 창을 닫고 앱 종료. macOS에서도 종료(설치기는 한 번 쓰고 끝이니 잔류시키지 않음). diff --git a/src/shared/i18n.ts b/src/shared/i18n.ts index 132aed7..48def36 100644 --- a/src/shared/i18n.ts +++ b/src/shared/i18n.ts @@ -73,7 +73,9 @@ export function createI18n(filePath: string): I18n { * 1. 패키징된 Electron 앱이면 `process.resourcesPath/locales//ko-kr.json` * 2. `<프로젝트 루트>/locales//ko-kr.json` */ -export function loadComponentI18n(component: 'server' | 'installer' | 'installer-rp' | 'installer-pf'): I18n { +export function loadComponentI18n( + component: 'server' | 'installer' | 'installer-rp' | 'installer-pf' | 'installer-uninstall' +): I18n { // 컴파일된 dist/shared/i18n.js 기준으로 프로젝트 루트는 2단계 위. const projectRoot = path.resolve(__dirname, '..', '..') diff --git a/src/shared/paths.ts b/src/shared/paths.ts index d87091c..5f5607f 100644 --- a/src/shared/paths.ts +++ b/src/shared/paths.ts @@ -39,9 +39,43 @@ export function getAppDataDir(): string { return process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config') } -/** %appdata%/.mc_custom — 음악퀴즈 관련 외부 도구/캐시 보관 디렉터리. */ +/** + * 커스텀 게임 디렉터리의 폴더 이름. 기본은 `.mc_custom` 이지만 환경변수 + * `MC_CUSTOM_DIR` 로 다른 이름을 지정할 수 있다(.env / .env.build 로 주입). + * 경로 구분자·상위경로 이스케이프(`/`, `\`, `..`)는 제거해 항상 %appdata% + * 바로 아래 단일 폴더로 강제한다. + */ +export function getMcCustomDirName(): string { + const raw = (process.env.MC_CUSTOM_DIR ?? '').trim() + if (!raw) return '.mc_custom' + const sanitized = raw.replace(/[\\/]+/g, '').replace(/\.\.+/g, '.') + return sanitized || '.mc_custom' +} + +/** %appdata%/ — 음악퀴즈 관련 게임 폴더/외부 도구/캐시 보관 디렉터리. */ export function getMcCustomDir(): string { - return path.join(getAppDataDir(), '.mc_custom') + return path.join(getAppDataDir(), getMcCustomDirName()) +} + +/** + * 사전/문자열 구조 안의 리터럴 `.mc_custom` 을 실제 폴더 이름으로 치환한 깊은 + * 복사본을 돌려준다. 기본값(`.mc_custom`)이면 원본을 그대로 반환한다. 렌더러로 + * 넘기는 i18n 사전에 적용해 UI 안내 문구가 실제 폴더 이름과 어긋나지 않게 한다. + */ +export function withCustomDirName(value: T): T { + const name = getMcCustomDirName() + if (name === '.mc_custom') return value + const replace = (v: unknown): unknown => { + if (typeof v === 'string') return v.split('.mc_custom').join(name) + if (Array.isArray(v)) return v.map(replace) + if (v && typeof v === 'object') { + const out: Record = {} + for (const [k, val] of Object.entries(v as Record)) out[k] = replace(val) + return out + } + return v + } + return replace(value) as T } /** diff --git a/tsconfig.installer-uninstall.json b/tsconfig.installer-uninstall.json new file mode 100644 index 0000000..835da36 --- /dev/null +++ b/tsconfig.installer-uninstall.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "include": ["src/installer-uninstall/**/*.ts", "src/shared/**/*.ts"] +}