-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using Dax now and pinning permissions
- Loading branch information
Showing
7 changed files
with
280 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,11 @@ | |
"udd": "deno run -r --allow-read=. --allow-write=. --allow-net https://deno.land/x/udd/main.ts deno.json" | ||
}, | ||
"imports": { | ||
"std/": "https://deno.land/[email protected]/", | ||
"zod": "https://deno.land/x/[email protected]/mod.ts", | ||
"std/": "https://deno.land/[email protected]/", | ||
"permissions": "https://deno.land/[email protected]/permissions/mod.ts#=", | ||
"dax": "https://deno.land/x/[email protected]/mod.ts", | ||
"ini": "npm:[email protected]", | ||
"zipjs": "https://deno.land/x/[email protected]/index.js" | ||
"zipjs": "https://deno.land/x/[email protected]/index.js", | ||
"zod": "https://deno.land/x/[email protected]/mod.ts" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
import * as path from "https://deno.land/[email protected]/path/mod.ts"; | ||
import { walk } from "https://deno.land/std@0.196.0/fs/mod.ts"; | ||
import { Select } from "https://deno.land/x/[email protected]/prompt/select.ts"; | ||
import { format as formatBytes } from "https://deno.land/std@0.196.0/fmt/bytes.ts"; | ||
import { crypto, toHashString } from "https://deno.land/std/crypto/mod.ts"; | ||
import { stripTrailingSeparators } from "https://deno.land/[email protected]/path/_util.ts"; | ||
|
||
let dir = Array.from(Deno.readDirSync(".")) | ||
.filter((v) => v.isFile && path.extname(v.name) == ".exe") | ||
import $ from "dax"; | ||
import { format as formatBytes } from "std/fmt/bytes.ts"; | ||
import { crypto } from "std/crypto/mod.ts"; | ||
import { encodeHex } from "std/encoding/hex.ts"; | ||
|
||
$.setPrintCommand(true); | ||
|
||
const dir = Array.from($.path(".").readDirFilePathsSync()) | ||
.filter((v) => v.isFileSync() && v.extname() == ".exe") | ||
.map((v) => ({ | ||
name: v.name, | ||
time: Deno.statSync(v.name).mtime?.valueOf() || 0, | ||
path: v, | ||
time: v.statSync()?.mtime?.valueOf() || 0, | ||
})) | ||
.sort((a, b) => b.time - a.time) | ||
.map((v) => v.name); | ||
const file: string = await Select.prompt({ | ||
message: "Pick a file", | ||
options: dir, | ||
}); | ||
.map((v) => v.path); | ||
|
||
const file = | ||
dir[ | ||
await $.select({ | ||
message: "Pick a file", | ||
options: dir.map((v) => v.basename()), | ||
}) | ||
]; | ||
|
||
function formatSize(size: number): string { | ||
return formatBytes(size, { | ||
|
@@ -26,26 +30,22 @@ function formatSize(size: number): string { | |
.replace("i", ""); | ||
} | ||
|
||
const downloadSize = formatSize((await Deno.stat(file)).size); | ||
const hash = toHashString( | ||
await crypto.subtle.digest("MD5", await Deno.readFile(file)) | ||
const downloadSize = formatSize((await file.stat())?.size || 0); | ||
const hash = encodeHex( | ||
await crypto.subtle.digest("MD5", await file.readBytes()) | ||
); | ||
|
||
const tempDir = await Deno.makeTempDir(); | ||
await new Deno.Command(".\\" + file, { | ||
args: [`/DESTINATION=${tempDir}\\`], | ||
}).output(); | ||
const tempDir = $.path(await Deno.makeTempDir()); | ||
await $`${file} /DESTINATION=${tempDir}\\`; | ||
|
||
let tempSize = 0; | ||
for await (const entry of walk(tempDir)) { | ||
for await (const entry of tempDir.walk()) { | ||
if (entry.isDirectory) continue; | ||
const stat = await Deno.stat(entry.path); | ||
tempSize += stat.size; | ||
const stat = await entry.path.stat(); | ||
tempSize += stat?.size || 0; | ||
} | ||
const installedSize = formatSize(tempSize); | ||
await Deno.remove(tempDir, { recursive: true }); | ||
await tempDir.remove({ recursive: true }); | ||
|
||
console.log(` | ||
[${downloadSize} download / ${installedSize} installed] | ||
(MD5: ${hash}) | ||
`); | ||
$.log(`[${downloadSize} download / ${installedSize} installed] | ||
(MD5: ${hash})`); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters