diff --git a/dev/src/MCUtil.ts b/dev/src/MCUtil.ts index 20b2708e..7f918c6e 100644 --- a/dev/src/MCUtil.ts +++ b/dev/src/MCUtil.ts @@ -194,6 +194,13 @@ namespace MCUtil { return path.join(os.homedir(), "codewind-workspace"); } + export function getCWDataPath(): string { + if (MCUtil.getOS() === "windows") { + return "C:\\codewind-data"; + } + return path.join(os.homedir(), "codewind-data"); + } + /** * Joins a string array into a user-friendly list. * Eg, `joinWithAnd([ "tim", "erin", "john" ])` => "tim, erin, and john" diff --git a/dev/src/codewind/connection/UserProjectCreator.ts b/dev/src/codewind/connection/UserProjectCreator.ts index e5230334..6a0e5ef1 100644 --- a/dev/src/codewind/connection/UserProjectCreator.ts +++ b/dev/src/codewind/connection/UserProjectCreator.ts @@ -18,6 +18,7 @@ import SocketEvents from "./SocketEvents"; import Requester from "../project/Requester"; import { ProjectType, IProjectSubtypesDescriptor } from "../project/ProjectType"; import { CLICommandRunner } from "./CLICommands"; +import MCUtil from "../../MCUtil"; export interface ICWTemplateData { label: string; @@ -300,10 +301,6 @@ namespace UserProjectCreator { } export async function promptForDir(btnLabel: string, defaultUri: vscode.Uri | undefined): Promise { - // if (!defaultUri && vscode.workspace.workspaceFolders != null) { - // defaultUri = vscode.workspace.workspaceFolders[0].uri; - // } - const selectedDirs = await vscode.window.showOpenDialog({ canSelectFiles: false, canSelectFolders: true, @@ -312,10 +309,17 @@ namespace UserProjectCreator { defaultUri }); if (selectedDirs == null) { - return; + return undefined; + } + // canSelectMany is false so we just use [0] + const selectedDir = selectedDirs[0]; + + const cwDataPath = MCUtil.getCWDataPath(); + if (selectedDir.fsPath.startsWith(cwDataPath)) { + vscode.window.showErrorMessage(`You cannot create or add a project under ${cwDataPath}. Select a different directory.`); + return undefined; } - // canSelectMany is false - return selectedDirs[0]; + return selectedDir; } } diff --git a/dev/src/command/connection/CreateUserProjectCmd.ts b/dev/src/command/connection/CreateUserProjectCmd.ts index aa56b470..265611df 100644 --- a/dev/src/command/connection/CreateUserProjectCmd.ts +++ b/dev/src/command/connection/CreateUserProjectCmd.ts @@ -95,18 +95,11 @@ export default async function createProject(connection: Connection): Promise