Skip to content

Commit 8efa688

Browse files
Fixed a critical bug causing dirs to be deleted
1 parent beab587 commit 8efa688

2 files changed

Lines changed: 44 additions & 12 deletions

File tree

src/archiveFsCommands.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,14 +1419,34 @@ export class ArchiveTreeDragDrop
14191419
return;
14201420
}
14211421
const uris = transfer.value as string[];
1422-
const sources = uris.map((uriString) => {
1422+
const sources: ArchiveTreeItem[] = [];
1423+
1424+
for (const uriString of uris) {
14231425
const uri = vscode.Uri.parse(uriString);
1424-
return {
1426+
const srcFsPath = uri.fsPath.toLowerCase();
1427+
const destFsPath = folderUri.fsPath.toLowerCase();
1428+
1429+
// Prevent dropping onto itself or its own parent (accidental drag)
1430+
if (srcFsPath === destFsPath || path.dirname(srcFsPath) === destFsPath) {
1431+
continue;
1432+
}
1433+
1434+
// Prevent dropping a folder into its own subdirectory
1435+
if (destFsPath.startsWith(srcFsPath + path.sep) || destFsPath.startsWith(srcFsPath + '/')) {
1436+
void vscode.window.showErrorMessage(`Cannot move an item into its own subdirectory.`);
1437+
continue;
1438+
}
1439+
1440+
sources.push({
14251441
resourceUri: uri,
14261442
entryName: path.basename(uri.fsPath),
14271443
contextValue: 'archiveFile',
1428-
} as ArchiveTreeItem;
1429-
});
1444+
} as ArchiveTreeItem);
1445+
}
1446+
1447+
if (sources.length === 0) {
1448+
return;
1449+
}
14301450
try {
14311451
const targets = await copyEntries(sources, folderUri, true);
14321452
const moves = sources.map((source, index) => ({

src/archiveTree.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,30 @@ export class ArchiveTreeProvider implements vscode.TreeDataProvider<ArchiveTreeI
121121

122122
try {
123123
const entries = await vscode.workspace.fs.readDirectory(element.resourceUri);
124-
const isProjectRoot = element.contextValue === 'archiveRoot';
124+
const isProjectRoot = element.contextValue === 'archiveRoot' || element.contextValue === 'archiveProjectDir' || element.contextValue === 'archiveProjectDirActive';
125125

126-
// Find the project root path for this element
127-
let projectRootPath = element.resourceUri.fsPath;
128-
if (!isProjectRoot) {
126+
// Find the workspace root path for hasMultipleMods
127+
let workspaceRootPath = element.resourceUri.fsPath;
128+
if (element.contextValue !== 'archiveRoot') {
129129
const matchedRoot = this.roots.find(r => element.resourceUri.fsPath.startsWith(r.fsPath));
130130
if (matchedRoot) {
131-
projectRootPath = matchedRoot.fsPath;
131+
workspaceRootPath = matchedRoot.fsPath;
132132
}
133133
}
134+
135+
// Find the project root for TKMM options
136+
let tkmmProjectRoot = element.resourceUri.fsPath;
137+
if (element.contextValue === 'tkmmOptionsRoot') {
138+
tkmmProjectRoot = path.dirname(element.resourceUri.fsPath);
139+
} else if (element.contextValue === 'tkmmOptionGroup') {
140+
tkmmProjectRoot = path.dirname(path.dirname(element.resourceUri.fsPath));
141+
} else if (element.contextValue === 'tkmmOption' || element.contextValue === 'tkmmOptionActive') {
142+
tkmmProjectRoot = path.dirname(path.dirname(path.dirname(element.resourceUri.fsPath)));
143+
} else if (!isProjectRoot) {
144+
tkmmProjectRoot = workspaceRootPath;
145+
}
134146

135-
const activeTkmmOption = getActiveTkmmOption(this.context, projectRootPath);
147+
const activeTkmmOption = getActiveTkmmOption(this.context, tkmmProjectRoot);
136148

137149
const children = await Promise.all(entries
138150
.sort(compareEntriesFoldersFirstKeepingArchivesMixed)
@@ -147,7 +159,7 @@ export class ArchiveTreeProvider implements vscode.TreeDataProvider<ArchiveTreeI
147159
contextValue = 'tkmmOptionGroup';
148160
} else if (element.contextValue === 'tkmmOptionGroup' && isDirectory) {
149161
contextValue = 'tkmmOption';
150-
} else if (isDirectory && this.hasMultipleMods.has(projectRootPath) && contextValue === 'archiveDir') {
162+
} else if (isDirectory && this.hasMultipleMods.has(workspaceRootPath) && contextValue === 'archiveDir') {
151163
// Check if this directory is a valid mod folder (has romfs/exefs/.tkproj)
152164
let isModFolder = false;
153165
try {
@@ -163,7 +175,7 @@ export class ArchiveTreeProvider implements vscode.TreeDataProvider<ArchiveTreeI
163175
// Ignore
164176
}
165177
if (isModFolder) {
166-
const currentLogicalRoot = this.logicalRoots.get(projectRootPath);
178+
const currentLogicalRoot = this.logicalRoots.get(workspaceRootPath);
167179
if (currentLogicalRoot && currentLogicalRoot === childUri.fsPath) {
168180
contextValue = 'archiveProjectDirActive';
169181
} else {

0 commit comments

Comments
 (0)