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

Commit b7b6875

Browse files
committed
refactor(extension): copy files directly to globalstorage path
1 parent 2479636 commit b7b6875

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/extension.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import setLibrary from './setLibrary';
1010
import setNativeLibrary from './setNativeLibrary';
1111
import * as path from 'node:path';
1212
import * as os from 'node:os';
13+
import moveFile from './moveFile';
1314

1415
export const id = 'overextended.cfxlua-vscode';
1516
export const extension = extensions.getExtension(id)!;
@@ -19,7 +20,6 @@ export async function activate(context: ExtensionContext) {
1920
const game = workspace.getConfiguration('cfxlua').get('game', 'GTAV');
2021
const storageUri = context.globalStorageUri;
2122
const sourceUri = Uri.joinPath(extension.extensionUri, 'plugin');
22-
const targetUri = Uri.joinPath(storageUri, 'cfxlua');
2323
const platform = os.platform();
2424
storagePath = storageUri.toString();
2525

@@ -35,11 +35,8 @@ export async function activate(context: ExtensionContext) {
3535
);
3636
}
3737

38-
try {
39-
await workspace.fs.stat(targetUri);
40-
} catch (e) {
41-
await workspace.fs.rename(sourceUri, targetUri, { overwrite: true });
42-
}
38+
await moveFile('plugin.lua', sourceUri, storageUri);
39+
await moveFile('library', sourceUri, storageUri);
4340

4441
await setPlugin(true);
4542
await setLibrary(

src/moveFile.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { workspace, Uri } from 'vscode';
2+
3+
export default async function (name: string, source: Uri, target: Uri) {
4+
const sourceFile = Uri.joinPath(source, name);
5+
6+
try {
7+
await workspace.fs.stat(sourceFile);
8+
9+
return workspace.fs.rename(sourceFile, Uri.joinPath(target, name), {
10+
overwrite: true,
11+
});
12+
} catch (e) {}
13+
}

0 commit comments

Comments
 (0)