Skip to content

Commit 28aab92

Browse files
committed
Update Windows Integration
1 parent 724a5a6 commit 28aab92

8 files changed

Lines changed: 205 additions & 21 deletions

File tree

bin/index.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { prefix, version, format, name__ } from "../lib/meta.js";
55
import JUSTC from "justc";
66
import { fileURLToPath } from "url";
77
import { execSync, spawn } from "child_process";
8-
import { compress as compressUI, message } from "./windows/import.cjs";
8+
import { compress as compressUI, message, decompress as decompressUI } from "./windows/import.cjs";
99
import { toFile, fromFile } from "./format.js";
1010
import readline from 'node:readline';
1111

@@ -352,6 +352,12 @@ function getInpName(inp) {
352352
console.log(prefix + e);
353353
exit(1, e);
354354
}
355+
let windowsConfig = {
356+
checksum: undefined,
357+
metadata: undefined,
358+
encrypt: undefined,
359+
password: undefined
360+
};
355361
if (!(()=>{
356362
if (!windows || !isFile) return true;
357363

@@ -375,6 +381,11 @@ function getInpName(inp) {
375381

376382
customConfig.depthLimit = Math.max(res[1].slider, 1);
377383

384+
windowsConfig.checksum = res[1].checked8;
385+
windowsConfig.metadata = res[1].checked9;
386+
windowsConfig.encrypt = res[1].checked10;
387+
windowsConfig.password = res[1].password;
388+
378389
config = {
379390
...config,
380391
...customConfig
@@ -456,6 +467,12 @@ function getInpName(inp) {
456467
dirs.push((await instance.compressToBase64(current, config)).replace(/=+$/, ''));
457468
total += 1;
458469
}
470+
471+
if (windows) {
472+
if (typeof windowsConfig.checksum == 'boolean') checksum = windowsConfig.checksum;
473+
if (typeof windowsConfig.metadata == 'boolean') includeMeta = windowsConfig.metadata;
474+
if (typeof windowsConfig.encrypt == 'boolean' && windowsConfig.encrypt && typeof windowsConfig.password == 'string') key = windowsConfig.password;
475+
}
459476

460477
const startsWithDot = extn[0] == '.';
461478
fs.writeFileSync(output[0] + (
@@ -510,8 +527,17 @@ function getInpName(inp) {
510527
let password;
511528

512529
if (key != '') password = key;
513-
else if (windows) password;
514-
else password = await ask(q);
530+
else if (windows) {
531+
const res = decompressUI(name__);
532+
if (!res[0] || (()=>{
533+
try {
534+
password = res[1];
535+
return false;
536+
} catch (_) {
537+
return true;
538+
}
539+
})) exit(0);
540+
} else password = await ask(q);
515541

516542
return password;
517543
});

bin/windows/default.justc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
-- Default configuration options for JavaScript String Compressor
22

3+
-- Archive options
4+
checksum = y,
5+
metadata = y,
6+
encrypt = n,
7+
38
-- Compress options
49
JUSTC = y,
510
recursiveCompression = y,

bin/windows/import.cjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
if (process.platform !== "win32") module.exports = {
2-
compress: () => {},
3-
message : () => {}
2+
compress : () => {},
3+
message : () => {},
4+
decompress: () => {},
45
}; else {
5-
const { compress } = require("./ui");
6+
const { compress, decompress } = require("./ui");
67
const { message } = require("./message");
78

89
module.exports = {
910
compress,
10-
message
11+
message,
12+
decompress
1113
};
1214
}

bin/windows/ui.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const uiDir = path.resolve(__dirname, "./ui");
99
const confirmPs1 = path.resolve(uiDir, "./confirm.ps1");
1010
const welcomePs1 = path.resolve(uiDir, "./welcome.ps1");
1111
const compresPs1 = path.resolve(__dirname, "./windows/ui/compress.ps1");
12+
const decomprPs1 = path.resolve(__dirname, "./windows/ui/decompress.ps1");
1213

1314
export function confirm(title, text, repo, site) {
1415
try {
@@ -64,6 +65,9 @@ export function compress(title, name, icon, config) {
6465
5: config.base64Packing,
6566
6: config.offsetEncoding,
6667
7: config.lzstring,
68+
8: config.checksum,
69+
9: config.metadata,
70+
10: config.encrypt
6771
}
6872

6973
const cmd = `pwsh -ExecutionPolicy Bypass -File "${compresPs1}" ` +
@@ -76,7 +80,10 @@ export function compress(title, name, icon, config) {
7680
`-CheckDefault4 ${cd[4] ? 1 : 0} ` +
7781
`-CheckDefault5 ${cd[5] ? 1 : 0} ` +
7882
`-CheckDefault6 ${cd[6] ? 1 : 0} ` +
79-
`-CheckDefault7 ${cd[7] ? 1 : 0}`;
83+
`-CheckDefault7 ${cd[7] ? 1 : 0} ` +
84+
`-CheckDefault8 ${cd[8] ? 1 : 0} ` +
85+
`-CheckDefault9 ${cd[9] ? 1 : 0} ` +
86+
`-CheckDefault10 ${cd[10] ? 1 : 0}`;
8087

8188
const stdout = execSync(cmd).toString();
8289

@@ -88,3 +95,18 @@ export function compress(title, name, icon, config) {
8895
return [false, null];
8996
}
9097
}
98+
99+
export function decompress(title) {
100+
try {
101+
const cmd = `pwsh -ExecutionPolicy Bypass -File "${decomprPs1}" ` +
102+
`-Name "${title}" ` +
103+
`-Text ""`;
104+
const stdout = execSync(cmd).toString();
105+
if (stdout) {
106+
const result = JSON.parse(stdout.trim());
107+
return [true, result.password];
108+
}
109+
} catch {
110+
return [false, null];
111+
}
112+
}

bin/windows/ui/compress.ps1

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ param (
77
[string]$CheckDefault5 = "0",
88
[string]$CheckDefault6 = "0",
99
[string]$CheckDefault7 = "0",
10+
[string]$CheckDefault8 = "0",
11+
[string]$CheckDefault9 = "0",
12+
[string]$CheckDefault10 = "0",
1013
[string]$Title = "",
1114
[string]$FileName = ""
1215
)
@@ -18,6 +21,9 @@ $IsChecked4 = ($CheckDefault4 -eq "1")
1821
$IsChecked5 = ($CheckDefault5 -eq "1")
1922
$IsChecked6 = ($CheckDefault6 -eq "1")
2023
$IsChecked7 = ($CheckDefault7 -eq "1")
24+
$IsChecked8 = ($CheckDefault8 -eq "1")
25+
$IsChecked9 = ($CheckDefault9 -eq "1")
26+
$IsChecked10 = ($CheckDefault10 -eq "1")
2127

2228
Add-Type -AssemblyName System.Windows.Forms
2329
Add-Type -AssemblyName System.Drawing
@@ -95,6 +101,13 @@ $CheckBox6.Text, $CheckBox6.Location, $CheckBox6.Checked, $CheckBox6.AutoSize =
95101
$CheckBox7 = New-Object system.Windows.Forms.CheckBox
96102
$CheckBox7.Text, $CheckBox7.Location, $CheckBox7.Checked, $CheckBox7.AutoSize = "lz-string", (New-Object System.Drawing.Point(15,201)), $IsChecked7, $true
97103

104+
$CheckBox8 = New-Object system.Windows.Forms.CheckBox
105+
$CheckBox8.Text, $CheckBox8.Location, $CheckBox8.Checked, $CheckBox8.AutoSize = "Checksum", (New-Object System.Drawing.Point(235,81)), $IsChecked8, $true
106+
$CheckBox9 = New-Object system.Windows.Forms.CheckBox
107+
$CheckBox9.Text, $CheckBox9.Location, $CheckBox9.Checked, $CheckBox9.AutoSize = "Metadata", (New-Object System.Drawing.Point(235,101)), $IsChecked9, $true
108+
$CheckBox10= New-Object system.Windows.Forms.CheckBox
109+
$CheckBox10.Text,$CheckBox10.Location,$CheckBox10.Checked,$CheckBox10.AutoSize= "Encrypt", (New-Object System.Drawing.Point(240,130)), $IsChecked10, $true
110+
98111
$Label4 = New-Object system.Windows.Forms.Label
99112
$Label4.text = "Options"
100113
$Label4.AutoSize = $true
@@ -199,6 +212,28 @@ $elhost = New-Object System.Windows.Forms.Integration.ElementHost
199212
$elhost.Dock = [System.Windows.Forms.DockStyle]::Fill
200213
$elhost.Child = $wpfSlider
201214

215+
$Label8 = New-Object system.Windows.Forms.Label
216+
$Label8.text = "Password"
217+
$Label8.AutoSize = $true
218+
$Label8.width = 25
219+
$Label8.height = 10
220+
$Label8.location = New-Object System.Drawing.Point(240,150)
221+
$Label8.Font = New-Object System.Drawing.Font('Microsoft JhengHei',10)
222+
223+
$InputBox = New-Object System.Windows.Forms.TextBox
224+
$InputBox.Text = ""
225+
$InputBox.Location = New-Object System.Drawing.Point(240, 170)
226+
$InputBox.Width = 170
227+
$InputBox.Font = New-Object System.Drawing.Font('Microsoft JhengHei', 10)
228+
229+
$Label7 = New-Object system.Windows.Forms.Label
230+
$Label7.text = "Archive options"
231+
$Label7.AutoSize = $true
232+
$Label7.width = 25
233+
$Label7.height = 10
234+
$Label7.location = New-Object System.Drawing.Point(230,54)
235+
$Label7.Font = New-Object System.Drawing.Font('Microsoft JhengHei',12)
236+
202237
$panel = New-Object System.Windows.Forms.Panel
203238
$panel.Location = New-Object System.Drawing.Point(20, 320)
204239
$panel.Size = New-Object System.Drawing.Size(400, 18)
@@ -211,6 +246,30 @@ $Panel1.add_HandleCreated({
211246
$this.Region = [System.Drawing.Region]::FromHrgn($hRgn)
212247
})
213248

249+
$Panel2 = New-Object system.Windows.Forms.Panel
250+
$Panel2.height, $Panel2.width, $Panel2.location = 80, 182, (New-Object System.Drawing.Point(235,125))
251+
$Panel2.add_HandleCreated({
252+
$hRgn = $Win32::CreateRoundRectRgn(0, 0, $this.Width, $this.Height, 10, 10)
253+
$this.Region = [System.Drawing.Region]::FromHrgn($hRgn)
254+
})
255+
$Panel3 = New-Object system.Windows.Forms.Panel
256+
$Panel3.height, $Panel3.width, $Panel3.location = 84, 186, (New-Object System.Drawing.Point(233,123))
257+
$Panel3.add_HandleCreated({
258+
$hRgn = $Win32::CreateRoundRectRgn(0, 0, $this.Width, $this.Height, 12, 12)
259+
$this.Region = [System.Drawing.Region]::FromHrgn($hRgn)
260+
})
261+
262+
function UpdateEncryption {
263+
$InputBox.Enabled = $CheckBox10.Checked
264+
if ($CheckBox10.Checked) {
265+
$Panel3.BackColor = [System.Drawing.Color]::FromArgb(150, 81, 90, 218)
266+
} else {
267+
$Panel3.BackColor = [System.Drawing.Color]::FromArgb(0, 239, 213, 255)
268+
}
269+
}
270+
UpdateEncryption
271+
$CheckBox10.add_CheckedChanged({UpdateEncryption})
272+
214273
$Button1 = New-Object system.Windows.Forms.Button
215274
$Button1.text = "Compress"
216275
$Button1.width = 90
@@ -224,14 +283,16 @@ $Button1.add_HandleCreated({
224283
$this.Region = [System.Drawing.Region]::FromHrgn($hRgn)
225284
})
226285

227-
$Form.Controls.AddRange(@($Button1, $CheckBox1, $Label4, $Label1, $Panel1, $CheckBox2, $CheckBox3, $CheckBox4, $CheckBox5, $CheckBox6, $CheckBox7, $Label2, $panel, $Label3, $Label5, $Label6))
286+
$Form.Controls.AddRange(@($Button1, $CheckBox1, $Label4, $Label1, $Panel1, $CheckBox2, $CheckBox3, $CheckBox4, $CheckBox5, $CheckBox6, $CheckBox7, $Label2, $panel, $Label3, $Label5, $Label6, $Label7, $CheckBox8, $CheckBox9, $CheckBox10, $InputBox, $Label8, $Panel2, $Panel3))
228287
if ($addImage) { $Form.Controls.Add($PictureBox1) }
229288

230289
$Form.AcceptButton = $Button1
290+
$Panel2.SendToBack()
291+
$Panel3.SendToBack()
231292
$Panel1.SendToBack()
232293

233294
$clr = [System.Drawing.Color]::FromArgb(175, 255, 255, 255)
234-
foreach ($ctl in @($Panel1, $CheckBox1, $Label4, $Label1, $PictureBox1, $CheckBox2, $CheckBox3, $CheckBox4, $CheckBox5, $CheckBox6, $CheckBox7, $Label2, $Label3, $Label5, $Label6)) {
295+
foreach ($ctl in @($Panel1, $CheckBox1, $Label4, $Label1, $PictureBox1, $CheckBox2, $CheckBox3, $CheckBox4, $CheckBox5, $CheckBox6, $CheckBox7, $Label2, $Label3, $Label5, $Label6, $Label7, $CheckBox8, $CheckBox9, $Panel2, $CheckBox10, $Label8)) {
235296
$ctl.BackColor = $clr
236297
}
237298
foreach ($ctl in @($elhost, $panel)) {
@@ -248,6 +309,10 @@ if ($result -eq "OK") {
248309
checked5 = $CheckBox5.Checked
249310
checked6 = $CheckBox6.Checked
250311
checked7 = $CheckBox7.Checked
312+
checked8 = $CheckBox8.Checked
313+
checked9 = $CheckBox9.Checked
314+
checked10 = $CheckBox10.Checked
315+
password = $InputBox.Text
251316
slider = $wpfSlider.Value
252317
}
253318
Write-Output ($output | ConvertTo-Json -Compress)

bin/windows/ui/decompress.ps1

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
param (
2+
[string]$Name = "",
3+
[string]$Text = ""
4+
)
5+
6+
Add-Type -AssemblyName System.Windows.Forms
7+
Add-Type -AssemblyName System.Drawing
8+
Add-Type -AssemblyName PresentationFramework
9+
Add-Type -AssemblyName WindowsFormsIntegration
10+
11+
[Windows.Forms.Application]::EnableVisualStyles()
12+
13+
$form = New-Object Windows.Forms.Form
14+
$form.Text = $Name
15+
$form.Size = New-Object Drawing.Size(400, 140)
16+
$form.StartPosition = "CenterScreen"
17+
$form.FormBorderStyle = "FixedDialog"
18+
$form.MaximizeBox = $false
19+
$form.MinimizeBox = $false
20+
$form.ControlBox = $false
21+
$form.TopMost = $true
22+
23+
$Icon = Join-Path $PSScriptRoot "..\..\..\..\jssc.ico"
24+
$Icon = [System.IO.Path]::GetFullPath($Icon)
25+
Add-Type -Path "$PSScriptRoot\process.cs"
26+
if (Test-Path $Icon) {
27+
[Taskbar]::SetCurrentProcessExplicitAppUserModelID("JSSC.Decompress") | Out-Null
28+
$form.Icon = New-Object System.Drawing.Icon($Icon)
29+
}
30+
31+
$label = New-Object Windows.Forms.Label
32+
$label.Text = "$Text"
33+
$label.Location = New-Object Drawing.Point(20, 5)
34+
$label.AutoSize = $true
35+
$label.Font = New-Object System.Drawing.Font('Microsoft JhengHei',10)
36+
37+
$InputBox = New-Object System.Windows.Forms.TextBox
38+
$InputBox.Text = ""
39+
$InputBox.Location = New-Object System.Drawing.Point(20, 30)
40+
$InputBox.Width = 340
41+
$InputBox.Font = New-Object System.Drawing.Font('Microsoft JhengHei', 10)
42+
43+
$Button1 = New-Object system.Windows.Forms.Button
44+
$Button1.text = "Decompress"
45+
$Button1.width = 340
46+
$Button1.height = 30
47+
$Button1.Anchor = 'right,bottom'
48+
$Button1.location = New-Object System.Drawing.Point(20,65)
49+
$Button1.Font = New-Object System.Drawing.Font('Microsoft JhengHei',10)
50+
$Button1.DialogResult = [Windows.Forms.DialogResult]::OK
51+
$Button1.add_HandleCreated({
52+
$hRgn = $Win32::CreateRoundRectRgn(0, 0, $this.Width, $this.Height, 5, 5)
53+
$this.Region = [System.Drawing.Region]::FromHrgn($hRgn)
54+
})
55+
56+
$form.Controls.AddRange(@($label, $InputBox, $Button1))
57+
58+
$result = $Form.ShowDialog()
59+
if ($result -eq "OK") {
60+
$output = @{
61+
password = $InputBox.Text
62+
}
63+
Write-Output ($output | ConvertTo-Json -Compress)
64+
}

bin/windows/ui/wait.ps1

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ $timer = New-Object Windows.Forms.Timer
6565
$timer.Interval = 100
6666

6767
$idleTicks = 0
68+
$idleTimer = New-Object Windows.Forms.Timer
69+
$idleTimer.Interval = 5000
70+
$idleTimer.Add_Tick({
71+
if ($idleTicks -ge 0) {
72+
$wpfProgress.IsIndeterminate = $true
73+
}
74+
$idleTicks = 0
75+
$idleTimer.Stop()
76+
})
6877
function Idle {
6978
$idleTicks++
70-
$timeout = New-Object Windows.Forms.Timer
71-
$timeout.Interval = 3000
72-
$timeout.Add_Tick({
73-
if ($idleTicks -ge 0) {
74-
$wpfProgress.IsIndeterminate = $true
75-
} else {
76-
$timeout.Stop()
77-
}
78-
})
79-
$timeout.Start()
79+
$idleTimer.Start()
8080
}
8181

8282
$timer.Add_Tick({

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "strc",
3-
"version": "2.1.1-g",
3+
"version": "2.1.1-h",
44
"description": "JavaScript String Compressor - lossless string compression algorithm",
55
"main": "dist/jssc.cjs",
66
"repository": {

0 commit comments

Comments
 (0)