|
1 | | -import { ExtensionContext, extensions, workspace, commands } from "vscode"; |
| 1 | +import { ExtensionContext, extensions, workspace, commands, Uri } from "vscode"; |
2 | 2 | import setPlugin from "./setPlugin"; |
3 | 3 | import setLibrary from "./setLibrary"; |
4 | 4 | import setNativeLibrary from "./setNativeLibrary"; |
5 | | -import { join as pathJoin } from "path"; |
| 5 | +import * as path from "path"; |
| 6 | +import { platform } from "os"; |
6 | 7 |
|
7 | 8 | export const id = "overextended.cfxlua-vscode"; |
8 | 9 | export const extension = extensions.getExtension(id)!; |
9 | | -export const extensionPath = (() => { |
10 | | - const extensionPath = extension.extensionPath; |
11 | | - const pos = extensionPath.indexOf(".vscode"); |
12 | | - |
13 | | - if (pos === -1) return extensionPath; |
14 | | - |
15 | | - return pathJoin("~", extensionPath.substring(pos)); |
16 | | -})(); |
| 10 | +export let storagePath = ""; |
17 | 11 |
|
18 | 12 | // this method is called when your extension is activated |
19 | 13 | // your extension is activated the very first time the command is executed |
20 | 14 | export async function activate(context: ExtensionContext) { |
21 | 15 | const game = workspace.getConfiguration("cfxlua").get("game", "GTAV"); |
| 16 | + const storageUri = context.globalStorageUri; |
| 17 | + const sourceUri = Uri.joinPath(extension.extensionUri, "plugin"); |
| 18 | + const targetUri = Uri.joinPath(storageUri, "cfxlua"); |
| 19 | + storagePath = targetUri.toString(); |
| 20 | + // istg they go out of their way to make referencing the global storage path annoying |
| 21 | + storagePath = path.join( |
| 22 | + "~", |
| 23 | + platform() === "win32" ? "AppData\\Roaming" : ".config", |
| 24 | + storagePath.substring(storagePath.indexOf("Code")), |
| 25 | + ); |
| 26 | + |
| 27 | + console.log("storagePath", storagePath); |
| 28 | + |
| 29 | + try { |
| 30 | + await workspace.fs.stat(targetUri); |
| 31 | + } catch (e) { |
| 32 | + await workspace.fs.rename(sourceUri, targetUri, { overwrite: true }); |
| 33 | + } |
| 34 | + |
22 | 35 | await setPlugin(true); |
23 | 36 | await setLibrary( |
24 | 37 | ["runtime", "natives/CFX-NATIVE", `natives/${game.toUpperCase()}`], |
|
0 commit comments