Skip to content

Commit

Permalink
Merge branch 'main' into devtest
Browse files Browse the repository at this point in the history
  • Loading branch information
RuiNtD committed Jul 26, 2023
2 parents e6ad1c2 + c073d90 commit 21f7881
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 0 deletions.
78 changes: 78 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions fileinfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import * as path from "https://deno.land/std@0.196.0/path/mod.ts";
import { walk } from "https://deno.land/std@0.196.0/fs/mod.ts";
import { Select } from "https://deno.land/x/cliffy@v1.0.0-rc.2/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/std@0.196.0/path/_util.ts";

let dir = Array.from(Deno.readDirSync("."))
.filter((v) => v.isFile && path.extname(v.name) == ".exe")
.map((v) => ({
name: v.name,
time: Deno.statSync(v.name).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,
});

function formatSize(size: number): string {
return formatBytes(size, {
binary: true,
})
.replace(" ", "")
.replace("i", "");
}

const downloadSize = formatSize((await Deno.stat(file)).size);
const hash = toHashString(
await crypto.subtle.digest("MD5", await Deno.readFile(file))
);

const tempDir = await Deno.makeTempDir();
await new Deno.Command(".\\" + file, {
args: [`/DESTINATION=${tempDir}\\`],
}).output();

let tempSize = 0;
for await (const entry of walk(tempDir)) {
if (entry.isDirectory) continue;
const stat = await Deno.stat(entry.path);
tempSize += stat.size;
}
const installedSize = formatSize(tempSize);
await Deno.remove(tempDir, { recursive: true });

console.log(`
[${downloadSize} download / ${installedSize} installed]
(MD5: ${hash})
`);

0 comments on commit 21f7881

Please sign in to comment.