Skip to content

Commit e788861

Browse files
Fixed [BUG] Canonical sync not work with options
Fixes #85 and [BUG] Adding a file to project option doesn't put it in romfs folder Fixes #84
1 parent 6d1fc06 commit e788861

6 files changed

Lines changed: 53 additions & 9 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"publisher": "TKVSC-Team",
55
"displayName": "TKVSC",
66
"description": "Canonically Amazing",
7-
"version": "0.0.2-beta.1",
7+
"version": "0.0.2-beta.2",
88
"repository": {
99
"type": "git",
1010
"url": "https://github.com/TKVSC-Team/totk-vscode"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "totk-vscode-python"
3-
version = "0.0.2b1"
3+
version = "0.0.2b2"
44
description = "Python scripts for TOTK VSCode extension"
55
requires-python = "~=3.12"
66
dependencies = [

src/canonicalSavePropagation.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ function pathMatchesBlacklistedFileSuffix(pathValue: string, fileSuffixes: strin
129129
return false;
130130
}
131131

132-
function inferActiveProjectRoot(
132+
function inferActiveModRoot(
133133
editedPath: string,
134134
roots: ProjectRootInfo[],
135135
): ProjectRootInfo | undefined {
@@ -148,7 +148,21 @@ function inferActiveProjectRoot(
148148
}
149149
}
150150

151-
return best?.root;
151+
if (!best) {
152+
return undefined;
153+
}
154+
155+
// Narrow down to the specific mod option if applicable
156+
const wsRoot = best.root.fsPath;
157+
const rel = path.relative(wsRoot, normalizedEditedPath);
158+
const parts = rel.split(path.sep);
159+
160+
if (parts.length >= 4 && parts[0]?.toLowerCase() === 'options') {
161+
const modRoot = path.join(wsRoot, 'options', parts[1]!, parts[2]!);
162+
return { ...best.root, fsPath: normalizePath(modRoot) };
163+
}
164+
165+
return best.root;
152166
}
153167

154168
async function ensureArchiveInProject(
@@ -202,7 +216,7 @@ export async function propagateCanonicalSave(
202216
return;
203217
}
204218

205-
const activeProjectRoot = inferActiveProjectRoot(
219+
const activeProjectRoot = inferActiveModRoot(
206220
options.writeInput.diskArchivePath,
207221
options.projectRoots,
208222
);

src/extension.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ import {
6464
setCanonicalIndexExtensionPath,
6565
} from './canonicalPathIndex';
6666
import { propagateCanonicalSave } from './canonicalSavePropagation';
67-
import { normalizePath, pathsEqual } from './projectPaths';
67+
import { getProjectModRoots, normalizePath, pathsEqual } from './projectPaths';
6868
import type { DiskWriteNotification } from './totkDiskFs';
6969
import { configureFilteringRules } from './filteringRules';
7070
import {
@@ -1078,17 +1078,25 @@ export async function activate(context: vscode.ExtensionContext) {
10781078
return;
10791079
}
10801080

1081+
const allModRoots = new Set<string>();
1082+
for (const root of roots) {
1083+
const modRoots = getProjectModRoots(root.fsPath);
1084+
for (const m of modRoots) {
1085+
allModRoots.add(m);
1086+
}
1087+
}
1088+
10811089
await vscode.window.withProgress(
10821090
{
10831091
location: vscode.ProgressLocation.Notification,
10841092
title: 'Scanning project files and mapping canonical paths...',
10851093
cancellable: false,
10861094
},
10871095
async () => {
1088-
for (const root of roots) {
1096+
for (const modRoot of allModRoots) {
10891097
await ensureProjectCanonicalImport({
10901098
overlayDbPath: projectCanonicalOverlayPath,
1091-
projectRoot: root.fsPath,
1099+
projectRoot: modRoot,
10921100
romfsPath,
10931101
pythonExecutable: pythonExe,
10941102
bridgePath,

src/projectPaths.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export function resolveProjectDestination(
146146
if (path.basename(gameRomfs).toLowerCase() === 'exefs') {
147147
isExefs = true;
148148
}
149+
foundFolder = true;
149150
} else {
150151
// Source is in the project (or a different dump structure). Find its relative path.
151152
const projectRel = path.relative(project, source);
@@ -206,3 +207,25 @@ export function resolveAddToCopyPaths(
206207
destination: resolveProjectDestination(copySource, projectRoot, romfsRoot, tkmmOption),
207208
};
208209
}
210+
211+
/**
212+
* Returns all isolated mod roots within a given workspace folder.
213+
* This includes the workspace root itself and all TKMM options (options/<Group>/<Option>).
214+
*/
215+
export function getProjectModRoots(projectRoot: string): string[] {
216+
const project = normalizePath(projectRoot);
217+
const roots: string[] = [project];
218+
const optionsDir = path.join(project, 'options');
219+
220+
if (fs.existsSync(optionsDir) && isDirectory(optionsDir)) {
221+
const groups = listSubdirectories(optionsDir);
222+
for (const group of groups) {
223+
const options = listSubdirectories(group);
224+
for (const option of options) {
225+
roots.push(normalizePath(option));
226+
}
227+
}
228+
}
229+
230+
return roots;
231+
}

vendor/py-xlink2

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)