Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Block project create/add under codewind-data (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Etchells authored and jopit committed Nov 21, 2019
1 parent ff94862 commit 6de861e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
7 changes: 7 additions & 0 deletions dev/src/MCUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 11 additions & 7 deletions dev/src/codewind/connection/UserProjectCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -300,10 +301,6 @@ namespace UserProjectCreator {
}

export async function promptForDir(btnLabel: string, defaultUri: vscode.Uri | undefined): Promise<vscode.Uri | undefined> {
// if (!defaultUri && vscode.workspace.workspaceFolders != null) {
// defaultUri = vscode.workspace.workspaceFolders[0].uri;
// }

const selectedDirs = await vscode.window.showOpenDialog({
canSelectFiles: false,
canSelectFolders: true,
Expand All @@ -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;
}
}

Expand Down
11 changes: 2 additions & 9 deletions dev/src/command/connection/CreateUserProjectCmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,11 @@ export default async function createProject(connection: Connection): Promise<voi
const defaultUri = vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders[0] ?
vscode.workspace.workspaceFolders[0].uri : undefined;

const selection = await vscode.window.showOpenDialog({
canSelectFiles: false,
canSelectFolders: true,
canSelectMany: false,
defaultUri,
openLabel: "Select Parent Directory",
});

const selection = await UserProjectCreator.promptForDir("Select Parent Directory", defaultUri);
if (!selection) {
return undefined;
}
parentDir = selection[0];
parentDir = selection;
}

const response = await UserProjectCreator.createProject(connection, template, parentDir, projectName);
Expand Down

0 comments on commit 6de861e

Please sign in to comment.