@eclipse-docks/core 0.7.96 → 0.7.98

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=unzip.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unzip.d.ts","sourceRoot":"","sources":["../../src/commands/unzip.ts"],"names":[],"mappings":""}
@@ -1,98 +0,0 @@
1
- import JSZip from "jszip";
2
- import { registerAll } from "../core/commandregistry";
3
- import { activeSelectionSignal } from "../core/appstate";
4
- import { File, FileContentType, workspaceService } from "../core/filesys";
5
- import { taskService } from "../core/taskservice";
6
- import { toastError, toastInfo } from "../core/toast";
7
-
8
- registerAll({
9
- command: {
10
- id: "unzip",
11
- name: "Unzip Archive",
12
- description: "Extract a zip archive from the workspace",
13
- parameters: [
14
- {
15
- name: "file",
16
- description: "the zip file to extract, if not provided, the current selection will be used",
17
- required: false
18
- },
19
- {
20
- name: "target",
21
- description: "target folder to extract into, defaults to the zip filename without extension",
22
- required: false
23
- }
24
- ]
25
- },
26
- handler: {
27
- canExecute: (context: any) => {
28
- let filePath: string = context.params?.file;
29
- if (!filePath) {
30
- const selectedItem = activeSelectionSignal.get() as any;
31
- if (!selectedItem || !("path" in selectedItem)) return false;
32
- filePath = selectedItem.path;
33
- }
34
- return filePath.toLowerCase().endsWith(".zip");
35
- },
36
- execute: async (context: any) => {
37
- let filePath: string = context.params?.file;
38
- if (!filePath) {
39
- const selectedItem = activeSelectionSignal.get() as any;
40
- filePath = selectedItem.path;
41
- }
42
-
43
- const workspaceDir = await workspaceService.getWorkspace();
44
- if (!workspaceDir) {
45
- toastError("No workspace selected.");
46
- return;
47
- }
48
-
49
- await taskService.runAsync("Extracting archive", async (progress: any) => {
50
- try {
51
- const fileResource = await workspaceDir.getResource(filePath);
52
- if (!fileResource) {
53
- toastError("File not found: " + filePath);
54
- return;
55
- }
56
-
57
- let targetFolder = context.params?.target;
58
- if (!targetFolder) {
59
- const fileName = filePath.split("/").pop() || "extracted";
60
- targetFolder = fileName.replace(/\.zip$/i, "") + "/";
61
- }
62
-
63
- progress.message = "Loading archive...";
64
- progress.progress = 0;
65
- await workspaceDir.getResource(targetFolder, { create: true });
66
-
67
- const file = fileResource as File;
68
- const blob = await file.getContents({ blob: true });
69
- const zip = await JSZip.loadAsync(blob);
70
- const totalFiles = Object.values(zip.files).filter(entry => !entry.dir).length;
71
- let extractedCount = 0;
72
-
73
- progress.message = `Extracting to ${targetFolder.replace(/\/$/, "")}...`;
74
-
75
- for (const [relativePath, zipEntry] of Object.entries(zip.files)) {
76
- if (zipEntry.dir) continue;
77
-
78
- const entryBlob = await zipEntry.async("blob");
79
- const fullPath = `${targetFolder}${relativePath}`;
80
- const entryResource = await workspaceDir.getResource(fullPath, { create: true });
81
- const newFile = entryResource as File;
82
- await newFile.saveContents(entryBlob, { contentType: FileContentType.BINARY });
83
-
84
- extractedCount++;
85
- progress.progress = Math.round((extractedCount / totalFiles) * 100);
86
- progress.message = `Extracting ${extractedCount}/${totalFiles} files...`;
87
- }
88
-
89
- progress.progress = 100;
90
- toastInfo(`Archive extracted to ${targetFolder.replace(/\/$/, "")}: ${extractedCount} file(s)`);
91
- } catch (err: any) {
92
- toastError("Failed to extract archive: " + err);
93
- throw err;
94
- }
95
- });
96
- }
97
- }
98
- });