Skip to content
This repository was archived by the owner on Apr 19, 2025. It is now read-only.

Commit 6af2fe7

Browse files
committed
feat(extension): move natives to globalStorage
what a pita
1 parent 0869386 commit 6af2fe7

File tree

4 files changed

+28
-31
lines changed

4 files changed

+28
-31
lines changed

src/extension.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
1-
import { ExtensionContext, extensions, workspace, commands } from "vscode";
1+
import { ExtensionContext, extensions, workspace, commands, Uri } from "vscode";
22
import setPlugin from "./setPlugin";
33
import setLibrary from "./setLibrary";
44
import setNativeLibrary from "./setNativeLibrary";
5-
import { join as pathJoin } from "path";
5+
import * as path from "path";
6+
import { platform } from "os";
67

78
export const id = "overextended.cfxlua-vscode";
89
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 = "";
1711

1812
// this method is called when your extension is activated
1913
// your extension is activated the very first time the command is executed
2014
export async function activate(context: ExtensionContext) {
2115
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+
2235
await setPlugin(true);
2336
await setLibrary(
2437
["runtime", "natives/CFX-NATIVE", `natives/${game.toUpperCase()}`],

src/getPath.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/setLibrary.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as path from "path";
2-
import { extensionPath, id as extensionId } from "./extension";
3-
import getLuaPath from "./getPath";
2+
import { storagePath } from "./extension";
43
import getLuaConfig from "./getLuaConfig";
54
import getSettingsScope from "./getSettingsScope";
65

@@ -9,17 +8,7 @@ export default async function setLibrary(folders: string[], enable: boolean) {
98
const library: string[] = config.get("workspace.library")!;
109

1110
for (const folder of folders) {
12-
const folderPath = getLuaPath(path.join("library", folder));
13-
14-
for (let i = library.length - 1; i >= 0; i--) {
15-
const el = library[i];
16-
const isSelfExtension = el.includes(extensionId);
17-
const isCurrentVersion = el.includes(extensionPath);
18-
if (isSelfExtension && !isCurrentVersion) {
19-
library.splice(i, 1);
20-
}
21-
}
22-
11+
const folderPath = path.join(storagePath, "library", folder);
2312
const index = library.indexOf(folderPath);
2413

2514
if (enable) {

src/setPlugin.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import { storagePath } from "./extension";
12
import getLuaConfig from "./getLuaConfig";
2-
import getLuaPath from "./getPath";
33
import getSettingsScope from "./getSettingsScope";
4+
import * as path from "path";
45

56
export default async function setPlugin(enable: boolean) {
67
const config = getLuaConfig();
7-
const pluginPath = getLuaPath("plugin.lua");
8+
const pluginPath = path.join(storagePath, "plugin.lua");
89
const settingsScope = getSettingsScope();
910

1011
if (enable) {

0 commit comments

Comments
 (0)